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