Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp86869rwl; Fri, 24 Mar 2023 21:34:01 -0700 (PDT) X-Google-Smtp-Source: AKy350aLc8t7d7MOzZJ7ua+G5vdIcicrQRME6gyc0412iWwWo93tsfQA6I5VaYTgjFHE7CyZaPvi X-Received: by 2002:a17:903:11d1:b0:1a2:3135:51a0 with SMTP id q17-20020a17090311d100b001a2313551a0mr505721plh.46.1679718840978; Fri, 24 Mar 2023 21:34:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679718840; cv=none; d=google.com; s=arc-20160816; b=wRbg6pLn0kd0f1vYGBpglIZ2qy/BX5H9heQlZVgDfL3Maj4RIf8omFIO/dltiaOnMa 0H7JaqrBLItaDlJwpVpVm+k7uBmZOqbjW6UBAaulvFkP4tjc5ElpCLlOtpxLAKYYsQFX oVkB6hSu8KclFnzwTznhh3HrXgt9o5P3h1YoGsHLtxdJRQh/hVAh3peDfeodSKtmg3XR ZtmFRBfbywha6bryX6bnseTklrw34tb0e15OLE83Wx79nEHPzb1oYUNlmVsfFFBRw7XJ 5cY3+uMOA0jiLclWxModpwr4MrbL8Xb4dZqb/4ih6b+lRvz4FQ62wdTMBox44Qceu/5R xBQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=ojNqyCrOkusGH2LTlNDkhXKwhs2hf+TvWh6xLRV8Pk0=; b=cb8wNK3CKrX8pI+fo7tN2ZKgHHT4clNrkfBZU3SaX2wK+o0PLamBHgPv5DBvHmFQqn g/6OIX8wo/yQ9wTd8cDOlWOl8W5r217jecGu+atKAnywXFMvJMC3hbFRMwDAes0B2dxK 4Jov/F7ARBTGXGuOHfgScxY1/V23tHPTBFjjoAMiYVZysvU93u8WiVdRgIiEZENbBYAj gxcBuE2GE8+AmDtz2aUdkBxOLN76fpShp32HCEd6zCB0BVw0DgKp5pLMQYu6EHVKdfup am7we3QDXtST1eM4kU8DsJj1niY6KpEqL/7bMVOmRGJHabVJQIwjrGa6a80U+J7K4wA8 p+vA== ARC-Authentication-Results: i=1; mx.google.com; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o10-20020a170902e00a00b0019d19fb5606si21000520plo.551.2023.03.24.21.33.49; Fri, 24 Mar 2023 21:34:00 -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; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229505AbjCYEb7 convert rfc822-to-8bit (ORCPT + 99 others); Sat, 25 Mar 2023 00:31:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42960 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232034AbjCYEbq (ORCPT ); Sat, 25 Mar 2023 00:31:46 -0400 Received: from mail-io1-f45.google.com (mail-io1-f45.google.com [209.85.166.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BCED1815A; Fri, 24 Mar 2023 21:31:38 -0700 (PDT) Received: by mail-io1-f45.google.com with SMTP id bl9so1621648iob.8; Fri, 24 Mar 2023 21:31:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679718697; x=1682310697; h=content-transfer-encoding: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=QshTmLJTyi9qX5SkDwCDlbE2dc7E+l9twlijdylPf7o=; b=OnCYEvN1YI3GsOsk0XM62ikt1MBIBl6V8sEJQuUpvAkN7jpNiNwhxbn1TQW89y+VHh /BdrE2zZWD0ZC35xgaAnVwM5PVZdYbX9gUNk0FXuym2A2NxcKwHKaIApMQdJfiR4Vf7V ac+keFtxkN1lri9lDc62P5Ho1+njXsm2RPPVm6UM0lO3dOmvaRfMEOvqnrpGBqAIN5PQ y2VZdPmKlDG7lGlPC+I/U6UlkwUFmIT6ase0iR0Iky4pHPpIj7E9nBmstxFa8OLrdnPH wSoSFOT4pivMZ8QkM622OD7C9tOuQQROtax+HSgxGBVr6S89CYSTFSXDClvR9WDIyJH6 HHKw== X-Gm-Message-State: AO0yUKVZeFlDdQGlZqFdgYAqu5eh3seMAnIeJWNzjZf+Q6KMVmxpFrwS 3vcHC24U1akZLUgEYRbtxrlpb+DtWHUNgHHqnUM= X-Received: by 2002:a6b:6a14:0:b0:751:dcc3:3279 with SMTP id x20-20020a6b6a14000000b00751dcc33279mr3448370iog.14.1679718697147; Fri, 24 Mar 2023 21:31:37 -0700 (PDT) MIME-Version: 1.0 References: <1679381821-22736-1-git-send-email-yangtiezhu@loongson.cn> In-Reply-To: <1679381821-22736-1-git-send-email-yangtiezhu@loongson.cn> From: Namhyung Kim Date: Fri, 24 Mar 2023 21:31:25 -0700 Message-ID: Subject: Re: [PATCH] perf bench syscall: Add fork syscall benchmark To: Tiezhu Yang Cc: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Mark Rutland , Alexander Shishkin , Jiri Olsa , Ian Rogers , Adrian Hunter , linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org, loongson-kernel@lists.loongnix.cn Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=0.5 required=5.0 tests=FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no 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 Hello, On Mon, Mar 20, 2023 at 11:57 PM Tiezhu Yang wrote: > > This is a follow up patch for the execve bench which is actually > fork + execve, it makes sense to add the fork syscall benchmark > to compare the execve part precisely. > > Some archs have no __NR_fork definition which is used only as a > check condition to call test_fork(), let us just define it as -1 > to avoid build error. > > Suggested-by: Namhyung Kim > Signed-off-by: Tiezhu Yang Acked-by: Namhyung Kim Thanks, Namhyung > --- > tools/arch/x86/include/uapi/asm/unistd_32.h | 4 ++-- > tools/arch/x86/include/uapi/asm/unistd_64.h | 3 +++ > tools/perf/bench/bench.h | 1 + > tools/perf/bench/syscall.c | 35 +++++++++++++++++++++++++++++ > tools/perf/builtin-bench.c | 1 + > 5 files changed, 42 insertions(+), 2 deletions(-) > > diff --git a/tools/arch/x86/include/uapi/asm/unistd_32.h b/tools/arch/x86/include/uapi/asm/unistd_32.h > index 2712d5e..b8ddfc4 100644 > --- a/tools/arch/x86/include/uapi/asm/unistd_32.h > +++ b/tools/arch/x86/include/uapi/asm/unistd_32.h > @@ -1,6 +1,6 @@ > /* SPDX-License-Identifier: GPL-2.0 */ > -#ifndef __NR_execve > -#define __NR_execve 11 > +#ifndef __NR_fork > +#define __NR_fork 2 > #endif > #ifndef __NR_getppid > #define __NR_getppid 64 > diff --git a/tools/arch/x86/include/uapi/asm/unistd_64.h b/tools/arch/x86/include/uapi/asm/unistd_64.h > index a6f7fe8..f70d2cad 100644 > --- a/tools/arch/x86/include/uapi/asm/unistd_64.h > +++ b/tools/arch/x86/include/uapi/asm/unistd_64.h > @@ -1,4 +1,7 @@ > /* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef __NR_fork > +#define __NR_fork 57 > +#endif > #ifndef __NR_execve > #define __NR_execve 59 > #endif > diff --git a/tools/perf/bench/bench.h b/tools/perf/bench/bench.h > index e438931..edfc257 100644 > --- a/tools/perf/bench/bench.h > +++ b/tools/perf/bench/bench.h > @@ -23,6 +23,7 @@ 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_getpgid(int argc, const char **argv); > +int bench_syscall_fork(int argc, const char **argv); > int bench_syscall_execve(int argc, const char **argv); > int bench_mem_memcpy(int argc, const char **argv); > int bench_mem_memset(int argc, const char **argv); > diff --git a/tools/perf/bench/syscall.c b/tools/perf/bench/syscall.c > index fe79f7f..ea4dfc07 100644 > --- a/tools/perf/bench/syscall.c > +++ b/tools/perf/bench/syscall.c > @@ -18,6 +18,10 @@ > #include > #include > > +#ifndef __NR_fork > +#define __NR_fork -1 > +#endif > + > #define LOOPS_DEFAULT 10000000 > static int loops = LOOPS_DEFAULT; > > @@ -31,6 +35,23 @@ static const char * const bench_syscall_usage[] = { > NULL > }; > > +static void test_fork(void) > +{ > + pid_t pid = fork(); > + > + if (pid < 0) { > + fprintf(stderr, "fork failed\n"); > + exit(1); > + } else if (pid == 0) { > + exit(0); > + } else { > + if (waitpid(pid, NULL, 0) < 0) { > + fprintf(stderr, "waitpid failed\n"); > + exit(1); > + } > + } > +} > + > static void test_execve(void) > { > const char *pathname = "/bin/true"; > @@ -71,6 +92,12 @@ static int bench_syscall_common(int argc, const char **argv, int syscall) > case __NR_getpgid: > getpgid(0); > break; > + case __NR_fork: > + test_fork(); > + /* Only loop 10000 times to save time */ > + if (i == 10000) > + loops = 10000; > + break; > case __NR_execve: > test_execve(); > /* Only loop 10000 times to save time */ > @@ -92,6 +119,9 @@ static int bench_syscall_common(int argc, const char **argv, int syscall) > case __NR_getpgid: > name = "getpgid()"; > break; > + case __NR_fork: > + name = "fork()"; > + break; > case __NR_execve: > name = "execve()"; > break; > @@ -143,6 +173,11 @@ int bench_syscall_getpgid(int argc, const char **argv) > return bench_syscall_common(argc, argv, __NR_getpgid); > } > > +int bench_syscall_fork(int argc, const char **argv) > +{ > + return bench_syscall_common(argc, argv, __NR_fork); > +} > + > int bench_syscall_execve(int argc, const char **argv) > { > return bench_syscall_common(argc, argv, __NR_execve); > diff --git a/tools/perf/builtin-bench.c b/tools/perf/builtin-bench.c > index 814e9af..d0fcc3c 100644 > --- a/tools/perf/builtin-bench.c > +++ b/tools/perf/builtin-bench.c > @@ -53,6 +53,7 @@ static struct bench sched_benchmarks[] = { > static struct bench syscall_benchmarks[] = { > { "basic", "Benchmark for basic getppid(2) calls", bench_syscall_basic }, > { "getpgid", "Benchmark for getpgid(2) calls", bench_syscall_getpgid }, > + { "fork", "Benchmark for fork(2) calls", bench_syscall_fork }, > { "execve", "Benchmark for execve(2) calls", bench_syscall_execve }, > { "all", "Run all syscall benchmarks", NULL }, > { NULL, NULL, NULL }, > -- > 2.1.0 >