From patchwork Wed Aug 17 21:04:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexei Starovoitov X-Patchwork-Id: 12946474 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 95391C32772 for ; Wed, 17 Aug 2022 21:04:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 26ADA8D0007; Wed, 17 Aug 2022 17:04:39 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 218B58D0003; Wed, 17 Aug 2022 17:04:39 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0B9558D0007; Wed, 17 Aug 2022 17:04:39 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id F20008D0003 for ; Wed, 17 Aug 2022 17:04:38 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id C89CB415B4 for ; Wed, 17 Aug 2022 21:04:38 +0000 (UTC) X-FDA: 79810313436.08.310FFB1 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by imf12.hostedemail.com (Postfix) with ESMTP id 6FD814008B for ; Wed, 17 Aug 2022 21:04:38 +0000 (UTC) Received: by mail-pf1-f181.google.com with SMTP id 130so12793946pfy.6 for ; Wed, 17 Aug 2022 14:04:38 -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=Y2Iep7E/2mTKKhtTknM/1Uwo/WL5pQSofmmMCSYQizM=; b=l511t2TjU9cNTBOx9nOJrQ6ETMhdEVpE34sc520kV4U+jZ5f1/mHDo0n9OekUckOKy du4HTtixwqbakopIP6DPt7uHyoakZjMbBFFYI2P6BgAezDFSgDnjzXkuF/HgbF4bXKrQ lXjZ2nN+GZMcztKh2LTcO0PENhud63SE9DLHss4fMDYrSDj+rRyftMt0+O6i9+MtgVZd Ygtrzto0rVVXWoQZsLipuFrePxZasxuS8/DFwMdD/qvZ7BPB3uAaYRUWnJZxw12ohn9n 9NJ/1olkJ8lCRS/0zQtacyESI++6VurdVTijINkcRMVs3BDS81X+4ZQ6u/jYBhfY1WFW uvGA== 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=Y2Iep7E/2mTKKhtTknM/1Uwo/WL5pQSofmmMCSYQizM=; b=cLW6xZ2YXeIY1kjRInywyYhuUqRhtm+eKkZhMsHOi0O7zZbxi9l0QcO4H5VaTxuCi5 2QI5K+ATqOqogzBukJAjq98LSaWLJeb910eeMCZZVvVH7iEUYZ2kKpYU+gqCfn0N8j6m MjGw32f3kegSI9UuLAECSigGUFmJcPSPXQp6bSQ03N8xOJlKF/tczqPyG4dk0cVlARoz tELByhu21HJH28OGOCfdspA+A6O3qdJ2Ab4l3pCMoAC7PxINK/Uh2gOTRVQPmtRXyI4K NBm3qAMhT1D9Q0SYVjAoBJ0mZYPsDVCH0m6Wk7ePB8YyBgqBsVrBxVj9K5PDnuLkr9H2 rKNQ== X-Gm-Message-State: ACgBeo0Rp3/kHH9Mrk0gNFStnRTQGhwpZhjbh3nWNteKO5/Skc0G0PFU w4B650XtoCK/ckXJcMTyMYI= X-Google-Smtp-Source: AA6agR45GVBnh/AwT6HQavfsDbI0KSDhUWRxLAFnLHiMWYdzeBKVe1kvgvJtDJgwHUoWoAjHWT8J1g== X-Received: by 2002:a63:54c:0:b0:429:ee05:92 with SMTP id 73-20020a63054c000000b00429ee050092mr28661pgf.587.1660770277392; Wed, 17 Aug 2022 14:04:37 -0700 (PDT) Received: from localhost.localdomain ([2620:10d:c090:500::1:ccd6]) by smtp.gmail.com with ESMTPSA id e15-20020a17090301cf00b0016e8178aa9csm346372plh.210.2022.08.17.14.04.35 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 17 Aug 2022 14:04:36 -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 v2 bpf-next 04/12] samples/bpf: Reduce syscall overhead in map_perf_test. Date: Wed, 17 Aug 2022 14:04:11 -0700 Message-Id: <20220817210419.95560-5-alexei.starovoitov@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220817210419.95560-1-alexei.starovoitov@gmail.com> References: <20220817210419.95560-1-alexei.starovoitov@gmail.com> MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=l511t2Tj; spf=pass (imf12.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.210.181 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1660770277; a=rsa-sha256; cv=none; b=HCCDoM5WbygOs4qkLj2h6a3Yk5MIN6Dfg4sPykA2RiZ6xIgn7PV5UJ4ojykr6oWCtrTvA4 6BKPF7PqZF74vLNgO2no+plbN95oN599bWz4GOZQTpRSZcfwfmhAcM/Pd7QWKER43WWCmw cJxIHTVh6i5Qth5DnHUSki6xouu2lKo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1660770277; 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=Y2Iep7E/2mTKKhtTknM/1Uwo/WL5pQSofmmMCSYQizM=; b=cTsorZbbHs3owGr2FEtAtK3ZBQqzLoSngJDLnWGXt/ItiwcO7EiQNW4qZ9EpTGytAylATn PvPSTjy7ICRfMC8b1kZUFL4HOUvmNYgVVVSs8MtJcfQYdi6PoWsfDU6er85CTzAuM7nUX2 XEAOv37sXfU7ts0MGQP4p3P8ga6aeSc= X-Rspamd-Queue-Id: 6FD814008B Authentication-Results: imf12.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=l511t2Tj; spf=pass (imf12.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.210.181 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspam-User: X-Rspamd-Server: rspam09 X-Stat-Signature: yrid571dif5ok38ddw5uesddnb9jq5ez X-HE-Tag: 1660770278-529603 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. 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) {