RE: Bug in ia64 specific down() function??

From: Chen, Kenneth W <kenneth.w.chen_at_intel.com>
Date: 2006-01-14 09:26:54
Zoltan Menyhart wrote on Friday, January 13, 2006 8:25 AM
> Chen, Kenneth W wrote:
> > The memory order semantics for include/asm-ia64/semaphore.h:down()
> > doesn't look right.  It is using atomic_dec_return, which eventually
> > translate into ia64_fetch_and_add() that uses release semantics.
> > Shouldn't it use acquire semantics?
> 
> What about this one:
> 
> --- linux-2.6.15-test/include/asm-ia64/semaphore.h	2006-01-10 13:54:31.000000000 +0100
> +++ linux-2.6.15-test-down/include/asm-ia64/semaphore.h	2006-01-13 16:16:04.000000000 +0100
> @@ -61,7 +61,7 @@ down (struct semaphore * sem)
>  down (struct semaphore *sem)
>  {
>  	might_sleep();
> -	if (atomic_dec_return(&sem->count) < 0)
> +	if (ia64_fetchadd(-1, &sem->count.counter, acq) < 1)
>  		__down(sem);
>  }
>  
> @@ -75,7 +75,7 @@ down_interruptible (struct semaphore * sem)
>  	int ret = 0;
>  
>  	might_sleep();
> -	if (atomic_dec_return(&sem->count) < 0)
> +	if (ia64_fetchadd(-1, &sem->count.counter, acq) < 1)
>  		ret = __down_interruptible(sem);
>  	return ret;
>  }
> @@ -85,7 +85,7 @@ down_trylock (struct semaphore *sem)
>  {
>  	int ret = 0;
>  
> -	if (atomic_dec_return(&sem->count) < 0)
> +	if (ia64_fetchadd(-1, &sem->count.counter, acq) < 1)
>  		ret = __down_trylock(sem);
>  	return ret;
>  }
> @@ -93,7 +93,7 @@ up (struct semaphore *sem)
>  static inline void
>  up (struct semaphore * sem)
>  {
> -	if (atomic_inc_return(&sem->count) <= 0)
> +	if (ia64_fetchadd(1, &sem->count.counter, rel) <= -1)
>  		__up(sem);
>  }

Yeah, looked OK to me.

- Ken

-
To unsubscribe from this list: send the line "unsubscribe linux-ia64" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Received on Sat Jan 14 09:28:37 2006

This archive was generated by hypermail 2.1.8 : 2006-01-14 09:28:44 EST