> On Thu, Aug 02, 2001 at 04:18:52PM -0700, Jack F. Vogel wrote:
> > The URL to access it is: http://lse.sourceforge.net/numa/numalock
> why do you local_irq_save in numa_lock?
If we do not do this, the following can happen:
o Assume that the lock is currently held, but that nobody is
spinning on it.
o Task 1 executes the xadd in numa_lock().
o Task 1 gets interrupted.
o Task 2 (which currently holds the lock) attempts to release it.
It finds that there is a bit in the lock word ("wanted" is nonzero),
but that find_wakeup() always returns -1, since task 1 has not
yet set its spin state up.
This is -not- a hang, but it -does- result in task 2 being delayed while
task 1 completes its interrupt.
There are a few ways of dealing with this:
1. Accept the overhead of the local_irq_save(), as the current code
does. My guess is that this would mean that the lock must be used
on a case-by-case basis, or on an architecture-by-architecture
2. Accept the possibility of some delay for the CPU attempting to hand
off the lock, as noted above. (Not sure that this is really a
problem in real life.)
3. Allow the CPUs to spin on the mask itself, and have two bits per
CPU. This would halve the number of CPUs that the lock could support
(might not be such a disaster), and would mean that there would
be increased memory contention from the CPUs spinning on the lock.
However, since a CPU could atomically get itself into spin state,
there would be no window where interrupts could cause delays.
> Also the xadd check + conditional jump fast path (3 asm instruction
> compared to 2 asm instruction we have right now) should always stay
> inlined in the caller with a jump in the .text.lock if we fail to
> acquire the lock (the .text.lock will 'call failed_numa_lock' or
> something like that), we should only have the slow path in the .c file.
One other way to cut out an instruction or two would be to replace the
current shift in numa_lock() represented by "mask = 1U<<cpu" with a load
from a per-processor data area, such as the one that Andi mentioned in