linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Robert Love <rml@tech9.net>
To: Linus Torvalds <torvalds@transmeta.com>
Cc: Andrew Morton <akpm@zip.com.au>,
	riel@conectiva.com.br, linux-kernel@vger.kernel.org,
	linux-mm@kvack.org
Subject: Re: [PATCH] low-latency zap_page_range
Date: 22 Jul 2002 11:22:25 -0700	[thread overview]
Message-ID: <1027362145.932.49.camel@sinai> (raw)
In-Reply-To: <Pine.LNX.4.44.0207221103430.2928-100000@home.transmeta.com>

On Mon, 2002-07-22 at 11:05, Linus Torvalds wrote:

> How about adding an "cond_resched_lock()" primitive?
> 
> You can do it better as a primitive than as the written-out thing (the
> spin_unlock() doesn't need to conditionally test the scheduling point
> again, it can just unconditionally call schedule())
> 
> And there might be other places that want to drop a lock before scheduling
> anyway.

Great idea.  I have similar functions in my lock-break patch...

This introduces "cond_resched_lock()" and "break_spin_lock()".  Both
take a lock has a parameter.  The former only drops the locks and
reschedules if need_resched is set.  It is optimized to only check once,
etc.  The later simply unlocks then relocks.

Patch is against your BK tree.

	Robert Love

diff -urN linux-2.5.27/include/linux/sched.h linux/include/linux/sched.h
--- linux-2.5.27/include/linux/sched.h	Sat Jul 20 12:11:07 2002
+++ linux/include/linux/sched.h	Mon Jul 22 11:16:55 2002
@@ -865,6 +867,30 @@
 		__cond_resched();
 }
 
+/*
+ * cond_resched_lock() - if a reschedule is pending, drop the given lock,
+ * call schedule, and on return reacquire the lock.  Note this assumes
+ * the given lock is the _only_ held lock and otherwise you are not atomic.
+ */
+static inline void cond_resched_lock(spinlock_t * lock)
+{
+	if (need_resched()) {
+		spin_unlock_no_resched(lock);
+		__cond_resched();
+		spin_lock(lock);
+	}
+}
+
+/*
+ * break_spin_lock - drop and immeditately reacquire the given lock.  This
+ * creates a preemption point if it is the only held lock.
+ */
+static inline void break_spin_lock(spinlock_t * lock)
+{
+	spin_unlock(lock);
+	spin_lock(lock);
+}
+
 /* Reevaluate whether the task has signals pending delivery.
    This is required every time the blocked sigset_t changes.
    Athread cathreaders should have t->sigmask_lock.  */

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/

  reply	other threads:[~2002-07-22 18:22 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-20 20:20 Robert Love
2002-07-22  5:14 ` Andrew Morton
2002-07-22 17:58   ` Robert Love
2002-07-22 18:05     ` Linus Torvalds
2002-07-22 18:22       ` Robert Love [this message]
2002-07-22 18:28       ` Robert Love
2002-07-22 18:40     ` Andrew Morton
2002-07-22 18:50       ` Robert Love

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=1027362145.932.49.camel@sinai \
    --to=rml@tech9.net \
    --cc=akpm@zip.com.au \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=riel@conectiva.com.br \
    --cc=torvalds@transmeta.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