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)
19 struct gup_benchmark
{
23 __u32 nr_pages_per_call
;
25 __u64 expansion
[10]; /* For future use */
28 int main(int argc
, char **argv
)
30 struct gup_benchmark gup
;
31 unsigned long size
= 128 * MB
;
32 int i
, fd
, opt
, nr_pages
= 1, thp
= -1, repeats
= 1, write
= 0;
35 while ((opt
= getopt(argc
, argv
, "m:r:n:tT")) != -1) {
38 size
= atoi(optarg
) * MB
;
41 repeats
= atoi(optarg
);
44 nr_pages
= atoi(optarg
);
60 gup
.nr_pages_per_call
= nr_pages
;
63 fd
= open("/sys/kernel/debug/gup_benchmark", O_RDWR
);
65 perror("open"), exit(1);
67 p
= mmap(NULL
, size
, PROT_READ
| PROT_WRITE
,
68 MAP_ANONYMOUS
| MAP_PRIVATE
, -1, 0);
70 perror("mmap"), exit(1);
71 gup
.addr
= (unsigned long)p
;
74 madvise(p
, size
, MADV_HUGEPAGE
);
76 madvise(p
, size
, MADV_NOHUGEPAGE
);
78 for (; (unsigned long)p
< gup
.addr
+ size
; p
+= PAGE_SIZE
)
81 for (i
= 0; i
< repeats
; i
++) {
83 if (ioctl(fd
, GUP_FAST_BENCHMARK
, &gup
))
84 perror("ioctl"), exit(1);
86 printf("Time: %lld us", gup
.delta_usec
);
88 printf(", truncated (size: %lld)", gup
.size
);