diff options
author | Tejun Heo <tj@kernel.org> | 2014-05-07 21:31:17 -0400 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2014-05-13 11:26:27 -0400 |
commit | 5024ae29cd285ce9e736776414da645d3a91828c (patch) | |
tree | 0afef891029af86947869d25b8a3c0e10b6ead69 /include | |
parent | 36c38fb7144aa941dc072ba8f58b2dbe509c0345 (diff) |
cgroup: introduce task_css_is_root()
Determining the css of a task usually requires RCU read lock as that's
the only thing which keeps the returned css accessible till its
reference is acquired; however, testing whether a task belongs to the
root can be performed without dereferencing the returned css by
comparing the returned pointer against the root one in init_css_set[]
which never changes.
Implement task_css_is_root() which can be invoked in any context.
This will be used by the scheduled cgroup_freezer change.
v2: cgroup no longer supports modular controllers. No need to export
init_css_set. Pointed out by Li.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Li Zefan <lizefan@huawei.com>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/cgroup.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index c2515851c1aa..d60904b9e505 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h | |||
@@ -473,6 +473,7 @@ struct cftype { | |||
473 | }; | 473 | }; |
474 | 474 | ||
475 | extern struct cgroup_root cgrp_dfl_root; | 475 | extern struct cgroup_root cgrp_dfl_root; |
476 | extern struct css_set init_css_set; | ||
476 | 477 | ||
477 | static inline bool cgroup_on_dfl(const struct cgroup *cgrp) | 478 | static inline bool cgroup_on_dfl(const struct cgroup *cgrp) |
478 | { | 479 | { |
@@ -700,6 +701,20 @@ static inline struct cgroup_subsys_state *task_css(struct task_struct *task, | |||
700 | return task_css_check(task, subsys_id, false); | 701 | return task_css_check(task, subsys_id, false); |
701 | } | 702 | } |
702 | 703 | ||
704 | /** | ||
705 | * task_css_is_root - test whether a task belongs to the root css | ||
706 | * @task: the target task | ||
707 | * @subsys_id: the target subsystem ID | ||
708 | * | ||
709 | * Test whether @task belongs to the root css on the specified subsystem. | ||
710 | * May be invoked in any context. | ||
711 | */ | ||
712 | static inline bool task_css_is_root(struct task_struct *task, int subsys_id) | ||
713 | { | ||
714 | return task_css_check(task, subsys_id, true) == | ||
715 | init_css_set.subsys[subsys_id]; | ||
716 | } | ||
717 | |||
703 | static inline struct cgroup *task_cgroup(struct task_struct *task, | 718 | static inline struct cgroup *task_cgroup(struct task_struct *task, |
704 | int subsys_id) | 719 | int subsys_id) |
705 | { | 720 | { |