Commit 1bb5ec2e authored by Tejun Heo's avatar Tejun Heo

cgroup: use cgroup->last_bstat instead of cgroup->bstat_pending for consistency

cgroup->bstat_pending is used to determine the base stat delta to
propagate to the parent.  While correct, this is different from how
percpu delta is determined for no good reason and the inconsistency
makes the code more difficult to understand.

This patch makes parent propagation delta calculation use the same
method as percpu to global propagation.

* cgroup_base_stat_accumulate() is renamed to cgroup_base_stat_add()
  and cgroup_base_stat_sub() is added.

* percpu propagation calculation is updated to use the above helpers.

* cgroup->bstat_pending is replaced with cgroup->last_bstat and
  updated to use the same calculation as percpu propagation.
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
parent 5153faac
...@@ -458,7 +458,7 @@ struct cgroup { ...@@ -458,7 +458,7 @@ struct cgroup {
struct list_head rstat_css_list; struct list_head rstat_css_list;
/* cgroup basic resource statistics */ /* cgroup basic resource statistics */
struct cgroup_base_stat pending_bstat; /* pending from children */ struct cgroup_base_stat last_bstat;
struct cgroup_base_stat bstat; struct cgroup_base_stat bstat;
struct prev_cputime prev_cputime; /* for printing out cputime */ struct prev_cputime prev_cputime; /* for printing out cputime */
......
...@@ -304,7 +304,7 @@ void __init cgroup_rstat_boot(void) ...@@ -304,7 +304,7 @@ void __init cgroup_rstat_boot(void)
* Functions for cgroup basic resource statistics implemented on top of * Functions for cgroup basic resource statistics implemented on top of
* rstat. * rstat.
*/ */
static void cgroup_base_stat_accumulate(struct cgroup_base_stat *dst_bstat, static void cgroup_base_stat_add(struct cgroup_base_stat *dst_bstat,
struct cgroup_base_stat *src_bstat) struct cgroup_base_stat *src_bstat)
{ {
dst_bstat->cputime.utime += src_bstat->cputime.utime; dst_bstat->cputime.utime += src_bstat->cputime.utime;
...@@ -312,36 +312,40 @@ static void cgroup_base_stat_accumulate(struct cgroup_base_stat *dst_bstat, ...@@ -312,36 +312,40 @@ static void cgroup_base_stat_accumulate(struct cgroup_base_stat *dst_bstat,
dst_bstat->cputime.sum_exec_runtime += src_bstat->cputime.sum_exec_runtime; dst_bstat->cputime.sum_exec_runtime += src_bstat->cputime.sum_exec_runtime;
} }
static void cgroup_base_stat_sub(struct cgroup_base_stat *dst_bstat,
struct cgroup_base_stat *src_bstat)
{
dst_bstat->cputime.utime -= src_bstat->cputime.utime;
dst_bstat->cputime.stime -= src_bstat->cputime.stime;
dst_bstat->cputime.sum_exec_runtime -= src_bstat->cputime.sum_exec_runtime;
}
static void cgroup_base_stat_flush(struct cgroup *cgrp, int cpu) static void cgroup_base_stat_flush(struct cgroup *cgrp, int cpu)
{ {
struct cgroup *parent = cgroup_parent(cgrp); struct cgroup *parent = cgroup_parent(cgrp);
struct cgroup_rstat_cpu *rstatc = cgroup_rstat_cpu(cgrp, cpu); struct cgroup_rstat_cpu *rstatc = cgroup_rstat_cpu(cgrp, cpu);
struct task_cputime *last_cputime = &rstatc->last_bstat.cputime; struct cgroup_base_stat cur, delta;
struct task_cputime cputime;
struct cgroup_base_stat delta;
unsigned seq; unsigned seq;
/* fetch the current per-cpu values */ /* fetch the current per-cpu values */
do { do {
seq = __u64_stats_fetch_begin(&rstatc->bsync); seq = __u64_stats_fetch_begin(&rstatc->bsync);
cputime = rstatc->bstat.cputime; cur.cputime = rstatc->bstat.cputime;
} while (__u64_stats_fetch_retry(&rstatc->bsync, seq)); } while (__u64_stats_fetch_retry(&rstatc->bsync, seq));
/* calculate the delta to propgate */ /* propagate percpu delta to global */
delta.cputime.utime = cputime.utime - last_cputime->utime; delta = cur;
delta.cputime.stime = cputime.stime - last_cputime->stime; cgroup_base_stat_sub(&delta, &rstatc->last_bstat);
delta.cputime.sum_exec_runtime = cputime.sum_exec_runtime - cgroup_base_stat_add(&cgrp->bstat, &delta);
last_cputime->sum_exec_runtime; cgroup_base_stat_add(&rstatc->last_bstat, &delta);
*last_cputime = cputime;
/* propagate global delta to parent */
/* transfer the pending stat into delta */ if (parent) {
cgroup_base_stat_accumulate(&delta, &cgrp->pending_bstat); delta = cgrp->bstat;
memset(&cgrp->pending_bstat, 0, sizeof(cgrp->pending_bstat)); cgroup_base_stat_sub(&delta, &cgrp->last_bstat);
cgroup_base_stat_add(&parent->bstat, &delta);
/* propagate delta into the global stat and the parent's pending */ cgroup_base_stat_add(&cgrp->last_bstat, &delta);
cgroup_base_stat_accumulate(&cgrp->bstat, &delta); }
if (parent)
cgroup_base_stat_accumulate(&parent->pending_bstat, &delta);
} }
static struct cgroup_rstat_cpu * static struct cgroup_rstat_cpu *
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment