fix: reduce idle CPU wakeups and deferred-work polling

This commit is contained in:
daniel committed 2026-08-15 16:50:36 +02:00
1 parent f7677ac3f1
commit 788b662d44
10 files changed
+109 -14

No files matched your search

@@ -419,6 +419,14 @@ namespace Drivers::USB::Bluetooth {
// ServiceEvents — steady-state event pump (idle loop)
// =========================================================================
bool HasDeferredWork() {
if (g_initPending.load(std::memory_order_acquire) &&
!g_initialized && Fs::Vfs::IsDriveRegistered(0)) {
return true;
}
return g_initialized && Hci::HasPendingCommands();
}
void ServiceEvents() {
if (!g_initialized) return;
if (Xhci::InPollContext()) return; // never nest under PollEvents
@@ -27,6 +27,11 @@ namespace Drivers::USB::Bluetooth {
// (PollEvents/DrainEvents/ProcessPendingCommands all self-serialize).
void ServiceEvents();
// True when boot-deferred initialization or queued HCI control work needs
// an idle-context service pass. USB receive events are signaled separately
// by xHCI and cause the dispatcher to service Bluetooth in the same pass.
bool HasDeferredWork();
// Query adapter state
bool IsInitialized();
uint8_t GetSlotId();
+5
View File
@@ -1719,6 +1719,11 @@ namespace Drivers::USB::Bluetooth::Hci {
s_active.store(false, std::memory_order_release);
}
bool HasPendingCommands() {
return g_pendingTail.load(std::memory_order_acquire) !=
g_pendingHead.load(std::memory_order_acquire);
}
bool WaitSecureSendResult(uint32_t timeoutMs, uint8_t* outResult, uint8_t* outStatus) {
uint64_t start = Timekeeping::GetMilliseconds();
while (Timekeeping::GetMilliseconds() - start < timeoutMs) {
+1
View File
@@ -331,6 +331,7 @@ namespace Drivers::USB::Bluetooth::Hci {
// real confirmed transfers. Call from top-level (e.g. the connect loop),
// NOT from an event handler -- event handlers only enqueue.
void ProcessPendingCommands();
bool HasPendingCommands();
// ACL TX flow control: outstanding (un-acked) ACL packets, and the
// controller's ACL buffer count (Number-Of-Completed-Packets credits). The