Commit f11aa24b authored by Colton Lewis's avatar Colton Lewis Committed by Sean Christopherson

KVM: selftests: create -r argument to specify random seed

Create a -r argument to specify a random seed. If no argument is
provided, the seed defaults to 1. The random seed is set with
perf_test_set_random_seed() and must be set before guest_code runs to
apply.
Signed-off-by: default avatarColton Lewis <coltonlewis@google.com>
Reviewed-by: default avatarDavid Matlack <dmatlack@google.com>
Link: https://lore.kernel.org/r/20221107182208.479157-3-coltonlewis@google.comSigned-off-by: default avatarSean Christopherson <seanjc@google.com>
parent b31f21a7
...@@ -132,6 +132,7 @@ struct test_params { ...@@ -132,6 +132,7 @@ struct test_params {
bool partition_vcpu_memory_access; bool partition_vcpu_memory_access;
enum vm_mem_backing_src_type backing_src; enum vm_mem_backing_src_type backing_src;
int slots; int slots;
uint32_t random_seed;
}; };
static void toggle_dirty_logging(struct kvm_vm *vm, int slots, bool enable) static void toggle_dirty_logging(struct kvm_vm *vm, int slots, bool enable)
...@@ -225,6 +226,8 @@ static void run_test(enum vm_guest_mode mode, void *arg) ...@@ -225,6 +226,8 @@ static void run_test(enum vm_guest_mode mode, void *arg)
p->slots, p->backing_src, p->slots, p->backing_src,
p->partition_vcpu_memory_access); p->partition_vcpu_memory_access);
pr_info("Random seed: %u\n", p->random_seed);
perf_test_set_random_seed(vm, p->random_seed);
perf_test_set_wr_fract(vm, p->wr_fract); perf_test_set_wr_fract(vm, p->wr_fract);
guest_num_pages = (nr_vcpus * guest_percpu_mem_size) >> vm->page_shift; guest_num_pages = (nr_vcpus * guest_percpu_mem_size) >> vm->page_shift;
...@@ -352,7 +355,7 @@ static void help(char *name) ...@@ -352,7 +355,7 @@ static void help(char *name)
{ {
puts(""); puts("");
printf("usage: %s [-h] [-i iterations] [-p offset] [-g] " printf("usage: %s [-h] [-i iterations] [-p offset] [-g] "
"[-m mode] [-n] [-b vcpu bytes] [-v vcpus] [-o] [-s mem type]" "[-m mode] [-n] [-b vcpu bytes] [-v vcpus] [-o] [-r random seed ] [-s mem type]"
"[-x memslots] [-c physical cpus to run test on]\n", name); "[-x memslots] [-c physical cpus to run test on]\n", name);
puts(""); puts("");
printf(" -i: specify iteration counts (default: %"PRIu64")\n", printf(" -i: specify iteration counts (default: %"PRIu64")\n",
...@@ -380,6 +383,7 @@ static void help(char *name) ...@@ -380,6 +383,7 @@ static void help(char *name)
printf(" -v: specify the number of vCPUs to run.\n"); printf(" -v: specify the number of vCPUs to run.\n");
printf(" -o: Overlap guest memory accesses instead of partitioning\n" printf(" -o: Overlap guest memory accesses instead of partitioning\n"
" them into a separate region of memory for each vCPU.\n"); " them into a separate region of memory for each vCPU.\n");
printf(" -r: specify the starting random seed.\n");
backing_src_help("-s"); backing_src_help("-s");
printf(" -x: Split the memory region into this number of memslots.\n" printf(" -x: Split the memory region into this number of memslots.\n"
" (default: 1)\n"); " (default: 1)\n");
...@@ -408,6 +412,7 @@ int main(int argc, char *argv[]) ...@@ -408,6 +412,7 @@ int main(int argc, char *argv[])
.partition_vcpu_memory_access = true, .partition_vcpu_memory_access = true,
.backing_src = DEFAULT_VM_MEM_SRC, .backing_src = DEFAULT_VM_MEM_SRC,
.slots = 1, .slots = 1,
.random_seed = 1,
}; };
int opt; int opt;
...@@ -418,7 +423,7 @@ int main(int argc, char *argv[]) ...@@ -418,7 +423,7 @@ int main(int argc, char *argv[])
guest_modes_append_default(); guest_modes_append_default();
while ((opt = getopt(argc, argv, "b:c:ef:ghi:m:nop:s:v:x:")) != -1) { while ((opt = getopt(argc, argv, "b:c:ef:ghi:m:nop:r:s:v:x:")) != -1) {
switch (opt) { switch (opt) {
case 'b': case 'b':
guest_percpu_mem_size = parse_size(optarg); guest_percpu_mem_size = parse_size(optarg);
...@@ -454,6 +459,9 @@ int main(int argc, char *argv[]) ...@@ -454,6 +459,9 @@ int main(int argc, char *argv[])
case 'p': case 'p':
p.phys_offset = strtoull(optarg, NULL, 0); p.phys_offset = strtoull(optarg, NULL, 0);
break; break;
case 'r':
p.random_seed = atoi_positive("Random seed", optarg);
break;
case 's': case 's':
p.backing_src = parse_backing_src_type(optarg); p.backing_src = parse_backing_src_type(optarg);
break; break;
......
...@@ -35,6 +35,7 @@ struct perf_test_args { ...@@ -35,6 +35,7 @@ struct perf_test_args {
uint64_t gpa; uint64_t gpa;
uint64_t size; uint64_t size;
uint64_t guest_page_size; uint64_t guest_page_size;
uint32_t random_seed;
int wr_fract; int wr_fract;
/* Run vCPUs in L2 instead of L1, if the architecture supports it. */ /* Run vCPUs in L2 instead of L1, if the architecture supports it. */
...@@ -56,6 +57,7 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int nr_vcpus, ...@@ -56,6 +57,7 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int nr_vcpus,
void perf_test_destroy_vm(struct kvm_vm *vm); 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_set_wr_fract(struct kvm_vm *vm, int wr_fract);
void perf_test_set_random_seed(struct kvm_vm *vm, uint32_t random_seed);
void perf_test_start_vcpu_threads(int vcpus, void (*vcpu_fn)(struct perf_test_vcpu_args *)); void perf_test_start_vcpu_threads(int vcpus, void (*vcpu_fn)(struct perf_test_vcpu_args *));
void perf_test_join_vcpu_threads(int vcpus); void perf_test_join_vcpu_threads(int vcpus);
......
...@@ -231,6 +231,12 @@ void perf_test_set_wr_fract(struct kvm_vm *vm, int wr_fract) ...@@ -231,6 +231,12 @@ void perf_test_set_wr_fract(struct kvm_vm *vm, int wr_fract)
sync_global_to_guest(vm, perf_test_args); sync_global_to_guest(vm, perf_test_args);
} }
void perf_test_set_random_seed(struct kvm_vm *vm, uint32_t random_seed)
{
perf_test_args.random_seed = random_seed;
sync_global_to_guest(vm, perf_test_args.random_seed);
}
uint64_t __weak perf_test_nested_pages(int nr_vcpus) uint64_t __weak perf_test_nested_pages(int nr_vcpus)
{ {
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment