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