where is __memory_barrier in kernel ?
hi all: I grep kernel source and found cpu_relax is defined as __memory_barrier(), which seems not defined in kernel source. At beginning I think it may be the gcc build-in functions, but I cannot find in the gcc document. Where and what is that used for? -- Regards, miloody
You can see linux/Documentation/memory_barriers.txt about barriers in common i think, that specific definition of __memory_barrier depend on architecture. What file did you found this definition in? 2011/3/6 loody <miloody@gmail.com>
hi all: I grep kernel source and found cpu_relax is defined as __memory_barrier(), which seems not defined in kernel source. At beginning I think it may be the gcc build-in functions, but I cannot find in the gcc document. Where and what is that used for?
-- Regards, miloody
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
AFAIK memory barriers are the architecture specific instructions which restricts the instruction execution in order as received, since otherwise CPU might change the order of execution of instructions for effective use of pipelines or instruction execution optimizations. Although many times it is required that the instructions to be executed in particular order only in order to prevent the consistency of data and hence memory barriers are required. Regards, Piyush 2011/3/6 Михаил Кринкин <krinkin.m.u@gmail.com>
You can see linux/Documentation/memory_barriers.txt about barriers in common
i think, that specific definition of __memory_barrier depend on architecture. What file did you found this definition in?
2011/3/6 loody <miloody@gmail.com>
hi all:
I grep kernel source and found cpu_relax is defined as __memory_barrier(), which seems not defined in kernel source. At beginning I think it may be the gcc build-in functions, but I cannot find in the gcc document. Where and what is that used for?
-- Regards, miloody
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
On Sun, Mar 6, 2011 at 21:02, loody <miloody@gmail.com> wrote:
hi all: I grep kernel source and found cpu_relax is defined as __memory_barrier(), which seems not defined in kernel source. At beginning I think it may be the gcc build-in functions, but I cannot find in the gcc document. Where and what is that used for?
Hi.. are you sure it's memory barrier? I check the source in lxr.linux.no (2.6.37.3) and cpu_relax is expanded as 'rep' and 'nop' asm instruction but speaking about __memory_barrier(), I find it in http://lxr.linux.no/#linux+v2.6.37.3/include/linux/compiler-intel.h#L19...me... least for me), it's a macro specificly defined in Intel C compiler (not gcc which we usually uses). IMHO, it does the same as barrier everywhere....processor stop a while and it make sure any memory operation (especially write) has been done.... -- regards, Mulyadi Santosa Freelance Linux trainer and consultant blog: the-hydra.blogspot.com training: mulyaditraining.blogspot.com
Yes what you are saying is also right, since in order to prevent the ordering all the pending memory operations should have completed hence as you mentioned processor stops and make sure all the memory operations are completed. On Tue, Mar 8, 2011 at 11:59 AM, Mulyadi Santosa <mulyadi.santosa@gmail.com>wrote:
On Sun, Mar 6, 2011 at 21:02, loody <miloody@gmail.com> wrote:
hi all: I grep kernel source and found cpu_relax is defined as __memory_barrier(), which seems not defined in kernel source. At beginning I think it may be the gcc build-in functions, but I cannot find in the gcc document. Where and what is that used for?
Hi..
are you sure it's memory barrier? I check the source in lxr.linux.no (2.6.37.3) and cpu_relax is expanded as 'rep' and 'nop' asm instruction
but speaking about __memory_barrier(), I find it in
http://lxr.linux.no/#linux+v2.6.37.3/include/linux/compiler-intel.h#L19...me... least for me), it's a macro specificly defined in Intel C compiler (not gcc which we usually uses).
IMHO, it does the same as barrier everywhere....processor stop a while and it make sure any memory operation (especially write) has been done....
-- regards,
Mulyadi Santosa Freelance Linux trainer and consultant
blog: the-hydra.blogspot.com training: mulyaditraining.blogspot.com
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
hi 2011/3/8 piyush moghe <pmkernel@gmail.com>:
Yes what you are saying is also right, since in order to prevent the ordering all the pending memory operations should have completed hence as you mentioned processor stops and make sure all the memory operations are completed. I am not sure whether all the memory operations are completed after cpu stops running for a while. I think there should be a more aggressive and precise instruction to handle this behavior, right? appreciate your kind help, miloody
On Thu, Mar 10, 2011 at 22:13, loody <miloody@gmail.com> wrote:
hi
2011/3/8 piyush moghe <pmkernel@gmail.com>:
Yes what you are saying is also right, since in order to prevent the ordering all the pending memory operations should have completed hence as you mentioned processor stops and make sure all the memory operations are completed. I am not sure whether all the memory operations are completed after cpu stops running for a while. I think there should be a more aggressive and precise instruction to handle this behavior, right?
In x86 which does strict ordering, memory barrier is rarely needed, unless in case such as synchronization between processors or core. In loose ordering processor such as Alpha, you really need it. about your question "i am not sure whether all memory operations are completion"...well, maybe you got it wrong. It's not forcing them to complete...it make them to be done right now..... a.k.a no more ordering..."just execute them" now. Symantically, their meanings are different, right? and btw, what do you mean by "aggresive and precise"? -- regards, Mulyadi Santosa Freelance Linux trainer and consultant blog: the-hydra.blogspot.com training: mulyaditraining.blogspot.com
On Thu, Mar 10, 2011 at 8:13 AM, loody <miloody@gmail.com> wrote:
hi
2011/3/8 piyush moghe <pmkernel@gmail.com>:
Yes what you are saying is also right, since in order to prevent the ordering all the pending memory operations should have completed hence as you mentioned processor stops and make sure all the memory operations are completed. I am not sure whether all the memory operations are completed after cpu stops running for a while. I think there should be a more aggressive and precise instruction to handle this behavior, right? appreciate your kind help, miloody
a consolidated view of locking primitives is in linux-2.6.git/tools/perf/perf.h it defines rmb(), cpu_relax() for many architectures in a single place. the comment block here: http://lxr.free-electrons.com/source/arch/x86/include/asm/system.h#L357 lines 371-421, say that rmb is heavier than memory_barrier() or barrier(). I think the comment speaks to your "aggressive and precise" questions.
participants (5)
-
Jim Cromie -
loody -
Mulyadi Santosa -
piyush moghe -
Михаил Кринкин