stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] x86/i8253: Disable PIT timer 0 when not in use
@ 2025-02-17 20:24 jaywang-amazon
  2025-02-18  7:49 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: jaywang-amazon @ 2025-02-17 20:24 UTC (permalink / raw)
  To: stable

From: David Woodhouse <dwmw@amazon.co.uk>

[upstream commit 70e6b7d9ae3c63df90a7bba7700e8d5c300c360]

Leaving the PIT interrupt running can cause noticeable steal time for
virtual guests. The VMM generally has a timer which toggles the IRQ input
to the PIC and I/O APIC, which takes CPU time away from the guest. Even
on real hardware, running the counter may use power needlessly (albeit
not much).

Make sure it's turned off if it isn't going to be used.

Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Tested-by: Michael Kelley <mhkelley@outlook.com>
Link: https://lore.kernel.org/all/20240802135555.564941-1-dwmw2@infradead.org

(cherry picked from commit 70e6b7d9ae3c63df90a7bba7700e8d5c300c3c60)

Cc: stable@vger.kernel.org # v5.15

Signed-off-by: jaywang-amazon <wanjay@amazon.com>
---
 arch/x86/kernel/i8253.c     | 11 +++++++++--
 drivers/clocksource/i8253.c | 13 +++++++++----
 include/linux/i8253.h       |  1 +
 3 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/arch/x86/kernel/i8253.c b/arch/x86/kernel/i8253.c
index 2b7999a1a50a..80e262bb627f 100644
--- a/arch/x86/kernel/i8253.c
+++ b/arch/x86/kernel/i8253.c
@@ -8,6 +8,7 @@
 #include <linux/timex.h>
 #include <linux/i8253.h>
 
+#include <asm/hypervisor.h>
 #include <asm/apic.h>
 #include <asm/hpet.h>
 #include <asm/time.h>
@@ -39,9 +40,15 @@ static bool __init use_pit(void)
 
 bool __init pit_timer_init(void)
 {
-	if (!use_pit())
+	if (!use_pit()) {
+		/*
+		 * Don't just ignore the PIT. Ensure it's stopped, because
+		 * VMMs otherwise steal CPU time just to pointlessly waggle
+		 * the (masked) IRQ.
+		 */
+		clockevent_i8253_disable();
 		return false;
-
+	}
 	clockevent_i8253_init(true);
 	global_clock_event = &i8253_clockevent;
 	return true;
diff --git a/drivers/clocksource/i8253.c b/drivers/clocksource/i8253.c
index d4350bb10b83..cb215e6f2e83 100644
--- a/drivers/clocksource/i8253.c
+++ b/drivers/clocksource/i8253.c
@@ -108,11 +108,8 @@ int __init clocksource_i8253_init(void)
 #endif
 
 #ifdef CONFIG_CLKEVT_I8253
-static int pit_shutdown(struct clock_event_device *evt)
+void clockevent_i8253_disable(void)
 {
-	if (!clockevent_state_oneshot(evt) && !clockevent_state_periodic(evt))
-		return 0;
-
 	raw_spin_lock(&i8253_lock);
 
 	outb_p(0x30, PIT_MODE);
@@ -123,6 +120,14 @@ static int pit_shutdown(struct clock_event_device *evt)
 	}
 
 	raw_spin_unlock(&i8253_lock);
+}
+
+static int pit_shutdown(struct clock_event_device *evt)
+{
+	if (!clockevent_state_oneshot(evt) && !clockevent_state_periodic(evt))
+		return 0;
+
+	clockevent_i8253_disable();
 	return 0;
 }
 
diff --git a/include/linux/i8253.h b/include/linux/i8253.h
index 8336b2f6f834..bf169cfef7f1 100644
--- a/include/linux/i8253.h
+++ b/include/linux/i8253.h
@@ -24,6 +24,7 @@ extern raw_spinlock_t i8253_lock;
 extern bool i8253_clear_counter_on_shutdown;
 extern struct clock_event_device i8253_clockevent;
 extern void clockevent_i8253_init(bool oneshot);
+extern void clockevent_i8253_disable(void);
 
 extern void setup_pit_timer(void);
 
-- 
2.47.1


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] x86/i8253: Disable PIT timer 0 when not in use
  2025-02-17 20:24 [PATCH] x86/i8253: Disable PIT timer 0 when not in use jaywang-amazon
@ 2025-02-18  7:49 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2025-02-18  7:49 UTC (permalink / raw)
  To: jaywang-amazon; +Cc: stable

On Mon, Feb 17, 2025 at 08:24:34PM +0000, jaywang-amazon wrote:
> From: David Woodhouse <dwmw@amazon.co.uk>
> 
> [upstream commit 70e6b7d9ae3c63df90a7bba7700e8d5c300c360]
> 
> Leaving the PIT interrupt running can cause noticeable steal time for
> virtual guests. The VMM generally has a timer which toggles the IRQ input
> to the PIC and I/O APIC, which takes CPU time away from the guest. Even
> on real hardware, running the counter may use power needlessly (albeit
> not much).
> 
> Make sure it's turned off if it isn't going to be used.
> 
> Signed-off-by: David Woodhouse <dwmw@amazon.co.uk>
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Tested-by: Michael Kelley <mhkelley@outlook.com>
> Link: https://lore.kernel.org/all/20240802135555.564941-1-dwmw2@infradead.org
> 
> (cherry picked from commit 70e6b7d9ae3c63df90a7bba7700e8d5c300c3c60)
> 
> Cc: stable@vger.kernel.org # v5.15
> 
> Signed-off-by: jaywang-amazon <wanjay@amazon.com>

Why all the blank space here?

And why not cc: all of the people who did this patch on it?

Also your name needs to be fixed up.

Please work with your coworkers on getting this all right so we don't
have to do this type of basic reviewing for you.  All of your recent
backprots suffer from this and can not be taken, sorry.

greg k-h

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-02-18  7:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-17 20:24 [PATCH] x86/i8253: Disable PIT timer 0 when not in use jaywang-amazon
2025-02-18  7:49 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).