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.2 2003/06/17 04:36:59 dillon Exp $
10 .Nd device polling support
12 .Cd "options DEVICE_POLLING"
16 (polling for brevity) refers to a technique to
17 handle devices that does not rely on the latter to generate
18 interrupts when they need attention, but rather lets the CPU poll
19 devices to service their needs.
20 This might seem inefficient and counterintuitive, but when done
23 gives more control to the operating system on
24 when and how to handle devices, with a number of advantages in terms
25 of system responsivity and performance.
29 reduces the overhead for context
30 switches which is incurred when servicing interrupts, and
31 gives more control on the scheduling of the CPU between various
32 tasks (user processes, software interrupts, device handling)
33 which ultimately reduces the chances of livelock in the system.
34 .Sh PRINCIPLES OF OPERATION
35 In the normal, interrupt-based mode, devices generate an interrupt
36 whenever they need attention.
38 context switch and the execution of an interrupt handler
39 which performs whatever processing is needed by the device.
40 The duration of the interrupt handler is potentially unbounded
41 unless the device driver has been programmed with real-time
42 concerns in mind (which is generally not the case for
45 Furthermore, under heavy traffic, the system might be
46 persistently processing interrupts without being able to
47 complete other work, either in the kernel or in userland.
50 disables interrupts by polling devices at appropriate
51 times, i.e., on clock interrupts, system calls and within the idle loop.
52 This way, the context switch overhead is removed.
54 the operating system can control accurately how much work to spend
55 in handling device events, and thus prevent livelock by reserving
56 some amount of CPU to other tasks.
62 .Va kern.polling.enable
63 whereas the percentage of CPU cycles reserved to userland processes is
67 .Va kern.polling.user_frac
68 whose range is 0 to 100 (50 is the default value).
72 is enabled, and provided that there is work to do,
74 .Va kern.polling.user_frac
75 percent of the CPU cycles is reserved to userland tasks, the
76 remaining fraction being available for device processing.
80 also changes the way network software interrupts
81 are scheduled, so there is never the risk of livelock because
82 packets are not processed to completion.
84 There are other variables which control or monitor the behaviour
85 of devices operating in polling mode, but they are unlikely to
86 require modifications, and are documented in the source file
87 .Pa sys/kern/kern_poll.c .
90 requires explicit modifications to the device drivers.
91 As of this writing, the
98 devices are supported, with other in the works.
99 The modifications are rather straightforward, consisting in
100 the extraction of the inner part of the interrupt service routine
101 and writing a callback function,
104 to probe the device for events and process them.
106 conditionally compiled sections of the devices mentioned above
109 Because in the worst case devices are only polled on
110 clock interrupts, in order to reduce the latency in processing
111 packets, it is advisable to increase the frequency of the clock
114 Device polling was introduced in February 2002 by
115 .An Luigi Rizzo Aq luigi@iet.unipi.it .