sched/nohz: Make the rest of kcpustat vtime aware v2
Subsystems (5)
cover sched/nohz: Make the rest of kcpustat vtime aware v2
(See https://lore.kernel.org/lkml/[email protected]/
for the record)
After review from Peter, I eventually gave up with the idea of fixing the nice fields of kcpustat. Therefore if a nice update happens on a task while it runs on a nohz_full CPU, the whole cputime will be accounted under the nice value observed at accounting time, hence the possibility of a nice VS unnice kcpustat inacurrate distribution.
But that's a lesser evil compared to interrupting a nohz_full CPU, which would be required to fix that. Also users of nohz_full shouldn't care about nice at all since a single task is expected to run on the CPU.
git://git.kernel.org/pub/scm/linux/kernel/git/frederic/linux-dynticks.git
nohz/kcpustat-v4
HEAD: dd59f186dc21e164097f659b4d60815e232f9555
Thanks,
Frederic
---
Frederic Weisbecker (6):
sched/cputime: Support other fields on kcpustat_field() sched/vtime: Bring all-in-one kcpustat accessor for vtime fields
procfs: Use all-in-one vtime aware kcpustat accessor
cpufreq: Use vtime aware kcpustat accessors for user time
leds: Use all-in-one vtime aware kcpustat accessor
rackmeter: Use vtime aware kcpustat accessor
drivers/cpufreq/cpufreq.c | 13 ++- drivers/cpufreq/cpufreq_governor.c | 6 +- drivers/leds/trigger/ledtrig-activity.c | 9 +- drivers/macintosh/rack-meter.c | 7 +- fs/proc/stat.c | 20 ++-- include/linux/kernel_stat.h | 23 ++++ kernel/sched/cputime.c | 192 ++++++++++++++++++++++++++------ 7 files changed, 216 insertions(+), 54 deletions(-)
PATCH 1/6 sched/cputime: Support other fields on kcpustat_field()
Provide support for user, nice, guest and guest_nice fields through kcpustat_field().
Whether we account the delta to a nice or not nice field is decided on top of the nice value snapshot taken at the time we call kcpustat_field(). If the nice value of the task has been changed since the last vtime update, we may have inacurrate distribution of the nice VS unnice cputime.
However this is considered as a minor issue compared to the proper fix that would involve interrupting the target on nice updates, which is undesired on nohz_full CPUs.
--- kernel/sched/cputime.c | 53 +++++++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 11 deletions(-)
kernel/sched/cputime.c +42 -11
@@ -912,11 +912,21 @@ 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, +struct task_struct *tsk,enum cpu_usage_stat usage,int cpu,u64 *val) { +struct vtime *vtime = &tsk->vtime;unsigned int seq;int err;
@@ -946,9 +956,36 @@ static int kcpustat_field_vtime(u64 *cpustat, *val = cpustat[usage]; -if (vtime->state ==VTIME_SYS ) - *val += vtime->stime +vtime_delta (vtime); - +/* +* Nice VS unnice cputime accounting may be inaccurate if +* the nice value has changed since the last vtime update. +* But proper fix would involve interrupting target on nice +* updates which is a no go on nohz_full. +*/ +switch (usage) { +case CPUTIME_SYSTEM : +if (vtime->state ==VTIME_SYS ) + *val += vtime->stime +vtime_delta (vtime); +break ; +case CPUTIME_USER : +if (task_nice (tsk) <=0 ) + *val +=kcpustat_user_vtime (vtime); +break ; +case CPUTIME_NICE : +if (task_nice (tsk) >0 ) + *val +=kcpustat_user_vtime (vtime); +break ; +case CPUTIME_GUEST : +if (vtime->state ==VTIME_GUEST &&task_nice (tsk) <=0 ) + *val += vtime->gtime +vtime_delta (vtime); +break ; +case CPUTIME_GUEST_NICE : +if (vtime->state ==VTIME_GUEST &&task_nice (tsk) >0 ) + *val += vtime->gtime +vtime_delta (vtime); +break ; +default : +break ; + } }while (read_seqcount_retry (&vtime->seqcount, seq));return 0 ;
@@ -965,15 +1002,10 @@ 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 (;;) {struct task_struct *curr; -struct vtime *vtime;rcu_read_lock (); curr =rcu_dereference (rq->curr);
@@ -982,8 +1014,7 @@ u64 kcpustat_field(struct kernel_cpustat *kcpustat,return cpustat[usage]; } - vtime = &curr->vtime; - err =kcpustat_field_vtime (cpustat, vtime, usage, cpu, &val); + err =kcpustat_field_vtime (cpustat, curr, usage, cpu, &val);rcu_read_unlock ();if (!err)
Signature · 1 line
2.23.0
PATCH 2/6 sched/vtime: Bring all-in-one kcpustat accessor for vtime fields
In reply to Frederic WeisbeckerMany callsites want to fetch the values of system, user, user_nice, guest or guest_nice kcpustat fields altogether or at least a pair of these.
In that case calling kcpustat_field() for each requested field brings unecessary overhead when we could fetch all of them in a row.
So provide kcpustat_cputime() that fetches all vtime sensitive fields under the same RCU and seqcount block.
--- include/linux/kernel_stat.h | 23 ++++++ kernel/sched/cputime.c | 139 ++++++++++++++++++++++++++++++------ 2 files changed, 142 insertions(+), 20 deletions(-)
include/linux/kernel_stat.h +23 -0
@@ -78,15 +78,38 @@ static inline unsigned int kstat_cpu_irqs_sum(unsigned int cpu)return kstat_cpu (cpu).irqs_sum; } + +static inline void kcpustat_cputime_raw (u64 *cpustat,u64 *user,u64 *nice, +u64 *system,u64 *guest,u64 *guest_nice) +{ + *user = cpustat[CPUTIME_USER ]; + *nice = cpustat[CPUTIME_NICE ]; + *system = cpustat[CPUTIME_SYSTEM ]; + *guest = cpustat[CPUTIME_GUEST ]; + *guest_nice = cpustat[CPUTIME_GUEST_NICE ]; +} +#ifdef CONFIG_VIRT_CPU_ACCOUNTING_GEN extern u64 kcpustat_field (struct kernel_cpustat *kcpustat,enum cpu_usage_stat usage,int cpu); +extern void kcpustat_cputime (struct kernel_cpustat *kcpustat,int cpu, +u64 *user,u64 *nice,u64 *system, +u64 *guest,u64 *guest_nice);#else static inline u64 kcpustat_field (struct kernel_cpustat *kcpustat,enum cpu_usage_stat usage,int cpu) {return kcpustat->cpustat[usage]; } + +static inline void kcpustat_cputime (struct kernel_cpustat *kcpustat,int cpu, +u64 *user,u64 *nice,u64 *system, +u64 *guest,u64 *guest_nice) +{ +kcpustat_cputime_raw (kcpustat->cpustat, user, nice, + system, guest, guest_nice); +} +#endif extern void account_user_time (struct task_struct *,u64 );
kernel/sched/cputime.c +119 -20
155 lines not on this page · raw message
Signature · 1 line
2.23.0
PATCH 3/6 procfs: Use all-in-one vtime aware kcpustat accessor
In reply to Frederic WeisbeckerNow that we can read also user and guest time safely under vtime, use the relevant accessor to fix frozen kcpustat values on nohz_full CPUs.
--- fs/proc/stat.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-)
fs/proc/stat.c +10 -10
@@ -120,18 +120,21 @@ static int show_stat(struct seq_file *p, void *v)getboottime64 (&boottime);for_each_possible_cpu (i) { +u64 cpu_user, cpu_nice, cpu_sys, cpu_guest, cpu_guest_nice;struct kernel_cpustat *kcs = &kcpustat_cpu (i); - user += kcs->cpustat[CPUTIME_USER ]; - nice += kcs->cpustat[CPUTIME_NICE ]; - system +=kcpustat_field (kcs,CPUTIME_SYSTEM , i); +kcpustat_cputime (kcs, i, &cpu_user, &cpu_nice, + &cpu_sys, &cpu_guest, &cpu_guest_nice); + user += cpu_user; + nice += cpu_nice; + system += cpu_sys; idle +=get_idle_time (kcs, i); iowait +=get_iowait_time (kcs, i); irq += kcs->cpustat[CPUTIME_IRQ ]; softirq += kcs->cpustat[CPUTIME_SOFTIRQ ]; steal += kcs->cpustat[CPUTIME_STEAL ]; - guest += kcs->cpustat[CPUTIME_GUEST ]; - guest_nice += kcs->cpustat[CPUTIME_GUEST_NICE ]; + guest += cpu_guest; + guest_nice += guest_nice; sum +=kstat_cpu_irqs_sum (i); sum +=arch_irq_stat_cpu (i);
@@ -159,17 +162,14 @@ static int show_stat(struct seq_file *p, void *v)for_each_online_cpu (i) {struct kernel_cpustat *kcs = &kcpustat_cpu (i); +kcpustat_cputime (kcs, i, &user, &nice, + &system, &guest, &guest_nice);/* Copy values here to work around gcc-2.95.3, gcc-2.96 */ - user = kcs->cpustat[CPUTIME_USER ]; - nice = kcs->cpustat[CPUTIME_NICE ]; - system =kcpustat_field (kcs,CPUTIME_SYSTEM , i); idle =get_idle_time (kcs, i); iowait =get_iowait_time (kcs, i); irq = kcs->cpustat[CPUTIME_IRQ ]; softirq = kcs->cpustat[CPUTIME_SOFTIRQ ]; steal = kcs->cpustat[CPUTIME_STEAL ]; - guest = kcs->cpustat[CPUTIME_GUEST ]; - guest_nice = kcs->cpustat[CPUTIME_GUEST_NICE ];seq_printf (p,"cpu%d" , i);seq_put_decimal_ull (p," " ,nsec_to_clock_t (user));seq_put_decimal_ull (p," " ,nsec_to_clock_t (nice));
Signature · 1 line
2.23.0
PATCH 4/6 cpufreq: Use vtime aware kcpustat accessors for user time
In reply to Frederic WeisbeckerWe can now safely read user and guest kcpustat fields on nohz_full CPUs. Use the appropriate accessors.
--- drivers/cpufreq/cpufreq.c | 13 +++++++++---- drivers/cpufreq/cpufreq_governor.c | 6 +++--- 2 files changed, 12 insertions(+), 7 deletions(-)
drivers/cpufreq/cpufreq.c +9 -4
@@ -113,18 +113,23 @@ EXPORT_SYMBOL_GPL(get_governor_parent_kobj);static inline u64 get_cpu_idle_time_jiffy (unsigned int cpu,u64 *wall) { -u64 idle_time; +struct kernel_cpustat *kcpustat = &kcpustat_cpu (cpu); +u64 user, nice, sys, guest, guest_nice;u64 cur_wall_time; +u64 idle_time;u64 busy_time; cur_wall_time =jiffies64_to_nsecs (get_jiffies_64 ()); - busy_time =kcpustat_cpu (cpu).cpustat[CPUTIME_USER ]; - busy_time +=kcpustat_field (&kcpustat_cpu (cpu),CPUTIME_SYSTEM , cpu); +kcpustat_cputime (kcpustat, cpu, &user, &nice, &sys, + &guest, &guest_nice); + + busy_time = user; + busy_time += sys; busy_time +=kcpustat_cpu (cpu).cpustat[CPUTIME_IRQ ]; busy_time +=kcpustat_cpu (cpu).cpustat[CPUTIME_SOFTIRQ ]; busy_time +=kcpustat_cpu (cpu).cpustat[CPUTIME_STEAL ]; - busy_time +=kcpustat_cpu (cpu).cpustat[CPUTIME_NICE ]; + busy_time += nice; idle_time = cur_wall_time - busy_time;if (wall)
drivers/cpufreq/cpufreq_governor.c +3 -3
@@ -105,7 +105,7 @@ void gov_update_cpu_data(struct dbs_data *dbs_data) j_cdbs->prev_cpu_idle =get_cpu_idle_time (j, &j_cdbs->prev_update_time, dbs_data->io_is_busy);if (dbs_data->ignore_nice_load) - j_cdbs->prev_cpu_nice =kcpustat_cpu (j).cpustat[CPUTIME_NICE ]; + j_cdbs->prev_cpu_nice =kcpustat_field (&kcpustat_cpu (j),CPUTIME_NICE , j); } } }
@@ -149,7 +149,7 @@ unsigned int dbs_update(struct cpufreq_policy *policy) j_cdbs->prev_cpu_idle = cur_idle_time;if (ignore_nice) { -u64 cur_nice =kcpustat_cpu (j).cpustat[CPUTIME_NICE ]; +u64 cur_nice =kcpustat_field (&kcpustat_cpu (j),CPUTIME_NICE , j); idle_time +=div_u64 (cur_nice - j_cdbs->prev_cpu_nice,NSEC_PER_USEC ); j_cdbs->prev_cpu_nice = cur_nice;
@@ -530,7 +530,7 @@ int cpufreq_dbs_governor_start(struct cpufreq_policy *policy) j_cdbs->prev_load =0 ;if (ignore_nice) - j_cdbs->prev_cpu_nice =kcpustat_cpu (j).cpustat[CPUTIME_NICE ]; + j_cdbs->prev_cpu_nice =kcpustat_field (&kcpustat_cpu (j),CPUTIME_NICE , j); } gov->start (policy);
Signature · 1 line
2.23.0
PATCH 5/6 leds: Use all-in-one vtime aware kcpustat accessor
In reply to Frederic WeisbeckerWe can now safely read user kcpustat fields on nohz_full CPUs. Use the appropriate accessor.
--- drivers/leds/trigger/ledtrig-activity.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/leds/trigger/ledtrig-activity.c +6 -3
@@ -57,9 +57,12 @@ static void led_activity_function(struct timer_list *t) curr_used =0 ;for_each_possible_cpu (i) { - curr_used +=kcpustat_cpu (i).cpustat[CPUTIME_USER ] - +kcpustat_cpu (i).cpustat[CPUTIME_NICE ] - +kcpustat_field (&kcpustat_cpu (i),CPUTIME_SYSTEM , i) +u64 user, nice, sys, guest, guest_nice; + +kcpustat_cputime (&kcpustat_cpu (i), i, &user, &nice, &sys, + &guest, &guest_nice); + + curr_used += user + nice + sys +kcpustat_cpu (i).cpustat[CPUTIME_SOFTIRQ ] +kcpustat_cpu (i).cpustat[CPUTIME_IRQ ]; cpus++;
Signature · 1 line
2.23.0
PATCH 6/6 rackmeter: Use vtime aware kcpustat accessor
In reply to Frederic WeisbeckerNow that we have a vtime safe kcpustat accessor, use it to fetch CPUTIME_NICE and fix frozen kcpustat values on nohz_full CPUs.
--- drivers/macintosh/rack-meter.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/macintosh/rack-meter.c +4 -3
@@ -81,13 +81,14 @@ static int rackmeter_ignore_nice;*/ static inline u64 get_cpu_idle_time (unsigned int cpu) { +struct kernel_cpustat *kcpustat = &kcpustat_cpu (cpu);u64 retval; - retval =kcpustat_cpu (cpu).cpustat[CPUTIME_IDLE ] + -kcpustat_cpu (cpu).cpustat[CPUTIME_IOWAIT ]; + retval = kcpustat->cpustat[CPUTIME_IDLE ] + + kcpustat->cpustat[CPUTIME_IOWAIT ];if (rackmeter_ignore_nice) - retval +=kcpustat_cpu (cpu).cpustat[CPUTIME_NICE ]; + retval +=kcpustat_field (kcpustat,CPUTIME_NICE , cpu);return retval; }
Signature · 1 line
2.23.0
Re: [PATCH 1/6] sched/cputime: Support other fields on kcpustat_field()
In reply to Frederic WeisbeckerQuoted 53 lines · Frederic Weisbecker
Provide support for user, nice, guest and
guest_nicefields throughkcpustat_field().Whether we account the delta to a nice or not nice field is decided on top of the nice value snapshot taken at the time we call
kcpustat_field(). If the nice value of the task has been changed since the last vtime update, we may have inacurrate distribution of the nice VS unnice cputime.However this is considered as a minor issue compared to the proper fix that would involve interrupting the target on nice updates, which is undesired on
nohz_fullCPUs.Signed-off-by Frederic Weisbecker <[email protected]>Cc Yauheni Kaliuta <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Rik van Riel <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Wanpeng Li <[email protected]>Cc Ingo Molnar <[email protected]>--- kernel/sched/cputime.c | 53 +++++++++++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 11 deletions(-)kernel/sched/cputime.c +11
-1@@ -912,11 +912,21 @@ 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, +struct task_struct *tsk,enum cpu_usage_stat usage,int cpu,u64 *val) { +struct vtime *vtime = &tsk->vtime;unsigned int seq;int err;@@ -946,9 +956,36 @@ static int kcpustat_field_vtime(u64 *cpustat,
kernel/sched/cputime.c static int kcpustat_field_vtime(u64 *cpustat, · line 963
Quoted 10 lines
kernel/sched/cputime.c +5
-3*val = cpustat[usage]; -if (vtime->state ==VTIME_SYS ) - *val += vtime->stime +vtime_delta (vtime); - +/* +* Nice VS unnice cputime accounting may be inaccurate if +* the nice value has changed since the last vtime update. +* But proper fix would involve interrupting target on nice +* updates which is a no go on nohz_full.
Well, we actually already interrupt the target in both sys_nice() and sys_setpriority() etc. syscall variants: we call set_user_nice() which calls resched_curr() and the task is sent an IPI and runs through a reschedule.
But ... I do agree that this kind of granularity of nice/non-nice accounting doesn't really matter in practice: the changing of nice values is a relatively low frequency operation on most systems.
But nevertheless the comment should probably be updated to reflect this.
Thanks,
Ingo
Re: [PATCH 2/6] sched/vtime: Bring all-in-one kcpustat accessor for vtime fields
In reply to Frederic WeisbeckerQuoted 28 lines · Frederic Weisbecker
Many callsites want to fetch the values of system, user,
user_nice, guest orguest_nicekcpustat fields altogether or at least a pair of these.In that case calling
kcpustat_field()for each requested field brings unecessary overhead when we could fetch all of them in a row.So provide
kcpustat_cputime()that fetches all vtime sensitive fields under the same RCU and seqcount block.Signed-off-by Frederic Weisbecker <[email protected]>Cc Yauheni Kaliuta <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Rik van Riel <[email protected]>Cc Peter Zijlstra <[email protected]>Cc Wanpeng Li <[email protected]>Cc Ingo Molnar <[email protected]>--- include/linux/kernel_stat.h | 23 ++++++ kernel/sched/cputime.c | 139 ++++++++++++++++++++++++++++++------ 2 files changed, 142 insertions(+), 20 deletions(-)include/linux/kernel_stat.h +0
-0@@ -78,15 +78,38 @@ static inline unsigned int kstat_cpu_irqs_sum(unsigned int cpu)return kstat_cpu (cpu).irqs_sum; }
include/linux/kernel_stat.h static inline unsigned int kstat_cpu_irqs_sum(unsigned int cpu) · line 89
Quoted 10 lines
include/linux/kernel_stat.h +9
-0+ +static inline void kcpustat_cputime_raw (u64 *cpustat,u64 *user,u64 *nice, +u64 *system,u64 *guest,u64 *guest_nice) +{ + *user = cpustat[CPUTIME_USER ]; + *nice = cpustat[CPUTIME_NICE ]; + *system = cpustat[CPUTIME_SYSTEM ]; + *guest = cpustat[CPUTIME_GUEST ]; + *guest_nice = cpustat[CPUTIME_GUEST_NICE ];
Could the 'cpustat' pointer be constified?
Also, please:
include/linux/kernel_stat.h static inline unsigned int kstat_cpu_irqs_sum(unsigned int cpu) · line 89
Quoted 5 lines
include/linux/kernel_stat.h +5
-0+ *user = cpustat[CPUTIME_USER ]; + *nice = cpustat[CPUTIME_NICE ]; + *system = cpustat[CPUTIME_SYSTEM ]; + *guest = cpustat[CPUTIME_GUEST ]; + *guest_nice = cpustat[CPUTIME_GUEST_NICE ];
More pleasing to look at and easier to verify as well.
include/linux/kernel_stat.h static inline unsigned int kstat_cpu_irqs_sum(unsigned int cpu) · line 100
Quoted 6 lines
include/linux/kernel_stat.h +6
-0+static int vtime_state_check (struct vtime *vtime,int cpu) +{ +/* +* We raced against context switch, fetch the +* kcpustat task again. +*/
s/against context switch
/against a context switch
Quoted 29 lines
include/linux/kernel_stat.h +29
-0+void kcpustat_cputime (struct kernel_cpustat *kcpustat,int cpu, +u64 *user,u64 *nice,u64 *system, +u64 *guest,u64 *guest_nice) +{ +u64 *cpustat = kcpustat->cpustat; +struct rq *rq; +int err; + +if (!vtime_accounting_enabled_cpu (cpu)) { +kcpustat_cputime_raw (cpustat, user, nice, + system, guest, guest_nice); +return ; + } + + rq =cpu_rq (cpu); + +for (;;) { +struct task_struct *curr; + +rcu_read_lock (); + curr =rcu_dereference (rq->curr); +if (WARN_ON_ONCE (!curr)) { +rcu_read_unlock (); +kcpustat_cputime_raw (cpustat, user, nice, + system, guest, guest_nice); +return ; + } + + err = kcpustat_cputime_vtime(cpustat, curr, cpu, user,
include/linux/kernel_stat.h static inline unsigned int kstat_cpu_irqs_sum(unsigned int cpu)
Quoted 10 lines
include/linux/kernel_stat.h +10
-0+ nice, system, guest, guest_nice); +rcu_read_unlock (); + +if (!err) +return ; + +cpu_relax (); + } +} +EXPORT_SYMBOL_GPL (kcpustat_cputime);
I'm wondering whether it's worth introducing a helper structure for this train of parameters: user, nice, system, guest, guest_nice?
We also have similar constructs in other places:
+ u64 cpu_user, cpu_nice, cpu_sys, cpu_guest, cpu_guest_nice;
But more broadly, what do we gain by passing along a quartet of pointers, while we could also just use a 'struct kernel_cpustat' and store the values there naturally?
Yes, it's larger, because it also has 5 other fields - but we lose much of the space savings due to always passing along the 4 pointers already.
So I really think the parameter passing should be organized better here. This probably affects similar cpustat functions as well.
Thanks,
Ingo
Re: [PATCH 2/6] sched/vtime: Bring all-in-one kcpustat accessor for vtime fields
Quoted 9 lines · Ingo Molnar
kernel/sched/cputime.c void task_cputime(struct task_struct *t, u64 *utime, u64 *stime) · line 920
Quoted 6 lines
kernel/sched/cputime.c +6
-0+static int vtime_state_check (struct vtime *vtime,int cpu) +{ +/* +* We raced against context switch, fetch the +* kcpustat task again. +*/ s/against context switch
/against a context switch
Ok.
Quoted 48 lines
Quoted 30 lines
kernel/sched/cputime.c +29
-0+void kcpustat_cputime (struct kernel_cpustat *kcpustat,int cpu, +u64 *user,u64 *nice,u64 *system, +u64 *guest,u64 *guest_nice) +{ +u64 *cpustat = kcpustat->cpustat; +struct rq *rq; +int err; + +if (!vtime_accounting_enabled_cpu (cpu)) { +kcpustat_cputime_raw (cpustat, user, nice, + system, guest, guest_nice); +return ; + } + + rq =cpu_rq (cpu); + +for (;;) { +struct task_struct *curr; + +rcu_read_lock (); + curr =rcu_dereference (rq->curr); +if (WARN_ON_ONCE (!curr)) { +rcu_read_unlock (); +kcpustat_cputime_raw (cpustat, user, nice, + system, guest, guest_nice); +return ; + } + + err = kcpustat_cputime_vtime(cpustat, curr, cpu, user,kernel/sched/cputime.c u64 kcpustat_field(struct kernel_cpustat *kcpustat, · line 1124
Quoted 10 lines
kernel/sched/cputime.c +10
-0+ nice, system, guest, guest_nice); +rcu_read_unlock (); + +if (!err) +return ; + +cpu_relax (); + } +} +EXPORT_SYMBOL_GPL (kcpustat_cputime);I'm wondering whether it's worth introducing a helper structure for this train of parameters: user, nice, system, guest,
guest_nice?We also have similar constructs in other places:
+ u64
cpu_user,cpu_nice,cpu_sys,cpu_guest,cpu_guest_nice;
Quoted 8 lines
But more broadly, what do we gain by passing along a quartet of pointers, while we could also just use a 'struct
kernel_cpustat' and store the values there naturally?Yes, it's larger, because it also has 5 other fields - but we lose much of the space savings due to always passing along the 4 pointers already.
So I really think the parameter passing should be organized better here.
Yeah I've been thinking about that too but I was worried about the stack use. It's probably not a big worry eventually. I'll do that for the next series.
Quoted 1 line
This probably affects similar cpustat functions as well.
Only this one fortunately :-)
Thanks.
Peter Zijlstra
maintainerRe: [PATCH 1/6] sched/cputime: Support other fields on kcpustat_field()
In reply to Ingo MolnarQuoted 12 lines · Ingo Molnar
kernel/sched/cputime.c static int kcpustat_field_vtime(u64 *cpustat, · line 963
Quoted 5 lines · Frederic Weisbecker
kernel/sched/cputime.c +5
-0+/* +* Nice VS unnice cputime accounting may be inaccurate if +* the nice value has changed since the last vtime update. +* But proper fix would involve interrupting target on nice +* updates which is a no go on nohz_full. Well, we actually already interrupt the target in both
sys_nice()andsys_setpriority()etc. syscall variants: we callset_user_nice()which callsresched_curr()and the task is sent an IPI and runs through a reschedule.
I think we can easily avoid doing that IPI when we find it is the only task on that runqueue. Which is exactly the case for NOHZ_FULL.