Skip to content

Commit a1cecf2

Browse files
fweisbecingomolnar
authored andcommitted
sched/cputime: Introduce special task_cputime_t() API to return old-typed cputime
This API returns a task's cputime in cputime_t in order to ease the conversion of cputime internals to use nsecs units instead. Blindly converting all cputime readers to use this API now will later let us convert more smoothly and step by step all these places to use the new nsec based cputime. Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Fenghua Yu <fenghua.yu@intel.com> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Rik van Riel <riel@redhat.com> Cc: Stanislaw Gruszka <sgruszka@redhat.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Tony Luck <tony.luck@intel.com> Cc: Wanpeng Li <wanpeng.li@hotmail.com> Link: http://lkml.kernel.org/r/1485832191-26889-7-git-send-email-fweisbec@gmail.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
1 parent 16a6d9b commit a1cecf2

12 files changed

Lines changed: 70 additions & 44 deletions

File tree

‎arch/alpha/kernel/osf_sys.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1154,7 +1154,7 @@ SYSCALL_DEFINE2(osf_getrusage, int, who, struct rusage32 __user *, ru)
11541154
memset(&r, 0, sizeof(r));
11551155
switch (who) {
11561156
case RUSAGE_SELF:
1157-
task_cputime(current, &utime, &stime);
1157+
task_cputime_t(current, &utime, &stime);
11581158
utime_jiffies = cputime_to_jiffies(utime);
11591159
stime_jiffies = cputime_to_jiffies(stime);
11601160
jiffies_to_timeval32(utime_jiffies, &r.ru_utime);

‎arch/x86/kernel/apm_32.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -913,7 +913,7 @@ static int apm_cpu_idle(struct cpuidle_device *dev,
913913
unsigned int bucket;
914914

915915
recalc:
916-
task_cputime(current, &utime, &stime);
916+
task_cputime_t(current, &utime, &stime);
917917
if (jiffies_since_last_check > IDLE_CALC_LIMIT) {
918918
use_apm_idle = 0;
919919
} else if (jiffies_since_last_check > idle_period) {

‎drivers/isdn/mISDN/stack.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ mISDNStackd(void *data)
306306
"msg %d sleep %d stopped\n",
307307
dev_name(&st->dev->dev), st->msg_cnt, st->sleep_cnt,
308308
st->stopped_cnt);
309-
task_cputime(st->thread, &utime, &stime);
309+
task_cputime_t(st->thread, &utime, &stime);
310310
printk(KERN_DEBUG
311311
"mISDNStackd daemon for %s utime(%ld) stime(%ld)\n",
312312
dev_name(&st->dev->dev), utime, stime);

‎fs/binfmt_elf.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,19 +1421,19 @@ static void fill_prstatus(struct elf_prstatus *prstatus,
14211421
prstatus->pr_pgrp = task_pgrp_vnr(p);
14221422
prstatus->pr_sid = task_session_vnr(p);
14231423
if (thread_group_leader(p)) {
1424-
struct task_cputime cputime;
1424+
struct task_cputime_t cputime;
14251425

14261426
/*
14271427
* This is the record for the group leader. It shows the
14281428
* group-wide total, not its individual thread total.
14291429
*/
1430-
thread_group_cputime(p, &cputime);
1430+
thread_group_cputime_t(p, &cputime);
14311431
cputime_to_timeval(cputime.utime, &prstatus->pr_utime);
14321432
cputime_to_timeval(cputime.stime, &prstatus->pr_stime);
14331433
} else {
14341434
cputime_t utime, stime;
14351435

1436-
task_cputime(p, &utime, &stime);
1436+
task_cputime_t(p, &utime, &stime);
14371437
cputime_to_timeval(utime, &prstatus->pr_utime);
14381438
cputime_to_timeval(stime, &prstatus->pr_stime);
14391439
}

‎fs/binfmt_elf_fdpic.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,19 +1342,19 @@ static void fill_prstatus(struct elf_prstatus *prstatus,
13421342
prstatus->pr_pgrp = task_pgrp_vnr(p);
13431343
prstatus->pr_sid = task_session_vnr(p);
13441344
if (thread_group_leader(p)) {
1345-
struct task_cputime cputime;
1345+
struct task_cputime_t cputime;
13461346

13471347
/*
13481348
* This is the record for the group leader. It shows the
13491349
* group-wide total, not its individual thread total.
13501350
*/
1351-
thread_group_cputime(p, &cputime);
1351+
thread_group_cputime_t(p, &cputime);
13521352
cputime_to_timeval(cputime.utime, &prstatus->pr_utime);
13531353
cputime_to_timeval(cputime.stime, &prstatus->pr_stime);
13541354
} else {
13551355
cputime_t utime, stime;
13561356

1357-
task_cputime(p, &utime, &stime);
1357+
task_cputime_t(p, &utime, &stime);
13581358
cputime_to_timeval(utime, &prstatus->pr_utime);
13591359
cputime_to_timeval(stime, &prstatus->pr_stime);
13601360
}

‎include/linux/sched.h‎

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,13 @@ struct task_cputime {
615615
unsigned long long sum_exec_runtime;
616616
};
617617

618+
/* Temporary type to ease cputime_t to nsecs conversion */
619+
struct task_cputime_t {
620+
cputime_t utime;
621+
cputime_t stime;
622+
unsigned long long sum_exec_runtime;
623+
};
624+
618625
/* Alternate field names when used to cache expirations. */
619626
#define virt_exp utime
620627
#define prof_exp stime
@@ -748,7 +755,7 @@ struct signal_struct {
748755
struct thread_group_cputimer cputimer;
749756

750757
/* Earliest-expiration cache. */
751-
struct task_cputime cputime_expires;
758+
struct task_cputime_t cputime_expires;
752759

753760
#ifdef CONFIG_NO_HZ_FULL
754761
atomic_t tick_dep_mask;
@@ -1682,7 +1689,7 @@ struct task_struct {
16821689
/* mm fault and swap info: this can arguably be seen as either mm-specific or thread-specific */
16831690
unsigned long min_flt, maj_flt;
16841691

1685-
struct task_cputime cputime_expires;
1692+
struct task_cputime_t cputime_expires;
16861693
struct list_head cpu_timers[3];
16871694

16881695
/* process credentials */
@@ -2286,6 +2293,19 @@ static inline void task_cputime_scaled(struct task_struct *t,
22862293
}
22872294
#endif
22882295

2296+
static inline void task_cputime_t(struct task_struct *t,
2297+
cputime_t *utime, cputime_t *stime)
2298+
{
2299+
task_cputime(t, utime, stime);
2300+
}
2301+
2302+
static inline void task_cputime_t_scaled(struct task_struct *t,
2303+
cputime_t *utimescaled,
2304+
cputime_t *stimescaled)
2305+
{
2306+
task_cputime_scaled(t, utimescaled, stimescaled);
2307+
}
2308+
22892309
extern void task_cputime_adjusted(struct task_struct *p, cputime_t *ut, cputime_t *st);
22902310
extern void thread_group_cputime_adjusted(struct task_struct *p, cputime_t *ut, cputime_t *st);
22912311

@@ -3499,7 +3519,13 @@ static __always_inline bool need_resched(void)
34993519
* Thread group CPU time accounting.
35003520
*/
35013521
void thread_group_cputime(struct task_struct *tsk, struct task_cputime *times);
3502-
void thread_group_cputimer(struct task_struct *tsk, struct task_cputime *times);
3522+
void thread_group_cputimer(struct task_struct *tsk, struct task_cputime_t *times);
3523+
3524+
static inline void thread_group_cputime_t(struct task_struct *tsk,
3525+
struct task_cputime_t *times)
3526+
{
3527+
thread_group_cputime(tsk, (struct task_cputime *)times);
3528+
}
35033529

35043530
/*
35053531
* Reevaluate whether the task has signals pending delivery.

‎kernel/acct.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ void acct_collect(long exitcode, int group_dead)
559559
pacct->ac_flag |= ACORE;
560560
if (current->flags & PF_SIGNALED)
561561
pacct->ac_flag |= AXSIG;
562-
task_cputime(current, &utime, &stime);
562+
task_cputime_t(current, &utime, &stime);
563563
pacct->ac_utime += utime;
564564
pacct->ac_stime += stime;
565565
pacct->ac_minflt += current->min_flt;

‎kernel/delayacct.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ int __delayacct_add_tsk(struct taskstats *d, struct task_struct *tsk)
8787
unsigned long flags, t1;
8888
s64 tmp;
8989

90-
task_cputime(tsk, &utime, &stime);
90+
task_cputime_t(tsk, &utime, &stime);
9191
tmp = (s64)d->cpu_run_real_total;
9292
tmp += cputime_to_nsecs(utime + stime);
9393
d->cpu_run_real_total = (tmp < (s64)d->cpu_run_real_total) ? 0 : tmp;
9494

95-
task_cputime_scaled(tsk, &utimescaled, &stimescaled);
95+
task_cputime_t_scaled(tsk, &utimescaled, &stimescaled);
9696
tmp = (s64)d->cpu_scaled_run_real_total;
9797
tmp += cputime_to_nsecs(utimescaled + stimescaled);
9898
d->cpu_scaled_run_real_total =

‎kernel/signal.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,7 +1619,7 @@ bool do_notify_parent(struct task_struct *tsk, int sig)
16191619
task_uid(tsk));
16201620
rcu_read_unlock();
16211621

1622-
task_cputime(tsk, &utime, &stime);
1622+
task_cputime_t(tsk, &utime, &stime);
16231623
info.si_utime = cputime_to_clock_t(utime + tsk->signal->utime);
16241624
info.si_stime = cputime_to_clock_t(stime + tsk->signal->stime);
16251625

@@ -1704,7 +1704,7 @@ static void do_notify_parent_cldstop(struct task_struct *tsk,
17041704
info.si_uid = from_kuid_munged(task_cred_xxx(parent, user_ns), task_uid(tsk));
17051705
rcu_read_unlock();
17061706

1707-
task_cputime(tsk, &utime, &stime);
1707+
task_cputime_t(tsk, &utime, &stime);
17081708
info.si_utime = cputime_to_clock_t(utime);
17091709
info.si_stime = cputime_to_clock_t(stime);
17101710

‎kernel/time/itimer.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ static void get_cpu_itimer(struct task_struct *tsk, unsigned int clock_id,
5353
cval = it->expires;
5454
cinterval = it->incr;
5555
if (cval) {
56-
struct task_cputime cputime;
56+
struct task_cputime_t cputime;
5757
cputime_t t;
5858

5959
thread_group_cputimer(tsk, &cputime);

0 commit comments

Comments
 (0)