From 9292abb2d8398eed32b1ba16259e6c636ac9edb7 Mon Sep 17 00:00:00 2001 From: Saleel Kudchadker Date: Fri, 18 Mar 2022 11:28:55 -0700 Subject: [PATCH] SWDEV-328349 - Rate limit hostcall listener Update timeout for hostcall wait for signal. If the timeout is small it checks frequent enough to affect performance for certain applications which may be CPU bound. Change-Id: I0a879559e4ad111b09a994a5b82a6faf6e4fea3f --- rocclr/device/devhostcall.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/rocclr/device/devhostcall.cpp b/rocclr/device/devhostcall.cpp index afd1cdf23d..c87ad199ae 100644 --- a/rocclr/device/devhostcall.cpp +++ b/rocclr/device/devhostcall.cpp @@ -270,17 +270,25 @@ class HostcallListener { HostcallListener* hostcallListener = nullptr; amd::Monitor listenerLock("Hostcall listener lock"); +constexpr static uint64_t kTimeoutFloor = K * K * 4; +constexpr static uint64_t kTimeoutCeil = K * K * 16; void HostcallListener::consumePackets() { - uint64_t timeout = 1024 * 1024; + uint64_t timeout = kTimeoutFloor; uint64_t signal_value = SIGNAL_INIT; while (true) { while (true) { uint64_t new_value = doorbell_->Wait(signal_value, device::Signal::Condition::Ne, timeout); if (new_value != signal_value) { signal_value = new_value; + // Reduce the timeout for quicker processing + timeout = timeout >> 0x1; + timeout = std::max(kTimeoutFloor, timeout); break; } + // Increase the timeout since we dont need to check as frequently + timeout = timeout << 0x1; + timeout = std::min(kTimeoutCeil, timeout); } if (signal_value == SIGNAL_DONE) {