Skip to contentSkip to conversation

cgroup: rstat: use same convention to assign cgroup_base_stat

PATCH In review Wei Yang 2 participants 3 messages Jan 8, 2022 – Jan 12, 2022 cgroup

lore
Share & tools
lore

Wei Yang

author
#0 lore raw

PATCH 1/2 cgroup: rstat: use same convention to assign cgroup_base_stat

In function cgroup_base_stat_flush(), we update cgroup_base_stat by getting rstatc->bstat and adjust delta to related fields.

There are two convention to assign cgroup_base_stat in this function:

* rstat2 = rstat1
* rstat2.cputime = rstat1.cputime

The second convention may make audience think just field "cputime" is updated, while cputime is the only field in cgroup_base_stat.

Let's use the same convention to eliminate this confusion.

---
 kernel/cgroup/rstat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/cgroup/rstat.c +1 -1
index a00875375f7d..c626d5a526c4 100644
@@ -324,7 +324,7 @@ static void cgroup_base_stat_flush(struct cgroup *cgrp, int cpu)
 	/* fetch the current per-cpu values */
 	do {
 		seq = __u64_stats_fetch_begin(&rstatc->bsync);
-		cur.cputime = rstatc->bstat.cputime;
+		cur = rstatc->bstat;
 	} while (__u64_stats_fetch_retry(&rstatc->bsync, seq));
 
 	/* propagate percpu delta to global */
Signature · 1 line
2.33.1
author
#1 lore raw

PATCH 2/2 cgroup: rstat: retrieve current bstat to delta directly

Instead of retrieve current bstat to cur and copy it to delta, let's use delta directly.

This saves one copy operation and has the same code convention as propagating delta to parent.

---
 kernel/cgroup/rstat.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
kernel/cgroup/rstat.c +2 -3
index c626d5a526c4..f66944c53613 100644
@@ -314,7 +314,7 @@ static void cgroup_base_stat_flush(struct cgroup *cgrp, int cpu)
 {
 	struct cgroup_rstat_cpu *rstatc = cgroup_rstat_cpu(cgrp, cpu);
 	struct cgroup *parent = cgroup_parent(cgrp);
-	struct cgroup_base_stat cur, delta;
+	struct cgroup_base_stat delta;
 	unsigned seq;
 
 	/* Root-level stats are sourced from system-wide CPU stats */
@@ -324,11 +324,10 @@ static void cgroup_base_stat_flush(struct cgroup *cgrp, int cpu)
 	/* fetch the current per-cpu values */
 	do {
 		seq = __u64_stats_fetch_begin(&rstatc->bsync);
-		cur = rstatc->bstat;
+		delta = rstatc->bstat;
 	} while (__u64_stats_fetch_retry(&rstatc->bsync, seq));
 
 	/* propagate percpu delta to global */
-	delta = cur;
 	cgroup_base_stat_sub(&delta, &rstatc->last_bstat);
 	cgroup_base_stat_add(&cgrp->bstat, &delta);
 	cgroup_base_stat_add(&rstatc->last_bstat, &delta);
Signature · 1 line
2.33.1
maintainer
#2 lore raw
In reply to Wei Yang
Quoted 8 lines · Wei Yang

In function cgroup_base_stat_flush(), we update cgroup_base_stat by getting rstatc->bstat and adjust delta to related fields.

There are two convention to assign cgroup_base_stat in this function:

* rstat2 = rstat1
* rstat2.cputime = rstat1.cputime

Quoted 6 lines

The second convention may make audience think just field "cputime" is updated, while cputime is the only field in cgroup_base_stat.

Let's use the same convention to eliminate this confusion.

Applied 1-2 to cgroup/for-5.18.

Thanks.

Signature · 1 line
tejun