Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp754384pxp; Fri, 11 Mar 2022 14:14:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJwXRSS1iN+jhUbHuUJbbt/OuxIeQkCD/B4kQ59hitigsK7Op++i7uVZCDMrEK+/3UdllrAz X-Received: by 2002:a63:834a:0:b0:380:bcc5:3422 with SMTP id h71-20020a63834a000000b00380bcc53422mr10372641pge.4.1647036887908; Fri, 11 Mar 2022 14:14:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647036887; cv=none; d=google.com; s=arc-20160816; b=UEs6ECymzoW8fUdhiTokBgHdf/Gh6CvXzE9f/ts46wJge0Gs7enCZKsZQf6hjggWml ZSxubGvC4vfF31xn3KdiY7ifSzqm906flN1qU9R15kSO1svLfqDon+UJNUM+QLa5aTsU kCSBquWPeMC9HIWOEfzfaRRelSwrWwI/ZmxQVMmbOdN4UFuN6mwp2DZlln1JZXBr9eUs 75K3P8+mcwChw8gu+N4HBGmR9mRBBytqvLLDi86v2qLp143mPrn0AoAvG/R7IERMGIwu 5/r7iLB55az4eJGLAXGvN0n6jitVsQ3QKqlKYPFdKMrXOyFEnUwP+7aHLnCGnAe12NRl XV/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=oNwgniXhrfm7CvcuLLM0t3XR420jHK9m9gqH6RVTGOk=; b=jjCyZNlFqkwoAWRbIW2dT77oeQRne6zpoukWwYT7F22an+pmNhHpN7lo774jCKCslF ZfKFtn27YoMsaR+OZxILd/8BzBWUBRTna98R+6MDeKPSDIcTNpycl7txVmVQpgYqUd/A QAFG+e51Jh9di7SkuOTzRMMdvW6xPB90cK9hlcFW9G1AqEQ2s2YNxQ3KvotZPgeqhTSC EVtF2QNQbgnGSwcfuSKZFJglt8i7D1TWN6jR1gzHrL/OT0KNJpMpmE0RbLzCtDDrUIxR N+C8AZarCBHOILcsjeovilAApJSaTu7E1o5EkkA7KJGeb4EZ94OfcTkB3dr8GryoLcWD ugvw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id b9-20020a17090a990900b001bd14e01f7esi9236671pjp.108.2022.03.11.14.14.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Mar 2022 14:14:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 84F13298F19; Fri, 11 Mar 2022 13:24:14 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1348611AbiCKMjX (ORCPT + 99 others); Fri, 11 Mar 2022 07:39:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236082AbiCKMjW (ORCPT ); Fri, 11 Mar 2022 07:39:22 -0500 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7896E0AC6 for ; Fri, 11 Mar 2022 04:38:16 -0800 (PST) Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4KFQT30BCwz9sS8; Fri, 11 Mar 2022 13:38:15 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id XKomrJimBXhG; Fri, 11 Mar 2022 13:38:14 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4KFQT2691Nz9sS7; Fri, 11 Mar 2022 13:38:14 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id C35E18B796; Fri, 11 Mar 2022 13:38:14 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id ia6w-43ynZ7o; Fri, 11 Mar 2022 13:38:14 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (unknown [192.168.202.87]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 75EE38B790; Fri, 11 Mar 2022 13:38:14 +0100 (CET) Received: from PO20335.IDSI0.si.c-s.fr (localhost [127.0.0.1]) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.16.1) with ESMTPS id 22BCc7Ao3854065 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 11 Mar 2022 13:38:07 +0100 Received: (from chleroy@localhost) by PO20335.IDSI0.si.c-s.fr (8.17.1/8.17.1/Submit) id 22BCc4863854064; Fri, 11 Mar 2022 13:38:04 +0100 X-Authentication-Warning: PO20335.IDSI0.si.c-s.fr: chleroy set sender to christophe.leroy@csgroup.eu using -f From: Christophe Leroy To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: Christophe Leroy , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Subject: [PATCH v1] powerpc: Use static call for get_irq() Date: Fri, 11 Mar 2022 13:38:04 +0100 Message-Id: X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1647002283; l=3058; s=20211009; h=from:subject:message-id; bh=mCINRThVIFcTaXfGzdqc1OpQCUN3uvZOAfilNMot2os=; b=GnKPWvWQ03NeIAxp/0h3RNLpjj7IVDTif2xSsblE+mG97TZmkjd1Yl3gTlHDBbb9QAmmgSDZ+MsG xjgLn7mqCMpi0P+ADa383i1dnNddOSoD/uXjqAXX164YMKyJ4VPz X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RDNS_NONE, SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org __do_irq() inconditionnaly calls ppc_md.get_irq() That's definitely a hot path. At the time being ppc_md.get_irq address is read every time from ppc_md structure. Replace that call by a static call, and initialise that call after ppc_md.init_IRQ() has set ppc_md.get_irq. Emit a warning and don't set the static call if ppc_md.init_IRQ() is still NULL, that way the kernel won't blow up if for some reason ppc_md.get_irq() doesn't get properly set. With the patch: 00000000 <__SCT__ppc_get_irq>: 0: 48 00 00 20 b 20 <__static_call_return0> <== Replaced by 'b ' at runtime ... 00000020 <__static_call_return0>: 20: 38 60 00 00 li r3,0 24: 4e 80 00 20 blr ... 00000058 <__do_irq>: ... 64: 48 00 00 01 bl 64 <__do_irq+0xc> 64: R_PPC_REL24 __SCT__ppc_get_irq 68: 2c 03 00 00 cmpwi r3,0 ... Before the patch: 00000038 <__do_irq>: ... 3c: 3d 20 00 00 lis r9,0 3e: R_PPC_ADDR16_HA ppc_md+0x1c ... 44: 81 29 00 00 lwz r9,0(r9) 46: R_PPC_ADDR16_LO ppc_md+0x1c ... 4c: 7d 29 03 a6 mtctr r9 50: 4e 80 04 21 bctrl 54: 2c 03 00 00 cmpwi r3,0 ... On PPC64 which doesn't implement static calls yet we get: 00000000000000d0 <__do_irq>: ... dc: 00 00 22 3d addis r9,r2,0 dc: R_PPC64_TOC16_HA .data+0x8 ... e4: 00 00 89 e9 ld r12,0(r9) e4: R_PPC64_TOC16_LO_DS .data+0x8 ... f0: a6 03 89 7d mtctr r12 f4: 18 00 41 f8 std r2,24(r1) f8: 21 04 80 4e bctrl fc: 18 00 41 e8 ld r2,24(r1) ... So on PPC64 that's similar to what we get without static calls. But at least until ppc_md.get_irq() is set the call is to __static_call_return0. Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/irq.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c index 752fb182eacb..1c4715a03cd1 100644 --- a/arch/powerpc/kernel/irq.c +++ b/arch/powerpc/kernel/irq.c @@ -52,6 +52,7 @@ #include #include #include +#include #include #include @@ -730,6 +731,8 @@ static __always_inline void call_do_irq(struct pt_regs *regs, void *sp) ); } +DEFINE_STATIC_CALL_RET0(ppc_get_irq, *ppc_md.get_irq); + void __do_irq(struct pt_regs *regs) { unsigned int irq; @@ -741,7 +744,7 @@ void __do_irq(struct pt_regs *regs) * * This will typically lower the interrupt line to the CPU */ - irq = ppc_md.get_irq(); + irq = static_call(ppc_get_irq)(); /* We can hard enable interrupts now to allow perf interrupts */ if (should_hard_irq_enable()) @@ -809,6 +812,9 @@ void __init init_IRQ(void) if (ppc_md.init_IRQ) ppc_md.init_IRQ(); + + if (!WARN_ON(!ppc_md.get_irq)) + static_call_update(ppc_get_irq, ppc_md.get_irq); } #ifdef CONFIG_BOOKE_OR_40x -- 2.34.1