Commit 95826e1e authored by Sean Christopherson's avatar Sean Christopherson
Browse files

KVM: selftests: Convert arch_timer tests to common helpers to pin task

Convert the arch timer tests to use __pin_task_to_cpu() and
pin_self_to_cpu().

No functional change intended.

Link: https://lore.kernel.org/r/20250626001225.744268-6-seanjc@google.com


Signed-off-by: default avatarSean Christopherson <seanjc@google.com>
parent df98ce78
Loading
Loading
Loading
Loading
+1 −6
Original line number Diff line number Diff line
@@ -98,16 +98,11 @@ static uint32_t test_get_pcpu(void)
static int test_migrate_vcpu(unsigned int vcpu_idx)
{
	int ret;
	cpu_set_t cpuset;
	uint32_t new_pcpu = test_get_pcpu();

	CPU_ZERO(&cpuset);
	CPU_SET(new_pcpu, &cpuset);

	pr_debug("Migrating vCPU: %u to pCPU: %u\n", vcpu_idx, new_pcpu);

	ret = pthread_setaffinity_np(pt_vcpu_run[vcpu_idx],
				     sizeof(cpuset), &cpuset);
	ret = __pin_task_to_cpu(pt_vcpu_run[vcpu_idx], new_pcpu);

	/* Allow the error where the vCPU thread is already finished */
	TEST_ASSERT(ret == 0 || ret == ESRCH,
+2 −21
Original line number Diff line number Diff line
@@ -862,25 +862,6 @@ static uint32_t next_pcpu(void)
	return next;
}

static void migrate_self(uint32_t new_pcpu)
{
	int ret;
	cpu_set_t cpuset;
	pthread_t thread;

	thread = pthread_self();

	CPU_ZERO(&cpuset);
	CPU_SET(new_pcpu, &cpuset);

	pr_debug("Migrating from %u to %u\n", sched_getcpu(), new_pcpu);

	ret = pthread_setaffinity_np(thread, sizeof(cpuset), &cpuset);

	TEST_ASSERT(ret == 0, "Failed to migrate to pCPU: %u; ret: %d\n",
		    new_pcpu, ret);
}

static void kvm_set_cntxct(struct kvm_vcpu *vcpu, uint64_t cnt,
			   enum arch_timer timer)
{
@@ -907,7 +888,7 @@ static void handle_sync(struct kvm_vcpu *vcpu, struct ucall *uc)
		sched_yield();
		break;
	case USERSPACE_MIGRATE_SELF:
		migrate_self(next_pcpu());
		pin_self_to_cpu(next_pcpu());
		break;
	default:
		break;
@@ -919,7 +900,7 @@ static void test_run(struct kvm_vm *vm, struct kvm_vcpu *vcpu)
	struct ucall uc;

	/* Start on CPU 0 */
	migrate_self(0);
	pin_self_to_cpu(0);

	while (true) {
		vcpu_run(vcpu);