mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Michel Lespinasse <walken@google.com>
To: linux-kernel@vger.kernel.org, anton@samba.org, hpa@zytor.com,
	mingo@kernel.org, arjan@linux.intel.com, a.p.zijlstra@chello.nl,
	torvalds@linux-foundation.org, alex.shi@intel.com,
	yuanhan.liu@linux.intel.com, dhowells@redhat.com,
	akpm@linux-foundation.org, tglx@linutronix.de
Subject: [PATCH 2/4] rwsem: shorter spinlocked section in rwsem_down_failed_common()
Date: Fri,  8 Feb 2013 18:45:35 -0800	[thread overview]
Message-ID: <1360377937-16297-3-git-send-email-walken@google.com> (raw)
In-Reply-To: <1360377937-16297-1-git-send-email-walken@google.com>

This change reduces the size of the spinlocked and TASK_UNINTERRUPTIBLE
sections in rwsem_down_failed_common():

- We only need the sem->wait_lock to insert ourselves on the wait_list;
  the waiter node can be prepared outside of the wait_lock.

- The task state only needs to be set to TASK_UNINTERRUPTIBLE immediately
  before testing waiter.task to see if someone woke us; it doesn't need to
  protect the entire function.

Signed-off-by: Michel Lespinasse <walken@google.com>

---
 lib/rwsem.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/lib/rwsem.c b/lib/rwsem.c
index 4a6ff093a433..cd2d803cbbe4 100644
--- a/lib/rwsem.c
+++ b/lib/rwsem.c
@@ -180,14 +180,12 @@ rwsem_down_failed_common(struct rw_semaphore *sem,
 	struct task_struct *tsk = current;
 	signed long count;
 
-	set_task_state(tsk, TASK_UNINTERRUPTIBLE);
-
 	/* set up my own style of waitqueue */
-	raw_spin_lock_irq(&sem->wait_lock);
 	waiter.task = tsk;
 	waiter.type = type;
 	get_task_struct(tsk);
 
+	raw_spin_lock_irq(&sem->wait_lock);
 	if (list_empty(&sem->wait_list))
 		adjustment += RWSEM_WAITING_BIAS;
 	list_add_tail(&waiter.list, &sem->wait_list);
@@ -210,11 +208,11 @@ rwsem_down_failed_common(struct rw_semaphore *sem,
 	raw_spin_unlock_irq(&sem->wait_lock);
 
 	/* wait to be given the lock */
-	for (;;) {
+	while (true) {
+		set_task_state(tsk, TASK_UNINTERRUPTIBLE);
 		if (!waiter.task)
 			break;
 		schedule();
-		set_task_state(tsk, TASK_UNINTERRUPTIBLE);
 	}
 
 	tsk->state = TASK_RUNNING;
-- 
1.8.1

  parent reply	other threads:[~2013-02-09  2:46 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-02-09  2:45 [PATCH 0/4] rwsem: Implement writer lock-stealing Michel Lespinasse
2013-02-09  2:45 ` [PATCH 1/4] rwsem: make the waiter type an enumeration rather than a bitmask Michel Lespinasse
2013-02-09  2:45 ` Michel Lespinasse [this message]
2013-02-09  2:45 ` [PATCH 3/4] rwsem: implement write lock stealing Michel Lespinasse
2013-02-09  7:30   ` Hillf Danton
2013-02-09  7:42     ` Michel Lespinasse
2013-02-09 13:11       ` Hillf Danton
2013-02-09  2:45 ` [PATCH 4/4] x86 rwsem: avoid taking slow path when stealing write lock Michel Lespinasse
2013-02-13 13:55 ` [PATCH 0/4] rwsem: Implement writer lock-stealing Alex Shi
2013-02-13 14:49   ` Ingo Molnar
2013-02-14  1:31     ` Michel Lespinasse
2013-02-14 12:08       ` Alex Shi
2013-02-20  8:50       ` Alex Shi
2013-02-20 10:40         ` Ingo Molnar
2013-02-20 16:50         ` Michel Lespinasse

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=1360377937-16297-3-git-send-email-walken@google.com \
    --to=walken@google.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=akpm@linux-foundation.org \
    --cc=alex.shi@intel.com \
    --cc=anton@samba.org \
    --cc=arjan@linux.intel.com \
    --cc=dhowells@redhat.com \
    --cc=hpa@zytor.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    --cc=yuanhan.liu@linux.intel.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®