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";