Интерактивная система просмотра системных руководств (man-ов)
>> polling (4) ( FreeBSD man: Специальные файлы /dev/* )
- device polling support
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.
This might seem inefficient and counterintuitive, but when done
gives more control to the operating system on
when and how to handle devices, with a number of advantages in terms
of system responsiveness and performance.
reduces the overhead for context
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.
Principles of Operation
In the normal, interrupt-based mode, devices generate an interrupt
whenever they need attention.
This in turn causes a
context switch and the execution of an interrupt handler
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
concerns in mind (which is generally not the case for
Furthermore, under heavy traffic load, the system might be
persistently processing interrupts without being able to
complete other work, either in the kernel or in userland.
Device polling disables interrupts by polling devices at appropriate
times, i.e., on clock interrupts and within the idle loop.
This way, the context switch overhead is removed.
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.
also changes the way software network interrupts
are scheduled, so there is never the risk of livelock because
packets are not processed to completion.
Currently only network interface drivers support the
It is turned on and off with help of
The operation of
is controlled by the following
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
Default is 50.
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
user_frac , burst_max
CPU speed, and system load.
The burst above is split into smaller chunks of this number of
packets, going round-robin among all interfaces registered for
This prevents the case that a large burst from a single interface
can saturate the IP interrupt queue
Default is 5.
Upper bound for
Note that when
is enabled, each interface can receive at most
(HZ * burst_max
packets per second unless there are spare CPU cycles available for
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.
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.
Controls how often (every
reg_frac / 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.
How many active devices have registered for
Legacy MIB, that was used to enable or disable polling globally.
Currently if set to 1,
is enabled on all capable interfaces.
If set to 0,
is disabled on all interfaces.
Device polling requires explicit modifications to the device drivers.
As of this writing, the
devices are supported, with others in the works.
The modifications are rather straightforward, consisting in
the extraction of the inner part of the interrupt service routine
and writing a callback function,
Fn *_poll ,
which is invoked
to probe the device for events and process them.
conditionally compiled sections of the devices mentioned above
for more details.)
As in the worst case the devices are only polled on clock interrupts,
in order to reduce the latency in processing packets, it is not advisable
to decrease the frequency of the clock below 1000 Hz.
Device polling first appeared in
Fx 5.0 .