[bootlin/training-materials updates] master: kernel: sleeping: Add a slide to provide hints on the various sleep mechanisms (3362e36b)

Miquel Raynal miquel.raynal at bootlin.com
Tue Jun 22 20:46:58 CEST 2021

Repository : https://github.com/bootlin/training-materials
On branch  : master
Link       : https://github.com/bootlin/training-materials/commit/3362e36b3a6ce6d03ea0197df67b1034f3ffc164


commit 3362e36b3a6ce6d03ea0197df67b1034f3ffc164
Author: Miquel Raynal <miquel.raynal at bootlin.com>
Date:   Tue Jun 22 20:38:49 2021 +0200

    kernel: sleeping: Add a slide to provide hints on the various sleep mechanisms
    Mentioning msleep, udelay, schedule and cpu_realx seems reasonable here.
    Signed-off-by: Miquel Raynal <miquel.raynal at bootlin.com>


 .../kernel-driver-development-sleeping.tex         | 28 ++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/slides/kernel-driver-development-sleeping/kernel-driver-development-sleeping.tex b/slides/kernel-driver-development-sleeping/kernel-driver-development-sleeping.tex
index aff7fead..a97831f8 100644
--- a/slides/kernel-driver-development-sleeping/kernel-driver-development-sleeping.tex
+++ b/slides/kernel-driver-development-sleeping/kernel-driver-development-sleeping.tex
@@ -209,3 +209,31 @@ From \kfile{char/tpm/tpm_ibmvtpm.c}
+  \frametitle{Waiting when there is no interrupt}
+  \begin{itemize}
+  \item When there is no interrupt mechanism tied to a particular
+        hardware state, it is tempting to implement a custom busy-wait loop.
+    \begin{itemize}
+    \item Spoiler alert: this is highly discouraged!
+    \end{itemize}
+  \item For long lasting pauses, rely on helpers which leverage the
+    system clock
+    \begin{itemize}
+    \item \kfunc{wait_event} helpers are (also) very useful outside of
+      interruption situations
+    \item Release the CPU with \kfunc{schedule}
+    \end{itemize}
+  \item For shorter pauses, use helpers which implement software loops
+    \begin{itemize}
+    \item \kfunc{msleep}/\kfunc{msleep_interruptible} put the process
+      in sleep for a given amount of milliseconds
+    \item \kfunc{udelay}/\kfunc{udelay_range} waste CPU cycles in order
+      to save a couple of context switches for a sub-millisecond period
+    \item \kfunc{cpu_relax} does nothing, but may be used as a way to
+      not being optimized out by the compiler when busy looping for very
+      short periods
+    \end{itemize}
+  \end{itemize}

More information about the training-materials-updates mailing list