mirror of
https://github.com/torvalds/linux.git
synced 2026-09-25 17:42:03 +02:00
KVM: selftests: Add kvm_sched_getaffinity() wrapper and convert users
Add and use a KVM wrapper for the sched_getaffinity() syscall so that selftests don't need to manually assert that the syscall succeeded. Note, some tests didn't actually assert success, but they all obviously rely on the syscall to succeed. Suggested-by: Sean Christopherson <seanjc@google.com> Signed-off-by: Josh Hilke <jrhilke@google.com> [sean: massage changelog] Link: https://patch.msgid.link/20260626213534.3866178-17-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
This commit is contained in:
parent
4512b27766
commit
76703ca0cb
|
|
@ -85,7 +85,7 @@ static u32 test_get_pcpu(void)
|
|||
cpu_set_t online_cpuset;
|
||||
|
||||
nproc_conf = get_nprocs_conf();
|
||||
sched_getaffinity(0, sizeof(cpu_set_t), &online_cpuset);
|
||||
kvm_sched_getaffinity(0, sizeof(cpu_set_t), &online_cpuset);
|
||||
|
||||
/* Randomly find an available pCPU to place a vCPU on */
|
||||
do {
|
||||
|
|
|
|||
|
|
@ -1039,7 +1039,7 @@ int main(int argc, char *argv[])
|
|||
if (!parse_args(argc, argv))
|
||||
exit(KSFT_SKIP);
|
||||
|
||||
sched_getaffinity(0, sizeof(default_cpuset), &default_cpuset);
|
||||
kvm_sched_getaffinity(0, sizeof(default_cpuset), &default_cpuset);
|
||||
set_counter_defaults();
|
||||
|
||||
if (test_args.test_virtual) {
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
#include <sys/mman.h>
|
||||
#include <sys/syscall.h>
|
||||
|
||||
#include <sched.h>
|
||||
#include <test_util.h>
|
||||
|
||||
#define MAP_ARGS0(m,...)
|
||||
|
|
@ -93,6 +94,7 @@ __KVM_SYSCALL_DEFINE(close, 1, int, fd);
|
|||
__KVM_SYSCALL_DEFINE(fallocate, 4, int, fd, int, mode, loff_t, offset, loff_t, len);
|
||||
__KVM_SYSCALL_DEFINE(ftruncate, 2, unsigned int, fd, off_t, length);
|
||||
__KVM_SYSCALL_DEFINE(madvise, 3, void *, addr, size_t, length, int, advice);
|
||||
__KVM_SYSCALL_DEFINE(sched_getaffinity, 3, pid_t, pid, size_t, cpusetsize, cpu_set_t *, mask);
|
||||
|
||||
#define kvm_free_fd(fd) \
|
||||
do { \
|
||||
|
|
|
|||
|
|
@ -674,13 +674,12 @@ void kvm_parse_vcpu_pinning(const char *pcpus_string, u32 vcpu_to_pcpu[],
|
|||
cpu_set_t allowed_mask;
|
||||
char *cpu, *cpu_list;
|
||||
char delim[2] = ",";
|
||||
int i, r;
|
||||
int i;
|
||||
|
||||
cpu_list = strdup(pcpus_string);
|
||||
TEST_ASSERT(cpu_list, "strdup() allocation failed.");
|
||||
|
||||
r = sched_getaffinity(0, sizeof(allowed_mask), &allowed_mask);
|
||||
TEST_ASSERT(!r, "sched_getaffinity() failed");
|
||||
kvm_sched_getaffinity(0, sizeof(allowed_mask), &allowed_mask);
|
||||
|
||||
cpu = strtok(cpu_list, delim);
|
||||
|
||||
|
|
|
|||
|
|
@ -255,11 +255,7 @@ static void rendezvous_with_vcpus(struct timespec *time, const char *name)
|
|||
static void calc_default_nr_vcpus(void)
|
||||
{
|
||||
cpu_set_t possible_mask;
|
||||
int r;
|
||||
|
||||
r = sched_getaffinity(0, sizeof(possible_mask), &possible_mask);
|
||||
TEST_ASSERT(!r, "sched_getaffinity failed, errno = %d (%s)",
|
||||
errno, strerror(errno));
|
||||
kvm_sched_getaffinity(0, sizeof(possible_mask), &possible_mask);
|
||||
|
||||
nr_vcpus = CPU_COUNT(&possible_mask);
|
||||
TEST_ASSERT(nr_vcpus > 0, "Uh, no CPUs?");
|
||||
|
|
|
|||
|
|
@ -226,9 +226,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
}
|
||||
|
||||
r = sched_getaffinity(0, sizeof(possible_mask), &possible_mask);
|
||||
TEST_ASSERT(!r, "sched_getaffinity failed, errno = %d (%s)", errno,
|
||||
strerror(errno));
|
||||
kvm_sched_getaffinity(0, sizeof(possible_mask), &possible_mask);
|
||||
|
||||
calc_min_max_cpu();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user