cgroups.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH cgroup/for-3.15-fixes 1/2] cgroup: introduce task_css_is_root()
@ 2014-05-05 22:35 Tejun Heo
       [not found] ` <20140505223557.GU11231-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
  0 siblings, 1 reply; 9+ messages in thread
From: Tejun Heo @ 2014-05-05 22:35 UTC (permalink / raw)
  To: Li Zefan; +Cc: cgroups-u79uwXL29TY76Z2rM5mHXA

From fc4ef71935b1effe8612bfb39c7e3a41a2e2346c Mon Sep 17 00:00:00 2001
From: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Date: Mon, 5 May 2014 18:35:12 -0400

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.

Signed-off-by: Tejun Heo <tj-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
---
 include/linux/cgroup.h | 15 +++++++++++++++
 kernel/cgroup.c        |  3 ++-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index c251585..d60904b 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -473,6 +473,7 @@ struct cftype {
 };
 
 extern struct cgroup_root cgrp_dfl_root;
+extern struct css_set init_css_set;
 
 static inline bool cgroup_on_dfl(const struct cgroup *cgrp)
 {
@@ -700,6 +701,20 @@ static inline struct cgroup_subsys_state *task_css(struct task_struct *task,
 	return task_css_check(task, subsys_id, false);
 }
 
+/**
+ * task_css_is_root - test whether a task belongs to the root css
+ * @task: the target task
+ * @subsys_id: the target subsystem ID
+ *
+ * Test whether @task belongs to the root css on the specified subsystem.
+ * May be invoked in any context.
+ */
+static inline bool task_css_is_root(struct task_struct *task, int subsys_id)
+{
+	return task_css_check(task, subsys_id, true) ==
+		init_css_set.subsys[subsys_id];
+}
+
 static inline struct cgroup *task_cgroup(struct task_struct *task,
 					 int subsys_id)
 {
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 11a03d6..7030b37 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -348,7 +348,7 @@ struct cgrp_cset_link {
  * reference-counted, to improve performance when child cgroups
  * haven't been created.
  */
-static struct css_set init_css_set = {
+struct css_set init_css_set = {
 	.refcount		= ATOMIC_INIT(1),
 	.cgrp_links		= LIST_HEAD_INIT(init_css_set.cgrp_links),
 	.tasks			= LIST_HEAD_INIT(init_css_set.tasks),
@@ -356,6 +356,7 @@ static struct css_set init_css_set = {
 	.mg_preload_node	= LIST_HEAD_INIT(init_css_set.mg_preload_node),
 	.mg_node		= LIST_HEAD_INIT(init_css_set.mg_node),
 };
+EXPORT_SYMBOL_GPL(init_css_set);
 
 static int css_set_count	= 1;	/* 1 for init_css_set */
 
-- 
1.9.0

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-05-13 15:35 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-05 22:35 [PATCH cgroup/for-3.15-fixes 1/2] cgroup: introduce task_css_is_root() Tejun Heo
     [not found] ` <20140505223557.GU11231-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
2014-05-05 22:39   ` [PATCH cgroup/for-3.15-fixes 2/2] cgroup_freezer: replace freezer->lock with freezer_mutex Tejun Heo
     [not found]     ` <20140505223941.GV11231-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
2014-05-08  1:23       ` Li Zefan
2014-05-07  2:50   ` [PATCH cgroup/for-3.15-fixes 1/2] cgroup: introduce task_css_is_root() Li Zefan
     [not found]     ` <53699F6E.3070107-hv44wF8Li93QT0dZR+AlfA@public.gmane.org>
2014-05-07  3:29       ` Tejun Heo
2014-05-07 13:06   ` [PATCH v2 " Tejun Heo
     [not found]     ` <20140507130627.GA16702-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
2014-05-08  1:22       ` Li Zefan
2014-05-08  1:32       ` Tejun Heo
     [not found]         ` <20140508013206.GA2797-Gd/HAXX7CRxy/B6EtB590w@public.gmane.org>
2014-05-13 15:35           ` Tejun Heo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).