toolsoftrade: Backport updates in LWN article
cover toolsoftrade: Backport updates in LWN article
Hi Paul,
This patch set backports changes made in the LWN article "Who's afraid of a big bad optimizing compiler?" around store tearing. Although the origin of the article was Section 4.3.4.1, we can think of the article as the original publication of the section. There will likely be further updates in perfbook on this matter.
Patch #1 adds entries in bib/swtools to be cited in Patch #2. Patch #2 does the backport, with the report in 2013 being kept in a citation.
Patch #3 is a cosmetic change in the beginning of Section 4.3.4.4.
Thanks, Akira
--
Akira Yokosawa (3):
bib/swtools: Add entries of reports on store tearing
toolsortrade: Backport LWN article
toolsoftrade: Use 'quote' for made-up dialogue
bib/swtools.bib | 18 ++++++++++++++++ toolsoftrade/toolsoftrade.tex | 39 +++++++++++++++++++++++++---------- 2 files changed, 46 insertions(+), 11 deletions(-)
Signature · 1 line
2.17.1
PATCH 1/3 bib/swtools: Add entries of reports on store tearing
From bb50063d1efafa1434449ef9c5c5968dcc00d772 Mon Sep 17 00:00:00 2001
From: Akira Yokosawa <[email protected]>
Date: Thu, 28 Nov 2019 07:42:06 +0900
Subject: [PATCH 1/3] bib/swtools: Add entries of reports on store tearing
--- bib/swtools.bib | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+)
bib/swtools.bib +18 -0
@@ -600,6 +600,15 @@ Architectural Support for Programming Languages and Operating Systems ,DOI={ 10.1007/978-3-642-33125-1_22 } } +@unpublished{KonstantinKhlebnikov2013gccstoretearing +,Author="Konstantin Khlebnikov and Paul E. McKenney" +,Title="{RCU: non-atomic assignment to long/pointer variables in gcc}" +,month="January" +,day="15" +,year="2013" +,note="\url{https://lore.kernel.org/lkml/[email protected]/}" +} + @unpublished{ThomasSewell2013L4binaryVerification ,Author="Thomas Sewell and Toby Murray" ,Title="Above and Beyond: {seL4} Noninterference and Binary Verification "
@@ -1188,6 +1197,15 @@ Michalis Kokologiannakis" ,note="\url{http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2369.pdf}" } +@unpublished{WillDeacon2019StoreTearingReport +,Author="Will Deacon" +,Title="{Re: [PATCH 1/1] Fix: trace sched switch start/stop racy updates}" +,month="August" +,day="21" +,year="2019" +,note="\url{https://lore.kernel.org/lkml/20190821103200.kpufwtviqhpbuv2n@willie-the-truck/}" +} + @unpublished{DanielBristotdeOliveira2019formal ,Author="Daniel Bristot de Oliveira" ,Title="Formal verification made easy (and fast)!"
Signature · 1 line
2.17.1
PATCH 2/3 toolsortrade: Backport LWN article
In reply to Akira YokosawaFrom 9132989d5f2db9c1829750971a187afdd4c4a6ee Mon Sep 17 00:00:00 2001
From: Akira Yokosawa <[email protected]>
Date: Thu, 28 Nov 2019 07:42:59 +0900
Subject: [PATCH 2/3] toolsortrade: Backport LWN article
The LWN article "Who's afraid of a big bad optimizing compiler?" originated from Section 4.3.4.1. In preparing the article, there were improvements around store tearing. Backport the changes into this section and designate the article by \OriginallyPublished.
--- toolsoftrade/toolsoftrade.tex | 37 ++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-)
toolsoftrade/toolsoftrade.tex +26 -11
@@ -1563,7 +1563,8 @@ variable, all of those accesses are loads. \subsubsection{Shared-Variable Shenanigans} \label{sec:toolsoftrade:Shared-Variable Shenanigans} - +\OriginallyPublished{Section}{sec:toolsoftrade:Shared-Variable Shenanigans}{Shared-Variable Shenanigans}{Linux Weekly News}{JadeAlglave2019WhoAfraidCompiler} +% Given code that does plain loads and stores,\footnote{ That is, normal loads and stores instead of C11 atomics, inline assembly, or volatile accesses.}
@@ -1599,20 +1600,34 @@ cannot rule out load tearing in the general case. {\bf Store tearing} occurs when the compiler uses multiple store instructions for a single access. -For example, one thread might store \co{0x1234} to a four-byte integer -variable at the same time another thread stored \co{0xabcd}. +For example, one thread might store \co{0x12345678} to a four-byte integer +variable at the same time another thread stored \co{0xabcdef00}. If the compiler used 16-bit stores for either access, the result -might well be \co{0x12cd}, which could come as quite a surprise to +might well be \co{0x1234ef00}, which could come as quite a surprise to code loading from this integer. Nor is this a strictly theoretical issue. -For example, there are CPUs that can store small immediate values -directly into memory, and on such CPUs, the compiler can be expected -to split this into two 16-bit stores in order to avoid the overhead -of explicitly forming the 32-bit constant.\footnote{ - One such CPU is the rare and elusive x86: - \url{https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55981}.} -Furthermore, the C standard simply has no choice in the general case, given +For example, there are CPUs that feature small immediate values, +and on such CPUs, the compiler can be tempted to split a 64-bit +store into two 32-bit stores in order to reduce the overhead +of explicitly forming the 64-bit constant in a register, +even on a 64-bit CPU. +There are historical reports of this actually happening in +the wild (e.g.~\cite{KonstantinKhlebnikov2013gccstoretearing}), +but there is also a recent +report~\cite{WillDeacon2019StoreTearingReport}.\footnote{ + Note that this tearing can happen even on properly aligned + and machine-word-sized accesses, and in this particular case, + even for volatile stores. + Some might argue that this behavior constitutes a bug in the + compiler, but either way it illustrates the perceived value of + store tearing from a compiler-writer viewpoint. +} + +Of course, the compiler simply has no choice but to tear some stores +in the general case, given the possibility of code using 64-bit integers running on a 32-bit system. +But for properly aligned machine-sized stores, \co{WRITE_ONCE} will +prevent store tearing. \begin{listing}[tbp] \begin{linelabel}[ln:toolsoftrade:Preventing Load Fusing]
Signature · 1 line
2.17.1
PATCH 3/3 toolsoftrade: Use 'quote' for made-up dialogue
In reply to Akira YokosawaFrom df9bed4d21029054ed07c2b92b3dfdf84cd651b8 Mon Sep 17 00:00:00 2001
From: Akira Yokosawa <[email protected]>
Date: Fri, 29 Nov 2019 00:22:17 +0900
Subject: [PATCH 3/3] toolsoftrade: Use 'quote' for made-up dialogue
--- toolsoftrade/toolsoftrade.tex | 2 ++ 1 file changed, 2 insertions(+)
toolsoftrade/toolsoftrade.tex +2 -0
@@ -2350,10 +2350,12 @@ limiting or even entirely avoiding data races. \subsubsection{Avoiding Data Races} \label{sec:toolsoftrade:Avoiding Data Races} +\begin{quote} ``Doctor, it hurts my head when I think about concurrently accessing shared variables!'' ``Then stop concurrently accessing shared variables!!!'' +\end{quote} The doctor's advice might seem unhelpful, but one time-tested way to avoid concurrently accessing shared variables
Signature · 1 line
2.17.1
Quoted 8 lines · Akira Yokosawa
Hi Paul,
This patch set backports changes made in the LWN article "Who's afraid of a big bad optimizing compiler?" around store tearing. Although the origin of the article was Section 4.3.4.1, we can think of the article as the original publication of the section. There will likely be further updates in perfbook on this matter.
Quoted 6 lines
Patch #1 adds entries in bib/swtools to be cited in Patch #2. Patch #2 does the backport, with the report in 2013 being kept in a citation.
Patch #3 is a cosmetic change in the beginning of Section 4.3.4.4.Thanks, Akira
Excellent, thank you very much!!!
I added "()" to a WRITE_ONCE(), but otherwise queued and pushed this series as-is.
Thanx, Paul
Quoted 13 lines
--
Akira Yokosawa (3):
bib/swtools: Add entries of reports on store tearing
toolsortrade: Backport LWN article
toolsoftrade: Use 'quote' for made-up dialoguebib/swtools.bib | 18 ++++++++++++++++ toolsoftrade/toolsoftrade.tex | 39 +++++++++++++++++++++++++---------- 2 files changed, 46 insertions(+), 11 deletions(-)Signature · 1 line
2.17.1