From: Kirill Tkhai <ktkhai@odin.com>
To: <linux-kernel@vger.kernel.org>
Cc: Oleg Nesterov <oleg@redhat.com>,
Andrew Morton <akpm@linux-foundation.org>,
Ingo Molnar <mingo@redhat.com>,
"Peter Zijlstra" <peterz@infradead.org>,
Michal Hocko <mhocko@suse.cz>, "Rik van Riel" <riel@redhat.com>,
Ionut Alexa <ionut.m.alexa@gmail.com>,
Peter Hurley <peter@hurleysoftware.com>,
Kirill Tkhai <tkhai@yandex.ru>
Subject: [PATCH RFC 07/13] kin_lock: Implement helpers for kin_lock locking.
Date: Mon, 25 May 2015 20:45:25 +0300 [thread overview]
Message-ID: <1432575925.6866.40.camel@odin.com> (raw)
In-Reply-To: <20150525162722.5171.15901.stgit@pro>
Signed-off-by: Kirill Tkhai <ktkhai@odin.com>
---
include/linux/sched.h | 302 +++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 302 insertions(+)
diff --git a/include/linux/sched.h b/include/linux/sched.h
index 58dc09f..6a810f3 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -1835,6 +1835,308 @@ static inline bool should_numa_migrate_memory(struct task_struct *p,
}
#endif
+static inline void write_real_parent_lock(struct task_struct *p)
+{
+ struct task_struct *real_parent;
+ rcu_read_lock();
+again:
+ real_parent = p->real_parent;
+ write_lock(&real_parent->kin_lock);
+ if (real_parent != p->real_parent) {
+ write_unlock(&real_parent->kin_lock);
+ goto again;
+ }
+ rcu_read_unlock();
+}
+
+static inline void write_real_parent_lock_irq(struct task_struct *p)
+{
+ local_irq_disable();
+ write_real_parent_lock(p);
+}
+
+static inline void write_real_parent_unlock(struct task_struct *p)
+{
+ write_unlock(&p->real_parent->kin_lock);
+}
+
+static inline void write_real_parent_unlock_irq(struct task_struct *p)
+{
+ write_unlock_irq(&p->real_parent->kin_lock);
+}
+
+static inline void read_parent_lock(struct task_struct *p)
+{
+ struct task_struct *parent;
+ rcu_read_lock();
+again:
+ parent = p->parent;
+ read_lock(&parent->kin_lock);
+ if (parent != p->parent) {
+ read_unlock(&parent->kin_lock);
+ goto again;
+ }
+ rcu_read_unlock();
+
+}
+
+static inline void read_parent_unlock(struct task_struct *p)
+{
+ read_unlock(&p->parent->kin_lock);
+}
+
+static inline void read_real_parent_lock(struct task_struct *p)
+{
+ struct task_struct *real_parent;
+ rcu_read_lock();
+again:
+ real_parent = p->real_parent;
+ read_lock(&real_parent->kin_lock);
+ if (real_parent != p->real_parent) {
+ read_unlock(&real_parent->kin_lock);
+ goto again;
+ }
+ rcu_read_unlock();
+
+}
+
+static inline void read_real_parent_unlock(struct task_struct *p)
+{
+ read_unlock(&p->real_parent->kin_lock);
+}
+
+static inline void write_parent_lock(struct task_struct *p)
+{
+ struct task_struct *parent;
+ rcu_read_lock();
+again:
+ parent = p->parent;
+ write_lock(&parent->kin_lock);
+ if (parent != p->parent) {
+ write_unlock(&parent->kin_lock);
+ goto again;
+ }
+ rcu_read_unlock();
+}
+
+static inline void write_parent_lock_irq(struct task_struct *p)
+{
+ local_irq_disable();
+ write_parent_lock(p);
+}
+
+static inline void write_parent_unlock(struct task_struct *p)
+{
+ write_unlock(&p->parent->kin_lock);
+}
+
+static inline void write_parent_unlock_irq(struct task_struct *p)
+{
+ write_unlock_irq(&p->parent->kin_lock);
+}
+
+static inline void write_parent_and_given_lock(struct task_struct *child,
+ struct task_struct *given)
+{
+ struct task_struct *parent;
+ rcu_read_lock();
+again:
+ parent = child->parent;
+ if (parent <= given) {
+ write_lock(&parent->kin_lock);
+ if (parent != child->parent) {
+ write_unlock(&parent->kin_lock);
+ goto again;
+ }
+ if (parent != given)
+ write_lock(&given->kin_lock);
+ } else {
+ write_lock(&given->kin_lock);
+ write_lock(&parent->kin_lock);
+ if (parent != child->parent) {
+ write_unlock(&given->kin_lock);
+ write_unlock(&parent->kin_lock);
+ goto again;
+ }
+ }
+ rcu_read_unlock();
+}
+
+static inline void write_parent_and_given_lock_irq(struct task_struct *child,
+ struct task_struct *given)
+{
+ local_irq_disable();
+ write_parent_and_given_lock(child, given);
+}
+
+static inline void read_parent_and_given_lock(struct task_struct *child,
+ struct task_struct *given)
+{
+ struct task_struct *parent;
+ rcu_read_lock();
+again:
+ parent = child->parent;
+ if (parent <= given) {
+ read_lock(&parent->kin_lock);
+ if (parent != child->parent) {
+ read_unlock(&parent->kin_lock);
+ goto again;
+ }
+ if (parent != given)
+ read_lock(&given->kin_lock);
+ } else {
+ read_lock(&given->kin_lock);
+ read_lock(&parent->kin_lock);
+ if (parent != child->parent) {
+ read_unlock(&given->kin_lock);
+ read_unlock(&parent->kin_lock);
+ goto again;
+ }
+ }
+ rcu_read_unlock();
+}
+
+static inline void read_real_parent_and_given_lock(struct task_struct *child,
+ struct task_struct *given)
+{
+ struct task_struct *real_parent;
+ rcu_read_lock();
+again:
+ real_parent = child->real_parent;
+ if (real_parent <= given) {
+ read_lock(&real_parent->kin_lock);
+ if (real_parent != child->real_parent) {
+ read_unlock(&real_parent->kin_lock);
+ goto again;
+ }
+ if (real_parent != given)
+ read_lock(&given->kin_lock);
+ } else {
+ read_lock(&given->kin_lock);
+ read_lock(&real_parent->kin_lock);
+ if (real_parent != child->real_parent) {
+ read_unlock(&given->kin_lock);
+ read_unlock(&real_parent->kin_lock);
+ goto again;
+ }
+ }
+ rcu_read_unlock();
+}
+
+static inline void read_real_parent_and_given_unlock(struct task_struct *child,
+ struct task_struct *given)
+{
+ struct task_struct *real_parent = child->real_parent;
+
+ if (real_parent != given)
+ read_unlock(&real_parent->kin_lock);
+ read_unlock(&given->kin_lock);
+}
+static inline void write_parent_and_real_parent_lock(struct task_struct *child)
+{
+ struct task_struct *parent, *real_parent;
+ rcu_read_lock();
+again:
+ parent = child->parent;
+ real_parent = child->real_parent;
+ if (parent <= real_parent) {
+ write_lock(&parent->kin_lock);
+ if (parent != child->parent) {
+ write_unlock(&parent->kin_lock);
+ goto again;
+ }
+ if (parent != real_parent) {
+ write_lock(&real_parent->kin_lock);
+ if (real_parent != child->real_parent) {
+ write_unlock(&parent->kin_lock);
+ write_unlock(&real_parent->kin_lock);
+ goto again;
+ }
+ }
+ } else {
+ write_lock(&real_parent->kin_lock);
+ write_lock(&parent->kin_lock);
+ if (real_parent != child->real_parent ||
+ parent != child->parent) {
+ write_unlock(&real_parent->kin_lock);
+ write_unlock(&parent->kin_lock);
+ goto again;
+ }
+ }
+ rcu_read_unlock();
+}
+
+static inline void write_parent_and_real_parent_lock_irq(struct task_struct *child)
+{
+ local_irq_disable();
+ write_parent_and_real_parent_lock(child);
+}
+
+static inline void write_parent_and_real_parent_unlock(struct task_struct *child)
+{
+ struct task_struct *parent, *real_parent;
+
+ parent = child->parent;
+ real_parent = child->real_parent;
+
+ write_unlock(&real_parent->kin_lock);
+ if (parent != real_parent)
+ write_unlock(&parent->kin_lock);
+}
+
+static inline void write_parent_and_real_parent_unlock_irq(struct task_struct *child)
+{
+ write_parent_and_real_parent_unlock(child);
+ local_irq_enable();
+}
+
+static inline void read_parent_and_real_parent_lock(struct task_struct *child)
+{
+ struct task_struct *parent, *real_parent;
+ rcu_read_lock();
+again:
+ parent = child->parent;
+ real_parent = child->real_parent;
+ if (parent <= real_parent) {
+ read_lock(&parent->kin_lock);
+ if (parent != child->parent) {
+ read_unlock(&parent->kin_lock);
+ goto again;
+ }
+ if (parent != real_parent) {
+ read_lock(&real_parent->kin_lock);
+ if (real_parent != child->real_parent) {
+ read_unlock(&parent->kin_lock);
+ read_unlock(&real_parent->kin_lock);
+ goto again;
+ }
+ }
+ } else {
+ read_lock(&real_parent->kin_lock);
+ read_lock(&parent->kin_lock);
+ if (real_parent != child->real_parent ||
+ parent != child->parent) {
+ read_unlock(&real_parent->kin_lock);
+ read_unlock(&parent->kin_lock);
+ goto again;
+ }
+ }
+ rcu_read_unlock();
+}
+
+static inline void read_parent_and_real_parent_unlock(struct task_struct *child)
+{
+ struct task_struct *parent, *real_parent;
+
+ parent = child->parent;
+ real_parent = child->real_parent;
+
+ read_unlock(&real_parent->kin_lock);
+ if (parent != real_parent)
+ read_unlock(&parent->kin_lock);
+}
+
+
static inline struct pid *task_pid(struct task_struct *task)
{
return task->pids[PIDTYPE_PID].pid;
next prev parent reply other threads:[~2015-05-25 17:45 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20150525162722.5171.15901.stgit@pro>
2015-05-25 17:44 ` [PATCH RFC 01/13] exit: Clarify choice of new parent in forget_original_parent() Kirill Tkhai
2015-05-25 17:44 ` [PATCH RFC 02/13] rwlock_t: Implement double_write_{,un}lock() Kirill Tkhai
2015-05-25 17:44 ` [PATCH RFC 03/13] pid_ns: Implement rwlock_t pid_ns::cr_lock for locking child_reaper Kirill Tkhai
2015-05-25 17:44 ` [PATCH RFC 04/13] exit: Small refactoring mm_update_next_owner() Kirill Tkhai
2015-05-25 17:45 ` [PATCH RFC 05/13] fs: Refactoring in get_children_pid() Kirill Tkhai
2015-05-25 17:45 ` [PATCH RFC 06/13] core: Add rwlock_t task_list::kin_lock Kirill Tkhai
2015-05-25 17:45 ` Kirill Tkhai [this message]
2015-05-25 17:45 ` [PATCH RFC 08/13] core: Use kin_lock synchronizations between parent and child and for thread group Kirill Tkhai
2015-05-25 17:45 ` [PATCH RFC 09/13] exit: Use for_each_thread() in do_wait() Kirill Tkhai
2015-05-26 19:46 ` Oleg Nesterov
2015-05-27 9:33 ` Kirill Tkhai
2015-05-27 9:42 ` Kirill Tkhai
2015-05-25 17:45 ` [PATCH RFC 10/13] exit: Add struct wait_opts's member held_lock and use it for tasklist_lock Kirill Tkhai
2015-05-25 17:46 ` [PATCH RFC 11/13] exit: Syncronize on kin_lock while do_notify_parent() Kirill Tkhai
2015-05-25 17:46 ` [PATCH RFC 12/13] exit: Delete write dependence on tasklist_lock in exit_notify() Kirill Tkhai
2015-05-25 17:46 ` [PATCH RFC 13/13] core: Nest tasklist_lock into task_struct::kin_lock Kirill Tkhai
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=1432575925.6866.40.camel@odin.com \
--to=ktkhai@odin.com \
--cc=akpm@linux-foundation.org \
--cc=ionut.m.alexa@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mhocko@suse.cz \
--cc=mingo@redhat.com \
--cc=oleg@redhat.com \
--cc=peter@hurleysoftware.com \
--cc=peterz@infradead.org \
--cc=riel@redhat.com \
--cc=tkhai@yandex.ru \
/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