Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp584019lqm; Wed, 1 May 2024 09:24:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUACc65RvAbT87hLa71Fkj/NFRRO6JOb6kimlOY1bXpWXSQ1EqjUl+rMQfY05y3sLQ5U6o4e1PO/O85kFg9LEaYKXPN8a6zaxc1eAFpQw== X-Google-Smtp-Source: AGHT+IHcUaDwrIZXXAMb6zNx05/edWN0ri9E3EY2jG2oAc1gHzBsMoy45JuvByVGWYmGNgn20zd9 X-Received: by 2002:a05:6a20:7290:b0:1ad:7e5:4594 with SMTP id o16-20020a056a20729000b001ad07e54594mr4132559pzk.53.1714580674460; Wed, 01 May 2024 09:24:34 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714580674; cv=pass; d=google.com; s=arc-20160816; b=kM0Dtx+x+NZZE3bH9pPI/TZLgVc29juteo6wwuL+QvHn7QqWQDtuZKFpEdYg9jdJ7s 8lCdig1xxV8VqyL+SFR3Jxl3K1VhQ41V3fW3f0eJr/2QnEaU6rLkEqoiXDboj9ruyT0P YkXnpETIb/2kRKQr2d42QLUlfTPAXOqmNUUz4vap6nu0xziMRCKC9cv2Jz7o2jhNkLJY ArwGCxDasE13+/kFmhmcNHV4aH8pwjJD6/dM3zDcHvWCxXkQ2CmFzaftjB/Hgfb5DTBA w6rkZQxEyJ7WMJSSA1liz8LD2sYmBARfgPjpqoHbedcDRcWug09IQyaERMTX/8STKliW VHyA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:in-reply-to:subject:cc:to:from:date :dkim-signature; bh=kkR7wev4WRUgxKbSEUDA+ZDIQOve893H52tRUH6J0XU=; fh=lhkSLS74ngNovNMdcd48ChRMlQtaFjtZciHzbH2MVX8=; b=Sxz8oU0HjxKeN3nxSS4eVfEX8NTKd7yoV/xZ+WILg6ncxNRIN+aqlJpLSAe7oL+w4A zBNQkUfM0RkjVH3peX1rj0MoXrCCUQinQPpJOknJAaxQEzJwjh06Q9fh4rLthVzF5eY4 KE8KzffdeNA02mVKOqZEW3ePTSa6OF6/WA7coSF7xe4KPQQRpcapKqCA79I5Sq1h7dI6 8vzl0u8r6jptF9W7eMCqyEJpbPCPZd+lhlIyv4cLdL91y7usXlnB27OYMvfg4AaufB17 E55YqMTh+jotcnax0xFwRAks1SiSbrPaiyqBefqywSqMt35xQBBwq/d691/iK1AmUTub veaw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gentwo.org header.s=default header.b=o6UMsQ6s; arc=pass (i=1 spf=pass spfdomain=gentwo.org dkim=pass dkdomain=gentwo.org dmarc=pass fromdomain=gentwo.org); spf=pass (google.com: domain of linux-kernel+bounces-165572-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-165572-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=gentwo.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id jc24-20020a056a006c9800b006e691660a08si24862007pfb.40.2024.05.01.09.24.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 09:24:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-165572-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gentwo.org header.s=default header.b=o6UMsQ6s; arc=pass (i=1 spf=pass spfdomain=gentwo.org dkim=pass dkdomain=gentwo.org dmarc=pass fromdomain=gentwo.org); spf=pass (google.com: domain of linux-kernel+bounces-165572-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-165572-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=gentwo.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 7129E281312 for ; Wed, 1 May 2024 16:24:08 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 5FF6F13049C; Wed, 1 May 2024 16:24:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=gentwo.org header.i=@gentwo.org header.b="o6UMsQ6s" Received: from gentwo.org (gentwo.org [62.72.0.81]) (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 0C6FD53368; Wed, 1 May 2024 16:24:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=62.72.0.81 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714580642; cv=none; b=aJpWKXoYm4ovVVO8va1gNlJIYqmmCeH9lSUesEWstztrSFCu7G/s1GPcP1rtCrnrarEoSqwaSVLcu1xjfFqnKWKqnX0fn6wE/Al1/OoTfnUz2/p9MPE9mN32JVTH3R1l6JfZVrk0qQBaLSHLptppNL90VNLhqQ3aKfW4AoqGyAk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714580642; c=relaxed/simple; bh=l0V5HGu95kO5qgq2XS1KnTgZewpsITQF5ij/V9NUhTw=; h=Date:From:To:cc:Subject:In-Reply-To:Message-ID:References: MIME-Version:Content-Type; b=jTtRTtXPRihxfHNzt4jS2VUcSBFlDMUzYc4t1SjSS1PoKrl+TidFRXtaOz69UEXm76DbA6Ywh0pK969+rIEB53nSsUWThsGGQtrHJd/BzXryql76JClkVMz72nvyzOgs+vofr0lhsDWVj79uJkshApzgm9KmLzp6pnrz5PLFHFE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=gentwo.org; spf=pass smtp.mailfrom=gentwo.org; dkim=pass (1024-bit key) header.d=gentwo.org header.i=@gentwo.org header.b=o6UMsQ6s; arc=none smtp.client-ip=62.72.0.81 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=gentwo.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gentwo.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gentwo.org; s=default; t=1714580634; bh=l0V5HGu95kO5qgq2XS1KnTgZewpsITQF5ij/V9NUhTw=; h=Date:From:To:cc:Subject:In-Reply-To:References:From; b=o6UMsQ6sBVUOoaOZnWF/sGLQ06jDahYjn1yG58Zj8f/sPqM5EJTE9PDq3TGyGZAkB 4ExEHxc61W8I9dRB9Yu1n3z9lyHxsPGppi3d/EpzUDIOhdq102bFnCitDvQduLhHn1 RSA9/CYJ17jtmjE1lShn5dDPPc04sU+HYfBOl6eU= Received: by gentwo.org (Postfix, from userid 1003) id 85081401D5; Wed, 1 May 2024 09:23:54 -0700 (PDT) Received: from localhost (localhost [127.0.0.1]) by gentwo.org (Postfix) with ESMTP id 829A5401C3; Wed, 1 May 2024 09:23:54 -0700 (PDT) Date: Wed, 1 May 2024 09:23:54 -0700 (PDT) From: "Christoph Lameter (Ampere)" To: Puranjay Mohan cc: Catalin Marinas , Will Deacon , Sumit Garg , Stephen Boyd , Douglas Anderson , "Peter Zijlstra (Intel)" , Thomas Gleixner , Mark Rutland , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org, puranjay12@gmail.com, Russell King Subject: Re: [PATCH] arm64: implement raw_smp_processor_id() using thread_info In-Reply-To: <20240501154236.10236-1-puranjay@kernel.org> Message-ID: <76b26dc9-af60-ee7f-6be5-dc17937b4a51@gentwo.org> References: <20240501154236.10236-1-puranjay@kernel.org> 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=US-ASCII; format=flowed On Wed, 1 May 2024, Puranjay Mohan wrote: > Dump of assembler code for function bpf_get_smp_processor_id: > 0xffff8000802cd608 <+0>: nop > 0xffff8000802cd60c <+4>: nop > 0xffff8000802cd610 <+8>: adrp x0, 0xffff800082138000 > 0xffff8000802cd614 <+12>: mrs x1, tpidr_el1 > 0xffff8000802cd618 <+16>: add x0, x0, #0x8 > 0xffff8000802cd61c <+20>: ldrsw x0, [x0, x1] > 0xffff8000802cd620 <+24>: ret In general arm64 has inefficient per cpu variable access. On x86 it is possible to access the processor id via a segment register relative access with a single instruction. Arm64 calculates the address of a percpu variable for each access. This result in inefficiencies because: 1. The address calculation is processor specific. Therefore preemption needs to be disabled during the calculation of the address and while it is in use. 2. Additional registers are used causing the compiler to potentially generate less efficient code. 3. Even RMV instructions on percpu variables require the disabling of preemption due to the address calculation. Russel King has a patchset for NUMA text replication and as part of that he introduces per cpu kernel page tables. https://lwn.net/Articles/957023/ If we had per cpu page tables then we could create a mapping for a fixed address virtual memory range to the physical per cpu area for each cpu. With that the address calculation would no longer be necessary for per cpu variable access and workarounds like this would not be necessary anymore. The retrieval of the cpu id would be a single instruction that performs a load from a fixed virtual address. No preemption etc would be required.