Sean Christopherson <seanjc@xxxxxxxxxx> writes:
On Mon, Sep 12, 2022, Colton Lewis wrote:
@@ -57,7 +58,17 @@ void perf_test_guest_code(uint32_t vcpu_id)
while (true) {
for (i = 0; i < pages; i++) {
- uint64_t addr = gva + (i * pta->guest_page_size);
+ guest_random(&rand);
+
+ if (pta->random_access)
+ addr = gva + ((rand % pages) * pta->guest_page_size);
Shouldn't this use a 64-bit random number since "pages" is a 64-bit
value? Ha!
And another case where the RNG APIs can help, e.g.
Do we need to test with memory chunks that have over 2^32 pages to
choose from? That's 16 TiB of memory. Possible a computer might have
that much to dedicate to a VM, but what would be the use of such a test?
+
+ /*
+ * Use a new random number here so read/write
+ * is not tied to the address used.
+ */
guest_random(&rand);
Ya, I'm trippling (quadrupling?) down on my suggestion to improve the
APIs. Users
should not be able to screw up like this, i.e. shouldn't need comments to
warn
readers, and adding another call to get a random number shouldn't affect
unrelated
code.
Previous calls to PRNGs always affect later calls to PRNGs. That's how
they work. This "screw up" would be equally likely with any API because
the caller always needs to decide if they should reuse the same random
number or need a new one.