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