Discussions of the Parallel Programming book
 help / color / mirror / Atom feed
From: Akira Yokosawa <akiyks@gmail.com>
To: "Paul E. McKenney" <paulmck@kernel.org>
Cc: perfbook@vger.kernel.org, Akira Yokosawa <akiyks@gmail.com>
Subject: [PATCH -perfbook 1/2] Define macros for multi-part listings in preamble
Date: Fri, 26 Jun 2026 20:34:47 +0900	[thread overview]
Message-ID: <14878d1b-2d34-417e-a7c8-fe74c6aee08b@gmail.com> (raw)

Paul said he has a plan to add listings similar to Listings 9.13
and 9.14 [1].

Move local definitions in rcuintro.tex for such multi-part listings
into preamble so that they can be used elsewhere.  Note that
"VerbatimT" and "adjustwidth" envs have vertical spacing tweaks
applied.

Link: https://lore.kernel.org/perfbook/abeb5ab5-9c0f-4948-bfcb-392c7b77c6db@paulmck-laptop/ [1]
Signed-off-by: Akira Yokosawa <akiyks@gmail.com>
---
 defer/rcuintro.tex | 52 ++++++++++++++++++----------------------------
 perfbook-lt.tex    |  6 ++++++
 2 files changed, 26 insertions(+), 32 deletions(-)

diff --git a/defer/rcuintro.tex b/defer/rcuintro.tex
index 6997378b..898cdf5f 100644
--- a/defer/rcuintro.tex
+++ b/defer/rcuintro.tex
@@ -2,10 +2,6 @@
 % 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}
 
@@ -75,27 +71,24 @@ that would normally be used in single-threaded code.
 \begin{listing}[tb]
 \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}
+\begin{VerbatimT}
  p = gp;
  do_something_with(p->a);
  do_something_with(p->b);
-\end{Verbatim}
-}\adjvspacebelow
+\end{VerbatimT}
+}
 Might be transformed to:
 {\renewcommand{\theFancyVerbLine}{%
   {\rmfamily\tiny B\arabic{FancyVerbLine}}}
-\adjvspaceabove%
-\begin{Verbatim}
+\begin{VerbatimT}
  p = gp;
  do_something_with(p->a);
  p = gp;
  do_something_with(p->b);
-\end{Verbatim}
-}\adjvspacebelow
+\end{VerbatimT}
+}
 The compiler assumes normal variables do not spontaneously change,
 \co{do_something_with()} might use many machine registers, and this
 transformation reduces register pressure.
@@ -104,14 +97,13 @@ 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}
+\begin{VerbatimT}
  p = rcu_dereference(gp);
  do_something_with(p->a);
  do_something_with(p->b);
-\end{Verbatim}
-}\adjvspacebelow
-\end{adjustwidth}\adjvspacebottom
+\end{VerbatimT}
+}
+\end{adjustwidth}
 \caption{Compilers Can Reload Values}
 \label{lst:defer:Compilers Can Reload Values}
 \end{listing}
@@ -119,28 +111,25 @@ Prevent this by using \co{rcu_dereference()} as follows:
 \begin{listing}[tb]
 \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}
+\begin{VerbatimT}
  p = malloc(sizeof(*p));
  p->a = compute_value();
  p->b = 42;
  gp = p;
-\end{Verbatim}
-}\adjvspacebelow
+\end{VerbatimT}
+}
 Might be transformed to:
 {\renewcommand{\theFancyVerbLine}{%
   {\rmfamily\tiny B\arabic{FancyVerbLine}}}
-\adjvspaceabove%
-\begin{Verbatim}
+\begin{VerbatimT}
  p = malloc(sizeof(*p));
  gp = p;
  p->a = compute_value();
  p->b = 42;
-\end{Verbatim}
-}\adjvspacebelow
+\end{VerbatimT}
+}
 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
@@ -151,15 +140,14 @@ 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}
+\begin{VerbatimT}
  p = malloc(sizeof(*p));
  p->a = compute_value();
  p->b = 42;
  rcu_assign_pointer(gp, p);
-\end{Verbatim}
-}\adjvspacebelow
-\end{adjustwidth}\adjvspacebottom
+\end{VerbatimT}
+}
+\end{adjustwidth}
 \caption{Compilers Can Reorder Accesses}
 \label{lst:defer:Compilers Can Reorder Accesses}
 \end{listing}
diff --git a/perfbook-lt.tex b/perfbook-lt.tex
index 0dc05325..cb8299a5 100644
--- a/perfbook-lt.tex
+++ b/perfbook-lt.tex
@@ -397,6 +397,12 @@
 {numbers=left,numbersep=3pt,xleftmargin=5pt,xrightmargin=5pt,frame=single}
 \DefineVerbatimEnvironment{VerbatimU}{Verbatim}%
 {numbers=none,xleftmargin=5pt,xrightmargin=5pt,samepage=true,frame=single}
+% for multi-part listings with explanation
+\DefineVerbatimEnvironment{VerbatimT}{Verbatim}%
+{numbers=left,numbersep=5pt,frame=single,xrightmargin=5pt}
+\BeforeBeginEnvironment{VerbatimT}{\vspace*{2pt}}
+\AfterEndEnvironment{VerbatimT}{\vspace*{-1pt}}
+\AfterEndEnvironment{adjustwidth}{\vspace*{-2pt}}
 
 \IfLmttForCode{
 \AtBeginEnvironment{verbatim}{\renewcommand{\ttdefault}{lmtt}}

base-commit: a9d5892eab1e41da0c12b0b093db1ce0fb06f7d3
-- 
2.43.0


             reply	other threads:[~2026-06-26 11:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-26 11:34 Akira Yokosawa [this message]
2026-06-26 11:41 ` [PATCH -perfbook 2/2] Redefine line count format at the beginning of VerbatimT env Akira Yokosawa
2026-06-26 17:59 ` [PATCH -perfbook 1/2] Define macros for multi-part listings in preamble Paul E. McKenney
2026-06-27  5:26   ` Akira Yokosawa
2026-06-27 17:26     ` Paul E. McKenney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=14878d1b-2d34-417e-a7c8-fe74c6aee08b@gmail.com \
    --to=akiyks@gmail.com \
    --cc=paulmck@kernel.org \
    --cc=perfbook@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox