From nobody Fri Dec 19 04:49:12 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EED31C04E69 for ; Fri, 11 Aug 2023 17:01:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236046AbjHKRBB (ORCPT ); Fri, 11 Aug 2023 13:01:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235273AbjHKRA6 (ORCPT ); Fri, 11 Aug 2023 13:00:58 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A7811FE3 for ; Fri, 11 Aug 2023 10:00:58 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0313565816 for ; Fri, 11 Aug 2023 17:00:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C5BF6C433CC; Fri, 11 Aug 2023 17:00:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691773257; bh=erurmBk6eYQvncO35/wgAhKngMgxH6cwdYjQXfYK+oY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KedcF9hvhoiTuwvwmjKJlSSKEawCZwEKWmHJ6+4HPVPxmFuWODvSihQVsIlxVDdEK j2eFLIFuxieQuQL/D8VMiGtY9AAsI2NsHptzs0cFPjhp+flYNfGCrgFHvOjD8dsuMw 2J0E7jS4x3RebYPuezSCYxWADvoWlaqUTpY0MB/Rlo7acpO0mmH8SI/mn8qOE+e62S bLdD7ZjPSZlxKPEIv78y+xLAt0R3Q4ihSud4LIcd2pshg2vEDyWcZjN1gTdncJO7l7 fUj4hhvlQqUI93iJ9lb8c+sm1IPpcregD/9taiXt9gWl3FroW81kFREy2WF9fa1atG 8oJo73E1HIvVA== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Peter Zijlstra , "Rafael J . Wysocki" , Daniel Lezcano , Thomas Gleixner , Anna-Maria Behnsen Subject: [PATCH 01/10] x86: Add a comment about the "magic" behind shadow sti before mwait Date: Fri, 11 Aug 2023 19:00:40 +0200 Message-Id: <20230811170049.308866-2-frederic@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230811170049.308866-1-frederic@kernel.org> References: <20230811170049.308866-1-frederic@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add a note to make sure we never miss and break the requirements behind it. Signed-off-by: Frederic Weisbecker Acked-by: Rafael J. Wysocki --- arch/x86/include/asm/mwait.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/arch/x86/include/asm/mwait.h b/arch/x86/include/asm/mwait.h index 778df05f8539..341ee4f1d91e 100644 --- a/arch/x86/include/asm/mwait.h +++ b/arch/x86/include/asm/mwait.h @@ -87,6 +87,15 @@ static __always_inline void __mwaitx(unsigned long eax, = unsigned long ebx, :: "a" (eax), "b" (ebx), "c" (ecx)); } =20 +/* + * Re-enable interrupts right upon calling mwait in such a way that + * no interrupt can fire _before_ the execution of mwait, ie: no + * instruction must be placed between "sti" and "mwait". + * + * This is necessary because if an interrupt queues a timer before + * executing mwait, it would otherwise go unnoticed and the next tick + * would not be reprogrammed accordingly before mwait ever wakes up. + */ static __always_inline void __sti_mwait(unsigned long eax, unsigned long e= cx) { mds_idle_clear_cpu_buffers(); --=20 2.34.1 From nobody Fri Dec 19 04:49:12 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C81BC0015E for ; Fri, 11 Aug 2023 17:01:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236316AbjHKRBP (ORCPT ); Fri, 11 Aug 2023 13:01:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236102AbjHKRBB (ORCPT ); Fri, 11 Aug 2023 13:01:01 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5E8C30CF for ; Fri, 11 Aug 2023 10:01:00 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6A96766AFF for ; Fri, 11 Aug 2023 17:01:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D4903C433D9; Fri, 11 Aug 2023 17:00:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691773259; bh=MSV7rGMv9w657y7ZDGytkmDXoScopLPoMt9dVwnOMVI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tadGZnDr53sGuJqbcI/oAX/TnBDHDgTNARh3umzbcSSYYx8vGBQi5UTdJIr1Lf/TS 1OvVgkVCZNhAzSd9RBsapuBEIOPJmQJHyqd3JXprL9pqM5TJpxz2O14Yhi58dc80N9 tshmu2SFc3VnhW0Xo9DlquA9TuwAQ8Xhg4cs1Ur5bB0Mnsw7QeZ+MSUFHqKaPKkjW2 /4TMCoxxZPae4qVEocgu7fuy+283DWmA3hxOJHsiFocKvDFSmTzq37ZwcFvBfL9obY 7XLrXxi6VcZy9cQFJwieKQ5yVghepD5HlvNwZT/ZWN2RWEbbvXa+mNVQxvVQLlv4xx dc6mKunDYsHVA== From: Frederic Weisbecker To: LKML Cc: Peter Zijlstra , Frederic Weisbecker , "Rafael J . Wysocki" , Daniel Lezcano , Thomas Gleixner , Anna-Maria Behnsen , Jacob Pan , Len Brown Subject: [PATCH 02/10] cpuidle: Fix CPUIDLE_FLAG_IRQ_ENABLE leaking timer reprogram Date: Fri, 11 Aug 2023 19:00:41 +0200 Message-Id: <20230811170049.308866-3-frederic@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230811170049.308866-1-frederic@kernel.org> References: <20230811170049.308866-1-frederic@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Peter Zijlstra intel_idle_irq() re-enables IRQs very early. As a result, an interrupt may fire before mwait() is eventually called. If such an interrupt queues a timer, it may go unnoticed until mwait returns and the idle loop handles the tick re-evaluation. And monitoring TIF_NEED_RESCHED doesn't help because a local timer enqueue doesn't set that flag. The issue is mitigated by the fact that this idle handler is only invoked for shallow C-states when, presumably, the next tick is supposed to be close enough. There may still be rare cases though when the next tick is far away and the selected C-state is shallow, resulting in a timer getting ignored for a while. Fix this with using sti_mwait() whose IRQ-reenablement only triggers upon calling mwait(), dealing with the race while keeping the interrupt latency within acceptable bounds. Fixes: c227233ad64c (intel_idle: enable interrupts before C1 on Xeons) Not-yet-signed-off-by: Peter Zijlstra Signed-off-by: Frederic Weisbecker Acked-by: Rafael J. Wysocki --- arch/x86/include/asm/mwait.h | 11 +++++++++-- drivers/idle/intel_idle.c | 19 +++++++------------ 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/arch/x86/include/asm/mwait.h b/arch/x86/include/asm/mwait.h index 341ee4f1d91e..920426d691ce 100644 --- a/arch/x86/include/asm/mwait.h +++ b/arch/x86/include/asm/mwait.h @@ -124,8 +124,15 @@ static __always_inline void mwait_idle_with_hints(unsi= gned long eax, unsigned lo } =20 __monitor((void *)¤t_thread_info()->flags, 0, 0); - if (!need_resched()) - __mwait(eax, ecx); + + if (!need_resched()) { + if (ecx & 1) { + __mwait(eax, ecx); + } else { + __sti_mwait(eax, ecx); + raw_local_irq_disable(); + } + } } current_clr_polling(); } diff --git a/drivers/idle/intel_idle.c b/drivers/idle/intel_idle.c index 256c2d42e350..d676d32741da 100644 --- a/drivers/idle/intel_idle.c +++ b/drivers/idle/intel_idle.c @@ -131,11 +131,12 @@ static unsigned int mwait_substates __initdata; #define MWAIT2flg(eax) ((eax & 0xFF) << 24) =20 static __always_inline int __intel_idle(struct cpuidle_device *dev, - struct cpuidle_driver *drv, int index) + struct cpuidle_driver *drv, + int index, bool irqoff) { struct cpuidle_state *state =3D &drv->states[index]; unsigned long eax =3D flg2MWAIT(state->flags); - unsigned long ecx =3D 1; /* break on interrupt flag */ + unsigned long ecx =3D 1*irqoff; /* break on interrupt flag */ =20 mwait_idle_with_hints(eax, ecx); =20 @@ -159,19 +160,13 @@ static __always_inline int __intel_idle(struct cpuidl= e_device *dev, static __cpuidle int intel_idle(struct cpuidle_device *dev, struct cpuidle_driver *drv, int index) { - return __intel_idle(dev, drv, index); + return __intel_idle(dev, drv, index, true); } =20 static __cpuidle int intel_idle_irq(struct cpuidle_device *dev, struct cpuidle_driver *drv, int index) { - int ret; - - raw_local_irq_enable(); - ret =3D __intel_idle(dev, drv, index); - raw_local_irq_disable(); - - return ret; + return __intel_idle(dev, drv, index, false); } =20 static __cpuidle int intel_idle_ibrs(struct cpuidle_device *dev, @@ -184,7 +179,7 @@ static __cpuidle int intel_idle_ibrs(struct cpuidle_dev= ice *dev, if (smt_active) native_wrmsrl(MSR_IA32_SPEC_CTRL, 0); =20 - ret =3D __intel_idle(dev, drv, index); + ret =3D __intel_idle(dev, drv, index, true); =20 if (smt_active) native_wrmsrl(MSR_IA32_SPEC_CTRL, spec_ctrl); @@ -196,7 +191,7 @@ static __cpuidle int intel_idle_xstate(struct cpuidle_d= evice *dev, struct cpuidle_driver *drv, int index) { fpu_idle_fpregs(); - return __intel_idle(dev, drv, index); + return __intel_idle(dev, drv, index, true); } =20 /** --=20 2.34.1 From nobody Fri Dec 19 04:49:12 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25792EB64DD for ; Fri, 11 Aug 2023 17:01:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236403AbjHKRBT (ORCPT ); Fri, 11 Aug 2023 13:01:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235983AbjHKRBL (ORCPT ); Fri, 11 Aug 2023 13:01:11 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D88DB30E7 for ; Fri, 11 Aug 2023 10:01:02 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 6E25D67684 for ; Fri, 11 Aug 2023 17:01:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 46D28C433C8; Fri, 11 Aug 2023 17:01:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691773261; bh=YaoIKYC/HMtW27OOcRlg0CgBQJS8nCnjs/a8mtWVN9k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cMAuv/uUk1D/ks5Q4Tofx42uo+5BObOOtWMdaGvK9vFT2YixjWvjrwrhxmNgits1L 9O8X6v6ubtlin/ESJ/BraO1nBxVuVsD5GIDnmrr+ywXDcsVpxMsTcEjIt7XK/dICL9 /aNDYUXTHwGSLFkS3TEVydJPQWPG8aVYtIjZzR0TIaqcGYjfHCmcr3QIukV9ex873X rfZUX0OBrxoHoGN/gEOO6i9z/5JMiLh3sHiQlyte7T7u2xlvf/WhrLbB46Tx32q/MC kTN+EESC255qjJDAseDUBchyqbkz3+tdE2pALmTWWLxow57Ebe42t2PCdyGilblR05 dNZHqH95bTnNw== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Peter Zijlstra , "Rafael J . Wysocki" , Daniel Lezcano , Thomas Gleixner , Anna-Maria Behnsen Subject: [PATCH 03/10] cpuidle: Report illegal tick stopped while polling Date: Fri, 11 Aug 2023 19:00:42 +0200 Message-Id: <20230811170049.308866-4-frederic@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230811170049.308866-1-frederic@kernel.org> References: <20230811170049.308866-1-frederic@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" poll_idle() can't be called while the tick is stopped because it enables interrupts and only polls on TIF_NEED_RESCHED, which doesn't tell if an interrupt queues a timer that would require a tick re-programming. There is no point anyway to poll with the tick stopped so add a check to make sure it never happens. Signed-off-by: Frederic Weisbecker --- drivers/cpuidle/poll_state.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/cpuidle/poll_state.c b/drivers/cpuidle/poll_state.c index 9b6d90a72601..009f46f121ae 100644 --- a/drivers/cpuidle/poll_state.c +++ b/drivers/cpuidle/poll_state.c @@ -7,6 +7,7 @@ #include #include #include +#include =20 #define POLL_IDLE_RELAX_COUNT 200 =20 @@ -19,6 +20,13 @@ static int __cpuidle poll_idle(struct cpuidle_device *de= v, =20 dev->poll_time_limit =3D false; =20 + /* + * This re-enables IRQs and only polls on TIF_NEED_RESCHED. + * A timer queued by an interrupt here may go unnoticed if + * the tick is stopped. + */ + WARN_ON_ONCE(tick_nohz_tick_stopped()); + raw_local_irq_enable(); if (!current_set_polling_and_test()) { unsigned int loop_count =3D 0; --=20 2.34.1 From nobody Fri Dec 19 04:49:12 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09959EB64DD for ; Fri, 11 Aug 2023 17:01:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236271AbjHKRBW (ORCPT ); Fri, 11 Aug 2023 13:01:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236192AbjHKRBM (ORCPT ); Fri, 11 Aug 2023 13:01:12 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BC4730F8 for ; Fri, 11 Aug 2023 10:01:05 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0C08267762 for ; Fri, 11 Aug 2023 17:01:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5125AC433C7; Fri, 11 Aug 2023 17:01:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691773264; bh=avuix5bG15MMoG/1/mFgPThQIvzwkN7p3FXy26I7Giw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SvV+gp5g5gzELLIxJzVjWBy9jH4Dr1dph56JxNHJDLbhjtbBPcfgWx0fDvwBMR8JJ MFdvd12oxGLPVAL1BUDpG4jC4IM2ohaqHWnv/6dfM/2rhE1kGmdk7bUHTRNTo4PGBS TH/3EkVf3lwQIgRieERTjBvL/JCtKKilmJ27qqWlNevT0W38UOdZOcL0dS6iZu+ijL rbTuO2gtnRwuiWmqYHvryTQgFj19MKL4UZ0q72ZgZkGhv53ssZ1hxogu7li5d80XSL r+P44pFqvg3cG1DSuwaVBnGRNq6v5NbRGeEu3UHQEe5S2vCO2ZqcF8OWUNtjEFcOuy N0lLJgBOpbUUw== From: Frederic Weisbecker To: LKML Cc: Peter Zijlstra , Frederic Weisbecker , "Rafael J . Wysocki" , Daniel Lezcano , Thomas Gleixner , Anna-Maria Behnsen , Bibo Mao , WANG Xuerui , Bibo@vger.kernel.org Subject: [PATCH 04/10] loongson: Fix idle VS timer enqueue Date: Fri, 11 Aug 2023 19:00:43 +0200 Message-Id: <20230811170049.308866-5-frederic@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230811170049.308866-1-frederic@kernel.org> References: <20230811170049.308866-1-frederic@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Peter Zijlstra Loongson re-enables interrupts on its idle routine and performs a TIF_NEED_RESCHED check afterwards before putting the CPU to sleep. The IRQs firing between the check and the idling instruction may set the TIF_NEED_RESCHED flag. In order to deal with the such a race, IRQs interrupting __arch_cpu_idle() rollback their return address to the beginning of __arch_cpu_idle() so that TIF_NEED_RESCHED is checked again before going back to sleep. However idle IRQs can also queue timers that may require a tick reprogramming through a new generic idle loop iteration but those timers would go unnoticed here because __arch_cpu_idle() only checks TIF_NEED_RESCHED. It doesn't check for pending timers. Fix this with fast-forwarding idle IRQs return value to the end of the idle routine instead of the beginning, so that the generic idle loop handles both TIF_NEED_RESCHED and pending timers. Fixes: 0603839b18f4 (LoongArch: Add exception/interrupt handling) Tested-by: Bibo, Mao Not-yet-signed-off-by: Peter Zijlstra Cc: WANG Xuerui Signed-off-by: Frederic Weisbecker --- arch/loongarch/kernel/genex.S | 32 ++++++++++++++++++-------------- arch/loongarch/kernel/idle.c | 1 - 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/arch/loongarch/kernel/genex.S b/arch/loongarch/kernel/genex.S index 78f066384657..359d693f112e 100644 --- a/arch/loongarch/kernel/genex.S +++ b/arch/loongarch/kernel/genex.S @@ -18,27 +18,31 @@ =20 .align 5 SYM_FUNC_START(__arch_cpu_idle) - /* start of rollback region */ - LONG_L t0, tp, TI_FLAGS - nop - andi t0, t0, _TIF_NEED_RESCHED - bnez t0, 1f - nop - nop - nop + /* start of idle interrupt region */ + move t0, CSR_CRMD_IE + csrxchg t0, t0, LOONGARCH_CSR_CRMD + /* + * If an interrupt lands here; between enabling interrupts above and + * going idle on the next instruction, we must *NOT* go idle since the + * interrupt could have set TIF_NEED_RESCHED or caused an timer to need + * reprogramming. Fall through -- see handle_vint() below -- and have + * the idle loop take care of things. + */ idle 0 - /* end of rollback region */ -1: jr ra + nop + /* end of idle interrupt region */ +SYM_INNER_LABEL(__arch_cpu_idle_exit, SYM_L_LOCAL) + jr ra SYM_FUNC_END(__arch_cpu_idle) =20 SYM_FUNC_START(handle_vint) BACKUP_T0T1 SAVE_ALL - la_abs t1, __arch_cpu_idle + la_abs t1, __arch_cpu_idle_exit LONG_L t0, sp, PT_ERA - /* 32 byte rollback region */ - ori t0, t0, 0x1f - xori t0, t0, 0x1f + /* 16 byte idle interrupt region */ + ori t0, t0, 0x0f + addi.d t0, t0, 1 bne t0, t1, 1f LONG_S t0, sp, PT_ERA 1: move a0, sp diff --git a/arch/loongarch/kernel/idle.c b/arch/loongarch/kernel/idle.c index 0b5dd2faeb90..5ba72d229920 100644 --- a/arch/loongarch/kernel/idle.c +++ b/arch/loongarch/kernel/idle.c @@ -11,7 +11,6 @@ =20 void __cpuidle arch_cpu_idle(void) { - raw_local_irq_enable(); __arch_cpu_idle(); /* idle instruction needs irq enabled */ raw_local_irq_disable(); } --=20 2.34.1 From nobody Fri Dec 19 04:49:12 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D9B4C001DE for ; Fri, 11 Aug 2023 17:01:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236314AbjHKRBY (ORCPT ); Fri, 11 Aug 2023 13:01:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236137AbjHKRBN (ORCPT ); Fri, 11 Aug 2023 13:01:13 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B943F358D for ; Fri, 11 Aug 2023 10:01:07 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1B6C4645D4 for ; Fri, 11 Aug 2023 17:01:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E0C8EC433C8; Fri, 11 Aug 2023 17:01:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691773266; bh=S08tGTg2h98OGDPV+poOPJ31ZbhjI75bLqTCYfR8VLE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rMyizXCKChWj0nTYNr5wnl6eRtZ4EEFVV37VHgROtV2bk77XB8WECJhMjGHeVS7WZ BMoZ6/X6yfFy33d1vj2Hv8Bc2DtvbP8Ef1H99meYWnt3BmuxqvnCWhnfeWo7wFg/eB ZtQlfZxqqZxOKqklVkyphHAhpysYvKQCErpy83U9EzDTPhmLR9rxIqJ9pMmviOx7wk LwbbNqaxxFuyTdM50rLCYvFP7iPCyZf1qJCJxtwzPfz9K4HCO1HrmNcqkNObPZdC92 +nMDMROWFF1t+ZI4Gq1drjVj5d/dgXYmCvMI1ZxuqEGs8C/gTsXhNXQQLjVwklg3MD Tsga622F1V/6Q== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Peter Zijlstra , "Rafael J . Wysocki" , Daniel Lezcano , Thomas Gleixner , Anna-Maria Behnsen Subject: [PATCH 05/10] cpuidle: Comment about timers requirements VS idle handler Date: Fri, 11 Aug 2023 19:00:44 +0200 Message-Id: <20230811170049.308866-6-frederic@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230811170049.308866-1-frederic@kernel.org> References: <20230811170049.308866-1-frederic@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Signed-off-by: Frederic Weisbecker Acked-by: Rafael J. Wysocki --- kernel/sched/idle.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c index 342f58a329f5..d52f6e3e3854 100644 --- a/kernel/sched/idle.c +++ b/kernel/sched/idle.c @@ -258,6 +258,36 @@ static void do_idle(void) while (!need_resched()) { rmb(); =20 + /* + * Interrupts shouldn't be re-enabled from that point on until + * the CPU sleeping instruction is reached. Otherwise an interrupt + * may fire and queue a timer that would be ignored until the CPU + * wakes from the sleeping instruction. And testing need_resched() + * doesn't tell about pending needed timer reprogram. + * + * Several cases to consider: + * + * - SLEEP-UNTIL-PENDING-INTERRUPT based instructions such as + * "wfi" or "mwait" are fine because they can be entered with + * interrupt disabled. + * + * - sti;mwait() couple is fine because the interrupts are + * re-enabled only upon the execution of mwait, leaving no gap + * in-between. + * + * - ROLLBACK based idle handlers with the sleeping instruction + * called with interrupts enabled are NOT fine. In this scheme + * when the interrupt detects it has interrupted an idle handler, + * it rolls back to its beginning which performs the + * need_resched() check before re-executing the sleeping + * instruction. This can leak a pending needed timer reprogram. + * If such a scheme is really mandatory due to the lack of an + * appropriate CPU sleeping instruction, then a FAST-FORWARD + * must instead be applied: when the interrupt detects it has + * interrupted an idle handler, it must resume to the end of + * this idle handler so that the generic idle loop is iterated + * again to reprogram the tick. + */ local_irq_disable(); =20 if (cpu_is_offline(cpu)) { --=20 2.34.1 From nobody Fri Dec 19 04:49:12 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3043EC0015E for ; Fri, 11 Aug 2023 17:01:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236507AbjHKRBe (ORCPT ); Fri, 11 Aug 2023 13:01:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234617AbjHKRBP (ORCPT ); Fri, 11 Aug 2023 13:01:15 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C337B35A9 for ; Fri, 11 Aug 2023 10:01:09 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4C316645D4 for ; Fri, 11 Aug 2023 17:01:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EC1BAC433C7; Fri, 11 Aug 2023 17:01:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691773268; bh=1NQPETUBxztpoNgtonFeGuuxCy+oiM7V1jas7MgPpLw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NhgGjX14Vfxa5mHU4CwZ2RvYwEyiALn1takLmpPnUFScmOqNOLb0xTxOhL1wecuIS dMQBaSRZK7lU0sYnl1m4AKEEZJsC+GDq86xovFbDEUqs2OoqKC5F0/tNP7MOzZQD8Z GTn92asL7geG3HT25qM9kIileTY0/BNd0CIotA8zwuKZ8G/VX6V3qXCWkZAi5H16ni scdvr1dq69gt2tSYU5VnJS/bPiV2FeaeH5yNcVqNZCWd9lWLK7JFpI6pdOYRNs6fG3 XUwWGuwqqyEnTInszoWbFfRtaWNeqjUM3iM0GnYPZQIcOfLhmJP9IrMCwx2LjTQbif od+SqAWYBmbaA== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Marcelo Tosatti , Peter Zijlstra , "Rafael J . Wysocki" , Daniel Lezcano , Thomas Gleixner , Anna-Maria Behnsen Subject: [PATCH 06/10] cpuidle: Remove unnecessary current_clr_polling_and_test() from haltpoll Date: Fri, 11 Aug 2023 19:00:45 +0200 Message-Id: <20230811170049.308866-7-frederic@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230811170049.308866-1-frederic@kernel.org> References: <20230811170049.308866-1-frederic@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When cpuidle drivers ->enter() callback are called, the TIF_NR_POLLING flag is cleared already and TIF_NEED_RESCHED checked by call_cpuidle(). Therefore calling current_clr_polling_and_test() is redundant here and further setting of TIF_NEED_RESCHED will result in an IPI and thus an idle loop exit. This call can be safely removed. Cc: Marcelo Tosatti Signed-off-by: Frederic Weisbecker Acked-by: Rafael J. Wysocki --- drivers/cpuidle/cpuidle-haltpoll.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/drivers/cpuidle/cpuidle-haltpoll.c b/drivers/cpuidle/cpuidle-h= altpoll.c index e66df22f9695..b641bc535102 100644 --- a/drivers/cpuidle/cpuidle-haltpoll.c +++ b/drivers/cpuidle/cpuidle-haltpoll.c @@ -28,11 +28,8 @@ static enum cpuhp_state haltpoll_hp_state; static int default_enter_idle(struct cpuidle_device *dev, struct cpuidle_driver *drv, int index) { - if (current_clr_polling_and_test()) { - local_irq_enable(); - return index; - } arch_cpu_idle(); + return index; } =20 --=20 2.34.1 From nobody Fri Dec 19 04:49:12 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8251FEB64DD for ; Fri, 11 Aug 2023 17:01:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236364AbjHKRBh (ORCPT ); Fri, 11 Aug 2023 13:01:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236208AbjHKRBQ (ORCPT ); Fri, 11 Aug 2023 13:01:16 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB52C30CF for ; Fri, 11 Aug 2023 10:01:11 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 61BBA645D4 for ; Fri, 11 Aug 2023 17:01:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 30619C433BA; Fri, 11 Aug 2023 17:01:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691773270; bh=TVovZjwyix5rQdhW8ECdApx6w3lNWl+b+lPUjWG+UIw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=A4PolbeRtyjUDFVWk+7yFw7BYAFBwaI4HrMy6fwJNiTWTirl79pOSGigmrem5nhhh N2kc0CnhxTT5A+ddzcDvVN90XSyvLjVp0XdycOwkMO8WHTqGcOEiGtE2vjixmyjkdj v02fmOiWR09SWyMYyW6mksAtAZp31nh1M4vDoJFTAjK/GgO/J2+97rgUMnRuScK1f3 Ye0JvYUa80GerYbElkN0TchAmUmsvacjyoGg1nNFhmLQkFrem36wwm6EeE0lTzooOu CBm6UAIJXt3rHZnpoPtTrd35G1eB8egqnGgoK0bSYg+ujZiEX9AdpP1Tb+wcKGEFZn yulqZnvlHCM5w== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Peter Zijlstra , "Rafael J . Wysocki" , Daniel Lezcano , Thomas Gleixner , Anna-Maria Behnsen Subject: [PATCH 07/10] cpuidle: Remove unnecessary current_clr_polling() on poll_idle() Date: Fri, 11 Aug 2023 19:00:46 +0200 Message-Id: <20230811170049.308866-8-frederic@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230811170049.308866-1-frederic@kernel.org> References: <20230811170049.308866-1-frederic@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" There is no point in clearing TIF_NR_POLLING and folding TIF_NEED_RESCHED upon poll_idle() exit because cpuidle_idle_call() is going to set again TIF_NR_POLLING anyway. Also if TIF_NEED_RESCHED is set, it will be folded and TIF_NR_POLLING will be cleared at the end of do_idle(). Signed-off-by: Frederic Weisbecker Acked-by: Rafael J. Wysocki --- drivers/cpuidle/poll_state.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/cpuidle/poll_state.c b/drivers/cpuidle/poll_state.c index 009f46f121ae..44a656464d06 100644 --- a/drivers/cpuidle/poll_state.c +++ b/drivers/cpuidle/poll_state.c @@ -48,8 +48,6 @@ static int __cpuidle poll_idle(struct cpuidle_device *dev, } raw_local_irq_disable(); =20 - current_clr_polling(); - return index; } =20 --=20 2.34.1 From nobody Fri Dec 19 04:49:12 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76E2EC001DE for ; Fri, 11 Aug 2023 17:01:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236559AbjHKRBk (ORCPT ); Fri, 11 Aug 2023 13:01:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236229AbjHKRBQ (ORCPT ); Fri, 11 Aug 2023 13:01:16 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA45530F0 for ; Fri, 11 Aug 2023 10:01:13 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7A59B67759 for ; Fri, 11 Aug 2023 17:01:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44C77C433CA; Fri, 11 Aug 2023 17:01:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691773272; bh=U6FUfmWsk+FhGtzYnlY3GoE5tLhV5tMKcMnNpThTCkM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZV58pxKmzLSPMaZiCldsycJVqKgIEqoKHshWDQ8vgXi1SSW2VWucBhgjWu0xTUAfX pJRibgZKZPYK7uZQPAIniijse8V4bO/cabLnzly0V7fwRfipt0EweNB8BM0mzbR8q9 +WfUOBx/78Qwz7EYKih5hY6fmZLBv1mPX8+oaa8JG8vBgNNUAGPfdGgxklEqOTjubV MGSzQA7TiORxR1kMRo5VA6drktmP7P/Usn0lNP8qIZIRNSo4KR4j5NwJzua0IDSjSW dmL1lK9qdaQsOE0Q66DOfOwtOzDD3elojxy+XAnIIVxxT5Iw2ee9Zi0H+2BAUfWR5A qWldTTNg4CfQw== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Peter Zijlstra , "Rafael J . Wysocki" , Daniel Lezcano , Thomas Gleixner , Anna-Maria Behnsen Subject: [PATCH 08/10] x86: Remove __current_clr_polling() from mwait_idle() Date: Fri, 11 Aug 2023 19:00:47 +0200 Message-Id: <20230811170049.308866-9-frederic@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230811170049.308866-1-frederic@kernel.org> References: <20230811170049.308866-1-frederic@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" mwait_idle() is only ever called through by cpuidle, either from default_idle_call() or from cpuidle_enter(). In any case cpuidle_idle_call() sets again TIF_NR_POLLING after calling it so there is no point for this atomic operation upon idle exit. Signed-off-by: Frederic Weisbecker Acked-by: Rafael J. Wysocki --- arch/x86/kernel/process.c | 1 - 1 file changed, 1 deletion(-) diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c index 72015dba72ab..f1eb769770b1 100644 --- a/arch/x86/kernel/process.c +++ b/arch/x86/kernel/process.c @@ -918,7 +918,6 @@ static __cpuidle void mwait_idle(void) raw_local_irq_disable(); } } - __current_clr_polling(); } =20 void select_idle_routine(const struct cpuinfo_x86 *c) --=20 2.34.1 From nobody Fri Dec 19 04:49:12 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 78387EB64DD for ; Fri, 11 Aug 2023 17:01:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236418AbjHKRBq (ORCPT ); Fri, 11 Aug 2023 13:01:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236258AbjHKRBT (ORCPT ); Fri, 11 Aug 2023 13:01:19 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D34C30F4 for ; Fri, 11 Aug 2023 10:01:16 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B406B65816 for ; Fri, 11 Aug 2023 17:01:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5A9C4C433CC; Fri, 11 Aug 2023 17:01:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691773275; bh=MZmgDtu6USFXQ4e5nMMY/JREFBhjkYnO2RkDI2BMkjU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tsZvUQ8ySYF4A2/3RW0XnSo8R5YkRZYqdUrubU/I4yprZB7EkuAc8o0ZDWS6CgdIj /pti4fyBFMT4Sv5SBTP1DZ9IRU8YcGYdjcDmsKDoZ/rHHBT5zmVCoPU9Q3MjhOn8/C E9AuFAiCgmS2cl/iDyxSVbPN47DpkxdEM6o8+FBYHd0GnoMFW3PT3fUriTZ71egoNH by8fx8X7n9VDlixdvztUxnZdl4Hwp0qoCeTXDXltjXgxrB/tHMV9Q2f0oVRYsGAPD4 xUhRjxJQ6Bdp+cro5zKPo1PCtBsS9f+d30qWxh2lr1VXdSqk/+Te1ThPAtMV016YG5 4HiBbDkUAESlA== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Len Brown , Peter Zijlstra , "Rafael J . Wysocki" , Daniel Lezcano , Thomas Gleixner , Anna-Maria Behnsen Subject: [PATCH 09/10] x86: Remove the current_clr_polling() call upon mwait exit Date: Fri, 11 Aug 2023 19:00:48 +0200 Message-Id: <20230811170049.308866-10-frederic@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230811170049.308866-1-frederic@kernel.org> References: <20230811170049.308866-1-frederic@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" mwait_idle_with_hints() is mostly called from cpuidle which already sets back TIF_NR_POLLING and fold TIF_NEED_RESCHED if necessary. The only non-cpuidle caller is power_saving_thread() which acts as an idle loop and is the only reason why mwait_idle_with_hints() carries a costly fully ordered atomic operation upon idle exit. Make this overhead proper to power_saving_thread() instead which already duplicates quite some cpuidle code. Signed-off-by: Frederic Weisbecker Acked-by: Rafael J. Wysocki --- arch/x86/include/asm/mwait.h | 1 - drivers/acpi/acpi_pad.c | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/include/asm/mwait.h b/arch/x86/include/asm/mwait.h index 920426d691ce..c1be3775b94a 100644 --- a/arch/x86/include/asm/mwait.h +++ b/arch/x86/include/asm/mwait.h @@ -134,7 +134,6 @@ static __always_inline void mwait_idle_with_hints(unsig= ned long eax, unsigned lo } } } - current_clr_polling(); } =20 /* diff --git a/drivers/acpi/acpi_pad.c b/drivers/acpi/acpi_pad.c index 7a453c5ff303..5a44afafe185 100644 --- a/drivers/acpi/acpi_pad.c +++ b/drivers/acpi/acpi_pad.c @@ -174,6 +174,7 @@ static int power_saving_thread(void *data) stop_critical_timings(); =20 mwait_idle_with_hints(power_saving_mwait_eax, 1); + current_clr_polling(); =20 start_critical_timings(); tick_broadcast_exit(); --=20 2.34.1 From nobody Fri Dec 19 04:49:12 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CACE8C001DE for ; Fri, 11 Aug 2023 17:01:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236144AbjHKRBs (ORCPT ); Fri, 11 Aug 2023 13:01:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233683AbjHKRBV (ORCPT ); Fri, 11 Aug 2023 13:01:21 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B5E530FC for ; Fri, 11 Aug 2023 10:01:18 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BF77065939 for ; Fri, 11 Aug 2023 17:01:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9360CC433CB; Fri, 11 Aug 2023 17:01:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691773277; bh=P4hs1/vw36aQkpeJTSOOps59gS7gR0fhrgXS9eBIDR8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=NrrMLc0j8bQVcFnhM/w9g+r6Jx7CbJC1Aptg+KGJMQYywqTu8zZGMtNNk2L+HG9z0 tqpckeIrYK2wdaicMpSB3HMZKuo+d98Tz6kQ5+JSek8FQffuhop5UonVZXQPUj1g1g vuvlBpHO6d31PCOCW5avnN1CjyuoYN6vwOpFMN1oM2kKu5cWwfkRlDAa05OdPN3LkG aIvAmc1WKA9b01Qv2qvPwQPLVzPviCfRZVpPtd8hwOEUe25TgQMLdZ7FdMnn00CYt8 vBcppA144m1gmulthZZ7oeI49eYC85SAMKw0YZVCbAd/fUMOVrMWfnNendhXccnQbg j7psMNPqSQTkg== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Peter Zijlstra , "Rafael J . Wysocki" , Daniel Lezcano , Thomas Gleixner , Anna-Maria Behnsen Subject: [PATCH 10/10] sched/timers: Explain why idle task schedules out on remote timer enqueue Date: Fri, 11 Aug 2023 19:00:49 +0200 Message-Id: <20230811170049.308866-11-frederic@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230811170049.308866-1-frederic@kernel.org> References: <20230811170049.308866-1-frederic@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Trying to avoid that didn't bring much value after testing, add comment about this. Signed-off-by: Frederic Weisbecker Acked-by: Rafael J. Wysocki --- kernel/sched/core.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/kernel/sched/core.c b/kernel/sched/core.c index c52c2eba7c73..e53b892167ad 100644 --- a/kernel/sched/core.c +++ b/kernel/sched/core.c @@ -1135,6 +1135,28 @@ static void wake_up_idle_cpu(int cpu) if (cpu =3D=3D smp_processor_id()) return; =20 + /* + * Set TIF_NEED_RESCHED and send an IPI if in the non-polling + * part of the idle loop. This forces an exit from the idle loop + * and a round trip to schedule(). Now this could be optimized + * because a simple new idle loop iteration is enough to + * re-evaluate the next tick. Provided some re-ordering of tick + * nohz functions that would need to follow TIF_NR_POLLING + * clearing: + * + * - On most archs, a simple fetch_or on ti::flags with a + * "0" value would be enough to know if an IPI needs to be sent. + * + * - x86 needs to perform a last need_resched() check between + * monitor and mwait which doesn't take timers into account. + * There a dedicated TIF_TIMER flag would be required to + * fetch_or here and be checked along with TIF_NEED_RESCHED + * before mwait(). + * + * However, remote timer enqueue is not such a frequent event + * and testing of the above solutions didn't appear to report + * much benefits. + */ if (set_nr_and_not_polling(rq->idle)) smp_send_reschedule(cpu); else --=20 2.34.1