Skip to content

Commit 95826e1

Browse files
committed
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: Sean Christopherson <seanjc@google.com>
1 parent df98ce7 commit 95826e1

2 files changed

Lines changed: 3 additions & 27 deletions

File tree

tools/testing/selftests/kvm/arch_timer.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,11 @@ static uint32_t test_get_pcpu(void)
9898
static int test_migrate_vcpu(unsigned int vcpu_idx)
9999
{
100100
int ret;
101-
cpu_set_t cpuset;
102101
uint32_t new_pcpu = test_get_pcpu();
103102

104-
CPU_ZERO(&cpuset);
105-
CPU_SET(new_pcpu, &cpuset);
106-
107103
pr_debug("Migrating vCPU: %u to pCPU: %u\n", vcpu_idx, new_pcpu);
108104

109-
ret = pthread_setaffinity_np(pt_vcpu_run[vcpu_idx],
110-
sizeof(cpuset), &cpuset);
105+
ret = __pin_task_to_cpu(pt_vcpu_run[vcpu_idx], new_pcpu);
111106

112107
/* Allow the error where the vCPU thread is already finished */
113108
TEST_ASSERT(ret == 0 || ret == ESRCH,

tools/testing/selftests/kvm/arm64/arch_timer_edge_cases.c

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -862,25 +862,6 @@ static uint32_t next_pcpu(void)
862862
return next;
863863
}
864864

865-
static void migrate_self(uint32_t new_pcpu)
866-
{
867-
int ret;
868-
cpu_set_t cpuset;
869-
pthread_t thread;
870-
871-
thread = pthread_self();
872-
873-
CPU_ZERO(&cpuset);
874-
CPU_SET(new_pcpu, &cpuset);
875-
876-
pr_debug("Migrating from %u to %u\n", sched_getcpu(), new_pcpu);
877-
878-
ret = pthread_setaffinity_np(thread, sizeof(cpuset), &cpuset);
879-
880-
TEST_ASSERT(ret == 0, "Failed to migrate to pCPU: %u; ret: %d\n",
881-
new_pcpu, ret);
882-
}
883-
884865
static void kvm_set_cntxct(struct kvm_vcpu *vcpu, uint64_t cnt,
885866
enum arch_timer timer)
886867
{
@@ -907,7 +888,7 @@ static void handle_sync(struct kvm_vcpu *vcpu, struct ucall *uc)
907888
sched_yield();
908889
break;
909890
case USERSPACE_MIGRATE_SELF:
910-
migrate_self(next_pcpu());
891+
pin_self_to_cpu(next_pcpu());
911892
break;
912893
default:
913894
break;
@@ -919,7 +900,7 @@ static void test_run(struct kvm_vm *vm, struct kvm_vcpu *vcpu)
919900
struct ucall uc;
920901

921902
/* Start on CPU 0 */
922-
migrate_self(0);
903+
pin_self_to_cpu(0);
923904

924905
while (true) {
925906
vcpu_run(vcpu);

0 commit comments

Comments
 (0)