Skip to content

Commit 8fc6134

Browse files
committed
test: Add oneshot mode to fast page fault helper
Add option for fast_page_fault_helper to run in a oneshot mode, that doesn't require the signal to be triggered before measuring the fault latency. This makes it possible to test fault latency on non-snapshotted vms as only the first fault is measured. Signed-off-by: Jack Thomson <jackabt@amazon.com>
1 parent 0355050 commit 8fc6134

File tree

1 file changed

+33
-11
lines changed

1 file changed

+33
-11
lines changed

resources/overlay/usr/local/bin/fast_page_fault_helper.c

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <sys/mman.h> // mmap
1717
#include <time.h> // clock_gettime
1818
#include <fcntl.h> // open
19+
#include <getopt.h> // getopt
1920

2021
#define MEM_SIZE_MIB (128 * 1024 * 1024)
2122
#define NANOS_PER_SEC 1000000000
@@ -30,20 +31,39 @@ void touch_memory(void *mem, size_t size, char val) {
3031

3132
int main() {
3233
sigset_t set;
33-
int signal;
34+
int signal, character;
3435
void *ptr;
3536
struct timespec start, end;
3637
long duration_nanos;
3738
FILE *out_file;
3839

39-
sigemptyset(&set);
40-
if (sigaddset(&set, SIGUSR1) == -1) {
41-
perror("sigaddset");
42-
return 1;
40+
char *options = 0;
41+
int longindex = 0;
42+
int signal_wait = 1;
43+
44+
struct option longopts[] = {
45+
{"nosignal", no_argument, NULL, 's'},
46+
{NULL, 0, NULL, 0}
47+
};
48+
49+
while((character = getopt_long(argc, argv, "s", longopts, &longindex)) != -1) {
50+
switch (character) {
51+
case 's':
52+
signal_wait = 0;
53+
break;
54+
}
4355
}
44-
if (sigprocmask(SIG_BLOCK, &set, NULL) == -1) {
45-
perror("sigprocmask");
46-
return 1;
56+
57+
if (signal_wait) {
58+
sigemptyset(&set);
59+
if (sigaddset(&set, SIGUSR1) == -1) {
60+
perror("sigaddset");
61+
return 1;
62+
}
63+
if (sigprocmask(SIG_BLOCK, &set, NULL) == -1) {
64+
perror("sigprocmask");
65+
return 1;
66+
}
4767
}
4868

4969
ptr = mmap(NULL, MEM_SIZE_MIB, PROT_READ | PROT_WRITE, MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
@@ -53,9 +73,11 @@ int main() {
5373
return 1;
5474
}
5575

56-
touch_memory(ptr, MEM_SIZE_MIB, 1);
76+
if (signal_wait) {
77+
touch_memory(ptr, MEM_SIZE_MIB, 1);
5778

58-
sigwait(&set, &signal);
79+
sigwait(&set, &signal);
80+
}
5981

6082
clock_gettime(CLOCK_BOOTTIME, &start);
6183
touch_memory(ptr, MEM_SIZE_MIB, 2);
@@ -76,4 +98,4 @@ int main() {
7698
}
7799

78100
return 0;
79-
}
101+
}

0 commit comments

Comments
 (0)