KVM: selftests: Run dirty_log_perf_test on specific cpus
PATCH 1/1 KVM: selftests: Run dirty_log_perf_test on specific cpus
Add command line options to run the vcpus and the main process on the specific cpus on a host machine. This is useful as it provides options to analyze performance based on the vcpus and dirty log worker locations, like on the different numa nodes or on the same numa nodes.
---
This is based on the discussion at
https://lore.kernel.org/lkml/[email protected]/
.../selftests/kvm/access_tracking_perf_test.c | 2 +- .../selftests/kvm/demand_paging_test.c | 2 +- .../selftests/kvm/dirty_log_perf_test.c | 108 +++++++++++++++++- .../selftests/kvm/include/perf_test_util.h | 3 +- .../selftests/kvm/lib/perf_test_util.c | 32 +++++- .../kvm/memslot_modification_stress_test.c | 2 +- 6 files changed, 139 insertions(+), 10 deletions(-)
tools/testing/selftests/kvm/access_tracking_perf_test.c +1 -1
@@ -299,7 +299,7 @@ static void run_test(enum vm_guest_mode mode, void *arg) vm =perf_test_create_vm (mode, nr_vcpus, params->vcpu_memory_bytes,1 , params->backing_src, !overlap_memory_access); -perf_test_start_vcpu_threads (nr_vcpus, vcpu_thread_main); +perf_test_start_vcpu_threads (nr_vcpus,NULL , vcpu_thread_main);pr_info ("\n" );access_memory (vm, nr_vcpus,ACCESS_WRITE ,"Populating memory" );
tools/testing/selftests/kvm/demand_paging_test.c +1 -1
@@ -336,7 +336,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)pr_info ("Finished creating vCPUs and starting uffd threads\n" );clock_gettime (CLOCK_MONOTONIC , &start); -perf_test_start_vcpu_threads (nr_vcpus, vcpu_worker); +perf_test_start_vcpu_threads (nr_vcpus,NULL , vcpu_worker);pr_info ("Started all vCPUs\n" );perf_test_join_vcpu_threads (nr_vcpus);
tools/testing/selftests/kvm/dirty_log_perf_test.c +105 -3
174 lines not on this page · raw message
tools/testing/selftests/kvm/include/perf_test_util.h +2 -1
@@ -53,7 +53,8 @@ void perf_test_destroy_vm(struct kvm_vm *vm);void perf_test_set_wr_fract (struct kvm_vm *vm,int wr_fract); -void perf_test_start_vcpu_threads (int vcpus,void (*vcpu_fn)(struct perf_test_vcpu_args *)); +void perf_test_start_vcpu_threads (int vcpus,int *vcpus_to_lcpu, +void (*vcpu_fn)(struct perf_test_vcpu_args *));void perf_test_join_vcpu_threads (int vcpus);void perf_test_guest_code (uint32_t vcpu_id);
tools/testing/selftests/kvm/lib/perf_test_util.c +29 -3
@@ -2,11 +2,14 @@/* * Copyright (C) 2020, Google LLC. */ +#define _GNU_SOURCE#include <inttypes.h> #include "kvm_util.h" #include "perf_test_util.h" #include "processor.h" +#include <pthread.h> +#include <sched.h> struct perf_test_args perf_test_args;
@@ -260,10 +263,15 @@ static void *vcpu_thread_main(void *data)return NULL ; } -void perf_test_start_vcpu_threads (int nr_vcpus, +void perf_test_start_vcpu_threads (int nr_vcpus,int *vcpu_to_lcpu,void (*vcpu_fn)(struct perf_test_vcpu_args *)) { -int i; +int i, err =0 ; +pthread_attr_t attr; +cpu_set_t cpuset; + +pthread_attr_init (&attr); +CPU_ZERO (&cpuset); vcpu_thread_fn = vcpu_fn;WRITE_ONCE (all_vcpu_threads_running, false);
@@ -274,7 +282,24 @@ void perf_test_start_vcpu_threads(int nr_vcpus, vcpu->vcpu_idx = i;WRITE_ONCE (vcpu->running, false); -pthread_create (&vcpu->thread,NULL , vcpu_thread_main, vcpu); +if (vcpu_to_lcpu) { +CPU_SET (vcpu_to_lcpu[i], &cpuset); + + err =pthread_attr_setaffinity_np (&attr, +sizeof (cpu_set_t), + &cpuset); +TEST_ASSERT (err ==0 , +"vCPU %d could not be mapped to logical cpu %d, error returned: %d\n" , + i, vcpu_to_lcpu[i], err); + +CPU_CLR (vcpu_to_lcpu[i], &cpuset); + } + + err =pthread_create (&vcpu->thread, &attr, vcpu_thread_main, + vcpu); +TEST_ASSERT (err ==0 , +"error in creating vcpu %d thread, error returned: %d\n" , + i, err); }for (i =0 ; i < nr_vcpus; i++) {
@@ -283,6 +308,7 @@ void perf_test_start_vcpu_threads(int nr_vcpus, }WRITE_ONCE (all_vcpu_threads_running, true); +pthread_attr_destroy (&attr); }void perf_test_join_vcpu_threads (int nr_vcpus)
tools/testing/selftests/kvm/memslot_modification_stress_test.c +1 -1
@@ -103,7 +103,7 @@ static void run_test(enum vm_guest_mode mode, void *arg)pr_info ("Finished creating vCPUs\n" ); -perf_test_start_vcpu_threads (nr_vcpus, vcpu_worker); +perf_test_start_vcpu_threads (nr_vcpus,NULL , vcpu_worker);pr_info ("Started all vCPUs\n" );
Signature · 1 line
2.37.1.595.g718a3a8f04-goog
Sean Christopherson
reviewerQuoted 4 lines · Vipin Sharma
Add command line options to run the vcpus and the main process on the specific cpus on a host machine. This is useful as it provides options to analyze performance based on the vcpus and dirty log worker locations, like on the different numa nodes or on the same numa nodes.
The two options should probably be separate patches, they are related but still two very distinct changes.
Quoted 8 lines
Signed-off-by Vipin Sharma <[email protected]>Suggested-by David Matlack <[email protected]>Suggested-by Sean Christopherson <[email protected]>Suggested-by Paolo Bonzini <[email protected]>---
This is based on the discussion at
https://lore.kernel.org/lkml/[email protected]/
This can and should be captured in the changelog proper:
Quoted 4 lines
tools/testing/selftests/kvm/dirty_log_perf_test.c +0
-0@@ -348,12 +353,74 @@ static void run_test(enum vm_guest_mode mode, void *arg)perf_test_destroy_vm (vm); }
tools/testing/selftests/kvm/dirty_log_perf_test.c static void run_test(enum vm_guest_mode mode, void *arg) · line 365
Quoted 10 lines
tools/testing/selftests/kvm/dirty_log_perf_test.c +10
-0+static int parse_num (const char *num_str) +{ +int num; +char *end_ptr; + + errno =0 ; + num = (int )strtol (num_str, &end_ptr,10 ); +TEST_ASSERT (num_str != end_ptr && *end_ptr =='\0' , +"Invalid number string.\n" ); +TEST_ASSERT (errno ==0 ,"Conversion error: %d\n" , errno);
Is the paranoia truly necessary? What happens if parse_cpu_list() simply uses atoi() and is passed garbage?
tools/testing/selftests/kvm/dirty_log_perf_test.c static void run_test(enum vm_guest_mode mode, void *arg) · line 377
Quoted 12 lines
tools/testing/selftests/kvm/dirty_log_perf_test.c +12
-0+ +return num; +} + +static int parse_cpu_list (const char *arg) +{ +char delim[2 ] ="," ; +char *cpu, *cpu_list; +int i =0 , cpu_num; + + cpu_list =strdup (arg); +TEST_ASSERT (cpu_list,"Low memory\n" );
Heh, probably a little less than "low". Just be literal and let the user figure out why the allocation failed instead.
TEST_ASSERT(cpu_list, "strdup() allocation failed\n");
tools/testing/selftests/kvm/dirty_log_perf_test.c static void run_test(enum vm_guest_mode mode, void *arg) · line 387
Quoted 10 lines
tools/testing/selftests/kvm/dirty_log_perf_test.c +10
-0+ + cpu =strtok (cpu_list, delim); +while (cpu) { + cpu_num =parse_num (cpu); +TEST_ASSERT (cpu_num >=0 ,"Invalid cpu number: %d\n" , cpu_num); + vcpu_to_lcpu_map[i++] = cpu_num; + cpu =strtok (NULL , delim); + } + +free (cpu_list);
The tokenization and parsing is nearly identical between parse_cpu_list() and assign_dirty_log_perf_test_cpu(). The code can be made into a common helper by passing in the destination, e.g.
static int parse_cpu_list(const char *arg, cpu_set_t *cpuset, int *vcpu_map)
{
const char delim[] = ",";
char *cpustr, *cpu_list;
int i = 0, cpu;
TEST_ASSERT(!!cpuset ^ !!vcpu_map);
cpu_list = strdup(arg);
TEST_ASSERT(cpu_list, "Low memory\n");
cpustr = strtok(cpu_list, delim);
while (cpustr) {
cpu = atoi(cpustr);
TEST_ASSERT(cpu >= 0, "Invalid cpu number: %d\n", cpu);
if (vcpu_map)
vcpu_to_lcpu_map[i++] = cpu_num;
else
CPU_SET(cpu_num, cpuset);
cpu = strtok(NULL, delim);
}
free(cpu_list);
return i;
}Quoted 29 lines
tools/testing/selftests/kvm/dirty_log_perf_test.c +20
-0@@ -383,6 +450,26 @@ static void help(char *name)backing_src_help ("-s" );printf (" -x: Split the memory region into this number of memslots.\n" " (default: 1)\n" ); +printf (" -c: Comma separated values of the logical CPUs which will run\n" +" the vCPUs. Number of values should be equal to the number\n" +" of vCPUs.\n\n" +" Example: ./dirty_log_perf_test -v 3 -c 22,43,1\n" +" This means that the vcpu 0 will run on the logical cpu 22,\n" +" vcpu 1 on the logical cpu 43 and vcpu 2 on the logical cpu 1.\n" +" (default: No cpu mapping)\n\n" ); +printf (" -d: Comma separated values of the logical CPUs on which\n" +" dirty_log_perf_test will run. Without -c option, all of\n" +" the vcpus and main process will run on the cpus provided here.\n" +" This option also accepts a single cpu. (default: No cpu mapping)\n\n" +" Example 1: ./dirty_log_perf_test -v 3 -c 22,43,1 -d 101\n" +" Main application thread will run on logical cpu 101 and\n" +" vcpus will run on the logical cpus 22, 43 and 1\n\n" +" Example 2: ./dirty_log_perf_test -v 3 -d 101\n" +" Main application thread and vcpus will run on the logical\n" +" cpu 101\n\n" +" Example 3: ./dirty_log_perf_test -v 3 -d 101,23,53\n" +" Main application thread and vcpus will run on logical cpus\n" +" 101, 23 and 53.\n" );puts ("" );exit (0 ); }
tools/testing/selftests/kvm/dirty_log_perf_test.c int main(int argc, char *argv[]) · line 552
Quoted 3 lines
tools/testing/selftests/kvm/dirty_log_perf_test.c +0
-0@@ -455,6 +550,13 @@ int main(int argc, char *argv[]) } }
I wonder if we should make -c and -d mutually exclusive. Tweak -c to include the application thread, i.e. TEST_ASSERT(nr_lcpus == nr_vcpus+1) and require 1:1 pinning for all tasks. E.g. allowing "-c ..., -d 0,1,22" seems unnecessary.
Quoted 10 lines
tools/testing/selftests/kvm/dirty_log_perf_test.c +7
-0+if (nr_lcpus !=-1 ) { +TEST_ASSERT (nr_lcpus == nr_vcpus, +"Number of vCPUs (%d) are not equal to number of logical cpus provided (%d)." , + nr_vcpus, nr_lcpus); + p.vcpu_to_lcpu = vcpu_to_lcpu_map; + } +TEST_ASSERT (p.iterations >=2 ,"The test should have at least two iterations" );pr_info ("Test iterations: %" PRIu64"\n" , p.iterations);
Quoted 14 lines · Sean Christopherson
tools/testing/selftests/kvm/dirty_log_perf_test.c static void run_test(enum vm_guest_mode mode, void *arg) · line 365
Quoted 11 lines
tools/testing/selftests/kvm/dirty_log_perf_test.c +10
-0+static int parse_num (const char *num_str) +{ +int num; +char *end_ptr; + + errno =0 ; + num = (int )strtol (num_str, &end_ptr,10 ); +TEST_ASSERT (num_str != end_ptr && *end_ptr =='\0' , +"Invalid number string.\n" ); +TEST_ASSERT (errno ==0 ,"Conversion error: %d\n" , errno);Is the paranoia truly necessary? What happens if
parse_cpu_list()simply usesatoi()and is passed garbage?
On error atoi() returns 0, which is also a valid logical cpu number. We need error checking here to make sure that the user really wants cpu 0 and it was not a mistake in typing.
I was thinking of using parse_num API for other places as well instead of atoi() in dirty_log_perf_test.
Quoted 33 lines
tools/testing/selftests/kvm/dirty_log_perf_test.c static void run_test(enum vm_guest_mode mode, void *arg) · line 387
Quoted 10 lines
tools/testing/selftests/kvm/dirty_log_perf_test.c +10
-0+ + cpu =strtok (cpu_list, delim); +while (cpu) { + cpu_num =parse_num (cpu); +TEST_ASSERT (cpu_num >=0 ,"Invalid cpu number: %d\n" , cpu_num); + vcpu_to_lcpu_map[i++] = cpu_num; + cpu =strtok (NULL , delim); + } + +free (cpu_list);The tokenization and parsing is nearly identical between
parse_cpu_list()andassign_dirty_log_perf_test_cpu(). The code can be made into a common helper by passing in the destination, e.g.static int
parse_cpu_list(const char *arg, cpu_set_t *cpuset, int *vcpu_map){ const char delim[] = ","; char *cpustr, *cpu_list; int i = 0, cpu; TEST_ASSERT(!!cpuset ^ !!vcpu_map); cpu_list = strdup(arg); TEST_ASSERT(cpu_list, "Low memory\n"); cpustr = strtok(cpu_list, delim); while (cpustr) { cpu = atoi(cpustr); TEST_ASSERT(cpu >= 0, "Invalid cpu number: %d\n", cpu); if (vcpu_map) vcpu_to_lcpu_map[i++] = cpu_num; else
Quoted 9 lines
CPU_SET(cpu_num, cpuset);
cpu = strtok(NULL, delim);
}
free(cpu_list);
return i;
}Yeah, it was either my almost duplicate functions or have the one function do two things via if-else. I am not happy with both approaches.
I think I will pass an integer array which this parsing function will fill up and return an int denoting how many elements were filled. The caller then can use the array as they wish, to copy it in vcpu_to_lcpu_map or cpuset.
Quoted 28 lines
Quoted 27 lines
tools/testing/selftests/kvm/dirty_log_perf_test.c +20
-0@@ -383,6 +450,26 @@ static void help(char *name)backing_src_help ("-s" );printf (" -x: Split the memory region into this number of memslots.\n" " (default: 1)\n" ); +printf (" -c: Comma separated values of the logical CPUs which will run\n" +" the vCPUs. Number of values should be equal to the number\n" +" of vCPUs.\n\n" +" Example: ./dirty_log_perf_test -v 3 -c 22,43,1\n" +" This means that the vcpu 0 will run on the logical cpu 22,\n" +" vcpu 1 on the logical cpu 43 and vcpu 2 on the logical cpu 1.\n" +" (default: No cpu mapping)\n\n" ); +printf (" -d: Comma separated values of the logical CPUs on which\n" +" dirty_log_perf_test will run. Without -c option, all of\n" +" the vcpus and main process will run on the cpus provided here.\n" +" This option also accepts a single cpu. (default: No cpu mapping)\n\n" +" Example 1: ./dirty_log_perf_test -v 3 -c 22,43,1 -d 101\n" +" Main application thread will run on logical cpu 101 and\n" +" vcpus will run on the logical cpus 22, 43 and 1\n\n" +" Example 2: ./dirty_log_perf_test -v 3 -d 101\n" +" Main application thread and vcpus will run on the logical\n" +" cpu 101\n\n" +" Example 3: ./dirty_log_perf_test -v 3 -d 101,23,53\n" +" Main application thread and vcpus will run on logical cpus\n" +" 101, 23 and 53.\n" );puts ("" );exit (0 ); }
Quoted 9 lines
Review int main(int argc, char *argv[]) · line 552
Quoted 4 lines
(quoted diff) +0
-0@@ -455,6 +550,13 @@ int main(int argc, char *argv[]) } }I wonder if we should make -c and -d mutually exclusive. Tweak -c to include the application thread, i.e.
TEST_ASSERT(nr_lcpus == nr_vcpus+1)and require 1:1 pinning for all tasks. E.g. allowing "-c ..., -d 0,1,22" seems unnecessary.
One downside I can think of will be if we add some worker threads which are not vcpus then all of those threads will end up running on a single cpu unless we edit this parsing logic again.
Current implementation gives vcpus special treatment via -c and for the whole application via -d. This gives good separation of concerns via flags.
Sean Christopherson
reviewerQuoted 16 lines · Vipin Sharma
Quoted 14 lines · Sean Christopherson
tools/testing/selftests/kvm/dirty_log_perf_test.c static void run_test(enum vm_guest_mode mode, void *arg) · line 365
Quoted 11 lines
tools/testing/selftests/kvm/dirty_log_perf_test.c +10
-0+static int parse_num (const char *num_str) +{ +int num; +char *end_ptr; + + errno =0 ; + num = (int )strtol (num_str, &end_ptr,10 ); +TEST_ASSERT (num_str != end_ptr && *end_ptr =='\0' , +"Invalid number string.\n" ); +TEST_ASSERT (errno ==0 ,"Conversion error: %d\n" , errno);Is the paranoia truly necessary? What happens if
parse_cpu_list()simply usesatoi()and is passed garbage?
Quoted 1 line
On error
atoi()returns 0, which is also a valid logical cpu number.
Lame.
Quoted 4 lines
We need error checking here to make sure that the user really wants cpu 0 and it was not a mistake in typing.
I was thinking of usingparse_numAPI for other places as well instead ofatoi()indirty_log_perf_test.
Yes, definitely. And maybe give it a name like atoi_paranoid()?
Quoted 8 lines
Yeah, it was either my almost duplicate functions or have the one function do two things via if-else. I am not happy with both approaches.
I think I will pass an integer array which this parsing function will fill up and return an int denoting how many elements were filled. The caller then can use the array as they wish, to copy it in
vcpu_to_lcpu_mapor cpuset.
Eh, I doubt that'll be a net improvement, e.g. the CPUSET case will then need to re-loop, which seems silly. If the exclusive cpuset vs. array is undesirable, we could have the API require at least one instead of exactly one, i.e.
TEST_ASSERT(cpuset || vcpu_map);
...
cpu = atoi(cpustr);
TEST_ASSERT(cpu >= 0, "Invalid cpu number: %d\n", cpu);
if (vcpu_map)
vcpu_map[i++] = cpu;
if (cpuset)
CPU_SET(cpu, cpuset);If we somehow end up with a third type of destination, then we can revisit this, but that seems unlikely at this point.
Quoted 38 lines
Quoted 28 lines
Quoted 27 lines
tools/testing/selftests/kvm/dirty_log_perf_test.c +20
-0@@ -383,6 +450,26 @@ static void help(char *name)backing_src_help ("-s" );printf (" -x: Split the memory region into this number of memslots.\n" " (default: 1)\n" ); +printf (" -c: Comma separated values of the logical CPUs which will run\n" +" the vCPUs. Number of values should be equal to the number\n" +" of vCPUs.\n\n" +" Example: ./dirty_log_perf_test -v 3 -c 22,43,1\n" +" This means that the vcpu 0 will run on the logical cpu 22,\n" +" vcpu 1 on the logical cpu 43 and vcpu 2 on the logical cpu 1.\n" +" (default: No cpu mapping)\n\n" ); +printf (" -d: Comma separated values of the logical CPUs on which\n" +" dirty_log_perf_test will run. Without -c option, all of\n" +" the vcpus and main process will run on the cpus provided here.\n" +" This option also accepts a single cpu. (default: No cpu mapping)\n\n" +" Example 1: ./dirty_log_perf_test -v 3 -c 22,43,1 -d 101\n" +" Main application thread will run on logical cpu 101 and\n" +" vcpus will run on the logical cpus 22, 43 and 1\n\n" +" Example 2: ./dirty_log_perf_test -v 3 -d 101\n" +" Main application thread and vcpus will run on the logical\n" +" cpu 101\n\n" +" Example 3: ./dirty_log_perf_test -v 3 -d 101,23,53\n" +" Main application thread and vcpus will run on logical cpus\n" +" 101, 23 and 53.\n" );puts ("" );exit (0 ); }Quoted 9 lines
Review int main(int argc, char *argv[]) · line 552
Quoted 4 lines
(quoted diff) +0
-0@@ -455,6 +550,13 @@ int main(int argc, char *argv[]) } }I wonder if we should make -c and -d mutually exclusive. Tweak -c to include the application thread, i.e.
TEST_ASSERT(nr_lcpus == nr_vcpus+1)and require 1:1 pinning for all tasks. E.g. allowing "-c ..., -d 0,1,22" seems unnecessary.
Quoted 3 lines
One downside I can think of will be if we add some worker threads which are not vcpus then all of those threads will end up running on a single cpu unless we edit this parsing logic again.
But adding worker threads also requires a code change, i.e. it won't require a separate commit/churn. And if we get to the point where we want multiple workers, it should be relatively straightforward to support pinning an arbitrary number of workers, e.g.
enum memtest_worker_type {
MAIN_WORKER,
MINION_1,
MINION_2,
NR_MEMTEST_WORKERS,
}
TEST_ASSERT(nr_lcpus == nr_vcpus + NR_MEMTEST_WORKERS);void spawn_worker(enum memtest_worker_type type, <function pointer>)
{
cpu_set_t cpuset;
CPU_ZERO(&cpuset);
CPU_SET(task_map[nr_vcpus + type], &cpuset);
<set affinity and spawn>
}Quoted 3 lines
Current implementation gives vcpus special treatment via -c and for the whole application via -d. This gives good separation of concerns via flags.
But they aren't separated, e.g. using -d without -c means vCPUs are thrown into the same pool as worker threads. And if we ever do add more workers, -d doesn't allow the user to pin workers 1:1 with logical CPUs.
Actually, if -c is extended to pin workers, then adding -d is unnecessary. If the user wants to affine tasks to CPUs but not pin 1:1, it can do that with e.g. taskset. What the user can't do is pin 1:1.
If we don't want to _require_ the caller to pin the main worker, then we could do
TEST_ASSERT(nr_lcpus >= nr_vcpus && nr_lcpus <= nr_vcpus + NR_MEMTEST_WORKERS);
to _require_ pinning all vCPUs, and allow but not require pinning non-vCPU tasks.
Quoted 10 lines · Sean Christopherson
Quoted 6 lines · Vipin Sharma
On Wed, Aug 17, 2022 at 10:25 AM Sean Christopherson <[email protected]> wrote:
We need error checking here to make sure that the user really wants cpu 0 and it was not a mistake in typing.
I was thinking of usingparse_numAPI for other places as well instead ofatoi()indirty_log_perf_test.Yes, definitely. And maybe give it a name like
atoi_paranoid()?
Lol. Absolutely, if that's what you want!
Quoted 25 lines
Quoted 9 lines
Yeah, it was either my almost duplicate functions or have the one function do two things via if-else. I am not happy with both approaches.
I think I will pass an integer array which this parsing function will fill up and return an int denoting how many elements were filled. The caller then can use the array as they wish, to copy it in
vcpu_to_lcpu_mapor cpuset.Eh, I doubt that'll be a net improvement, e.g. the CPUSET case will then need to re-loop, which seems silly. If the exclusive cpuset vs. array is undesirable, we could have the API require at least one instead of exactly one, i.e.
TEST_ASSERT(cpuset || vcpu_map); ... cpu = atoi(cpustr); TEST_ASSERT(cpu >= 0, "Invalid cpu number: %d\n", cpu); if (vcpu_map) vcpu_map[i++] = cpu; if (cpuset) CPU_SET(cpu, cpuset);
Quoted 3 lines
If we somehow end up with a third type of destination, then we can revisit this, but that seems unlikely at this point.
I am removing the -d option, so this is not needed anymore.
Quoted 46 lines
Quoted 8 lines
Quoted 4 lines
I wonder if we should make -c and -d mutually exclusive. Tweak -c to include the application thread, i.e.
TEST_ASSERT(nr_lcpus == nr_vcpus+1)and require 1:1 pinning for all tasks. E.g. allowing "-c ..., -d 0,1,22" seems unnecessary.One downside I can think of will be if we add some worker threads which are not vcpus then all of those threads will end up running on a single cpu unless we edit this parsing logic again.
But adding worker threads also requires a code change, i.e. it won't require a separate commit/churn. And if we get to the point where we want multiple workers, it should be relatively straightforward to support pinning an arbitrary number of workers, e.g.
enum memtest_worker_type { MAIN_WORKER, MINION_1, MINION_2, NR_MEMTEST_WORKERS, } TEST_ASSERT(nr_lcpus == nr_vcpus + NR_MEMTEST_WORKERS);void
spawn_worker(enum memtest_worker_type type, <function pointer>){ cpu_set_t cpuset; CPU_ZERO(&cpuset); CPU_SET(task_map[nr_vcpus + type], &cpuset); <set affinity and spawn> }Quoted 3 lines
Current implementation gives vcpus special treatment via -c and for the whole application via -d. This gives good separation of concerns via flags.
But they aren't separated, e.g. using -d without -c means vCPUs are thrown into the same pool as worker threads. And if we ever do add more workers, -d doesn't allow the user to pin workers 1:1 with logical CPUs.
Actually, if -c is extended to pin workers, then adding -d is unnecessary. If the user wants to affine tasks to CPUs but not pin 1:1, it can do that with e.g. taskset. What the user can't do is pin 1:1.
Quoted 6 lines
If we don't want to _require_ the caller to pin the main worker, then we could do
TEST_ASSERT(nr_lcpus >= nr_vcpus && nr_lcpus <= nr_vcpus + NR_MEMTEST_WORKERS);to _require_ pinning all vCPUs, and allow but not require pinning non-vCPU tasks.
Okay, I will remove -d and only keep -c. I will extend it to support pinning the main worker and vcpus. Arguments to -c will be like:
<main woker lcpu>, <vcpu0's lcpu>, <vcpu1's lcpu>, <vcpu2's lcpu>,... Example:
./dirty_log_perf_test -v 3 -c 1,20,21,22
Main worker will run on 1 and 3 vcpus will run on logical cpus 20, 21 and 22.
Sounds good?
Thanks
Vipin
Sean Christopherson
reviewerQuoted 5 lines · Vipin Sharma
Quoted 3 lines · Sean Christopherson
Quoted 1 line · Vipin Sharma
On Wed, Aug 17, 2022 at 10:25 AM Sean Christopherson <[email protected]> wrote:
Quoted 8 lines
Quoted 6 lines
Quoted 4 lines
We need error checking here to make sure that the user really wants cpu 0 and it was not a mistake in typing.
I was thinking of usingparse_numAPI for other places as well instead ofatoi()indirty_log_perf_test.Yes, definitely. And maybe give it a name like
atoi_paranoid()?Lol. Absolutely, if that's what you want!
The goal is to capture that it's effectively atoi(), but with checking. E.g. most developers will be familiar with atoi() and won't have to think too hard if they see e.g. atoi_paranoid(). On the other hand, parse_num() leaves the reader wondering if it's parsing hex, decimal, octal, etc..., why selftests just doesn't use atoi(), etc...
Quoted 7 lines
Okay, I will remove -d and only keep -c. I will extend it to support pinning the main worker and vcpus. Arguments to -c will be like:
<main woker lcpu>, <vcpu0's lcpu>, <vcpu1's lcpu>, <vcpu2's lcpu>,... Example:
./dirty_log_perf_test -v 3 -c 1,20,21,22Main worker will run on 1 and 3 vcpus will run on logical cpus 20, 21 and 22.
I think it makes sense to have the vCPUs be first. That way vcpu0 => task_map[0], and we can also extend the option in the future without breaking existing command lines, e.g. to add more workers and/or redefine the behavior of the "trailing" numbers to say that all workers are affined to those CPUs (to allow sequestering the main worker from vCPUs without pinning it to a single CPU).
Quoted 10 lines · Sean Christopherson
Quoted 8 lines · Vipin Sharma
On Wed, Aug 17, 2022 at 2:29 PM Sean Christopherson <[email protected]> wrote:
Okay, I will remove -d and only keep -c. I will extend it to support pinning the main worker and vcpus. Arguments to -c will be like:
<main woker lcpu>, <vcpu0's lcpu>, <vcpu1's lcpu>, <vcpu2's lcpu>,... Example:
./dirty_log_perf_test -v 3 -c 1,20,21,22
Quoted 7 lines
Quoted 1 line
Main worker will run on 1 and 3 vcpus will run on logical cpus 20, 21 and 22.
I think it makes sense to have the vCPUs be first. That way vcpu0 => task_map[0], and we can also extend the option in the future without breaking existing command lines, e.g. to add more workers and/or redefine the behavior of the "trailing" numbers to say that all workers are affined to those CPUs (to allow sequestering the main worker from vCPUs without pinning it to a single CPU).
Make sense. vcpus first followed by worker cpus.
Thanks