POLLING(4)
π POLLING(4) π
okay bestie, so this is the Kernel Interfaces Manual page for polling β yes, device polling support, and it's literally so cool. let me break it down for you fr fr.
β¨ SYNOPSIS β¨
options DEVICE_POLLING
that's it. that's the whole synopsis. iconic.
π¦ DESCRIPTION π¦
so like, device polling (or just "polling" if we're being casual) is this technique where the OS periodically checks on devices instead of waiting for them to interrupt and be like "hey i need attention." and yeah, at first glance you'd think "bestie that sounds inefficient and counterintuitive," but no cap β when you do it properly, polling gives the OS way more control over when and how to handle devices. it's giving main character energy in terms of system responsiveness and performance.
the way that polling reduces the overhead for context switches? obsessed. those are the things that happen when you're servicing interrupts, and polling also gives you more control over how the CPU schedules itself between all the tasks (user processes, software interrupts, device handling). ultimately it reduces the chances of livelock in the system. periodt.
πΈ Principles of Operation πΈ
so in the normal, interrupt-based mode, devices generate an interrupt whenever they need attention. that causes a context switch and runs an interrupt handler that does whatever processing the device needs. and the duration of that interrupt handler is potentially unbounded unless the device driver was programmed with real-time concerns in mind β which is generally not the case for FreeBSD drivers. oop. π
and under heavy traffic load? the system might just be persistently processing interrupts without being able to complete other work, either in the kernel or in userland. not slay.
but device polling disables interrupts by polling devices at appropriate times β like on clock interrupts and within the idle loop. this way, the context switch overhead is removed. and the OS can control accurately how much work to spend handling device events, so it can prevent livelock by reserving some amount of CPU for other tasks. chef's kiss.
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. we love to see it.
π Enabling polling π
currently only network interface drivers support the polling feature. it's turned on and off with the help of ifconfig(8). iykyk.
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 there's some work to do, up to this percent of CPU cycles is reserved for userland tasks, and the remaining fraction is available for polling processing. default is50. slay.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 programmeduser_frac,burst_max, CPU speed, and system load. fancy.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 polling. this prevents the case where a large burst from a single interface can saturate the IP interrupt queue (net.inet.ip.intr_queue_maxlen). default is5.kern.polling.burst_maxβ 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. no cap.kern.polling.idle_pollβ controls if 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. so like, don't.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 also delays the 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β debugging variables. π
π 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), sis(4), ste(4), stge(4), vge(4), vr(4), and xl(4) 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, *_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.)
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. like, just don't. π
β HISTORY β
device polling first appeared in FreeBSD 4.6 and FreeBSD 5.0. we stan a legacy feature.
π AUTHORS π
device polling was written by Luigi Rizzo <luigi@iet.unipi.it>. king behavior, honestly. π«Ά
so that's the whole tea bestie! this page came from the Debian manual, dated December 26, 2020. go forth and poll responsibly! πβ¨
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- nixpkgs unstable: source
- Copyright (c) 2002 Luigi Rizzo
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms