Re: memort-barriers?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jan 27, 2004 at 21:32:30 -0800, prasanna wakhare wrote:
> Hi all,
> its OK to use memory barriers for avoiding software
> and
> hardware optimization.
> 
> But in kernel they are used in  loop like
> do { var=val;wmb()}while(0) loop

This in NOT A LOOP in the first place ;-).

> 
> or in driver like
> while(count --){
>                   writeb(*(ptr++),address);
>                   wmb();
>                }
> 
> why they r used in above case,
> means why they used there(for direct assignment)

wmb does not only protect against optimization. It guarantees, that all
writes before the barrier are fully completed (safely in memory, bus
unlocked, caches know about it), before the writes after the barrier
start. Many SMP platforms don't make such guarantee unless you
explicitely say they should. So in this very case the wmb() does
2 things:

    * Guarantees that the compiler won't change the iteration direction
      (it could otherwise).
    * Makes sure that the writes are actualy ordered by the underlying
      hardware.
    * As a result, it is guaranteed, that if a new value is read from
      one of the fileds, all values before are also new values, which
      might save some locking in another code.

-------------------------------------------------------------------------------
						 Jan 'Bulb' Hudec <bulb@ucw.cz>

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux