diff options
author | Tejun Heo <tj@kernel.org> | 2013-08-08 20:11:23 -0400 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2013-08-08 20:11:23 -0400 |
commit | 6387698699afd72d6304566fb6ccf84bffe07c56 (patch) | |
tree | 9440e96fa8e5adce62409a5b0e40984dfedaada3 /kernel | |
parent | a7c6d554aa01236ac2a9f851ab0f75704f76dfa2 (diff) |
cgroup: add css_parent()
Currently, controllers have to explicitly follow the cgroup hierarchy
to find the parent of a given css. cgroup is moving towards using
cgroup_subsys_state as the main controller interface construct, so
let's provide a way to climb the hierarchy using just csses.
This patch implements css_parent() which, given a css, returns its
parent. The function is guarnateed to valid non-NULL parent css as
long as the target css is not at the top of the hierarchy.
freezer, cpuset, cpu, cpuacct, hugetlb, memory, net_cls and devices
are converted to use css_parent() instead of accessing cgroup->parent
directly.
* __parent_ca() is dropped from cpuacct and its usage is replaced with
parent_ca(). The only difference between the two was NULL test on
cgroup->parent which is now embedded in css_parent() making the
distinction moot. Note that eventually a css->parent field will be
added to css and the NULL check in css_parent() will go away.
This patch shouldn't cause any behavior differences.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Li Zefan <lizefan@huawei.com>
Diffstat (limited to 'kernel')
-rw-r--r-- | kernel/cgroup_freezer.c | 8 | ||||
-rw-r--r-- | kernel/cpuset.c | 6 | ||||
-rw-r--r-- | kernel/sched/core.c | 9 | ||||
-rw-r--r-- | kernel/sched/cpuacct.c | 11 |
4 files changed, 8 insertions, 26 deletions
diff --git a/kernel/cgroup_freezer.c b/kernel/cgroup_freezer.c index 1db686e47a22..657a73cd44c4 100644 --- a/kernel/cgroup_freezer.c +++ b/kernel/cgroup_freezer.c | |||
@@ -62,11 +62,7 @@ static inline struct freezer *task_freezer(struct task_struct *task) | |||
62 | 62 | ||
63 | static struct freezer *parent_freezer(struct freezer *freezer) | 63 | static struct freezer *parent_freezer(struct freezer *freezer) |
64 | { | 64 | { |
65 | struct cgroup *pcg = freezer->css.cgroup->parent; | 65 | return css_freezer(css_parent(&freezer->css)); |
66 | |||
67 | if (pcg) | ||
68 | return cgroup_freezer(pcg); | ||
69 | return NULL; | ||
70 | } | 66 | } |
71 | 67 | ||
72 | bool cgroup_freezing(struct task_struct *task) | 68 | bool cgroup_freezing(struct task_struct *task) |
@@ -234,7 +230,7 @@ static void freezer_fork(struct task_struct *task) | |||
234 | * The root cgroup is non-freezable, so we can skip the | 230 | * The root cgroup is non-freezable, so we can skip the |
235 | * following check. | 231 | * following check. |
236 | */ | 232 | */ |
237 | if (!freezer->css.cgroup->parent) | 233 | if (!parent_freezer(freezer)) |
238 | goto out; | 234 | goto out; |
239 | 235 | ||
240 | spin_lock_irq(&freezer->lock); | 236 | spin_lock_irq(&freezer->lock); |
diff --git a/kernel/cpuset.c b/kernel/cpuset.c index 6e9cbdde25bd..259a4af37e69 100644 --- a/kernel/cpuset.c +++ b/kernel/cpuset.c | |||
@@ -133,11 +133,7 @@ static inline struct cpuset *task_cs(struct task_struct *task) | |||
133 | 133 | ||
134 | static inline struct cpuset *parent_cs(struct cpuset *cs) | 134 | static inline struct cpuset *parent_cs(struct cpuset *cs) |
135 | { | 135 | { |
136 | struct cgroup *pcgrp = cs->css.cgroup->parent; | 136 | return css_cs(css_parent(&cs->css)); |
137 | |||
138 | if (pcgrp) | ||
139 | return cgroup_cs(pcgrp); | ||
140 | return NULL; | ||
141 | } | 137 | } |
142 | 138 | ||
143 | #ifdef CONFIG_NUMA | 139 | #ifdef CONFIG_NUMA |
diff --git a/kernel/sched/core.c b/kernel/sched/core.c index 5bccb0277129..7a10742b389a 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c | |||
@@ -7114,13 +7114,10 @@ static struct cgroup_subsys_state *cpu_cgroup_css_alloc(struct cgroup *cgrp) | |||
7114 | static int cpu_cgroup_css_online(struct cgroup *cgrp) | 7114 | static int cpu_cgroup_css_online(struct cgroup *cgrp) |
7115 | { | 7115 | { |
7116 | struct task_group *tg = cgroup_tg(cgrp); | 7116 | struct task_group *tg = cgroup_tg(cgrp); |
7117 | struct task_group *parent; | 7117 | struct task_group *parent = css_tg(css_parent(&tg->css)); |
7118 | 7118 | ||
7119 | if (!cgrp->parent) | 7119 | if (parent) |
7120 | return 0; | 7120 | sched_online_group(tg, parent); |
7121 | |||
7122 | parent = cgroup_tg(cgrp->parent); | ||
7123 | sched_online_group(tg, parent); | ||
7124 | return 0; | 7121 | return 0; |
7125 | } | 7122 | } |
7126 | 7123 | ||
diff --git a/kernel/sched/cpuacct.c b/kernel/sched/cpuacct.c index 8ccfa10cc89f..f6926a149a71 100644 --- a/kernel/sched/cpuacct.c +++ b/kernel/sched/cpuacct.c | |||
@@ -50,16 +50,9 @@ static inline struct cpuacct *task_ca(struct task_struct *tsk) | |||
50 | return css_ca(task_css(tsk, cpuacct_subsys_id)); | 50 | return css_ca(task_css(tsk, cpuacct_subsys_id)); |
51 | } | 51 | } |
52 | 52 | ||
53 | static inline struct cpuacct *__parent_ca(struct cpuacct *ca) | ||
54 | { | ||
55 | return cgroup_ca(ca->css.cgroup->parent); | ||
56 | } | ||
57 | |||
58 | static inline struct cpuacct *parent_ca(struct cpuacct *ca) | 53 | static inline struct cpuacct *parent_ca(struct cpuacct *ca) |
59 | { | 54 | { |
60 | if (!ca->css.cgroup->parent) | 55 | return css_ca(css_parent(&ca->css)); |
61 | return NULL; | ||
62 | return cgroup_ca(ca->css.cgroup->parent); | ||
63 | } | 56 | } |
64 | 57 | ||
65 | static DEFINE_PER_CPU(u64, root_cpuacct_cpuusage); | 58 | static DEFINE_PER_CPU(u64, root_cpuacct_cpuusage); |
@@ -284,7 +277,7 @@ void cpuacct_account_field(struct task_struct *p, int index, u64 val) | |||
284 | while (ca != &root_cpuacct) { | 277 | while (ca != &root_cpuacct) { |
285 | kcpustat = this_cpu_ptr(ca->cpustat); | 278 | kcpustat = this_cpu_ptr(ca->cpustat); |
286 | kcpustat->cpustat[index] += val; | 279 | kcpustat->cpustat[index] += val; |
287 | ca = __parent_ca(ca); | 280 | ca = parent_ca(ca); |
288 | } | 281 | } |
289 | rcu_read_unlock(); | 282 | rcu_read_unlock(); |
290 | } | 283 | } |