From: Rik van Riel <riel@redhat.com>
To: Davidlohr Bueso <davidlohr.bueso@hp.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>,
Emmanuel Benisty <benisty.e@gmail.com>,
"Vinod, Chegu" <chegu_vinod@hp.com>,
"Low, Jason" <jason.low2@hp.com>,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
"H. Peter Anvin" <hpa@zytor.com>,
Andrew Morton <akpm@linux-foundation.org>,
aquini@redhat.com, Michel Lespinasse <walken@google.com>,
Ingo Molnar <mingo@kernel.org>,
Larry Woodman <lwoodman@redhat.com>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Steven Rostedt <rostedt@goodmis.org>,
Thomas Gleixner <tglx@linutronix.de>
Subject: [PATCH v2 6/4] ipc: open code and rename sem_lock
Date: Wed, 6 Mar 2013 17:14:43 -0500 [thread overview]
Message-ID: <20130306171443.6a1ee9d6@cuia.bos.redhat.com> (raw)
In-Reply-To: <1362476149.2225.50.camel@buesod1.americas.hpqcorp.net>
Rename sem_lock to sem_obtain_lock, so we can introduce a sem_lock
function later that only locks the sem_array and does nothing else.
Open code the locking from ipc_lock in sem_obtain_lock, so we can
introduce finer grained locking for the sem_array in the next patch.
Signed-off-by: Rik van Riel <riel@redhat.com>
---
ipc/sem.c | 23 +++++++++++++++++++----
1 files changed, 19 insertions(+), 4 deletions(-)
diff --git a/ipc/sem.c b/ipc/sem.c
index efb49e7..d92ba32 100644
--- a/ipc/sem.c
+++ b/ipc/sem.c
@@ -194,14 +194,29 @@ void __init sem_init (void)
* sem_lock_(check_) routines are called in the paths where the rw_mutex
* is not held.
*/
-static inline struct sem_array *sem_lock(struct ipc_namespace *ns, int id)
+static inline struct sem_array *sem_obtain_lock(struct ipc_namespace *ns, int id)
{
- struct kern_ipc_perm *ipcp = ipc_lock(&sem_ids(ns), id);
+ struct kern_ipc_perm *ipcp;
+ rcu_read_lock();
+ ipcp = ipc_obtain_object(&sem_ids(ns), id);
if (IS_ERR(ipcp))
- return (struct sem_array *)ipcp;
+ goto err1;
+
+ write_lock(&ipcp->lock);
+
+ /* ipc_rmid() may have already freed the ID while write_lock
+ * was spinning: verify that the structure is still valid
+ */
+ if (ipcp->deleted)
+ goto err0;
return container_of(ipcp, struct sem_array, sem_perm);
+err0:
+ write_unlock(&ipcp->lock);
+err1:
+ rcu_read_unlock();
+ return ERR_PTR(-EINVAL);
}
static inline struct sem_array *sem_obtain_object(struct ipc_namespace *ns, int id)
@@ -1558,7 +1573,7 @@ SYSCALL_DEFINE4(semtimedop, int, semid, struct sembuf __user *, tsops,
goto out_free;
}
- sma = sem_lock(ns, semid);
+ sma = sem_obtain_lock(ns, semid);
/*
* Wait until it's guaranteed that no wakeup_sem_queue_do() is ongoing.
next prev parent reply other threads:[~2013-03-06 22:15 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-05 9:35 [PATCH v2 0/4] ipc: reduce ipc lock contention Davidlohr Bueso
2013-03-05 15:40 ` Linus Torvalds
2013-03-06 7:13 ` Davidlohr Bueso
2013-03-06 16:01 ` Linus Torvalds
2013-03-05 17:10 ` Rik van Riel
2013-03-05 19:42 ` Waiman Long
2013-03-05 20:52 ` Linus Torvalds
2013-03-05 20:53 ` Rik van Riel
2013-03-06 3:46 ` Waiman Long
2013-03-06 3:53 ` Rik van Riel
2013-03-06 7:14 ` Davidlohr Bueso
2013-03-07 8:45 ` Peter Zijlstra
2013-03-07 12:55 ` Chris Mason
2013-03-07 15:54 ` Dave Kleikamp
2013-03-07 16:42 ` Chris Mason
2013-03-06 22:13 ` [PATCH v2 5/4] ipc: replace ipc_perm.lock with an rwlock Rik van Riel
2013-03-06 22:14 ` Rik van Riel [this message]
2013-03-06 22:15 ` [PATCH v2 7/4] ipc: fine grained locking for semtimedop Rik van Riel
2013-03-06 22:57 ` Linus Torvalds
2013-03-06 23:09 ` Rik van Riel
2013-03-07 1:36 ` Davidlohr Bueso
2013-03-07 20:55 ` Rik van Riel
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=20130306171443.6a1ee9d6@cuia.bos.redhat.com \
--to=riel@redhat.com \
--cc=a.p.zijlstra@chello.nl \
--cc=akpm@linux-foundation.org \
--cc=aquini@redhat.com \
--cc=benisty.e@gmail.com \
--cc=chegu_vinod@hp.com \
--cc=davidlohr.bueso@hp.com \
--cc=hpa@zytor.com \
--cc=jason.low2@hp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lwoodman@redhat.com \
--cc=mingo@kernel.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=walken@google.com \
/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
all inboxes | Powered by JetHome®