Skip to content

Commit 93b3566

Browse files
inwardvesselhtejun
authored andcommitted
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>
1 parent 748922d commit 93b3566

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

kernel/cgroup/rstat.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ static DEFINE_PER_CPU(raw_spinlock_t, rstat_base_cpu_lock);
1414

1515
static void cgroup_base_stat_flush(struct cgroup *cgrp, int cpu);
1616

17+
/*
18+
* Determines whether a given css can participate in rstat.
19+
* css's that are cgroup::self use rstat for base stats.
20+
* Other css's associated with a subsystem use rstat only when
21+
* they define the ss->css_rstat_flush callback.
22+
*/
23+
static inline bool css_uses_rstat(struct cgroup_subsys_state *css)
24+
{
25+
return css_is_self(css) || css->ss->css_rstat_flush != NULL;
26+
}
27+
1728
static struct css_rstat_cpu *css_rstat_cpu(
1829
struct cgroup_subsys_state *css, int cpu)
1930
{
@@ -119,7 +130,7 @@ __bpf_kfunc void css_rstat_updated(struct cgroup_subsys_state *css, int cpu)
119130
* Since bpf programs can call this function, prevent access to
120131
* uninitialized rstat pointers.
121132
*/
122-
if (!css_is_self(css) && css->ss->css_rstat_flush == NULL)
133+
if (!css_uses_rstat(css))
123134
return;
124135

125136
/*
@@ -390,7 +401,7 @@ __bpf_kfunc void css_rstat_flush(struct cgroup_subsys_state *css)
390401
* Since bpf programs can call this function, prevent access to
391402
* uninitialized rstat pointers.
392403
*/
393-
if (!is_self && css->ss->css_rstat_flush == NULL)
404+
if (!css_uses_rstat(css))
394405
return;
395406

396407
might_sleep();
@@ -462,7 +473,7 @@ void css_rstat_exit(struct cgroup_subsys_state *css)
462473
{
463474
int cpu;
464475

465-
if (!css_is_self(css) && css->ss->css_rstat_flush == NULL)
476+
if (!css_uses_rstat(css))
466477
return;
467478

468479
css_rstat_flush(css);

0 commit comments

Comments
 (0)