From: JP Kobryn Date: Thu, 15 May 2025 00:19:36 +0000 (-0700) Subject: cgroup: helper for checking rstat participation of css X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=93b35663f2018ff2accf4336a909081883eda76b;p=users%2Fdwmw2%2Flinux.git cgroup: helper for checking rstat participation of css There are a few places where a conditional check is performed to validate a given css on its rstat participation. This new helper tries to make the code more readable where this check is performed. Signed-off-by: JP Kobryn Signed-off-by: Tejun Heo --- diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c index 0bb609e73bde1..7dd396ae3c682 100644 --- a/kernel/cgroup/rstat.c +++ b/kernel/cgroup/rstat.c @@ -14,6 +14,17 @@ static DEFINE_PER_CPU(raw_spinlock_t, rstat_base_cpu_lock); static void cgroup_base_stat_flush(struct cgroup *cgrp, int cpu); +/* + * Determines whether a given css can participate in rstat. + * css's that are cgroup::self use rstat for base stats. + * Other css's associated with a subsystem use rstat only when + * they define the ss->css_rstat_flush callback. + */ +static inline bool css_uses_rstat(struct cgroup_subsys_state *css) +{ + return css_is_self(css) || css->ss->css_rstat_flush != NULL; +} + static struct css_rstat_cpu *css_rstat_cpu( struct cgroup_subsys_state *css, int cpu) { @@ -119,7 +130,7 @@ __bpf_kfunc void css_rstat_updated(struct cgroup_subsys_state *css, int cpu) * Since bpf programs can call this function, prevent access to * uninitialized rstat pointers. */ - if (!css_is_self(css) && css->ss->css_rstat_flush == NULL) + if (!css_uses_rstat(css)) return; /* @@ -390,7 +401,7 @@ __bpf_kfunc void css_rstat_flush(struct cgroup_subsys_state *css) * Since bpf programs can call this function, prevent access to * uninitialized rstat pointers. */ - if (!is_self && css->ss->css_rstat_flush == NULL) + if (!css_uses_rstat(css)) return; might_sleep(); @@ -462,7 +473,7 @@ void css_rstat_exit(struct cgroup_subsys_state *css) { int cpu; - if (!css_is_self(css) && css->ss->css_rstat_flush == NULL) + if (!css_uses_rstat(css)) return; css_rstat_flush(css);