From: Andrew Jones <drjones@redhat.com>
To: kvm@vger.kernel.org
Cc: pbonzini@redhat.com, borntraeger@de.ibm.com,
frankja@linux.ibm.com, bgardon@google.com, peterx@redhat.com
Subject: [PATCH 06/11] KVM: selftests: Make the per vcpu memory size global
Date: Wed, 4 Nov 2020 22:23:52 +0100 [thread overview]
Message-ID: <20201104212357.171559-7-drjones@redhat.com> (raw)
In-Reply-To: <20201104212357.171559-1-drjones@redhat.com>
Rename vcpu_memory_bytes to something with "percpu" in it
in order to be less ambiguous. Also make it global to
simplify things.
Signed-off-by: Andrew Jones <drjones@redhat.com>
---
.../selftests/kvm/demand_paging_test.c | 36 +++++++++----------
1 file changed, 17 insertions(+), 19 deletions(-)
diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testing/selftests/kvm/demand_paging_test.c
index d1fe6c8e595b..89699652c34d 100644
--- a/tools/testing/selftests/kvm/demand_paging_test.c
+++ b/tools/testing/selftests/kvm/demand_paging_test.c
@@ -32,8 +32,7 @@
/* Default guest test virtual memory offset */
#define DEFAULT_GUEST_TEST_MEM 0xc0000000
-
-#define DEFAULT_GUEST_TEST_MEM_SIZE (1 << 30) /* 1G */
+#define DEFAULT_PER_VCPU_MEM_SIZE (1 << 30) /* 1G */
#ifdef PRINT_PER_PAGE_UPDATES
#define PER_PAGE_DEBUG(...) printf(__VA_ARGS__)
@@ -72,6 +71,7 @@ static uint64_t guest_test_phys_mem;
* Must not conflict with identity mapped test code.
*/
static uint64_t guest_test_virt_mem = DEFAULT_GUEST_TEST_MEM;
+static uint64_t guest_percpu_mem_size = DEFAULT_PER_VCPU_MEM_SIZE;
struct vcpu_args {
uint64_t gva;
@@ -145,7 +145,7 @@ static void *vcpu_worker(void *data)
#define PTES_PER_4K_PT 512
static struct kvm_vm *create_vm(enum vm_guest_mode mode, int vcpus,
- uint64_t vcpu_memory_bytes)
+ uint64_t guest_percpu_mem_size)
{
struct kvm_vm *vm;
uint64_t pages = DEFAULT_GUEST_PHY_PAGES;
@@ -160,7 +160,7 @@ static struct kvm_vm *create_vm(enum vm_guest_mode mode, int vcpus,
* page size guest will need even less memory for page tables).
*/
pages += (2 * pages) / PTES_PER_4K_PT;
- pages += ((2 * vcpus * vcpu_memory_bytes) >> PAGE_SHIFT_4K) /
+ pages += ((2 * vcpus * guest_percpu_mem_size) >> PAGE_SHIFT_4K) /
PTES_PER_4K_PT;
pages = vm_adjust_num_guest_pages(mode, pages);
@@ -351,8 +351,7 @@ static int setup_demand_paging(struct kvm_vm *vm,
}
static void run_test(enum vm_guest_mode mode, bool use_uffd,
- useconds_t uffd_delay, int vcpus,
- uint64_t vcpu_memory_bytes)
+ useconds_t uffd_delay, int vcpus)
{
pthread_t *vcpu_threads;
pthread_t *uffd_handler_threads = NULL;
@@ -364,14 +363,14 @@ static void run_test(enum vm_guest_mode mode, bool use_uffd,
int vcpu_id;
int r;
- vm = create_vm(mode, vcpus, vcpu_memory_bytes);
+ vm = create_vm(mode, vcpus, guest_percpu_mem_size);
guest_page_size = vm_get_page_size(vm);
- TEST_ASSERT(vcpu_memory_bytes % guest_page_size == 0,
+ TEST_ASSERT(guest_percpu_mem_size % guest_page_size == 0,
"Guest memory size is not guest page size aligned.");
- guest_num_pages = (vcpus * vcpu_memory_bytes) / guest_page_size;
+ guest_num_pages = (vcpus * guest_percpu_mem_size) / guest_page_size;
guest_num_pages = vm_adjust_num_guest_pages(mode, guest_num_pages);
/*
@@ -382,10 +381,10 @@ static void run_test(enum vm_guest_mode mode, bool use_uffd,
"Requested more guest memory than address space allows.\n"
" guest pages: %lx max gfn: %x vcpus: %d wss: %lx]\n",
guest_num_pages, vm_get_max_gfn(vm), vcpus,
- vcpu_memory_bytes);
+ guest_percpu_mem_size);
host_page_size = getpagesize();
- TEST_ASSERT(vcpu_memory_bytes % host_page_size == 0,
+ TEST_ASSERT(guest_percpu_mem_size % host_page_size == 0,
"Guest memory size is not host page size aligned.");
guest_test_phys_mem = (vm_get_max_gfn(vm) - guest_num_pages) *
@@ -436,9 +435,9 @@ static void run_test(enum vm_guest_mode mode, bool use_uffd,
vm_vcpu_add_default(vm, vcpu_id, guest_code);
- vcpu_gpa = guest_test_phys_mem + (vcpu_id * vcpu_memory_bytes);
+ vcpu_gpa = guest_test_phys_mem + (vcpu_id * guest_percpu_mem_size);
PER_VCPU_DEBUG("Added VCPU %d with test mem gpa [%lx, %lx)\n",
- vcpu_id, vcpu_gpa, vcpu_gpa + vcpu_memory_bytes);
+ vcpu_id, vcpu_gpa, vcpu_gpa + guest_percpu_mem_size);
/* Cache the HVA pointer of the region */
vcpu_hva = addr_gpa2hva(vm, vcpu_gpa);
@@ -456,7 +455,7 @@ static void run_test(enum vm_guest_mode mode, bool use_uffd,
&uffd_handler_threads[vcpu_id],
pipefds[vcpu_id * 2],
uffd_delay, &uffd_args[vcpu_id],
- vcpu_hva, vcpu_memory_bytes);
+ vcpu_hva, guest_percpu_mem_size);
if (r < 0)
exit(-r);
}
@@ -468,8 +467,8 @@ static void run_test(enum vm_guest_mode mode, bool use_uffd,
vcpu_args[vcpu_id].vm = vm;
vcpu_args[vcpu_id].vcpu_id = vcpu_id;
vcpu_args[vcpu_id].gva = guest_test_virt_mem +
- (vcpu_id * vcpu_memory_bytes);
- vcpu_args[vcpu_id].pages = vcpu_memory_bytes / guest_page_size;
+ (vcpu_id * guest_percpu_mem_size);
+ vcpu_args[vcpu_id].pages = guest_percpu_mem_size / guest_page_size;
}
/* Export the shared variables to the guest */
@@ -569,7 +568,6 @@ static void help(char *name)
int main(int argc, char *argv[])
{
bool mode_selected = false;
- uint64_t vcpu_memory_bytes = DEFAULT_GUEST_TEST_MEM_SIZE;
int vcpus = 1;
unsigned int mode;
int opt, i;
@@ -619,7 +617,7 @@ int main(int argc, char *argv[])
"A negative UFFD delay is not supported.");
break;
case 'b':
- vcpu_memory_bytes = parse_size(optarg);
+ guest_percpu_mem_size = parse_size(optarg);
break;
case 'v':
vcpus = atoi(optarg);
@@ -642,7 +640,7 @@ int main(int argc, char *argv[])
TEST_ASSERT(guest_modes[i].supported,
"Guest mode ID %d (%s) not supported.",
i, vm_guest_mode_string(i));
- run_test(i, use_uffd, uffd_delay, vcpus, vcpu_memory_bytes);
+ run_test(i, use_uffd, uffd_delay, vcpus);
}
return 0;
--
2.26.2
next prev parent reply other threads:[~2020-11-04 21:24 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-04 21:23 [PATCH 00/11] KVM: selftests: Cleanups Andrew Jones
2020-11-04 21:23 ` [PATCH 01/11] KVM: selftests: Add x86_64/tsc_msrs_test to .gitignore Andrew Jones
2020-11-04 21:23 ` [PATCH 02/11] KVM: selftests: Drop pointless vm_create wrapper Andrew Jones
2020-11-04 21:23 ` [PATCH 03/11] KVM: selftests: Always clear dirty bitmap after iteration Andrew Jones
2020-11-04 21:23 ` [PATCH 04/11] KVM: selftests: Use a single binary for dirty/clear log test Andrew Jones
2020-11-04 21:23 ` [PATCH 05/11] KVM: selftests: Introduce after_vcpu_run hook for dirty " Andrew Jones
2020-11-04 21:23 ` Andrew Jones [this message]
2020-11-04 21:23 ` [PATCH 07/11] KVM: selftests: Make the number of vcpus global Andrew Jones
2020-11-04 21:23 ` [PATCH 08/11] KVM: selftests: Factor out guest mode code Andrew Jones
2020-11-04 21:23 ` [PATCH 09/11] KVM: selftests: Make vm_create_default common Andrew Jones
2020-11-04 21:36 ` Andrew Jones
2020-11-05 7:18 ` Christian Borntraeger
2020-11-05 9:59 ` Andrew Jones
2020-11-05 18:45 ` Peter Xu
2020-11-05 18:54 ` Christian Borntraeger
2020-11-04 21:23 ` [PATCH 10/11] KVM: selftests: Introduce vm_create_[default_]vcpus Andrew Jones
2020-11-04 21:23 ` [PATCH 11/11] KVM: selftests: Remove create_vm Andrew Jones
2020-11-05 7:08 ` [PATCH 00/11] KVM: selftests: Cleanups Christian Borntraeger
2020-11-05 18:55 ` Peter Xu
2020-11-05 19:41 ` Ben Gardon
2020-11-06 9:45 ` Andrew Jones
2020-11-06 15:04 ` Peter Xu
2020-11-09 17:11 ` Ben Gardon
2020-11-06 13:01 ` Paolo Bonzini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201104212357.171559-7-drjones@redhat.com \
--to=drjones@redhat.com \
--cc=bgardon@google.com \
--cc=borntraeger@de.ibm.com \
--cc=frankja@linux.ibm.com \
--cc=kvm@vger.kernel.org \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox