Messages in this thread Patch in this message | | | From | Frederic Weisbecker <> | Subject | [PATCH 4/9] sched/cputime: Support other fields on kcpustat_field() | Date | Wed, 6 Nov 2019 04:08:02 +0100 |
| |
Now that we support nice updates under vtime accounting, we can provide tickless values for kcpustat readers of user and guest time.
Signed-off-by: Frederic Weisbecker <frederic@kernel.org> Cc: Yauheni Kaliuta <yauheni.kaliuta@redhat.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Rik van Riel <riel@surriel.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Wanpeng Li <wanpengli@tencent.com> Cc: Ingo Molnar <mingo@kernel.org> --- kernel/sched/cputime.c | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-)
diff --git a/kernel/sched/cputime.c b/kernel/sched/cputime.c index e09194415c35..bf4b61f71194 100644 --- a/kernel/sched/cputime.c +++ b/kernel/sched/cputime.c @@ -1042,6 +1042,15 @@ void task_cputime(struct task_struct *t, u64 *utime, u64 *stime) } while (read_seqcount_retry(&vtime->seqcount, seq)); } +static u64 kcpustat_user_vtime(struct vtime *vtime) +{ + if (vtime->state == VTIME_USER) + return vtime->utime + vtime_delta(vtime); + else if (vtime->state == VTIME_GUEST) + return vtime->gtime + vtime_delta(vtime); + return 0; +} + static int kcpustat_field_vtime(u64 *cpustat, struct vtime *vtime, enum cpu_usage_stat usage, @@ -1076,9 +1085,30 @@ static int kcpustat_field_vtime(u64 *cpustat, *val = cpustat[usage]; - if (vtime->state == VTIME_SYS) - *val += vtime->stime + vtime_delta(vtime); - + switch (usage) { + case CPUTIME_SYSTEM: + if (vtime->state == VTIME_SYS) + *val += vtime->stime + vtime_delta(vtime); + break; + case CPUTIME_USER: + if (!vtime->nice) + *val += kcpustat_user_vtime(vtime); + break; + case CPUTIME_NICE: + if (vtime->nice) + *val += kcpustat_user_vtime(vtime); + break; + case CPUTIME_GUEST: + if (vtime->state == VTIME_GUEST && !vtime->nice) + *val += vtime->gtime + vtime_delta(vtime); + break; + case CPUTIME_GUEST_NICE: + if (vtime->state == VTIME_GUEST && vtime->nice) + *val += vtime->gtime + vtime_delta(vtime); + break; + default: + break; + } } while (read_seqcount_retry(&vtime->seqcount, seq)); return 0; @@ -1095,10 +1125,6 @@ u64 kcpustat_field(struct kernel_cpustat *kcpustat, if (!vtime_accounting_enabled_cpu(cpu)) return cpustat[usage]; - /* Only support sys vtime for now */ - if (usage != CPUTIME_SYSTEM) - return cpustat[usage]; - rq = cpu_rq(cpu); for (;;) { -- 2.23.0
| |