DPDK patches and discussions
 help / color / mirror / Atom feed
From: Olivier MATZ <olivier.matz@6wind.com>
To: "Ananyev, Konstantin" <konstantin.ananyev@intel.com>,
	 "dev@dpdk.org" <dev@dpdk.org>
Subject: Re: [dpdk-dev] [PATCH] atomic: clarify use of memory barriers
Date: Fri, 23 May 2014 16:10:11 +0200	[thread overview]
Message-ID: <537F56C3.3060503@6wind.com> (raw)
In-Reply-To: <2601191342CEEE43887BDE71AB9772580EFA776F@IRSMSX105.ger.corp.intel.com>

Hi Konstantin,

Thanks for these code examples and explanations.

On 05/20/2014 06:35 PM, Ananyev, Konstantin wrote:
 > So with the following fragment of code:
 > extern int *x;
 > extern  __128i a, *p;
 > L0:
 > _mm_stream_si128( p, a);
 > rte_compiler_barrier();
 > L1:
 > *x = 0;
 >
 > There is no guarantee that store at L0 will always be finished
 > before store at L1.

This code fragment looks very similar to what is done in
__rte_ring_sp_do_enqueue():

     [...]
     ENQUEUE_PTRS(); /* I expect it is converted to an SSE store */
     rte_compiler_barrier();
     [...]
     r->prod.tail = prod_next;

So, according to your previous explanation, I understand that
this code would require a write memory barrier in place of the
compiler barrier. Am I wrong?

If it's correct, we are back on the initial question: in this kind
of code, if the programmer wants that all stores are issued before
setting the value of r->prod.tail. This is the definition of the
write memory barrier. So wouldn't be better that he explicitelly
calls rte_smp_wmb() instead of adding a compiler barrier because
he knows that it is sufficient on all currently supported CPUs?
Can we be sure that next Intel CPU generations will behave that
way in the future?

Moreover, if I understand well, a real wmb() is needed only if
a SSE store is issued. But the programmer may not control that,
it's the job of the compiler.

 > But now, there seems a confusion: everyone has to remember that
 > smp_mb() and smp_wmb() are 'real' fences, while smp_rmb() is not.
 > That's why my suggestion was to simply keep using compiler_barrier()
 > for all cases, when we don't need real fence.

I'm not sure the programmer has to know which smp_*mb() is a real fence
or not. He just expects that it generates the proper CPU instructions
that guarantees the effectiveness of the memory barrier.

Regards,
Olivier

  parent reply	other threads:[~2014-05-23 14:10 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-20  9:36 Olivier Matz
2014-05-20 10:05 ` Ananyev, Konstantin
2014-05-20 12:12   ` Olivier MATZ
2014-05-20 16:35     ` Ananyev, Konstantin
2014-05-23 14:10   ` Olivier MATZ [this message]
2014-05-26 13:57     ` Ananyev, Konstantin
2014-05-26 14:20       ` Olivier MATZ

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=537F56C3.3060503@6wind.com \
    --to=olivier.matz@6wind.com \
    --cc=dev@dpdk.org \
    --cc=konstantin.ananyev@intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).