[Kos-dev] Non-Blocking Synchronization

Christophe Avoinne kos-dev@enix.org
Mon, 25 Jun 2001 15:31:20 +0200


This is a multi-part message in MIME format.

------=_NextPart_000_0023_01C0FD8B.E1FEFD80
Content-Type: multipart/alternative;
	boundary="----=_NextPart_001_0024_01C0FD8B.E1FEFD80"


------=_NextPart_001_0024_01C0FD8B.E1FEFD80
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Il y a des exemples de sources mais en allemand.

A noter qu'ils parlent de l'instruction "xchgcmp" pour illustre le CAS =
et prennent l'exemple suivant :

#define INCREASE(x)             \
asm volatile("                  \
0:      mov     %1,%%eax\n      \
        mov     %%eax,%%ebx\n   \
        inc     %%ebx\n         \
        cmpxchg %%ebx,%0\n      \
        jne     0b"             \
        : "=3Dm" ((x))            \
        : "m" ((x))             \
        : "eax", "ebx", "cc");

En r=E9alit=E9, leur exemple n'est pas tr=E8s bon dans la mesure o=F9 on =
peut faire simplement "lock; inc %0" =E0 la place. Par contre si on a =
besoin de conna=EEtre la valeur avant l'incr=E9mentation atomique, il =
faut utiliser =E0 la place "xadd" qui correspond =E0 la classe "fetch =
and modify" :

#define INCREASE(x) \
asm volatile("xadd %1,%2" : "=3Da" (result) : "a"(1), "m" ((x)) : "cc");

L=E0, deux processeurs ne peuvent pas lire en m=EAme temps la m=EAme =
valeur dans leur registre "eax".


 http://www.first.gmd.de/~fs/peace-pro97/non_blocking_sync/

------=_NextPart_001_0024_01C0FD8B.E1FEFD80
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content=3D"text/html; charset=3Diso-8859-1" =
http-equiv=3DContent-Type>
<META content=3D"MSHTML 5.00.3018.900" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Il y a des exemples de sources mais en=20
allemand.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>A noter qu'ils parlent de l'instruction =
"xchgcmp"=20
pour illustre le CAS et prennent l'exemple suivant :</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>
<DIV><FONT face=3DArial size=3D2>#define=20
INCREASE(x)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;=20
\<BR>asm=20
volatile("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
\<BR>0:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mov&nbsp;&nbsp;&nbsp;&nbsp;=20
%1,%%eax\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
\<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
mov&nbsp;&nbsp;&nbsp;&nbsp;=20
%%eax,%%ebx\n&nbsp;&nbsp; =
\<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
inc&nbsp;&nbsp;&nbsp;&nbsp;=20
%%ebx\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
\<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; cmpxchg=20
%%ebx,%0\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
\<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
jne&nbsp;&nbsp;&nbsp;&nbsp;=20
0b"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;=20
\<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : "=3Dm"=20
((x))&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
\<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : "m"=20
((x))&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;=20
\<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : "eax", "ebx",=20
"cc");</FONT></DIV>
<DIV>&nbsp;</DIV></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>En r=E9alit=E9, leur exemple n'est pas =
tr=E8s bon dans la=20
mesure o=F9 on peut faire simplement "lock; inc %0" =E0 la place. Par =
contre si on a=20
besoin de conna=EEtre la valeur avant l'incr=E9mentation atomique, il =
faut utiliser=20
=E0 la place "xadd" qui correspond =E0 la classe "fetch and modify" =
:</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>
<DIV><FONT face=3DArial size=3D2>#define INCREASE(x) \<BR>asm =
volatile("xadd=20
%1,%2"&nbsp;: "=3Da" (result) :&nbsp;"a"(1), "m" ((x)) =
:&nbsp;"cc");</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>L=E0, deux processeurs ne peuvent pas lire en m=EAme temps la =
m=EAme valeur dans=20
leur registre "eax".</DIV>
<DIV>&nbsp;</DIV></FONT><BR>&nbsp;<A=20
href=3D"http://www.first.gmd.de/~fs/peace-pro97/non_blocking_sync/">http:=
//www.first.gmd.de/~fs/peace-pro97/non_blocking_sync/</A></DIV></BODY></H=
TML>

------=_NextPart_001_0024_01C0FD8B.E1FEFD80--

------=_NextPart_000_0023_01C0FD8B.E1FEFD80
Content-Type: application/octet-stream;
	name="Non-Blocking Synchronization.url"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
	filename="Non-Blocking Synchronization.url"

[DEFAULT]
BASEURL=http://www.first.gmd.de/~fs/peace-pro97/non_blocking_sync/
[InternetShortcut]
URL=http://www.first.gmd.de/~fs/peace-pro97/non_blocking_sync/
Modified=90DBC82379FDC0018D

------=_NextPart_000_0023_01C0FD8B.E1FEFD80--