From patchwork Thu Sep 1 16:15:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexei Starovoitov X-Patchwork-Id: 12962887 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 509EEECAAD8 for ; Thu, 1 Sep 2022 16:16:09 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C9518940008; Thu, 1 Sep 2022 12:16:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C1DAF6B009D; Thu, 1 Sep 2022 12:16:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A70D7940008; Thu, 1 Sep 2022 12:16:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 9536D6B009C for ; Thu, 1 Sep 2022 12:16:08 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 691CB1C65FD for ; Thu, 1 Sep 2022 16:16:08 +0000 (UTC) X-FDA: 79864018416.28.0C93285 Received: from mail-pj1-f42.google.com (mail-pj1-f42.google.com [209.85.216.42]) by imf09.hostedemail.com (Postfix) with ESMTP id A5FC3140065 for ; Thu, 1 Sep 2022 16:16:07 +0000 (UTC) Received: by mail-pj1-f42.google.com with SMTP id n65-20020a17090a5ac700b001fbb4fad865so3130848pji.1 for ; Thu, 01 Sep 2022 09:16:07 -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=4+uhdcDVuSjjem7hAR91KRY20zQndt0vkR0L244Rk1E=; b=X3BQnN1FrgHzUYqVbVs1H1+mR0vvs5nam4bT9s2R8NmvUqCWS2jYL5Hx9tovemlNUC VtgRk9Ol9wZ+uMvlqWhA2hO5eBZwi0AEls2phiK4D87fd0bVR9SrCySTZCEsxGBHJt7h SToxP96pnw7JM5j/X6fgZEJl5BvcShX8/P5pLOX8eUeJZAB3IqKw8RPCQNsa6hKBkrYT xqYN+q2GHOo+hHKBst5IWxG+IsKjG0WrqQiYWu1Jwsf2lT3lD7t3WaxLL/1LK5Z/wRsA 2k7wBm+OJ6UczjU3U9M88OdpcVPPcKxavFkS2bDSFlvh3U6yuUu6Tg+uNlmv7TBdrdqj aPDw== 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=4+uhdcDVuSjjem7hAR91KRY20zQndt0vkR0L244Rk1E=; b=iGF0Ik0QSwqsg68MUqWE6tFDm5taU0+z/hjJB26gaLAw3fvhOlMdwYgwZADuweaX/F 1N734z0sI1mgyR0uEzFeQ7+wBZWfopQWN53kZ8zouyuEWyBe+ssMgsgt6nTa8lFLR46D nNG7Cleiy84S06Nf6ezv1YF3l9lSQgbZeoOvDW2WhjkajOW+wC/yJY0JxKk6Q04FI1hw 5V2RW36oIXC/vN+ZbfFs2XeQTkpiV2GRy2VuHKrNWqkxHtdy100OMPWuLLyrCCpn0ZsW LGoMx7oV7eABJit7JdFlT2ukbr3oBEc3qoEdmZW1UHzBQjbpdkcTxmzIEwOwoHufLL3N 6d9g== X-Gm-Message-State: ACgBeo2wMJqz6UJj0bY9DBSzpzKNENgZzP39ooPKiPO6Na1CpB9BDyeX rvwYCULQlRLZwvMHt/XeSNk= X-Google-Smtp-Source: AA6agR5gABxsJnibFAbtnZO6qA0vlV4mshES5C/WYy8Tev8VVQ5AolYNHCMJMYfMtawypsYBlFEzMg== X-Received: by 2002:a17:90a:6001:b0:1fa:e851:3480 with SMTP id y1-20020a17090a600100b001fae8513480mr9452909pji.153.1662048966625; Thu, 01 Sep 2022 09:16:06 -0700 (PDT) Received: from localhost.localdomain ([2620:10d:c090:500::3:4dc5]) by smtp.gmail.com with ESMTPSA id t2-20020a1709027fc200b001708e1a10a3sm14133494plb.94.2022.09.01.09.16.05 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 01 Sep 2022 09:16:06 -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 v5 bpf-next 04/15] samples/bpf: Reduce syscall overhead in map_perf_test. Date: Thu, 1 Sep 2022 09:15:36 -0700 Message-Id: <20220901161547.57722-5-alexei.starovoitov@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220901161547.57722-1-alexei.starovoitov@gmail.com> References: <20220901161547.57722-1-alexei.starovoitov@gmail.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1662048967; a=rsa-sha256; cv=none; b=Ch+Ra8Uc45PfAFyiQvapJ+e3veaMo98+bsw6yeDr5rfLwH6aNBdRyyJH56qvnjdhP8quPo 8kjy5MYeVqL/o7P63BO4KX6DngumuHXamocZXVkmRt/fF5C1aFfMwkUBAmyzlpc/qHDUZz DQbxxIvtZtLUN6RJkHfSIh7+/XW2CTc= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=X3BQnN1F; spf=pass (imf09.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.216.42 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1662048967; 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=4+uhdcDVuSjjem7hAR91KRY20zQndt0vkR0L244Rk1E=; b=OfdsouTHPU+kpAzjsWtbzFAUPWJsZvG1iLNVGQE8eo7J019eKamAR7C5Cd7M7Le4HlwbBo mBG3nimg1OjmGYO/J6UWw85YhsKFpptmGKHE/eSIsCliBEXoaBw0hJX9MsiIQG7LU7D+V1 fUR/rodAMefnupZUyt/xyqPTmE9KAKE= Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=X3BQnN1F; spf=pass (imf09.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.216.42 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: A5FC3140065 X-Stat-Signature: bb8odcoaq8qyds1d189gxs4kpzhkshu6 X-HE-Tag: 1662048967-829662 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 Acked-by: Andrii Nakryiko 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) {