<html>
<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:΢ÈíÑźÚ
}
--></style>
</head>
<body class='hmmessage'><div dir='ltr'>
Hi :<BR>
<BR>
if you write code as below:<BR>
<BR>
golbal int in1=0,int2=0;<BR>
<BR>
cpu1: cpu2:<BR>
<BR>
int1 = 1; b= int2;<BR>
smp_wmb()<BR>
int2 = 2; a = in1;<BR>
<BR>
cpu2 may get the result: b==2 & a==0 , which means although cpu1 set int1=1 before int2=2, there is no garentee for cpu2 to perceive int1 before int2.<BR>
you must add smp_rmb() inside cpu2 to prevent this.<BR>
<BR>
two cpus must cooperate to acheive the sequence memory order. <BR>
<BR>
<BR>
<BR> <BR>
<DIV>
> Date: Fri, 9 Dec 2011 14:14:37 +0530<BR>> Subject: Re: Memory barrier<BR>> From: trisha1march@gmail.com<BR>> To: buyit@live.cn<BR>> CC: kernelnewbies@kernelnewbies.org<BR>> <BR>> I will add more info here:<BR>> smp_mb()<BR>> Similar to mb(), but only guarantees ordering between cores/processors<BR>> within an SMP system. All memory accesses before the smp_mb() will be<BR>> visible to all cores within the SMP system before any accesses after<BR>> the smp_mb().<BR>> smp_rmb()<BR>> Like smp_mb(), but only guarantees ordering between read accesses.<BR>> smp_wmb()<BR>> Like smp_mb(), but only guarantees ordering between write accesses.<BR>> <BR>> So these made me total confuse .<BR>> <BR>> Thanks<BR>> <BR>> 2011/12/9 trisha yad <trisha1march@gmail.com>:<BR>> > Thanks,<BR>> ><BR>> > I got bit confuse with below statement:<BR>> > This is from paper Memory access ordering Part 2<BR>> > SMP conditional barriers<BR>> > The SMP conditional barriers are used to ensure a consistent view of<BR>> > memory between different cores within a cache coherent SMP system.<BR>> > When compiling a kernel without CONFIG_SMP, all SMP barriers are<BR>> > converted into plain compiler barriers.<BR>> ><BR>> > 2011/12/9 ²·ß®Ìì <buyit@live.cn>:<BR>> >> Hi :<BR>> >><BR>> >> memory barriers can not make order on other cpus, only the current<BR>> >> cpu's order will be promised.<BR>> >><BR>> >><BR>> >><BR>> >>> Date: Fri, 9 Dec 2011 12:54:40 +0530<BR>> >>> Subject: Memory barrier<BR>> >>> From: trisha1march@gmail.com<BR>> >>> To: Kernelnewbies@kernelnewbies.org<BR>> >><BR>> >>><BR>> >>> Hi All,<BR>> >>><BR>> >>> I need small clarification on memory barrier.<BR>> >>> #define smp_mb() mb()<BR>> >>> #define smp_rmb() rmb()<BR>> >>> #define smp_wmb() wmb()<BR>> >>> In case of SMP:<BR>> >>> is smp_mb() or smp_rmb() make order on current CPU or all cpu's<BR>> >>><BR>> >>> Thanks<BR>> >>><BR>> >>> _______________________________________________<BR>> >>> Kernelnewbies mailing list<BR>> >>> Kernelnewbies@kernelnewbies.org<BR>> >>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies<BR>> <BR>> _______________________________________________<BR>> Kernelnewbies mailing list<BR>> Kernelnewbies@kernelnewbies.org<BR>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies<BR></DIV>                                            </div></body>
</html>