aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
authorTejun Heo <tj@kernel.org>2018-04-26 17:29:04 -0400
committerTejun Heo <tj@kernel.org>2018-04-26 17:29:04 -0400
commitd4ff749b5e0f1e2d4d69a3e4ea81cdeaeb4904d2 (patch)
tree99a922407a9aa00dbd7441e26969e18120a027e5 /kernel
parentc58632b3631cb222da41d9dc0dd39e106c1eafd0 (diff)
cgroup: Distinguish base resource stat implementation from rstat
Base resource stat accounts universial (not specific to any controller) resource consumptions on top of rstat. Currently, its implementation is intermixed with rstat implementation making the code confusing to follow. This patch clarifies the distintion by doing the followings. * Encapsulate base resource stat counters, currently only cputime, in struct cgroup_base_stat. * Move prev_cputime into struct cgroup and initialize it with cgroup. * Rename the related functions so that they start with cgroup_base_stat. * Prefix the related variables and field names with b. This patch doesn't make any functional changes. Signed-off-by: Tejun Heo <tj@kernel.org>
Diffstat (limited to 'kernel')
-rw-r--r--kernel/cgroup/cgroup-internal.h2
-rw-r--r--kernel/cgroup/cgroup.c4
-rw-r--r--kernel/cgroup/rstat.c67
3 files changed, 36 insertions, 37 deletions
diff --git a/kernel/cgroup/cgroup-internal.h b/kernel/cgroup/cgroup-internal.h
index 092711114a1f..aab4d0a09670 100644
--- a/kernel/cgroup/cgroup-internal.h
+++ b/kernel/cgroup/cgroup-internal.h
@@ -206,7 +206,7 @@ int cgroup_task_count(const struct cgroup *cgrp);
206void cgroup_rstat_flush(struct cgroup *cgrp); 206void cgroup_rstat_flush(struct cgroup *cgrp);
207int cgroup_rstat_init(struct cgroup *cgrp); 207int cgroup_rstat_init(struct cgroup *cgrp);
208void cgroup_rstat_exit(struct cgroup *cgrp); 208void cgroup_rstat_exit(struct cgroup *cgrp);
209void cgroup_stat_show_cputime(struct seq_file *seq); 209void cgroup_base_stat_cputime_show(struct seq_file *seq);
210void cgroup_rstat_boot(void); 210void cgroup_rstat_boot(void);
211 211
212/* 212/*
diff --git a/kernel/cgroup/cgroup.c b/kernel/cgroup/cgroup.c
index 32eb7ce0ad71..31af98996692 100644
--- a/kernel/cgroup/cgroup.c
+++ b/kernel/cgroup/cgroup.c
@@ -54,6 +54,7 @@
54#include <linux/proc_ns.h> 54#include <linux/proc_ns.h>
55#include <linux/nsproxy.h> 55#include <linux/nsproxy.h>
56#include <linux/file.h> 56#include <linux/file.h>
57#include <linux/sched/cputime.h>
57#include <net/sock.h> 58#include <net/sock.h>
58 59
59#define CREATE_TRACE_POINTS 60#define CREATE_TRACE_POINTS
@@ -1859,6 +1860,7 @@ static void init_cgroup_housekeeping(struct cgroup *cgrp)
1859 cgrp->dom_cgrp = cgrp; 1860 cgrp->dom_cgrp = cgrp;
1860 cgrp->max_descendants = INT_MAX; 1861 cgrp->max_descendants = INT_MAX;
1861 cgrp->max_depth = INT_MAX; 1862 cgrp->max_depth = INT_MAX;
1863 prev_cputime_init(&cgrp->prev_cputime);
1862 1864
1863 for_each_subsys(ss, ssid) 1865 for_each_subsys(ss, ssid)
1864 INIT_LIST_HEAD(&cgrp->e_csets[ssid]); 1866 INIT_LIST_HEAD(&cgrp->e_csets[ssid]);
@@ -3396,7 +3398,7 @@ static int cpu_stat_show(struct seq_file *seq, void *v)
3396 struct cgroup __maybe_unused *cgrp = seq_css(seq)->cgroup; 3398 struct cgroup __maybe_unused *cgrp = seq_css(seq)->cgroup;
3397 int ret = 0; 3399 int ret = 0;
3398 3400
3399 cgroup_stat_show_cputime(seq); 3401 cgroup_base_stat_cputime_show(seq);
3400#ifdef CONFIG_CGROUP_SCHED 3402#ifdef CONFIG_CGROUP_SCHED
3401 ret = cgroup_extra_stat_show(seq, cgrp, cpu_cgrp_id); 3403 ret = cgroup_extra_stat_show(seq, cgrp, cpu_cgrp_id);
3402#endif 3404#endif
diff --git a/kernel/cgroup/rstat.c b/kernel/cgroup/rstat.c
index 6824047b57a9..7670191fa776 100644
--- a/kernel/cgroup/rstat.c
+++ b/kernel/cgroup/rstat.c
@@ -128,30 +128,30 @@ static struct cgroup *cgroup_rstat_cpu_pop_updated(struct cgroup *pos,
128 return pos; 128 return pos;
129} 129}
130 130
131static void cgroup_stat_accumulate(struct cgroup_stat *dst_stat, 131static void cgroup_base_stat_accumulate(struct cgroup_base_stat *dst_bstat,
132 struct cgroup_stat *src_stat) 132 struct cgroup_base_stat *src_bstat)
133{ 133{
134 dst_stat->cputime.utime += src_stat->cputime.utime; 134 dst_bstat->cputime.utime += src_bstat->cputime.utime;
135 dst_stat->cputime.stime += src_stat->cputime.stime; 135 dst_bstat->cputime.stime += src_bstat->cputime.stime;
136 dst_stat->cputime.sum_exec_runtime += src_stat->cputime.sum_exec_runtime; 136 dst_bstat->cputime.sum_exec_runtime += src_bstat->cputime.sum_exec_runtime;
137} 137}
138 138
139static void cgroup_cpu_stat_flush_one(struct cgroup *cgrp, int cpu) 139static void cgroup_base_stat_flush(struct cgroup *cgrp, int cpu)
140{ 140{
141 struct cgroup *parent = cgroup_parent(cgrp); 141 struct cgroup *parent = cgroup_parent(cgrp);
142 struct cgroup_rstat_cpu *rstatc = cgroup_rstat_cpu(cgrp, cpu); 142 struct cgroup_rstat_cpu *rstatc = cgroup_rstat_cpu(cgrp, cpu);
143 struct task_cputime *last_cputime = &rstatc->last_cputime; 143 struct task_cputime *last_cputime = &rstatc->last_bstat.cputime;
144 struct task_cputime cputime; 144 struct task_cputime cputime;
145 struct cgroup_stat delta; 145 struct cgroup_base_stat delta;
146 unsigned seq; 146 unsigned seq;
147 147
148 lockdep_assert_held(&cgroup_rstat_mutex); 148 lockdep_assert_held(&cgroup_rstat_mutex);
149 149
150 /* fetch the current per-cpu values */ 150 /* fetch the current per-cpu values */
151 do { 151 do {
152 seq = __u64_stats_fetch_begin(&rstatc->sync); 152 seq = __u64_stats_fetch_begin(&rstatc->bsync);
153 cputime = rstatc->cputime; 153 cputime = rstatc->bstat.cputime;
154 } while (__u64_stats_fetch_retry(&rstatc->sync, seq)); 154 } while (__u64_stats_fetch_retry(&rstatc->bsync, seq));
155 155
156 /* accumulate the deltas to propgate */ 156 /* accumulate the deltas to propgate */
157 delta.cputime.utime = cputime.utime - last_cputime->utime; 157 delta.cputime.utime = cputime.utime - last_cputime->utime;
@@ -161,13 +161,13 @@ static void cgroup_cpu_stat_flush_one(struct cgroup *cgrp, int cpu)
161 *last_cputime = cputime; 161 *last_cputime = cputime;
162 162
163 /* transfer the pending stat into delta */ 163 /* transfer the pending stat into delta */
164 cgroup_stat_accumulate(&delta, &cgrp->pending_stat); 164 cgroup_base_stat_accumulate(&delta, &cgrp->pending_bstat);
165 memset(&cgrp->pending_stat, 0, sizeof(cgrp->pending_stat)); 165 memset(&cgrp->pending_bstat, 0, sizeof(cgrp->pending_bstat));
166 166
167 /* propagate delta into the global stat and the parent's pending */ 167 /* propagate delta into the global stat and the parent's pending */
168 cgroup_stat_accumulate(&cgrp->stat, &delta); 168 cgroup_base_stat_accumulate(&cgrp->bstat, &delta);
169 if (parent) 169 if (parent)
170 cgroup_stat_accumulate(&parent->pending_stat, &delta); 170 cgroup_base_stat_accumulate(&parent->pending_bstat, &delta);
171} 171}
172 172
173/* see cgroup_rstat_flush() */ 173/* see cgroup_rstat_flush() */
@@ -184,7 +184,7 @@ static void cgroup_rstat_flush_locked(struct cgroup *cgrp)
184 184
185 raw_spin_lock_irq(cpu_lock); 185 raw_spin_lock_irq(cpu_lock);
186 while ((pos = cgroup_rstat_cpu_pop_updated(pos, cgrp, cpu))) 186 while ((pos = cgroup_rstat_cpu_pop_updated(pos, cgrp, cpu)))
187 cgroup_cpu_stat_flush_one(pos, cpu); 187 cgroup_base_stat_flush(pos, cpu);
188 raw_spin_unlock_irq(cpu_lock); 188 raw_spin_unlock_irq(cpu_lock);
189 } 189 }
190} 190}
@@ -208,19 +208,19 @@ void cgroup_rstat_flush(struct cgroup *cgrp)
208} 208}
209 209
210static struct cgroup_rstat_cpu * 210static struct cgroup_rstat_cpu *
211cgroup_cpu_stat_account_begin(struct cgroup *cgrp) 211cgroup_base_stat_cputime_account_begin(struct cgroup *cgrp)
212{ 212{
213 struct cgroup_rstat_cpu *rstatc; 213 struct cgroup_rstat_cpu *rstatc;
214 214
215 rstatc = get_cpu_ptr(cgrp->rstat_cpu); 215 rstatc = get_cpu_ptr(cgrp->rstat_cpu);
216 u64_stats_update_begin(&rstatc->sync); 216 u64_stats_update_begin(&rstatc->bsync);
217 return rstatc; 217 return rstatc;
218} 218}
219 219
220static void cgroup_cpu_stat_account_end(struct cgroup *cgrp, 220static void cgroup_base_stat_cputime_account_end(struct cgroup *cgrp,
221 struct cgroup_rstat_cpu *rstatc) 221 struct cgroup_rstat_cpu *rstatc)
222{ 222{
223 u64_stats_update_end(&rstatc->sync); 223 u64_stats_update_end(&rstatc->bsync);
224 cgroup_rstat_cpu_updated(cgrp, smp_processor_id()); 224 cgroup_rstat_cpu_updated(cgrp, smp_processor_id());
225 put_cpu_ptr(rstatc); 225 put_cpu_ptr(rstatc);
226} 226}
@@ -229,9 +229,9 @@ void __cgroup_account_cputime(struct cgroup *cgrp, u64 delta_exec)
229{ 229{
230 struct cgroup_rstat_cpu *rstatc; 230 struct cgroup_rstat_cpu *rstatc;
231 231
232 rstatc = cgroup_cpu_stat_account_begin(cgrp); 232 rstatc = cgroup_base_stat_cputime_account_begin(cgrp);
233 rstatc->cputime.sum_exec_runtime += delta_exec; 233 rstatc->bstat.cputime.sum_exec_runtime += delta_exec;
234 cgroup_cpu_stat_account_end(cgrp, rstatc); 234 cgroup_base_stat_cputime_account_end(cgrp, rstatc);
235} 235}
236 236
237void __cgroup_account_cputime_field(struct cgroup *cgrp, 237void __cgroup_account_cputime_field(struct cgroup *cgrp,
@@ -239,26 +239,26 @@ void __cgroup_account_cputime_field(struct cgroup *cgrp,
239{ 239{
240 struct cgroup_rstat_cpu *rstatc; 240 struct cgroup_rstat_cpu *rstatc;
241 241
242 rstatc = cgroup_cpu_stat_account_begin(cgrp); 242 rstatc = cgroup_base_stat_cputime_account_begin(cgrp);
243 243
244 switch (index) { 244 switch (index) {
245 case CPUTIME_USER: 245 case CPUTIME_USER:
246 case CPUTIME_NICE: 246 case CPUTIME_NICE:
247 rstatc->cputime.utime += delta_exec; 247 rstatc->bstat.cputime.utime += delta_exec;
248 break; 248 break;
249 case CPUTIME_SYSTEM: 249 case CPUTIME_SYSTEM:
250 case CPUTIME_IRQ: 250 case CPUTIME_IRQ:
251 case CPUTIME_SOFTIRQ: 251 case CPUTIME_SOFTIRQ:
252 rstatc->cputime.stime += delta_exec; 252 rstatc->bstat.cputime.stime += delta_exec;
253 break; 253 break;
254 default: 254 default: