2018-03-22 16:41:17 +08:00
|
|
|
/*
|
2022-03-23 22:36:07 +08:00
|
|
|
* Copyright (C) 2018-2022 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
|
|
|
|
2022-11-25 23:04:24 +08:00
|
|
|
#include "shared/source/command_stream/queue_throttle.h"
|
2022-11-22 21:53:59 +08:00
|
|
|
#include "shared/source/command_stream/task_count_helper.h"
|
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
|
|
|
|
2022-11-25 23:04:24 +08:00
|
|
|
#include <chrono>
|
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
|
|
|
|
2022-03-23 22:36:07 +08:00
|
|
|
WaitParams KmdNotifyHelper::obtainTimeoutParams(bool quickKmdSleepRequest,
|
2022-11-22 21:53:59 +08:00
|
|
|
TagAddressType currentHwTag,
|
|
|
|
TaskCountType taskCountToWait,
|
2022-03-23 22:36:07 +08:00
|
|
|
FlushStamp flushStampToWait,
|
|
|
|
QueueThrottle throttle,
|
|
|
|
bool kmdWaitModeActive,
|
|
|
|
bool directSubmissionEnabled) {
|
|
|
|
if (throttle == QueueThrottle::HIGH) {
|
|
|
|
return WaitParams{true};
|
|
|
|
}
|
|
|
|
|
2018-11-15 00:33:20 +08:00
|
|
|
if (flushStampToWait == 0) {
|
2022-03-23 22:36:07 +08:00
|
|
|
return WaitParams{};
|
2021-02-17 18:33:41 +08:00
|
|
|
}
|
|
|
|
|
2021-06-15 19:31:12 +08:00
|
|
|
if (!kmdWaitModeActive) {
|
2022-03-23 22:36:07 +08:00
|
|
|
return WaitParams{};
|
2018-11-15 00:33:20 +08:00
|
|
|
}
|
|
|
|
|
2022-03-23 22:36:07 +08:00
|
|
|
if (DebugManager.flags.PowerSavingMode.get() || throttle == QueueThrottle::LOW) {
|
|
|
|
return WaitParams{false, true, 1};
|
2018-11-15 00:33:20 +08:00
|
|
|
}
|
|
|
|
|
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();
|
2022-03-23 22:36:07 +08:00
|
|
|
WaitParams params;
|
2018-04-09 16:05:32 +08:00
|
|
|
|
2019-05-07 20:24:13 +08:00
|
|
|
if (!properties->enableKmdNotify && !acLineConnected) {
|
2022-03-23 22:36:07 +08:00
|
|
|
params.waitTimeout = KmdNotifyConstants::timeoutInMicrosecondsForDisconnectedAcLine;
|
2018-04-10 16:26:59 +08:00
|
|
|
} else if (quickKmdSleepRequest && properties->enableQuickKmdSleep) {
|
2022-03-23 22:36:07 +08:00
|
|
|
params.waitTimeout = properties->delayQuickKmdSleepMicroseconds;
|
2021-12-18 02:42:13 +08:00
|
|
|
} else if (directSubmissionEnabled && properties->enableQuickKmdSleepForDirectSubmission) {
|
2022-03-23 22:36:07 +08:00
|
|
|
params.waitTimeout = properties->delayQuickKmdSleepForDirectSubmissionMicroseconds;
|
2018-04-10 16:26:59 +08:00
|
|
|
} else {
|
2022-03-23 22:36:07 +08:00
|
|
|
params.waitTimeout = getBaseTimeout(multiplier);
|
2018-04-09 16:05:32 +08:00
|
|
|
}
|
|
|
|
|
2022-03-23 22:36:07 +08:00
|
|
|
params.enableTimeout = (properties->enableKmdNotify || !acLineConnected);
|
|
|
|
|
|
|
|
return params;
|
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);
|
|
|
|
}
|
|
|
|
}
|