Skip to content

Commit d4ec586

Browse files
xzpetersean-jc
authored andcommitted
KVM: selftests: Allow specify physical cpu list in demand paging test
Mimic the dirty log test and allow the user to pin demand paging test tasks to physical CPUs. Put the help message into a general helper as suggested by Sean. Signed-off-by: Peter Xu <peterx@redhat.com> [sean: rebase, tweak arg ordering, add "print" to helper, print program name] Link: https://lore.kernel.org/r/20230607001226.1398889-1-seanjc@google.com Signed-off-by: Sean Christopherson <seanjc@google.com>
1 parent dfa78a2 commit d4ec586

4 files changed

Lines changed: 32 additions & 13 deletions

File tree

tools/testing/selftests/kvm/demand_paging_test.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,11 @@ static void help(char *name)
208208
{
209209
puts("");
210210
printf("usage: %s [-h] [-m vm_mode] [-u uffd_mode] [-d uffd_delay_usec]\n"
211-
" [-b memory] [-s type] [-v vcpus] [-o]\n", name);
211+
" [-b memory] [-s type] [-v vcpus] [-c cpu_list] [-o]\n", name);
212212
guest_modes_help();
213213
printf(" -u: use userfaultfd to handle vCPU page faults. Mode is a\n"
214214
" UFFD registration mode: 'MISSING' or 'MINOR'.\n");
215+
kvm_print_vcpu_pinning_help();
215216
printf(" -d: add a delay in usec to the User Fault\n"
216217
" FD handler to simulate demand paging\n"
217218
" overheads. Ignored without -u.\n");
@@ -229,6 +230,7 @@ static void help(char *name)
229230
int main(int argc, char *argv[])
230231
{
231232
int max_vcpus = kvm_check_cap(KVM_CAP_MAX_VCPUS);
233+
const char *cpulist = NULL;
232234
struct test_params p = {
233235
.src_type = DEFAULT_VM_MEM_SRC,
234236
.partition_vcpu_memory_access = true,
@@ -237,7 +239,7 @@ int main(int argc, char *argv[])
237239

238240
guest_modes_append_default();
239241

240-
while ((opt = getopt(argc, argv, "hm:u:d:b:s:v:o")) != -1) {
242+
while ((opt = getopt(argc, argv, "hm:u:d:b:s:v:c:o")) != -1) {
241243
switch (opt) {
242244
case 'm':
243245
guest_modes_cmdline(optarg);
@@ -264,6 +266,9 @@ int main(int argc, char *argv[])
264266
TEST_ASSERT(nr_vcpus <= max_vcpus,
265267
"Invalid number of vcpus, must be between 1 and %d", max_vcpus);
266268
break;
269+
case 'c':
270+
cpulist = optarg;
271+
break;
267272
case 'o':
268273
p.partition_vcpu_memory_access = false;
269274
break;
@@ -279,6 +284,12 @@ int main(int argc, char *argv[])
279284
TEST_FAIL("userfaultfd MINOR mode requires shared memory; pick a different -s");
280285
}
281286

287+
if (cpulist) {
288+
kvm_parse_vcpu_pinning(cpulist, memstress_args.vcpu_to_pcpu,
289+
nr_vcpus);
290+
memstress_args.pin_vcpus = true;
291+
}
292+
282293
for_each_guest_mode(run_test, &p);
283294

284295
return 0;

tools/testing/selftests/kvm/dirty_log_perf_test.c

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -332,17 +332,7 @@ static void help(char *name)
332332
" so -w X means each page has an X%% chance of writing\n"
333333
" and a (100-X)%% chance of reading.\n"
334334
" (default: 100 i.e. all pages are written to.)\n");
335-
printf(" -c: Pin tasks to physical CPUs. Takes a list of comma separated\n"
336-
" values (target pCPU), one for each vCPU, plus an optional\n"
337-
" entry for the main application task (specified via entry\n"
338-
" <nr_vcpus + 1>). If used, entries must be provided for all\n"
339-
" vCPUs, i.e. pinning vCPUs is all or nothing.\n\n"
340-
" E.g. to create 3 vCPUs, pin vCPU0=>pCPU22, vCPU1=>pCPU23,\n"
341-
" vCPU2=>pCPU24, and pin the application task to pCPU50:\n\n"
342-
" ./dirty_log_perf_test -v 3 -c 22,23,24,50\n\n"
343-
" To leave the application task unpinned, drop the final entry:\n\n"
344-
" ./dirty_log_perf_test -v 3 -c 22,23,24\n\n"
345-
" (default: no pinning)\n");
335+
kvm_print_vcpu_pinning_help();
346336
puts("");
347337
exit(0);
348338
}

tools/testing/selftests/kvm/include/kvm_util_base.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,7 @@ static inline struct kvm_vm *vm_create_with_one_vcpu(struct kvm_vcpu **vcpu,
733733
struct kvm_vcpu *vm_recreate_with_one_vcpu(struct kvm_vm *vm);
734734

735735
void kvm_pin_this_task_to_pcpu(uint32_t pcpu);
736+
void kvm_print_vcpu_pinning_help(void);
736737
void kvm_parse_vcpu_pinning(const char *pcpus_string, uint32_t vcpu_to_pcpu[],
737738
int nr_vcpus);
738739

tools/testing/selftests/kvm/lib/kvm_util.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,23 @@ static uint32_t parse_pcpu(const char *cpu_str, const cpu_set_t *allowed_mask)
494494
return pcpu;
495495
}
496496

497+
void kvm_print_vcpu_pinning_help(void)
498+
{
499+
const char *name = program_invocation_name;
500+
501+
printf(" -c: Pin tasks to physical CPUs. Takes a list of comma separated\n"
502+
" values (target pCPU), one for each vCPU, plus an optional\n"
503+
" entry for the main application task (specified via entry\n"
504+
" <nr_vcpus + 1>). If used, entries must be provided for all\n"
505+
" vCPUs, i.e. pinning vCPUs is all or nothing.\n\n"
506+
" E.g. to create 3 vCPUs, pin vCPU0=>pCPU22, vCPU1=>pCPU23,\n"
507+
" vCPU2=>pCPU24, and pin the application task to pCPU50:\n\n"
508+
" %s -v 3 -c 22,23,24,50\n\n"
509+
" To leave the application task unpinned, drop the final entry:\n\n"
510+
" %s -v 3 -c 22,23,24\n\n"
511+
" (default: no pinning)\n", name, name);
512+
}
513+
497514
void kvm_parse_vcpu_pinning(const char *pcpus_string, uint32_t vcpu_to_pcpu[],
498515
int nr_vcpus)
499516
{

0 commit comments

Comments
 (0)