kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
* where is __memory_barrier in kernel ?
@ 2011-03-06 14:02 loody
  2011-03-06 14:38 ` Михаил Кринкин
  2011-03-08  6:29 ` Mulyadi Santosa
  0 siblings, 2 replies; 8+ messages in thread
From: loody @ 2011-03-06 14:02 UTC (permalink / raw)
  To: kernelnewbies

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* where is __memory_barrier in kernel ?
  2011-03-06 14:02 where is __memory_barrier in kernel ? loody
@ 2011-03-06 14:38 ` Михаил Кринкин
  2011-03-08  6:20   ` piyush moghe
  2011-03-08  6:29 ` Mulyadi Santosa
  1 sibling, 1 reply; 8+ messages in thread
From: Михаил Кринкин @ 2011-03-06 14:38 UTC (permalink / raw)
  To: kernelnewbies

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 at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20110306/aef0abfe/attachment.html 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* where is __memory_barrier in kernel ?
  2011-03-06 14:38 ` Михаил Кринкин
@ 2011-03-08  6:20   ` piyush moghe
  0 siblings, 0 replies; 8+ messages in thread
From: piyush moghe @ 2011-03-08  6:20 UTC (permalink / raw)
  To: 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 at kernelnewbies.org
>> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>>
>
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20110308/317c8b05/attachment.html 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* where is __memory_barrier in kernel ?
  2011-03-06 14:02 where is __memory_barrier in kernel ? loody
  2011-03-06 14:38 ` Михаил Кринкин
@ 2011-03-08  6:29 ` Mulyadi Santosa
  2011-03-08  6:38   ` piyush moghe
  1 sibling, 1 reply; 8+ messages in thread
From: Mulyadi Santosa @ 2011-03-08  6:29 UTC (permalink / raw)
  To: 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...meaning...(at
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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* where is __memory_barrier in kernel ?
  2011-03-08  6:29 ` Mulyadi Santosa
@ 2011-03-08  6:38   ` piyush moghe
  2011-03-10 15:13     ` loody
  0 siblings, 1 reply; 8+ messages in thread
From: piyush moghe @ 2011-03-08  6:38 UTC (permalink / raw)
  To: kernelnewbies

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...meaning...(at
> 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 at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20110308/701651ef/attachment.html 

^ permalink raw reply	[flat|nested] 8+ messages in thread

* where is __memory_barrier in kernel ?
  2011-03-08  6:38   ` piyush moghe
@ 2011-03-10 15:13     ` loody
  2011-03-10 16:51       ` Mulyadi Santosa
  2011-03-13  2:26       ` Jim Cromie
  0 siblings, 2 replies; 8+ messages in thread
From: loody @ 2011-03-10 15:13 UTC (permalink / raw)
  To: 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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* where is __memory_barrier in kernel ?
  2011-03-10 15:13     ` loody
@ 2011-03-10 16:51       ` Mulyadi Santosa
  2011-03-13  2:26       ` Jim Cromie
  1 sibling, 0 replies; 8+ messages in thread
From: Mulyadi Santosa @ 2011-03-10 16:51 UTC (permalink / raw)
  To: kernelnewbies

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* where is __memory_barrier in kernel ?
  2011-03-10 15:13     ` loody
  2011-03-10 16:51       ` Mulyadi Santosa
@ 2011-03-13  2:26       ` Jim Cromie
  1 sibling, 0 replies; 8+ messages in thread
From: Jim Cromie @ 2011-03-13  2:26 UTC (permalink / raw)
  To: kernelnewbies

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20110312/c8295070/attachment.html 

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-03-13  2:26 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-06 14:02 where is __memory_barrier in kernel ? loody
2011-03-06 14:38 ` Михаил Кринкин
2011-03-08  6:20   ` piyush moghe
2011-03-08  6:29 ` Mulyadi Santosa
2011-03-08  6:38   ` piyush moghe
2011-03-10 15:13     ` loody
2011-03-10 16:51       ` Mulyadi Santosa
2011-03-13  2:26       ` Jim Cromie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).