Skip to content

Conversation

@Enigamict
Copy link

@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
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
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
} else {
let _irq_enable = awkernel_lib::interrupt::InterruptEnable::new();
awkernel_lib::delay::wait_microsec(10);
awkernel_lib::cpu::sleep_cpu(None);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If us <= 1000, the main CPU will not wake up after us microseconds.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Having CPUs remain in the HLT state indefinitely when a specific timeout is requested would be a more serious issue. Therefore, I’ll revert this part to the previous implementation that uses a busy-loop for short waits.

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
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.

3 participants