Skip to contentSkip to conversation

whymb: Fix description of compiler mischief

PATCH In review Akira Yokosawa 3 participants 10 messages Dec 2, 2020 – Dec 10, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 whymb: Fix description of compiler mischief

From 89ab8426f9821b6a8bf86e9d4f7eb596e0cfed73 Mon Sep 17 00:00:00 2001
From: Akira Yokosawa <[email protected]>
Date: Wed, 2 Dec 2020 07:35:08 +0900
Subject: [PATCH -perfbook] whymb: Fix description of compiler mischief

In this code snippet, the assertion can not fire due to different reasons.
When bar() observes b == 1, the smp_mb() assures a == 1. When bar() observes b == 0, the while loop will loop forever and the assertion can't be reached.

This was pointed out by Motohiro Kanda in his Japanese translation of perfbook [1].

[1]: https://sites.google.com/site/kandamotohiro/perfbook-d/perfbookappendixf10

---
Hi Paul,

(Cc: Motohiro)

Looks like this inconsistency in the Answer to Quick Quiz has been Motohiro's translation note for quite a while. (since 2017?)

He contributed to perfbook in the past. There is a couple of commits with his Reported-by.

Motohiro, do you mind if I submit patches to Paul on behalf of you like this?

And I think Paul is likely to do some wordsmithing on top of this patch. ;-)

Thanks, Akira
--

 appendix/whymb/whymemorybarriers.tex | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
appendix/whymb/whymemorybarriers.tex +4 -1
index dff7fafc..301342f3 100644
@@ -1152,7 +1152,10 @@ void bar(void)
 }
 \end{VerbatimN}
 
-	Given this optimization, the assertion could clearly fire.
+	Given this optimization, the code would behave in a completely
+	different way than the original intention.
+	If \co{bar()} observed \qco{b == 0}, the assertion could not
+	be reached due to the infinite loop.
 	You should use volatile casts or (where available) C++
 	relaxed atomics to prevent the compiler from optimizing
 	your parallel code into oblivion.
Signature · 1 line
2.17.1
#1 lore raw

Hi, all

Quoted 1 line

Motohiro, do you mind if I submit patches to Paul on behalf of

Certainly, please submit patches.

While I was working on Japanese translation, I felt something odd with this smp_mb sample code, but I did not report one to upstream because I was not so sure.
I just left a comment on my translation.

It is my great pleasure that someone reads my translation so seriously, Akira.

Thanks again for great book, Paul and others!

--
Motohiro Kanda

2020-12-02 23:50 GMT+09:00, Akira Yokosawa <[email protected]>:

Quoted 63 lines

From 89ab8426f9821b6a8bf86e9d4f7eb596e0cfed73 Mon Sep 17 00:00:00 2001
From: Akira Yokosawa <[email protected]>
Date: Wed, 2 Dec 2020 07:35:08 +0900
Subject: [PATCH -perfbook] whymb: Fix description of compiler mischief

In this code snippet, the assertion can not fire due to different reasons.
When bar() observes b == 1, the smp_mb() assures a == 1. When bar() observes b == 0, the while loop will loop forever and the assertion can't be reached.

This was pointed out by Motohiro Kanda in his Japanese translation of perfbook [1].

[1]:
https://sites.google.com/site/kandamotohiro/perfbook-d/perfbookappendixf10

---
Hi Paul,

(Cc: Motohiro)

Looks like this inconsistency in the Answer to Quick Quiz has been Motohiro's translation note for quite a while. (since 2017?)

He contributed to perfbook in the past. There is a couple of commits with his Reported-by.

Motohiro, do you mind if I submit patches to Paul on behalf of you like this?

And I think Paul is likely to do some wordsmithing on top of this patch. ;-)

Thanks, Akira
--

 appendix/whymb/whymemorybarriers.tex | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
appendix/whymb/whymemorybarriers.tex +4 -2
index dff7fafc..301342f3 100644
@@ -1152,7 +1152,10 @@ void bar(void)
 }
 \end{VerbatimN}
 
-	Given this optimization, the assertion could clearly fire.
+	Given this optimization, the code would behave in a completely
+	different way than the original intention.
+	If \co{bar()} observed \qco{b == 0}, the assertion could not
+	be reached due to the infinite loop.
 	You should use volatile casts or (where available) C++
 	relaxed atomics to prevent the compiler from optimizing
 	your parallel code into oblivion.
--

2.17.1

#2 lore raw
Quoted 5 lines · Motohiro Kanda

Hi, all

Quoted 1 line

Motohiro, do you mind if I submit patches to Paul on behalf of

Certainly, please submit patches.

Glad to hearing from you, Motohiro!
Can I take it as your Acked-by?

Quoted 7 lines

While I was working on Japanese translation, I felt something odd with this smp_mb sample code, but I did not report one to upstream because I was not so sure.
I just left a comment on my translation.

It is my great pleasure that someone reads my translation so seriously, Akira.

I'll keep picking up comments in your translation and submitting patches upstream based on them.

Some background:

I was tempted to do translation on my own when I first encountered perfbook, but seeing what you had done at the time (2015 or 2016), I changed my mind and started contributing to perfbook as a LaTeX advisor. The rapid update pace of upstream perfbook was another factor I changed my mind.
At that time your translation was work-in-progress, but last weekend, I was impressed to find out it is mostly complete.

If there is anything I can't understand in your comments, I'll ask you in person (in Japanese maybe).

Thanks, Akira

Quoted 6 lines

Thanks again for great book, Paul and others!

--
Motohiro Kanda

[...]

#3 lore raw
In reply to Akira Yokosawa
Quoted 11 lines · Akira Yokosawa
Quoted 1 line

From 89ab8426f9821b6a8bf86e9d4f7eb596e0cfed73 Mon Sep 17 00:00:00 2001

From: Akira Yokosawa <[email protected]>
Date: Wed, 2 Dec 2020 07:35:08 +0900
Subject: [PATCH -perfbook] whymb: Fix description of compiler mischief

In this code snippet, the assertion can not fire due to different reasons.
When bar() observes b == 1, the smp_mb() assures a == 1. When bar() observes b == 0, the while loop will loop forever and the assertion can't be reached.

Quoted 7 lines

This was pointed out by Motohiro Kanda in his Japanese translation of perfbook [1].

[1]: https://sites.google.com/site/kandamotohiro/perfbook-d/perfbookappendixf10

I took this patch as is, but added a patch on top that (hopefully) does a better job of explaining the situation. Thank you both!!!

Would it also help to add a reference to the discussion of control dependencies? The straightforward answer given that information is "control dependencies do not order later loads".

Motohiro, would you be OK with my mentioning your translation in the next set of release notes for perfbook? Either way, I much appreciate your doing this work!

Thanx, Paul

#4 lore raw
Quoted 15 lines · Paul E. McKenney
Quoted 14 lines · Akira Yokosawa
Quoted 1 line

From 89ab8426f9821b6a8bf86e9d4f7eb596e0cfed73 Mon Sep 17 00:00:00 2001

From: Akira Yokosawa <[email protected]>
Date: Wed, 2 Dec 2020 07:35:08 +0900
Subject: [PATCH -perfbook] whymb: Fix description of compiler mischief

In this code snippet, the assertion can not fire due to different reasons.
When bar() observes b == 1, the smp_mb() assures a == 1. When bar() observes b == 0, the while loop will loop forever and the assertion can't be reached.

This was pointed out by Motohiro Kanda in his Japanese translation of perfbook [1].

Quoted 7 lines
Quoted 4 lines

[1]: https://sites.google.com/site/kandamotohiro/perfbook-d/perfbookappendixf10

I took this patch as is, but added a patch on top that (hopefully) does a better job of explaining the situation. Thank you both!!!

Ah, this was your original intention of this Quick Quiz.

Yes, this explains the situation much better.

I did thought about dropping the smp_mb() in the snippet at first, but that would require me to do a larger rewrite of the answer. Instead, I submitted the minimal patch to attract your attention. ;-)

Quoted 3 lines

Would it also help to add a reference to the discussion of control dependencies?

Yes, I think so.
Section 15.3.3 or Section 15.3 as a whole would be a good reference.

Thanks, Akira

Quoted 9 lines

The straightforward answer given that information is
"control dependencies do not order later loads".

Motohiro, would you be OK with my mentioning your translation in the next set of release notes for perfbook? Either way, I much appreciate your doing this work!

Thanx, Paul

#6 lore raw
Quoted 2 lines · Motohiro Kanda
Quoted 1 line

Motohiro, would you be OK with my mentioning your translation in the

Sure, my honor!

Very good!

We have you in the FAQ, but it just says that you have started.

What should I change that to? "N chapters done"? "Done through Chapter/Appendix X"? "Completed"? Something else?

Thanx, Paul

#7 lore raw

Paul,

Will you change the FAQ.txt in following way?

Quoted 2 lines

Motohiro Kanda has started work on a Japanese translation:
https://sites.google.com/site/kandamotohiro/perfbook

to,
quote:

Motohiro Kanda publishes a Japanese translation of most chapters:

https://sites.google.com/view/kandamotohiro2/perfbook

This one is based on 2014 edition and contains topics including "Parallel Real-Time Computing", "Axiomatic Approaches" from later editions.

end quote

Some background:

Due to Google classic site deprecation policy, I have moved all of my contents from
sites.google.com/site/kandamotohiro
to sites.google.com/view/kandamotohiro2.

https://sites.google.com/site/kandamotohiro/perfbook will be gone on September 2021.

I have translated chapter 1 to 16 and appendix A to D and F. All from 2014 first printed edition.
I loved "Parallel Real-Time Computing" chapter in 2015 edition and "Axiomatic Approaches" section in 2017 edition and added their translation as well.

But I do not have energy to keep up with the speed and volume of latest changes. So, my translation is published as-is, based on old 2014 edition.

You can change wordings of my FAQ.txt change proposal as you like. Thanks.

--
Motohiro Kanda

Quoted 7 lines

We have you in the FAQ, but it just says that you have started.

What should I change that to? "N chapters done"? "Done through Chapter/Appendix X"? "Completed"? Something else?

Thanx, Paul

#8 lore raw
Quoted 36 lines · Motohiro Kanda

Paul,

Will you change the FAQ.txt in following way?

Quoted 2 lines

Motohiro Kanda has started work on a Japanese translation:
https://sites.google.com/site/kandamotohiro/perfbook

to,
quote:

Motohiro Kanda publishes a Japanese translation of most chapters:

https://sites.google.com/view/kandamotohiro2/perfbook

This one is based on 2014 edition and contains topics including "Parallel Real-Time Computing", "Axiomatic Approaches" from later editions.

end quote

Some background:

Due to Google classic site deprecation policy, I have moved all of my contents from
sites.google.com/site/kandamotohiro
to sites.google.com/view/kandamotohiro2.

https://sites.google.com/site/kandamotohiro/perfbook will be gone on September 2021.

I have translated chapter 1 to 16 and appendix A to D and F. All from 2014 first printed edition.
I loved "Parallel Real-Time Computing" chapter in 2015 edition and "Axiomatic Approaches" section in 2017 edition and added their translation as well.

Quoted 5 lines

But I do not have energy to keep up with the speed and volume of latest changes. So, my translation is published as-is, based on old 2014 edition.

You can change wordings of my FAQ.txt change proposal as you like. Thanks.

How about like this? Please let me know of any errors or omission so that I can fix them.

Thanx, Paul

------------------------------------------------------------------------

commit a80871756cccbaba8678b7f762794dd56d697de9

Author: Paul E. McKenney <[email protected]>
Date:   Wed Dec 9 17:27:37 2020 -0800

FAQ: Update information on Motohiro Kanda's Japanese translation

FAQ.txt +5 -2
index a284615..45e30c3 100644
@@ -128,9 +128,12 @@
 
 		http://kernel.org/pub/linux/kernel/people/paulmck/perfbook/perfbook-cn.2011.10.18a.pdf
 
-		Motohiro Kanda has started work on a Japanese translation:
+		Motohiro Kanda has a Japanese translation of Chapters 1-16
+		and Appendices A-D and F based on the 2014 print edition,
+		but with the "Parallel Real-Time Computing" and "Axiomatic
+		Approaches" sections taken from later editions:
 
-		https://sites.google.com/site/kandamotohiro/perfbook
+		https://sites.google.com/view/kandamotohiro2/perfbook
 
 		SeongJae Park has started work on a Korean translation: