Re: spinaphore conceptual draft

Kyle Moffett
2005-05-30T19:41:47Z

On May 30, 2005, at 15:28:26, Andi Kleen wrote:
> On Mon, May 30, 2005 at 02:04:36PM -0400, Kyle Moffett wrote:
>>> I suspect any attempt to use time stamps in locks is a bad
>>> idea because of this.
>>
>> Something like this could be built only for CPUs that do support that
>> kind of cycle counter.
>
> That gets you into a problem with binary distribution kernels.
> While binary patching works to some extent, it also becomes
> messy pretty quickly.

Well, a runtime-set function-pointer isn't all that bad. Basically
if a simple cycle-counter driver is available, it would use that,
otherwise it would fall back to ordinary spinlock behavior.

>> The idea behind these locks is for bigger systems (8-way or more) for
>> heavily contended locks (say 32 threads doing write() on the same
>> fd).
>
> Didn't Dipankar & co just fix that with their latest RCU patchkit?
> (assuming you mean the FD locks)

That's lock-free FD lookup (open, close, and read/write to a certain
extent). I'm handling something more like serialization on a fifo
accessed in both user context and interrupt context, which in a
traditional implementation would use a spinlock, but with a spinaphore,
one could do this:

In interrupt context:

spinaphore_lock_atomic(&fifo->sph);
put_stuff_in_fifo(fifo,stuff);
spinaphore_unlock(&fifo->sph);

In user context:

spinaphore_lock(&fifo->sph);
put_stuff_in_fifo(fifo,stuff);
spinaphore_unlock(&fifo->sph);

If there are multiple devices generating interrupts to put stuff in the
fifo and multiple processes also trying to put stuff in the fifo, all
bursting on different CPUs, then the fifo lock would be heavily loaded.
If the system had other things it could be doing while waiting for the
FIFO to become available, then it should be able to do those.

Cheers,
Kyle Moffett

-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCM/CS/IT/U d- s++: a18 C++++>$ UB/L/X/*++++(+)>$ P+++(++++)>$
L++++(+++) E W++(+) N+++(++) o? K? w--- O? M++ V? PS+() PE+(-) Y+
PGP+++ t+(+++) 5 X R? tv-(--) b++++(++) DI+ D+ G e->++++$ h!*()>++$
r !y?(-)
------END GEEK CODE BLOCK------