From mboxrd@z Thu Jan 1 00:00:00 1970 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6F40C54EAA for ; Tue, 31 Jan 2023 00:23:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229379AbjAaAXQ (ORCPT ); Mon, 30 Jan 2023 19:23:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229692AbjAaAXP (ORCPT ); Mon, 30 Jan 2023 19:23:15 -0500 Received: from out-231.mta0.migadu.com (out-231.mta0.migadu.com [IPv6:2001:41d0:1004:224b::e7]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82C8E12586 for ; Mon, 30 Jan 2023 16:23:14 -0800 (PST) Message-ID: <23c1f484-380a-c112-86a1-5e104fb981f9@linux.dev> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1675124591; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dhdu29yOG2JI4UvfvGh5x55VRMVl1NSwl/G8pQdFaD8=; b=S1rQSfmssl2ttXW1yS6lMQrtFRnTTYLceNIVviWd5sOnCbzW9P0NsooRe4BZmzFvMdXc2g AGqP3b/nnKRdxiHERK5SypOF85be0LSXXsUjbeU5WaqZGWK4VmRLQN41sTaVkWY3OYCDHa YDkGz83l8AcfOXIOUF1MAJ59ddTAGHY= Date: Mon, 30 Jan 2023 16:22:57 -0800 MIME-Version: 1.0 Subject: Re: [PATCH bpf-next 6/6] selftest/bpf/benchs: Add benchmark for hashmap lookups Content-Language: en-US To: Anton Protopopov References: <20230127181457.21389-1-aspsk@isovalent.com> <20230127181457.21389-7-aspsk@isovalent.com> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Martin KaFai Lau Cc: bpf@vger.kernel.org, Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , John Fastabend In-Reply-To: <20230127181457.21389-7-aspsk@isovalent.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org On 1/27/23 10:14 AM, Anton Protopopov wrote: > +/* The number of slots to store times */ > +#define NR_SLOTS 32 > + > +/* Configured by userspace */ > +u64 nr_entries; > +u64 nr_loops; > +u32 __attribute__((__aligned__(8))) key[256]; > + > +/* Filled by us */ > +u64 __attribute__((__aligned__(256))) percpu_times_index[NR_SLOTS]; > +u64 __attribute__((__aligned__(256))) percpu_times[256][NR_SLOTS]; > + > +static inline void patch_key(u32 i) > +{ > +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ > + key[0] = i + 1; > +#else > + key[0] = __builtin_bswap32(i + 1); > +#endif > + /* the rest of key is random and is configured by userspace */ > +} > + > +static int lookup_callback(__u32 index, u32 *unused) > +{ > + patch_key(index); > + return bpf_map_lookup_elem(&hash_map_bench, key) ? 0 : 1; > +} > + > +static int loop_lookup_callback(__u32 index, u32 *unused) > +{ > + return bpf_loop(nr_entries, lookup_callback, NULL, 0) ? 0 : 1; > +} > + > +SEC("fentry/" SYS_PREFIX "sys_getpgid") > +int benchmark(void *ctx) > +{ > + u32 cpu = bpf_get_smp_processor_id(); > + u32 times_index; > + u64 start_time; > + > + times_index = percpu_times_index[cpu & 255] % NR_SLOTS; percpu_times_index only has NR_SLOTS (32) elements? > + start_time = bpf_ktime_get_ns(); > + bpf_loop(nr_loops, loop_lookup_callback, NULL, 0); > + percpu_times[cpu & 255][times_index] = bpf_ktime_get_ns() - start_time; > + percpu_times_index[cpu & 255] += 1; > + return 0; > +}