About the memory barrier in BSD libc

Fengwei yin yfw.bsd at gmail.com
Thu Apr 26 01:28:14 UTC 2012


On Thu, Apr 26, 2012 at 6:51 AM, Ricardo Nabinger Sanchez
<rnsanchez at wait4.org> wrote:
> On Mon, 23 Apr 2012 12:41:20 +0400, Slawa Olhovchenkov wrote:
>
>> /usr/include/machine/atomic.h:
>>
>> #define mb()    __asm __volatile("lock; addl $0,(%%esp)" : : : "memory")
>> #define wmb()   __asm __volatile("lock; addl $0,(%%esp)" : : : "memory")
>> #define rmb()   __asm __volatile("lock; addl $0,(%%esp)" : : : "memory")
>
> Somewhat late on this topic, but I'd like to understand why issue a write
> on %esp, which would invalidate (%esp) on other cores --- thus forcing a
> miss on them?

The key here is prefix "lock:" which could be considered as "mfence" on
modern CPU.

>
> Instead, why not issue "mfence" (mb), "sfence" (wmb), and "lfence" (rmb)?
>
Not all x86 family support "fence" instruction. "lock" prefix works for all.

> Cheers
>
> --
> Ricardo Nabinger Sanchez           http://rnsanchez.wait4.org/
>  "Left to themselves, things tend to go from bad to worse."
>
> _______________________________________________
> freebsd-threads at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-threads
> To unsubscribe, send any mail to "freebsd-threads-unsubscribe at freebsd.org"


More information about the freebsd-threads mailing list