Received: by 2002:a19:771d:0:0:0:0:0 with SMTP id s29csp1236459lfc; Wed, 1 Jun 2022 12:38:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzBPOhuqBXMoTE5LYAPVCJ5YcBKVOUsXVepBTwj7qmjllQcUayZQAUwMIQCQ9ufatH4IbKJ X-Received: by 2002:a05:6a00:894:b0:518:7f19:f21d with SMTP id q20-20020a056a00089400b005187f19f21dmr56551728pfj.4.1654112293851; Wed, 01 Jun 2022 12:38:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654112293; cv=none; d=google.com; s=arc-20160816; b=wBOryEKI7REBA9xwj5167mxEZHa9aALgjAT50AqW1Kp1PBEemhbl5oUOAVT1Zlr39m Zf0aV6lQfUjONneHHaq/rxVaHm0nkWgOnV6kYTLGqLu+2mgXOzruGkg3w7W4iv7Dnmkg ahG/Svbsle/erQwvN3Nior6EwAuapiCJWm4RSjgt/fbx+VKvwf/MWkNTkvC0Y3Be8rjA 8VCyL/s8F7aiM0CbFvMM715hp8inadAUoc7+R9/hchIJRQqX5p7HQesyJ5hux6iuo592 DWc5LZ6uc18r9eX73wP8FaTGsScdbTFMfStcq84RoEPJcAW8cwV/zyTQuTRrLKi1o3fF wzCA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:subject:user-agent:mime-version:date:message-id :dkim-signature; bh=zgtg5YY4jxLLXJWg7yCH0UX5NIavoSEKqMcQkwk1jy8=; b=CW7mR6MsLCOd4ndtxqSv5smP28jVwpFjMlF+F0BLgEU4O2JroRfnuSzoIGc42OxG/e vZhlMGh/L2hVAxkh78C0m+YU4AkA/geGqDRMzzujWGPRskowtPzlEeELX13wQ1ONxdgt Dtr6nhWSh03az4gfv+oPME5TnRP8PhbUD4B1B1Y7Whh2NSZVgvUXEqW6lZbAMnLga+Kl XruhBedPUqIy0Iw1fKuv8NvKXj0ap/RqQHPvGPvTLxiu1jsNgHjy/GNHBFOdI62STkoV wn+b6iUUV+uLaeCk79+d71KJYcuNp+swfNIOYURxqEbLYpzbs7hFhOQCQHApsJIa5lFX XPZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b="iVctfEk/"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id bc14-20020a656d8e000000b003fba60e01e1si3261263pgb.546.2022.06.01.12.38.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jun 2022 12:38:13 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b="iVctfEk/"; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 053D51BC783; Wed, 1 Jun 2022 12:06:22 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352597AbiFALSA (ORCPT + 99 others); Wed, 1 Jun 2022 07:18:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351216AbiFALR5 (ORCPT ); Wed, 1 Jun 2022 07:17:57 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9426262A27 for ; Wed, 1 Jun 2022 04:17:56 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id g205so1661378pfb.11 for ; Wed, 01 Jun 2022 04:17:56 -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=zgtg5YY4jxLLXJWg7yCH0UX5NIavoSEKqMcQkwk1jy8=; b=iVctfEk/aFz/ZdHQcUCWxtMjHH035La+UIBcOyoXJYzVxhVcfdCBsimFa2OeG10qXR maNOi9bczGYUXgMLMcEvpBHDNXdTTs2rmLUjAM6ZLLjduXPmK/oUY8Pup6HWDJ5gNed7 TUN4TBaNb1xWmciQ9QgeJoExJCcLg81GwEhVJpn75RZN36wTHpre3s+P1z2cc3v9y8zn 6ICqbv33zoLhoCxChTilA+BxiYG24A3BIAMouwbclWo+G4vf/n5Bd8EWR0xyQa9sd64I GFe7+1F84SQnvV4lk0zYEvy69QgDlI0+qv3xYFbPYQwVMlkqdJQ/1geI0vCl4v/9Klz7 X+Fw== 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=zgtg5YY4jxLLXJWg7yCH0UX5NIavoSEKqMcQkwk1jy8=; b=EoNyaAwW5Lq0GfAWlf71PhA2ZF6vQrfKF64TgXOMkhjwe/sH7PQqvCTliINAwH9XpW Hzh0AxOcgtNbBDBK/nEVTfhn6ceBRJWhx4SoXi05jo+IiH+Rv2B6ZJSRaFxxamTAnToO mu+QqRX0bncutGt4ghBY0ohJ5+dEzkIMIXJeboaL+Wp49+Zf122ymU4w1oLaqcLm048m G81k0LUiNKaU2alciSQl788uMx+EMvmb2LoTgKiOTtmw77LIwfqAi+DdVUJkZVPwBx8B PFce6bqcjj+66jj6iHWLfCObmeA/DhWXPC00yfaKF7G9zfZbB77WTLGNJ5HHKUX3Pi2H FHOA== X-Gm-Message-State: AOAM533IEFnpxWYrPYjiNW511DpuCQz5EeQfUUxCXcfgdLplkSKyUHaj 9CwbYZholodo5UK+vjBKOKPU3A== X-Received: by 2002:a05:6a00:cd2:b0:518:e103:7cee with SMTP id b18-20020a056a000cd200b00518e1037ceemr37788845pfv.67.1654082276096; Wed, 01 Jun 2022 04:17:56 -0700 (PDT) Received: from [10.71.57.194] ([139.177.225.241]) by smtp.gmail.com with ESMTPSA id x18-20020aa79ad2000000b0051bbbf14c6csm349622pfp.55.2022.06.01.04.17.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 01 Jun 2022 04:17:55 -0700 (PDT) Message-ID: <041465f0-0fd3-fd39-0dac-8093a1c98c00@bytedance.com> Date: Wed, 1 Jun 2022 19:17:48 +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: Re: [PATCH v4 2/2] selftest/bpf/benchs: Add bpf_map benchmark To: Alexei Starovoitov 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 References: <20220601084149.13097-1-zhoufeng.zf@bytedance.com> <20220601084149.13097-3-zhoufeng.zf@bytedance.com> From: Feng Zhou In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 在 2022/6/1 下午5:53, Alexei Starovoitov 写道: > On Wed, Jun 1, 2022 at 10:42 AM Feng zhou wrote: >> +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 = 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 = bpf_get_prandom_u32() % MAX_ENTRIES + MAX_ENTRIES; > What is the point of random ? > just key = MAX_ENTRIES would be the same, no? > or key = -1 ? If all threads on different cpu trigger sys_getpgid and lookup the same key, it will cause "ret = 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. > >> + u32 cpu = bpf_get_smp_processor_id(); >> + u64 start_time = bpf_ktime_get_ns(); >> + >> + bpf_loop(nr_loops, loop_update_callback, &key, 0); >> + percpu_time[cpu & 255] = bpf_ktime_get_ns() - start_time; >> + return 0; >> +} >> -- >> 2.20.1 >>