Commit d57af9b2142f31a39dcfdeb30776baadfc802827

Authored by Michael Holzheu
Committed by Linus Torvalds
1 parent 3d9e0cf1fe

taskstats: use real microsecond granularity for CPU times

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>

Showing 5 changed files with 21 additions and 23 deletions Side-by-side Diff

arch/ia64/include/asm/cputime.h
... ... @@ -56,10 +56,10 @@
56 56 #define jiffies64_to_cputime64(__jif) ((__jif) * (NSEC_PER_SEC / HZ))
57 57  
58 58 /*
59   - * Convert cputime <-> milliseconds
  59 + * Convert cputime <-> microseconds
60 60 */
61   -#define cputime_to_msecs(__ct) ((__ct) / NSEC_PER_MSEC)
62   -#define msecs_to_cputime(__msecs) ((__msecs) * NSEC_PER_MSEC)
  61 +#define cputime_to_usecs(__ct) ((__ct) / NSEC_PER_USEC)
  62 +#define usecs_to_cputime(__usecs) ((__usecs) * NSEC_PER_USEC)
63 63  
64 64 /*
65 65 * Convert cputime <-> seconds
arch/powerpc/include/asm/cputime.h
... ... @@ -124,23 +124,23 @@
124 124 }
125 125  
126 126 /*
127   - * Convert cputime <-> milliseconds
  127 + * Convert cputime <-> microseconds
128 128 */
129 129 extern u64 __cputime_msec_factor;
130 130  
131   -static inline unsigned long cputime_to_msecs(const cputime_t ct)
  131 +static inline unsigned long cputime_to_usecs(const cputime_t ct)
132 132 {
133   - return mulhdu(ct, __cputime_msec_factor);
  133 + return mulhdu(ct, __cputime_msec_factor) * USEC_PER_MSEC;
134 134 }
135 135  
136   -static inline cputime_t msecs_to_cputime(const unsigned long ms)
  136 +static inline cputime_t usecs_to_cputime(const unsigned long us)
137 137 {
138 138 cputime_t ct;
139 139 unsigned long sec;
140 140  
141 141 /* have to be a little careful about overflow */
142   - ct = ms % 1000;
143   - sec = ms / 1000;
  142 + ct = us % 1000000;
  143 + sec = us / 1000000;
144 144 if (ct) {
145 145 ct *= tb_ticks_per_sec;
146 146 do_div(ct, 1000);
arch/s390/include/asm/cputime.h
... ... @@ -73,18 +73,18 @@
73 73 }
74 74  
75 75 /*
76   - * Convert cputime to milliseconds and back.
  76 + * Convert cputime to microseconds and back.
77 77 */
78 78 static inline unsigned int
79   -cputime_to_msecs(const cputime_t cputime)
  79 +cputime_to_usecs(const cputime_t cputime)
80 80 {
81   - return cputime_div(cputime, 4096000);
  81 + return cputime_div(cputime, 4096);
82 82 }
83 83  
84 84 static inline cputime_t
85   -msecs_to_cputime(const unsigned int m)
  85 +usecs_to_cputime(const unsigned int m)
86 86 {
87   - return (cputime_t) m * 4096000;
  87 + return (cputime_t) m * 4096;
88 88 }
89 89  
90 90 /*
include/asm-generic/cputime.h
... ... @@ -33,10 +33,10 @@
33 33  
34 34  
35 35 /*
36   - * Convert cputime to milliseconds and back.
  36 + * Convert cputime to microseconds and back.
37 37 */
38   -#define cputime_to_msecs(__ct) jiffies_to_msecs(__ct)
39   -#define msecs_to_cputime(__msecs) msecs_to_jiffies(__msecs)
  38 +#define cputime_to_usecs(__ct) jiffies_to_usecs(__ct);
  39 +#define usecs_to_cputime(__msecs) usecs_to_jiffies(__msecs);
40 40  
41 41 /*
42 42 * Convert cputime to seconds and back.
... ... @@ -63,12 +63,10 @@
63 63 stats->ac_ppid = pid_alive(tsk) ?
64 64 rcu_dereference(tsk->real_parent)->tgid : 0;
65 65 rcu_read_unlock();
66   - stats->ac_utime = cputime_to_msecs(tsk->utime) * USEC_PER_MSEC;
67   - stats->ac_stime = cputime_to_msecs(tsk->stime) * USEC_PER_MSEC;
68   - stats->ac_utimescaled =
69   - cputime_to_msecs(tsk->utimescaled) * USEC_PER_MSEC;
70   - stats->ac_stimescaled =
71   - cputime_to_msecs(tsk->stimescaled) * USEC_PER_MSEC;
  66 + stats->ac_utime = cputime_to_usecs(tsk->utime);
  67 + stats->ac_stime = cputime_to_usecs(tsk->stime);
  68 + stats->ac_utimescaled = cputime_to_usecs(tsk->utimescaled);
  69 + stats->ac_stimescaled = cputime_to_usecs(tsk->stimescaled);
72 70 stats->ac_minflt = tsk->min_flt;
73 71 stats->ac_majflt = tsk->maj_flt;
74 72