From 26ab0f47bc9f52687f4790ae2de0ce0ad49716c2 Mon Sep 17 00:00:00 2001
From: Manuel Traut <manut@linutronix.de>
Date: Thu, 10 Jan 2019 09:28:12 +0100
Subject: kernel-dbg: update printk slides

- add a reference to elinux.org/Debugging_by_printing
- improve explanation of /proc/sys/kernel/printk
- add a slide about rate limiting printk
- add a slide about wrappers like dev_dbg

Signed-off-by: Manuel Traut <manut@linutronix.de>
---
 .../kernel-debugging/pres_kernel-debugging_en.tex  | 46 ++++++++++++++++++++--
 1 file changed, 42 insertions(+), 4 deletions(-)

(limited to 'kernel-devel/kernel-debugging/pres_kernel-debugging_en.tex')

diff --git a/kernel-devel/kernel-debugging/pres_kernel-debugging_en.tex b/kernel-devel/kernel-debugging/pres_kernel-debugging_en.tex
index 5e9d30f..104d8c4 100644
--- a/kernel-devel/kernel-debugging/pres_kernel-debugging_en.tex
+++ b/kernel-devel/kernel-debugging/pres_kernel-debugging_en.tex
@@ -69,10 +69,14 @@ stack trace is printed on detection
 \item[Remote debugging over FireWire] Documentation/debugging-via-ohci1394.txt
 \end{description}
 \end{frame}
+
 \section{printk}
 \begin{frame}[fragile]
 \frametitle{printk is your friend!!}
-Usage is similar to printf() in userspace. Different loglevels:
+\url{https://elinux.org/Debugging\_by\_printing}
+\vspace{1em}
+
+Usage is similar to printf() in userspace, but supports different loglevels:
 \small
 \begin{verbatim}
 KERN_EMERG   "<0>" /* system is unusable               */
@@ -86,7 +90,6 @@ KERN_DEBUG   "<7>" /* debug-level messages             */
 \end{verbatim}
 \end{frame}
 
-\section{printk}
 \begin{frame}[fragile]
 \frametitle{Example}
 \begin{verbatim}
@@ -101,10 +104,46 @@ Loglevel in procfs:
 # console_loglevel, default_message_loglevel,
 # minimum_console_level and default_console_loglevel
 $ cat /proc/sys/kernel/printk
-4       4       1       7
+  4       4       1       7
+# current default minimum boot-time-default
 \end{verbatim}
 \end{frame}
 
+\begin{frame}
+\frametitle{limiting printk}
+\begin{description}
+\item[printk\_once] no matter how often it is called,
+                    it prints once and never again.
+\item[printk\_ratelimited] prints not more than 10 times,
+                           in every 5 seconds.
+\end{description}
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{printk wrapper}
+If you have a 'struct device *dev' pointer, use
+\begin{lstlisting}
+dev_dbg(dev, "debug-message");
+dev_err_once(dev, "error-message");
+\end{lstlisting}
+\pause
+
+In general it is recommended to use the pr\_ wrappers
+instead of using printk directly:
+\begin{lstlisting}
+pr_dbg_ratelimited("debug-message");
+pr_err("error-message");
+\end{lstlisting}
+
+This allows dynamic printk control. (Details on next slide)
+\pause
+
+\begin{lstlisting}
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+\end{lstlisting}
+can be used to define the printed prefix.
+\end{frame}
+
 \section{dynamic printk}
 \begin{frame}
 \frametitle{dynamic printk}
@@ -119,7 +158,6 @@ format: filename:lineno [module]function flags format
 \item[flags] '=p' means the line is turned 'on' for printing
 \item[format] the format used for the debug statement
 \end{description}
-Use pr\_debug() and dev\_dbg() in your code.
 
 see also: Documentation/dynamic-debug-howto.txt
 \end{frame}
-- 
cgit v1.2.3

