1<html><head><meta http-equiv="Content-Type" content="text/html; charset=ANSI_X3.4-1968"><title>Chapter 2. The Players</title><meta name="generator" content="DocBook XSL Stylesheets V1.78.1"><link rel="home" href="index.html" title="Unreliable Guide To Hacking The Linux Kernel"><link rel="up" href="index.html" title="Unreliable Guide To Hacking The Linux Kernel"><link rel="prev" href="introduction.html" title="Chapter 1. Introduction"><link rel="next" href="basics-hardirqs.html" title="Hardware Interrupts (Hard IRQs)"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter 2. The Players</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="introduction.html">Prev</a> </td><th width="60%" align="center"> </th><td width="20%" align="right"> <a accesskey="n" href="basics-hardirqs.html">Next</a></td></tr></table><hr></div><div class="chapter"><div class="titlepage"><div><div><h1 class="title"><a name="basic-players"></a>Chapter 2. The Players</h1></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl class="toc"><dt><span class="sect1"><a href="basic-players.html#basics-usercontext">User Context</a></span></dt><dt><span class="sect1"><a href="basics-hardirqs.html">Hardware Interrupts (Hard IRQs)</a></span></dt><dt><span class="sect1"><a href="basics-softirqs.html">Software Interrupt Context: Softirqs and Tasklets</a></span></dt></dl></div><p> 2 At any time each of the CPUs in a system can be: 3 </p><div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p> 4 not associated with any process, serving a hardware interrupt; 5 </p></li><li class="listitem"><p> 6 not associated with any process, serving a softirq or tasklet; 7 </p></li><li class="listitem"><p> 8 running in kernel space, associated with a process (user context); 9 </p></li><li class="listitem"><p> 10 running a process in user space. 11 </p></li></ul></div><p> 12 There is an ordering between these. The bottom two can preempt 13 each other, but above that is a strict hierarchy: each can only be 14 preempted by the ones above it. For example, while a softirq is 15 running on a CPU, no other softirq will preempt it, but a hardware 16 interrupt can. However, any other CPUs in the system execute 17 independently. 18 </p><p> 19 We'll see a number of ways that the user context can block 20 interrupts, to become truly non-preemptable. 21 </p><div class="sect1"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="basics-usercontext"></a>User Context</h2></div></div></div><p> 22 User context is when you are coming in from a system call or other 23 trap: like userspace, you can be preempted by more important tasks 24 and by interrupts. You can sleep, by calling 25 <code class="function">schedule()</code>. 26 </p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p> 27 You are always in user context on module load and unload, 28 and on operations on the block device layer. 29 </p></div><p> 30 In user context, the <code class="varname">current</code> pointer (indicating 31 the task we are currently executing) is valid, and 32 <code class="function">in_interrupt()</code> 33 (<code class="filename">include/linux/interrupt.h</code>) is <span class="returnvalue">false 34 </span>. 35 </p><div class="caution" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Caution</h3><p> 36 Beware that if you have preemption or softirqs disabled 37 (see below), <code class="function">in_interrupt()</code> will return a 38 false positive. 39 </p></div></div></div><div class="navfooter"><hr><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="introduction.html">Prev</a> </td><td width="20%" align="center"> </td><td width="40%" align="right"> <a accesskey="n" href="basics-hardirqs.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 1. Introduction </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Hardware Interrupts (Hard IRQs)</td></tr></table></div></body></html> 40