[Threading] Add thread priority mapping with timer-driven quantum decay

And default ignore_thread_priorities to false.

Map Xenon's 0-31 priority range across all 5 host priority levels
instead of collapsing 0-17 into kNormal.

Use timer-driven quantum decay (~20ms period) matching Xenon's
60-quantum / 3-per-tick cycle to prevent starvation by gradually lowering
effective priority for non-real-time threads (< 18), piggybacking on the
existing 1ms timestamp timer.
This commit is contained in:
Herman S.
2026-04-09 22:33:08 +09:00
parent 61c8eb0707
commit b3d8a21b72
7 changed files with 194 additions and 44 deletions

View File

@@ -1151,6 +1151,18 @@ void KernelState::UpdateKeTimestampBundle() {
xe::store_and_swap<uint64_t>(&lpKeTimeStampBundle->system_time,
Clock::QueryGuestSystemTime());
xe::store_and_swap<uint32_t>(&lpKeTimeStampBundle->tick_count, uptime_ms);
// Every 20 ticks (~20ms), decay priority on running guest threads.
// This simulates the Xenon decrementer-driven quantum expiration.
if (++quantum_timer_counter_ >= 20) {
quantum_timer_counter_ = 0;
auto global_lock = global_critical_region_.Acquire();
for (auto& [id, thread] : threads_by_id_) {
if (thread->is_running()) {
thread->CheckQuantumAndDecay();
}
}
}
}
uint32_t KernelState::GetKeTimestampBundle() {