Re: [PATCH for testing] Re: Decreasing stime running confuses top

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Christian Borntraeger <borntraeger@...>
Cc: Luca Tettamanti <kronos.it@...>, Frans Pop <elendil@...>, Willy Tarreau <w@...>, LKML <linux-kernel@...>, Ilpo Järvinen <ilpo.jarvinen@...>, Alexander E. Patrakov <patrakov@...>, Ingo Molnar <mingo@...>
Date: Thursday, October 4, 2007 - 6:01 pm

On 10/04/2007 05:10 PM, Christian Borntraeger wrote:


Alternative patch:

procfs: Don't read runtime twice when computing task's stime

Current code reads p->se.sum_exec_runtime twice and goes through
multiple type conversions to calculate stime. Read it once and
skip some of the conversions.

Signed-off-by: Chuck Ebbert <cebbert@redhat.com>

--- linux-2.6.23-rc6-dell.orig/fs/proc/array.c
+++ linux-2.6.23-rc6-dell/fs/proc/array.c
@@ -334,39 +334,38 @@ static cputime_t task_stime(struct task_
 	return p->stime;
 }
 #else
-static cputime_t task_utime(struct task_struct *p)
+static clock_t __task_utime(struct task_struct *p, u64 runtime)
 {
 	clock_t utime = cputime_to_clock_t(p->utime),
 		total = utime + cputime_to_clock_t(p->stime);
-	u64 temp;
 
 	/*
 	 * Use CFS's precise accounting:
 	 */
-	temp = (u64)nsec_to_clock_t(p->se.sum_exec_runtime);
-
 	if (total) {
-		temp *= utime;
-		do_div(temp, total);
+		runtime *= utime;
+		do_div(runtime, total);
 	}
-	utime = (clock_t)temp;
+	return (clock_t)runtime;
+}
 
-	return clock_t_to_cputime(utime);
+static cputime_t task_utime(struct task_struct *p)
+{
+	u64 runtime = (u64)nsec_to_clock_t(p->se.sum_exec_runtime);
+
+	return clock_t_to_cputime(__task_utime(p, runtime));
 }
 
 static cputime_t task_stime(struct task_struct *p)
 {
-	clock_t stime;
+	u64 runtime = (u64)nsec_to_clock_t(p->se.sum_exec_runtime);
 
 	/*
 	 * Use CFS's precise accounting. (we subtract utime from
 	 * the total, to make sure the total observed by userspace
 	 * grows monotonically - apps rely on that):
 	 */
-	stime = nsec_to_clock_t(p->se.sum_exec_runtime) -
-			cputime_to_clock_t(task_utime(p));
-
-	return clock_t_to_cputime(stime);
+	return clock_t_to_cputime(runtime - __task_utime(p, runtime));
 }
 #endif
 

-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
top displaying 9999% CPU usage, Frans Pop, (Wed Oct 3, 8:33 am)
Re: top displaying 9999% CPU usage, Alexander E. Patrakov, (Wed Oct 3, 9:03 am)
Re: top displaying 9999% CPU usage, Frans Pop, (Wed Oct 3, 10:04 am)
Re: top displaying 9999% CPU usage, Ilpo Järvinen, (Wed Oct 3, 10:43 am)
Re: top displaying 9999% CPU usage, Ilpo Järvinen, (Wed Oct 3, 10:51 am)
Re: Decreasing stime running confuses top, Chuck Ebbert, (Thu Oct 4, 3:32 pm)
Re: Decreasing stime running confuses top, Christian Borntraeger, (Thu Oct 4, 4:00 pm)
Re: Decreasing stime running confuses top, Chuck Ebbert, (Thu Oct 4, 4:21 pm)
[PATCH for testing] Re: Decreasing stime running confuses top, Christian Borntraeger, (Thu Oct 4, 5:10 pm)
Re: [PATCH for testing] Re: Decreasing stime running confuse..., Christian Borntraeger, (Mon Oct 8, 12:49 pm)
Re: [PATCH for testing] Re: Decreasing stime running confuse..., Chuck Ebbert, (Thu Oct 4, 6:01 pm)
Re: [PATCH for testing] Re: Decreasing stime running confuse..., Christian Borntraeger, (Thu Oct 4, 6:31 pm)
Re: top displaying 9999% CPU usage, Jan Engelhardt, (Wed Oct 3, 8:52 am)