From patchwork Sun Sep 30 07:42:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 10621177 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0582814BD for ; Sun, 30 Sep 2018 07:43:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EDD4B295D5 for ; Sun, 30 Sep 2018 07:43:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E179F295DE; Sun, 30 Sep 2018 07:43:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 01E3A295DD for ; Sun, 30 Sep 2018 07:43:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DCA6A8E0003; Sun, 30 Sep 2018 03:43:13 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id D7A698E0001; Sun, 30 Sep 2018 03:43:13 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C6AAB8E0003; Sun, 30 Sep 2018 03:43:13 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by kanga.kvack.org (Postfix) with ESMTP id 9E8688E0001 for ; Sun, 30 Sep 2018 03:43:13 -0400 (EDT) Received: by mail-qt1-f200.google.com with SMTP id l22-v6so10591072qtr.3 for ; Sun, 30 Sep 2018 00:43:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:from:to:cc :subject:date:message-id:in-reply-to:references; bh=VGugSaH/p+7KRxdn9p/o8GvL8kFfpigjCC8IwUdpNAs=; b=abcmbTe4B9JOqtJNdKnqwBb6hFZM++mhaax0C4R+aiuxI87OI3ifIClqV60BsV6voa 7GMboRIgAXX0Abl+Fvhc1d/lqFH7drkMGZIN+aS/sXF3AKg/hPavRTUsT2tZrTCN3UH4 BwIZ1wkHHpvLH3sJsZM1mtZ1HeO6gBdu0iYbbVx/sAs8QEjCa9HFSY+kQVQQzsE1j+CJ ScW/NDsC5wIh5YOQXzvBqng3PPMl5tXgzJ5G38gsbiTdb/sFjMrAGUBca190CfKa59qI 00iBixl0/5arXrbEnACrobuwUhWN2mo8zN6gcqNfCl44vMefRHnmcjHJRTyWpGNL3Wmb BZCA== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of peterx@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com X-Gm-Message-State: ABuFfoin3zAoLAdF71pdvRqYsW8mwRKkP0Nm8GuSOu+QbUGCWT30AjgG kUUSfDjuPWPbfriv5u8ZX8/7IXHqbaZ8ChSctGpSFm/r7+mKzVDNfBAyyEJbuemSMmBwWSc1uRU AMaeJzp6m5AjbXCcX1wEgQxGV/IdhN83ovQcUUnuriPYGfu7HCPZdC5tjS1VSm87fVQ== X-Received: by 2002:aed:35cd:: with SMTP id d13-v6mr4669537qte.212.1538293393366; Sun, 30 Sep 2018 00:43:13 -0700 (PDT) X-Google-Smtp-Source: ACcGV61gjEI9kK19mH2T97FnZ873CNfTHacJbCDQ9tsRjjjVrvCI/6aDFvBSxeXnl3x4VnG/V3ad X-Received: by 2002:aed:35cd:: with SMTP id d13-v6mr4669524qte.212.1538293392828; Sun, 30 Sep 2018 00:43:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538293392; cv=none; d=google.com; s=arc-20160816; b=TiZQsKGzWGgHAyl9rLUCQZnWzHytgb0xuUTDgKmxGXy4Jeikm9gsvqKcjQ1qDXqMMr ZmuxzUiW/SGktzqemrijv6rBy/rtrqsCoqUS0sR+JEFuv5NqeV8o+E/U/9/+0YaocTQr TELRAJx0BSSpOwWtEeEZjwwPCk1QSC9sUIzW9wKhWNXxaCHJ6xs7kSAJMeXSfTzURrOi 8iV9XjWRU+07ZxDgrOsOUfu54wzPohhg74GdO4rSMX3bJOK+wMWP2coWecmOxkqwWE76 Eyw6gfL4/608Xfit6Z6aL9KqdaG+ZcbPvMt//cMlUM3moJGk+jcO/A5Vh0XO4Xclb/nX W7kw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from; bh=VGugSaH/p+7KRxdn9p/o8GvL8kFfpigjCC8IwUdpNAs=; b=y8DnLrZ0IP6hg36gWGOrtIPwKQO9N8CW6yvaBeMxhgCvP/eRwlchKe0ioh+cQgWdQe kD8yKmGl2w0DxKbQfu6ssSWejQ9ooumWxbMCpdUFEGRYZN9btCLvKXeCNyZZdFxqBm5E rsLInajSwEnYnzDGUT6mE9cMXE59h9G5ZqzPMxNZSctxti/MuifSis5aqJvcpT0s7A3y zFeRLKAUAGtoFRzJBppRcLF1gfnuBLKW55EiexCOBGEclwYKve+GE7UalGuEp+0sqwwT czr14Dqhh/LNl3GM281O0djvtGQsIYZxOSe/4GyHWY+V05qd6h3UV19ruAF6ZgtkLqp9 Z5oA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of peterx@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from mx1.redhat.com (mx1.redhat.com. [209.132.183.28]) by mx.google.com with ESMTPS id d2-v6si2364505qvn.206.2018.09.30.00.43.12 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 30 Sep 2018 00:43:12 -0700 (PDT) Received-SPF: pass (google.com: domain of peterx@redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; Authentication-Results: mx.google.com; spf=pass (google.com: domain of peterx@redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=peterx@redhat.com; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F2B734E90D; Sun, 30 Sep 2018 07:43:11 +0000 (UTC) Received: from xz-x1.nay.redhat.com (dhcp-14-128.nay.redhat.com [10.66.14.128]) by smtp.corp.redhat.com (Postfix) with ESMTP id AAF8A60164; Sun, 30 Sep 2018 07:43:07 +0000 (UTC) From: Peter Xu To: linux-kernel@vger.kernel.org Cc: Shuah Khan , Mike Kravetz , Mike Rapoport , Jerome Glisse , peterx@redhat.com, linux-mm@kvack.org, Zi Yan , "Kirill A . Shutemov" , linux-kselftest@vger.kernel.org, Shaohua Li , Andrea Arcangeli , "Dr . David Alan Gilbert" , Andrew Morton Subject: [PATCH v2 1/3] userfaultfd: selftest: cleanup help messages Date: Sun, 30 Sep 2018 15:42:57 +0800 Message-Id: <20180930074259.18229-2-peterx@redhat.com> In-Reply-To: <20180930074259.18229-1-peterx@redhat.com> References: <20180930074259.18229-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Sun, 30 Sep 2018 07:43:12 +0000 (UTC) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP 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. Acked-by: Mike Rapoport Signed-off-by: Peter Xu --- tools/testing/selftests/vm/userfaultfd.c | 46 ++++++++++++++---------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c index 7b8171e3128a..5ff3a4f9173e 100644 --- a/tools/testing/selftests/vm/userfaultfd.c +++ b/tools/testing/selftests/vm/userfaultfd.c @@ -34,18 +34,6 @@ * per-CPU threads 1 by triggering userfaults inside * pthread_mutex_lock will also verify the atomicity of the memory * 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 @@ -115,6 +103,30 @@ pthread_attr_t attr; ~(unsigned long)(sizeof(unsigned long long) \ - 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 " + "[hugetlbfs_file]\n\n"); + fprintf(stderr, "Supported : 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) { int ret = 0; @@ -1272,8 +1284,7 @@ static void sigalrm(int sig) int main(int argc, char **argv) { if (argc < 4) - fprintf(stderr, "Usage: [hugetlbfs_file]\n"), - exit(1); + usage(); if (signal(SIGALRM, sigalrm) == SIG_ERR) fprintf(stderr, "failed to arm SIGALRM"), exit(1); @@ -1286,20 +1297,19 @@ int main(int argc, char **argv) nr_cpus; if (!nr_pages_per_cpu) { fprintf(stderr, "invalid MiB\n"); - fprintf(stderr, "Usage: \n"), exit(1); + usage(); } bounces = atoi(argv[3]); if (bounces <= 0) { fprintf(stderr, "invalid bounces\n"); - fprintf(stderr, "Usage: \n"), exit(1); + usage(); } nr_pages = nr_pages_per_cpu * nr_cpus; if (test_type == TEST_HUGETLB) { if (argc < 5) - fprintf(stderr, "Usage: hugetlb \n"), - exit(1); + usage(); huge_fd = open(argv[4], O_CREAT | O_RDWR, 0755); if (huge_fd < 0) { fprintf(stderr, "Open of %s failed", argv[3]);