POLLING(4)
π POLLING π
okay bestie, gather round, because today we're talking about polling β aka device polling support β and it's genuinely one of those things that sounds backwards until you get it, and then you're like. oh. oh that's iconic.
β¨ SYNOPSIS β¨
options DEVICE_POLLING
π¦ DESCRIPTION π¦
So. Device polling (or just polling, because we're casual like that) is a technique where the operating system periodically polls devices instead of sitting there waiting for the devices to interrupt and be like "hey!! i need attention!!"
And yeah, on first read that sounds inefficient and counterintuitive, ngl. But when it's done properly? Polling hands the OS way more control over when and how it handles devices, and that comes with a bunch of advantages for system responsiveness and performance. π
Specifically:
- it reduces the overhead for context switches that you'd otherwise pay when servicing interrupts
- it gives more control over how the CPU is scheduled between all the various tasks β user processes, software interrupts, device handling
- and all of that 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. That causes a context switch, and then an interrupt handler runs and does whatever processing the device needs.
Here's the tea though: the duration of the interrupt handler is potentially unbounded unless the device driver was written with real-time concerns in mind β and for FreeBSD drivers, that's generally not the case. π
And under heavy traffic load? The system might just be persistently processing interrupts without ever being able to finish other work β whether that's in the kernel or in userland.
bestie. that's the livelock nightmare. not cute.
So device polling disables interrupts by polling devices at appropriate times β specifically, on clock interrupts and within the idle loop. This way, the context switch overhead is removed. β¨
And it gets better: the OS can accurately control how much work to spend handling device events, which means it can prevent livelock by reserving some amount of CPU for other tasks. main character scheduling energy, honestly.
Enabling polling also changes the way software network interrupts are scheduled, so there's never the risk of livelock because packets are not processed to completion. π«Ά
π Enabling polling π
Currently only network interface drivers support the polling feature. You turn it on and off with the help of ifconfig(8).
The historic kern.polling.enable, which enabled polling for all interfaces, can be replaced with the following code:
for i in `ifconfig -l` ;
do ifconfig $i polling; # use -polling to disable
done
β MIB Variables β
The operation of polling is controlled by the following sysctl(8) MIB variables:
kern.polling.user_fracβ when polling is enabled, and provided that there is some work to do, up to this percent of the CPU cycles is reserved for userland tasks, and the remaining fraction is available for polling processing. Default is50.kern.polling.burstβ the maximum number of packets grabbed from each network interface in each timer tick. This number is dynamically adjusted by the kernel, according to the programmeduser_frac,burst_max, CPU speed, and system load.kern.polling.each_burstβ the burst above gets split into smaller chunks of this number of packets, going round-robin among all interfaces registered for polling. This prevents the situation where a large burst from a single interface saturates the IP interrupt queue (net.inet.ip.intr_queue_maxlen). Default is5.kern.polling.burst_maxβ the upper bound forkern.polling.burst. Note that when polling is enabled, each interface can receive at most(HZ * burst_max)packets per second, unless there are spare CPU cycles available for polling in the idle loop. This number should be tuned to match the expected load (which can be quite high with GigE cards). Default is150, which is adequate for 100Mbit network andHZ=1000.kern.polling.idle_pollβ controls whether polling 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.kern.polling.reg_fracβ controls how often (everyreg_frac / HZseconds) the status registers of the device are checked for error conditions and the like. Increasing this value reduces the load on the bus, but it also delays error detection. Default is20.kern.polling.handlersβ how many active devices have registered for polling.kern.polling.short_tickskern.polling.lost_pollskern.polling.pending_pollskern.polling.residual_burstkern.polling.phasekern.polling.suspectkern.polling.stalled
those last seven? yeah. Debugging variables. they're the little guys watching from the wings. π§
π₯ SUPPORTED DEVICES π₯
Device polling requires explicit modifications to the device drivers. As of this writing, the bge(4), dc(4), em(4), fwe(4), fwip(4), fxp(4), igb(4), nfe(4), nge(4), re(4), rl(4), sf(4), sis(4), ste(4), stge(4), vge(4), vr(4), and xl(4) devices are supported, with others in the works. π
The modifications are actually pretty straightforward, consisting of:
- extracting the inner part of the interrupt service routine, and
- writing a callback function,
*_poll(), which is invoked to probe the device for events and process them.
(See the conditionally compiled sections of the devices mentioned above for more details.)
β οΈ heads up bestie: since in the worst case the devices are only polled on clock interrupts, it is not advisable to decrease the frequency of the clock below 1000 Hz β that would just add latency to packet processing. no cap.
π HISTORY π
Device polling first appeared in FreeBSD 4.6 and FreeBSD 5.0.
π AUTHORS π
Device polling was written by Luigi Rizzo <luigi@iet.unipi.it>. absolute legend behavior, fr fr. π
okay that's the whole page, you ate it, you read it, you're basically a kernel girlie now π β¨
this was from the Debian build, dated April 6, 2007 β shoutout to the archive for keeping it cute, and byeee ππ¦
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2002 Luigi Rizzo
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms