x86/i8253: Disable PIT timer 0 when not in use
Subsystems (3)
PATCH 1/1 x86/i8253: Disable PIT timer 0 when not in use
commit 70e6b7d9ae3c63df90a7bba7700e8d5c300c3c60 upstream
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.
--- arch/x86/kernel/i8253.c | 11 +++++++++-- drivers/clocksource/i8253.c | 13 +++++++++---- include/linux/i8253.h | 1 + 3 files changed, 19 insertions(+), 6 deletions(-)
arch/x86/kernel/i8253.c +9 -2
@@ -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;
drivers/clocksource/i8253.c +9 -4
@@ -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 ; }
include/linux/i8253.h +1 -0
@@ -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 );
Signature · 1 line
2.47.1
Greg KH
maintainerQuoted 16 lines · Jay Wang
commit
70e6b7d9ae3c63df90a7bba7700e8d5c300c3c60upstreamLeaving 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 <[email protected]>Signed-off-by Thomas Gleixner <[email protected]>Tested-by Michael Kelley <[email protected]>Signed-off-by Jay Wang <[email protected]>Cc [email protected] #v5.10/v5.15/v6.1
Quoted 5 lines
--- arch/x86/kernel/i8253.c | 11 +++++++++-- drivers/clocksource/i8253.c | 13 +++++++++---- include/linux/i8253.h | 1 + 3 files changed, 19 insertions(+), 6 deletions(-)
Why don't you also want this in 6.6.y? You can't submit patches for only older kernels without them also being in newer ones, otherwise you will get a regression when upgrading.
Please always submit patches for all relevant kernel trees.
thanks,
greg k-h
PATCH 1/1 Please also incorporate this patch into 6.6.y
commit 70e6b7d9ae3c63df90a7bba7700e8d5c300c3c60 upstream
Jay Wang (1):
x86/i8253: Disable PIT timer 0 when not in use
arch/x86/kernel/i8253.c | 11 +++++++++-- drivers/clocksource/i8253.c | 13 +++++++++---- include/linux/i8253.h | 1 + 3 files changed, 19 insertions(+), 6 deletions(-)
Signature · 1 line
2.47.1