FreeBSD/sys/kern/kern_poll.c
/*
 * Hook from hardclock. Tries to schedule a netisr, but keeps track
 * of lost ticks due to the previous handler taking too long.
 * Normally, this should not happen, because polling handler should
 * run for a short time. However, in some cases (e.g. when there are
 * changes in link status etc.) the drivers take a very long time
 * (even in the order of milliseconds) to reset and reconfigure the
 * device, causing apparent lost polls.
 *
 * The first part of the code is just for debugging purposes, and tries
 * to count how often hardclock ticks are shorter than they should,
 * meaning either stray interrupts or delayed events.
 */
Hook from hardclock. Tries to schedule a netisr, but keeps track
of lost ticks due to the previous handler taking too long.
Normally, this should not happen, because polling handler should
run for a short time. However, in some cases  the drivers take a very long time
(even in the order of milliseconds) to reset and reconfigure the
device, causing apparent lost polls.

The first part of the code is just for debugging purposes, and tries
to count how often hardclock ticks are shorter than they should,
meaning either stray interrupts or delayed events.
Hook from hardclock . Tries to schedule a netisr but keeps track of lost ticks due to the previous handler taking too long . Normally this should not happen because polling handler should run for a short time . However in some cases the drivers take a very long time ( even in the order of milliseconds ) to reset and reconfigure the device causing apparent lost polls . The first part of the code is just for debugging purposes and tries to count how often hardclock ticks are shorter than they should meaning either stray interrupts or delayed events .
void
hardclock_device_poll(void)
{
	static struct timeval prev_t, t;
	int delta;
	if (poll_handlers == 0 || poll_shutting_down)
		return;
	microuptime(&t);
	delta = (t.tv_usec - prev_t.tv_usec) +
		(t.tv_sec - prev_t.tv_sec)*1000000;
	if (delta * hz < 500000)
		short_ticks++;
	else
		prev_t = t;
	if (pending_polls > 100) {
		stalled++;
		pending_polls = 0;
		phase = 0;
	}
	if (phase <= 2) {
		if (phase != 0)
			suspect++;
		phase = 1;
		netisr_poll_scheduled = 1;
		netisr_pollmore_scheduled = 1;
		netisr_sched_poll();
		phase = 2;
	}
	if (pending_polls++ > 0)
		lost_polls++;
}
void hardclock_device_poll ( void ) { static struct timeval prev_t , t ; int delta ; if ( poll_handlers == 0 || poll_shutting_down ) return ; microuptime ( & t ) ; delta = ( t . tv_usec - prev_t . tv_usec ) + ( t . tv_sec - prev_t . tv_sec ) * 1000000 ; if ( delta * hz < 500000 ) short_ticks ++ ; else prev_t = t ; if ( pending_polls > 100 ) { stalled ++ ; pending_polls = 0 ; phase = 0 ; } if ( phase <= 2 ) { if ( phase != 0 ) suspect ++ ; phase = 1 ; netisr_poll_scheduled = 1 ; netisr_pollmore_scheduled = 1 ; netisr_sched_poll ( ) ; phase = 2 ; } if ( pending_polls ++ > 0 ) lost_polls ++ ; }
Hook from hardclock.
Hook from hardclock .
/*
		 * Too much, assume it has stalled (not always true
		 * see comment above).
		 */