Re: [PATCH] Futexes IV (Fast Lightweight Userspace Semaphores)

Linus Torvalds
2002-03-08T23:42:15Z

On Fri, 8 Mar 2002, Hubertus Franke wrote:
> >
> > I think the next step should be to map in one page of kernel code in a
> > user-readable location, and just do it there.
>
> Your kidding .....
> Seriously, how can we guarantee that we correctly determine the
> lock holder, due to memory corruption problems. If we can't do
> it correctly all the times, why do it at all ?

You don't understand. This has nothing to do with lock holders, or
anything else.

I'm saying that we map in a page at a magic offset (just above the stack),
and that page contains the locking code.

For 386 CPU's (where only UP matters), we can trivially come up with a
lock that doesn't use cmpxchg8b and that isn't SMP-safe. It might even go
into the kernel every time if it has to - ie it _works_, it just isn't
optimal.

> Fail to see why that matters. User level locking is mostly beneficial on SMPs.

That's not the issue AT ALL.

Semaphores are absolutely required on UP too, with threads. There is
_zero_ difference between UP and SMP from a locking perspective in user
space due to the fact that we can be preempted at any time - except from
the cache coherency issue.

> So, you lock the bus for the atomic update. This is UP, nothing's going on
> on the bus anyway.

That's not the point. Nobody has locked the bus in the last ten years: the
cache coherency is done on a cacheline basis, not on the bus.

The point being that the difference between a "decl" and a "lock ; decl"
is about 1:12 or so in performance.

> Even if its a few more cycles, still beats the heck out of using other
> heavyweight kernel APIs

Sure it does. But if the speed of locking matters enough for user-level
locks to matter, don't you think the 1:12 difference matters as well?

Linus