2004-03-06 21:20:47 +00:00
|
|
|
.\" Copyright (c) 2002 Luigi Rizzo
|
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
2002-02-15 08:34:33 +00:00
|
|
|
.\"
|
|
|
|
.\" $FreeBSD$
|
|
|
|
.\"
|
2004-12-14 19:27:16 +00:00
|
|
|
.Dd December 14, 2004
|
2002-02-15 08:34:33 +00:00
|
|
|
.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
|
2004-03-06 21:20:47 +00:00
|
|
|
Device polling
|
|
|
|
.Nm (
|
2004-09-18 12:33:01 +00:00
|
|
|
for brevity) refers to a technique that
|
|
|
|
lets the operating system periodically poll devices, instead of
|
|
|
|
relying on the devices to generate interrupts when they need attention.
|
2002-02-15 08:34:33 +00:00
|
|
|
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
|
2004-03-06 21:20:47 +00:00
|
|
|
of system responsiveness and performance.
|
2002-02-15 08:34:33 +00:00
|
|
|
.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.
|
2004-03-06 21:20:47 +00:00
|
|
|
.Ss Principles of Operation
|
2002-02-15 08:34:33 +00:00
|
|
|
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).
|
2004-03-06 21:20:47 +00:00
|
|
|
Furthermore, under heavy traffic load, 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
|
2004-03-06 21:20:47 +00:00
|
|
|
Device polling disables interrupts by polling devices at appropriate
|
2002-03-18 16:29:26 +00:00
|
|
|
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
|
2004-03-06 21:20:47 +00:00
|
|
|
Enabling
|
|
|
|
.Nm
|
|
|
|
also changes the way software network interrupts
|
|
|
|
are scheduled, so there is never the risk of livelock because
|
|
|
|
packets are not processed to completion.
|
|
|
|
.Ss MIB Variables
|
|
|
|
The operation of
|
|
|
|
.Nm
|
|
|
|
is controlled by the following
|
2002-03-18 16:29:26 +00:00
|
|
|
.Xr sysctl 8
|
2004-03-06 21:20:47 +00:00
|
|
|
MIB variables:
|
|
|
|
.Pp
|
|
|
|
.Bl -tag -width indent -compact
|
|
|
|
.It Va kern.polling.enable
|
|
|
|
If set to non-zero,
|
|
|
|
.Nm
|
|
|
|
is enabled.
|
|
|
|
Default is disabled.
|
2002-02-15 08:34:33 +00:00
|
|
|
.Pp
|
2004-03-06 21:20:47 +00:00
|
|
|
.It Va kern.polling.user_frac
|
2002-03-18 16:29:26 +00:00
|
|
|
When
|
|
|
|
.Nm
|
2004-03-06 21:20:47 +00:00
|
|
|
is enabled, and provided that there is some work to do,
|
|
|
|
up to this percent of the CPU cycles is reserved to userland tasks,
|
|
|
|
the remaining fraction being available for
|
|
|
|
.Nm
|
|
|
|
processing.
|
|
|
|
Default is 50.
|
2002-02-15 08:34:33 +00:00
|
|
|
.Pp
|
2004-03-06 21:20:47 +00:00
|
|
|
.It Va kern.polling.burst
|
|
|
|
Maximum number of packets grabbed from each network interface in
|
|
|
|
each timer tick.
|
|
|
|
This number is dynamically adjusted by the kernel,
|
|
|
|
according to the programmed
|
|
|
|
.Va user_frac , burst_max ,
|
|
|
|
CPU speed, and system load.
|
|
|
|
.Pp
|
|
|
|
.It Va kern.polling.each_burst
|
|
|
|
The burst above is split into smaller chunks of this number of
|
|
|
|
packets, going round-robin among all interfaces registered for
|
|
|
|
.Nm .
|
|
|
|
This prevents the case that a large burst from a single interface
|
|
|
|
can saturate the IP interrupt queue
|
|
|
|
.Pq Va net.inet.ip.intr_queue_maxlen .
|
|
|
|
Default is 5.
|
|
|
|
.Pp
|
|
|
|
.It Va kern.polling.burst_max
|
|
|
|
Upper bound for
|
|
|
|
.Va kern.polling.burst .
|
|
|
|
Note that when
|
2002-03-18 16:29:26 +00:00
|
|
|
.Nm
|
2004-03-06 21:20:47 +00:00
|
|
|
is enabled, each interface can receive at most
|
|
|
|
.Pq Va HZ No * Va burst_max
|
|
|
|
packets per second unless there are spare CPU cycles available for
|
|
|
|
.Nm
|
|
|
|
in the idle loop.
|
|
|
|
This number should be tuned to match the expected load
|
|
|
|
(which can be quite high with GigE cards).
|
|
|
|
Default is 150 which is adequate for 100Mbit network and HZ=1000.
|
|
|
|
.Pp
|
|
|
|
.It Va kern.polling.idle_poll
|
|
|
|
Controls if
|
|
|
|
.Nm
|
|
|
|
is enabled in the idle loop.
|
|
|
|
There are no reasons (other than power saving or bugs in the scheduler's
|
|
|
|
handling of idle priority kernel threads) to disable this.
|
|
|
|
Note that -CURRENT apparently has some problems in this respect now,
|
|
|
|
so default is disabled.
|
|
|
|
.Pp
|
|
|
|
.It Va kern.polling.poll_in_trap
|
|
|
|
Controls if
|
|
|
|
.Nm
|
|
|
|
is enabled during hardware traps.
|
|
|
|
Enabling this can be useful to improve the network responsiveness
|
|
|
|
of boxes with 100% CPU usage.
|
|
|
|
Default is disabled.
|
2002-02-15 08:34:33 +00:00
|
|
|
.Pp
|
2004-03-06 21:20:47 +00:00
|
|
|
.It Va kern.polling.reg_frac
|
|
|
|
Controls how often (every
|
|
|
|
.Va reg_frac No / Va HZ
|
|
|
|
seconds) the status registers of the device are checked for error
|
|
|
|
conditions and the like.
|
|
|
|
Increasing this value reduces the load on the bus, but also delays
|
|
|
|
the error detection.
|
|
|
|
Default is 20.
|
|
|
|
.Pp
|
|
|
|
.It Va kern.polling.handlers
|
|
|
|
How many active devices have registered for
|
|
|
|
.Nm .
|
|
|
|
.Pp
|
|
|
|
.It Va kern.polling.short_ticks
|
|
|
|
.It Va kern.polling.lost_polls
|
|
|
|
.It Va kern.polling.pending_polls
|
|
|
|
.It Va kern.polling.residual_burst
|
|
|
|
.It Va kern.polling.phase
|
|
|
|
.It Va kern.polling.suspect
|
|
|
|
.It Va kern.polling.stalled
|
|
|
|
Debugging variables.
|
|
|
|
.El
|
2002-02-15 08:34:33 +00:00
|
|
|
.Sh SUPPORTED DEVICES
|
2004-03-06 21:20:47 +00:00
|
|
|
Device 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 ,
|
2004-12-14 19:27:16 +00:00
|
|
|
.Xr fwip 4 ,
|
2002-03-18 16:29:26 +00:00
|
|
|
.Xr fxp 4 ,
|
2004-09-05 14:47:10 +00:00
|
|
|
.Xr ixgb 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 ,
|
2004-11-10 23:31:15 +00:00
|
|
|
.Xr sf 4 ,
|
2004-03-31 20:39:20 +00:00
|
|
|
.Xr sis 4 ,
|
2004-04-05 17:43:57 +00:00
|
|
|
.Xr ste 4 ,
|
2004-10-11 13:27:44 +00:00
|
|
|
.Xr vge 4 ,
|
2002-02-15 08:34:33 +00:00
|
|
|
and
|
2004-04-05 17:43:57 +00:00
|
|
|
.Xr vr 4
|
2004-03-06 21:20:47 +00:00
|
|
|
devices are supported, with others in the works.
|
2002-02-15 08:34:33 +00:00
|
|
|
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.
|
2004-03-06 21:20:47 +00:00
|
|
|
(See the
|
2002-02-15 08:34:33 +00:00
|
|
|
conditionally compiled sections of the devices mentioned above
|
2004-03-06 21:20:47 +00:00
|
|
|
for more details.)
|
2002-02-15 08:34:33 +00:00
|
|
|
.Pp
|
2004-03-06 21:20:47 +00:00
|
|
|
As in the worst case the 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
|
2004-03-06 21:20:47 +00:00
|
|
|
Device polling first appeared in
|
|
|
|
.Fx 4.6
|
|
|
|
and
|
|
|
|
.Fx 5.0 .
|
|
|
|
.Sh AUTHORS
|
|
|
|
Device polling was written by
|
2002-02-15 08:34:33 +00:00
|
|
|
.An Luigi Rizzo Aq luigi@iet.unipi.it .
|