linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Aleksa Sarai <cyphar@cyphar.com>
To: tj@kernel.org, lizefan@huawei.com, mingo@redhat.com,
	peterz@infradead.org
Cc: richard@nod.at, fweisbec@gmail.com, linux-kernel@vger.kernel.org,
	cgroups@vger.kernel.org
Subject: [PATCH v14 2/4] cgroup, block: implement task_get_css()
Date: Tue,  9 Jun 2015 21:32:08 +1000	[thread overview]
Message-ID: <1433849530-22845-3-git-send-email-cyphar@cyphar.com> (raw)
In-Reply-To: <1433849530-22845-1-git-send-email-cyphar@cyphar.com>

From: Tejun Heo <tj@kernel.org>

Implement task_get_css() which find and pins the css for the specified
task and subsys.  As a task is always associated with an online css
for every subsystem except while the css_set update is propagating,
task_get_css() retries till css_tryget_online() succeeds.

Signed-off-by: Tejun Heo <tj@kernel.org>
Cc: Li Zefan <lizefan@huawei.com>
---
 include/linux/cgroup.h | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h
index 82319fb..a593e29 100644
--- a/include/linux/cgroup.h
+++ b/include/linux/cgroup.h
@@ -354,6 +354,31 @@ static inline struct cgroup_subsys_state *task_css(struct task_struct *task,
 }
 
 /**
+ * task_get_css - find and get the css for (task, subsys)
+ * @task: the target task
+ * @subsys_id: the target subsystem ID
+ *
+ * Find the css for the (@task, @subsys_id) combination, increment a
+ * reference on and return it.  This function is guaranteed to return a
+ * valid css.
+ */
+static inline struct cgroup_subsys_state *
+task_get_css(struct task_struct *task, int subsys_id)
+{
+	struct cgroup_subsys_state *css;
+
+	rcu_read_lock();
+	while (true) {
+		css = task_css(task, subsys_id);
+		if (likely(css_tryget_online(css)))
+			break;
+		cpu_relax();
+	}
+	rcu_read_unlock();
+	return css;
+}
+
+/**
  * task_css_is_root - test whether a task belongs to the root css
  * @task: the target task
  * @subsys_id: the target subsystem ID
-- 
2.4.2


  parent reply	other threads:[~2015-06-09 11:33 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-09 11:32 [PATCH v14 0/4] cgroup: add PIDs subsystem Aleksa Sarai
2015-06-09 11:32 ` [PATCH v14 1/4] cgroup: fix uninitialised iterator in for_each_subsys_which Aleksa Sarai
2015-06-10  4:49   ` Tejun Heo
2015-06-09 11:32 ` Aleksa Sarai [this message]
2015-06-09 11:32 ` [PATCH v14 3/4] cgroup: allow a cgroup subsystem to reject a fork Aleksa Sarai
2015-06-09 11:32 ` [PATCH v14 4/4] cgroup: implement the PIDs subsystem Aleksa Sarai
2015-06-10  4:53   ` Tejun Heo
2015-06-10 15:01     ` Aleksa Sarai
2015-06-12 17:21       ` [PATCH] cgroup: add documentation for the PIDs controller Aleksa Sarai
2015-07-14 21:32         ` Tejun Heo
2015-07-14 21:31     ` [PATCH v14 4/4] cgroup: implement the PIDs subsystem Tejun Heo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1433849530-22845-3-git-send-email-cyphar@cyphar.com \
    --to=cyphar@cyphar.com \
    --cc=cgroups@vger.kernel.org \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizefan@huawei.com \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=richard@nod.at \
    --cc=tj@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).