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