Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * tools/testing/selftests/kvm/include/perf_test_util.h
0004  *
0005  * Copyright (C) 2020, Google LLC.
0006  */
0007 
0008 #ifndef SELFTEST_KVM_PERF_TEST_UTIL_H
0009 #define SELFTEST_KVM_PERF_TEST_UTIL_H
0010 
0011 #include <pthread.h>
0012 
0013 #include "kvm_util.h"
0014 
0015 /* Default guest test virtual memory offset */
0016 #define DEFAULT_GUEST_TEST_MEM      0xc0000000
0017 
0018 #define DEFAULT_PER_VCPU_MEM_SIZE   (1 << 30) /* 1G */
0019 
0020 #define PERF_TEST_MEM_SLOT_INDEX    1
0021 
0022 struct perf_test_vcpu_args {
0023     uint64_t gpa;
0024     uint64_t gva;
0025     uint64_t pages;
0026 
0027     /* Only used by the host userspace part of the vCPU thread */
0028     struct kvm_vcpu *vcpu;
0029     int vcpu_idx;
0030 };
0031 
0032 struct perf_test_args {
0033     struct kvm_vm *vm;
0034     /* The starting address and size of the guest test region. */
0035     uint64_t gpa;
0036     uint64_t size;
0037     uint64_t guest_page_size;
0038     int wr_fract;
0039 
0040     /* Run vCPUs in L2 instead of L1, if the architecture supports it. */
0041     bool nested;
0042 
0043     struct perf_test_vcpu_args vcpu_args[KVM_MAX_VCPUS];
0044 };
0045 
0046 extern struct perf_test_args perf_test_args;
0047 
0048 struct kvm_vm *perf_test_create_vm(enum vm_guest_mode mode, int nr_vcpus,
0049                    uint64_t vcpu_memory_bytes, int slots,
0050                    enum vm_mem_backing_src_type backing_src,
0051                    bool partition_vcpu_memory_access);
0052 void perf_test_destroy_vm(struct kvm_vm *vm);
0053 
0054 void perf_test_set_wr_fract(struct kvm_vm *vm, int wr_fract);
0055 
0056 void perf_test_start_vcpu_threads(int vcpus, void (*vcpu_fn)(struct perf_test_vcpu_args *));
0057 void perf_test_join_vcpu_threads(int vcpus);
0058 void perf_test_guest_code(uint32_t vcpu_id);
0059 
0060 uint64_t perf_test_nested_pages(int nr_vcpus);
0061 void perf_test_setup_nested(struct kvm_vm *vm, int nr_vcpus, struct kvm_vcpu *vcpus[]);
0062 
0063 #endif /* SELFTEST_KVM_PERF_TEST_UTIL_H */