Re: [PATCH 06/15] KVM: selftests: Use shorthand local var to access struct perf_tests_args

From: Ben Gardon
Date: Wed Feb 10 2021 - 20:10:24 EST


On Wed, Feb 10, 2021 at 3:06 PM Sean Christopherson <seanjc@xxxxxxxxxx> wrote:
>
> Use 'pta' as a local pointer to the global perf_tests_args in order to
> shorten line lengths and make the code borderline readable.
>
> No functional change intended.
>
> Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>

Reviewed-by: Ben Gardon <bgardon@xxxxxxxxxx>

> ---
> .../selftests/kvm/lib/perf_test_util.c | 36 ++++++++++---------
> 1 file changed, 19 insertions(+), 17 deletions(-)
>
> diff --git a/tools/testing/selftests/kvm/lib/perf_test_util.c b/tools/testing/selftests/kvm/lib/perf_test_util.c
> index f187b86f2e14..73b0fccc28b9 100644
> --- a/tools/testing/selftests/kvm/lib/perf_test_util.c
> +++ b/tools/testing/selftests/kvm/lib/perf_test_util.c
> @@ -23,7 +23,8 @@ static uint64_t guest_test_virt_mem = DEFAULT_GUEST_TEST_MEM;
> */
> static void guest_code(uint32_t vcpu_id)
> {
> - struct perf_test_vcpu_args *vcpu_args = &perf_test_args.vcpu_args[vcpu_id];
> + struct perf_test_args *pta = &perf_test_args;
> + struct perf_test_vcpu_args *vcpu_args = &pta->vcpu_args[vcpu_id];
> uint64_t gva;
> uint64_t pages;
> int i;
> @@ -36,9 +37,9 @@ static void guest_code(uint32_t vcpu_id)
>
> while (true) {
> for (i = 0; i < pages; i++) {
> - uint64_t addr = gva + (i * perf_test_args.guest_page_size);
> + uint64_t addr = gva + (i * pta->guest_page_size);
>
> - if (i % perf_test_args.wr_fract == 0)
> + if (i % pta->wr_fract == 0)
> *(uint64_t *)addr = 0x0123456789ABCDEF;
> else
> READ_ONCE(*(uint64_t *)addr);
> @@ -52,32 +53,32 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
> uint64_t vcpu_memory_bytes,
> enum vm_mem_backing_src_type backing_src)
> {
> + struct perf_test_args *pta = &perf_test_args;
> struct kvm_vm *vm;
> uint64_t guest_num_pages;
>
> pr_info("Testing guest mode: %s\n", vm_guest_mode_string(mode));
>
> - perf_test_args.host_page_size = getpagesize();
> + pta->host_page_size = getpagesize();
>
> /*
> * Snapshot the non-huge page size. This is used by the guest code to
> * access/dirty pages at the logging granularity.
> */
> - perf_test_args.guest_page_size = vm_guest_mode_params[mode].page_size;
> + pta->guest_page_size = vm_guest_mode_params[mode].page_size;
>
> guest_num_pages = vm_adjust_num_guest_pages(mode,
> - (vcpus * vcpu_memory_bytes) / perf_test_args.guest_page_size);
> + (vcpus * vcpu_memory_bytes) / pta->guest_page_size);
>
> - TEST_ASSERT(vcpu_memory_bytes % perf_test_args.host_page_size == 0,
> + TEST_ASSERT(vcpu_memory_bytes % pta->host_page_size == 0,
> "Guest memory size is not host page size aligned.");
> - TEST_ASSERT(vcpu_memory_bytes % perf_test_args.guest_page_size == 0,
> + TEST_ASSERT(vcpu_memory_bytes % pta->guest_page_size == 0,
> "Guest memory size is not guest page size aligned.");
>
> vm = vm_create_with_vcpus(mode, vcpus,
> - (vcpus * vcpu_memory_bytes) / perf_test_args.guest_page_size,
> + (vcpus * vcpu_memory_bytes) / pta->guest_page_size,
> 0, guest_code, NULL);
> -
> - perf_test_args.vm = vm;
> + pta->vm = vm;
>
> /*
> * If there should be more memory in the guest test region than there
> @@ -90,8 +91,8 @@ struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int vcpus,
> vcpu_memory_bytes);
>
> guest_test_phys_mem = (vm_get_max_gfn(vm) - guest_num_pages) *
> - perf_test_args.guest_page_size;
> - guest_test_phys_mem &= ~(perf_test_args.host_page_size - 1);
> + pta->guest_page_size;
> + guest_test_phys_mem &= ~(pta->host_page_size - 1);

Not really germane to this patch, but the align macro could be used
here as well.

> if (backing_src == VM_MEM_SRC_ANONYMOUS_THP ||
> backing_src == VM_MEM_SRC_ANONYMOUS_HUGETLB)
> guest_test_phys_mem &= ~(KVM_UTIL_HUGEPAGE_ALIGNMENT - 1);
> @@ -125,30 +126,31 @@ void perf_test_setup_vcpus(struct kvm_vm *vm, int vcpus,
> uint64_t vcpu_memory_bytes,
> bool partition_vcpu_memory_access)
> {
> + struct perf_test_args *pta = &perf_test_args;
> vm_paddr_t vcpu_gpa;
> struct perf_test_vcpu_args *vcpu_args;
> int vcpu_id;
>
> for (vcpu_id = 0; vcpu_id < vcpus; vcpu_id++) {
> - vcpu_args = &perf_test_args.vcpu_args[vcpu_id];
> + vcpu_args = &pta->vcpu_args[vcpu_id];
>
> vcpu_args->vcpu_id = vcpu_id;
> if (partition_vcpu_memory_access) {
> vcpu_args->gva = guest_test_virt_mem +
> (vcpu_id * vcpu_memory_bytes);
> vcpu_args->pages = vcpu_memory_bytes /
> - perf_test_args.guest_page_size;
> + pta->guest_page_size;
> vcpu_gpa = guest_test_phys_mem +
> (vcpu_id * vcpu_memory_bytes);
> } else {
> vcpu_args->gva = guest_test_virt_mem;
> vcpu_args->pages = (vcpus * vcpu_memory_bytes) /
> - perf_test_args.guest_page_size;
> + pta->guest_page_size;
> vcpu_gpa = guest_test_phys_mem;
> }
>
> pr_debug("Added VCPU %d with test mem gpa [%lx, %lx)\n",
> vcpu_id, vcpu_gpa, vcpu_gpa +
> - (vcpu_args->pages * perf_test_args.guest_page_size));
> + (vcpu_args->pages * pta->guest_page_size));
> }
> }
> --
> 2.30.0.478.g8a0d178c01-goog
>