Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp8631378rwi; Tue, 25 Oct 2022 08:59:15 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7HC9FZIXkdbHaxOx8Had4wsYrpiQy5zsQIujibdeL4WQpv2s6+UY7TGhKwq4U6A6657WWf X-Received: by 2002:a05:6402:f0e:b0:461:aaa3:a11c with SMTP id i14-20020a0564020f0e00b00461aaa3a11cmr12455637eda.53.1666713555421; Tue, 25 Oct 2022 08:59:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666713555; cv=none; d=google.com; s=arc-20160816; b=f62u2zN/fVvMRJ+25coqT7ip4EadfL1PQvaErw4z/MuYthpUUbUIHDTDs5gfXlInso UQfI+JucGUFmfod7H7Yj/FORFQ0g5J+5WSHR18msymCtny3TyX/gs0uvv7KrK4Q6qg7l k4eUwWxzNtvUwvVT5frgFP+hVbdFPeSD1kaZuef4DI/F473e43N1DcZucsvyL4O6tt1Q yMFAg1YB2F5XiZZpQLjOQjMtO4jBXqXydI5OtMM50liyQiW8IfQDL7aYviWiv4Hkzn5f upfJI4jYwOIXQUDO/0j+xMyeMxd5wCTwELlBaOd4ypqoDc0NG52LGgZlsYziB6ytwIHW OPcg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=23SsZSw/1NrmKAtnYWodEwVyGyRFfxdjumQj+Wu9VNY=; b=y0FrCB/1ecAm2+LXqSfSmOtoaCmMXA0zQ+op/1AL39z7BNIufuP6NoNFXQwWsRmA1x glfSQcj9P+ElQUqf4g8731kjPwSrj+9ulRnJPwlLN8pEc/siNMiUutRd8Wh2KFsnRFkc 3A1PWcatInxGtAcVpAXu2LBFfN8XpI73fLETJOtN8Fc8ovWeVDrueu6u3m7ph1jFAClI +2ymez7T5n26gJsvcMxSt/b3zlYyab1/o3zwluiC2lq7RIinv/VI11Hl/Go+ZK1sFBye Zg/HJzimtcHYQNfYSlSoKFWcpvv+7V2jPc9QCnr45SxJLJSy+nNwF9fWfuyovO957Don 4TiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ogpTgLJ4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qb31-20020a1709077e9f00b0078dd12d0a9fsi3509651ejc.548.2022.10.25.08.58.48; Tue, 25 Oct 2022 08:59:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ogpTgLJ4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232875AbiJYPh1 (ORCPT + 99 others); Tue, 25 Oct 2022 11:37:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231379AbiJYPhY (ORCPT ); Tue, 25 Oct 2022 11:37:24 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A0CC4D8EF5 for ; Tue, 25 Oct 2022 08:37:22 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id l14so14517377wrw.2 for ; Tue, 25 Oct 2022 08:37:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=23SsZSw/1NrmKAtnYWodEwVyGyRFfxdjumQj+Wu9VNY=; b=ogpTgLJ4JQp4OHIInETJFxtlRExrjwqfExrmFhu1LaywnFQTxRzobA3DaKg8Zh3o0f HJ6k60NPtz7jQcbLvmJ68jGcrWJ0EhR7HUcC6duCcz4paT3ipvYtme4Q00Mes3KHcFAr IpFTi2O9Lh6hOLMNp2LNZn/nDXxcjvVtrn+Qjek1Aj6ey9bz1ufN3G6wHC3Aq8w2APDc yNIBDBSn7PEB5rlxuoWNXem2VIS3PyNFFwATFOJoJWko9dqIcaZEOdhdX/zIMIcBamch A+0aTmmdT0IyiwitjDU91iL8w/7EnLerSKQI1ND0L4JLxNkSegZtBNz2m8y+JFHgHTSA pfsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=23SsZSw/1NrmKAtnYWodEwVyGyRFfxdjumQj+Wu9VNY=; b=CRTcx/APgu8mXNL5RqJn/DgGtm7VALYtO6i8Tn/ZQuDI9qNzgd0g/oE1IgXsRyo/8Z evc+71lRxi1oQt5jcUHlMJNEUvveweVfsQHP1xFAGhXO0KgNWYiPXxHOCF7UF3sXy8Sn 05sOTqN7rF8g1/C7QKTjpj1kUz6z2x3sog1jaRfjlj7p7/L1gAl/Bfw8+3zOvqV4MfAy xRiMoRzzl2bEogX7YGfVXgqED57YTxu+gCIIdhLJ26XA08QqT6D28N7CxfKBN8Zbn+N6 roVSerzsm6jplzO1j2GkdI/HicnO5Ot0FWStsK2exXCwkkaiKSpbXGBrvOEbmtTHmrls T94g== X-Gm-Message-State: ACrzQf1+Zp/U0Mh85s6HSVJhSUurQJvGoTd7/c7wp5APpRhDquP4QU6v qEgsBkdwfk6p2JZLyySEWQSmtQ/h6fXxvj/ApW7oPhTEjPc= X-Received: by 2002:a5d:47a9:0:b0:22e:3beb:dc3a with SMTP id 9-20020a5d47a9000000b0022e3bebdc3amr26057264wrb.654.1666712241029; Tue, 25 Oct 2022 08:37:21 -0700 (PDT) MIME-Version: 1.0 References: <1665042130-15786-1-git-send-email-yangtiezhu@loongson.cn> <1665042130-15786-3-git-send-email-yangtiezhu@loongson.cn> In-Reply-To: <1665042130-15786-3-git-send-email-yangtiezhu@loongson.cn> From: Ian Rogers Date: Tue, 25 Oct 2022 08:37:09 -0700 Message-ID: Subject: Re: [PATCH v3 2/3] perf bench syscall: Add close syscall benchmark To: Tiezhu Yang Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Oct 6, 2022 at 12:42 AM Tiezhu Yang wrote: > > This commit adds a simple close syscall benchmark, more syscall > benchmarks can be added in the future. > > Here are the test results: > > [loongson@linux perf]$ ./perf bench syscall > > # List of available benchmarks for collection 'syscall': > > basic: Benchmark for basic getppid(2) calls > close: Benchmark for close(2) calls > all: Run all syscall benchmarks > > [loongson@linux perf]$ ./perf bench syscall basic > # Running 'syscall/basic' benchmark: > # Executed 10000000 getppid() calls > Total time: 1.956 [sec] > > 0.195687 usecs/op > 5110201 ops/sec > [loongson@linux perf]$ ./perf bench syscall close > # Running 'syscall/close' benchmark: > # Executed 10000000 close() calls > Total time: 6.302 [sec] > > 0.630297 usecs/op > 1586553 ops/sec > [loongson@linux perf]$ ./perf bench syscall all > # Running syscall/basic benchmark... > # Executed 10000000 getppid() calls > Total time: 1.956 [sec] > > 0.195686 usecs/op > 5110232 ops/sec > > # Running syscall/close benchmark... > # Executed 10000000 close() calls > Total time: 6.302 [sec] > > 0.630271 usecs/op > 1586619 ops/sec > > Signed-off-by: Tiezhu Yang > --- > tools/arch/x86/include/uapi/asm/unistd_32.h | 3 +++ > tools/arch/x86/include/uapi/asm/unistd_64.h | 3 +++ > tools/perf/bench/bench.h | 1 + > tools/perf/bench/syscall.c | 11 +++++++++++ > tools/perf/builtin-bench.c | 1 + > 5 files changed, 19 insertions(+) > > diff --git a/tools/arch/x86/include/uapi/asm/unistd_32.h b/tools/arch/x86/include/uapi/asm/unistd_32.h > index 4a480a0..2f24b0eb 100644 > --- a/tools/arch/x86/include/uapi/asm/unistd_32.h > +++ b/tools/arch/x86/include/uapi/asm/unistd_32.h > @@ -2,6 +2,9 @@ > #ifndef __NR_perf_event_open > # define __NR_perf_event_open 336 > #endif > +#ifndef __NR_close > +# define __NR_close 6 > +#endif > #ifndef __NR_futex > # define __NR_futex 240 > #endif > diff --git a/tools/arch/x86/include/uapi/asm/unistd_64.h b/tools/arch/x86/include/uapi/asm/unistd_64.h > index 860257f..8eb32b2 100644 > --- a/tools/arch/x86/include/uapi/asm/unistd_64.h > +++ b/tools/arch/x86/include/uapi/asm/unistd_64.h > @@ -2,6 +2,9 @@ > #ifndef __NR_perf_event_open > # define __NR_perf_event_open 298 > #endif > +#ifndef __NR_close > +# define __NR_close 3 > +#endif > #ifndef __NR_futex > # define __NR_futex 202 > #endif > diff --git a/tools/perf/bench/bench.h b/tools/perf/bench/bench.h > index 6cefb43..916cd47 100644 > --- a/tools/perf/bench/bench.h > +++ b/tools/perf/bench/bench.h > @@ -34,6 +34,7 @@ int bench_numa(int argc, const char **argv); > int bench_sched_messaging(int argc, const char **argv); > int bench_sched_pipe(int argc, const char **argv); > int bench_syscall_basic(int argc, const char **argv); > +int bench_syscall_close(int argc, const char **argv); > int bench_mem_memcpy(int argc, const char **argv); > int bench_mem_memset(int argc, const char **argv); > int bench_mem_find_bit(int argc, const char **argv); > diff --git a/tools/perf/bench/syscall.c b/tools/perf/bench/syscall.c > index 746fd71..058394b 100644 > --- a/tools/perf/bench/syscall.c > +++ b/tools/perf/bench/syscall.c > @@ -46,6 +46,9 @@ static int bench_syscall_common(int argc, const char **argv, int syscall) > case __NR_getppid: > getppid(); > break; > + case __NR_close: > + close(dup(0)); Thanks for contributing! This benchmark will compute the cost of close and dup, naively dup could perform memory allocation and be slow. Perhaps a number of file descriptors could be made outside of the timed region? Thanks, Ian > + break; > default: > break; > } > @@ -58,6 +61,9 @@ static int bench_syscall_common(int argc, const char **argv, int syscall) > case __NR_getppid: > name = "getppid()"; > break; > + case __NR_close: > + name = "close()"; > + break; > default: > break; > } > @@ -100,3 +106,8 @@ int bench_syscall_basic(int argc, const char **argv) > { > return bench_syscall_common(argc, argv, __NR_getppid); > } > + > +int bench_syscall_close(int argc, const char **argv) > +{ > + return bench_syscall_common(argc, argv, __NR_close); > +} > diff --git a/tools/perf/builtin-bench.c b/tools/perf/builtin-bench.c > index 334ab89..b63c711 100644 > --- a/tools/perf/builtin-bench.c > +++ b/tools/perf/builtin-bench.c > @@ -52,6 +52,7 @@ static struct bench sched_benchmarks[] = { > > static struct bench syscall_benchmarks[] = { > { "basic", "Benchmark for basic getppid(2) calls", bench_syscall_basic }, > + { "close", "Benchmark for close(2) calls", bench_syscall_close }, > { "all", "Run all syscall benchmarks", NULL }, > { NULL, NULL, NULL }, > }; > -- > 2.1.0 >