int main(void) { /* This is a fairly solid assumption that the math we're doing * is based on tb_hz of exactly 512mhz. * If we do start doing the math on different tb_hz, you probably * want to go and audit every bit of code that touches tb to * count/delay things. */ assert(tb_hz == 512000000); assert(secs_to_tb(1) == tb_hz); assert(secs_to_tb(2) == 1024000000); assert(secs_to_tb(10) == 5120000000); assert(tb_to_secs(512000000) == 1); assert(tb_to_secs(5120000000) == 10); assert(tb_to_secs(1024000000) == 2); assert(msecs_to_tb(1) == 512000); assert(msecs_to_tb(100) == 51200000); assert(msecs_to_tb(5) == 2560000); assert(tb_to_msecs(512000) == 1); assert(usecs_to_tb(5) == 2560); assert(tb_to_usecs(2560) == 5); assert(usecs_to_tb(5)*1000 == msecs_to_tb(5)); assert(tb_to_usecs(512000) == 1000); assert(tb_compare(msecs_to_tb(5), usecs_to_tb(5)) == TB_AAFTERB); assert(tb_compare(msecs_to_tb(5), usecs_to_tb(50000)) == TB_ABEFOREB); assert(tb_compare(msecs_to_tb(5), usecs_to_tb(5)*1000) == TB_AEQUALB); return 0; }
void p8_sbe_init_timer(void) { struct dt_node *np; int64_t rc; uint32_t tick_us; np = dt_find_compatible_node(dt_root, NULL, "ibm,power8-sbe-timer"); if (!np) return; sbe_timer_chip = dt_get_chip_id(np); tick_us = dt_prop_get_u32(np, "tick-time-us"); sbe_timer_inc = usecs_to_tb(tick_us); sbe_timer_target = ~0ull; rc = xscom_read(sbe_timer_chip, 0xE0006, &sbe_last_gen); if (rc) { prerror("SLW: Error %lld reading tmr gen count\n", rc); return; } sbe_last_gen_stamp = mftb(); prlog(PR_INFO, "SLW: Timer facility on chip %d, resolution %dus\n", sbe_timer_chip, tick_us); sbe_has_timer = true; }
void cpu_wait_job(struct cpu_job *job, bool free_it) { unsigned long ticks = usecs_to_tb(5); if (!job) return; while(!job->complete) { time_wait(ticks); lwsync(); } lwsync(); smt_medium(); if (free_it) free(job); }