LibC: Cleanup TSC clock_gettime control flow
This commit is contained in:
@@ -47,30 +47,25 @@ int clock_gettime(clockid_t clock_id, struct timespec* tp)
|
|||||||
} while (seq1 != seq2 || (seq1 & 1));
|
} while (seq1 != seq2 || (seq1 & 1));
|
||||||
};
|
};
|
||||||
|
|
||||||
read_tsc_info:
|
|
||||||
if (g_shared_page->features & Kernel::API::SPF_RDTSCP)
|
if (g_shared_page->features & Kernel::API::SPF_RDTSCP)
|
||||||
{
|
{
|
||||||
|
do {
|
||||||
uint32_t cpu;
|
uint32_t cpu;
|
||||||
curr_tsc = __builtin_ia32_rdtscp(&cpu);
|
curr_tsc = __builtin_ia32_rdtscp(&cpu);
|
||||||
read_tsc_info(g_shared_page->cpus[cpu].gettime_local);
|
read_tsc_info(g_shared_page->cpus[cpu].gettime_local);
|
||||||
|
} while (curr_tsc < last_tsc);
|
||||||
}
|
}
|
||||||
else for (;;)
|
else
|
||||||
{
|
{
|
||||||
uint16_t cpu1, cpu2;
|
uint16_t cpu1, cpu2;
|
||||||
|
do {
|
||||||
asm volatile("lsl %1, %0" : "=r"(cpu1) : "r"(g_shared_page->gdt_cpu_offset));
|
asm volatile("lsl %1, %0" : "=r"(cpu1) : "r"(g_shared_page->gdt_cpu_offset));
|
||||||
|
read_tsc_info(g_shared_page->cpus[cpu1].gettime_local);
|
||||||
curr_tsc = __builtin_ia32_rdtsc();
|
curr_tsc = __builtin_ia32_rdtsc();
|
||||||
asm volatile("lsl %1, %0" : "=r"(cpu2) : "r"(g_shared_page->gdt_cpu_offset));
|
asm volatile("lsl %1, %0" : "=r"(cpu2) : "r"(g_shared_page->gdt_cpu_offset));
|
||||||
if (cpu1 != cpu2)
|
} while (cpu1 != cpu2);
|
||||||
continue;
|
|
||||||
read_tsc_info(g_shared_page->cpus[cpu1].gettime_local);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NOTE: as we read TSC before getting the calibration, it is possible
|
|
||||||
// for the calibration to get updated in between.
|
|
||||||
if (curr_tsc < last_tsc)
|
|
||||||
goto read_tsc_info;
|
|
||||||
|
|
||||||
uint64_t clock_ns = curr_tsc - last_tsc;
|
uint64_t clock_ns = curr_tsc - last_tsc;
|
||||||
if (shift >= 0)
|
if (shift >= 0)
|
||||||
clock_ns <<= shift;
|
clock_ns <<= shift;
|
||||||
|
|||||||
Reference in New Issue
Block a user