From patchwork Thu May 6 23:25:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Xu X-Patchwork-Id: 12243603 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id ADEBBC433B4 for ; Thu, 6 May 2021 23:25:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 47C8661289 for ; Thu, 6 May 2021 23:25:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 47C8661289 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D9E166B0071; Thu, 6 May 2021 19:25:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D745E6B0072; Thu, 6 May 2021 19:25:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BC8B06B0073; Thu, 6 May 2021 19:25:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0070.hostedemail.com [216.40.44.70]) by kanga.kvack.org (Postfix) with ESMTP id 9ECE96B0071 for ; Thu, 6 May 2021 19:25:45 -0400 (EDT) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 51692181AEF2A for ; Thu, 6 May 2021 23:25:45 +0000 (UTC) X-FDA: 78112390650.02.61E085A Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by imf25.hostedemail.com (Postfix) with ESMTP id DA1976000104 for ; Thu, 6 May 2021 23:25:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1620343544; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=T2/Kp/6DMcvb66SGLUrQ0litwe4gG/CMDxNGXzk5jHI=; b=agWYeuKAVb2tjpUbbK8YNJ+PPo84OIW0ts8sEui9CGy1wrv4kWEb3kUwQQaHI49rq0hTw2 chhTfyPKSQIwu4CT0yDUAHtHgEYWX/09KpqtXeip1/XtSRkzK452Vu/2tPLhnmcXUTcexK j95Vht4vYYoRwkFFTCbwTPL+JPX/LZE= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-21-R9EJSJlEMPida8MZHQG0cw-1; Thu, 06 May 2021 19:25:42 -0400 X-MC-Unique: R9EJSJlEMPida8MZHQG0cw-1 Received: by mail-qt1-f200.google.com with SMTP id h4-20020ac858440000b029019d657b9f21so4575176qth.9 for ; Thu, 06 May 2021 16:25:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=T2/Kp/6DMcvb66SGLUrQ0litwe4gG/CMDxNGXzk5jHI=; b=cbrbrd+ynkn9yXYbBWe+uZ1mJi0Jsl7qr5KNvPxLYtJha9r7SnjPVt5UvtamLvwefG y0opVkQ8G9p7O3LeIrUQohTcLs4hV2JLysMzNzGM/FffsP6gXk9nZSmh68Hq90as4Ps4 6XdrIYgSJfr41jY5eKsxV5GHJHOt/LplmS+zkAxz1HBq9cXX7mIlfN+CTa8lSg0Tlops lUCdDVm/DL2d2l0vHA1031W6nIooJPzp9aYzREcPmJPiPOVp9JMMCxwxHGLAAHHKBLyP 5OC8ykxXRIYaE0DW4TDgDFQBgFNXkU+RLspOmAy89YhY9mb2NOGZ5+AjYjouL3f3j93l /kow== X-Gm-Message-State: AOAM530gyPqLXg0jIW8Xo+j7sT989YaXK4XSoP2B4A/UgjhQbiCbgpkZ rtiC2KwueCC9XrB4LemLhg47SBCfhbCDKtYrEz//lLzYVHKnC3rAZ95uQnMtI3gGnc/K8vMBOxR I9ShQtimQKJay8rg+bgkzP4wDCIXweNH51ykYGbQ7AjAiz2g4TTVOtOFkNUrQ X-Received: by 2002:ac8:5fd4:: with SMTP id k20mr6521819qta.239.1620343541695; Thu, 06 May 2021 16:25:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwiu2OYXRhtEUQX7rvGo4YfZRmLbpxFTcAg2tSwrt6j14FGtqU73BnoVhIbOEEpZWoT1F1fFQ== X-Received: by 2002:ac8:5fd4:: with SMTP id k20mr6521788qta.239.1620343541343; Thu, 06 May 2021 16:25:41 -0700 (PDT) Received: from t490s.redhat.com (bras-base-toroon474qw-grc-72-184-145-4-219.dsl.bell.ca. [184.145.4.219]) by smtp.gmail.com with ESMTPSA id q13sm1605026qkn.10.2021.05.06.16.25.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 May 2021 16:25:40 -0700 (PDT) From: Peter Xu To: linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: Hugh Dickins , peterx@redhat.com, John Hubbard , Jan Kara , Kirill Shutemov , Jason Gunthorpe , Andrew Morton , Kirill Tkhai , Michal Hocko , Oleg Nesterov , Jann Horn , Linus Torvalds , Matthew Wilcox , Andrea Arcangeli Subject: [PATCH 1/3] mm/gup_benchmark: Support threading Date: Thu, 6 May 2021 19:25:35 -0400 Message-Id: <20210506232537.165788-2-peterx@redhat.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210506232537.165788-1-peterx@redhat.com> References: <20210506232537.165788-1-peterx@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=agWYeuKA; dmarc=pass (policy=none) header.from=redhat.com; spf=none (imf25.hostedemail.com: domain of peterx@redhat.com has no SPF policy when checking 216.205.24.124) smtp.mailfrom=peterx@redhat.com X-Rspamd-Server: rspam03 X-Stat-Signature: jc5ajdjrk9wh1gh3iu5g8n1gunparzpi X-Rspamd-Queue-Id: DA1976000104 Received-SPF: none (redhat.com>: No applicable sender policy available) receiver=imf25; identity=mailfrom; envelope-from=""; helo=us-smtp-delivery-124.mimecast.com; client-ip=216.205.24.124 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1620343537-401620 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: Add a new parameter "-j N" to support concurrent gup test. Signed-off-by: Peter Xu Reviewed-by: John Hubbard --- tools/testing/selftests/vm/gup_test.c | 94 ++++++++++++++++++--------- 1 file changed, 63 insertions(+), 31 deletions(-) diff --git a/tools/testing/selftests/vm/gup_test.c b/tools/testing/selftests/vm/gup_test.c index 1e662d59c502a..3f0fcc697c3fc 100644 --- a/tools/testing/selftests/vm/gup_test.c +++ b/tools/testing/selftests/vm/gup_test.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "../../../../mm/gup_test.h" #define MB (1UL << 20) @@ -15,6 +16,12 @@ #define FOLL_WRITE 0x01 /* check pte is writable */ #define FOLL_TOUCH 0x02 /* mark page accessed */ +static unsigned long cmd = GUP_FAST_BENCHMARK; +static int gup_fd, repeats = 1; +static unsigned long size = 128 * MB; +/* Serialize prints */ +static pthread_mutex_t print_mutex = PTHREAD_MUTEX_INITIALIZER; + static char *cmd_to_str(unsigned long cmd) { switch (cmd) { @@ -34,17 +41,55 @@ static char *cmd_to_str(unsigned long cmd) return "Unknown command"; } +void *gup_thread(void *data) +{ + struct gup_test gup = *(struct gup_test *)data; + int i; + + /* Only report timing information on the *_BENCHMARK commands: */ + if ((cmd == PIN_FAST_BENCHMARK) || (cmd == GUP_FAST_BENCHMARK) || + (cmd == PIN_LONGTERM_BENCHMARK)) { + for (i = 0; i < repeats; i++) { + gup.size = size; + if (ioctl(gup_fd, cmd, &gup)) + perror("ioctl"), exit(1); + + pthread_mutex_lock(&print_mutex); + printf("%s: Time: get:%lld put:%lld us", + cmd_to_str(cmd), gup.get_delta_usec, + gup.put_delta_usec); + if (gup.size != size) + printf(", truncated (size: %lld)", gup.size); + printf("\n"); + pthread_mutex_unlock(&print_mutex); + } + } else { + gup.size = size; + if (ioctl(gup_fd, cmd, &gup)) { + perror("ioctl"); + exit(1); + } + + pthread_mutex_lock(&print_mutex); + printf("%s: done\n", cmd_to_str(cmd)); + if (gup.size != size) + printf("Truncated (size: %lld)\n", gup.size); + pthread_mutex_unlock(&print_mutex); + } + + return NULL; +} + int main(int argc, char **argv) { struct gup_test gup = { 0 }; - unsigned long size = 128 * MB; - int i, fd, filed, opt, nr_pages = 1, thp = -1, repeats = 1, write = 1; - unsigned long cmd = GUP_FAST_BENCHMARK; + int filed, i, opt, nr_pages = 1, thp = -1, write = 1, threads = 1; int flags = MAP_PRIVATE, touch = 0; char *file = "/dev/zero"; + pthread_t *tid; char *p; - while ((opt = getopt(argc, argv, "m:r:n:F:f:abctTLUuwWSHpz")) != -1) { + while ((opt = getopt(argc, argv, "m:r:n:F:f:abcj:tTLUuwWSHpz")) != -1) { switch (opt) { case 'a': cmd = PIN_FAST_BENCHMARK; @@ -74,6 +119,9 @@ int main(int argc, char **argv) /* strtol, so you can pass flags in hex form */ gup.gup_flags = strtol(optarg, 0, 0); break; + case 'j': + threads = atoi(optarg); + break; case 'm': size = atoi(optarg) * MB; break; @@ -154,8 +202,8 @@ int main(int argc, char **argv) if (write) gup.gup_flags |= FOLL_WRITE; - fd = open("/sys/kernel/debug/gup_test", O_RDWR); - if (fd == -1) { + gup_fd = open("/sys/kernel/debug/gup_test", O_RDWR); + if (gup_fd == -1) { perror("open"); exit(1); } @@ -185,32 +233,16 @@ int main(int argc, char **argv) p[0] = 0; } - /* Only report timing information on the *_BENCHMARK commands: */ - if ((cmd == PIN_FAST_BENCHMARK) || (cmd == GUP_FAST_BENCHMARK) || - (cmd == PIN_LONGTERM_BENCHMARK)) { - for (i = 0; i < repeats; i++) { - gup.size = size; - if (ioctl(fd, cmd, &gup)) - perror("ioctl"), exit(1); - - printf("%s: Time: get:%lld put:%lld us", - cmd_to_str(cmd), gup.get_delta_usec, - gup.put_delta_usec); - if (gup.size != size) - printf(", truncated (size: %lld)", gup.size); - printf("\n"); - } - } else { - gup.size = size; - if (ioctl(fd, cmd, &gup)) { - perror("ioctl"); - exit(1); - } - - printf("%s: done\n", cmd_to_str(cmd)); - if (gup.size != size) - printf("Truncated (size: %lld)\n", gup.size); + tid = malloc(sizeof(pthread_t) * threads); + if (!tid) { + perror("malloc()"); + exit(1); } + for (i = 0; i < threads; i++) + pthread_create(&tid[i], NULL, gup_thread, &gup); + for (i = 0; i < threads; i++) + pthread_join(tid[i], NULL); + free(tid); return 0; }