2018-03-22 16:41:17 +08:00
|
|
|
/*
|
2020-02-23 05:21:06 +08:00
|
|
|
* Copyright (C) 2018-2020 Intel Corporation
|
2018-09-18 15:11:08 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
2018-03-22 16:41:17 +08:00
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/helpers/kmd_notify_properties.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/debug_settings/debug_settings_manager.h"
|
2018-03-22 16:41:17 +08:00
|
|
|
|
2019-02-27 18:39:32 +08:00
|
|
|
#include <cstdint>
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
using namespace NEO;
|
2018-03-22 16:41:17 +08:00
|
|
|
|
2018-04-10 16:26:59 +08:00
|
|
|
bool KmdNotifyHelper::obtainTimeoutParams(int64_t &timeoutValueOutput,
|
|
|
|
bool quickKmdSleepRequest,
|
|
|
|
uint32_t currentHwTag,
|
|
|
|
uint32_t taskCountToWait,
|
2018-11-16 19:46:49 +08:00
|
|
|
FlushStamp flushStampToWait,
|
|
|
|
bool forcePowerSavingMode) {
|
2018-11-15 00:33:20 +08:00
|
|
|
if (flushStampToWait == 0) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-11-16 19:46:49 +08:00
|
|
|
if (DebugManager.flags.PowerSavingMode.get() || forcePowerSavingMode) {
|
2018-11-15 00:33:20 +08:00
|
|
|
timeoutValueOutput = 1;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-04-10 16:26:59 +08:00
|
|
|
int64_t multiplier = (currentHwTag < taskCountToWait) ? static_cast<int64_t>(taskCountToWait - currentHwTag) : 1;
|
|
|
|
if (!properties->enableKmdNotify && multiplier > KmdNotifyConstants::minimumTaskCountDiffToCheckAcLine) {
|
|
|
|
updateAcLineStatus();
|
|
|
|
}
|
2018-04-09 16:05:32 +08:00
|
|
|
|
2018-04-10 16:26:59 +08:00
|
|
|
quickKmdSleepRequest |= applyQuickKmdSleepForSporadicWait();
|
2018-04-09 16:05:32 +08:00
|
|
|
|
2019-05-07 20:24:13 +08:00
|
|
|
if (!properties->enableKmdNotify && !acLineConnected) {
|
2018-04-10 16:26:59 +08:00
|
|
|
timeoutValueOutput = KmdNotifyConstants::timeoutInMicrosecondsForDisconnectedAcLine;
|
|
|
|
} else if (quickKmdSleepRequest && properties->enableQuickKmdSleep) {
|
|
|
|
timeoutValueOutput = properties->delayQuickKmdSleepMicroseconds;
|
|
|
|
} else {
|
2018-04-20 01:08:10 +08:00
|
|
|
timeoutValueOutput = getBaseTimeout(multiplier);
|
2018-04-09 16:05:32 +08:00
|
|
|
}
|
|
|
|
|
2018-11-15 00:33:20 +08:00
|
|
|
return (properties->enableKmdNotify || !acLineConnected);
|
2018-04-09 16:05:32 +08:00
|
|
|
}
|
|
|
|
|
2018-04-10 16:26:59 +08:00
|
|
|
bool KmdNotifyHelper::applyQuickKmdSleepForSporadicWait() const {
|
|
|
|
if (properties->enableQuickKmdSleepForSporadicWaits) {
|
2018-06-07 15:14:00 +08:00
|
|
|
auto timeDiff = getMicrosecondsSinceEpoch() - lastWaitForCompletionTimestampUs.load();
|
2018-04-10 16:26:59 +08:00
|
|
|
if (timeDiff > properties->delayQuickKmdSleepForSporadicWaitsMicroseconds) {
|
2018-03-22 16:41:17 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-04-10 16:26:59 +08:00
|
|
|
void KmdNotifyHelper::updateLastWaitForCompletionTimestamp() {
|
2018-06-07 15:14:00 +08:00
|
|
|
lastWaitForCompletionTimestampUs = getMicrosecondsSinceEpoch();
|
|
|
|
}
|
|
|
|
|
|
|
|
int64_t KmdNotifyHelper::getMicrosecondsSinceEpoch() const {
|
|
|
|
auto now = std::chrono::high_resolution_clock::now().time_since_epoch();
|
|
|
|
return std::chrono::duration_cast<std::chrono::microseconds>(now).count();
|
2018-04-10 16:26:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void KmdNotifyHelper::overrideFromDebugVariable(int32_t debugVariableValue, int64_t &destination) {
|
2018-03-22 16:41:17 +08:00
|
|
|
if (debugVariableValue >= 0) {
|
|
|
|
destination = static_cast<int64_t>(debugVariableValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-10 16:26:59 +08:00
|
|
|
void KmdNotifyHelper::overrideFromDebugVariable(int32_t debugVariableValue, bool &destination) {
|
2018-03-22 16:41:17 +08:00
|
|
|
if (debugVariableValue >= 0) {
|
|
|
|
destination = !!(debugVariableValue);
|
|
|
|
}
|
|
|
|
}
|