Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1258076lqm; Thu, 2 May 2024 09:18:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVnrgT+oPsorbxxlvK01aOdfEL7WOq4gftewCJArFL10yHpKxcUHibwmqyllPYtwebxKG1yCc+FVf9zNIDTAXYRqluH488Ww0SQcwIB3Q== X-Google-Smtp-Source: AGHT+IGVyAITj3W5uAbplyp25Qq14lIAuIFSyUenW0ZY81UKvjIfVxEs2V7HO7cCJ3ZVNK+ND8SY X-Received: by 2002:a05:6122:9a8:b0:4d3:34f4:7e99 with SMTP id g40-20020a05612209a800b004d334f47e99mr518956vkd.0.1714666709233; Thu, 02 May 2024 09:18:29 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714666709; cv=pass; d=google.com; s=arc-20160816; b=cUASr/e0QRGy7O+DJ5vCiX2ky9caFAR01r10ofpG5MjRa4PXbaYb2tJvHsuWmQ2U3g cqlPiAwSmyZBt0WIORu90eRk8PpQ1he3zFMmnpcdL3L6unzdTU0fGO4lMGG0rCnQcbko fJ58kNEbW5jr9FbIVc/X15FOkX8VFe4ZtpUuqYfSQLZ7yrmpjkSu31sME6bj/MZBUQuA BoJEdU9Y+CwTRu6AkC02DQeQsGyrHjeqCWKrUqKR4zD6mefQIubxJW9yhBd5WFpNuYIh 9xI/r50TISiGhKjMzWFrTdxDJIRaRkg7tMC5YYSraL8fDiZIuAzxWfzuYqne8HPnJvhw MsyA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:references :in-reply-to:subject:cc:to:from:dkim-signature; bh=PhlRm27gYdVT42Jw079LR+xtnix1N82cokHst6oiPuk=; fh=eCMNwiSB35rm/2YZyuH5hPS0+dDnAIf+TQVj/JSQCOs=; b=UiYzpjN+qRBPdzuPY29y6mtf7b7hoPXyGQD8xT+lvjb2CHbTITLfJYFYH+YBGE4urW jDEHWOyp4QEBF6mDJi2vWbGWJOpq7Z8FaPHq4HDfIC9ydD8cIUseZy6OBZkV/xPRpxaH vQSBrUeyMiwNY7jncjNjR9Mnc9CSFMIH0pKytCR0sDkn3XNnTVVb9jJwR7ncj2SSCOhW IDolyd3obrRMZTyzfyVSG2zvNIi696smn2zrS7cTm8zGRgr5vwu3jbFwy1noUGxzMjXW /7reoKXrXrNE4EwoCxUsP/oNTXfybkQWWL0ZRr4ZrEV0rj0V0k0+qnq+0QgN0Y092d/t T1Kw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DVaarcyh; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-166702-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166702-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id hy6-20020a67e7c6000000b0047c2f0e7c7csi310367vsb.696.2024.05.02.09.18.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 May 2024 09:18:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-166702-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=DVaarcyh; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-166702-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-166702-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id EB99C1C20ECB for ; Thu, 2 May 2024 16:18:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 9BEF415E1EE; Thu, 2 May 2024 16:18:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="DVaarcyh" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AEDBA1586D5; Thu, 2 May 2024 16:18:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714666690; cv=none; b=T5D+1JYx/6oSpkfewmj4dpZRlsN4p1eTD5ZOkbMp0jW778rKvVghAi0MTKzCxajiaslVQh16335TxoTdR0Mg98JqFl77zvamXLrwbucEKeUpBWilcQUbmDVjkB5IKC0ITNWjxkNdvoyT9oSqAIRXaMfHLSaC9UaSER/+2Si82Mw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714666690; c=relaxed/simple; bh=6NQhuMcNkmpWazM0HHYky5tZ2j68IK0b4aybNOPTBRY=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=NDbCq2WaNR2SrJk8hc3plMcHa79Gu4mt39KOJXfNp9NMwRdRpG1FSGG1OBHaYSUJaQy0TomJf6CgeIxqS8Xy3JUqYgA1i72FOATD7INZyhmvHUmchnJR8G+S5X1e5WvLgebfia5AIlGDphSBq3Bnn0Rgd+xTsFvrV6TGUjZYloA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=DVaarcyh; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9CE04C113CC; Thu, 2 May 2024 16:18:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714666690; bh=6NQhuMcNkmpWazM0HHYky5tZ2j68IK0b4aybNOPTBRY=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=DVaarcyhyqTPFst4peTVuc9ArbfOqACLBdPeQH2p0+rqkOhyOVV9Xh7OIoX4FknVF Sn7+gecM7Sz2oICS+8bVUzPW07FGUfDKOPvxD8TmgTuEA5XZEG81KISdQ20CO4ZomE M41E8o8MPBSi10WXCPXPdoqB3wxlXwYidlLSQFevLud01ck5Q34NJdqluekPKBsAmO LgNBL0JWTFWd+X3yljpjs2+pQscTMvQ1icWonnkskJYDbFHVjHM7xGVzJwo8bqmkV9 nwtSs7vru4n/aufQYAj5IYbSkIEykr+3lvf/Em5TCttCsNh5CvAJLZ6F8X72dNCbZk nSwTGsVhdrjuQ== From: =?utf-8?B?QmrDtnJuIFTDtnBlbA==?= To: Andrii Nakryiko , Puranjay Mohan Cc: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Eduard Zingerman , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Paul Walmsley , Palmer Dabbelt , Albert Ou , bpf@vger.kernel.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Pu Lehui , puranjay12@gmail.com Subject: Re: [PATCH bpf-next v2 1/2] riscv, bpf: add internal-only MOV instruction to resolve per-CPU addrs In-Reply-To: References: <20240430175834.33152-1-puranjay@kernel.org> <20240430175834.33152-2-puranjay@kernel.org> Date: Thu, 02 May 2024 18:18:06 +0200 Message-ID: <87jzkcw5kx.fsf@all.your.base.are.belong.to.us> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Andrii Nakryiko writes: > On Tue, Apr 30, 2024 at 10:58=E2=80=AFAM Puranjay Mohan wrote: >> >> Support an instruction for resolving absolute addresses of per-CPU >> data from their per-CPU offsets. This instruction is internal-only and >> users are not allowed to use them directly. They will only be used for >> internal inlining optimizations for now between BPF verifier and BPF >> JITs. >> >> RISC-V uses generic per-cpu implementation where the offsets for CPUs >> are kept in an array called __per_cpu_offset[cpu_number]. RISCV stores >> the address of the task_struct in TP register. The first element in >> task_struct is struct thread_info, and we can get the cpu number by >> reading from the TP register + offsetof(struct thread_info, cpu). >> >> Once we have the cpu number in a register we read the offset for that >> cpu from address: &__per_cpu_offset + cpu_number << 3. Then we add this >> offset to the destination register. >> >> To measure the improvement from this change, the benchmark in [1] was >> used on Qemu: >> >> Before: >> glob-arr-inc : 1.127 =C2=B1 0.013M/s >> arr-inc : 1.121 =C2=B1 0.004M/s >> hash-inc : 0.681 =C2=B1 0.052M/s >> >> After: >> glob-arr-inc : 1.138 =C2=B1 0.011M/s >> arr-inc : 1.366 =C2=B1 0.006M/s >> hash-inc : 0.676 =C2=B1 0.001M/s >> >> [1] https://github.com/anakryiko/linux/commit/8dec900975ef >> >> Signed-off-by: Puranjay Mohan >> --- >> arch/riscv/net/bpf_jit_comp64.c | 24 ++++++++++++++++++++++++ >> 1 file changed, 24 insertions(+) >> >> diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_co= mp64.c >> index 15e482f2c657..99d7006f1420 100644 >> --- a/arch/riscv/net/bpf_jit_comp64.c >> +++ b/arch/riscv/net/bpf_jit_comp64.c >> @@ -12,6 +12,7 @@ >> #include >> #include >> #include >> +#include >> #include "bpf_jit.h" >> >> #define RV_FENTRY_NINSNS 2 >> @@ -1089,6 +1090,24 @@ int bpf_jit_emit_insn(const struct bpf_insn *insn= , struct rv_jit_context *ctx, >> emit_or(RV_REG_T1, rd, RV_REG_T1, ctx); >> emit_mv(rd, RV_REG_T1, ctx); >> break; >> + } else if (insn_is_mov_percpu_addr(insn)) { >> + if (rd !=3D rs) >> + emit_mv(rd, rs, ctx); No biggie, but you did not fold this check into emit_mv(). >> +#ifdef CONFIG_SMP >> + /* Load current CPU number in T1 */ >> + emit_ld(RV_REG_T1, offsetof(struct threa= d_info, cpu), >> + RV_REG_TP, ctx); >> + /* << 3 because offsets are 8 bytes */ >> + emit_slli(RV_REG_T1, RV_REG_T1, 3, ctx); >> + /* Load address of __per_cpu_offset arra= y in T2 */ >> + emit_addr(RV_REG_T2, (u64)&__per_cpu_off= set, extra_pass, ctx); >> + /* Add offset of current CPU to __per_c= pu_offset */ >> + emit_add(RV_REG_T1, RV_REG_T2, RV_REG_T1= , ctx); >> + /* Load __per_cpu_offset[cpu] in T1 */ >> + emit_ld(RV_REG_T1, 0, RV_REG_T1, ctx); >> + /* Add the offset to Rd */ >> + emit_add(rd, rd, RV_REG_T1, ctx); > > is this the right level of code indentation? Looks wrong. When the indent is fixed, feel free to add: Acked-by: Bj=C3=B6rn T=C3=B6pel