Re: [PATCH] include/asm-i386/semaphore.h speedup

Jamie Lokier (lkd@tantalophile.demon.co.uk)
Fri, 15 Jan 1999 19:04:21 +0000


I was looking at this code the other day too.

> I think that (with %0 being "=m" (sem->waiting)) : "0" (sem->waiting))
> the following code ought to work.
>
> 1: lock; decl %0
> jns 2f /* If result >= 0, success */
> lock; incl %0 /* Went too far; go back */
> jg 1b /* If result > 0, retry */
> return 0;
> 2:
> return 1;
>
> Here, we're transiently letting sem->waiting drop below zero.
> As long as nobody gets confused, that should be fine.

It's probably worth preceding this with the original test, `cmpl $0,%0;
jg 2f', to avoid a thundering herd of locked operations.

Remember to do atomic_inc(&sem->waking) in wake_one_more() too.

Having given your code some thought, it looks ok. The retry loop is
obviously very important.

I can't think of any livelock scenarious either, which is a good sign.

-- Jamie

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/