Re: 2.2.7 Alpha Semaphore Bug

Ivan Kokshaysky (ink@jurassic.park.msu.ru)
Fri, 7 May 1999 20:47:29 +0400


On Thu, May 06, 1999 at 02:21:06PM -0500, Kenneth Preslan wrote:
> Hi,
>
> I'm having more problems with semaphores on a LX164 Alpha with 2.2.7.
>
[...]
>
> The problem is that the thread doesn't sleep when the counter of the semaphore
> reaches zero. The counter of the semaphore goes negative and the thread
> keeps going. If the up() function was called on the semaphore 5 times,
> the thread eventually goes to sleep when the counter reaches -5.
>
[...]

*Sigh*. This time the problem is in up(). We should not increment
waking if count > 0 in wake_one_more().

Ivan.

--- linux/include/asm-alpha/semaphore-helper.h.orig Thu Apr 15 16:42:32 1999
+++ linux/include/asm-alpha/semaphore-helper.h Fri May 7 19:59:46 1999
@@ -18,7 +18,23 @@
static inline void
wake_one_more(struct semaphore * sem)
{
- atomic_inc(&sem->waking);
+ long tmp, tmp1;
+
+ /* if (count <= 0) waking++ */
+ /* An atomic conditional increment. */
+ __asm__ __volatile__(
+ "1: ldq_l %0,%2\n"
+ " addq %0,%3,%1\n"
+ " addl %0,0,%0\n"
+ " bgt %0,2f\n"
+ " stq_c %1,%2\n"
+ " beq %1,3f\n"
+ "2:\n"
+ ".section .text2,\"ax\"\n"
+ "3: br 1b\n"
+ ".previous"
+ : "=&r"(tmp), "=&r"(tmp1), "=m"(*sem)
+ : "r"(0x0000000100000000));
}

static inline int

-
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/