David Matlack <dmatlack@xxxxxxxxxx> writes:
On Wed, Nov 02, 2022 at 04:00:05PM +0000, Colton Lewis wrote:
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: Colton Lewis <coltonlewis@xxxxxxxxxx>
---
tools/testing/selftests/kvm/dirty_log_perf_test.c | 12 ++++++++++--
tools/testing/selftests/kvm/include/perf_test_util.h | 2 ++
tools/testing/selftests/kvm/lib/perf_test_util.c | 6 ++++++
3 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/kvm/dirty_log_perf_test.c
b/tools/testing/selftests/kvm/dirty_log_perf_test.c
index f99e39a672d3..c97a5e455699 100644
--- a/tools/testing/selftests/kvm/dirty_log_perf_test.c
+++ b/tools/testing/selftests/kvm/dirty_log_perf_test.c
@@ -132,6 +132,7 @@ struct test_params {
bool partition_vcpu_memory_access;
enum vm_mem_backing_src_type backing_src;
int slots;
+ uint32_t random_seed;
};
static void toggle_dirty_logging(struct kvm_vm *vm, int slots, bool
enable)
@@ -225,6 +226,9 @@ static void run_test(enum vm_guest_mode mode, void
*arg)
p->slots, p->backing_src,
p->partition_vcpu_memory_access);
+ /* If no argument provided, random seed will be 1. */
+ pr_info("Random seed: %u\n", p->random_seed);
+ perf_test_set_random_seed(vm, p->random_seed ? p->random_seed : 1);
If the user passes `-r 0` or does not pass `-r` at all, this will print
"Random seed: 0" and then proceed to use 1 as the random seed, which
seems unnecessarily misleading.
Fair point, forgot to change the print statement when I made that
change.
If you want the default random seed to be 1, you can initialize
p.random_seed to 1 before argument parsing (where all the other
test_params are default initialized), then the value you print here will
be accurate and you don't need the comment or ternary operator.
Will do. This also need a argument parsing check to specifically prevent
0 since my reason for changing in the first place is realizing 0 is not
a valid input to the pRNG I chose. Anything multiplied by 0 is 0 so a 0
seed produces a string of 0s. libc random also chooses 1 if seed is not
specified.