Re: [PATCH] Documentation/memory-barriers: fix wrong comment in example

From: SeongJae Park
Date: Sun Feb 21 2016 - 12:57:50 EST


On Sun, Feb 21, 2016 at 2:25 PM, Paul E. McKenney
<paulmck@xxxxxxxxxxxxxxxxxx> wrote:
> On Sun, Feb 21, 2016 at 07:50:19AM +0900, SeongJae Park wrote:
>> On Sun, Feb 21, 2016 at 4:57 AM, Paul E. McKenney
>> <paulmck@xxxxxxxxxxxxxxxxxx> wrote:
>> > On Sat, Feb 20, 2016 at 03:01:08PM +0900, SeongJae Park wrote:
>> >> There is wrong comment in example for compiler store omit behavior. It
>> >> shows example of the problem and than problem solved version code.
>> >> However, the comment in the solved version is still same with not solved
>> >> version. Fix the wrong statement with this commit.
>> >>
>> >> Signed-off-by: SeongJae Park <sj38.park@xxxxxxxxx>
>> >
>> > Hmmm... The code between the two stores of zero to "a" is intended to
>> > remain the same in the broken and fixed versions. So the only change
>> > is from "a = 0" to "WRITE_ONCE(a, 0)". Note that it is some other
>> > CPU that did the third store to "a".
>>
>> Agree, of course.
>>
>> >
>> > Or am I missing your point here?
>>
>> My point is about the comment.
>> I thought the comment in broken version is saying "Below line(a = 0) says
>> it will store to variable 'a', but it will not in actual because a compiler can
>> omit it".
>> However, in fixed version, because the compiler cannot omit the store
>> now, I thought the comment also should be changed to say the difference
>> between broken and fixed version.
>>
>> If I am understanding anything wrong, please let me know.
>
> Hmmm... The intent of the comment is to act as a placeholder for
> arbitrary code that does not affect the value of "a". The current
> comment is clearly not doing that for you. Possible changes include:
>
> o Adding test to the comment making the intent more clear.
> o Replacing the comment with a function call, perhaps to
> does_not_change_a() or some similar name.
> o Keeping the current comment, but adding a call to something
> like does_not_change_a() after it.
>
> Other thoughts?

Ah, now I understood the original intent. Thank you for the kind explanation.
I think your third option will be most helpful for me. How about the
patch below?

BTW, the problem looks trivial rather than critical.
If you think so, feel free to ignore my patch, please.


Thanks,
SeongJae Park


========================== >3 ==========================