<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:Consolas;}
span.lno
        {mso-style-name:lno;}
span.code
        {mso-style-name:code;}
span.EmailStyle21
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> kernelnewbies-bounces@kernelnewbies.org [mailto:kernelnewbies-bounces@kernelnewbies.org]
<b>On Behalf Of </b>Malte Vesper<br>
<b>Sent:</b> Thursday, March 26, 2015 10:50 AM<br>
<b>To:</b> kernelnewbies<br>
<b>Subject:</b> Re: Atomics and memory barriers<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal" style="margin-bottom:12.0pt">On a second thought:<br>
<br>
Is it correct that atomic_set() without a writebarrier following it is still atomic (no torn writes), however not guaranteed to be visible to other threads?<o:p></o:p></p>
<div>
<p class="MsoNormal">On 26/03/15 17:47, Malte Vesper wrote:<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal">Hello,<br>
I have been reading up on atomics and struggle to grasp when exactly I need explicit memory barriers.<br>
<br>
While the documentation (Documentat/atomic_ops.txt), talks about operations needing explicit barriers both sides, I assume this is only half true.<br>
If I for instance only want to use an atomic as a flag to show that some operation is complete I reckon that a barrier before is sufficient.<br>
<br>
Furthermore I found the following lines:<o:p></o:p></p>
<pre><span class="lno"><a href="http://users.sosdg.org/%7Eqiyong/lxr/source/Documentation/atomic_ops.txt#L288" id="L288">288</a> </span><span class="code">If a caller requires memory barrier semantics around an atomic_t</span><o:p></o:p></pre>
<pre><span class="lno"><a href="http://users.sosdg.org/%7Eqiyong/lxr/source/Documentation/atomic_ops.txt#L289" id="L289">289</a> </span><span class="code">operation which does not return a value, a set of interfaces are</span><o:p></o:p></pre>
<pre><span class="lno"><a href="http://users.sosdg.org/%7Eqiyong/lxr/source/Documentation/atomic_ops.txt#L290" id="L290">290</a> </span><span class="code">defined which accomplish this:</span><o:p></o:p></pre>
<pre><span class="lno"><a href="http://users.sosdg.org/%7Eqiyong/lxr/source/Documentation/atomic_ops.txt#L291" id="L291">291</a> </span><o:p></o:p></pre>
<pre><span class="lno"><a href="http://users.sosdg.org/%7Eqiyong/lxr/source/Documentation/atomic_ops.txt#L292" id="L292">292</a> </span><span class="code"> void smp_mb__before_atomic(void);</span><o:p></o:p></pre>
<pre><span class="lno"><a href="http://users.sosdg.org/%7Eqiyong/lxr/source/Documentation/atomic_ops.txt#L293" id="L293">293</a> </span><span class="code"> void smp_mb__after_atomic(void);</span><o:p></o:p></pre>
<p class="MsoNormal">note how it refers to "operation which does not return a value", why can't I use these for atomic operations that do return a value?<br>
What should I use instead, normal barriers like mb?<br>
<br>
Please enlighten me<br>
Malte<o:p></o:p></p>
</blockquote>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">You might want to try reading Documentation/memory-barriers.txt.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">It does a better job of explaining this stuff than atomic_ops.txt.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">That being said, none of this stuff is easy to understand.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">I’ve read both a few times and still don’t quite get all of it.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Good luck,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">Jeff Haran<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
</div>
</body>
</html>