From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C6E87C433EF for ; Thu, 26 May 2022 02:09:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345909AbiEZCJC (ORCPT ); Wed, 25 May 2022 22:09:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232001AbiEZCI7 (ORCPT ); Wed, 25 May 2022 22:08:59 -0400 Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C8CD69B4C for ; Wed, 25 May 2022 19:08:59 -0700 (PDT) Received: by mail-pj1-x1032.google.com with SMTP id nn3-20020a17090b38c300b001e0e091cf03so23382pjb.1 for ; Wed, 25 May 2022 19:08:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:to:cc:references :from:in-reply-to:content-transfer-encoding; bh=R7rKNvHXsGzLgjMUdkYaFVed5E2JRJcJJNqZfVZ+5rk=; b=co6cy7kfyLhyWRoqI9xLrDZWZ4RkKwnrUf88l8B6e1qN1ihtUyVs25s3wWNnfPY0kM +mxYx5A8uRu/udu4clhRH0E4qEVWGY98p7D4oJoSshLcEbPjvb08+mXZYFmkYwLBZU0o 9ayYBUL7m3SIvvbu4eJZ+EC7Mp9R4qocfaHcfpDwplTFDxIOUWGCecuHw3A4ICWncNVQ 0oEefde8JiCMO6/hHIFWCfjVMdqmHrWAF3lz4IlTHicLwIy/Q1himKOYQOtuVr8nNlS6 utygQAbCTcWDyekohJJeT8axFIOuiSzq6x/lqJyA3UIol+TFIj9quxF0Yb/U2Gc/RWgy R54w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :to:cc:references:from:in-reply-to:content-transfer-encoding; bh=R7rKNvHXsGzLgjMUdkYaFVed5E2JRJcJJNqZfVZ+5rk=; b=TjQfK7zt5IzF50hL9KckJl68negJWxpuGfg2m9HRRnLnJBW2a7QVyJ50DqlBweRGZm MEh+rBO3WN8Qtx4bTfutrrYNmyAeEssAPDf36sge/IS6CwAvSYTXJ1Oh2rBbgDLLbMYu OvXRSbTI8cQd7aiA7HQP4DeL/FjJT3qbZneZckk8ZPRlV3970Zy59R3YKDHetVnFq8Y6 q4K4XMcIvGP8bGaWvfzXlotntCjN0+fnfCuewkuGzN/9xrWLMmwezYgJ33BbpPqn6nc4 JzqaHevIGCWqye8Cor80fds4VQzLRz58XtvoiKBEt9HRvIir7B8Ev2/Y2W1blONpcJAH Fr2g== X-Gm-Message-State: AOAM530FU3YZeb5/et47vWKpTOXxn8VW/EKdkJJ+9lB/PBwe7OcOFw3k sdM60XH4o/6hMAM+51El0butb2wWLujLE6FG X-Google-Smtp-Source: ABdhPJwGanAZG3Fj5Jtt06ObKLk1KKtCz0LEo3zEuRu6eg3wdFoGtq3zxEAPPb46K4UWT2YaWLQFeQ== X-Received: by 2002:a17:902:f605:b0:14f:5d75:4fb0 with SMTP id n5-20020a170902f60500b0014f5d754fb0mr35495209plg.101.1653530938546; Wed, 25 May 2022 19:08:58 -0700 (PDT) Received: from [10.71.57.194] ([139.177.225.225]) by smtp.gmail.com with ESMTPSA id g1-20020a056a001a0100b0051868677e6dsm82610pfv.51.2022.05.25.19.08.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 25 May 2022 19:08:58 -0700 (PDT) Message-ID: <1f291e35-808a-92f2-f93a-1bc5c8c3e44d@bytedance.com> Date: Thu, 26 May 2022 10:08:51 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.9.0 Subject: Re: [External] Re: [PATCH v2 2/2] selftest/bpf/benchs: Add bpf_map benchmark To: Andrii Nakryiko Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin Lau , Song Liu , Yonghong Song , john fastabend , KP Singh , Networking , bpf , open list , duanxiongchun@bytedance.com, Muchun Song , Dongdong Wang , Cong Wang , zhouchengming@bytedance.com References: <20220524075306.32306-1-zhoufeng.zf@bytedance.com> <20220524075306.32306-3-zhoufeng.zf@bytedance.com> From: Feng Zhou In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 在 2022/5/25 上午7:29, Andrii Nakryiko 写道: > On Tue, May 24, 2022 at 12:53 AM Feng zhou wrote: >> From: Feng Zhou >> >> Add benchmark for hash_map to reproduce the worst case >> that non-stop update when map's free is zero. >> >> Signed-off-by: Feng Zhou >> --- >> tools/testing/selftests/bpf/Makefile | 4 +- >> tools/testing/selftests/bpf/bench.c | 2 + >> .../selftests/bpf/benchs/bench_bpf_map.c | 78 +++++++++++++++++++ >> .../selftests/bpf/benchs/run_bench_bpf_map.sh | 10 +++ >> .../selftests/bpf/progs/bpf_map_bench.c | 27 +++++++ >> 5 files changed, 120 insertions(+), 1 deletion(-) >> create mode 100644 tools/testing/selftests/bpf/benchs/bench_bpf_map.c >> create mode 100755 tools/testing/selftests/bpf/benchs/run_bench_bpf_map.sh >> create mode 100644 tools/testing/selftests/bpf/progs/bpf_map_bench.c >> > [...] > >> +static void setup(void) >> +{ >> + struct bpf_link *link; >> + int map_fd, i, max_entries; >> + >> + setup_libbpf(); >> + >> + ctx.skel = bpf_map_bench__open_and_load(); >> + if (!ctx.skel) { >> + fprintf(stderr, "failed to open skeleton\n"); >> + exit(1); >> + } >> + >> + link = bpf_program__attach(ctx.skel->progs.benchmark); >> + if (!link) { >> + fprintf(stderr, "failed to attach program!\n"); >> + exit(1); >> + } >> + >> + //fill hash_map > don't use C++ comments Ok, will do. Thanks. > >> + map_fd = bpf_map__fd(ctx.skel->maps.hash_map_bench); >> + max_entries = bpf_map__max_entries(ctx.skel->maps.hash_map_bench); >> + for (i = 0; i < max_entries; i++) >> + bpf_map_update_elem(map_fd, &i, &i, BPF_ANY); >> +} >> + >> +const struct bench bench_bpf_map = { >> + .name = "bpf-map", > this is too generic name, it's testing one particular scenario, so > call this out in the name. bpf-hashmap-full-update or something (same > for all the relevant function and file names) > Ok, will do. Thanks. >> + .validate = validate, >> + .setup = setup, >> + .producer_thread = producer, >> + .consumer_thread = consumer, >> + .measure = measure, >> + .report_progress = ops_report_progress, >> + .report_final = ops_report_final, >> +}; >> diff --git a/tools/testing/selftests/bpf/benchs/run_bench_bpf_map.sh b/tools/testing/selftests/bpf/benchs/run_bench_bpf_map.sh >> new file mode 100755 >> index 000000000000..d7cc969e4f85 >> --- /dev/null >> +++ b/tools/testing/selftests/bpf/benchs/run_bench_bpf_map.sh >> @@ -0,0 +1,10 @@ >> +#!/bin/bash >> +# SPDX-License-Identifier: GPL-2.0 >> + >> +source ./benchs/run_common.sh >> + >> +set -eufo pipefail >> + >> +nr_threads=`expr $(cat /proc/cpuinfo | grep "processor"| wc -l) - 1` >> +summary=$($RUN_BENCH -p $nr_threads bpf-map) >> +printf "$summary" >> diff --git a/tools/testing/selftests/bpf/progs/bpf_map_bench.c b/tools/testing/selftests/bpf/progs/bpf_map_bench.c >> new file mode 100644 >> index 000000000000..655366e6e0f4 >> --- /dev/null >> +++ b/tools/testing/selftests/bpf/progs/bpf_map_bench.c >> @@ -0,0 +1,27 @@ >> +// SPDX-License-Identifier: GPL-2.0 >> +/* Copyright (c) 2022 Bytedance */ >> + >> +#include "vmlinux.h" >> +#include >> +#include "bpf_misc.h" >> + >> +char _license[] SEC("license") = "GPL"; >> + >> +#define MAX_ENTRIES 1000 >> + >> +struct { >> + __uint(type, BPF_MAP_TYPE_HASH); >> + __type(key, u32); >> + __type(value, u64); >> + __uint(max_entries, MAX_ENTRIES); >> +} hash_map_bench SEC(".maps"); >> + >> +SEC("fentry/" SYS_PREFIX "sys_getpgid") >> +int benchmark(void *ctx) >> +{ >> + u32 key = bpf_get_prandom_u32(); >> + u64 init_val = 1; >> + >> + bpf_map_update_elem(&hash_map_bench, &key, &init_val, BPF_ANY); >> + return 0; >> +} >> -- >> 2.20.1 >>