DragonFly BSD
DragonFly kernel List (threaded) for 2005-11
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

lockmgr interlock spinlock conversion patch #1

From: Matthew Dillon <dillon@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 16 Nov 2005 12:42:44 -0800 (PST)

    This patch converts the lock manager's interlock from a token to a 
    spinlock.  This will theoretically fix the race condition that I had to
    work around in kern/vfs_bio.c rev 1.52.

	fetch http://apollo.backplane.com/DFlyMisc/interlock01.patch

    The race condition workaround prints two messages to the console if the
    race occurs.  It is my hope that this patch will result in these warning
    messages no longer occuring:

	"getnewbuf: warning, locked buf %p, race corrected"
	"getnewbuf: warning, BUF_LOCK blocked unexpectedly on buf %p..."

    I have also come up with a solution to implement the equivalent of
    FreeBSD's msleep() (interlocked sleep with release of mutex).  Due
    to the cpu-locality-of-reference abstraction that DragonFly uses, there
    is an ULTRA NIFTY shortcut that DragonFly can take.  All DragonFly
    needs to do is set the cpumask bit in the tsleep/wakeup hash table to
    ensure that a wakeup() being called on another cpu sends an IPI message
    to our cpu.  The critical section we hold then protects us from processing
    the IPI message too early, allowing us to enter the tsleep() after
    releasing the resource without any possibility of a race.  So:

    in_critical_section {
	tsleep_interlock(ident);	/* set cpumask in hash table */
			<--------- wakeup from another cpu can occur here
	tsleep(ident, ...)
			<--------- but processing of the wakeup is defered
				   to here due to our critical section.

    It is yet another example of the advantages of using a
    cpu-locality-of-reference model for safe MP operation instead of a
    mutex model.

					Matthew Dillon 

[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]