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
;
27 int main(int argc
, char **argv
)
29 struct gup_benchmark gup
;
30 unsigned long size
= 128 * MB
;
31 int i
, fd
, opt
, nr_pages
= 1, thp
= -1, repeats
= 1, write
= 0;
34 while ((opt
= getopt(argc
, argv
, "m:r:n:tT")) != -1) {
37 size
= atoi(optarg
) * MB
;
40 repeats
= atoi(optarg
);
43 nr_pages
= atoi(optarg
);
58 gup
.nr_pages_per_call
= nr_pages
;
61 fd
= open("/sys/kernel/debug/gup_benchmark", O_RDWR
);
63 perror("open"), exit(1);
65 p
= mmap(NULL
, size
, PROT_READ
| PROT_WRITE
,
66 MAP_ANONYMOUS
| MAP_PRIVATE
, -1, 0);
68 perror("mmap"), exit(1);
69 gup
.addr
= (unsigned long)p
;
72 madvise(p
, size
, MADV_HUGEPAGE
);
74 madvise(p
, size
, MADV_NOHUGEPAGE
);
76 for (; (unsigned long)p
< gup
.addr
+ size
; p
+= PAGE_SIZE
)
79 for (i
= 0; i
< repeats
; i
++) {
81 if (ioctl(fd
, GUP_FAST_BENCHMARK
, &gup
))
82 perror("ioctl"), exit(1);
84 printf("Time: %lld us", gup
.delta_usec
);
86 printf(", truncated (size: %lld)", gup
.size
);