Skip to content

Commit d57af9b

Browse files
Michael Holzheutorvalds
authored andcommitted
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>
1 parent 3d9e0cf commit d57af9b

5 files changed

Lines changed: 21 additions & 23 deletions

File tree

‎arch/ia64/include/asm/cputime.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ typedef u64 cputime64_t;
5656
#define jiffies64_to_cputime64(__jif) ((__jif) * (NSEC_PER_SEC / HZ))
5757

5858
/*
59-
* Convert cputime <-> milliseconds
59+
* Convert cputime <-> microseconds
6060
*/
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)
6363

6464
/*
6565
* Convert cputime <-> seconds

‎arch/powerpc/include/asm/cputime.h‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,23 +124,23 @@ static inline u64 cputime64_to_jiffies64(const cputime_t ct)
124124
}
125125

126126
/*
127-
* Convert cputime <-> milliseconds
127+
* Convert cputime <-> microseconds
128128
*/
129129
extern u64 __cputime_msec_factor;
130130

131-
static inline unsigned long cputime_to_msecs(const cputime_t ct)
131+
static inline unsigned long cputime_to_usecs(const cputime_t ct)
132132
{
133-
return mulhdu(ct, __cputime_msec_factor);
133+
return mulhdu(ct, __cputime_msec_factor) * USEC_PER_MSEC;
134134
}
135135

136-
static inline cputime_t msecs_to_cputime(const unsigned long ms)
136+
static inline cputime_t usecs_to_cputime(const unsigned long us)
137137
{
138138
cputime_t ct;
139139
unsigned long sec;
140140

141141
/* have to be a little careful about overflow */
142-
ct = ms % 1000;
143-
sec = ms / 1000;
142+
ct = us % 1000000;
143+
sec = us / 1000000;
144144
if (ct) {
145145
ct *= tb_ticks_per_sec;
146146
do_div(ct, 1000);

‎arch/s390/include/asm/cputime.h‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,18 @@ cputime64_to_jiffies64(cputime64_t cputime)
7373
}
7474

7575
/*
76-
* Convert cputime to milliseconds and back.
76+
* Convert cputime to microseconds and back.
7777
*/
7878
static inline unsigned int
79-
cputime_to_msecs(const cputime_t cputime)
79+
cputime_to_usecs(const cputime_t cputime)
8080
{
81-
return cputime_div(cputime, 4096000);
81+
return cputime_div(cputime, 4096);
8282
}
8383

8484
static inline cputime_t
85-
msecs_to_cputime(const unsigned int m)
85+
usecs_to_cputime(const unsigned int m)
8686
{
87-
return (cputime_t) m * 4096000;
87+
return (cputime_t) m * 4096;
8888
}
8989

9090
/*

‎include/asm-generic/cputime.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ typedef u64 cputime64_t;
3333

3434

3535
/*
36-
* Convert cputime to milliseconds and back.
36+
* Convert cputime to microseconds and back.
3737
*/
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);
4040

4141
/*
4242
* Convert cputime to seconds and back.

‎kernel/tsacct.c‎

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,10 @@ void bacct_add_tsk(struct taskstats *stats, struct task_struct *tsk)
6363
stats->ac_ppid = pid_alive(tsk) ?
6464
rcu_dereference(tsk->real_parent)->tgid : 0;
6565
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);
7270
stats->ac_minflt = tsk->min_flt;
7371
stats->ac_majflt = tsk->maj_flt;
7472

0 commit comments

Comments
 (0)