From: npiggin@suse.de
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Manfred Spraul <manfred@colorfullife.com>,
Nadia Derbey <Nadia.Derbey@bull.net>,
Pierre Peiffer <peifferp@gmail.com>,
linux-kernel@vger.kernel.org
Subject: [patch 2/4] ipc: sem use list operations
Date: Tue, 11 Aug 2009 21:09:04 +1000 [thread overview]
Message-ID: <20090811111606.997443191@suse.de> (raw)
In-Reply-To: 20090811110902.255877673@suse.de
[-- Attachment #1: ipc-sem-use-list-ops.patch --]
[-- Type: text/plain, Size: 2838 bytes --]
Signed-off-by: Nick Piggin <npiggin@suse.de>
---
ipc/sem.c | 79 +++++++++++++++++++++++++-------------------------------------
1 file changed, 33 insertions(+), 46 deletions(-)
Index: linux-2.6/ipc/sem.c
===================================================================
--- linux-2.6.orig/ipc/sem.c
+++ linux-2.6/ipc/sem.c
@@ -402,58 +402,45 @@ undo:
*/
static void update_queue (struct sem_array * sma)
{
- int error;
- struct sem_queue * q;
+ struct sem_queue *q, *tq;
+
+again:
+ list_for_each_entry_safe(q, tq, &sma->sem_pending, list) {
+ int error;
+ int alter;
- q = list_entry(sma->sem_pending.next, struct sem_queue, list);
- while (&q->list != &sma->sem_pending) {
error = try_atomic_semop(sma, q->sops, q->nsops,
q->undo, q->pid);
/* Does q->sleeper still need to sleep? */
- if (error <= 0) {
- struct sem_queue *n;
+ if (error > 0)
+ continue;
+
+ list_del(&q->list);
+
+ /*
+ * The next operation that must be checked depends on the type
+ * of the completed operation:
+ * - if the operation modified the array, then restart from the
+ * head of the queue and check for threads that might be
+ * waiting for semaphore values to become 0.
+ * - if the operation didn't modify the array, then just
+ * continue.
+ */
+ alter = q->alter;
+
+ /* wake up the waiting thread */
+ q->status = IN_WAKEUP;
+
+ wake_up_process(q->sleeper);
+ /* hands-off: q will disappear immediately after
+ * writing q->status.
+ */
+ smp_wmb();
+ q->status = error;
- /*
- * Continue scanning. The next operation
- * that must be checked depends on the type of the
- * completed operation:
- * - if the operation modified the array, then
- * restart from the head of the queue and
- * check for threads that might be waiting
- * for semaphore values to become 0.
- * - if the operation didn't modify the array,
- * then just continue.
- * The order of list_del() and reading ->next
- * is crucial: In the former case, the list_del()
- * must be done first [because we might be the
- * first entry in ->sem_pending], in the latter
- * case the list_del() must be done last
- * [because the list is invalid after the list_del()]
- */
- if (q->alter) {
- list_del(&q->list);
- n = list_entry(sma->sem_pending.next,
- struct sem_queue, list);
- } else {
- n = list_entry(q->list.next, struct sem_queue,
- list);
- list_del(&q->list);
- }
-
- /* wake up the waiting thread */
- q->status = IN_WAKEUP;
-
- wake_up_process(q->sleeper);
- /* hands-off: q will disappear immediately after
- * writing q->status.
- */
- smp_wmb();
- q->status = error;
- q = n;
- } else {
- q = list_entry(q->list.next, struct sem_queue, list);
- }
+ if (alter)
+ goto again;
}
}
next prev parent reply other threads:[~2009-08-11 11:54 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-08-11 11:09 [patch 0/4] ipc sem improvements npiggin
2009-08-11 11:09 ` [patch 1/4] ipc: sem optimise undo list search npiggin
2009-08-16 13:17 ` Manfred Spraul
2009-08-11 11:09 ` npiggin [this message]
2009-08-16 13:18 ` [patch 2/4] ipc: sem use list operations Manfred Spraul
2009-08-11 11:09 ` [patch 3/4] ipc: sem preempt improve npiggin
2009-08-16 13:20 ` Manfred Spraul
2009-08-11 11:09 ` [patch 4/4] ipc: sem optimise simple operations npiggin
2009-08-11 18:19 ` Manfred Spraul
2009-08-11 18:23 ` Zach Brown
2009-08-12 4:07 ` Nick Piggin
2009-08-12 18:35 ` Manfred Spraul
2009-08-14 8:58 ` Nick Piggin
2009-08-14 17:53 ` Manfred Spraul
2009-08-11 20:07 ` Cyrill Gorcunov
2009-08-12 4:48 ` Nick Piggin
2009-08-12 5:43 ` Cyrill Gorcunov
2009-08-14 18:48 ` Manfred Spraul
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=20090811111606.997443191@suse.de \
--to=npiggin@suse.de \
--cc=Nadia.Derbey@bull.net \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=manfred@colorfullife.com \
--cc=peifferp@gmail.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