POLLING(4)

πŸ“¦ version 15.1, in freebsd 14.5, freebsd 15.1, nixpkgs unstable

πŸ’– 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 is 50. 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 programmed user_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 is 5.
  • kern.polling.burst_max β€” upper bound for kern.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 is 150, which is adequate for 100Mbit network and HZ=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 (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.
  • kern.polling.handlers β€” how many active devices have registered for polling.
  • kern.polling.short_ticks
  • kern.polling.lost_polls
  • kern.polling.pending_polls
  • kern.polling.residual_burst
  • kern.polling.phase
  • kern.polling.suspect
  • kern.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