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

Function round_freq

freebsd/kern/kern_clocksource.c:568–587  ·  view source on GitHub ↗

* Calculate nearest frequency supported by hardware timer. */

Source from the content-addressed store, hash-verified

566 * Calculate nearest frequency supported by hardware timer.
567 */
568static int
569round_freq(struct eventtimer *et, int freq)
570{
571 uint64_t div;
572
573 if (et->et_frequency != 0) {
574 div = lmax((et->et_frequency + freq / 2) / freq, 1);
575 if (et->et_flags & ET_FLAGS_POW2DIV)
576 div = 1 << (flsl(div + div / 2) - 1);
577 freq = (et->et_frequency + div / 2) / div;
578 }
579 if (et->et_min_period > SBT_1S)
580 panic("Event timer \"%s\" doesn't support sub-second periods!",
581 et->et_name);
582 else if (et->et_min_period != 0)
583 freq = min(freq, SBT2FREQ(et->et_min_period));
584 if (et->et_max_period < SBT_1S && et->et_max_period != 0)
585 freq = max(freq, SBT2FREQ(et->et_max_period));
586 return (freq);
587}
588
589/*
590 * Configure and start event timers (BSP part).

Callers 2

setuptimerFunction · 0.85
cpu_initclocks_bspFunction · 0.85

Calls 5

lmaxFunction · 0.85
minFunction · 0.85
maxFunction · 0.85
panicFunction · 0.70
flslFunction · 0.50

Tested by

no test coverage detected