From patchwork Fri Aug 26 02:44:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexei Starovoitov X-Patchwork-Id: 12955496 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id BDC3BECAAD1 for ; Fri, 26 Aug 2022 02:44:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 54C36940007; Thu, 25 Aug 2022 22:44:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4FBFD80007; Thu, 25 Aug 2022 22:44:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 39DA894000C; Thu, 25 Aug 2022 22:44:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 2BDEF940007 for ; Thu, 25 Aug 2022 22:44:51 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id F33664049E for ; Fri, 26 Aug 2022 02:44:50 +0000 (UTC) X-FDA: 79840201140.20.E06A09B Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) by imf15.hostedemail.com (Postfix) with ESMTP id 9F032A0017 for ; Fri, 26 Aug 2022 02:44:50 +0000 (UTC) Received: by mail-pf1-f175.google.com with SMTP id 72so306838pfx.9 for ; Thu, 25 Aug 2022 19:44:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc; bh=OsoTVXPQ6+PDC/ic9azQGTBktlzZtn9DYA063dTVrZc=; b=luqFTwYi12weGzQ+UoeVPQSf1nhScJ0NkKyeKThJurowbjiXXy0lv7aSHQe1cfmt1P xsFeT3FWfP1wL7fse38yym5SfqWIyh4hvNqR87ivgRfx/grhUyjD0ldYpBZlAlW7WhtZ r2+NMugZ/qMUoim6eLe2te13jAU5IfUIQS4Y+2NtU9S6Wz8NunrN4afxGSOrBeKppwmH JNU9jyU/KITi1nu7v6ub/xagl13MF8SkYPfqBpdy5+8lJ0COEAHPg2RZMVZXYkWhV/EE zyJl+J0sg+2B70hPvRh9od7DUku2fa69Kr3RJlHmJ0q/Q+yc8K5AGeqMNgQc6alRUODH 47Vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc; bh=OsoTVXPQ6+PDC/ic9azQGTBktlzZtn9DYA063dTVrZc=; b=dp952mUndZjCC27B5Gd2suaF7XL7dnnx4VBfBDoRUdN8uGGHU4LRILAXDiYgP4a395 grnpN+/dnTqA1XkG4WdgscldOAe8BUUQF6cfhwACuenmSGiyjPXOuMETX3xzf7vDaUCN U/5s/7XgFcghH5XaNb2POgK7nR5V5UGH/oDt2KpPDGSW99XtxLnd/fxnBKpjeA3wlaJ+ L2QzRn6KS2XyIEtXz6SO9X2xT/4WXGMjk9cJspLniFMV0Th/6Fn+Dr5WJto80XwvYJ8a 2tNFKxjwKhlwcLrSLLorSGIlkJoA1/OahVMESJ/LHbmSf1+ACkSXeo78RPKMkZmL0/4Y PbdQ== X-Gm-Message-State: ACgBeo2x5/EkdzQV9Cdm7kJ5GRAjYMXW9/h3njB5l0VC8StPCLJNNing Ammrcbb11A52onzIlFF3f+0= X-Google-Smtp-Source: AA6agR6kavHPljuwulMUHsrGVJHdEQX4+1VJhqZ3+3NTWH7ASxAm2WjdfuseM2tmAtrAW00wL8lWGg== X-Received: by 2002:a63:ff09:0:b0:42a:59ee:1775 with SMTP id k9-20020a63ff09000000b0042a59ee1775mr1563462pgi.85.1661481889744; Thu, 25 Aug 2022 19:44:49 -0700 (PDT) Received: from macbook-pro-3.dhcp.thefacebook.com ([2620:10d:c090:400::5:15dc]) by smtp.gmail.com with ESMTPSA id b5-20020a656685000000b00429c5270710sm312596pgw.1.2022.08.25.19.44.48 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 25 Aug 2022 19:44:49 -0700 (PDT) From: Alexei Starovoitov To: davem@davemloft.net Cc: daniel@iogearbox.net, andrii@kernel.org, tj@kernel.org, memxor@gmail.com, delyank@fb.com, linux-mm@kvack.org, bpf@vger.kernel.org, kernel-team@fb.com Subject: [PATCH v4 bpf-next 04/15] samples/bpf: Reduce syscall overhead in map_perf_test. Date: Thu, 25 Aug 2022 19:44:19 -0700 Message-Id: <20220826024430.84565-5-alexei.starovoitov@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220826024430.84565-1-alexei.starovoitov@gmail.com> References: <20220826024430.84565-1-alexei.starovoitov@gmail.com> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1661481890; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=OsoTVXPQ6+PDC/ic9azQGTBktlzZtn9DYA063dTVrZc=; b=w1J+BVa3wCCsKAmd3dd56MFMs/bGqvBGpaQlU9K68K3JQsu868TekseWzp+fgrR1XvGbiE c+ByVCqNWtIkLNIF9afZWFc/ylvDr5YsGjZtCN1Lk4A3uuTNqSkuxeJTQNR49gHx+DUscL ukRfVYON+JzOtqNUGb5MNvOYsPKh1A4= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=luqFTwYi; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf15.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1661481890; a=rsa-sha256; cv=none; b=GF6aLzh0Zn9nLFeTLmtBW2QLepHAS5aiwtY0G7Ix9WqWJJNuBnh1E0wtnr5mZLdodmw/WD FrTG05KVUqWmRERVHUdHuxq3MO/bl9fnD4fW5I0TZir4f/ZixLhRDl4KrVbYzgCrJEuC9h iN6uDoyh4b2Erasz/XuxgJ7LhE03X18= Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=luqFTwYi; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf15.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.210.175 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 9F032A0017 X-Stat-Signature: omttn8fgic3hnybqt8ppnhhjjmpnnmcq X-Rspam-User: X-HE-Tag: 1661481890-680764 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Alexei Starovoitov Make map_perf_test for preallocated and non-preallocated hash map spend more time inside bpf program to focus performance analysis on the speed of update/lookup/delete operations performed by bpf program. It makes 'perf report' of bpf_mem_alloc look like: 11.76% map_perf_test [k] _raw_spin_lock_irqsave 11.26% map_perf_test [k] htab_map_update_elem 9.70% map_perf_test [k] _raw_spin_lock 9.47% map_perf_test [k] htab_map_delete_elem 8.57% map_perf_test [k] memcpy_erms 5.58% map_perf_test [k] alloc_htab_elem 4.09% map_perf_test [k] __htab_map_lookup_elem 3.44% map_perf_test [k] syscall_exit_to_user_mode 3.13% map_perf_test [k] lookup_nulls_elem_raw 3.05% map_perf_test [k] migrate_enable 3.04% map_perf_test [k] memcmp 2.67% map_perf_test [k] unit_free 2.39% map_perf_test [k] lookup_elem_raw Reduce default iteration count as well to make 'map_perf_test' quick enough even on debug kernels. Acked-by: Kumar Kartikeya Dwivedi Signed-off-by: Alexei Starovoitov --- samples/bpf/map_perf_test_kern.c | 44 ++++++++++++++++++++------------ samples/bpf/map_perf_test_user.c | 2 +- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/samples/bpf/map_perf_test_kern.c b/samples/bpf/map_perf_test_kern.c index 8773f22b6a98..7342c5b2f278 100644 --- a/samples/bpf/map_perf_test_kern.c +++ b/samples/bpf/map_perf_test_kern.c @@ -108,11 +108,14 @@ int stress_hmap(struct pt_regs *ctx) u32 key = bpf_get_current_pid_tgid(); long init_val = 1; long *value; + int i; - bpf_map_update_elem(&hash_map, &key, &init_val, BPF_ANY); - value = bpf_map_lookup_elem(&hash_map, &key); - if (value) - bpf_map_delete_elem(&hash_map, &key); + for (i = 0; i < 10; i++) { + bpf_map_update_elem(&hash_map, &key, &init_val, BPF_ANY); + value = bpf_map_lookup_elem(&hash_map, &key); + if (value) + bpf_map_delete_elem(&hash_map, &key); + } return 0; } @@ -123,11 +126,14 @@ int stress_percpu_hmap(struct pt_regs *ctx) u32 key = bpf_get_current_pid_tgid(); long init_val = 1; long *value; + int i; - bpf_map_update_elem(&percpu_hash_map, &key, &init_val, BPF_ANY); - value = bpf_map_lookup_elem(&percpu_hash_map, &key); - if (value) - bpf_map_delete_elem(&percpu_hash_map, &key); + for (i = 0; i < 10; i++) { + bpf_map_update_elem(&percpu_hash_map, &key, &init_val, BPF_ANY); + value = bpf_map_lookup_elem(&percpu_hash_map, &key); + if (value) + bpf_map_delete_elem(&percpu_hash_map, &key); + } return 0; } @@ -137,11 +143,14 @@ int stress_hmap_alloc(struct pt_regs *ctx) u32 key = bpf_get_current_pid_tgid(); long init_val = 1; long *value; + int i; - bpf_map_update_elem(&hash_map_alloc, &key, &init_val, BPF_ANY); - value = bpf_map_lookup_elem(&hash_map_alloc, &key); - if (value) - bpf_map_delete_elem(&hash_map_alloc, &key); + for (i = 0; i < 10; i++) { + bpf_map_update_elem(&hash_map_alloc, &key, &init_val, BPF_ANY); + value = bpf_map_lookup_elem(&hash_map_alloc, &key); + if (value) + bpf_map_delete_elem(&hash_map_alloc, &key); + } return 0; } @@ -151,11 +160,14 @@ int stress_percpu_hmap_alloc(struct pt_regs *ctx) u32 key = bpf_get_current_pid_tgid(); long init_val = 1; long *value; + int i; - bpf_map_update_elem(&percpu_hash_map_alloc, &key, &init_val, BPF_ANY); - value = bpf_map_lookup_elem(&percpu_hash_map_alloc, &key); - if (value) - bpf_map_delete_elem(&percpu_hash_map_alloc, &key); + for (i = 0; i < 10; i++) { + bpf_map_update_elem(&percpu_hash_map_alloc, &key, &init_val, BPF_ANY); + value = bpf_map_lookup_elem(&percpu_hash_map_alloc, &key); + if (value) + bpf_map_delete_elem(&percpu_hash_map_alloc, &key); + } return 0; } diff --git a/samples/bpf/map_perf_test_user.c b/samples/bpf/map_perf_test_user.c index b6fc174ab1f2..1bb53f4b29e1 100644 --- a/samples/bpf/map_perf_test_user.c +++ b/samples/bpf/map_perf_test_user.c @@ -72,7 +72,7 @@ static int test_flags = ~0; static uint32_t num_map_entries; static uint32_t inner_lru_hash_size; static int lru_hash_lookup_test_entries = 32; -static uint32_t max_cnt = 1000000; +static uint32_t max_cnt = 10000; static int check_test_flags(enum test_type t) {