MCPcopy Create free account
hub / github.com/F-Stack/f-stack / callout_process

Function callout_process

freebsd/kern/kern_timeout.c:415–539  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

413}
414
415void
416callout_process(sbintime_t now)
417{
418 struct callout *tmp, *tmpn;
419 struct callout_cpu *cc;
420 struct callout_list *sc;
421 sbintime_t first, last, max, tmp_max;
422 uint32_t lookahead;
423 u_int firstb, lastb, nowb;
424#ifdef CALLOUT_PROFILING
425 int depth_dir = 0, mpcalls_dir = 0, lockcalls_dir = 0;
426#endif
427
428 cc = CC_SELF();
429 mtx_lock_spin_flags(&cc->cc_lock, MTX_QUIET);
430
431 /* Compute the buckets of the last scan and present times. */
432 firstb = callout_hash(cc->cc_lastscan);
433 cc->cc_lastscan = now;
434 nowb = callout_hash(now);
435
436 /* Compute the last bucket and minimum time of the bucket after it. */
437 if (nowb == firstb)
438 lookahead = (SBT_1S / 16);
439 else if (nowb - firstb == 1)
440 lookahead = (SBT_1S / 8);
441 else
442 lookahead = (SBT_1S / 2);
443 first = last = now;
444 first += (lookahead / 2);
445 last += lookahead;
446 last &= (0xffffffffffffffffLLU << (32 - CC_HASH_SHIFT));
447 lastb = callout_hash(last) - 1;
448 max = last;
449
450 /*
451 * Check if we wrapped around the entire wheel from the last scan.
452 * In case, we need to scan entirely the wheel for pending callouts.
453 */
454 if (lastb - firstb >= callwheelsize) {
455 lastb = firstb + callwheelsize - 1;
456 if (nowb - firstb >= callwheelsize)
457 nowb = lastb;
458 }
459
460 /* Iterate callwheel from firstb to nowb and then up to lastb. */
461 do {
462 sc = &cc->cc_callwheel[firstb & callwheelmask];
463 tmp = LIST_FIRST(sc);
464 while (tmp != NULL) {
465 /* Run the callout if present time within allowed. */
466 if (tmp->c_time <= now) {
467 /*
468 * Consumer told us the callout may be run
469 * directly from hardware interrupt context.
470 */
471 if (tmp->c_iflags & CALLOUT_DIRECT) {
472#ifdef CALLOUT_PROFILING

Callers 1

handleeventsFunction · 0.85

Calls 4

callout_hashFunction · 0.85
cpu_new_calloutFunction · 0.85
softclock_call_ccFunction · 0.70
swi_schedFunction · 0.70

Tested by

no test coverage detected