From patchwork Thu May 2 12:34:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Puranjay Mohan X-Patchwork-Id: 13651695 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 599B0C4345F for ; Thu, 2 May 2024 12:35:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=bYkBA+0KeH0fCij1SLFameyxW2bp/utmD+tDUYKouZA=; b=hPajD+jJs9g/7Q wWcULqzhB1+XFrpHJOE+Ntr1E38mAgS+iwrZQDL+2qg8hFkVl2to68OczDSCkT26aSIFkhpgbb4Ae 5lynUtG+j4+DWdQzQVEyVRhWuFF7ZebNU9QfcMCzucH62djB4l9RL1ONV33fbHxMDJSn8/uJlsySR FUCJbLEwktkd5VlQqaOm4z5Pymj3+mN2HCBh2AXrXbjNvdwhLaNk/PQDIc3CLve5994aLxqO9t7Nv SoRWNcDeAVi13dpWJHkn/ZM+rTpexwJmkTafyk81tMZRHwSQArZueRTTjiatTXhdt617GQl55mGVJ jDmjJUdLmWHGvMwRK8bA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s2Vek-0000000CgKd-22U1; Thu, 02 May 2024 12:35:22 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s2Veg-0000000CgJf-3s8k for linux-arm-kernel@lists.infradead.org; Thu, 02 May 2024 12:35:20 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id AEC6861A87; Thu, 2 May 2024 12:35:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 13A66C113CC; Thu, 2 May 2024 12:35:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714653317; bh=WlKxebhw7412R6YXQz6YwsAh+Molh2hfBvugAc0mpbg=; h=From:To:Cc:Subject:Date:From; b=nYLLKxV8o3+Z20fq820fXOAXBId0L4cMWCCXPXtwX4pgrz0JEFnD8r599mmvqAcng uyLkIPCkxbHaWwXBqmTgwKEib8Oz5yprgfgVN2EAigO4hKJcH6cHqHNEBuEvKScWP3 501dLo6/yviawJ2JybDqnSqZqYrZsfTW7ati3oXXEKgW9RXa2u5H0KCszv/QvrQWuC g1pDQgp83Ers75yoaLkn9Wf8vrw/A5EO83fxhTzTV0yCrQf5mppOxU2wOOPIxDdPK3 7vur5WnX3/agBnMF29r1iNM0K3Zw5cQKyEwIevVUUaH0U2yzLRJ8CknhEG83B2xNIO XPlTuqD+eb92Q== From: Puranjay Mohan To: 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 Cc: puranjay12@gmail.com Subject: [PATCH v2 1/2] arm64/arch_timer: include Date: Thu, 2 May 2024 12:34:48 +0000 Message-Id: <20240502123449.2690-1-puranjay@kernel.org> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240502_053519_059207_E981B904 X-CRM114-Status: GOOD ( 11.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org arch_timer.h includes linux/smp.h to use DEFINE_PER_CPU() and it works because smp.h includes percpu.h. The next commit will remove percpu.h from smp.h and it will break this usage. Explicitly include percpu.h and remove smp.h Signed-off-by: Puranjay Mohan Acked-by: Mark Rutland Reviewed-by: Anshuman Khandual --- arch/arm64/include/asm/arch_timer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm64/include/asm/arch_timer.h b/arch/arm64/include/asm/arch_timer.h index 934c658ee947..f5794d50f51d 100644 --- a/arch/arm64/include/asm/arch_timer.h +++ b/arch/arm64/include/asm/arch_timer.h @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include From patchwork Thu May 2 12:34:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Puranjay Mohan X-Patchwork-Id: 13651696 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 77E51C4345F for ; Thu, 2 May 2024 12:35:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=UkYHImXcwxVpHsr6wwhQqvi4SYFGKDR3QbaMLIA6Ihc=; b=iAoTBedft2ASdo K3nwLHZcoTqcB3VXpPzbM9pM8Xmzc7XpKNj2LEjifal/AWcsjzQLPH3YBjaZyHdS8jRIWztmcFawh ValQxKrU5NA2cotL/cKhhg4lgYqlbyKOUaN3Yo+pTNb159I3UI6elmh3A/9BhsLiUIgBoAFhZcYPK mdI47GolNF4ZLKP5gMgzgJUqt+x2p85FFXJVfGwS8yvSdTiRDxtBOu9CwBMJSfeODzE4cFgFl5iuF B5yfd5Yv8vqRpHBZfdNwffeR3DGm13gbkNkmnYZUNtUnNzkt+K6rwdn9+3/NwGCgb//ChBLG5q6gM IaITgxMAVV6WXSCDE1xg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s2Vez-0000000CgQh-2JWE; Thu, 02 May 2024 12:35:37 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s2Vev-0000000CgO3-0iSz for linux-arm-kernel@lists.infradead.org; Thu, 02 May 2024 12:35:35 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by dfw.source.kernel.org (Postfix) with ESMTP id 40F4D614FE; Thu, 2 May 2024 12:35:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7696C4AF1A; Thu, 2 May 2024 12:35:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1714653332; bh=1iCPxTYI/pWQqAi8vVdqGnub1dSEJs9IuaXYhwyCwuE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q0oA7urDCD13K1L0cCU8HeM+7YcjiTjuyh+c7i/+Td/1fhozuvdP/0d9ryRRMIlGh Fxnwe7dUXuAZSkCRGPojYpvJtAqj2goIyyNIoKAg5s7N7LegK+Q0ig0yTzXidmoOMA u9VPCndHJ4wPVDdV6WP+64NtQTNgV05kLXr94d+XZQ//2xD5N9B9z1wpz8fJLgYfSt oZTyFYstifkOarSaNm57faFrAHZnmIDyCXYJxAf02Ht6H1FxJvk8HrfhVCjKo9bhlD wILsHliajdkrMhQnycBmDqOyEFW7wMGKLAYbztTTZd8hoaFAOFEr1KLQMqc98ebK8I /8vnC+E3XaceQ== From: Puranjay Mohan To: 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 Cc: puranjay12@gmail.com Subject: [PATCH v2 2/2] arm64: implement raw_smp_processor_id() using thread_info Date: Thu, 2 May 2024 12:34:49 +0000 Message-Id: <20240502123449.2690-2-puranjay@kernel.org> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240502123449.2690-1-puranjay@kernel.org> References: <20240502123449.2690-1-puranjay@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240502_053533_307892_282A63E2 X-CRM114-Status: GOOD ( 19.69 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Historically, arm64 implemented raw_smp_processor_id() as a read of current_thread_info()->cpu. This changed when arm64 moved thread_info into task struct, as at the time CONFIG_THREAD_INFO_IN_TASK made core code use thread_struct::cpu for the cpu number, and due to header dependencies prevented using this in raw_smp_processor_id(). As a workaround, we moved to using a percpu variable in commit: commit 57c82954e77f ("arm64: make cpu number a percpu variable") Since then, thread_info::cpu was reintroduced, and core code was made to use this in commits: commit 001430c1910d ("arm64: add CPU field to struct thread_info") commit bcf9033e5449 ("sched: move CPU field back into thread_info if THREAD_INFO_IN_TASK=y") Consequently it is possible to use current_thread_info()->cpu again. This decreases the number of emitted instructions like in the following example: 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 After this patch: Dump of assembler code for function bpf_get_smp_processor_id: 0xffff8000802c9130 <+0>: nop 0xffff8000802c9134 <+4>: nop 0xffff8000802c9138 <+8>: mrs x0, sp_el0 0xffff8000802c913c <+12>: ldr w0, [x0, #24] 0xffff8000802c9140 <+16>: ret A microbenchmark[1] was built to measure the performance improvement provided by this change. It calls the following function given number of times and finds the runtime overhead: static noinline int get_cpu_id(void) { return smp_processor_id(); } Run the benchmark like: modprobe smp_processor_id nr_function_calls=1000000000 +--------------------------+------------------------+ | | Number of Calls | Time taken | +--------+-----------------+------------------------+ | Before | 1000000000 | 1602888401ns | +--------+-----------------+------------------------+ | After | 1000000000 | 1206212658ns | +--------+-----------------+------------------------+ | Difference (decrease) | 396675743ns (24.74%) | +---------------------------------------------------+ Remove the percpu variable cpu_number as it is used only in set_smp_ipi_range() as a dummy variable to be passed to ipi_handler(). Use irq_stat in place of cpu_number here. [1] https://github.com/puranjaymohan/linux/commit/77d3fdd Signed-off-by: Puranjay Mohan Acked-by: Mark Rutland Reviewed-by: Anshuman Khandual --- Changes in v1 -> v2: v1: https://lore.kernel.org/all/20240501154236.10236-1-puranjay@kernel.org/ - Remove the percpu variable cpu_number - Add more information to the commit message. --- arch/arm64/include/asm/smp.h | 13 +------------ arch/arm64/kernel/smp.c | 9 ++------- 2 files changed, 3 insertions(+), 19 deletions(-) diff --git a/arch/arm64/include/asm/smp.h b/arch/arm64/include/asm/smp.h index efb13112b408..2510eec026f7 100644 --- a/arch/arm64/include/asm/smp.h +++ b/arch/arm64/include/asm/smp.h @@ -25,22 +25,11 @@ #ifndef __ASSEMBLY__ -#include - #include #include #include -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number); - -/* - * We don't use this_cpu_read(cpu_number) as that has implicit writes to - * preempt_count, and associated (compiler) barriers, that we'd like to avoid - * the expense of. If we're preemptible, the value can be stale at use anyway. - * And we can't use this_cpu_ptr() either, as that winds up recursing back - * here under CONFIG_DEBUG_PREEMPT=y. - */ -#define raw_smp_processor_id() (*raw_cpu_ptr(&cpu_number)) +#define raw_smp_processor_id() (current_thread_info()->cpu) /* * Logical CPU mapping. diff --git a/arch/arm64/kernel/smp.c b/arch/arm64/kernel/smp.c index 4ced34f62dab..98d4e352c3d0 100644 --- a/arch/arm64/kernel/smp.c +++ b/arch/arm64/kernel/smp.c @@ -55,9 +55,6 @@ #include -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number); -EXPORT_PER_CPU_SYMBOL(cpu_number); - /* * as from 2.5, kernels no longer have an init_tasks structure * so we need some other way of telling a new secondary core @@ -742,8 +739,6 @@ void __init smp_prepare_cpus(unsigned int max_cpus) */ for_each_possible_cpu(cpu) { - per_cpu(cpu_number, cpu) = cpu; - if (cpu == smp_processor_id()) continue; @@ -1021,12 +1016,12 @@ void __init set_smp_ipi_range(int ipi_base, int n) if (ipi_should_be_nmi(i)) { err = request_percpu_nmi(ipi_base + i, ipi_handler, - "IPI", &cpu_number); + "IPI", &irq_stat); WARN(err, "Could not request IPI %d as NMI, err=%d\n", i, err); } else { err = request_percpu_irq(ipi_base + i, ipi_handler, - "IPI", &cpu_number); + "IPI", &irq_stat); WARN(err, "Could not request IPI %d as IRQ, err=%d\n", i, err); }