Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp5817691ioo; Wed, 1 Jun 2022 13:13:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3tHGyntsw4dsWR0ILwokwAd8Gho63DaKPSmJNpEPV1R6dp+UqMWi9g6K9M41sbSdFPSUS X-Received: by 2002:a17:903:1205:b0:15e:8cbc:fd2b with SMTP id l5-20020a170903120500b0015e8cbcfd2bmr1121716plh.99.1654114427481; Wed, 01 Jun 2022 13:13:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654114427; cv=none; d=google.com; s=arc-20160816; b=Z/vYYoraHKxuqD8/CHp9cuwbmOTsyyOXddE6OoQLnJGVwgZDRveAqhdmpAumf9Iphe xF2UKreA1eqSNLSn9uQSfsDdq2y8/Lj8V2J9hMQJwRjiXVPzqu1DNKxryvTPd35X8oNH 2H2kzQ54iO9OPddRh50shDqmw3Tc7tLZk/E2UUePZjjym8VV6/lpRJQGuxnpbhCSaDRv C5E8qrzv9grGpvUGPEkkRAA/nS2fff2EnqqsoYzMFaTTdwNndBY9iaiaDmxtBfOsctb8 Kk2hW7aOjOKYWTErHywmt/055hId2b9wFjCV86DgD2RCIQgz41jZYPG7rCTMvAQrAFv4 np9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=lgS1YFKqi2uJamBMChe9mVllG2N97UqDarRjzfMsUHA=; b=okZRZfRSFfWJFOMN9003WH3lOdWx8pNBYBQlfv87BO6Mqdq9dCHXObMFktBWPg1jej CqM3fP+BNjudiLSSGlI66T6EWiY+80eZJKDFW+7QPzuRyqGIMjGgnLYg+3rhSUSL2CsN 9pn8qOsSo9VUegJCqZ27/W4zX4iY5QjLjmhNwCGhAgr5jaxvRpneLOLsgkm1oanLtZPF h6G1JYv9qnQPmkVYVPdVDbjRJYAHCDkRucSyttRy0pScvIQ0pHz5AwPFL5QP+9dy1WLP z6fHOGeXoUo1gIBVyabHlS9lHVzuRXmLCJvAu4j128H2Xc+PPXHbwlvIK/qn+VslcdVp WlFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=k3AZWD76; 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 k11-20020a170902c40b00b00164026896c2si4011399plk.212.2022.06.01.13.13.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 13:13:47 -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=k3AZWD76; 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 B62A957B3D; Wed, 1 Jun 2022 12:27:12 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351268AbiFALiO (ORCPT + 99 others); Wed, 1 Jun 2022 07:38:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229979AbiFALiM (ORCPT ); Wed, 1 Jun 2022 07:38:12 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14FAD1402B; Wed, 1 Jun 2022 04:38:11 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id u12so3138708eja.8; Wed, 01 Jun 2022 04:38:11 -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:content-transfer-encoding; bh=lgS1YFKqi2uJamBMChe9mVllG2N97UqDarRjzfMsUHA=; b=k3AZWD76xz4xvkaZhjc5Lihx1Q8j5csqqFFCXPOgzynZ/ZJfptD505c242PQNC/kHo G1c1IrXEAY+ON8jBfBf6OK0vsb/SYYrdXMv0TXuj1TgnC10vaCfYWOH5tBiFcfIqXPP9 NP0L4l7Xyb+NrOnJF69Be+jLaHTnHXhHLD7wDfoOx44uvVvMhvUdaI4pAwNIwV4gmbSL pvHKj63AaYFegrF10wTl//I4FSdbbuK2tKGjdg4QB7mvdDeSqAW5lttLAm5oi/QFapIM XyjBye5KnRWmXfqzNsn7dL1y80T6M/t11gwfsE20rgtN2FLUMB9o7ZAPALLB3cgU0kGb +sjA== 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:content-transfer-encoding; bh=lgS1YFKqi2uJamBMChe9mVllG2N97UqDarRjzfMsUHA=; b=RQyiuZNTyQ/nfd+MYIOMoqQPLYeSKx+FKFjJvxiUEEycyviyPL9/1lf5cTWmZo92KG Wd0U9H+x3rXjFZYJET4nRB+rgbHATbAAav/v29Xu/GXFrpk2T2JrqxrkRNsghnDwG1KX cOudNG43ZikL8uWwTud+VJivRFiiLExvzHr3lqlrsEo2ewKcZ+l+eXB4k+fp63WMlJzD x/ukGLwwQ3o2lfd4HPffpC3ebej0bM8hGGZyd3pRGPH6irGhW5KR5xByGT+Z3MssqbRM 0a6en+PSnULioCkzmyH4JkJMxBjKk5cdu9hcohQvnjmtT4UgDYVUTbGwKS95m8tvdL+t 3vgA== X-Gm-Message-State: AOAM530HbIJTMkYlaaTQYBQVhPFse8moH1RmHzXoPuHlRbmogWCQhNh1 3gMkViBZy306M6NNAo3slQLZHuCsxPh9+JfO6TE= X-Received: by 2002:a17:907:7da5:b0:6fe:d818:ee49 with SMTP id oz37-20020a1709077da500b006fed818ee49mr44795116ejc.58.1654083489501; Wed, 01 Jun 2022 04:38:09 -0700 (PDT) MIME-Version: 1.0 References: <20220601084149.13097-1-zhoufeng.zf@bytedance.com> <20220601084149.13097-3-zhoufeng.zf@bytedance.com> <041465f0-0fd3-fd39-0dac-8093a1c98c00@bytedance.com> In-Reply-To: <041465f0-0fd3-fd39-0dac-8093a1c98c00@bytedance.com> From: Alexei Starovoitov Date: Wed, 1 Jun 2022 13:37:57 +0200 Message-ID: Subject: Re: Re: [PATCH v4 2/2] selftest/bpf/benchs: Add bpf_map benchmark To: Feng Zhou Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Network Development , bpf , LKML , Xiongchun Duan , Muchun Song , Dongdong Wang , Cong Wang , Chengming Zhou Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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,T_SCC_BODY_TEXT_LINE 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 Wed, Jun 1, 2022 at 1:17 PM Feng Zhou wrote: > > =E5=9C=A8 2022/6/1 =E4=B8=8B=E5=8D=885:53, Alexei Starovoitov =E5=86=99= =E9=81=93: > > On Wed, Jun 1, 2022 at 10:42 AM Feng zhou w= rote: > >> +struct { > >> + __uint(type, BPF_MAP_TYPE_HASH); > >> + __type(key, u32); > >> + __type(value, u64); > >> + __uint(max_entries, MAX_ENTRIES); > >> +} hash_map_bench SEC(".maps"); > >> + > >> +u64 __attribute__((__aligned__(256))) percpu_time[256]; > > aligned 256 ? > > What is the point? > > I didn't think too much about it here, just referenced it from > tools/testing/selftests/bpf/progs/bloom_filter_bench.c > > > > >> +u64 nr_loops; > >> + > >> +static int loop_update_callback(__u32 index, u32 *key) > >> +{ > >> + u64 init_val =3D 1; > >> + > >> + bpf_map_update_elem(&hash_map_bench, key, &init_val, BPF_ANY); > >> + return 0; > >> +} > >> + > >> +SEC("fentry/" SYS_PREFIX "sys_getpgid") > >> +int benchmark(void *ctx) > >> +{ > >> + u32 key =3D bpf_get_prandom_u32() % MAX_ENTRIES + MAX_ENTRIES; > > What is the point of random ? > > just key =3D MAX_ENTRIES would be the same, no? > > or key =3D -1 ? > > If all threads on different cpu trigger sys_getpgid and lookup the same > key, it will cause > "ret =3D htab_lock_bucket(htab, b, hash, &flags); " > the lock competition here is fierce, and unnecessary overhead is > introduced, > and I don't want it to interfere with the test. I see. but using random leaves it to chance. Use cpu+max_entries then?