qemu/hw/misc/macio/cuda.c
/* MacOS uses timer 1 for calibration on startup, so we use
 * the timebase frequency and cuda_get_counter_value() with
 * cuda_get_load_time() to steer MacOS to calculate calibrate its timers
 * correctly for both TCG and KVM (see commit b981289c49 "PPC: Cuda: Use cuda
 * timer to expose tbfreq to guest" for more information) */
MacOS uses timer 1 for calibration on startup, so we use
the timebase frequency and cuda_get_counter_value() with
cuda_get_load_time() to steer MacOS to calculate calibrate its timers
correctly for both TCG and KVM (see commit b981289c49 "PPC: Cuda: Use cuda
timer to expose tbfreq to guest" for more information)
MacOS uses timer 1 for calibration on startup so we use the timebase frequency and cuda_get_counter_value () with cuda_get_load_time () to steer MacOS to calculate calibrate its timers correctly for both TCG and KVM ( see commit b981289c49 " PPC : Cuda : Use cuda timer to expose tbfreq to guest " for more information )
static uint64_t cuda_get_counter_value(MOS6522State *s, MOS6522Timer *ti)
{
    MOS6522CUDAState *mcs = container_of(s, MOS6522CUDAState, parent_obj);
    CUDAState *cs = container_of(mcs, CUDAState, mos6522_cuda);
    uint64_t tb_diff = muldiv64(qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL),
                                cs->tb_frequency, NANOSECONDS_PER_SECOND) -
                           ti->load_time;
    return (tb_diff * 0xBF401675E5DULL) / (cs->tb_frequency << 24);
}
static uint64_t cuda_get_counter_value ( MOS6522State * s , MOS6522Timer * ti ) { MOS6522CUDAState * mcs = container_of ( s , MOS6522CUDAState , parent_obj ) ; CUDAState * cs = container_of ( mcs , CUDAState , mos6522_cuda ) ; uint64_t tb_diff = muldiv64 ( qemu_clock_get_ns ( QEMU_CLOCK_VIRTUAL ) , cs -> tb_frequency , NANOSECONDS_PER_SECOND ) - ti -> load_time ; return ( tb_diff * 0xBF401675E5DULL ) / ( cs -> tb_frequency << 24 ) ; }
MacOS uses timer 1 for calibration on startup, so we use
 the timebase frequency and cuda_get_counter_value() with
 cuda_get_load_time() to steer MacOS to calculate calibrate its timers
 correctly for both TCG and KVM (see commit b981289c49 "PPC: Cuda: Use cuda
 timer to expose tbfreq to guest" for more information)
MacOS uses timer 1 for calibration on startup so we use the timebase frequency and cuda_get_counter_value () with cuda_get_load_time () to steer MacOS to calculate calibrate its timers correctly for both TCG and KVM ( see commit b981289c49 " PPC : Cuda : Use cuda timer to expose tbfreq to guest " for more information )
/* Reverse of the tb calculation algorithm that Mac OS X uses on bootup */