summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJP Kobryn <inwardvessel@gmail.com>2025-05-14 17:19:36 -0700
committerTejun Heo <tj@kernel.org>2025-05-19 10:29:49 -1000
commit93b35663f2018ff2accf4336a909081883eda76b (patch)
treea79fe1e21d5b8931f4b94bf8e5e703063bdade83
parent748922dcfabdd655d25fb6dd09a60e694a3d35e6 (diff)
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 <inwardvessel@gmail.com> Signed-off-by: Tejun Heo <tj@kernel.org>
-rw-r--r--kernel/cgroup/rstat.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c
index 0bb609e73bde..7dd396ae3c68 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);