Commit 2fe9e0fc authored by Marc Zyngier's avatar Marc Zyngier
Browse files

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: default avatarColton Lewis <coltonlewis@google.com>
Signed-off-by: default avatarMarc Zyngier <maz@kernel.org>
Link: https://lore.kernel.org/r/20230330174800.2677007-21-maz@kernel.org
parent 056c1566
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ struct test_args {
	int nr_iter;
	int timer_period_ms;
	int migration_freq_ms;
	struct kvm_arm_counter_offset offset;
};

static struct test_args test_args = {
@@ -54,6 +55,7 @@ static struct test_args test_args = {
	.nr_iter = NR_TEST_ITERS_DEF,
	.timer_period_ms = TIMER_TEST_PERIOD_MS_DEF,
	.migration_freq_ms = TIMER_TEST_MIGRATION_FREQ_MS,
	.offset = { .reserved = 1 },
};

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

	if (!test_args.offset.reserved) {
		if (kvm_has_cap(KVM_CAP_COUNTER_OFFSET))
			vm_ioctl(vm, KVM_ARM_SET_COUNTER_OFFSET, &test_args.offset);
		else
			TEST_FAIL("no support for global offset\n");
	}

	for (i = 0; i < nr_vcpus; i++)
		vcpu_init_descriptor_tables(vcpus[i]);

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

@@ -420,7 +430,7 @@ static bool parse_args(int argc, char *argv[])
{
	int opt;

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