Initial import from FreeBSD RELENG_4:
[dragonfly.git] / share / man / man4 / polling.4
1 .\"
2 .\" $FreeBSD: src/share/man/man4/polling.4,v 1.1.2.4 2003/04/14 08:58:02 maxim Exp $
3 .\"
4 .Dd February 15, 2002
5 .Dt POLLING 4
6 .Os
7 .Sh NAME
8 .Nm polling
9 .Nd device polling support
10 .Sh SYNOPSIS
11 .Cd "options DEVICE_POLLING"
12 .Cd "options HZ=1000"
13 .Sh DESCRIPTION
14 .Dq "Device polling"
15 (polling for brevity) refers to a technique to
16 handle devices that does not rely on the latter to generate
17 interrupts when they need attention, but rather lets the CPU poll
18 devices to service their needs.
19 This might seem inefficient and counterintuitive, but when done
20 properly,
21 .Nm
22 gives more control to the operating system on
23 when and how to handle devices, with a number of advantages in terms
24 of system responsivity and performance.
25 .Pp
26 In particular,
27 .Nm
28 reduces the overhead for context
29 switches which is incurred when servicing interrupts, and
30 gives more control on the scheduling of the CPU between various
31 tasks (user processes, software interrupts, device handling)
32 which ultimately reduces the chances of livelock in the system.
33 .Sh PRINCIPLES OF OPERATION
34 In the normal, interrupt-based mode, devices generate an interrupt
35 whenever they need attention.
36 This in turn causes a
37 context switch and the execution of an interrupt handler
38 which performs whatever processing is needed by the device.
39 The duration of the interrupt handler is potentially unbounded
40 unless the device driver has been programmed with real-time
41 concerns in mind (which is generally not the case for
42 .Fx
43 drivers).
44 Furthermore, under heavy traffic, the system might be
45 persistently processing interrupts without being able to
46 complete other work, either in the kernel or in userland.
47 .Pp
48 .Nm Polling
49 disables interrupts by polling devices at appropriate
50 times, i.e., on clock interrupts, system calls and within the idle loop.
51 This way, the context switch overhead is removed.
52 Furthermore,
53 the operating system can control accurately how much work to spend
54 in handling device events, and thus prevent livelock by reserving
55 some amount of CPU to other tasks.
56 .Pp
57 .Nm Polling
58 is enabled with a
59 .Xr sysctl 8
60 variable
61 .Va kern.polling.enable
62 whereas the percentage of CPU cycles reserved to userland processes is
63 controlled by the
64 .Xr sysctl 8
65 variable
66 .Va kern.polling.user_frac
67 whose range is 0 to 100 (50 is the default value).
68 .Pp
69 When
70 .Nm
71 is enabled, and provided that there is work to do,
72 up to
73 .Va kern.polling.user_frac
74 percent of the CPU cycles is reserved to userland tasks, the
75 remaining fraction being available for device processing.
76 .Pp
77 Enabling
78 .Nm
79 also changes the way network software interrupts
80 are scheduled, so there is never the risk of livelock because
81 packets are not processed to completion.
82 .Pp
83 There are other variables which control or monitor the behaviour
84 of devices operating in polling mode, but they are unlikely to
85 require modifications, and are documented in the source file
86 .Pa sys/kern/kern_poll.c .
87 .Sh SUPPORTED DEVICES
88 .Nm Polling
89 requires explicit modifications to the device drivers.
90 As of this writing, the
91 .Xr dc 4 ,
92 .Xr em 4 ,
93 .Xr fxp 4 ,
94 .Xr rl 4 ,
95 and
96 .Xr sis 4
97 devices are supported, with other in the works.
98 The modifications are rather straightforward, consisting in
99 the extraction of the inner part of the interrupt service routine
100 and writing a callback function,
101 .Fn *_poll ,
102 which is invoked
103 to probe the device for events and process them.
104 See the
105 conditionally compiled sections of the devices mentioned above
106 for more details.
107 .Pp
108 Because in the worst case devices are only polled on
109 clock interrupts, in order to reduce the latency in processing
110 packets, it is advisable to increase the frequency of the clock
111 to at least 1000 HZ.
112 .Sh HISTORY
113 Device polling was introduced in February 2002 by
114 .An Luigi Rizzo Aq luigi@iet.unipi.it .