]>
git.ipfire.org Git - thirdparty/kernel/linux.git/blob - tools/testing/selftests/vm/gup_benchmark.c
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
{
24 __u32 nr_pages_per_call
;
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
);
59 gup
.nr_pages_per_call
= nr_pages
;
62 fd
= open("/sys/kernel/debug/gup_benchmark", O_RDWR
);
64 perror("open"), exit(1);
66 p
= mmap(NULL
, size
, PROT_READ
| PROT_WRITE
,
67 MAP_ANONYMOUS
| MAP_PRIVATE
, -1, 0);
69 perror("mmap"), exit(1);
70 gup
.addr
= (unsigned long)p
;
73 madvise(p
, size
, MADV_HUGEPAGE
);
75 madvise(p
, size
, MADV_NOHUGEPAGE
);
77 for (; (unsigned long)p
< gup
.addr
+ size
; p
+= PAGE_SIZE
)
80 for (i
= 0; i
< repeats
; i
++) {
82 if (ioctl(fd
, GUP_FAST_BENCHMARK
, &gup
))
83 perror("ioctl"), exit(1);
85 printf("Time: get:%lld put:%lld us", gup
.get_delta_usec
,
88 printf(", truncated (size: %lld)", gup
.size
);