Re: [PATCH v7 1/3] KVM: selftests: implement random number generation for guest code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Sean Christopherson <seanjc@xxxxxxxxxx> writes:

On Wed, Oct 19, 2022, Colton Lewis wrote:
Implement random number generation for guest code to randomize parts
of the test, making it less predictable and a more accurate reflection
of reality.

Create a -r argument to specify a random seed. If no argument is
provided, the seed defaults to 0. The random seed is set with
perf_test_set_random_seed() and must be set before guest_code runs to
apply.

The random number generator chosen is the Park-Miller Linear
Congruential Generator, a fancy name for a basic and well-understood
random number generator entirely sufficient for this purpose. Each
vCPU calculates its own seed by adding its index to the seed provided.

Signed-off-by: Colton Lewis <coltonlewis@xxxxxxxxxx>
Reviewed-by: Ricardo Koller <ricarkol@xxxxxxxxxx>
Reviewed-by: David Matlack <dmatlack@xxxxxxxxxx>

This patch has changed a fair bit since David and Ricardo gave their reviews, their Reviewed-by's should be dropped. Alternatively, if a patch has is on the fence so to speak, i.e. has changed a little bit but not thaaaaat much, you can add something in the cover letter, e.g. "David/Ricardo, I kept your reviews, let me know if that's not ok". But in this case, I think the code has changed enough
that their reviews should be dropped.


I talked to Ricardo privately and he thought it was ok to leave the
names in this borderline case. IMO, changing this interface doesn't
change anything important of what the patch is doing.

Nevertheless, I'll drop the names and ask them to reconfirm.

---
  .../testing/selftests/kvm/dirty_log_perf_test.c | 12 ++++++++++--
  .../selftests/kvm/include/perf_test_util.h      |  2 ++
  tools/testing/selftests/kvm/include/test_util.h |  7 +++++++
  .../testing/selftests/kvm/lib/perf_test_util.c  |  7 +++++++
  tools/testing/selftests/kvm/lib/test_util.c     | 17 +++++++++++++++++
  5 files changed, 43 insertions(+), 2 deletions(-)

I think it makes sense to introduce "struct guest_random_state" separately from the usage in perf_test_util and dirty_log_perf_test. E.g. so that if we need to revert the perf_test_util changes (extremely unlikely), we can do so without having to wipe out the pRNG at the same time. Or so that someone can pull in the pRNG to
their series without having to take a dependency on the other changes.


Will do. Was attempting to avoid adding unused code in its own commit
according to
https://www.kernel.org/doc/html/latest/process/5.Posting.html

"Whenever possible, a patch which adds new code should make that code
active immediately."

diff --git a/tools/testing/selftests/kvm/include/test_util.h b/tools/testing/selftests/kvm/include/test_util.h
index befc754ce9b3..9e4f36a1a8b0 100644
--- a/tools/testing/selftests/kvm/include/test_util.h
+++ b/tools/testing/selftests/kvm/include/test_util.h
@@ -152,4 +152,11 @@ static inline void *align_ptr_up(void *x, size_t size)
  	return (void *)align_up((unsigned long)x, size);
  }

+struct guest_random_state {
+	uint32_t seed;
+};
+
+struct guest_random_state new_guest_random_state(uint32_t seed);
+uint32_t guest_random_u32(struct guest_random_state *state);
+
  #endif /* SELFTEST_KVM_TEST_UTIL_H */
diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testing/selftests/kvm/lib/perf_test_util.c
index 9618b37c66f7..5f0eebb626b5 100644
--- a/tools/testing/selftests/kvm/lib/perf_test_util.c
+++ b/tools/testing/selftests/kvm/lib/perf_test_util.c
@@ -49,6 +49,7 @@ void perf_test_guest_code(uint32_t vcpu_idx)
  	uint64_t gva;
  	uint64_t pages;
  	int i;
+ struct guest_random_state rand_state = new_guest_random_state(pta->random_seed + vcpu_idx);

lib/perf_test_util.c: In function ‘perf_test_guest_code’:
lib/perf_test_util.c:52:35: error: unused variable ‘rand_state’ [-Werror=unused-variable] 52 | struct guest_random_state rand_state = new_guest_random_state(pta->random_seed + vcpu_idx);
       |                                   ^~~~~~~~~~

This belongs in the next path. I'd also prefer to split the declaration from the
initialization as this is an unnecessarily long line, e.g.

Understood that this is implied by the previous comment. As for the line
length, checkpatch doesn't complain.




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux