Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1682013imm; Sat, 29 Sep 2018 01:43:49 -0700 (PDT) X-Google-Smtp-Source: ACcGV61XfX0pR3q1qIRr4e8mOlju5xpWhFra16Dq3retVRNXRuWcHV03sojiQ+6NMDyFAsqTgBfG X-Received: by 2002:a62:aa17:: with SMTP id e23-v6mr2186028pff.211.1538210629138; Sat, 29 Sep 2018 01:43:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538210629; cv=none; d=google.com; s=arc-20160816; b=KdpaYv3Di9J7CYVnfUbtude0TcilLetGb1jI+DsJZE60s8CyG6i0KUGV1jRECSiKap XgBySWtJI9mt4jbs/oVBXPo6GQnDU1W3/hTLVBetYyELfH59WncwipZuTlneCfMu1+DZ XHxNDpieclTvmCoY/dQAKYXPvU6Y6Ss/Aabu3LZd3afTFtcSL0YL/u5G+wv6w/0/8B7F T8NzaqAKayYwmpOYmAmNkVLZ+KdjAzmGHVj8KZhGE2aWjMpsevETpdmmMMgGuNbMiN6O wdAV0wtrRjtHF1Ry9TuIA+43/+4lhN3opnR302SVgj/ma9ynwSNzh+ebbXstYObfkhGh +8zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=jr2FkhdpO4Zy0gr3lTuVC3vLaaL0bHiEHlC2dEEztIs=; b=0pTbDQBOPgMNI+nI4dwcUGt0o9zYrVrQdGGN1rANJOdEXq6z/wNe0jM0Rp9Kjh9eey qeCVzZnKtZoiKWX0qnyQiDJhrfXnrujmpqPjnsMekG/go3WuurrZCfD1KnZVyWwq9ita +7lWxhUDv1S7jvOUjfriqyK1YTtb+MwVL6X6wPmr3aQzT/4UNG/ty9lWFdB0i9jTKyGu bkfkizCq31dzB7eanxem4rxPssP13HE8hOj9jYRnUfR/vPiKGWmXXY1CwWha5AWw2Dqc f3y+8RmFRE7/fO7icGRT+pxICgQXuTy/xvLuq9Fyp2rJFQYTMc8RsuKTuZ5AotAvJ2V0 LhPQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 37-v6si6958241plq.316.2018.09.29.01.43.34; Sat, 29 Sep 2018 01:43:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727802AbeI2PLA (ORCPT + 99 others); Sat, 29 Sep 2018 11:11:00 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37064 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727620AbeI2PLA (ORCPT ); Sat, 29 Sep 2018 11:11:00 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7B9D4308338E; Sat, 29 Sep 2018 08:43:24 +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 299B3106A790; Sat, 29 Sep 2018 08:43:19 +0000 (UTC) From: Peter Xu To: linux-kernel@vger.kernel.org Cc: Shuah Khan , Jerome Glisse , Mike Rapoport , Mike Kravetz , 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 1/3] userfaultfd: selftest: cleanup help messages Date: Sat, 29 Sep 2018 16:43:09 +0800 Message-Id: <20180929084311.15600-2-peterx@redhat.com> In-Reply-To: <20180929084311.15600-1-peterx@redhat.com> References: <20180929084311.15600-1-peterx@redhat.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Sat, 29 Sep 2018 08:43:24 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: Peter Xu --- tools/testing/selftests/vm/userfaultfd.c | 44 ++++++++++++++---------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/tools/testing/selftests/vm/userfaultfd.c b/tools/testing/selftests/vm/userfaultfd.c index 7b8171e3128a..2a84adaf8cf8 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,28 @@ pthread_attr_t attr; ~(unsigned long)(sizeof(unsigned long long) \ - 1))) +const char *examples = + "# 100MiB 99999 bounces\n" + "./userfaultfd anon 100 99999\n" + "\n" + "# 1GiB 99 bounces\n" + "./userfaultfd anon 1000 99\n" + "\n" + "# 10MiB-~6GiB 999 bounces, 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 +1282,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 +1295,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]); -- 2.17.1