[PATCH -perfbook 4/6] defer/rcuintro: More tweaks for Listings 9.13 and 9.14
Akira Yokosawa <[email protected]> Tue, 23 Jun 2026 19:28:56 +0900
| Newsgroups | org.kernel.vger.perfbook |
|---|---|
| Message-ID | <[email protected]> |
To make text parts in those floating listings easier to distinguish from those of main contents, fine tune their appearance by: 1) Use \footnotesize, 2) Widen margins, and 3) Tweak vertical spaces above/below framed code snippets. Signed-off-by: Akira Yokosawa <[email protected]> --- defer/rcuintro.tex | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/defer/rcuintro.tex b/defer/rcuintro.tex index 596f138f..6997378b 100644 --- a/defer/rcuintro.tex +++ b/defer/rcuintro.tex @@ -2,6 +2,10 @@ % mainfile: ../perfbook.tex % SPDX-License-Identifier: CC-BY-SA-3.0 +\newcommand{\adjvspaceabove}{\vspace*{2pt}} +\newcommand{\adjvspacebelow}{\vspace*{-1pt}} +\newcommand{\adjvspacebottom}{\vspace*{-2pt}} + \subsection{Introduction to RCU} \label{sec:defer:Introduction to RCU} @@ -69,26 +73,29 @@ can be implemented with a single load instruction, exactly the instruction that would normally be used in single-threaded code. \begin{listing}[tb] -\small -\fvset{numbers=left,numbersep=5pt,fontsize=\scriptsize,frame=single,xleftmargin=15pt,xrightmargin=5pt} +\begin{adjustwidth}{10pt}{5pt} +\footnotesize +\fvset{numbers=left,numbersep=5pt,fontsize=\scriptsize,frame=single,xrightmargin=5pt} {\renewcommand{\theFancyVerbLine}{% {\rmfamily\tiny A\arabic{FancyVerbLine}}} +\adjvspaceabove% \begin{Verbatim} p = gp; do_something_with(p->a); do_something_with(p->b); \end{Verbatim} -} +}\adjvspacebelow Might be transformed to: {\renewcommand{\theFancyVerbLine}{% {\rmfamily\tiny B\arabic{FancyVerbLine}}} +\adjvspaceabove% \begin{Verbatim} p = gp; do_something_with(p->a); p = gp; do_something_with(p->b); \end{Verbatim} -} +}\adjvspacebelow The compiler assumes normal variables do not spontaneously change, \co{do_something_with()} might use many machine registers, and this transformation reduces register pressure. @@ -97,38 +104,43 @@ transformed code, the values of \co{p->a} and \co{p->b} will be mismatched. Prevent this by using \co{rcu_dereference()} as follows: {\renewcommand{\theFancyVerbLine}{% {\rmfamily\tiny C\arabic{FancyVerbLine}}} +\adjvspaceabove% \begin{Verbatim} p = rcu_dereference(gp); do_something_with(p->a); do_something_with(p->b); \end{Verbatim} -} +}\adjvspacebelow +\end{adjustwidth}\adjvspacebottom \caption{Compilers Can Reload Values} \label{lst:defer:Compilers Can Reload Values} \end{listing} \begin{listing}[tb] -\small -\fvset{numbers=left,numbersep=5pt,fontsize=\scriptsize,frame=single,xleftmargin=15pt,xrightmargin=5pt} +\begin{adjustwidth}{10pt}{5pt} +\footnotesize +\fvset{numbers=left,numbersep=5pt,fontsize=\scriptsize,frame=single,xrightmargin=5pt} {\renewcommand{\theFancyVerbLine}{% {\rmfamily\tiny A\arabic{FancyVerbLine}}} +\adjvspaceabove% \begin{Verbatim} p = malloc(sizeof(*p)); p->a = compute_value(); p->b = 42; gp = p; \end{Verbatim} -} +}\adjvspacebelow Might be transformed to: {\renewcommand{\theFancyVerbLine}{% {\rmfamily\tiny B\arabic{FancyVerbLine}}} +\adjvspaceabove% \begin{Verbatim} p = malloc(sizeof(*p)); gp = p; p->a = compute_value(); p->b = 42; \end{Verbatim} -} +}\adjvspacebelow The compiler assumes normal variables are not concurrently accessed, and thus that the order of stores does not matter. If \co{compute_value()} was inlined, this transformation might produce @@ -139,13 +151,15 @@ garbage in \co{p->a} and \co{p->b}. Prevent this by using \co{rcu_assign_pointer()} as follows: {\renewcommand{\theFancyVerbLine}{% {\rmfamily\tiny C\arabic{FancyVerbLine}}} +\adjvspaceabove% \begin{Verbatim} p = malloc(sizeof(*p)); p->a = compute_value(); p->b = 42; rcu_assign_pointer(gp, p); \end{Verbatim} -} +}\adjvspacebelow +\end{adjustwidth}\adjvspacebottom \caption{Compilers Can Reorder Accesses} \label{lst:defer:Compilers Can Reorder Accesses} \end{listing} -- 2.43.0