Skip to content

Commit 2fe9e0f

Browse files
author
Marc Zyngier
committed
KVM: arm64: selftests: Augment existing timer test to handle variable offset
Allow a user to specify the global offset on the command-line. Reviewed-by: Colton Lewis <coltonlewis@google.com> Signed-off-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20230330174800.2677007-21-maz@kernel.org
1 parent 056c156 commit 2fe9e0f

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

tools/testing/selftests/kvm/aarch64/arch_timer.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@ struct test_args {
4747
int nr_iter;
4848
int timer_period_ms;
4949
int migration_freq_ms;
50+
struct kvm_arm_counter_offset offset;
5051
};
5152

5253
static struct test_args test_args = {
5354
.nr_vcpus = NR_VCPUS_DEF,
5455
.nr_iter = NR_TEST_ITERS_DEF,
5556
.timer_period_ms = TIMER_TEST_PERIOD_MS_DEF,
5657
.migration_freq_ms = TIMER_TEST_MIGRATION_FREQ_MS,
58+
.offset = { .reserved = 1 },
5759
};
5860

5961
#define msecs_to_usecs(msec) ((msec) * 1000LL)
@@ -382,6 +384,13 @@ static struct kvm_vm *test_vm_create(void)
382384
vm_init_descriptor_tables(vm);
383385
vm_install_exception_handler(vm, VECTOR_IRQ_CURRENT, guest_irq_handler);
384386

387+
if (!test_args.offset.reserved) {
388+
if (kvm_has_cap(KVM_CAP_COUNTER_OFFSET))
389+
vm_ioctl(vm, KVM_ARM_SET_COUNTER_OFFSET, &test_args.offset);
390+
else
391+
TEST_FAIL("no support for global offset\n");
392+
}
393+
385394
for (i = 0; i < nr_vcpus; i++)
386395
vcpu_init_descriptor_tables(vcpus[i]);
387396

@@ -413,14 +422,15 @@ static void test_print_help(char *name)
413422
TIMER_TEST_PERIOD_MS_DEF);
414423
pr_info("\t-m: Frequency (in ms) of vCPUs to migrate to different pCPU. 0 to turn off (default: %u)\n",
415424
TIMER_TEST_MIGRATION_FREQ_MS);
425+
pr_info("\t-o: Counter offset (in counter cycles, default: 0)\n");
416426
pr_info("\t-h: print this help screen\n");
417427
}
418428

419429
static bool parse_args(int argc, char *argv[])
420430
{
421431
int opt;
422432

423-
while ((opt = getopt(argc, argv, "hn:i:p:m:")) != -1) {
433+
while ((opt = getopt(argc, argv, "hn:i:p:m:o:")) != -1) {
424434
switch (opt) {
425435
case 'n':
426436
test_args.nr_vcpus = atoi_positive("Number of vCPUs", optarg);
@@ -439,6 +449,10 @@ static bool parse_args(int argc, char *argv[])
439449
case 'm':
440450
test_args.migration_freq_ms = atoi_non_negative("Frequency", optarg);
441451
break;
452+
case 'o':
453+
test_args.offset.counter_offset = strtol(optarg, NULL, 0);
454+
test_args.offset.reserved = 0;
455+
break;
442456
case 'h':
443457
default:
444458
goto err;

0 commit comments

Comments
 (0)