public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* RE: Atomic operations
@ 2002-06-03 19:09 Gregory Giguashvili
  2002-06-03 18:43 ` H. Peter Anvin
  0 siblings, 1 reply; 11+ messages in thread
From: Gregory Giguashvili @ 2002-06-03 19:09 UTC (permalink / raw)
  To: linux-kernel

Peter,

Thanks a lot for your help. 

> atomic_t test_then_add (int i, atomic_t* v)
> {
>    atomic_t old = *v;
>    v->counter += i;
>    return old;
> }
> There is no way to do this (without waiting and trying again type
> code) that I know of on i386.  However, you can test for zeroness of
> the result, or for <= 0, or a few other options.

Could you, please, clarify what you meant saying that there was no way of
doing so. I admit, I'm no expert in i386 assembly, but this operation seems
so simple to me...

Could you, please, suggest some other implementation (with waiting and
trying again - whatever this means)?

test_and_set and test_then_add functions are coming from code written for
IRIX. Solaris has similar functionality. Windows NT also provides these
primitives in Win32 API (possibly implemented not in the most effective way,
according to what you say). The only OS where they are missing is Linux. 

Unfortunately, these primitives became an integral part of our code, which
makes it very painful to change their behavior.

Thanks in advance.
Giga

^ permalink raw reply	[flat|nested] 11+ messages in thread
* RE: Atomic operations
@ 2002-06-04  9:23 Gregory Giguashvili
  0 siblings, 0 replies; 11+ messages in thread
From: Gregory Giguashvili @ 2002-06-04  9:23 UTC (permalink / raw)
  To: Linux Kernel (E-mail)

Hello,

Thanks a lot for your help to all of you...

The last thing, I want to make sure of, is that the following type of code:

int atomic_xadd(int i, atomic_t *v)
{
	int ret;
	__asm__(LOCK "xaddl %1,%0"
		: "=m" (v->counter), "=r" (ret)
		: "0" (v->counter), "1" (i));
	return ret;
}

is less efficient than this one:

int atomic_xadd(int i, atomic_t *v)
{
	asm volatile(LOCK "xaddl %1,%0"
		: "+m" (v->counter), "+r" (i));
	return i;
}

The reason for it is that the first one is more easy to read (at least for
me as a beginner). 

Thanks again for your precious comments.
Best,
Giga

^ permalink raw reply	[flat|nested] 11+ messages in thread
* Atomic operations
@ 2002-06-03 15:58 Gregory Giguashvili
  0 siblings, 0 replies; 11+ messages in thread
From: Gregory Giguashvili @ 2002-06-03 15:58 UTC (permalink / raw)
  To: Linux Kernel (E-mail); +Cc: 'chyang@ah.edu.cn'

Hello,

I forgot to add that I know that it can be implemented using XCHG and LOCK
operations. However, I'm not an expert in ASM, so I was hoping somebody
would help me...

Thanks 
Giga


^ permalink raw reply	[flat|nested] 11+ messages in thread
* Atomic operations
@ 2002-06-03 15:04 Gregory Giguashvili
  2002-06-03 17:27 ` H. Peter Anvin
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Gregory Giguashvili @ 2002-06-03 15:04 UTC (permalink / raw)
  To: Linux Kernel (E-mail)

Hello,

I wonder if someone can help me to change the behaviour of the atomic
functions available in <asm/atomic.h> include file. The operations I need to
implement are described below:

atomic_t test_and_set (int i, atomic_t* v)
{
   atomic_t old = *v;
   v->counter = i;
   return old;
}

atomic_t test_then_add (int i, atomic_t* v)
{
   atomic_t old = *v;
   v->counter += i;
   return old;
}

Thanks in advance,
Giga


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2002-06-04  8:25 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-06-03 19:09 Atomic operations Gregory Giguashvili
2002-06-03 18:43 ` H. Peter Anvin
  -- strict thread matches above, loose matches on Subject: below --
2002-06-04  9:23 Gregory Giguashvili
2002-06-03 15:58 Gregory Giguashvili
2002-06-03 15:04 Gregory Giguashvili
2002-06-03 17:27 ` H. Peter Anvin
2002-06-03 18:08 ` Richard B. Johnson
2002-06-03 19:36   ` Thunder from the hill
2002-06-03 21:30     ` Richard B. Johnson
2002-06-03 18:39 ` Brian Gerst
2002-06-03 19:49   ` H. Peter Anvin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox