mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-09-13 05:34:06 -04:00
KVM: selftests: Extract picking of random CPU from cpu_set_t to separate API
Extract kvm_pick_random_cpu() out of pin_task_to_random_cpu() so that tests can choose a random CPU without having to immediately pin a task to that CPU. No functional change intended. Link: https://patch.msgid.link/20260731195612.2697986-6-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
This commit is contained in:
@@ -1084,6 +1084,8 @@ struct kvm_vcpu *vm_recreate_with_one_vcpu(struct kvm_vm *vm);
|
||||
|
||||
void kvm_set_files_rlimit(u32 nr_vcpus);
|
||||
|
||||
int kvm_pick_random_cpu(cpu_set_t *possible_cpus);
|
||||
|
||||
int __pin_task_to_cpu(pthread_t task, int cpu);
|
||||
|
||||
static inline void pin_task_to_cpu(pthread_t task, int cpu)
|
||||
@@ -1094,7 +1096,14 @@ static inline void pin_task_to_cpu(pthread_t task, int cpu)
|
||||
TEST_ASSERT(!r, "Failed to set thread affinity to pCPU '%u'", cpu);
|
||||
}
|
||||
|
||||
int pin_task_to_random_cpu(pthread_t task, cpu_set_t *possible_cpus);
|
||||
static inline int pin_task_to_random_cpu(pthread_t task, cpu_set_t *possible_cpus)
|
||||
{
|
||||
int cpu;
|
||||
|
||||
cpu = kvm_pick_random_cpu(possible_cpus);
|
||||
pin_task_to_cpu(task, cpu);
|
||||
return cpu;
|
||||
}
|
||||
|
||||
static inline int pin_task_to_any_cpu(pthread_t task)
|
||||
{
|
||||
|
||||
@@ -668,7 +668,7 @@ void kvm_print_vcpu_pinning_help(void)
|
||||
" (default: no pinning)\n", name, name);
|
||||
}
|
||||
|
||||
int pin_task_to_random_cpu(pthread_t task, cpu_set_t *possible_cpus)
|
||||
int kvm_pick_random_cpu(cpu_set_t *possible_cpus)
|
||||
{
|
||||
int target_idx;
|
||||
int nr_cpus;
|
||||
@@ -680,12 +680,9 @@ int pin_task_to_random_cpu(pthread_t task, cpu_set_t *possible_cpus)
|
||||
target_idx = kvm_random_u64(&kvm_rng) % nr_cpus;
|
||||
|
||||
for (cpu = 0; cpu < CPU_SETSIZE; cpu++) {
|
||||
if (CPU_ISSET(cpu, possible_cpus) && target_idx-- == 0) {
|
||||
pin_task_to_cpu(task, cpu);
|
||||
if (CPU_ISSET(cpu, possible_cpus) && target_idx-- == 0)
|
||||
return cpu;
|
||||
}
|
||||
}
|
||||
|
||||
TEST_FAIL("Failed to find random CPU in possible_cpus");
|
||||
return -1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user