From patchwork Fri Jan 13 12:31:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 43271 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp245581wrt; Fri, 13 Jan 2023 04:41:08 -0800 (PST) X-Google-Smtp-Source: AMrXdXtS2NSQgNi8eFwBXWOdO9sE5SluhYaJTj9D3DESfYaNpBC4BZQMRNaEFVWYqQ8rh4aiS7sl X-Received: by 2002:a05:6a20:492a:b0:af:6cc0:344d with SMTP id ft42-20020a056a20492a00b000af6cc0344dmr84493730pzb.18.1673613668506; Fri, 13 Jan 2023 04:41:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673613668; cv=none; d=google.com; s=arc-20160816; b=dXylX7cHdFCCW8F+HthmCcPwz47YQuxMTMVlhQvbcMWKEQR90Gt8FmYImKlZR6qQGk vuLqgvLOzJSpfLrnJRPofYQuMnTyFkv7OqS7v3UIdxwa3gKCYZP8tgnTNTTksJJCLsf6 sTXu6sCiY69aVX5mNcR+BhTcSU0Ys+atTx+GcXEA47DwiXf4TatZVhiAczceapa0Ksst uCYzWIpGIbnBhJzb1cj2R7wnj/BDOP5AJUjtz2IFf/B4SOwMhP+34erczqJKnD7PJg61 qzLnR7KGvu+KYI5Zm17kIK39u3osT4J8r3VqGcEk6r21+jI9oA05EILzGRkZLgdFaqBF fcuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=6MOxP0q2phAy5N9tYdA2yH6rtSrdxa7nUWRoM0QGD4w=; b=xknjkcCarpdpWcfSj8MisUzYG3nR+EPFlPEqS4od7LKfgGyBKBV6F95PBHPGaTiQuU dgL6R9nQiK/Nvz/uxVIUopIVQfHx6uyFpWCfMmI/5pqCeVjwxMweJZzTKqRVsuHS5Vvu 1fGaqIcOn/pqDoQd1OKLPDJzqK7Obx1wbEjJ6P7ibiGMWB7FZSLSGabbQxdFZANa3RYn OvbMZQO3P7hrl0qnestPhVGZEsevQI+MArMwj99M32vOKn1BHljlLXPdNIlzpoFbKqpL eBXlSBVG1vXS4IaOPquOEa1b0WR6UPIrtOdeDpUdll/8BkLncYJM9p2/kHO8X9izTmzv cUJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=BBZeA2Bw; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=cGuHc95d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a2-20020a63e402000000b004a2f26de947si21498061pgi.224.2023.01.13.04.40.55; Fri, 13 Jan 2023 04:41:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=BBZeA2Bw; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=cGuHc95d; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230335AbjAMMhk (ORCPT + 99 others); Fri, 13 Jan 2023 07:37:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33692 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241191AbjAMMcV (ORCPT ); Fri, 13 Jan 2023 07:32:21 -0500 Received: from galois.linutronix.de (Galois.linutronix.de [IPv6:2a0a:51c0:0:12e:550::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E556574E6; Fri, 13 Jan 2023 04:31:18 -0800 (PST) Date: Fri, 13 Jan 2023 12:31:16 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1673613076; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6MOxP0q2phAy5N9tYdA2yH6rtSrdxa7nUWRoM0QGD4w=; b=BBZeA2BwDQQm++usnWAjDk+vVSD7jfBQYKfOtrOyZ0w7yv/C3M/FvTLazOos8yDvK/4i2s RPGzMzucvFF0OIhSK4z+aVRjFgnTg2TcE5lA1RP29i432ndTcnc24KYqkxnpySjjJmyBw6 rxFn+MTf8pZGeIJQbWtj8nRFe2j9amYfOJVjD1BbZAvw+s6v4joCO1brWJdUJC65fXww5W a3N/8PaUJvDYAGR4guHQX6Bm0A0QOQze5aO1tNCnIGOzwWFH5eCxB1rXoZ+TMbOTj65qtd UUIsBTPzmd0kbNplTFO6H5yEoccLO59gtj00C9qEQWwWs16UjJsuovv15hB9NA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1673613076; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6MOxP0q2phAy5N9tYdA2yH6rtSrdxa7nUWRoM0QGD4w=; b=cGuHc95dHNUBFN/XqiM++Jfzl7pxgFnHr9UUYtAKVH8vkmSQS48eOS1TUBBUzEW7i4Zl/h uUeP3IPftFB9SWCw== From: "tip-bot2 for Peter Zijlstra" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/core] x86/idle: Replace 'x86_idle' function pointer with a static_call Cc: "Peter Zijlstra (Intel)" , Ingo Molnar , Tony Lindgren , Ulf Hansson , Frederic Weisbecker , "Rafael J. Wysocki" , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20230112195539.453613251@infradead.org> References: <20230112195539.453613251@infradead.org> MIME-Version: 1.0 Message-ID: <167361307658.4906.13785875807510499856.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS autolearn=ham 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1754911126418107808?= X-GMAIL-MSGID: =?utf-8?q?1754911126418107808?= The following commit has been merged into the sched/core branch of tip: Commit-ID: aaa3896b969bdf946e0fd6aa6199da17b5da8d5c Gitweb: https://git.kernel.org/tip/aaa3896b969bdf946e0fd6aa6199da17b5da8d5c Author: Peter Zijlstra AuthorDate: Thu, 12 Jan 2023 20:43:16 +01:00 Committer: Ingo Molnar CommitterDate: Fri, 13 Jan 2023 11:03:21 +01:00 x86/idle: Replace 'x86_idle' function pointer with a static_call Typical boot time setup; no need to suffer an indirect call for that. Signed-off-by: Peter Zijlstra (Intel) Signed-off-by: Ingo Molnar Tested-by: Tony Lindgren Tested-by: Ulf Hansson Reviewed-by: Frederic Weisbecker Reviewed-by: Rafael J. Wysocki Link: https://lore.kernel.org/r/20230112195539.453613251@infradead.org --- arch/x86/kernel/process.c | 50 +++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c index 40d156a..8481fbe 100644 --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -694,7 +695,23 @@ void __switch_to_xtra(struct task_struct *prev_p, struct task_struct *next_p) unsigned long boot_option_idle_override = IDLE_NO_OVERRIDE; EXPORT_SYMBOL(boot_option_idle_override); -static void (*x86_idle)(void); +/* + * We use this if we don't have any better idle routine.. + */ +void __cpuidle default_idle(void) +{ + raw_safe_halt(); +} +#if defined(CONFIG_APM_MODULE) || defined(CONFIG_HALTPOLL_CPUIDLE_MODULE) +EXPORT_SYMBOL(default_idle); +#endif + +DEFINE_STATIC_CALL_NULL(x86_idle, default_idle); + +static bool x86_idle_set(void) +{ + return !!static_call_query(x86_idle); +} #ifndef CONFIG_SMP static inline void play_dead(void) @@ -717,28 +734,17 @@ void arch_cpu_idle_dead(void) /* * Called from the generic idle code. */ -void arch_cpu_idle(void) -{ - x86_idle(); -} - -/* - * We use this if we don't have any better idle routine.. - */ -void __cpuidle default_idle(void) +void __cpuidle arch_cpu_idle(void) { - raw_safe_halt(); + static_call(x86_idle)(); } -#if defined(CONFIG_APM_MODULE) || defined(CONFIG_HALTPOLL_CPUIDLE_MODULE) -EXPORT_SYMBOL(default_idle); -#endif #ifdef CONFIG_XEN bool xen_set_default_idle(void) { - bool ret = !!x86_idle; + bool ret = x86_idle_set(); - x86_idle = default_idle; + static_call_update(x86_idle, default_idle); return ret; } @@ -880,20 +886,20 @@ void select_idle_routine(const struct cpuinfo_x86 *c) if (boot_option_idle_override == IDLE_POLL && smp_num_siblings > 1) pr_warn_once("WARNING: polling idle and HT enabled, performance may degrade\n"); #endif - if (x86_idle || boot_option_idle_override == IDLE_POLL) + if (x86_idle_set() || boot_option_idle_override == IDLE_POLL) return; if (boot_cpu_has_bug(X86_BUG_AMD_E400)) { pr_info("using AMD E400 aware idle routine\n"); - x86_idle = amd_e400_idle; + static_call_update(x86_idle, amd_e400_idle); } else if (prefer_mwait_c1_over_halt(c)) { pr_info("using mwait in idle threads\n"); - x86_idle = mwait_idle; + static_call_update(x86_idle, mwait_idle); } else if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) { pr_info("using TDX aware idle routine\n"); - x86_idle = tdx_safe_halt; + static_call_update(x86_idle, tdx_safe_halt); } else - x86_idle = default_idle; + static_call_update(x86_idle, default_idle); } void amd_e400_c1e_apic_setup(void) @@ -946,7 +952,7 @@ static int __init idle_setup(char *str) * To continue to load the CPU idle driver, don't touch * the boot_option_idle_override. */ - x86_idle = default_idle; + static_call_update(x86_idle, default_idle); boot_option_idle_override = IDLE_HALT; } else if (!strcmp(str, "nomwait")) { /*