[bootlin/training-materials updates] master: Kernel slides: misc improvements to locking section (f76df5f2)

Michael Opdenacker michael.opdenacker at bootlin.com
Thu Dec 12 10:46:18 CET 2019


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

>---------------------------------------------------------------

commit f76df5f22b1cecdd181843d62b54f18fe25e7acb
Author: Michael Opdenacker <michael.opdenacker at bootlin.com>
Date:   Thu Dec 12 10:45:52 2019 +0100

    Kernel slides: misc improvements to locking section
    
    Signed-off-by: Michael Opdenacker <michael.opdenacker at bootlin.com>


>---------------------------------------------------------------

f76df5f22b1cecdd181843d62b54f18fe25e7acb
 ...stration_of_the_dining_philosophers_problem.jpg | Bin 0 -> 232868 bytes
 .../kernel-driver-development-concurrency.tex      |  39 +++++++++++++++------
 2 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/slides/kernel-driver-development-concurrency/An_illustration_of_the_dining_philosophers_problem.jpg b/slides/kernel-driver-development-concurrency/An_illustration_of_the_dining_philosophers_problem.jpg
new file mode 100644
index 00000000..298d8e4f
Binary files /dev/null and b/slides/kernel-driver-development-concurrency/An_illustration_of_the_dining_philosophers_problem.jpg differ
diff --git a/slides/kernel-driver-development-concurrency/kernel-driver-development-concurrency.tex b/slides/kernel-driver-development-concurrency/kernel-driver-development-concurrency.tex
index 1a6095e2..616f9443 100644
--- a/slides/kernel-driver-development-concurrency/kernel-driver-development-concurrency.tex
+++ b/slides/kernel-driver-development-concurrency/kernel-driver-development-concurrency.tex
@@ -35,7 +35,9 @@
   \frametitle{Linux mutexes}
   {\em mutex = {\bf mut}ual {\bf ex}clusion}
   \begin{itemize}
-  \item The kernel's main locking primitive
+  \item The kernel's main locking primitive. It's a {\em binary lock}.
+    Note that {\em counting locks} ({\em semaphores}) are also available,
+    but used 30x less frequently.
   \item The process requesting the lock blocks when the lock is
     already held.  Mutexes can therefore only be used in contexts
     where sleeping is allowed.
@@ -172,14 +174,17 @@
   \begin{itemize}
   \item From \kfile{drivers/tty/serial/uartlite.c}
   \item Spinlock structure embedded into \kstruct{uart_port}
-    \begin{minted}{c}
+    \begin{block}{}
+    \begin{minted}[fontsize=\small]{c}
 struct uart_port {
         spinlock_t lock;
         /* Other fields */
 };
     \end{minted}
+    \end{block}
   \item Spinlock taken/released with protection against interrupts
-    \begin{minted}{c}
+    \begin{block}{}
+    \begin{minted}[fontsize=\small]{c}
 static unsigned int ulite_tx_empty
     (struct uart_port *port) {
         unsigned long flags;
@@ -189,6 +194,7 @@ static unsigned int ulite_tx_empty
         spin_unlock_irqrestore(&port->lock, flags);
 }
     \end{minted}
+    \end{block}
   \end{itemize}
 \end{frame}
 
@@ -321,12 +327,23 @@ static unsigned int ulite_tx_empty
 
 \begin{frame}
   \frametitle{Kernel locking: summary and references}
-  \begin{itemize}
-  \item Use mutexes in code that is allowed to sleep
-  \item Use spinlocks in code that is not allowed to sleep (interrupts)
-    or for which sleeping would be too costly (critical sections)
-  \item Use atomic operations to protect integers or addresses
-  \end{itemize}
-  See \kerneldochtml{kernel-hacking/locking} in kernel documentation
-  for many details about kernel locking mechanisms.
+  \begin{columns}
+  \column[t]{0.65\textwidth}
+    \begin{itemize}
+    \item Use mutexes in code that is allowed to sleep
+    \item Use spinlocks in code that is not allowed to sleep (interrupts)
+      or for which sleeping would be too costly (critical sections)
+    \item Use atomic operations to protect integers or addresses
+    \end{itemize}
+    See \kerneldochtml{kernel-hacking/locking} in kernel documentation
+    for many details about kernel locking mechanisms.
+  \column[t]{0.35\textwidth}
+    \small
+    Further reading: see the classical
+    {\em \href{https://en.wikipedia.org/wiki/Dining_philosophers_problem}
+    {dining philosophers problem}} for a nice illustration of synchronization
+    and concurrency issues.
+    \includegraphics[width=\textwidth]{slides/kernel-driver-development-concurrency/An_illustration_of_the_dining_philosophers_problem.jpg}
+    \tiny Image source: Wikipedia (\url{https://frama.link/xg3Wnd0F})
+  \end{columns}
 \end{frame}




More information about the training-materials-updates mailing list