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