Subject: can somebody explain barrier() macro ?

Hi,

barrier() is defined in kernel.h as follows :

#define barrier() __asm__ __volatile__("": : :"memory")


what does this mean ? is this like "nop" ?

TIA,
-hiren


2001-02-20 20:05:41

by Erik Mouw

[permalink] [raw]
Subject: Re: can somebody explain barrier() macro ?

On Tue, Feb 20, 2001 at 12:50:54PM -0700, [email protected] wrote:
> barrier() is defined in kernel.h as follows :
>
> #define barrier() __asm__ __volatile__("": : :"memory")
>
> what does this mean ? is this like "nop" ?

It's a write barrier. It prevents the compiler from optimising writes
to memory: all outstanding writes should be done before the program
flow crosses the barrier().


Erik

--
J.A.K. (Erik) Mouw, Information and Communication Theory Group, Department
of Electrical Engineering, Faculty of Information Technology and Systems,
Delft University of Technology, PO BOX 5031, 2600 GA Delft, The Netherlands
Phone: +31-15-2783635 Fax: +31-15-2781843 Email: [email protected]
WWW: http://www-ict.its.tudelft.nl/~erik/

2001-02-20 20:18:41

by Richard B. Johnson

[permalink] [raw]
Subject: Re: can somebody explain barrier() macro ?

On Tue, 20 Feb 2001 [email protected] wrote:

> Hi,
>
> barrier() is defined in kernel.h as follows :
>
> #define barrier() __asm__ __volatile__("": : :"memory")
>
>
> what does this mean ? is this like "nop" ?
>

It tells the compiler that memory was, or is about to be, modified.
Therefore, the complier must put back into memory anything it
was caching, and after the barrier, it must re-read anything it
uses from memory. It, itself, generates no code, but the compiler
will usually spew out some 'extra' instructions as a result of
this, so it isn't a "nop".


Cheers,
Dick Johnson

Penguin : Linux version 2.4.1 on an i686 machine (799.53 BogoMips).

"Memory is like gasoline. You use it up when you are running. Of
course you get it all back when you reboot..."; Actual explanation
obtained from the Micro$oft help desk.


2001-02-20 20:59:11

by Alan

[permalink] [raw]
Subject: Re: can somebody explain barrier() macro ?

> barrier() is defined in kernel.h as follows :
>
> #define barrier() __asm__ __volatile__("": : :"memory")
>
> what does this mean ? is this like "nop" ?

Its adds an empty piece of assembler (ie no code) and declares that this
non code causes effects on memory. That forces gcc to writeback before the
barrier and reload cached values afterwards