From patchwork Thu Feb 29 14:23:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Gleixner X-Patchwork-Id: 208389 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2097:b0:108:e6aa:91d0 with SMTP id gs23csp431618dyb; Thu, 29 Feb 2024 06:25:29 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVSjU3m0oJjXxmec6fKuigf+3QycIaQ7PUCGIPT6LzZMYnokONFgnL3YmLW+hRs7rD+HfDBgYBIqcbDfYCbWDdI0CbXYA== X-Google-Smtp-Source: AGHT+IFYjlMtDViiORMBkFN9L3VBZbttnloELytvjTdAF+fdAL42xYUYtWuxU5ivLboQVlz0B8qP X-Received: by 2002:a05:6402:26c5:b0:565:5de9:719b with SMTP id x5-20020a05640226c500b005655de9719bmr1976371edd.25.1709216729515; Thu, 29 Feb 2024 06:25:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709216729; cv=pass; d=google.com; s=arc-20160816; b=AOGpZPl4JaDfFOU4dUx4wb45Xs+PvWVdONlnbOf4b8FLd2jaLr+ybKXe+gKTn889He gAWeSViQmNE+Hb+wdXjg0EbmJ7Jl579FB6RSUpJEppImk8ngwOXF72ZkX4skqLzHS2sV DQCldwhNh+PlKjeoxyqZkNpi5jqF5n+fOOhrjzroKDQMvI1eqV90nN3clv6jhVvM8jkw RmKk32jWy/vBSIhw7U3nbQu+hxpts2dIwL4FfueDPG8U1lCcc2wh1OP1zgfl4xSFRTQ3 0eYsBjmfsZzVfYNudN+tCH5G1/ziUPVIV2rBd85o5ACW/1NHUUvvAr8njtDUR5ii2vMe zaSw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=date:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:subject:cc:to:from:dkim-signature :dkim-signature:message-id; bh=LNNG9Jq+5CN9Sd6cMwb+ZtsoydO1GTY3u/PKYA5LbYI=; fh=PG4pDnEpPgvD7rD3Usg/3IzySUyERYtwQcr+tbVLEzM=; b=Q4OQJh83/LwlD+xHc9ZozcD7JIAoYAfNrA8dgSUsSKacc9Mcch0ukIaQou042hKtPc /uShrEFJy+Ml3Cx6waqvKJtHoQqVsMCKEZBTFQLyUmcnoXvPo8THvJXqGYdsTRgVk1Sr LkIKvqUnvb3y1nC0YxxGf3TsOpIYv1hRV200jvfoSxG25ZvE5kkB8wxa6/cgq+R2w2M0 DjY+Sz2FhaR2tHN+u5TFxkXrcLQTAzV/DPpXCvc+2NOKbqsrRqIFq2G8864b8ipC/sp6 vWvbEFMWW5SSerfumCznYufBYAbueaU1Img2DTbKrK95Fo14V96sF3fRRU1F0+Aqeyfz yQXA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=rCgrKLzN; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=wrb4cDbK; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-86834-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86834-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id y7-20020a056402358700b00566a3aaba8dsi550897edc.45.2024.02.29.06.25.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Feb 2024 06:25:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-86834-ouuuleilei=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=@linutronix.de header.s=2020 header.b=rCgrKLzN; dkim=neutral (no key) header.i=@linutronix.de header.s=2020e header.b=wrb4cDbK; arc=pass (i=1 spf=pass spfdomain=linutronix.de dkim=pass dkdomain=linutronix.de dmarc=pass fromdomain=linutronix.de); spf=pass (google.com: domain of linux-kernel+bounces-86834-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-86834-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de 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 273651F25420 for ; Thu, 29 Feb 2024 14:25:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8A8341420D8; Thu, 29 Feb 2024 14:23:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="rCgrKLzN"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="wrb4cDbK" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 39FC41361CF for ; Thu, 29 Feb 2024 14:23:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709216625; cv=none; b=HlTqmkGoIiIS6fkFJgWDV9Gaw0FuyykzWpae1hQhAwJ9zdgedwGsMsJyGrqMYTfi/FWqsCA/SLAGPB9lS9QrlER6JQOlPos16xNmrJgrnO5DIIlP8z5psWv81o95weyqfQcUnc9Y3jEVB1vWDiheKMVIaudrQ+Bh4cYcY3tszD8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709216625; c=relaxed/simple; bh=RYjgrsnTa5ZE0/Y2Vs7u3YT+7pEEBNYqFqB94PRnE9Y=; h=Message-ID:From:To:Cc:Subject:References:MIME-Version: Content-Type:Date; b=tbRKIK63v6NKdmYHkegnSVRzR6YgrQdrubXjOOa07P52mLKoAoi9mskikfxm0QBJ63NeeXRq03uMJ/Wabopi08nBgohL43pZU9aY2OEseXKtridKV9eQiKuKCUpNWm0KyJg6hLt5S7cHsV8Eo9Sut3MR2v+v+W8xgGXMVLBdX0s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=rCgrKLzN; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=wrb4cDbK; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Message-ID: <20240229142248.582321500@linutronix.de> DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1709216622; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=LNNG9Jq+5CN9Sd6cMwb+ZtsoydO1GTY3u/PKYA5LbYI=; b=rCgrKLzNnXAJY4Zz0SDVlmyfrwrDTu1tzaZdnmqkKGsPyT8ZvfLWIrxWM0KMMstuUsF4Mp 97wJ0KRpLX6QqeXkvlcbzkZQVfpZTMeusQ4GBJuZER5nrB0oSySQjs0AzfJSWSo8t/SRlr 6lLWUnEMzXPgViZs+oRCFLTeMEc0F3U2qS13dPNPZHXS6TvXvP0W5ncMekrVxuZsiIRpi2 wMqd3IdOQbEng36tO+U9mAnPrkmhi6cJ/bFcwdWjGMAArLWEQs5+WwLIbJjU9ztNBM6IPl E95s9nm1Kd+xIsyPUcrcQshE/PJ1PCWiSk79ZsF5ydZsFZ225Rrg5yCAEIz7MQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1709216622; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: references:references; bh=LNNG9Jq+5CN9Sd6cMwb+ZtsoydO1GTY3u/PKYA5LbYI=; b=wrb4cDbKtuppv+wHBLyf/kbGN8Bpl/sOApjOH/vE/24sPbalv/MlJMr3qmAp2IwJTtjcka 4qMjKjSYLXXY0ODA== From: Thomas Gleixner To: LKML Cc: x86@kernel.org, Steven Rostedt , "Paul E. McKenney" Subject: [patch 6/6] x86/idle: Select idle routine only once References: <20240229141407.283316443@linutronix.de> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Date: Thu, 29 Feb 2024 15:23:42 +0100 (CET) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1792243641169637166 X-GMAIL-MSGID: 1792243641169637166 The idle routine selection is done on every CPU bringup operation and has a guard in place which is effective after the first invocation, which is a pointless exercise. Invoke it once on the boot CPU and mark the related functions __init. Signed-off-by: Thomas Gleixner Signed-off-by: Thomas Gleixner Signed-off-by: Thomas Gleixner --- arch/x86/include/asm/processor.h | 2 +- arch/x86/kernel/cpu/common.c | 4 ++-- arch/x86/kernel/process.c | 10 ++++------ 3 files changed, 7 insertions(+), 9 deletions(-) --- a/arch/x86/include/asm/processor.h +++ b/arch/x86/include/asm/processor.h @@ -555,7 +555,7 @@ static inline void load_sp0(unsigned lon unsigned long __get_wchan(struct task_struct *p); -extern void select_idle_routine(const struct cpuinfo_x86 *c); +extern void select_idle_routine(void); extern void amd_e400_c1e_apic_setup(void); extern unsigned long boot_option_idle_override; --- a/arch/x86/kernel/cpu/common.c +++ b/arch/x86/kernel/cpu/common.c @@ -1938,8 +1938,6 @@ static void identify_cpu(struct cpuinfo_ /* Init Machine Check Exception if available. */ mcheck_cpu_init(c); - select_idle_routine(c); - #ifdef CONFIG_NUMA numa_add_cpu(smp_processor_id()); #endif @@ -2343,6 +2341,8 @@ void __init arch_cpu_finalize_init(void) { identify_boot_cpu(); + select_idle_routine(); + /* * identify_boot_cpu() initialized SMT support information, let the * core code know. --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -853,8 +853,9 @@ void __noreturn stop_this_cpu(void *dumm * Do not prefer MWAIT if MONITOR instruction has a bug or idle=nomwait * is passed to kernel commandline parameter. */ -static bool prefer_mwait_c1_over_halt(const struct cpuinfo_x86 *c) +static __init bool prefer_mwait_c1_over_halt(void) { + const struct cpuinfo_x86 *c = &boot_cpu_data; u32 eax, ebx, ecx, edx; /* If override is enforced on the command line, fall back to HALT. */ @@ -908,7 +909,7 @@ static __cpuidle void mwait_idle(void) __current_clr_polling(); } -void select_idle_routine(const struct cpuinfo_x86 *c) +void __init select_idle_routine(void) { if (boot_option_idle_override == IDLE_POLL) { if (IS_ENABLED(CONFIG_SMP) && smp_num_siblings > 1) @@ -916,10 +917,7 @@ void select_idle_routine(const struct cp return; } - if (x86_idle_set()) - return; - - if (prefer_mwait_c1_over_halt(c)) { + if (prefer_mwait_c1_over_halt()) { pr_info("using mwait in idle threads\n"); static_call_update(x86_idle, mwait_idle); } else if (cpu_feature_enabled(X86_FEATURE_TDX_GUEST)) {