Gitweb:     
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=b27f03d4bdc145a09fb7b0c0e004b29f1ee555fa
Commit:     b27f03d4bdc145a09fb7b0c0e004b29f1ee555fa
Parent:     1b9f19c2125dd1021b9327111dc40b14b557ee12
Author:     Ingo Molnar <[EMAIL PROTECTED]>
AuthorDate: Mon Jul 9 18:51:59 2007 +0200
Committer:  Ingo Molnar <[EMAIL PROTECTED]>
CommitDate: Mon Jul 9 18:51:59 2007 +0200

    sched: make use of precise accounting for /proc task stats
    
    make use of CFS's precise accounting to drive /proc/<pid>/stat statistics.
    
    this code was co-authored by:
    
     Balbir Singh <[EMAIL PROTECTED]>
     Dmitry Adamushko <[EMAIL PROTECTED]>
     Ingo Molnar <[EMAIL PROTECTED]>
    
    Signed-off-by: Ingo Molnar <[EMAIL PROTECTED]>
    Signed-off-by: Dmitry Adamushko <[EMAIL PROTECTED]>
---
 fs/proc/array.c |   57 +++++++++++++++++++++++++++++++++++++++++++++---------
 1 files changed, 47 insertions(+), 10 deletions(-)

diff --git a/fs/proc/array.c b/fs/proc/array.c
index 3df6443..98e78e2 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -310,6 +310,41 @@ int proc_pid_status(struct task_struct *task, char * 
buffer)
        return buffer - orig;
 }
 
+static clock_t task_utime(struct task_struct *p)
+{
+       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);
+       }
+       utime = (clock_t)temp;
+
+       return utime;
+}
+
+static clock_t task_stime(struct task_struct *p)
+{
+       clock_t stime = cputime_to_clock_t(p->stime);
+
+       /*
+        * 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) - task_utime(p);
+
+       return stime;
+}
+
+
 static int do_task_stat(struct task_struct *task, char * buffer, int whole)
 {
        unsigned long vsize, eip, esp, wchan = ~0UL;
@@ -324,7 +359,8 @@ static int do_task_stat(struct task_struct *task, char * 
buffer, int whole)
        unsigned long long start_time;
        unsigned long cmin_flt = 0, cmaj_flt = 0;
        unsigned long  min_flt = 0,  maj_flt = 0;
-       cputime_t cutime, cstime, utime, stime;
+       cputime_t cutime, cstime;
+       clock_t utime, stime;
        unsigned long rsslim = 0;
        char tcomm[sizeof(task->comm)];
        unsigned long flags;
@@ -342,7 +378,8 @@ static int do_task_stat(struct task_struct *task, char * 
buffer, int whole)
 
        sigemptyset(&sigign);
        sigemptyset(&sigcatch);
-       cutime = cstime = utime = stime = cputime_zero;
+       cutime = cstime = cputime_zero;
+       utime = stime = 0;
 
        rcu_read_lock();
        if (lock_task_sighand(task, &flags)) {
@@ -368,15 +405,15 @@ static int do_task_stat(struct task_struct *task, char * 
buffer, int whole)
                        do {
                                min_flt += t->min_flt;
                                maj_flt += t->maj_flt;
-                               utime = cputime_add(utime, t->utime);
-                               stime = cputime_add(stime, t->stime);
+                               utime += task_utime(t);
+                               stime += task_stime(t);
                                t = next_thread(t);
                        } while (t != task);
 
                        min_flt += sig->min_flt;
                        maj_flt += sig->maj_flt;
-                       utime = cputime_add(utime, sig->utime);
-                       stime = cputime_add(stime, sig->stime);
+                       utime += cputime_to_clock_t(sig->utime);
+                       stime += cputime_to_clock_t(sig->stime);
                }
 
                sid = signal_session(sig);
@@ -392,8 +429,8 @@ static int do_task_stat(struct task_struct *task, char * 
buffer, int whole)
        if (!whole) {
                min_flt = task->min_flt;
                maj_flt = task->maj_flt;
-               utime = task->utime;
-               stime = task->stime;
+               utime = task_utime(task);
+               stime = task_stime(task);
        }
 
        /* scale priority and nice values from timeslices to -20..20 */
@@ -424,8 +461,8 @@ static int do_task_stat(struct task_struct *task, char * 
buffer, int whole)
                cmin_flt,
                maj_flt,
                cmaj_flt,
-               cputime_to_clock_t(utime),
-               cputime_to_clock_t(stime),
+               utime,
+               stime,
                cputime_to_clock_t(cutime),
                cputime_to_clock_t(cstime),
                priority,
-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to