Commit 439de0d7 authored by Peter Xu's avatar Peter Xu Committed by Linus Torvalds

userfaultfd: selftest: cleanup help messages

Firstly, the help in the comment region is obsolete, now we support
three parameters.  Since at it, change it and move it into the help
message of the program.

Also, the help messages dumped here and there is obsolete too.  Use a
single usage() helper.

Link: http://lkml.kernel.org/r/20180930074259.18229-2-peterx@redhat.comSigned-off-by: default avatarPeter Xu <peterx@redhat.com>
Acked-by: default avatarMike Rapoport <rppt@linux.vnet.ibm.com>
Cc: Shuah Khan <shuah@kernel.org>
Cc: Mike Kravetz <mike.kravetz@oracle.com>
Cc: Jerome Glisse <jglisse@redhat.com>
Cc: Zi Yan <zi.yan@cs.rutgers.edu>
Cc: "Kirill A . Shutemov" <kirill@shutemov.name>
Cc: Shaohua Li <shli@fb.com>
Cc: Andrea Arcangeli <aarcange@redhat.com>
Cc: "Dr . David Alan Gilbert" <dgilbert@redhat.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent f0ecf25a
...@@ -34,18 +34,6 @@ ...@@ -34,18 +34,6 @@
* per-CPU threads 1 by triggering userfaults inside * per-CPU threads 1 by triggering userfaults inside
* pthread_mutex_lock will also verify the atomicity of the memory * pthread_mutex_lock will also verify the atomicity of the memory
* transfer (UFFDIO_COPY). * transfer (UFFDIO_COPY).
*
* The program takes two parameters: the amounts of physical memory in
* megabytes (MiB) of the area and the number of bounces to execute.
*
* # 100MiB 99999 bounces
* ./userfaultfd 100 99999
*
* # 1GiB 99 bounces
* ./userfaultfd 1000 99
*
* # 10MiB-~6GiB 999 bounces, continue forever unless an error triggers
* while ./userfaultfd $[RANDOM % 6000 + 10] 999; do true; done
*/ */
#define _GNU_SOURCE #define _GNU_SOURCE
...@@ -115,6 +103,30 @@ pthread_attr_t attr; ...@@ -115,6 +103,30 @@ pthread_attr_t attr;
~(unsigned long)(sizeof(unsigned long long) \ ~(unsigned long)(sizeof(unsigned long long) \
- 1))) - 1)))
const char *examples =
"# Run anonymous memory test on 100MiB region with 99999 bounces:\n"
"./userfaultfd anon 100 99999\n\n"
"# Run share memory test on 1GiB region with 99 bounces:\n"
"./userfaultfd shmem 1000 99\n\n"
"# Run hugetlb memory test on 256MiB region with 50 bounces (using /dev/hugepages/hugefile):\n"
"./userfaultfd hugetlb 256 50 /dev/hugepages/hugefile\n\n"
"# Run the same hugetlb test but using shmem:\n"
"./userfaultfd hugetlb_shared 256 50 /dev/hugepages/hugefile\n\n"
"# 10MiB-~6GiB 999 bounces anonymous test, "
"continue forever unless an error triggers\n"
"while ./userfaultfd anon $[RANDOM % 6000 + 10] 999; do true; done\n\n";
static void usage(void)
{
fprintf(stderr, "\nUsage: ./userfaultfd <test type> <MiB> <bounces> "
"[hugetlbfs_file]\n\n");
fprintf(stderr, "Supported <test type>: anon, hugetlb, "
"hugetlb_shared, shmem\n\n");
fprintf(stderr, "Examples:\n\n");
fprintf(stderr, examples);
exit(1);
}
static int anon_release_pages(char *rel_area) static int anon_release_pages(char *rel_area)
{ {
int ret = 0; int ret = 0;
...@@ -1272,8 +1284,7 @@ static void sigalrm(int sig) ...@@ -1272,8 +1284,7 @@ static void sigalrm(int sig)
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
if (argc < 4) if (argc < 4)
fprintf(stderr, "Usage: <test type> <MiB> <bounces> [hugetlbfs_file]\n"), usage();
exit(1);
if (signal(SIGALRM, sigalrm) == SIG_ERR) if (signal(SIGALRM, sigalrm) == SIG_ERR)
fprintf(stderr, "failed to arm SIGALRM"), exit(1); fprintf(stderr, "failed to arm SIGALRM"), exit(1);
...@@ -1286,20 +1297,19 @@ int main(int argc, char **argv) ...@@ -1286,20 +1297,19 @@ int main(int argc, char **argv)
nr_cpus; nr_cpus;
if (!nr_pages_per_cpu) { if (!nr_pages_per_cpu) {
fprintf(stderr, "invalid MiB\n"); fprintf(stderr, "invalid MiB\n");
fprintf(stderr, "Usage: <MiB> <bounces>\n"), exit(1); usage();
} }
bounces = atoi(argv[3]); bounces = atoi(argv[3]);
if (bounces <= 0) { if (bounces <= 0) {
fprintf(stderr, "invalid bounces\n"); fprintf(stderr, "invalid bounces\n");
fprintf(stderr, "Usage: <MiB> <bounces>\n"), exit(1); usage();
} }
nr_pages = nr_pages_per_cpu * nr_cpus; nr_pages = nr_pages_per_cpu * nr_cpus;
if (test_type == TEST_HUGETLB) { if (test_type == TEST_HUGETLB) {
if (argc < 5) if (argc < 5)
fprintf(stderr, "Usage: hugetlb <MiB> <bounces> <hugetlbfs_file>\n"), usage();
exit(1);
huge_fd = open(argv[4], O_CREAT | O_RDWR, 0755); huge_fd = open(argv[4], O_CREAT | O_RDWR, 0755);
if (huge_fd < 0) { if (huge_fd < 0) {
fprintf(stderr, "Open of %s failed", argv[3]); fprintf(stderr, "Open of %s failed", argv[3]);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment