From patchwork Wed Jul 19 20:49:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 122840 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2713519vqt; Wed, 19 Jul 2023 14:18:31 -0700 (PDT) X-Google-Smtp-Source: APBJJlEoAhXIHT6gkK4PsG6TRTeMyjEF1ITOOWRcWtOWNNmEcjfDDPpjOQp2JUqJ/iEKAncs4Bss X-Received: by 2002:a17:90b:1b48:b0:263:cfc9:754a with SMTP id nv8-20020a17090b1b4800b00263cfc9754amr438438pjb.0.1689801511000; Wed, 19 Jul 2023 14:18:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689801510; cv=none; d=google.com; s=arc-20160816; b=NT6aJfnguRiuWtq9kUbrpSURg62H1D5W9jocZL5mFbxLdVbfu/6VDzsKoIriDTHUqY p6EASAO18dGHcLtg1/lwUaj0b4a0KvEAfUYIkavBHjrGWjRuYk+UHR18B02fgU7o+Yce sBhVholPB0uPj0UdQ7DaYXrx6aTz+G87dGsc3oaH2hs/4NbNNbVTzXxHtrcbWH71Gl0d M0EMF+H0RHym0Vmy9JpBKL1romP6i5Tni9PvIZNBsxklecsu1KTY2Sg83mpCBJn2C9ni a/iNIqW1U/NoXEAU4kSa7MlW7FoveKdKqU5L4xPJHY0CtSDgaI4QP59KITouMAsgCHHW aycg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=n0WVPwR1Of5ogl86mawPp14P2MhSqw/7v7RejwYDSfY=; fh=+f/UgXFaEXexPSiEzT8nRacxrlb6xSaAhUFMhN/xNro=; b=utKDJB6f5EQtxNLMz9vdRHTEXeo2H6GGzFVq6yKzf6VpJOmat4pKN+ZiONks9KpRnq bM0+vpbKxQYuXo2tRgz9m1b1kOSoOWjuCMdYYPItC8yjYgr5cs78PFObS1z1M+uo9mqL Km7T5ERcNh1f7GDLwh+IjLbc/T2UVT0b8J6fGCofJUTbdYvOzNOirJ0uX9vr1h7lhVS2 coJ48cOEo2aOADQbylz8hcfPPPnGud+MsrGXF3R1kYG8mJgRNZfuOSKHlhXuWnxtJKEo ac/ObSRPeBfDU7gEyBLmTYsjB9rUJ65xPii70iQRk27Tr1GA+qsYguC8H/vgocj9rKQS VxJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tActNpwl; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z14-20020a170902d54e00b001b3d822f131si4322726plf.239.2023.07.19.14.18.15; Wed, 19 Jul 2023 14:18:30 -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=@kernel.org header.s=k20201202 header.b=tActNpwl; 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 S230311AbjGSUtb (ORCPT + 99 others); Wed, 19 Jul 2023 16:49:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229611AbjGSUt3 (ORCPT ); Wed, 19 Jul 2023 16:49:29 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 740871FC0; Wed, 19 Jul 2023 13:49:28 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 11F2661834; Wed, 19 Jul 2023 20:49:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 398A4C433D9; Wed, 19 Jul 2023 20:49:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689799767; bh=97AqN7YVHWJkxacW9EppZd/xOvf0O8SW/yCKvmWXGRw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tActNpwlU3MQD+XPFn1X4Bvf65Uj9h2MHNVgK7V+lPs4ixSHytolacKLC4Ju3J78N cRQftqY80h+WG3MEwKI6fHaBtsSzg48jnnTR4kPNHycqfPZSh71VvigyPQgBAUNrKJ GIcRiJ21dhHUz9IYOLZTjQuWTeZJ4HOOPkLGb4QvsZ5YF6WixOnIi3kHQNJ9aqWjXr azVgtVpH3N3W5jBP547+Op2P+zmrVNCZMwA8Y7/fun9x8dvaLAl0UY74MoqVaiWfj/ bUGMSQSX04zd5W6ffANL7T0GEy4RnqUxufs1zHhrH6JRmn11xr4baqTpk0zLQmNOGE J7rxQunfa9dJA== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , Jiri Olsa , Ian Rogers , Adrian Hunter , Clark Williams , Kate Carcia , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo , Andre Fredette , Dave Tucker , Derek Barbosa , Masami Hiramatsu Subject: [PATCH 1/5] perf bench uprobe: Add benchmark to test uprobe overhead Date: Wed, 19 Jul 2023 17:49:06 -0300 Message-ID: <20230719204910.539044-2-acme@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230719204910.539044-1-acme@kernel.org> References: <20230719204910.539044-1-acme@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771885309251883687 X-GMAIL-MSGID: 1771885309251883687 From: Arnaldo Carvalho de Melo This just adds the initial "workload", a call to libc's usleep(1000us) function: $ perf stat --null perf bench uprobe all # Running uprobe/baseline benchmark... # Executed 1000 usleep(1000) calls Total time: 1053533 usecs 1053.533 usecs/op Performance counter stats for 'perf bench uprobe all': 1.061042896 seconds time elapsed 0.001079000 seconds user 0.006499000 seconds sys $ More entries will be added using a BPF skel to add various uprobes to the usleep() function. Cc: Adrian Hunter Cc: Andre Fredette Cc: Clark Williams Cc: Dave Tucker Cc: Derek Barbosa Cc: Ian Rogers Cc: Jiri Olsa Cc: Masami Hiramatsu (Google) Cc: Namhyung Kim Signed-off-by: Arnaldo Carvalho de Melo Reviewed-by: Masami Hiramatsu (Google) --- tools/perf/Documentation/perf-bench.txt | 3 + tools/perf/bench/Build | 1 + tools/perf/bench/bench.h | 1 + tools/perf/bench/uprobe.c | 80 +++++++++++++++++++++++++ tools/perf/builtin-bench.c | 6 ++ 5 files changed, 91 insertions(+) create mode 100644 tools/perf/bench/uprobe.c diff --git a/tools/perf/Documentation/perf-bench.txt b/tools/perf/Documentation/perf-bench.txt index f04f0eaded985fc8..ca5789625cd2b8e5 100644 --- a/tools/perf/Documentation/perf-bench.txt +++ b/tools/perf/Documentation/perf-bench.txt @@ -67,6 +67,9 @@ SUBSYSTEM 'internals':: Benchmark internal perf functionality. +'uprobe':: + Benchmark overhead of uprobe + BPF. + 'all':: All benchmark subsystems. diff --git a/tools/perf/bench/Build b/tools/perf/bench/Build index 0f158dc8139bbd0d..47412d47dccfeff2 100644 --- a/tools/perf/bench/Build +++ b/tools/perf/bench/Build @@ -16,6 +16,7 @@ perf-y += inject-buildid.o perf-y += evlist-open-close.o perf-y += breakpoint.o perf-y += pmu-scan.o +perf-y += uprobe.o perf-$(CONFIG_X86_64) += mem-memcpy-x86-64-asm.o perf-$(CONFIG_X86_64) += mem-memset-x86-64-asm.o diff --git a/tools/perf/bench/bench.h b/tools/perf/bench/bench.h index 0d2b65976212333a..201311f75c964df2 100644 --- a/tools/perf/bench/bench.h +++ b/tools/perf/bench/bench.h @@ -42,6 +42,7 @@ int bench_inject_build_id(int argc, const char **argv); int bench_evlist_open_close(int argc, const char **argv); int bench_breakpoint_thread(int argc, const char **argv); int bench_breakpoint_enable(int argc, const char **argv); +int bench_uprobe_baseline(int argc, const char **argv); int bench_pmu_scan(int argc, const char **argv); #define BENCH_FORMAT_DEFAULT_STR "default" diff --git a/tools/perf/bench/uprobe.c b/tools/perf/bench/uprobe.c new file mode 100644 index 0000000000000000..707174220a76701f --- /dev/null +++ b/tools/perf/bench/uprobe.c @@ -0,0 +1,80 @@ +// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +/* + * uprobe.c + * + * uprobe benchmarks + * + * Copyright (C) 2023, Red Hat Inc, Arnaldo Carvalho de Melo + */ +#include "../perf.h" +#include "../util/util.h" +#include +#include "../builtin.h" +#include "bench.h" +#include + +#include +#include +#include +#include +#include +#include +#include + +#define LOOPS_DEFAULT 1000 +static int loops = LOOPS_DEFAULT; + +static const struct option options[] = { + OPT_INTEGER('l', "loop", &loops, "Specify number of loops"), + OPT_END() +}; + +static const char * const bench_uprobe_usage[] = { + "perf bench uprobe ", + NULL +}; + +static int bench_uprobe(int argc, const char **argv) +{ + const char *name = "usleep(1000)", *unit = "usec"; + struct timespec start, end; + u64 diff; + int i; + + argc = parse_options(argc, argv, options, bench_uprobe_usage, 0); + + clock_gettime(CLOCK_REALTIME, &start); + + for (i = 0; i < loops; i++) { + usleep(USEC_PER_MSEC); + } + + clock_gettime(CLOCK_REALTIME, &end); + + diff = end.tv_sec * NSEC_PER_SEC + end.tv_nsec - (start.tv_sec * NSEC_PER_SEC + start.tv_nsec); + diff /= NSEC_PER_USEC; + + switch (bench_format) { + case BENCH_FORMAT_DEFAULT: + printf("# Executed %'d %s calls\n", loops, name); + printf(" %14s: %'" PRIu64 " %ss\n\n", "Total time", diff, unit); + printf(" %'.3f %ss/op\n", (double)diff / (double)loops, unit); + break; + + case BENCH_FORMAT_SIMPLE: + printf("%" PRIu64 "\n", diff); + break; + + default: + /* reaching here is something of a disaster */ + fprintf(stderr, "Unknown format:%d\n", bench_format); + exit(1); + } + + return 0; +} + +int bench_uprobe_baseline(int argc, const char **argv) +{ + return bench_uprobe(argc, argv); +} diff --git a/tools/perf/builtin-bench.c b/tools/perf/builtin-bench.c index db435b791a09b69b..09637aee83413e63 100644 --- a/tools/perf/builtin-bench.c +++ b/tools/perf/builtin-bench.c @@ -104,6 +104,11 @@ static struct bench breakpoint_benchmarks[] = { { NULL, NULL, NULL }, }; +static struct bench uprobe_benchmarks[] = { + { "baseline", "Baseline libc usleep(1000) call", bench_uprobe_baseline, }, + { NULL, NULL, NULL }, +}; + struct collection { const char *name; const char *summary; @@ -123,6 +128,7 @@ static struct collection collections[] = { #endif { "internals", "Perf-internals benchmarks", internals_benchmarks }, { "breakpoint", "Breakpoint benchmarks", breakpoint_benchmarks }, + { "uprobe", "uprobe benchmarks", uprobe_benchmarks }, { "all", "All benchmarks", NULL }, { NULL, NULL, NULL } }; From patchwork Wed Jul 19 20:49:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 122837 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2713061vqt; Wed, 19 Jul 2023 14:17:25 -0700 (PDT) X-Google-Smtp-Source: APBJJlFEtHXRM5ERb9BsGurMYbnY+czF64M2PCZbz5t73CtixwOFyLvyuWNHLkswfEav6asI81jS X-Received: by 2002:a05:6a20:8414:b0:133:fd64:8d48 with SMTP id c20-20020a056a20841400b00133fd648d48mr12680376pzd.4.1689801444858; Wed, 19 Jul 2023 14:17:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689801444; cv=none; d=google.com; s=arc-20160816; b=cADYkH4YKquH8+fPDrP2phC5H9M/CVmSlywhpCTtVZioBrxXcKtgI9PsagYVmhler4 9CMnWAVqQBRqGQ8TeUkz//E4xjFDbY0h+TkvOanUVB4QMb5a6VqcaP1fy5Amv+f3GIlc hD57OKgpgKwL5ywhwucwt2ax7t90fw3Ue23m/uVvhwblRii3LDaHMEaK2S6zkd6zkzOf culQSxt7Re42I5f0xYolvMYaRAeqWKolb/iB13LLOMqelEqkfhcWxoZ7ld5nhShZyjE8 YL4d5T6Vt4y1Ib+91z+Az+JieQjXJZo2YN+OqdyMQvT9jtKLdfYR5l9fw5RccetotHJ8 BdFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=11h9wZpZPoBQdv66/QeX1XthsxriDdZfYVTYgxC/xsI=; fh=+f/UgXFaEXexPSiEzT8nRacxrlb6xSaAhUFMhN/xNro=; b=0vk0IFDxvgc60O2x7+fWzd0tcOluwZsJVD0EufW1hTW5XafKqynSEI8W1eYuguivvJ BLBYS4Y/OQaGW9oOHzqKG8QeNheDju93QknmPzT+fzoxsQFF5+tTxUEJm1d1uLcFVQM2 q3Ilx7YzNpBeh9yzuskgPfkb2OUECeQwGNrekA1n826+RDqO024YI10nhA/jGTcRi78P +1GvZNylwmOvInN1NZydofn+oHjlhoCCwrz05e8O62VytARbhxjT6ONs27SC7Cf4p0UL tiGyTgxVJxTIKRy2Y2F2rEj/QlWPMq3sZXFpSSX81C7nMthEXeEe4djT+AxN+t1XRGw8 Ik3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dEXRxMJr; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w65-20020a636244000000b0053ee9b21820si4126041pgb.72.2023.07.19.14.17.12; Wed, 19 Jul 2023 14:17:24 -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=@kernel.org header.s=k20201202 header.b=dEXRxMJr; 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 S230492AbjGSUtg (ORCPT + 99 others); Wed, 19 Jul 2023 16:49:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230471AbjGSUtd (ORCPT ); Wed, 19 Jul 2023 16:49:33 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36BF21FED; Wed, 19 Jul 2023 13:49:32 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id C448B6183B; Wed, 19 Jul 2023 20:49:31 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EDFC0C433C9; Wed, 19 Jul 2023 20:49:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689799771; bh=UpIXw98xleRtWat9gzqiYLTx+YUEV/h5AHcduRz0D+A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dEXRxMJrFP/XDIveNjZ0NxFNqYfaNvIfalXAk5YT1ma0zjp9vX2pXPbD+VdYFBFgm cB8AZjF3cwGd/0alqe7e0/D2wU9Bc1syjBdbq5ZuZfOAaqZN2qRMUgA5yOfAAjSq6I AAjQwjOIKdrjs7hYAUeQrLOwDVkKPqNwu59FQiH7qeH32Ocy07bPfq63bbNHKzArFo y2j56WisF0Eh8oGHw6YR7MShJXoC6w37Vu0E4smV8Vk+hEc57txDVNVYeuokFP1NDK +LjwGf/20R2T19WZmOdN42bb50g5TLNizg2R+dW72u9FONA/Bmoax9ezf4imqQih9E nnzgj5KFoEN1A== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , Jiri Olsa , Ian Rogers , Adrian Hunter , Clark Williams , Kate Carcia , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo , Andre Fredette , Dave Tucker , Derek Barbosa , Masami Hiramatsu Subject: [PATCH 2/5] perf bench uprobe: Print diff to baseline Date: Wed, 19 Jul 2023 17:49:07 -0300 Message-ID: <20230719204910.539044-3-acme@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230719204910.539044-1-acme@kernel.org> References: <20230719204910.539044-1-acme@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771885239334333907 X-GMAIL-MSGID: 1771885239334333907 From: Arnaldo Carvalho de Melo This is just prep work to show the diff to the unmodified workload. Cc: Adrian Hunter Cc: Andre Fredette Cc: Clark Williams Cc: Dave Tucker Cc: Derek Barbosa Cc: Ian Rogers Cc: Jiri Olsa Cc: Masami Hiramatsu (Google) Cc: Namhyung Kim Signed-off-by: Arnaldo Carvalho de Melo Reviewed-by: Masami Hiramatsu (Google) --- tools/perf/bench/uprobe.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/tools/perf/bench/uprobe.c b/tools/perf/bench/uprobe.c index 707174220a76701f..60e7c43298d8cf56 100644 --- a/tools/perf/bench/uprobe.c +++ b/tools/perf/bench/uprobe.c @@ -34,6 +34,29 @@ static const char * const bench_uprobe_usage[] = { NULL }; +static int bench_uprobe_format__default_fprintf(const char *name, const char *unit, u64 diff, FILE *fp) +{ + static u64 baseline; + s64 diff_to_baseline = diff - baseline; + int printed = fprintf(fp, "# Executed %'d %s calls\n", loops, name); + + printed += fprintf(fp, " %14s: %'" PRIu64 " %ss", "Total time", diff, unit); + + if (baseline) + printed += fprintf(fp, " %s%'" PRId64 " to baseline", diff_to_baseline > 0 ? "+" : "", diff_to_baseline); + + printed += fprintf(fp, "\n\n %'.3f %ss/op", (double)diff / (double)loops, unit); + + if (baseline) + printed += fprintf(fp, " %'.3f %ss/op to baseline", (double)diff_to_baseline / (double)loops, unit); + else + baseline = diff; + + fputc('\n', fp); + + return printed + 1; +} + static int bench_uprobe(int argc, const char **argv) { const char *name = "usleep(1000)", *unit = "usec"; @@ -56,9 +79,7 @@ static int bench_uprobe(int argc, const char **argv) switch (bench_format) { case BENCH_FORMAT_DEFAULT: - printf("# Executed %'d %s calls\n", loops, name); - printf(" %14s: %'" PRIu64 " %ss\n\n", "Total time", diff, unit); - printf(" %'.3f %ss/op\n", (double)diff / (double)loops, unit); + bench_uprobe_format__default_fprintf(name, unit, diff, stdout); break; case BENCH_FORMAT_SIMPLE: From patchwork Wed Jul 19 20:49:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 122838 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2713167vqt; Wed, 19 Jul 2023 14:17:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlHM973VFfL2gmOUFAdw6g/f6S0SOBg0aGBI8PQxgkIAljDYh9fLrC3tDB0ENgv9B/xBPRge X-Received: by 2002:a17:90b:b10:b0:263:72fe:3ef7 with SMTP id bf16-20020a17090b0b1000b0026372fe3ef7mr15789597pjb.42.1689801462985; Wed, 19 Jul 2023 14:17:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689801462; cv=none; d=google.com; s=arc-20160816; b=J7mrSH5jZvGE5rzRNJ64YMiiyvqMKgRH78cPK2ZJkcEKzdxxbAZhgQAJBrR5ZwWs6z Nyxk70OMN5n+BtjQXlkdfTV5viUUdNrBuwaweygtt4C95Qvt3I7b7dwOEwy1JovrAGvD ulVxuPFenyUqZP+EXw/MRDA62kESt+gzVqRNDGPrZFGWp8wVXPPmSRuT0pS+F/wMNr+v C1FXTaYYPfn7iflU32zGa3CSSoGsvltyxAMIk2pYKCZGMBoa7Sf6TsfuUf2HAGH3WUDq tc7QvtSTQhuySqGwFQk/Ll3+iaBWHOxKYHS23VQOs63SG4B9aC8AvO04xeoR/m7zTaow bvtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CeTeSvzTZmjJ8PuEZOBwS5Se+Tvb9FHwatF06dFzR8s=; fh=+f/UgXFaEXexPSiEzT8nRacxrlb6xSaAhUFMhN/xNro=; b=jHAq++c1P6KzCSKgcREzmXb4xYDeb+jCaRBTP3hs2MCaNnZtnfdfsARmzFL/Sbed+9 w3tukcL2tKTQ5d8us+yaRmHUNTci1/cL68Mevdb22vIkKY3+cf6gBLIVugwRdgglZW2l 6rDo9OYuVCw8es93qy++esOC86AN/6N6ttUSZ1ANEcU2gqsfrJiuJHWV1LiFSTlLxXRh UwBfyNJrOkAlCaQXO5/UcqcNQYjnFPHGTpnto4vj2ttHVZbmw3a2g2lbvx6uT/lCpTNm DqV+Be7LKgBETw3XwV7eIR3y+T7kJJw43xaptE0g0M4XU6s4MrS54Yk9RRu0xQ7YziE7 wrMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=BpQv1z4I; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 1-20020a17090a0b8100b00263e5a7d8d7si2112934pjr.1.2023.07.19.14.17.30; Wed, 19 Jul 2023 14:17:42 -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=@kernel.org header.s=k20201202 header.b=BpQv1z4I; 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 S230232AbjGSUtp (ORCPT + 99 others); Wed, 19 Jul 2023 16:49:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231167AbjGSUti (ORCPT ); Wed, 19 Jul 2023 16:49:38 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 348AA2110; Wed, 19 Jul 2023 13:49:36 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 80C14617D6; Wed, 19 Jul 2023 20:49:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AADD4C433C8; Wed, 19 Jul 2023 20:49:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689799774; bh=TSAUEsjKipWRQRCBkVitDwEGleao6uFXPDlBRtKZDMY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BpQv1z4IO7BiRIUvVWopfhw3MykuFZpy3RXqTvmrt7KISq9+8J4SU5/PmtjFvUJuS OtstdL3dcbNi4uW1/Ol+zhIJ4DAxjmPTRtHZNCqtlmi1PXEMxJv3cnRBrnXua5+DzX Xo19PPG66VTGCv3+V6tX9esKr2qEd0wG2Xy/216H7vXKOKRjBkJOIVeZom7T5cquPb 1wH1awSkRnN2LDamE1Ma4+ZBNXcLBddmSQWF3w7Ut6vYHYb1cGHJZWUV3tYeIir7X6 49ZemQSPku2IYoHz/RvGZhT0El8eFlUtPT1R2IG5f8hkdOSdU2OujZyh9qXyHFKc2L 9f0TbJRReTKvQ== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , Jiri Olsa , Ian Rogers , Adrian Hunter , Clark Williams , Kate Carcia , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo , Andre Fredette , Dave Tucker , Derek Barbosa , Masami Hiramatsu Subject: [PATCH 3/5] perf bench uprobe: Show diff to previous Date: Wed, 19 Jul 2023 17:49:08 -0300 Message-ID: <20230719204910.539044-4-acme@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230719204910.539044-1-acme@kernel.org> References: <20230719204910.539044-1-acme@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771885258721290376 X-GMAIL-MSGID: 1771885258721290376 From: Arnaldo Carvalho de Melo Will be useful to show the incremental overhead as we do more stuff in the BPF program attached to the uprobes. Cc: Adrian Hunter Cc: Andre Fredette Cc: Clark Williams Cc: Dave Tucker Cc: Derek Barbosa Cc: Ian Rogers Cc: Jiri Olsa Cc: Masami Hiramatsu (Google) Cc: Namhyung Kim Signed-off-by: Arnaldo Carvalho de Melo Reviewed-by: Masami Hiramatsu (Google) --- tools/perf/bench/uprobe.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/tools/perf/bench/uprobe.c b/tools/perf/bench/uprobe.c index 60e7c43298d8cf56..a90e09f791c540a9 100644 --- a/tools/perf/bench/uprobe.c +++ b/tools/perf/bench/uprobe.c @@ -36,24 +36,35 @@ static const char * const bench_uprobe_usage[] = { static int bench_uprobe_format__default_fprintf(const char *name, const char *unit, u64 diff, FILE *fp) { - static u64 baseline; - s64 diff_to_baseline = diff - baseline; + static u64 baseline, previous; + s64 diff_to_baseline = diff - baseline, + diff_to_previous = diff - previous; int printed = fprintf(fp, "# Executed %'d %s calls\n", loops, name); printed += fprintf(fp, " %14s: %'" PRIu64 " %ss", "Total time", diff, unit); - if (baseline) + if (baseline) { printed += fprintf(fp, " %s%'" PRId64 " to baseline", diff_to_baseline > 0 ? "+" : "", diff_to_baseline); + if (previous != baseline) + fprintf(stdout, " %s%'" PRId64 " to previous", diff_to_previous > 0 ? "+" : "", diff_to_previous); + } + printed += fprintf(fp, "\n\n %'.3f %ss/op", (double)diff / (double)loops, unit); - if (baseline) + if (baseline) { printed += fprintf(fp, " %'.3f %ss/op to baseline", (double)diff_to_baseline / (double)loops, unit); - else + + if (previous != baseline) + printed += fprintf(fp, " %'.3f %ss/op to previous", (double)diff_to_previous / (double)loops, unit); + } else { baseline = diff; + } fputc('\n', fp); + previous = diff; + return printed + 1; } From patchwork Wed Jul 19 20:49:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 122839 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2713203vqt; Wed, 19 Jul 2023 14:17:47 -0700 (PDT) X-Google-Smtp-Source: APBJJlGZH/rYH9J5QmOikIV45bNYm+88Z8OevYs7n0ywbveUVJ6AWZV+Zi9PwbpkqfJICLX1TdX5 X-Received: by 2002:a05:6a20:4417:b0:137:63fa:2a17 with SMTP id ce23-20020a056a20441700b0013763fa2a17mr897293pzb.12.1689801467323; Wed, 19 Jul 2023 14:17:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689801467; cv=none; d=google.com; s=arc-20160816; b=uGDNDmE7C/AFtghFudmFN+Vok61Wu6SOj1dbXzaOo684juOzPdc5G9ryL9+50we1TE dW0/PCaaTbyqn1EOw2peJ1IAraKERAmFC7KjnScMjvdCwvDR1H95N3JOLgZzFVw4InYE 0WbquWkn0RIYb8EqfjMUuWSkeXNta9EUwxX23pIx4HHGd+jgPLECJl67zG7zpdB8GKP+ PWU5SQ3Br7nIPLe9LAuqBl53lPwixdzwEq9M+5opJh1b2xNkfqNMQtOvGvHGeW9xQWVO I5RKIkcEyogtwpXbcsxrkmv2x+KJq/QndCHIuBeemtaoAVt69dqRBieD8rN6l0Ly5e2g 3uPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=vM8SJ2QBw0Ty+RjhsmB88JX9ULdA03oRsSplcJjS5Cs=; fh=+f/UgXFaEXexPSiEzT8nRacxrlb6xSaAhUFMhN/xNro=; b=ljfydzmD4YSwULbmJd2bzOHVwvlGuyfN0zic6SesSCNkow/Eg6gAztzElXKID7ftsR SB3yb51eSAGKXPRU8Esgf+DTBnlBuDwunhsDsLFMEid7Ah5KY3R5xNloJ7DiSPmm9bKU 3hFtb3bTpFCRr5Wil7mxItLG7rhj24IllRP6o8ZwwKf1X+byXWIatnseLO+47qk0GRab MGLr4bQXg0ivNWLJsY9mI1xWxoQCApYZa/Ykl24nct47/OlQbxmQ7xN8F0Dcw22yOOht xtqgcltupR+3zXM7yCGd7jIyrVY+sP5uOpeeuzZ7EayiFXw3y33V7q00RnVlrcgjBg1U imCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=s5fcWtrl; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dc7-20020a056a0035c700b00681695f1f67si4076646pfb.263.2023.07.19.14.17.34; Wed, 19 Jul 2023 14:17:47 -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=@kernel.org header.s=k20201202 header.b=s5fcWtrl; 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 S230360AbjGSUtw (ORCPT + 99 others); Wed, 19 Jul 2023 16:49:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47514 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230475AbjGSUto (ORCPT ); Wed, 19 Jul 2023 16:49:44 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEF14212B; Wed, 19 Jul 2023 13:49:39 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3B5E661834; Wed, 19 Jul 2023 20:49:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 66F80C433C9; Wed, 19 Jul 2023 20:49:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689799778; bh=ElLJOq0QUPKDQnER3dHopH9uUZiA0v6ocxNfFBx/PLI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s5fcWtrleX1d5Jmq4RLRJ7Y7NtH8/8O1NK8B5WkiOuSOIRYa3Eb4RV9JJ/IEs9TQq myOY1kb6vtaKViRVfq5qdY0XYMikWGQIqYVlxo0NdTJutHs3cGuzqtjdK3bS20zfk9 YfMaJcNDIasiCAUGMGWZ+JkF9znAMXI4Bcnl7qfF99URb6IB9x7+k/lVzwbWSdUxb0 ubvf6Yjt5wkjC9jENIWczVdkZ04EKQ9dNkTc2vWHZtRFeMHnOm7pQQyR8hpRPVgj67 UwqgPFRHoD0VTc4F6Qz5XKc9mjkMql4uy2ABApxvLfMHcB3/HqcsaNpI1I3bzD3/h/ ah+k8Q6/LbVcA== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , Jiri Olsa , Ian Rogers , Adrian Hunter , Clark Williams , Kate Carcia , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo , Andre Fredette , Dave Tucker , Derek Barbosa , Masami Hiramatsu Subject: [PATCH 4/5] perf bench uprobe empty: Add entry attaching an empty BPF program Date: Wed, 19 Jul 2023 17:49:09 -0300 Message-ID: <20230719204910.539044-5-acme@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230719204910.539044-1-acme@kernel.org> References: <20230719204910.539044-1-acme@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771885262965222915 X-GMAIL-MSGID: 1771885262965222915 From: Arnaldo Carvalho de Melo Using libbpf and a BPF skel: # perf bench uprobe all # Running uprobe/baseline benchmark... # Executed 1,000 usleep(1000) calls Total time: 1,055,618 usecs 1,055.618 usecs/op # Running uprobe/empty benchmark... # Executed 1,000 usleep(1000) calls Total time: 1,057,146 usecs +1,528 to baseline 1,057.146 usecs/op # Cc: Adrian Hunter Cc: Andre Fredette Cc: Clark Williams Cc: Dave Tucker Cc: Derek Barbosa Cc: Ian Rogers Cc: Jiri Olsa Cc: Masami Hiramatsu (Google) Cc: Namhyung Kim Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/Makefile.perf | 1 + tools/perf/bench/bench.h | 1 + tools/perf/bench/uprobe.c | 75 ++++++++++++++++++++- tools/perf/builtin-bench.c | 3 +- tools/perf/util/bpf_skel/bench_uprobe.bpf.c | 12 ++++ 5 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 tools/perf/util/bpf_skel/bench_uprobe.bpf.c diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf index 097316ef38e6a80f..a44d16ec11ee5490 100644 --- a/tools/perf/Makefile.perf +++ b/tools/perf/Makefile.perf @@ -1057,6 +1057,7 @@ SKELETONS += $(SKEL_OUT)/bperf_leader.skel.h $(SKEL_OUT)/bperf_follower.skel.h SKELETONS += $(SKEL_OUT)/bperf_cgroup.skel.h $(SKEL_OUT)/func_latency.skel.h SKELETONS += $(SKEL_OUT)/off_cpu.skel.h $(SKEL_OUT)/lock_contention.skel.h SKELETONS += $(SKEL_OUT)/kwork_trace.skel.h $(SKEL_OUT)/sample_filter.skel.h +SKELETONS += $(SKEL_OUT)/bench_uprobe.skel.h $(SKEL_TMP_OUT) $(LIBAPI_OUTPUT) $(LIBBPF_OUTPUT) $(LIBPERF_OUTPUT) $(LIBSUBCMD_OUTPUT) $(LIBSYMBOL_OUTPUT): $(Q)$(MKDIR) -p $@ diff --git a/tools/perf/bench/bench.h b/tools/perf/bench/bench.h index 201311f75c964df2..daf4850b441cf91c 100644 --- a/tools/perf/bench/bench.h +++ b/tools/perf/bench/bench.h @@ -43,6 +43,7 @@ int bench_evlist_open_close(int argc, const char **argv); int bench_breakpoint_thread(int argc, const char **argv); int bench_breakpoint_enable(int argc, const char **argv); int bench_uprobe_baseline(int argc, const char **argv); +int bench_uprobe_empty(int argc, const char **argv); int bench_pmu_scan(int argc, const char **argv); #define BENCH_FORMAT_DEFAULT_STR "default" diff --git a/tools/perf/bench/uprobe.c b/tools/perf/bench/uprobe.c index a90e09f791c540a9..dfb90038a4f7a06a 100644 --- a/tools/perf/bench/uprobe.c +++ b/tools/perf/bench/uprobe.c @@ -24,6 +24,11 @@ #define LOOPS_DEFAULT 1000 static int loops = LOOPS_DEFAULT; +enum bench_uprobe { + BENCH_UPROBE__BASELINE, + BENCH_UPROBE__EMPTY, +}; + static const struct option options[] = { OPT_INTEGER('l', "loop", &loops, "Specify number of loops"), OPT_END() @@ -34,6 +39,59 @@ static const char * const bench_uprobe_usage[] = { NULL }; +#ifdef HAVE_BPF_SKEL +#include "bpf_skel/bench_uprobe.skel.h" + +struct bench_uprobe_bpf *skel; + +static int bench_uprobe__setup_bpf_skel(void) +{ + DECLARE_LIBBPF_OPTS(bpf_uprobe_opts, uprobe_opts); + int err; + + /* Load and verify BPF application */ + skel = bench_uprobe_bpf__open(); + if (!skel) { + fprintf(stderr, "Failed to open and load uprobes bench BPF skeleton\n"); + return -1; + } + + err = bench_uprobe_bpf__load(skel); + if (err) { + fprintf(stderr, "Failed to load and verify BPF skeleton\n"); + goto cleanup; + } + + uprobe_opts.func_name = "usleep"; + skel->links.empty = bpf_program__attach_uprobe_opts(/*prog=*/skel->progs.empty, + /*pid=*/-1, + /*binary_path=*/"/lib64/libc.so.6", + /*func_offset=*/0, + /*opts=*/&uprobe_opts); + if (!skel->links.empty) { + err = -errno; + fprintf(stderr, "Failed to attach bench uprobe: %s\n", strerror(errno)); + goto cleanup; + } + + return err; +cleanup: + bench_uprobe_bpf__destroy(skel); + return err; +} + +static void bench_uprobe__teardown_bpf_skel(void) +{ + if (skel) { + bench_uprobe_bpf__destroy(skel); + skel = NULL; + } +} +#else +static int bench_uprobe__setup_bpf_skel(void) { return 0; } +static void bench_uprobe__teardown_bpf_skel(void) {}; +#endif + static int bench_uprobe_format__default_fprintf(const char *name, const char *unit, u64 diff, FILE *fp) { static u64 baseline, previous; @@ -68,7 +126,7 @@ static int bench_uprobe_format__default_fprintf(const char *name, const char *un return printed + 1; } -static int bench_uprobe(int argc, const char **argv) +static int bench_uprobe(int argc, const char **argv, enum bench_uprobe bench) { const char *name = "usleep(1000)", *unit = "usec"; struct timespec start, end; @@ -77,7 +135,10 @@ static int bench_uprobe(int argc, const char **argv) argc = parse_options(argc, argv, options, bench_uprobe_usage, 0); - clock_gettime(CLOCK_REALTIME, &start); + if (bench != BENCH_UPROBE__BASELINE && bench_uprobe__setup_bpf_skel() < 0) + return 0; + + clock_gettime(CLOCK_REALTIME, &start); for (i = 0; i < loops; i++) { usleep(USEC_PER_MSEC); @@ -103,10 +164,18 @@ static int bench_uprobe(int argc, const char **argv) exit(1); } + if (bench != BENCH_UPROBE__BASELINE) + bench_uprobe__teardown_bpf_skel(); + return 0; } int bench_uprobe_baseline(int argc, const char **argv) { - return bench_uprobe(argc, argv); + return bench_uprobe(argc, argv, BENCH_UPROBE__BASELINE); +} + +int bench_uprobe_empty(int argc, const char **argv) +{ + return bench_uprobe(argc, argv, BENCH_UPROBE__EMPTY); } diff --git a/tools/perf/builtin-bench.c b/tools/perf/builtin-bench.c index 09637aee83413e63..1021680bbc6d4298 100644 --- a/tools/perf/builtin-bench.c +++ b/tools/perf/builtin-bench.c @@ -105,7 +105,8 @@ static struct bench breakpoint_benchmarks[] = { }; static struct bench uprobe_benchmarks[] = { - { "baseline", "Baseline libc usleep(1000) call", bench_uprobe_baseline, }, + { "baseline", "Baseline libc usleep(1000) call", bench_uprobe_baseline, }, + { "empty", "Attach empty BPF prog to uprobe on usleep, system wide", bench_uprobe_empty, }, { NULL, NULL, NULL }, }; diff --git a/tools/perf/util/bpf_skel/bench_uprobe.bpf.c b/tools/perf/util/bpf_skel/bench_uprobe.bpf.c new file mode 100644 index 0000000000000000..1365dcc5dddff546 --- /dev/null +++ b/tools/perf/util/bpf_skel/bench_uprobe.bpf.c @@ -0,0 +1,12 @@ +// SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +// Copyright (c) 2023 Red Hat +#include "vmlinux.h" +#include + +SEC("uprobe") +int BPF_UPROBE(empty) +{ + return 0; +} + +char LICENSE[] SEC("license") = "Dual BSD/GPL"; From patchwork Wed Jul 19 20:49:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 122841 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp2713780vqt; Wed, 19 Jul 2023 14:19:01 -0700 (PDT) X-Google-Smtp-Source: APBJJlEineRfcCg+JVM6ZpWB62Lqwg3qCl3fdB8D8NrKHUb2LlSUNS47GeegJqX0U1nxG/9e+FQI X-Received: by 2002:a05:6808:8f8:b0:3a4:8e9b:e5cb with SMTP id d24-20020a05680808f800b003a48e9be5cbmr273542oic.1.1689801541153; Wed, 19 Jul 2023 14:19:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689801541; cv=none; d=google.com; s=arc-20160816; b=jiXV/EA+8cgKqhfB11CaYqX5StxieQ6tCWGyWMR9N2xxkIbBoo8u9MRGGVLYLdj6so vqKPAOBgEfkElbJmqCD2onYJ4WsPWKHP3PeJgvwZNVnakdosI3X5uuNr/vCpDIUN6dIS qGhF95c8J+E66R6iCczUJ1eyPChKVKn3HssmqcOasWW81UZJBkmDzMjKo3XGY4Rh4T9b ljHMxdry8LpbWdc5IYPmUKjtF1Y99wu/y6N15SjoLwOoRPlTHnT8qXGvn++G/oyk2pup OTbH54PC1uMQn0gXZTmV+J8BkNC7GmZO5RBaCl/smmIwTICVWDvPbhnm1LKk2+QEnZ3X ng3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=V2eNfKSycUGY0egwE+XFVAeQdCU8/0SRQ6V1Rxg6VXI=; fh=+f/UgXFaEXexPSiEzT8nRacxrlb6xSaAhUFMhN/xNro=; b=LdVTJ18hlz45JApkXF5WzetmlXxSKGFFb+vP8jA4tt/u9LjH/jZ4WYEWZqRIFsij9Q neVNZ0lLcbufed/Rwv9PIKJ/tTwmnuP2hJHbxz4+vY3KPIKHnxhGSWIyRoO3wY+hgS16 kXEsM8E3r2BQJMT08gX1XHlBjIRTBOuaNr6bu1U9ZdY3vofKOdMCWUqEQpySKAl0nlLB 2nwWfmqXynE67PvwuotnIvBE5otlZgL/0RI9sDJJyZQoL2vslpHOwpkEWrBVlkcjbpJI GVlmK2bgM5+VifOU+Rj//XEYyZNcawEA2KeogEFHGX2vuItq7iu1FJ90GBpmsSsaQ87o VY8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="ZE2Q9/7x"; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id rm2-20020a17090b3ec200b0025653dc2881si2282997pjb.23.2023.07.19.14.18.47; Wed, 19 Jul 2023 14:19:01 -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=@kernel.org header.s=k20201202 header.b="ZE2Q9/7x"; 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 S230286AbjGSUuB (ORCPT + 99 others); Wed, 19 Jul 2023 16:50:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230264AbjGSUtw (ORCPT ); Wed, 19 Jul 2023 16:49:52 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 452DB2108; Wed, 19 Jul 2023 13:49:43 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 01F8861843; Wed, 19 Jul 2023 20:49:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 270F6C433CA; Wed, 19 Jul 2023 20:49:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1689799782; bh=OazpdNCdjjMaiaC/TvQE6CjFJ6T/f9NfLfUAUPgtiPA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZE2Q9/7xBBEfujluvrRVJM0CsJUEth7+NFDpXRW5r0p8RCdU6V9heUR8LvzekahbM Gi1zcfLtLIvYlgFQJ8Q0izhZFhi66yVvwalcduhqWfvPkJ9eeUuOvv1nE7HMnp7P+U JXdXINJa1jB2U6hZpr9x9WO4UGmmXrdm5O1FQ8VXFo5n6Ns9QM39ilzD/E7gGSG0/6 nYCXx6JgTGd8QDjsGKZP7KPHZRT+zsxTOBmzae/TGvAmnIxY6dRCanBMxxLynax5Jg 8hf+OzfUyMQQpx/ZBTQFKFnUc83PuINmQdDOAdvBdb76itOuJM45eHsZfyBuOiGvxJ MWtzgYK6o/r6g== From: Arnaldo Carvalho de Melo To: Namhyung Kim Cc: Ingo Molnar , Thomas Gleixner , Jiri Olsa , Ian Rogers , Adrian Hunter , Clark Williams , Kate Carcia , linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, Arnaldo Carvalho de Melo , Andre Fredette , Dave Tucker , Derek Barbosa , Masami Hiramatsu Subject: [PATCH 5/5] perf bench uprobe trace_printk: Add entry attaching an BPF program that does a trace_printk Date: Wed, 19 Jul 2023 17:49:10 -0300 Message-ID: <20230719204910.539044-6-acme@kernel.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230719204910.539044-1-acme@kernel.org> References: <20230719204910.539044-1-acme@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771885340301237781 X-GMAIL-MSGID: 1771885340301237781 From: Arnaldo Carvalho de Melo [root@five ~]# perf bench uprobe all # Running uprobe/baseline benchmark... # Executed 1,000 usleep(1000) calls Total time: 1,053,963 usecs 1,053.963 usecs/op # Running uprobe/empty benchmark... # Executed 1,000 usleep(1000) calls Total time: 1,056,293 usecs +2,330 to baseline 1,056.293 usecs/op 2.330 usecs/op to baseline # Running uprobe/trace_printk benchmark... # Executed 1,000 usleep(1000) calls Total time: 1,056,977 usecs +3,014 to baseline +684 to previous 1,056.977 usecs/op 3.014 usecs/op to baseline 0.684 usecs/op to previous [root@five ~]# Cc: Adrian Hunter Cc: Andre Fredette Cc: Clark Williams Cc: Dave Tucker Cc: Derek Barbosa Cc: Ian Rogers Cc: Jiri Olsa Cc: Masami Hiramatsu (Google) Cc: Namhyung Kim Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/bench/bench.h | 1 + tools/perf/bench/uprobe.c | 39 +++++++++++++++------ tools/perf/builtin-bench.c | 1 + tools/perf/util/bpf_skel/bench_uprobe.bpf.c | 11 ++++++ 4 files changed, 41 insertions(+), 11 deletions(-) diff --git a/tools/perf/bench/bench.h b/tools/perf/bench/bench.h index daf4850b441cf91c..50de4773651f9914 100644 --- a/tools/perf/bench/bench.h +++ b/tools/perf/bench/bench.h @@ -44,6 +44,7 @@ int bench_breakpoint_thread(int argc, const char **argv); int bench_breakpoint_enable(int argc, const char **argv); int bench_uprobe_baseline(int argc, const char **argv); int bench_uprobe_empty(int argc, const char **argv); +int bench_uprobe_trace_printk(int argc, const char **argv); int bench_pmu_scan(int argc, const char **argv); #define BENCH_FORMAT_DEFAULT_STR "default" diff --git a/tools/perf/bench/uprobe.c b/tools/perf/bench/uprobe.c index dfb90038a4f7a06a..914c0817fe8ad31b 100644 --- a/tools/perf/bench/uprobe.c +++ b/tools/perf/bench/uprobe.c @@ -11,6 +11,7 @@ #include #include "../builtin.h" #include "bench.h" +#include #include #include @@ -27,6 +28,7 @@ static int loops = LOOPS_DEFAULT; enum bench_uprobe { BENCH_UPROBE__BASELINE, BENCH_UPROBE__EMPTY, + BENCH_UPROBE__TRACE_PRINTK, }; static const struct option options[] = { @@ -42,9 +44,21 @@ static const char * const bench_uprobe_usage[] = { #ifdef HAVE_BPF_SKEL #include "bpf_skel/bench_uprobe.skel.h" +#define bench_uprobe__attach_uprobe(prog) \ + skel->links.prog = bpf_program__attach_uprobe_opts(/*prog=*/skel->progs.prog, \ + /*pid=*/-1, \ + /*binary_path=*/"/lib64/libc.so.6", \ + /*func_offset=*/0, \ + /*opts=*/&uprobe_opts); \ + if (!skel->links.prog) { \ + err = -errno; \ + fprintf(stderr, "Failed to attach bench uprobe \"%s\": %s\n", #prog, strerror(errno)); \ + goto cleanup; \ + } + struct bench_uprobe_bpf *skel; -static int bench_uprobe__setup_bpf_skel(void) +static int bench_uprobe__setup_bpf_skel(enum bench_uprobe bench) { DECLARE_LIBBPF_OPTS(bpf_uprobe_opts, uprobe_opts); int err; @@ -63,14 +77,12 @@ static int bench_uprobe__setup_bpf_skel(void) } uprobe_opts.func_name = "usleep"; - skel->links.empty = bpf_program__attach_uprobe_opts(/*prog=*/skel->progs.empty, - /*pid=*/-1, - /*binary_path=*/"/lib64/libc.so.6", - /*func_offset=*/0, - /*opts=*/&uprobe_opts); - if (!skel->links.empty) { - err = -errno; - fprintf(stderr, "Failed to attach bench uprobe: %s\n", strerror(errno)); + switch (bench) { + case BENCH_UPROBE__BASELINE: break; + case BENCH_UPROBE__EMPTY: bench_uprobe__attach_uprobe(empty); break; + case BENCH_UPROBE__TRACE_PRINTK: bench_uprobe__attach_uprobe(trace_printk); break; + default: + fprintf(stderr, "Invalid bench: %d\n", bench); goto cleanup; } @@ -88,7 +100,7 @@ static void bench_uprobe__teardown_bpf_skel(void) } } #else -static int bench_uprobe__setup_bpf_skel(void) { return 0; } +static int bench_uprobe__setup_bpf_skel(enum bench_uprobe bench __maybe_unused) { return 0; } static void bench_uprobe__teardown_bpf_skel(void) {}; #endif @@ -135,7 +147,7 @@ static int bench_uprobe(int argc, const char **argv, enum bench_uprobe bench) argc = parse_options(argc, argv, options, bench_uprobe_usage, 0); - if (bench != BENCH_UPROBE__BASELINE && bench_uprobe__setup_bpf_skel() < 0) + if (bench != BENCH_UPROBE__BASELINE && bench_uprobe__setup_bpf_skel(bench) < 0) return 0; clock_gettime(CLOCK_REALTIME, &start); @@ -179,3 +191,8 @@ int bench_uprobe_empty(int argc, const char **argv) { return bench_uprobe(argc, argv, BENCH_UPROBE__EMPTY); } + +int bench_uprobe_trace_printk(int argc, const char **argv) +{ + return bench_uprobe(argc, argv, BENCH_UPROBE__TRACE_PRINTK); +} diff --git a/tools/perf/builtin-bench.c b/tools/perf/builtin-bench.c index 1021680bbc6d4298..f60ccafccac25602 100644 --- a/tools/perf/builtin-bench.c +++ b/tools/perf/builtin-bench.c @@ -107,6 +107,7 @@ static struct bench breakpoint_benchmarks[] = { static struct bench uprobe_benchmarks[] = { { "baseline", "Baseline libc usleep(1000) call", bench_uprobe_baseline, }, { "empty", "Attach empty BPF prog to uprobe on usleep, system wide", bench_uprobe_empty, }, + { "trace_printk", "Attach trace_printk BPF prog to uprobe on usleep syswide", bench_uprobe_trace_printk, }, { NULL, NULL, NULL }, }; diff --git a/tools/perf/util/bpf_skel/bench_uprobe.bpf.c b/tools/perf/util/bpf_skel/bench_uprobe.bpf.c index 1365dcc5dddff546..7046bea5da871627 100644 --- a/tools/perf/util/bpf_skel/bench_uprobe.bpf.c +++ b/tools/perf/util/bpf_skel/bench_uprobe.bpf.c @@ -3,10 +3,21 @@ #include "vmlinux.h" #include +unsigned int nr_uprobes; + SEC("uprobe") int BPF_UPROBE(empty) { return 0; } +SEC("uprobe") +int BPF_UPROBE(trace_printk) +{ + char fmt[] = "perf bench uprobe %u"; + + bpf_trace_printk(fmt, sizeof(fmt), ++nr_uprobes); + return 0; +} + char LICENSE[] SEC("license") = "Dual BSD/GPL";