]> www.infradead.org Git - users/dwmw2/linux.git/commitdiff
cgroup: helper for checking rstat participation of css
authorJP Kobryn <inwardvessel@gmail.com>
Thu, 15 May 2025 00:19:36 +0000 (17:19 -0700)
committerTejun Heo <tj@kernel.org>
Mon, 19 May 2025 20:29:49 +0000 (10:29 -1000)
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 <inwardvessel@gmail.com>
Signed-off-by: Tejun Heo <tj@kernel.org>
kernel/cgroup/rstat.c

index 0bb609e73bde1a18637ea28cc3caab5aa4fd13a7..7dd396ae3c68213c36840dc6d17f810ed372dffa 100644 (file)
@@ -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);