Skip to content

Commit b824766

Browse files
Chen Ridonghtejun
authored andcommitted
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. Signed-off-by: Chen Ridong <[email protected]> Signed-off-by: Tejun Heo <[email protected]>
1 parent 1028f39 commit b824766

File tree

1 file changed

+17
-20
lines changed

1 file changed

+17
-20
lines changed

kernel/cgroup/rstat.c

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -594,49 +594,46 @@ static void root_cgroup_cputime(struct cgroup_base_stat *bstat)
594594
}
595595
}
596596

597+
598+
static void cgroup_force_idle_show(struct seq_file *seq, struct cgroup_base_stat *bstat)
599+
{
600+
#ifdef CONFIG_SCHED_CORE
601+
u64 forceidle_time = bstat->forceidle_sum;
602+
603+
do_div(forceidle_time, NSEC_PER_USEC);
604+
seq_printf(seq, "core_sched.force_idle_usec %llu\n", forceidle_time);
605+
#endif
606+
}
607+
597608
void cgroup_base_stat_cputime_show(struct seq_file *seq)
598609
{
599610
struct cgroup *cgrp = seq_css(seq)->cgroup;
600611
u64 usage, utime, stime;
601-
struct cgroup_base_stat bstat;
602-
#ifdef CONFIG_SCHED_CORE
603-
u64 forceidle_time;
604-
#endif
605612

606613
if (cgroup_parent(cgrp)) {
607614
cgroup_rstat_flush_hold(cgrp);
608615
usage = cgrp->bstat.cputime.sum_exec_runtime;
609616
cputime_adjust(&cgrp->bstat.cputime, &cgrp->prev_cputime,
610617
&utime, &stime);
611-
#ifdef CONFIG_SCHED_CORE
612-
forceidle_time = cgrp->bstat.forceidle_sum;
613-
#endif
614618
cgroup_rstat_flush_release(cgrp);
615619
} else {
616-
root_cgroup_cputime(&bstat);
617-
usage = bstat.cputime.sum_exec_runtime;
618-
utime = bstat.cputime.utime;
619-
stime = bstat.cputime.stime;
620-
#ifdef CONFIG_SCHED_CORE
621-
forceidle_time = bstat.forceidle_sum;
622-
#endif
620+
/* cgrp->bstat of root is not actually used, reuse it */
621+
root_cgroup_cputime(&cgrp->bstat);
622+
usage = cgrp->bstat.cputime.sum_exec_runtime;
623+
utime = cgrp->bstat.cputime.utime;
624+
stime = cgrp->bstat.cputime.stime;
623625
}
624626

625627
do_div(usage, NSEC_PER_USEC);
626628
do_div(utime, NSEC_PER_USEC);
627629
do_div(stime, NSEC_PER_USEC);
628-
#ifdef CONFIG_SCHED_CORE
629-
do_div(forceidle_time, NSEC_PER_USEC);
630-
#endif
631630

632631
seq_printf(seq, "usage_usec %llu\n"
633632
"user_usec %llu\n"
634633
"system_usec %llu\n",
635634
usage, utime, stime);
636635

637-
#ifdef CONFIG_SCHED_CORE
638-
seq_printf(seq, "core_sched.force_idle_usec %llu\n", forceidle_time);
639-
#endif
636+
cgroup_force_idle_show(seq, &cgrp->bstat);
640637
}
641638

642639
/* Add bpf kfuncs for cgroup_rstat_updated() and cgroup_rstat_flush() */

0 commit comments

Comments
 (0)