aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKeith Busch <keith.busch@intel.com>2018-10-26 18:10:02 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-10-26 19:38:15 -0400
commitaeb85ed4f41a8c0f5c4606d69f5da75e2348d984 (patch)
tree4f0bafc535530f7a5eb94605f394b085641e3a8a
parent319e0bec1aecb36c5ac6d23812af487ff2c8f47f (diff)
tools/testing/selftests/vm/gup_benchmark.c: allow user specified file
Allow a user to specify a file to map by adding a new option, '-f', providing a means to test various file backings. If not specified, the benchmark will use a private mapping of /dev/zero, which produces an anonymous mapping as before. [akpm@linux-foundation.org: avoid using comma operator] Link: http://lkml.kernel.org/r/20181010195605.10689-4-keith.busch@intel.com Signed-off-by: Keith Busch <keith.busch@intel.com> Reviewed-by: Andrew Morton <akpm@linux-foundation.org> Cc: Kirill Shutemov <kirill.shutemov@linux.intel.com> Cc: Dave Hansen <dave.hansen@intel.com> Cc: Dan Williams <dan.j.williams@intel.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--tools/testing/selftests/vm/gup_benchmark.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/tools/testing/selftests/vm/gup_benchmark.c b/tools/testing/selftests/vm/gup_benchmark.c
index b2082df8beb4..43a2d60e0e93 100644
--- a/tools/testing/selftests/vm/gup_benchmark.c
+++ b/tools/testing/selftests/vm/gup_benchmark.c
@@ -31,11 +31,12 @@ int main(int argc, char **argv)
31{ 31{
32 struct gup_benchmark gup; 32 struct gup_benchmark gup;
33 unsigned long size = 128 * MB; 33 unsigned long size = 128 * MB;
34 int i, fd, opt, nr_pages = 1, thp = -1, repeats = 1, write = 0; 34 int i, fd, filed, opt, nr_pages = 1, thp = -1, repeats = 1, write = 0;
35 int cmd = GUP_FAST_BENCHMARK; 35 int cmd = GUP_FAST_BENCHMARK;
36 char *file = "/dev/zero";
36 char *p; 37 char *p;
37 38
38 while ((opt = getopt(argc, argv, "m:r:n:tTLU")) != -1) { 39 while ((opt = getopt(argc, argv, "m:r:n:f:tTLU")) != -1) {
39 switch (opt) { 40 switch (opt) {
40 case 'm': 41 case 'm':
41 size = atoi(optarg) * MB; 42 size = atoi(optarg) * MB;
@@ -61,11 +62,20 @@ int main(int argc, char **argv)
61 case 'w': 62 case 'w':
62 write = 1; 63 write = 1;
63 break; 64 break;
65 case 'f':
66 file = optarg;
67 break;
64 default: 68 default:
65 return -1; 69 return -1;
66 } 70 }
67 } 71 }
68 72
73 filed = open(file, O_RDWR|O_CREAT);
74 if (filed < 0) {
75 perror("open");
76 exit(filed);
77 }
78
69 gup.nr_pages_per_call = nr_pages; 79 gup.nr_pages_per_call = nr_pages;
70 gup.flags = write; 80 gup.flags = write;
71 81
@@ -73,8 +83,7 @@ int main(int argc, char **argv)
73 if (fd == -1) 83 if (fd == -1)
74 perror("open"), exit(1); 84 perror("open"), exit(1);
75 85
76 p = mmap(NULL, size, PROT_READ | PROT_WRITE, 86 p = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_PRIVATE, filed, 0);
77 MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
78 if (p == MAP_FAILED) 87 if (p == MAP_FAILED)
79 perror("mmap"), exit(1); 88 perror("mmap"), exit(1);
80 gup.addr = (unsigned long)p; 89 gup.addr = (unsigned long)p;