X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FKernel%2Farch%2Fx86_64%2Ftime.c;h=fabd9286145377c8c0a898e8a28620a7a292f43e;hb=2b339e917d778c76b249457bcb66c4fb0007c495;hp=03c889fecc4faf6c4b207c78db0663c1d1d393c3;hpb=48743e39650eb1ef988380e9d95f27fd40d3a9ce;p=tpg%2Facess2.git diff --git a/KernelLand/Kernel/arch/x86_64/time.c b/KernelLand/Kernel/arch/x86_64/time.c index 03c889fe..fabd9286 100644 --- a/KernelLand/Kernel/arch/x86_64/time.c +++ b/KernelLand/Kernel/arch/x86_64/time.c @@ -5,12 +5,14 @@ */ #include #include +#include // === MACROS === #define TIMER_QUANTUM 100 #define TIMER_FREQ PIT_TIMER_BASE_N/(PIT_TIMER_BASE_D*PIT_TIMER_DIVISOR) #define MS_PER_TICK_WHOLE (1000*(PIT_TIMER_BASE_D*PIT_TIMER_DIVISOR)/PIT_TIMER_BASE_N) #define MS_PER_TICK_FRACT ((0x80000000ULL*1000ULL*PIT_TIMER_BASE_D*PIT_TIMER_DIVISOR/PIT_TIMER_BASE_N)&0x7FFFFFFF) +#define US_PER_TICK (1000*1000/(TIMER_FREQ)) // === IMPORTS === extern volatile Sint64 giTimestamp; @@ -103,6 +105,21 @@ void Time_TimerThread(void) } #endif +void Time_MicroSleep(Uint16 Microsecs) // max 64 ms +{ + Uint64 cur_tsc = Time_ReadTSC(); + // tsc_per_us * Microsec + Uint64 delta_tsc = (Uint64)Microsecs * giTime_TSCPerTick / US_PER_TICK; + Uint64 tgt_tsc = cur_tsc + delta_tsc; + + if( tgt_tsc < cur_tsc ) + while(Time_ReadTSC() > cur_tsc) + ; + + while( Time_ReadTSC() < tgt_tsc ) + ; +} + Uint64 Time_ReadTSC(void) { Uint32 a, d;