Received: by 2002:ab2:3350:0:b0:1f4:6588:b3a7 with SMTP id o16csp20082lqe; Fri, 5 Apr 2024 11:11:05 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWuIjlD7NtYAt1OpcFQD1DoJrvrn7z5zh7sbXLjuZacoCkRoYq2RPGsZWCVg7dQnX2QtFtPaC6ugTw7QqQ/TRBbfyTCJdZJ2TuV7D6J4w== X-Google-Smtp-Source: AGHT+IHf4T64o0da2BENbAw20KcdpazMkt6jBTIgdjcabVWkGh16W6SO1rrmkMHlh8UtyEBjDKxV X-Received: by 2002:a17:906:bc86:b0:a51:87be:adee with SMTP id lv6-20020a170906bc8600b00a5187beadeemr1716210ejb.45.1712340665063; Fri, 05 Apr 2024 11:11:05 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712340665; cv=pass; d=google.com; s=arc-20160816; b=kMLsLOyfGdKuhjnJqEYKSaghPEK5QCtEyxMNYmTexpO4SRCvVIB/rt2Heverayw9mk 0VmEBXHQg55gxd6cuCswIro0FDJrLcxf1Un/dxJghMyeSgyoCv/YH71RgL+w419GJIyG qQNO7xoSYjeasXjym85JH5lcXWBnOEAZ5PyQLFCWhd44YOKqtabohGDQMPUbbR1xwpXJ c4bOXEFPMATKg/Y5SuhrdSSn3Xu7zbkbJ4vigbiCd9QHX6fMO1TrWAC802LO25poe+om y6cFDvxqAnBNDf3EHtHDHut8SX1ud1TePJbATnUBW6dESRjllb4htJau/SFid91XGDRO ypDA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=oH6LfvKVj4QuobKK/trwqUlflVnFHEvHshhJj8bw+OQ=; fh=JSEMdvebEsr7R2fy6JXSJUg4BEEbxDf7vxC8QlXh9II=; b=u9beZXZ1SACoUnC6akkQIoeUDnANQ/e8D8sO6om1Su7AoSrB5eEuny9sElB+xh1odw vxGtNr8SgyZTeodzrILYb+FoaxLetfXbA6GxkR/Bv3I/cOIPKVGtMmy1jj32W3SR9FnA 2ar4ArOQsTAjTW8STF1Aq61KSf9dC4c5Z9kR7WYy68pUM3PfzCpeF/BLZtoWm6Da7/52 fpmJ56byU/H9nAEPwizoRdaGBB92a61V6K6YW5yOh0oA3FwUk5sdbwiNG3cOhi9MIqoI gbrXBs67RxQJhoT2aQHiB7sKzssTQOqSXFDYUO9FWEM7SmEhm6nP81Vxp1yolcB4lcVi hv7A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ewAbd5Fm; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-133453-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-133453-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id x21-20020a170906135500b00a51a283d334si883919ejb.786.2024.04.05.11.11.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 05 Apr 2024 11:11:05 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-133453-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ewAbd5Fm; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-133453-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-133453-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 936F11F24326 for ; Fri, 5 Apr 2024 18:11:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 05468171E78; Fri, 5 Apr 2024 18:10:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ewAbd5Fm" Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B85CB171E40; Fri, 5 Apr 2024 18:10:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712340655; cv=none; b=QT744Eufi7YTYB90l4IT1/qpJrZBYN6Za4JozEyMignVOSraNHahqX5BBQsrTKAWqLKnbX9KeAoJGrJ2nzFT/vT6zHSVkGbUobtZuMsZ3eoJHAr9KY0gKLIv6zhd4nbZ0+Et4NhdXXMuLVO5wmPTQxH3p06jJUmXtVmZguLeL4g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712340655; c=relaxed/simple; bh=fWSrOr8f8fr5/BXZ8KkPYzpWRfdNWjXg2YH35wIn7nM=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=sq1KbRm6Tx/Poy2sMiZrJzhTvhVd1ITBAxEFUUhxck+qVh5FoF1CjNjPxX9376IyzJNRVJljMBku/w+wWcUkj5jQuGFnxhlPsuN2/ifOEjByyFCzt1/Hm8mjHdzpzSCB1FVIXwz7m6lAetSyMAt7PRYuOf4W5Lvm72fCIV5KhXg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ewAbd5Fm; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1e2232e30f4so22475555ad.2; Fri, 05 Apr 2024 11:10:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1712340653; x=1712945453; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=oH6LfvKVj4QuobKK/trwqUlflVnFHEvHshhJj8bw+OQ=; b=ewAbd5FmGLP2by/UqDCtSwbwNwkc7RzC7dab7b9ktvZkIhFaSvRrmAGI+ooSiqOnTw Bf6EcSiqhBYK5qcoxvocLEAzQ2mFxqhAAwMu3lhENsiHwDP0cPAmmYv8vFVJN4w+fO9i eKLowYMV4v6JIN9H/RP+ho3HKRmhznWHnuvtE9Lp2IUI0l3ygkQq9pndWEhgkCV8mWau +TIbWij8fCLvUdpaMCxIBbARK8ajHk7cOxEpxxo/MNiCd3uCnU6LTg/JyG2jTpFO4unM nCtQUUdvGxnwpdOfaImdW0lqK2eHd7qPwaFH9vW6+wVT3/bu9Gmya20beVDfunJ6XWpE Eskw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712340653; x=1712945453; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oH6LfvKVj4QuobKK/trwqUlflVnFHEvHshhJj8bw+OQ=; b=KKIBCM5uBDyJesI8iJ/SX+hcmFdgHDWeLnsKngbyO6/IjM3Hmtwks8cPis8f+yGxA5 sSbbNvJCIhKCFo4uBquIZwVMr3mPUmR4bRbvjqUW95+GGUzcaZjTc3CWhrYi+LqfNAxg QYgydftgK3U7dqQSCV7pYC6RG/To1qor0Bz5xFfxU6daqv+lYcZCDHOn2WTPxrODx5es 34C2lUB9h7g+lL0eV6MHNz28fwZxDayq+PVa94RpQAnXzFiirWvq6IoVACM+DB2BiIQI eyxSzIjBSDpbZqKaoOL56XaiSNY62OT/rpoykadnOs18eVvMKDNfzDJSRleAOmyq15LH 6eyw== X-Forwarded-Encrypted: i=1; AJvYcCUq/ujsScBqPrEzCmv/CTOOU6KJT7bopMpJjgwPpvbTfgMx4hdK/1cOG2O42trxA6zOtXpNuumQfY8QeCAllymXWwYrHBx0Xts3R2i3PG11X3VEsj9EtxioTBytFFjgfM8f X-Gm-Message-State: AOJu0YwlOGm1Qcmk3ulanTeCSk5+aTdmHo3TAMq1yKMGo56QRC7CRMAs 8MLnTreb8+J/ECzAuuafss64tw0m/D+uTH+Tz0/7V+rtJUJh5KhiiSg23kxuQWZ+bo5UV90T+9d jDrcCP6YF75r24HTByUuPcAvalQk= X-Received: by 2002:a17:902:e751:b0:1de:ffbc:8d95 with SMTP id p17-20020a170902e75100b001deffbc8d95mr2548204plf.67.1712340652945; Fri, 05 Apr 2024 11:10:52 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240405091707.66675-1-puranjay12@gmail.com> In-Reply-To: From: Andrii Nakryiko Date: Fri, 5 Apr 2024 11:10:41 -0700 Message-ID: Subject: Re: [PATCH bpf-next] arm64, bpf: add internal-only MOV instruction to resolve per-CPU addrs To: Alexei Starovoitov Cc: Puranjay Mohan , Catalin Marinas , Will Deacon , 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 , Zi Shen Lim , Xu Kuohai , Florent Revest , linux-arm-kernel , LKML , bpf Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Apr 5, 2024 at 8:48=E2=80=AFAM Alexei Starovoitov wrote: > > On Fri, Apr 5, 2024 at 2:17=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. > > > > Since commit 7158627686f0 ("arm64: percpu: implement optimised pcpu > > access using tpidr_el1"), the per-cpu offset for the CPU is stored in > > the tpidr_el1/2 register of that CPU. > > > > To support this BPF instruction in the ARM64 JIT, the following ARM64 > > instructions are emitted: > > > > mov dst, src // Move src to dst, if src !=3D dst > > mrs tmp, tpidr_el1/2 // Move per-cpu offset of the current cpu in tm= p. > > add dst, dst, tmp // Add the per cpu offset to the dst. > > > > If CONFIG_SMP is not defined, then nothing is emitted if src =3D=3D dst= , and > > mov dst, src is emitted if dst !=3D src. > > > > To measure the performance improvement provided by this change, the > > benchmark in [1] was used: > > > > Before: > > glob-arr-inc : 23.597 =C2=B1 0.012M/s > > arr-inc : 23.173 =C2=B1 0.019M/s > > hash-inc : 12.186 =C2=B1 0.028M/s > > > > After: > > glob-arr-inc : 23.819 =C2=B1 0.034M/s > > arr-inc : 23.285 =C2=B1 0.017M/s > > hash-inc : 12.419 =C2=B1 0.011M/s > > > > [1] https://github.com/anakryiko/linux/commit/8dec900975ef > > You don't see as big of a gain, because bpf_get_smp_processor_id() > is not inlined yet on arm64. > yep, would be nice to add ARM64 and RISC-V support there as well. Though it feels that supporting this in BPF JIT directly might be actually easier for RISC-V/ARM64, not sure? > But even without it I expected bigger gains. > Could you do 'perf report' before/after ? > Just want to see what's on top. I also did `bpftool p d x id ` and `bpftool p d j id ` to validate expected inlined BPF instructions and jitted code. So it might be a good idea to do that as well. Either way, thanks for working on this! > > > > > Signed-off-by: Puranjay Mohan > > --- > > arch/arm64/include/asm/insn.h | 7 +++++++ > > arch/arm64/lib/insn.c | 11 +++++++++++ > > arch/arm64/net/bpf_jit.h | 6 ++++++ > > arch/arm64/net/bpf_jit_comp.c | 16 ++++++++++++++++ > > 4 files changed, 40 insertions(+) > > [...]