Skip to content

Commit 4341ad0

Browse files
Add PowerSaving debug variable.
- It allows to easily turn ON the power saving mode for the driver. - In that mode, whenever GPU is not ready it will put current thread to sleep, thread is resumed when GPU completes. - PowerSaving mode reduces CPU utilization on blocking calls, while increasing completion latencies. Change-Id: I3de83713687952ac31a1ec8c397f48aa4212781d
1 parent 8c87fdd commit 4341ad0

File tree

5 files changed

+45
-2
lines changed

5 files changed

+45
-2
lines changed

runtime/helpers/kmd_notify_properties.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
#include <cstdint>
99
#include "runtime/helpers/kmd_notify_properties.h"
10+
#include "runtime/os_interface/debug_settings_manager.h"
1011

1112
using namespace OCLRT;
1213

@@ -15,6 +16,15 @@ bool KmdNotifyHelper::obtainTimeoutParams(int64_t &timeoutValueOutput,
1516
uint32_t currentHwTag,
1617
uint32_t taskCountToWait,
1718
FlushStamp flushStampToWait) {
19+
if (flushStampToWait == 0) {
20+
return false;
21+
}
22+
23+
if (DebugManager.flags.PowerSavingMode.get()) {
24+
timeoutValueOutput = 1;
25+
return true;
26+
}
27+
1828
int64_t multiplier = (currentHwTag < taskCountToWait) ? static_cast<int64_t>(taskCountToWait - currentHwTag) : 1;
1929
if (!properties->enableKmdNotify && multiplier > KmdNotifyConstants::minimumTaskCountDiffToCheckAcLine) {
2030
updateAcLineStatus();
@@ -32,7 +42,7 @@ bool KmdNotifyHelper::obtainTimeoutParams(int64_t &timeoutValueOutput,
3242
timeoutValueOutput = getBaseTimeout(multiplier);
3343
}
3444

35-
return flushStampToWait != 0 && (properties->enableKmdNotify || !acLineConnected);
45+
return (properties->enableKmdNotify || !acLineConnected);
3646
}
3747

3848
bool KmdNotifyHelper::applyQuickKmdSleepForSporadicWait() const {

runtime/os_interface/debug_variables_base.inl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ DECLARE_DEBUG_VARIABLE(int32_t, OverrideEnableQuickKmdSleep, -1, "-1: dont overr
100100
DECLARE_DEBUG_VARIABLE(int32_t, OverrideQuickKmdSleepDelayMicroseconds, -1, "-1: dont override, 0: infinite timeout, >0: timeout in microseconds")
101101
DECLARE_DEBUG_VARIABLE(int32_t, OverrideEnableQuickKmdSleepForSporadicWaits, -1, "-1: dont override, 0: disable, 1: enable. It works only when QuickKmdSleep is enabled.")
102102
DECLARE_DEBUG_VARIABLE(int32_t, OverrideDelayQuickKmdSleepForSporadicWaitsMicroseconds, -1, "-1: dont override, >0: timeout in microseconds")
103+
DECLARE_DEBUG_VARIABLE(int32_t, PowerSavingMode, 0, "0: default 1: enable. Whenever driver waits on GPU and its not ready, put waiting thread to sleep and wait for notification.")
103104
DECLARE_DEBUG_VARIABLE(int32_t, CsrDispatchMode, 0, "Chooses DispatchMode for Csr")
104105
DECLARE_DEBUG_VARIABLE(int32_t, OverrideDefaultFP64Settings, -1, "-1: dont override, 0: disable, 1: enable.")
105106

unit_tests/event/event_tests.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,6 +1389,7 @@ HWTEST_F(EventTest, givenQuickKmdSleepRequestWhenWaitIsCalledThenPassRequestToWa
13891389
pDevice->resetCommandStreamReceiver(csr);
13901390

13911391
Event event(pCmdQ, CL_COMMAND_NDRANGE_KERNEL, 0, 0);
1392+
event.updateCompletionStamp(1u, 1u, 1u);
13921393

13931394
EXPECT_CALL(*csr, waitForCompletionWithTimeout(::testing::_,
13941395
localHwInfo.capabilityTable.kmdNotifyProperties.delayQuickKmdSleepMicroseconds, ::testing::_))
@@ -1414,6 +1415,7 @@ HWTEST_F(EventTest, givenNonQuickKmdSleepRequestWhenWaitIsCalledThenPassRequestT
14141415
pDevice->resetCommandStreamReceiver(csr);
14151416

14161417
Event event(pCmdQ, CL_COMMAND_NDRANGE_KERNEL, 0, 0);
1418+
event.updateCompletionStamp(1u, 1u, 1u);
14171419

14181420
EXPECT_CALL(*csr, waitForCompletionWithTimeout(::testing::_,
14191421
localHwInfo.capabilityTable.kmdNotifyProperties.delayKmdNotifyMicroseconds, ::testing::_))

unit_tests/helpers/kmd_notify_tests.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "runtime/command_queue/command_queue.h"
99
#include "runtime/os_interface/os_context.h"
1010

11+
#include "unit_tests/helpers/debug_manager_state_restore.h"
1112
#include "unit_tests/mocks/mock_device.h"
1213
#include "unit_tests/mocks/mock_context.h"
1314
#include "test.h"
@@ -366,6 +367,34 @@ TEST_F(KmdNotifyTests, givenDisabledKmdNotifyMechanismAndFlushStampIsZeroWhenAcL
366367
EXPECT_FALSE(timeoutEnabled);
367368
}
368369

370+
TEST_F(KmdNotifyTests, givenDisabledKmdNotifyMechanismWhenPowerSavingModeIsSetThenKmdNotifyMechanismIsUsedAndReturnsShortestWaitingTimePossible) {
371+
DebugManagerStateRestore stateRestore;
372+
DebugManager.flags.PowerSavingMode.set(1u);
373+
localHwInfo.capabilityTable.kmdNotifyProperties.enableKmdNotify = false;
374+
MockKmdNotifyHelper helper(&(localHwInfo.capabilityTable.kmdNotifyProperties));
375+
helper.acLineConnected = false;
376+
377+
int64_t timeout = 0;
378+
FlushStamp flushStampToWait = 1;
379+
bool timeoutEnabled = helper.obtainTimeoutParams(timeout, false, 1, 2, flushStampToWait);
380+
EXPECT_TRUE(timeoutEnabled);
381+
EXPECT_EQ(1, timeout);
382+
}
383+
384+
TEST_F(KmdNotifyTests, givenEnabledKmdNotifyMechanismWhenPowerSavingModeIsSetAndNoFlushStampProvidedWhenParametersAreObtainedThenFalseIsReturned) {
385+
DebugManagerStateRestore stateRestore;
386+
DebugManager.flags.PowerSavingMode.set(1u);
387+
localHwInfo.capabilityTable.kmdNotifyProperties.enableKmdNotify = true;
388+
MockKmdNotifyHelper helper(&(localHwInfo.capabilityTable.kmdNotifyProperties));
389+
helper.acLineConnected = false;
390+
391+
int64_t timeout = 0;
392+
FlushStamp flushStampToWait = 0;
393+
bool timeoutEnabled = helper.obtainTimeoutParams(timeout, false, 1, 2, flushStampToWait);
394+
EXPECT_FALSE(timeoutEnabled);
395+
EXPECT_EQ(0, timeout);
396+
}
397+
369398
#if defined(__clang__)
370399
#pragma clang diagnostic pop
371400
#endif

unit_tests/test_files/igdrcl.config

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,5 @@ UseAubStream = false
9595
AubDumpOverrideMmioRegister = 0
9696
AubDumpOverrideMmioRegisterValue = 0
9797
AubDumpAddMmioRegister = 0
98-
AubDumpAddMmioRegisterValue = 0
98+
AubDumpAddMmioRegisterValue = 0
99+
PowerSavingMode = 0

0 commit comments

Comments
 (0)