2002-02-15 08:34:33 +00:00
|
|
|
.\"
|
|
|
|
.\" $FreeBSD$
|
|
|
|
.\"
|
|
|
|
.Dd February 15, 2002
|
|
|
|
.Dt POLLING 4
|
|
|
|
.Os
|
|
|
|
.Sh NAME
|
|
|
|
.Nm polling
|
|
|
|
.Nd device polling support
|
|
|
|
.Sh SYNOPSIS
|
2002-03-18 16:29:26 +00:00
|
|
|
.Cd "options DEVICE_POLLING"
|
|
|
|
.Cd "options HZ=1000"
|
2002-02-15 08:34:33 +00:00
|
|
|
.Sh DESCRIPTION
|
2002-03-18 16:29:26 +00:00
|
|
|
.Dq "Device polling"
|
|
|
|
(polling for brevity) refers to a technique to
|
2002-02-15 08:34:33 +00:00
|
|
|
handle devices that does not rely on the latter to generate
|
|
|
|
interrupts when they need attention, but rather lets the CPU poll
|
|
|
|
devices to service their needs.
|
|
|
|
This might seem inefficient and counterintuitive, but when done
|
2002-03-18 16:29:26 +00:00
|
|
|
properly,
|
|
|
|
.Nm
|
|
|
|
gives more control to the operating system on
|
2002-02-15 08:34:33 +00:00
|
|
|
when and how to handle devices, with a number of advantages in terms
|
|
|
|
of system responsivity and performance.
|
|
|
|
.Pp
|
2002-03-18 16:29:26 +00:00
|
|
|
In particular,
|
|
|
|
.Nm
|
|
|
|
reduces the overhead for context
|
2002-02-15 08:34:33 +00:00
|
|
|
switches which is incurred when servicing interrupts, and
|
|
|
|
gives more control on the scheduling of the CPU between various
|
|
|
|
tasks (user processes, software interrupts, device handling)
|
|
|
|
which ultimately reduces the chances of livelock in the system.
|
|
|
|
.Sh PRINCIPLES OF OPERATION
|
|
|
|
In the normal, interrupt-based mode, devices generate an interrupt
|
2002-03-18 16:29:26 +00:00
|
|
|
whenever they need attention.
|
|
|
|
This in turn causes a
|
2003-01-01 18:49:04 +00:00
|
|
|
context switch and the execution of an interrupt handler
|
2002-02-15 08:34:33 +00:00
|
|
|
which performs whatever processing is needed by the device.
|
|
|
|
The duration of the interrupt handler is potentially unbounded
|
|
|
|
unless the device driver has been programmed with real-time
|
2002-03-18 16:29:26 +00:00
|
|
|
concerns in mind (which is generally not the case for
|
|
|
|
.Fx
|
|
|
|
drivers).
|
|
|
|
Furthermore, under heavy traffic, the system might be
|
2002-02-15 08:34:33 +00:00
|
|
|
persistently processing interrupts without being able to
|
|
|
|
complete other work, either in the kernel or in userland.
|
|
|
|
.Pp
|
2002-03-18 16:29:26 +00:00
|
|
|
.Nm Polling
|
|
|
|
disables interrupts by polling devices at appropriate
|
|
|
|
times, i.e., on clock interrupts, system calls and within the idle loop.
|
|
|
|
This way, the context switch overhead is removed.
|
|
|
|
Furthermore,
|
2002-02-15 08:34:33 +00:00
|
|
|
the operating system can control accurately how much work to spend
|
|
|
|
in handling device events, and thus prevent livelock by reserving
|
|
|
|
some amount of CPU to other tasks.
|
|
|
|
.Pp
|
2002-03-18 16:29:26 +00:00
|
|
|
.Nm Polling
|
|
|
|
is enabled with a
|
|
|
|
.Xr sysctl 8
|
|
|
|
variable
|
2002-02-15 08:34:33 +00:00
|
|
|
.Va kern.polling.enable
|
|
|
|
whereas the percentage of CPU cycles reserved to userland processes is
|
2002-03-18 16:29:26 +00:00
|
|
|
controlled by the
|
|
|
|
.Xr sysctl 8
|
|
|
|
variable
|
2002-02-15 08:34:33 +00:00
|
|
|
.Va kern.polling.user_frac
|
|
|
|
whose range is 0 to 100 (50 is the default value).
|
|
|
|
.Pp
|
2002-03-18 16:29:26 +00:00
|
|
|
When
|
|
|
|
.Nm
|
|
|
|
is enabled, and provided that there is work to do,
|
2002-02-15 08:34:33 +00:00
|
|
|
up to
|
2002-03-18 16:29:26 +00:00
|
|
|
.Va kern.polling.user_frac
|
2002-02-15 08:34:33 +00:00
|
|
|
percent of the CPU cycles is reserved to userland tasks, the
|
|
|
|
remaining fraction being available for device processing.
|
|
|
|
.Pp
|
2002-03-18 16:29:26 +00:00
|
|
|
Enabling
|
|
|
|
.Nm
|
|
|
|
also changes the way network software interrupts
|
2002-02-15 08:34:33 +00:00
|
|
|
are scheduled, so there is never the risk of livelock because
|
|
|
|
packets are not processed to completion.
|
|
|
|
.Pp
|
|
|
|
There are other variables which control or monitor the behaviour
|
|
|
|
of devices operating in polling mode, but they are unlikely to
|
|
|
|
require modifications, and are documented in the source file
|
2002-03-18 16:29:26 +00:00
|
|
|
.Pa sys/kern/kern_poll.c .
|
2002-02-15 08:34:33 +00:00
|
|
|
.Sh SUPPORTED DEVICES
|
2002-03-18 16:29:26 +00:00
|
|
|
.Nm Polling
|
|
|
|
requires explicit modifications to the device drivers.
|
2002-02-15 08:34:33 +00:00
|
|
|
As of this writing, the
|
2002-03-18 16:29:26 +00:00
|
|
|
.Xr dc 4 ,
|
2003-04-07 07:21:49 +00:00
|
|
|
.Xr em 4 ,
|
2004-01-11 22:07:19 +00:00
|
|
|
.Xr fwe 4 ,
|
2002-03-18 16:29:26 +00:00
|
|
|
.Xr fxp 4 ,
|
2004-01-11 22:07:19 +00:00
|
|
|
.Xr nge 4 ,
|
|
|
|
.Xr re 4 ,
|
2002-04-21 15:47:59 +00:00
|
|
|
.Xr rl 4 ,
|
2002-02-15 08:34:33 +00:00
|
|
|
and
|
2002-03-18 16:29:26 +00:00
|
|
|
.Xr sis 4
|
2002-02-15 08:34:33 +00:00
|
|
|
devices are supported, with other in the works.
|
|
|
|
The modifications are rather straightforward, consisting in
|
|
|
|
the extraction of the inner part of the interrupt service routine
|
2002-03-18 16:29:26 +00:00
|
|
|
and writing a callback function,
|
|
|
|
.Fn *_poll ,
|
|
|
|
which is invoked
|
|
|
|
to probe the device for events and process them.
|
|
|
|
See the
|
2002-02-15 08:34:33 +00:00
|
|
|
conditionally compiled sections of the devices mentioned above
|
|
|
|
for more details.
|
|
|
|
.Pp
|
2003-06-28 23:53:39 +00:00
|
|
|
As in the worst case devices are only polled on
|
2002-02-15 08:34:33 +00:00
|
|
|
clock interrupts, in order to reduce the latency in processing
|
2002-03-18 16:29:26 +00:00
|
|
|
packets, it is advisable to increase the frequency of the clock
|
2002-02-15 08:34:33 +00:00
|
|
|
to at least 1000 HZ.
|
|
|
|
.Sh HISTORY
|
|
|
|
Device polling was introduced in February 2002 by
|
|
|
|
.An Luigi Rizzo Aq luigi@iet.unipi.it .
|