From: Ben Gardon <bgardon@google.com>
To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
linux-kselftest@vger.kernel.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Cannon Matthews <cannonmatthews@google.com>,
Peter Xu <peterx@redhat.com>, Andrew Jones <drjones@redhat.com>,
Peter Shier <pshier@google.com>, Oliver Upton <oupton@google.com>,
Ben Gardon <bgardon@google.com>
Subject: [PATCH v4 03/10] KVM: selftests: Add configurable demand paging delay
Date: Thu, 23 Jan 2020 10:04:29 -0800 [thread overview]
Message-ID: <20200123180436.99487-4-bgardon@google.com> (raw)
In-Reply-To: <20200123180436.99487-1-bgardon@google.com>
When running the demand paging test with the -u option, the User Fault
FD handler essentially adds an arbitrary delay to page fault resolution.
To enable better simulation of a real demand paging scenario, add a
configurable delay to the UFFD handler.
Reviewed-by: Peter Xu <peterx@redhat.com>
Signed-off-by: Ben Gardon <bgardon@google.com>
---
.../selftests/kvm/demand_paging_test.c | 32 +++++++++++++++----
1 file changed, 25 insertions(+), 7 deletions(-)
diff --git a/tools/testing/selftests/kvm/demand_paging_test.c b/tools/testing/selftests/kvm/demand_paging_test.c
index 6fab4468f97f6..01d2c76ada55d 100644
--- a/tools/testing/selftests/kvm/demand_paging_test.c
+++ b/tools/testing/selftests/kvm/demand_paging_test.c
@@ -143,6 +143,7 @@ bool quit_uffd_thread;
struct uffd_handler_args {
int uffd;
int pipefd;
+ useconds_t delay;
};
static void *uffd_handler_thread_fn(void *arg)
@@ -150,6 +151,7 @@ static void *uffd_handler_thread_fn(void *arg)
struct uffd_handler_args *uffd_args = (struct uffd_handler_args *)arg;
int uffd = uffd_args->uffd;
int pipefd = uffd_args->pipefd;
+ useconds_t delay = uffd_args->delay;
int64_t pages = 0;
while (!quit_uffd_thread) {
@@ -210,6 +212,8 @@ static void *uffd_handler_thread_fn(void *arg)
if (!(msg.event & UFFD_EVENT_PAGEFAULT))
continue;
+ if (delay)
+ usleep(delay);
addr = msg.arg.pagefault.address;
r = handle_uffd_page_request(uffd, addr);
if (r < 0)
@@ -221,7 +225,8 @@ static void *uffd_handler_thread_fn(void *arg)
}
static int setup_demand_paging(struct kvm_vm *vm,
- pthread_t *uffd_handler_thread, int pipefd)
+ pthread_t *uffd_handler_thread, int pipefd,
+ useconds_t uffd_delay)
{
int uffd;
struct uffdio_api uffdio_api;
@@ -262,6 +267,7 @@ static int setup_demand_paging(struct kvm_vm *vm,
uffd_args.uffd = uffd;
uffd_args.pipefd = pipefd;
+ uffd_args.delay = uffd_delay;
pthread_create(uffd_handler_thread, NULL, uffd_handler_thread_fn,
&uffd_args);
@@ -271,7 +277,8 @@ static int setup_demand_paging(struct kvm_vm *vm,
#define GUEST_MEM_SHIFT 30 /* 1G */
#define PAGE_SHIFT_4K 12
-static void run_test(enum vm_guest_mode mode, bool use_uffd)
+static void run_test(enum vm_guest_mode mode, bool use_uffd,
+ useconds_t uffd_delay)
{
pthread_t vcpu_thread;
pthread_t uffd_handler_thread;
@@ -339,7 +346,8 @@ static void run_test(enum vm_guest_mode mode, bool use_uffd)
r = pipe2(pipefd, O_CLOEXEC | O_NONBLOCK);
TEST_ASSERT(!r, "Failed to set up pipefd");
- r = setup_demand_paging(vm, &uffd_handler_thread, pipefd[0]);
+ r = setup_demand_paging(vm, &uffd_handler_thread, pipefd[0],
+ uffd_delay);
if (r < 0)
exit(-r);
}
@@ -395,7 +403,7 @@ static void help(char *name)
int i;
puts("");
- printf("usage: %s [-h] [-m mode] [-u]\n", name);
+ printf("usage: %s [-h] [-m mode] [-u] [-d uffd_delay_usec]\n", name);
printf(" -m: specify the guest mode ID to test\n"
" (default: test all supported modes)\n"
" This option may be used multiple times.\n"
@@ -404,7 +412,11 @@ static void help(char *name)
printf(" %d: %s%s\n", i, vm_guest_mode_string(i),
vm_guest_mode_params[i].supported ? " (supported)" : "");
}
- printf(" -u: Use User Fault FD to handle vCPU page faults.\n");
+ printf(" -u: use User Fault FD to handle vCPU page\n"
+ " faults.\n");
+ printf(" -d: add a delay in usec to the User Fault\n"
+ " FD handler to simulate demand paging\n"
+ " overheads. Ignored without -u.\n");
puts("");
exit(0);
}
@@ -415,6 +427,7 @@ int main(int argc, char *argv[])
unsigned int mode;
int opt, i;
bool use_uffd = false;
+ useconds_t uffd_delay = 0;
#ifdef __aarch64__
unsigned int host_ipa_limit;
#endif
@@ -438,7 +451,7 @@ int main(int argc, char *argv[])
vm_guest_mode_params_init(VM_MODE_P40V48_4K, true, true);
#endif
- while ((opt = getopt(argc, argv, "hm:u")) != -1) {
+ while ((opt = getopt(argc, argv, "hm:ud:")) != -1) {
switch (opt) {
case 'm':
if (!mode_selected) {
@@ -454,6 +467,11 @@ int main(int argc, char *argv[])
case 'u':
use_uffd = true;
break;
+ case 'd':
+ uffd_delay = strtoul(optarg, NULL, 0);
+ TEST_ASSERT(uffd_delay >= 0,
+ "A negative UFFD delay is not supported.");
+ break;
case 'h':
default:
help(argv[0]);
@@ -467,7 +485,7 @@ int main(int argc, char *argv[])
TEST_ASSERT(vm_guest_mode_params[i].supported,
"Guest mode ID %d (%s) not supported.",
i, vm_guest_mode_string(i));
- run_test(i, use_uffd);
+ run_test(i, use_uffd, uffd_delay);
}
return 0;
--
2.25.0.341.g760bfbb309-goog
next prev parent reply other threads:[~2020-01-23 18:05 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-23 18:04 [PATCH v4 00/10] Create a userfaultfd demand paging test Ben Gardon
2020-01-23 18:04 ` [PATCH v4 01/10] KVM: selftests: Create a " Ben Gardon
2020-01-24 9:49 ` Andrew Jones
2020-01-27 9:18 ` Thomas Huth
2020-01-23 18:04 ` [PATCH v4 02/10] KVM: selftests: Add demand paging content to the " Ben Gardon
2020-01-23 18:04 ` Ben Gardon [this message]
2020-01-23 18:04 ` [PATCH v4 04/10] KVM: selftests: Add memory size parameter " Ben Gardon
2020-01-24 10:01 ` Andrew Jones
2020-01-23 18:04 ` [PATCH v4 05/10] KVM: selftests: Pass args to vCPU in global vCPU args struct Ben Gardon
2020-01-23 18:04 ` [PATCH v4 06/10] KVM: selftests: Add support for vcpu_args_set to aarch64 and s390x Ben Gardon
2020-01-24 9:03 ` Paolo Bonzini
2020-01-24 9:35 ` Andrew Jones
2020-01-24 9:44 ` Paolo Bonzini
2020-01-24 10:45 ` Andrew Jones
2020-01-24 18:33 ` Christian Borntraeger
2020-01-25 9:34 ` Paolo Bonzini
2020-01-27 8:38 ` Andrew Jones
2020-01-27 9:01 ` Thomas Huth
2020-01-23 18:04 ` [PATCH v4 07/10] KVM: selftests: Support multiple vCPUs in demand paging test Ben Gardon
2020-01-24 10:16 ` Andrew Jones
2020-01-24 10:49 ` Andrew Jones
2020-01-25 9:39 ` Paolo Bonzini
2020-01-27 8:39 ` Andrew Jones
2020-01-23 18:04 ` [PATCH v4 08/10] KVM: selftests: Time guest demand paging Ben Gardon
2020-01-24 10:21 ` Andrew Jones
2020-01-23 18:04 ` [PATCH v4 09/10] KVM: selftests: Stop memslot creation in KVM internal memslot region Ben Gardon
2020-01-24 8:58 ` Paolo Bonzini
2020-01-24 18:41 ` Ben Gardon
2020-01-25 9:37 ` Paolo Bonzini
2020-01-27 17:28 ` Ben Gardon
2020-01-23 18:04 ` [PATCH v4 10/10] KVM: selftests: Move memslot 0 above KVM internal memslots Ben Gardon
2020-01-24 9:01 ` Paolo Bonzini
2020-01-24 18:53 ` Ben Gardon
2020-01-27 9:42 ` Thomas Huth
2020-01-24 9:03 ` [PATCH v4 00/10] Create a userfaultfd demand paging test 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=20200123180436.99487-4-bgardon@google.com \
--to=bgardon@google.com \
--cc=cannonmatthews@google.com \
--cc=drjones@redhat.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=oupton@google.com \
--cc=pbonzini@redhat.com \
--cc=peterx@redhat.com \
--cc=pshier@google.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;
as well as URLs for NNTP newsgroup(s).