cgroup/rstat: add force idle show helper
PATCH v3 1/1 cgroup/rstat: add force idle show helper
In the function cgroup_base_stat_cputime_show, there are five instances of #ifdef, which makes the code not concise. To address this, add the function cgroup_force_idle_show to make the code more succinct.
--- kernel/cgroup/rstat.c | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-)
kernel/cgroup/rstat.c +16 -20
@@ -594,49 +594,45 @@ static void root_cgroup_cputime(struct cgroup_base_stat *bstat) } } + +static void cgroup_force_idle_show (struct seq_file *seq,struct cgroup_base_stat *bstat) +{ +#ifdef CONFIG_SCHED_CORE +u64 forceidle_time = bstat->forceidle_sum; + +do_div (forceidle_time,NSEC_PER_USEC ); +seq_printf (seq,"core_sched.force_idle_usec %llu\n" , forceidle_time); +#endif +} +void cgroup_base_stat_cputime_show (struct seq_file *seq) {struct cgroup *cgrp =seq_css (seq)->cgroup;u64 usage, utime, stime; -struct cgroup_base_stat bstat; -#ifdef CONFIG_SCHED_CORE -u64 forceidle_time; -#endif if (cgroup_parent (cgrp)) {cgroup_rstat_flush_hold (cgrp); usage = cgrp->bstat.cputime.sum_exec_runtime;cputime_adjust (&cgrp->bstat.cputime, &cgrp->prev_cputime, &utime, &stime); -#ifdef CONFIG_SCHED_CORE - forceidle_time = cgrp->bstat.forceidle_sum; -#endif cgroup_rstat_flush_release (cgrp); }else { -root_cgroup_cputime (&bstat); - usage = bstat.cputime.sum_exec_runtime; - utime = bstat.cputime.utime; - stime = bstat.cputime.stime; -#ifdef CONFIG_SCHED_CORE - forceidle_time = bstat.forceidle_sum; -#endif +root_cgroup_cputime (&cgrp->bstat); + usage = cgrp->bstat.cputime.sum_exec_runtime; + utime = cgrp->bstat.cputime.utime; + stime = cgrp->bstat.cputime.stime; }do_div (usage,NSEC_PER_USEC );do_div (utime,NSEC_PER_USEC );do_div (stime,NSEC_PER_USEC ); -#ifdef CONFIG_SCHED_CORE -do_div (forceidle_time,NSEC_PER_USEC ); -#endif seq_printf (seq,"usage_usec %llu\n" "user_usec %llu\n" "system_usec %llu\n" , usage, utime, stime); -#ifdef CONFIG_SCHED_CORE -seq_printf (seq,"core_sched.force_idle_usec %llu\n" , forceidle_time); -#endif +cgroup_force_idle_show (seq, &cgrp->bstat); }/* Add bpf kfuncs for cgroup_rstat_updated() and cgroup_rstat_flush() */
Signature · 1 line
2.34.1
Quoted 49 lines · Chen Ridong
In the function
cgroup_base_stat_cputime_show, there are five instances of #ifdef, which makes the code not concise. To address this, add the functioncgroup_force_idle_showto make the code more succinct.Signed-off-by Chen Ridong <[email protected]>--- kernel/cgroup/rstat.c | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-)kernel/cgroup/rstat.c +11
-8@@ -594,49 +594,45 @@ static void root_cgroup_cputime(struct cgroup_base_stat *bstat) } } + +static void cgroup_force_idle_show (struct seq_file *seq,struct cgroup_base_stat *bstat) +{ +#ifdef CONFIG_SCHED_CORE +u64 forceidle_time = bstat->forceidle_sum; + +do_div (forceidle_time,NSEC_PER_USEC ); +seq_printf (seq,"core_sched.force_idle_usec %llu\n" , forceidle_time); +#endif +} +void cgroup_base_stat_cputime_show (struct seq_file *seq) {struct cgroup *cgrp =seq_css (seq)->cgroup;u64 usage, utime, stime; -struct cgroup_base_stat bstat; -#ifdef CONFIG_SCHED_CORE -u64 forceidle_time; -#endif if (cgroup_parent (cgrp)) {cgroup_rstat_flush_hold (cgrp); usage = cgrp->bstat.cputime.sum_exec_runtime;cputime_adjust (&cgrp->bstat.cputime, &cgrp->prev_cputime, &utime, &stime); -#ifdef CONFIG_SCHED_CORE - forceidle_time = cgrp->bstat.forceidle_sum; -#endif cgroup_rstat_flush_release (cgrp); }else { -root_cgroup_cputime (&bstat);
kernel/cgroup/rstat.c static void root_cgroup_cputime(struct cgroup_base_stat *bstat) · line 623
Quoted 10 lines
kernel/cgroup/rstat.c +4
-6- usage = bstat.cputime.sum_exec_runtime; - utime = bstat.cputime.utime; - stime = bstat.cputime.stime; -#ifdef CONFIG_SCHED_CORE - forceidle_time = bstat.forceidle_sum; -#endif +root_cgroup_cputime (&cgrp->bstat); + usage = cgrp->bstat.cputime.sum_exec_runtime; + utime = cgrp->bstat.cputime.utime; + stime = cgrp->bstat.cputime.stime;
Just a simple comment saying that you are reusing the root cgroup bstat which is otherwise not being used will help readability.
Other than that, the change LGTM.
Cheers,
Longman
Quoted 21 lines
kernel/cgroup/rstat.c +1
-6}do_div (usage,NSEC_PER_USEC );do_div (utime,NSEC_PER_USEC );do_div (stime,NSEC_PER_USEC ); -#ifdef CONFIG_SCHED_CORE -do_div (forceidle_time,NSEC_PER_USEC ); -#endif seq_printf (seq,"usage_usec %llu\n" "user_usec %llu\n" "system_usec %llu\n" , usage, utime, stime); -#ifdef CONFIG_SCHED_CORE -seq_printf (seq,"core_sched.force_idle_usec %llu\n" , forceidle_time); -#endif +cgroup_force_idle_show (seq, &cgrp->bstat); }/* Add bpf kfuncs for cgroup_rstat_updated() and cgroup_rstat_flush() */
Quoted 65 lines · Waiman Long
Quoted 50 lines · Chen Ridong
In the function
cgroup_base_stat_cputime_show, there are five instances of #ifdef, which makes the code not concise. To address this, add the functioncgroup_force_idle_showto make the code more succinct.Signed-off-by Chen Ridong <[email protected]>---
kernel/cgroup/rstat.c| 36 ++++++++++++++++--------------------1 file changed, 16 insertions(+), 20 deletions(-)kernel/cgroup/rstat.c +11
-8@@ -594,49 +594,45 @@ static void root_cgroup_cputime(struct cgroup_base_stat *bstat) } } + +static void cgroup_force_idle_show (struct seq_file *seq,struct cgroup_base_stat *bstat) +{ +#ifdef CONFIG_SCHED_CORE + u64 forceidle_time = bstat->forceidle_sum; + + do_div(forceidle_time, NSEC_PER_USEC); + seq_printf(seq, "core_sched.force_idle_usec %llu\n", forceidle_time); +#endif +} + void cgroup_base_stat_cputime_show(struct seq_file *seq) { struct cgroup *cgrp = seq_css(seq)->cgroup; u64 usage, utime, stime; - struct cgroup_base_stat bstat; -#ifdef CONFIG_SCHED_CORE - u64 forceidle_time; -#endif if (cgroup_parent(cgrp)) { cgroup_rstat_flush_hold(cgrp); usage = cgrp->bstat.cputime.sum_exec_runtime; cputime_adjust(&cgrp->bstat.cputime, &cgrp->prev_cputime, &utime, &stime); -#ifdef CONFIG_SCHED_CORE - forceidle_time = cgrp->bstat.forceidle_sum; -#endif cgroup_rstat_flush_release(cgrp); } else { - root_cgroup_cputime(&bstat);kernel/cgroup/rstat.c static void root_cgroup_cputime(struct · line 624
Quoted 10 lines
kernel/cgroup/rstat.c +4
-6- usage = bstat.cputime.sum_exec_runtime; - utime = bstat.cputime.utime; - stime = bstat.cputime.stime; -#ifdef CONFIG_SCHED_CORE - forceidle_time = bstat.forceidle_sum; -#endif + root_cgroup_cputime(&cgrp->bstat); + usage = cgrp->bstat.cputime.sum_exec_runtime; + utime = cgrp->bstat.cputime.utime; + stime = cgrp->bstat.cputime.stime;Just a simple comment saying that you are reusing the root cgroup bstat which is otherwise not being used will help readability.
Quoted 1 line
Other than that, the change LGTM.
Thank you, Longman. I will do that.
Regards,
Ridong
Quoted 24 lines
Cheers,
LongmanQuoted 18 lines
kernel/cgroup/rstat.c +0
-3} do_div(usage, NSEC_PER_USEC); do_div(utime, NSEC_PER_USEC); do_div(stime, NSEC_PER_USEC); -#ifdef CONFIG_SCHED_CORE - do_div(forceidle_time, NSEC_PER_USEC); -#endif seq_printf(seq, "
usage_usec%llu\n"
"user_usec%llu\n"
"system_usec%llu\n",
usage, utime, stime);
-#ifdefCONFIG_SCHED_CORE
-seq_printf(seq, "core_sched.force_idle_usec %llu\n", forceidle_time);
-#endif
+cgroup_force_idle_show(seq, &cgrp->bstat);
}
/* Add bpf kfuncs forcgroup_rstat_updated()andcgroup_rstat_flush()*/