taskstats: use real microsecond granularity for CPU times
authorMichael Holzheu <holzheu@linux.vnet.ibm.com>
Wed, 27 Oct 2010 22:34:45 +0000 (15:34 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 28 Oct 2010 01:03:17 +0000 (18:03 -0700)
The taskstats interface uses microsecond granularity for the user and
system time values.  The conversion from cputime to the taskstats values
uses the cputime_to_msecs primitive which effectively limits the
granularity to milliseconds.  Add the cputime_to_usecs primitive for
architectures that have better, more precise CPU time values.  Remove
cputime_to_msecs primitive because there are no more users left.

Signed-off-by: Michael Holzheu <holzheu@linux.vnet.ibm.com>
Acked-by: Balbir Singh <balbir@linux.vnet.ibm.com>
Cc: Luck Tony <tony.luck@intel.com>
Cc: Shailabh Nagar <nagar1234@in.ibm.com>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Heiko Carstens <heiko.carstens@de.ibm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Shailabh Nagar <nagar@us.ibm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
arch/ia64/include/asm/cputime.h
arch/powerpc/include/asm/cputime.h
arch/s390/include/asm/cputime.h
include/asm-generic/cputime.h
kernel/tsacct.c

index 7fa8a859466017410a58e2f483721623cf1d6694..6073b187528a26a8ac16826aa98cd7986c5724ed 100644 (file)
@@ -56,10 +56,10 @@ typedef u64 cputime64_t;
 #define jiffies64_to_cputime64(__jif)  ((__jif) * (NSEC_PER_SEC / HZ))
 
 /*
 #define jiffies64_to_cputime64(__jif)  ((__jif) * (NSEC_PER_SEC / HZ))
 
 /*
- * Convert cputime <-> milliseconds
+ * Convert cputime <-> microseconds
  */
  */
-#define cputime_to_msecs(__ct)         ((__ct) / NSEC_PER_MSEC)
-#define msecs_to_cputime(__msecs)      ((__msecs) * NSEC_PER_MSEC)
+#define cputime_to_usecs(__ct)         ((__ct) / NSEC_PER_USEC)
+#define usecs_to_cputime(__usecs)      ((__usecs) * NSEC_PER_USEC)
 
 /*
  * Convert cputime <-> seconds
 
 /*
  * Convert cputime <-> seconds
index 8bdc6a9e57733109eb75ec47d664cd37be22e94f..1cf20bdfbecaada5bb2b88d439d776c32af2558c 100644 (file)
@@ -124,23 +124,23 @@ static inline u64 cputime64_to_jiffies64(const cputime_t ct)
 }
 
 /*
 }
 
 /*
- * Convert cputime <-> milliseconds
+ * Convert cputime <-> microseconds
  */
 extern u64 __cputime_msec_factor;
 
  */
 extern u64 __cputime_msec_factor;
 
-static inline unsigned long cputime_to_msecs(const cputime_t ct)
+static inline unsigned long cputime_to_usecs(const cputime_t ct)
 {
 {
-       return mulhdu(ct, __cputime_msec_factor);
+       return mulhdu(ct, __cputime_msec_factor) * USEC_PER_MSEC;
 }
 
 }
 
-static inline cputime_t msecs_to_cputime(const unsigned long ms)
+static inline cputime_t usecs_to_cputime(const unsigned long us)
 {
        cputime_t ct;
        unsigned long sec;
 
        /* have to be a little careful about overflow */
 {
        cputime_t ct;
        unsigned long sec;
 
        /* have to be a little careful about overflow */
-       ct = ms % 1000;
-       sec = ms / 1000;
+       ct = us % 1000000;
+       sec = us / 1000000;
        if (ct) {
                ct *= tb_ticks_per_sec;
                do_div(ct, 1000);
        if (ct) {
                ct *= tb_ticks_per_sec;
                do_div(ct, 1000);
index 8b1a52a137c5b2558bd9223cf87ac16708aae7c7..40e2ab0fa3f0bbb4416e10d3c5314a7f1e03dd16 100644 (file)
@@ -73,18 +73,18 @@ cputime64_to_jiffies64(cputime64_t cputime)
 }
 
 /*
 }
 
 /*
- * Convert cputime to milliseconds and back.
+ * Convert cputime to microseconds and back.
  */
 static inline unsigned int
  */
 static inline unsigned int
-cputime_to_msecs(const cputime_t cputime)
+cputime_to_usecs(const cputime_t cputime)
 {
 {
-       return cputime_div(cputime, 4096000);
+       return cputime_div(cputime, 4096);
 }
 
 static inline cputime_t
 }
 
 static inline cputime_t
-msecs_to_cputime(const unsigned int m)
+usecs_to_cputime(const unsigned int m)
 {
 {
-       return (cputime_t) m * 4096000;
+       return (cputime_t) m * 4096;
 }
 
 /*
 }
 
 /*
index ca0f239f0e13cec272e373dabec7d4c4b6bc941c..2bcc5c7c22a6329752c666f409a1a2abefbbc430 100644 (file)
@@ -33,10 +33,10 @@ typedef u64 cputime64_t;
 
 
 /*
 
 
 /*
- * Convert cputime to milliseconds and back.
+ * Convert cputime to microseconds and back.
  */
  */
-#define cputime_to_msecs(__ct)         jiffies_to_msecs(__ct)
-#define msecs_to_cputime(__msecs)      msecs_to_jiffies(__msecs)
+#define cputime_to_usecs(__ct)         jiffies_to_usecs(__ct);
+#define usecs_to_cputime(__msecs)      usecs_to_jiffies(__msecs);
 
 /*
  * Convert cputime to seconds and back.
 
 /*
  * Convert cputime to seconds and back.
index 0a67e041edf82ee3f614959c2643713063e5739b..24dc60d9fa1f2c09de3dcb12ac33e51a7fd22562 100644 (file)
@@ -63,12 +63,10 @@ void bacct_add_tsk(struct taskstats *stats, struct task_struct *tsk)
        stats->ac_ppid   = pid_alive(tsk) ?
                                rcu_dereference(tsk->real_parent)->tgid : 0;
        rcu_read_unlock();
        stats->ac_ppid   = pid_alive(tsk) ?
                                rcu_dereference(tsk->real_parent)->tgid : 0;
        rcu_read_unlock();
-       stats->ac_utime  = cputime_to_msecs(tsk->utime) * USEC_PER_MSEC;
-       stats->ac_stime  = cputime_to_msecs(tsk->stime) * USEC_PER_MSEC;
-       stats->ac_utimescaled =
-               cputime_to_msecs(tsk->utimescaled) * USEC_PER_MSEC;
-       stats->ac_stimescaled =
-               cputime_to_msecs(tsk->stimescaled) * USEC_PER_MSEC;
+       stats->ac_utime = cputime_to_usecs(tsk->utime);
+       stats->ac_stime = cputime_to_usecs(tsk->stime);
+       stats->ac_utimescaled = cputime_to_usecs(tsk->utimescaled);
+       stats->ac_stimescaled = cputime_to_usecs(tsk->stimescaled);
        stats->ac_minflt = tsk->min_flt;
        stats->ac_majflt = tsk->maj_flt;
 
        stats->ac_minflt = tsk->min_flt;
        stats->ac_majflt = tsk->maj_flt;