mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-30 05:58:22 +00:00
timekeeper: ticks_per_us (mhz) -> hz
This commit is contained in:
@@ -89,7 +89,7 @@ static timekeeper_source_info_t *hpet_init(void) {
|
||||
struct acpi_hpet *table;
|
||||
|
||||
MUTEX_ACQUIRE(&init_mutex, false);
|
||||
if (timekeeper_source_info.ticks_per_us) {
|
||||
if (timekeeper_source_info.hz) {
|
||||
// already initialized by someone else
|
||||
goto leave;
|
||||
}
|
||||
@@ -107,9 +107,9 @@ static timekeeper_source_info_t *hpet_init(void) {
|
||||
hpet_private.hpet = (void *)((uintptr_t)hpet_private.hpet + page_offset);
|
||||
|
||||
uint64_t capabilities = read64(HPET_REG_CAPS);
|
||||
timekeeper_source_info.ticks_per_us = 1000000000 / HPET_CAP_FSPERTICK(capabilities);
|
||||
printf("hpet%lu: %lu ticks per us (%lu fs per tick)\n", table->number, timekeeper_source_info.ticks_per_us, HPET_CAP_FSPERTICK(capabilities));
|
||||
__assert(timekeeper_source_info.ticks_per_us);
|
||||
timekeeper_source_info.hz = 1000000000000000lu / HPET_CAP_FSPERTICK(capabilities);
|
||||
printf("hpet%lu: %lu ticks per us (%lu hz)\n", table->number, timekeeper_source_info.hz, HPET_CAP_FSPERTICK(capabilities));
|
||||
__assert(timekeeper_source_info.hz);
|
||||
|
||||
write64(HPET_REG_CONFIG, 0);
|
||||
write64(HPET_REG_COUNTER, 0);
|
||||
|
||||
@@ -47,7 +47,7 @@ static timekeeper_source_info_t *kvm_timer_init(void) {
|
||||
timekeeper_source_info_t *timekeeper_source_info = alloc(sizeof(timekeeper_source_info_t));
|
||||
__assert(timekeeper_source_info);
|
||||
|
||||
timekeeper_source_info->ticks_per_us = 1000; // each tick in the kvm timer system_time field is 1 ns
|
||||
timekeeper_source_info->hz = 1000000000; // each tick in the kvm timer system_time field is 1 ns
|
||||
void *virtual_address = alloc(sizeof(kvm_timer_info_t));
|
||||
__assert(virtual_address);
|
||||
__assert(((uintptr_t)virtual_address % KVM_TIMER_SYSTEM_TIME_ALIGNMENT) == 0);
|
||||
|
||||
@@ -21,7 +21,9 @@ static bool tsc_probe(void) {
|
||||
}
|
||||
|
||||
static MUTEX_DEFINE(init_mutex);
|
||||
static time_t ticks_per_us;
|
||||
// keeping this here in a multisocket machine could possibly result in completely wrong
|
||||
// tsc measurements for the other sokets. disable the tsc in these using the "notsc" commandline option.
|
||||
static time_t hz;
|
||||
|
||||
static timekeeper_source_info_t *tsc_init(void) {
|
||||
MUTEX_ACQUIRE(&init_mutex, false);
|
||||
@@ -32,7 +34,7 @@ static timekeeper_source_info_t *tsc_init(void) {
|
||||
|
||||
timekeeper_source_info->private = current_cpu();
|
||||
|
||||
if (ticks_per_us)
|
||||
if (hz)
|
||||
goto leave;
|
||||
|
||||
bool need_calibration = false;
|
||||
@@ -50,17 +52,17 @@ static timekeeper_source_info_t *tsc_init(void) {
|
||||
uint64_t core_denominator = cpuid_results.eax;
|
||||
|
||||
uint64_t tsc_frequency = core_frequency * core_numerator / core_denominator;
|
||||
ticks_per_us = tsc_frequency / 1000000;
|
||||
hz = tsc_frequency;
|
||||
}
|
||||
|
||||
calibrate:
|
||||
if (need_calibration) {
|
||||
ticks_per_us = arch_hpet_calibrate_tsc(200) / 1000;
|
||||
__assert(ticks_per_us);
|
||||
hz = arch_hpet_calibrate_tsc(200) * 1000;
|
||||
__assert(hz);
|
||||
}
|
||||
|
||||
leave:
|
||||
timekeeper_source_info->ticks_per_us = ticks_per_us;
|
||||
timekeeper_source_info->hz = hz;
|
||||
MUTEX_RELEASE(&init_mutex);
|
||||
return timekeeper_source_info;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user