KVM: selftests: Return the target CPU from pin_task_to_random_cpu()

When pinning a task to a random CPU, return which CPU the task was pinned
to so that the caller can do things like avoid running other tasks on the
target CPU.

Link: https://patch.msgid.link/20260731195612.2697986-5-seanjc@google.com
Signed-off-by: Sean Christopherson <seanjc@google.com>
This commit is contained in:
Sean Christopherson
2026-07-31 12:56:04 -07:00
parent 496779b549
commit 8de0e85f65
2 changed files with 4 additions and 3 deletions

View File

@@ -1094,7 +1094,7 @@ static inline void pin_task_to_cpu(pthread_t task, int cpu)
TEST_ASSERT(!r, "Failed to set thread affinity to pCPU '%u'", cpu);
}
void pin_task_to_random_cpu(pthread_t task, cpu_set_t *possible_cpus);
int pin_task_to_random_cpu(pthread_t task, cpu_set_t *possible_cpus);
static inline int pin_task_to_any_cpu(pthread_t task)
{

View File

@@ -668,7 +668,7 @@ void kvm_print_vcpu_pinning_help(void)
" (default: no pinning)\n", name, name);
}
void pin_task_to_random_cpu(pthread_t task, cpu_set_t *possible_cpus)
int pin_task_to_random_cpu(pthread_t task, cpu_set_t *possible_cpus)
{
int target_idx;
int nr_cpus;
@@ -682,11 +682,12 @@ void pin_task_to_random_cpu(pthread_t task, cpu_set_t *possible_cpus)
for (cpu = 0; cpu < CPU_SETSIZE; cpu++) {
if (CPU_ISSET(cpu, possible_cpus) && target_idx-- == 0) {
pin_task_to_cpu(task, cpu);
return;
return cpu;
}
}
TEST_FAIL("Failed to find random CPU in possible_cpus");
return -1;
}
void kvm_parse_vcpu_pinning(const char *pcpus_string, u32 vcpu_to_pcpu[],