Skip to content

Comments

perf(timer): unify idle to HLT and bump LAPIC tick to 1ms#657

Merged
ytakano merged 1 commit intomainfrom
perf/apic-timer-hlt-idle
Nov 10, 2025
Merged

perf(timer): unify idle to HLT and bump LAPIC tick to 1ms#657
ytakano merged 1 commit intomainfrom
perf/apic-timer-hlt-idle

Conversation

@Enigamict
Copy link
Contributor

@Enigamict Enigamict commented Oct 31, 2025

Description

First, On QEMU, CPU threads sometimes spiked to 900–1400% host CPU.
A combination of short-period timers(100 µs)and busy-wait, creating an interrupt reprogramming loop so dense that hlt was rarely reached.

Next, Added the changes below

  1. LAPIC timer period from 100 µs → 1 ms to prevent interrupt overruns that keep cores from idling.

With this change, CPU runaway no longer occurs, and the system runs stably on QEMU.

Related links

How was this PR tested?

Notes for reviewers

@Enigamict
Copy link
Contributor Author

todo: Investigate a strategy to branch timer configuration between QEMU and physical machines, reflecting their markedly different timer behavior.

@Enigamict Enigamict force-pushed the perf/apic-timer-hlt-idle branch from 67e4444 to 935b7cf Compare November 5, 2025 09:24
@Enigamict
Copy link
Contributor Author

Enigamict commented Nov 5, 2025

To handle differences between real hardware and virtualized environments, I implemented detection for KVM/QEMU and adjusted the local APIC timer period accordingly.
The CPU sleep subsystem sleep_cpu_no_std::init() and sleep_cpu_no_std::reset_wakeup_timer() now uses wakeup_interval() to perform keep-alive scheduling: 1 ms under KVM/QEMU and 100 µs on bare-metal hardware.
Note that this detection relies on x86_64 CPUID information, so this adaptive timing mechanism is currently limited to the x86_64 architecture.

@Enigamict Enigamict marked this pull request as ready for review November 5, 2025 09:32
@Enigamict Enigamict requested a review from ytakano November 5, 2025 09:32
Signed-off-by: Enigamict <atsuki.takata@tier4.jp>
@Enigamict Enigamict force-pushed the perf/apic-timer-hlt-idle branch from 935b7cf to ecdaeac Compare November 7, 2025 08:43
@Enigamict Enigamict requested a review from ytakano November 7, 2025 09:05
@ytakano ytakano merged commit 32ff7bc into main Nov 10, 2025
1 check passed
@ytakano ytakano deleted the perf/apic-timer-hlt-idle branch November 10, 2025 06:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants