sched/cputime: Add vtime idle task state
Record idle as a VTIME state instead of guessing it from VTIME_SYS and is_idle_task(). This is going to simplify the cputime read side especially as its state machine is going to further expand in order to fully support kcpustat on nohz_full. Signed-off-by: Frederic Weisbecker <frederic@kernel.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Cc: Jacek Anaszewski <jacek.anaszewski@gmail.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Pavel Machek <pavel@ucw.cz> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Rafael J . Wysocki <rjw@rjwysocki.net> Cc: Rik van Riel <riel@surriel.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Viresh Kumar <viresh.kumar@linaro.org> Cc: Wanpeng Li <wanpengli@tencent.com> Cc: Yauheni Kaliuta <yauheni.kaliuta@redhat.com> Link: https://lkml.kernel.org/r/20191016025700.31277-3-frederic@kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org>
This commit is contained in:

committed by
Ingo Molnar

parent
802f4a827f
commit
14faf6fcac
@@ -249,10 +249,12 @@ struct prev_cputime {
|
|||||||
enum vtime_state {
|
enum vtime_state {
|
||||||
/* Task is sleeping or running in a CPU with VTIME inactive: */
|
/* Task is sleeping or running in a CPU with VTIME inactive: */
|
||||||
VTIME_INACTIVE = 0,
|
VTIME_INACTIVE = 0,
|
||||||
/* Task runs in userspace in a CPU with VTIME active: */
|
/* Task is idle */
|
||||||
VTIME_USER,
|
VTIME_IDLE,
|
||||||
/* Task runs in kernelspace in a CPU with VTIME active: */
|
/* Task runs in kernelspace in a CPU with VTIME active: */
|
||||||
VTIME_SYS,
|
VTIME_SYS,
|
||||||
|
/* Task runs in userspace in a CPU with VTIME active: */
|
||||||
|
VTIME_USER,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct vtime {
|
struct vtime {
|
||||||
|
@@ -813,7 +813,7 @@ void vtime_task_switch_generic(struct task_struct *prev)
|
|||||||
struct vtime *vtime = &prev->vtime;
|
struct vtime *vtime = &prev->vtime;
|
||||||
|
|
||||||
write_seqcount_begin(&vtime->seqcount);
|
write_seqcount_begin(&vtime->seqcount);
|
||||||
if (is_idle_task(prev))
|
if (vtime->state == VTIME_IDLE)
|
||||||
vtime_account_idle(prev);
|
vtime_account_idle(prev);
|
||||||
else
|
else
|
||||||
__vtime_account_kernel(prev, vtime);
|
__vtime_account_kernel(prev, vtime);
|
||||||
@@ -824,7 +824,10 @@ void vtime_task_switch_generic(struct task_struct *prev)
|
|||||||
vtime = ¤t->vtime;
|
vtime = ¤t->vtime;
|
||||||
|
|
||||||
write_seqcount_begin(&vtime->seqcount);
|
write_seqcount_begin(&vtime->seqcount);
|
||||||
vtime->state = VTIME_SYS;
|
if (is_idle_task(current))
|
||||||
|
vtime->state = VTIME_IDLE;
|
||||||
|
else
|
||||||
|
vtime->state = VTIME_SYS;
|
||||||
vtime->starttime = sched_clock();
|
vtime->starttime = sched_clock();
|
||||||
vtime->cpu = smp_processor_id();
|
vtime->cpu = smp_processor_id();
|
||||||
write_seqcount_end(&vtime->seqcount);
|
write_seqcount_end(&vtime->seqcount);
|
||||||
@@ -837,7 +840,7 @@ void vtime_init_idle(struct task_struct *t, int cpu)
|
|||||||
|
|
||||||
local_irq_save(flags);
|
local_irq_save(flags);
|
||||||
write_seqcount_begin(&vtime->seqcount);
|
write_seqcount_begin(&vtime->seqcount);
|
||||||
vtime->state = VTIME_SYS;
|
vtime->state = VTIME_IDLE;
|
||||||
vtime->starttime = sched_clock();
|
vtime->starttime = sched_clock();
|
||||||
vtime->cpu = cpu;
|
vtime->cpu = cpu;
|
||||||
write_seqcount_end(&vtime->seqcount);
|
write_seqcount_end(&vtime->seqcount);
|
||||||
@@ -888,8 +891,8 @@ void task_cputime(struct task_struct *t, u64 *utime, u64 *stime)
|
|||||||
*utime = t->utime;
|
*utime = t->utime;
|
||||||
*stime = t->stime;
|
*stime = t->stime;
|
||||||
|
|
||||||
/* Task is sleeping, nothing to add */
|
/* Task is sleeping or idle, nothing to add */
|
||||||
if (vtime->state == VTIME_INACTIVE || is_idle_task(t))
|
if (vtime->state < VTIME_SYS)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
delta = vtime_delta(vtime);
|
delta = vtime_delta(vtime);
|
||||||
|
Reference in New Issue
Block a user