From: "tip-bot2 for David Woodhouse" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: David Woodhouse <dwmw@amazon.co.uk>,
Thomas Gleixner <tglx@linutronix.de>,
Michael Kelley <mhkelley@outlook.com>,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: x86/timers] x86/i8253: Disable PIT timer 0 when not in use
Date: Fri, 02 Aug 2024 16:35:01 -0000 [thread overview]
Message-ID: <172261650197.2215.13331839934148253272.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20240802135555.564941-1-dwmw2@infradead.org>
The following commit has been merged into the x86/timers branch of tip:
Commit-ID: 70e6b7d9ae3c63df90a7bba7700e8d5c300c3c60
Gitweb: https://git.kernel.org/tip/70e6b7d9ae3c63df90a7bba7700e8d5c300c3c60
Author: David Woodhouse <dwmw@amazon.co.uk>
AuthorDate: Fri, 02 Aug 2024 14:55:54 +01:00
Committer: Thomas Gleixner <tglx@linutronix.de>
CommitterDate: Fri, 02 Aug 2024 18:27:05 +02:00
x86/i8253: Disable PIT timer 0 when not in use
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
---
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 2b7999a..80e262b 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 d4350bb..cb215e6 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 8336b2f..bf169cf 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);
prev parent reply other threads:[~2024-08-02 16:35 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-02 13:55 [PATCH 1/2] i8253: " David Woodhouse
2024-08-02 13:55 ` [PATCH 2/2] i8253: Fix stop sequence for timer 0 David Woodhouse
2024-08-02 16:35 ` [tip: x86/timers] clockevents/drivers/i8253: " tip-bot2 for David Woodhouse
2024-08-02 15:44 ` [PATCH 1/2] i8253: Disable PIT timer 0 when not in use Michael Kelley
2024-08-02 16:01 ` David Woodhouse
2024-08-02 16:35 ` tip-bot2 for David Woodhouse [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=172261650197.2215.13331839934148253272.tip-bot2@tip-bot2 \
--to=tip-bot2@linutronix.de \
--cc=dwmw@amazon.co.uk \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=mhkelley@outlook.com \
--cc=tglx@linutronix.de \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®