Skip to content

Commit

Permalink
kernel: sleeping: Add a slide to provide hints on the various sleep m…
Browse files Browse the repository at this point in the history
…echanisms

Mentioning msleep, udelay, schedule and cpu_realx seems reasonable here.

Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
  • Loading branch information
miquelraynal committed Jun 22, 2021
1 parent 408bc90 commit 3362e36
Showing 1 changed file with 28 additions and 0 deletions.
Expand Up @@ -209,3 +209,31 @@ \subsection{Sleeping}
\end{itemize}
\end{itemize}
\end{frame}

\begin{frame}[fragile]
\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}
\end{frame}

0 comments on commit 3362e36

Please sign in to comment.