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