10 #include <sys/types.h>
12 #include <linux/types.h>
14 #define MB (1UL << 20)
15 #define PAGE_SIZE sysconf(_SC_PAGESIZE)
17 #define GUP_FAST_BENCHMARK _IOWR('g', 1, struct gup_benchmark)
18 #define GUP_LONGTERM_BENCHMARK _IOWR('g', 2, struct gup_benchmark)
19 #define GUP_BENCHMARK _IOWR('g', 3, struct gup_benchmark)
21 struct gup_benchmark {
26 __u32 nr_pages_per_call;
30 int main(int argc, char **argv)
32 struct gup_benchmark gup;
33 unsigned long size = 128 * MB;
34 int i, fd, filed, opt, nr_pages = 1, thp = -1, repeats = 1, write = 0;
35 int cmd = GUP_FAST_BENCHMARK, flags = MAP_PRIVATE;
36 char *file = "/dev/zero";
39 while ((opt = getopt(argc, argv, "m:r:n:f:tTLUSH")) != -1) {
42 size = atoi(optarg) * MB;
45 repeats = atoi(optarg);
48 nr_pages = atoi(optarg);
57 cmd = GUP_LONGTERM_BENCHMARK;
69 flags &= ~MAP_PRIVATE;
80 filed = open(file, O_RDWR|O_CREAT);
86 gup.nr_pages_per_call = nr_pages;
89 fd = open("/sys/kernel/debug/gup_benchmark", O_RDWR);
91 perror("open"), exit(1);
93 p = mmap(NULL, size, PROT_READ | PROT_WRITE, flags, filed, 0);
95 perror("mmap"), exit(1);
96 gup.addr = (unsigned long)p;
99 madvise(p, size, MADV_HUGEPAGE);
101 madvise(p, size, MADV_NOHUGEPAGE);
103 for (; (unsigned long)p < gup.addr + size; p += PAGE_SIZE)
106 for (i = 0; i < repeats; i++) {
108 if (ioctl(fd, cmd, &gup))
109 perror("ioctl"), exit(1);
111 printf("Time: get:%lld put:%lld us", gup.get_delta_usec,
113 if (gup.size != size)
114 printf(", truncated (size: %lld)", gup.size);