// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2024 Intel Corporation * * Verify KVM correctly emulates the APIC bus frequency when the VMM configures * the frequency via KVM_CAP_X86_APIC_BUS_CYCLES_NS. Start the APIC timer by * programming TMICT (timer initial count) to the largest value possible (so * that the timer will not expire during the test). Then, after an arbitrary * amount of time has elapsed, verify TMCCT (timer current count) is within 1% * of the expected value based on the time elapsed, the APIC bus frequency, and * the programmed TDCR (timer divide configuration register).
*/
/* * Setup one-shot timer. The vector does not matter because the * interrupt should not fire.
*/
apic_write_reg(APIC_LVTT, APIC_LVT_TIMER_ONESHOT | APIC_LVT_MASKED);
for (i = 0; i < ARRAY_SIZE(tdcrs); i++) {
apic_write_reg(APIC_TDCR, tdcrs[i].tdcr);
apic_write_reg(APIC_TMICT, tmict);
/* * Stop the timer _after_ reading the current, final count, as * writing the initial counter also modifies the current count.
*/
apic_write_reg(APIC_TMICT, 0);
ret = __vm_enable_cap(vm, KVM_CAP_X86_APIC_BUS_CYCLES_NS,
NSEC_PER_SEC / apic_hz);
TEST_ASSERT(ret < 0 && errno == EINVAL, "Setting of APIC bus frequency after vCPU is created should fail.");
if (!is_x2apic)
virt_pg_map(vm, APIC_DEFAULT_GPA, APIC_DEFAULT_GPA);
test_apic_bus_clock(vcpu);
kvm_vm_free(vm);
}
staticvoid help(char *name)
{
puts("");
printf("usage: %s [-h] [-d delay] [-f APIC bus freq]\n", name);
puts("");
printf("-d: Delay (in msec) guest uses to measure APIC bus frequency.\n");
printf("-f: The APIC bus frequency (in MHz) to be configured for the guest.\n");
puts("");
}
int main(int argc, char *argv[])
{ /* * Arbitrarilty default to 25MHz for the APIC bus frequency, which is * different enough from the default 1GHz to be interesting.
*/
uint64_t apic_hz = 25 * 1000 * 1000;
uint64_t delay_ms = 100; int opt;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.