Re: mb()!!

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

 



> >I was going through the code of __wait_event in sched.c [ kernel 2.2.19] 
> >and i
> >came across a MACRO mb(), and it was defined in asm-i386/system.h as 
> >following
> >
> >#define mb()    __asm__ __volatile__ ("lock; addl $0,0(%%esp)": : 
> >:"memory")
> >
> >I don't know what this MACRO does?? [ I actually don't know assembly ]
> >
> >Can anyone help me?? 
> 
> mb() stands for 'memory barrior'... it is a command to prevent the 
> compiler from re-ordering memory accesses across that point.

... and in addition on SMP it has to synchronize CPU caches for
architectures where that matters. I suppose that's why there's that
nop with lock prefix (for optimization empty assembly whith "memory"
clovver is sufficient). It also forces all values currently in registers
to be saved in memory and reloaded.

It assures, that under any conditions whatever any memory access before
the barrier acutally happens before any memory access after the barrier.

--------------------------------------------------------------------------------
                  				- Jan Hudec `Bulb' <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