Received: by 2002:a05:6a10:6d10:0:0:0:0 with SMTP id gq16csp888246pxb; Fri, 22 Apr 2022 13:30:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDguP9Kuepd7Kboi1PiflIMh3ESJNhYBhCmB4xuhx2XIdcj6WYVEy7bfwMEN0UTqwOW11I X-Received: by 2002:a17:90b:4a49:b0:1d2:adce:8a89 with SMTP id lb9-20020a17090b4a4900b001d2adce8a89mr18224967pjb.43.1650659409938; Fri, 22 Apr 2022 13:30:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650659409; cv=none; d=google.com; s=arc-20160816; b=IOT+CPKUdFpVL8s3rVrSddspg609Z6EiOGDW4JcLGI3UB3Idbdf0fMzw7OwvyUMUZC 6vSnbK1YAU0uIrZx5QmkoeR2QGNzRBGm4hk9LljXo0J0adaKkbnQ081EUc75WrIEhvMZ XdXyDyk2+KJhVQfDUtBtIWN9RgJENCUSxQlV0fe4EVHSlqPsZtMAg/oev0rPvtCjstou k5m3RDXDi6AvoKwPNEKpSCQmfZgpqx27d7xk08Blaz/qBb0G/6KWm8pqZ7oUENErTPx4 5077ofniV7XvngZcuRPxfTd272OABQbsYuzixZGznD2jp5rmJNfXtyiBp3/6TXNQ+9ld j84g== 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=XV35Uhu02nhpc/+S29bQrcl9X0sx9xBTyC1cMcdAS0s=; b=M4D9fvD3VLxqTWPC+kCaacpkiPC/8ujD6u+39E5t+wvyeXgZ/IS4C8Q1DwHoOgCPwq 102+ycFeKobDk7KR26s8oJQY8hcj8RfIAuDcRveotg0Ab56cRt5LSpqCs/iiXhTFJly5 wCP3Aal0WNL/TbgTqcBY+g6fp8veOdwsTCLWixzQQfzkVL6xIJBpYVFI5iMirGOFUTw4 wecHmo5BwXV0hxxEWl7eU/tVStNge+AT+OC6FM3ohIaB4UesLa2DyPd4vjiD0qgKVrOC KNwX1gnVlNCdoqByOTTOMYOtlsHvk4CqhnvyqEm9pCa5TCwV5WIS3OC2WY3mQ2Ts1eMn s7MQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=LEBmYdSt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id o4-20020a056a0015c400b004fa8832da6dsi9978146pfu.76.2022.04.22.13.30.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Apr 2022 13:30:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=LEBmYdSt; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 281311B89C9; Fri, 22 Apr 2022 12:17:06 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1382709AbiDTV7z (ORCPT + 99 others); Wed, 20 Apr 2022 17:59:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236516AbiDTV7x (ORCPT ); Wed, 20 Apr 2022 17:59:53 -0400 Received: from mail-vk1-xa2b.google.com (mail-vk1-xa2b.google.com [IPv6:2607:f8b0:4864:20::a2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BFBC3BBC2; Wed, 20 Apr 2022 14:57:05 -0700 (PDT) Received: by mail-vk1-xa2b.google.com with SMTP id o132so1438804vko.11; Wed, 20 Apr 2022 14:57:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=XV35Uhu02nhpc/+S29bQrcl9X0sx9xBTyC1cMcdAS0s=; b=LEBmYdStR/8Bi3o9F1wTA7JXqWfejnTtHV7VFQdsVGTF7bYv9Dt3LOfHyoKU64TyfO d/aXaMmspy4+NEm7Aa8Ctz6WE8EmC5fe3H7vRBBP2jA75fAHZGPTP8eedjfUyAtEI7Kd oQZx+4vlwIP/Nt8ePNk4+y/3b3UsUh0h7HFEgIzEgiv9fzQQbJILWZavjiatsHL62CBy YovP3WmFBekWBd47GvLm5zJOMB1BooXf3UqLtFV9WjA87wRuP6OqmfBudJXbzENLRoPQ Huu8H2FvoRrffbOHbhB8fl8KdqSkvV9rAYOc6U4R7wg1XKZJH8PvXVbo3e2bl3SZojiC 8MkQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=XV35Uhu02nhpc/+S29bQrcl9X0sx9xBTyC1cMcdAS0s=; b=eG4iOQwLJ/ax3EedKZYQDF1YonLzCTXO9ToMd4c3V2GuNL1OU6mvIX6gWeSJbael9t xWR760TSSqLmnrC+D9Zp6/B3zKNGY7LCJtRgHCmS8IksT4wlLfDqXunvkENxRLvhD3Gj 1I382DBvIdYh9Q8+AXMEez71KBOcBIYorEU1OftBVCBBa4NAAjn3tIvmVmrYrNIJp6db ZcDTGClpHzh+4wogIos/RoNuDQn492HDbkrK503r6Xq8Xvl2CsHjXKlUIldwx9S9BSuB ricMfsa/b/Mvm7UPsn+Z4aEFy+addko+g6Rj/BReh9tOpPaVF1EZuLrXWZSH8h9gv0Ta NASg== X-Gm-Message-State: AOAM533yZHRE5h7RoWdbn7rpcioqDXAVazsYUU/6nl6lWDQT6aPdn3o9 unC4xP231mSNwx22uiynHcs5WAJrO4tCCOE5FaM= X-Received: by 2002:ac5:cd88:0:b0:32c:5497:6995 with SMTP id i8-20020ac5cd88000000b0032c54976995mr6630525vka.33.1650491824683; Wed, 20 Apr 2022 14:57:04 -0700 (PDT) MIME-Version: 1.0 References: <20220418124834.829064-1-jolsa@kernel.org> <20220418124834.829064-5-jolsa@kernel.org> In-Reply-To: <20220418124834.829064-5-jolsa@kernel.org> From: Andrii Nakryiko Date: Wed, 20 Apr 2022 14:56:53 -0700 Message-ID: Subject: Re: [PATCHv2 bpf-next 4/4] selftests/bpf: Add attach bench test To: Jiri Olsa Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Masami Hiramatsu , Networking , bpf , lkml , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE 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 On Mon, Apr 18, 2022 at 5:49 AM Jiri Olsa wrote: > > Adding test that reads all functions from ftrace available_filter_functions > file and attach them all through kprobe_multi API. > > It also prints stats info with -v option, like on my setup: > > test_bench_attach: found 48712 functions > test_bench_attach: attached in 1.069s > test_bench_attach: detached in 0.373s > > Signed-off-by: Jiri Olsa > --- > .../bpf/prog_tests/kprobe_multi_test.c | 136 ++++++++++++++++++ > .../selftests/bpf/progs/kprobe_multi_empty.c | 12 ++ > 2 files changed, 148 insertions(+) > create mode 100644 tools/testing/selftests/bpf/progs/kprobe_multi_empty.c > > diff --git a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c > index b9876b55fc0c..05f0fab8af89 100644 > --- a/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c > +++ b/tools/testing/selftests/bpf/prog_tests/kprobe_multi_test.c > @@ -2,6 +2,9 @@ > #include > #include "kprobe_multi.skel.h" > #include "trace_helpers.h" > +#include "kprobe_multi_empty.skel.h" > +#include "bpf/libbpf_internal.h" > +#include "bpf/hashmap.h" > > static void kprobe_multi_test_run(struct kprobe_multi *skel, bool test_return) > { > @@ -301,6 +304,137 @@ static void test_attach_api_fails(void) > kprobe_multi__destroy(skel); > } > > +static inline __u64 get_time_ns(void) > +{ > + struct timespec t; > + > + clock_gettime(CLOCK_MONOTONIC, &t); > + return (__u64) t.tv_sec * 1000000000 + t.tv_nsec; > +} > + > +static size_t symbol_hash(const void *key, void *ctx __maybe_unused) > +{ > + return str_hash((const char *) key); > +} > + > +static bool symbol_equal(const void *key1, const void *key2, void *ctx __maybe_unused) > +{ > + return strcmp((const char *) key1, (const char *) key2) == 0; > +} > + > +#define DEBUGFS "/sys/kernel/debug/tracing/" > + > +static int get_syms(char ***symsp, size_t *cntp) > +{ > + size_t cap = 0, cnt = 0, i; > + char *name, **syms = NULL; > + struct hashmap *map; > + char buf[256]; > + FILE *f; > + int err; > + > + /* > + * The available_filter_functions contains many duplicates, > + * but other than that all symbols are usable in kprobe multi > + * interface. > + * Filtering out duplicates by using hashmap__add, which won't > + * add existing entry. > + */ > + f = fopen(DEBUGFS "available_filter_functions", "r"); nit: DEBUGFS "constant" just makes it harder to follow the code and doesn't add anything, please just use the full path here directly > + if (!f) > + return -EINVAL; > + > + map = hashmap__new(symbol_hash, symbol_equal, NULL); > + err = libbpf_get_error(map); hashmap__new() is an internal API, so please use IS_ERR() directly here. libbpf_get_error() should be used for public libbpf APIs, and preferably not in libbpf 1.0 mode > + if (err) > + goto error; > + > + while (fgets(buf, sizeof(buf), f)) { > + /* skip modules */ > + if (strchr(buf, '[')) > + continue; [...] > + attach_delta = (attach_end_ns - attach_start_ns) / 1000000000.0; > + detach_delta = (detach_end_ns - detach_start_ns) / 1000000000.0; > + > + fprintf(stderr, "%s: found %lu functions\n", __func__, cnt); > + fprintf(stderr, "%s: attached in %7.3lfs\n", __func__, attach_delta); > + fprintf(stderr, "%s: detached in %7.3lfs\n", __func__, detach_delta); why stderr? just do printf() and let test_progs handle output > + > +cleanup: > + kprobe_multi_empty__destroy(skel); > + if (syms) { > + for (i = 0; i < cnt; i++) > + free(syms[i]); > + free(syms); > + } > +} > + > void test_kprobe_multi_test(void) > { > if (!ASSERT_OK(load_kallsyms(), "load_kallsyms")) > @@ -320,4 +454,6 @@ void test_kprobe_multi_test(void) > test_attach_api_syms(); > if (test__start_subtest("attach_api_fails")) > test_attach_api_fails(); > + if (test__start_subtest("bench_attach")) > + test_bench_attach(); > } > diff --git a/tools/testing/selftests/bpf/progs/kprobe_multi_empty.c b/tools/testing/selftests/bpf/progs/kprobe_multi_empty.c > new file mode 100644 > index 000000000000..be9e3d891d46 > --- /dev/null > +++ b/tools/testing/selftests/bpf/progs/kprobe_multi_empty.c > @@ -0,0 +1,12 @@ > +// SPDX-License-Identifier: GPL-2.0 > +#include > +#include > +#include > + > +char _license[] SEC("license") = "GPL"; > + > +SEC("kprobe.multi/*") use SEC("kprobe.multi") to make it clear that we are attaching it "manually"? > +int test_kprobe_empty(struct pt_regs *ctx) > +{ > + return 0; > +} > -- > 2.35.1 >