2021-07-30 09:56:58 +00:00
|
|
|
/*
|
2025-01-28 13:18:46 +00:00
|
|
|
* Copyright (C) 2019-2025 Intel Corporation
|
2021-07-30 09:56:58 +00:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2024-03-22 11:18:35 +00:00
|
|
|
#include "shared/source/command_stream/queue_throttle.h"
|
2022-11-22 13:53:59 +00:00
|
|
|
#include "shared/source/command_stream/task_count_helper.h"
|
2023-01-24 15:33:52 +00:00
|
|
|
#include "shared/source/helpers/device_bitfield.h"
|
2022-06-20 11:02:28 +00:00
|
|
|
|
|
|
|
|
#include <array>
|
2021-07-30 09:56:58 +00:00
|
|
|
#include <atomic>
|
2023-04-06 12:14:02 +00:00
|
|
|
#include <chrono>
|
2024-08-06 16:13:06 +00:00
|
|
|
#include <condition_variable>
|
2021-09-14 12:00:16 +00:00
|
|
|
#include <memory>
|
2021-07-30 09:56:58 +00:00
|
|
|
#include <mutex>
|
2025-07-17 12:44:46 +00:00
|
|
|
#include <optional>
|
2024-08-06 16:13:06 +00:00
|
|
|
#include <queue>
|
2021-07-30 09:56:58 +00:00
|
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
|
|
namespace NEO {
|
|
|
|
|
class MemoryManager;
|
|
|
|
|
class CommandStreamReceiver;
|
2021-09-14 12:00:16 +00:00
|
|
|
class Thread;
|
2024-03-22 11:18:35 +00:00
|
|
|
class ProductHelper;
|
2021-07-30 09:56:58 +00:00
|
|
|
|
2023-04-06 12:14:02 +00:00
|
|
|
using SteadyClock = std::chrono::steady_clock;
|
2024-10-30 14:02:28 +00:00
|
|
|
using HighResolutionClock = std::chrono::high_resolution_clock;
|
2023-04-06 12:14:02 +00:00
|
|
|
|
2024-08-06 16:13:06 +00:00
|
|
|
struct WaitForPagingFenceRequest {
|
|
|
|
|
CommandStreamReceiver *csr;
|
|
|
|
|
uint64_t pagingFenceValue;
|
|
|
|
|
};
|
|
|
|
|
|
2024-10-23 15:55:31 +00:00
|
|
|
enum class TimeoutElapsedMode {
|
|
|
|
|
notElapsed,
|
|
|
|
|
bcsOnly,
|
|
|
|
|
fullyElapsed
|
|
|
|
|
};
|
|
|
|
|
|
2025-09-12 08:21:40 +00:00
|
|
|
struct ContextGroupKey {
|
|
|
|
|
uint32_t rootDeviceIndex;
|
|
|
|
|
uint32_t contextGroupId;
|
|
|
|
|
|
|
|
|
|
bool operator==(const ContextGroupKey &other) const {
|
|
|
|
|
return rootDeviceIndex == other.rootDeviceIndex && contextGroupId == other.contextGroupId;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2021-07-30 09:56:58 +00:00
|
|
|
class DirectSubmissionController {
|
|
|
|
|
public:
|
2025-01-30 02:53:44 +01:00
|
|
|
static constexpr size_t defaultTimeout = 5'000;
|
2024-10-22 11:41:19 +00:00
|
|
|
static constexpr size_t timeToPollTagUpdateNS = 20'000;
|
2021-07-30 09:56:58 +00:00
|
|
|
DirectSubmissionController();
|
|
|
|
|
virtual ~DirectSubmissionController();
|
|
|
|
|
|
|
|
|
|
void registerDirectSubmission(CommandStreamReceiver *csr);
|
|
|
|
|
void unregisterDirectSubmission(CommandStreamReceiver *csr);
|
|
|
|
|
|
2024-03-26 18:08:25 +00:00
|
|
|
void startThread();
|
2021-10-29 11:54:52 +00:00
|
|
|
void startControlling();
|
2024-03-29 11:24:19 +00:00
|
|
|
void stopThread();
|
2021-10-29 11:54:52 +00:00
|
|
|
|
2021-10-25 15:33:38 +00:00
|
|
|
static bool isSupported();
|
|
|
|
|
|
2024-08-06 16:13:06 +00:00
|
|
|
void enqueueWaitForPagingFence(CommandStreamReceiver *csr, uint64_t pagingFenceValue);
|
2024-08-29 15:38:06 +00:00
|
|
|
void drainPagingFenceQueue();
|
2024-08-06 16:13:06 +00:00
|
|
|
|
2021-07-30 09:56:58 +00:00
|
|
|
protected:
|
|
|
|
|
struct DirectSubmissionState {
|
2025-06-05 13:28:04 +00:00
|
|
|
DirectSubmissionState(DirectSubmissionState &&other) noexcept {
|
2024-03-28 13:15:59 +00:00
|
|
|
isStopped = other.isStopped.load();
|
|
|
|
|
taskCount = other.taskCount.load();
|
|
|
|
|
}
|
2024-03-28 15:20:52 +00:00
|
|
|
DirectSubmissionState &operator=(const DirectSubmissionState &other) {
|
|
|
|
|
if (this == &other) {
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
this->isStopped = other.isStopped.load();
|
|
|
|
|
this->taskCount = other.taskCount.load();
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
2024-04-24 09:49:23 +00:00
|
|
|
|
2024-03-28 13:15:59 +00:00
|
|
|
DirectSubmissionState() = default;
|
2024-04-24 09:49:23 +00:00
|
|
|
~DirectSubmissionState() = default;
|
|
|
|
|
|
|
|
|
|
DirectSubmissionState(const DirectSubmissionState &other) = delete;
|
|
|
|
|
DirectSubmissionState &operator=(DirectSubmissionState &&other) = delete;
|
|
|
|
|
|
|
|
|
|
std::atomic_bool isStopped{true};
|
|
|
|
|
std::atomic<TaskCountType> taskCount{0};
|
2021-07-30 09:56:58 +00:00
|
|
|
};
|
|
|
|
|
|
2021-09-14 12:00:16 +00:00
|
|
|
static void *controlDirectSubmissionsState(void *self);
|
2025-10-06 20:04:43 +02:00
|
|
|
void checkNewSubmissions();
|
2024-10-22 11:41:19 +00:00
|
|
|
bool isDirectSubmissionIdle(CommandStreamReceiver *csr, std::unique_lock<std::recursive_mutex> &csrLock);
|
2025-07-17 12:44:46 +00:00
|
|
|
bool isCopyEngineOnDeviceIdle(uint32_t rootDeviceIndex, std::optional<TaskCountType> &bcsTaskCount);
|
2024-08-06 16:13:06 +00:00
|
|
|
MOCKABLE_VIRTUAL bool sleep(std::unique_lock<std::mutex> &lock);
|
2023-04-06 12:14:02 +00:00
|
|
|
MOCKABLE_VIRTUAL SteadyClock::time_point getCpuTimestamp();
|
2025-09-19 06:25:40 +02:00
|
|
|
MOCKABLE_VIRTUAL void overrideDirectSubmissionTimeouts(const ProductHelper &productHelper);
|
2025-01-30 02:53:44 +01:00
|
|
|
|
2023-04-06 12:14:02 +00:00
|
|
|
void recalculateTimeout();
|
2024-03-22 11:18:35 +00:00
|
|
|
void applyTimeoutForAcLineStatusAndThrottle(bool acLineConnected);
|
|
|
|
|
void updateLastSubmittedThrottle(QueueThrottle throttle);
|
|
|
|
|
size_t getTimeoutParamsMapKey(QueueThrottle throttle, bool acLineStatus);
|
2022-05-24 13:03:11 +00:00
|
|
|
|
2025-10-06 20:04:43 +02:00
|
|
|
void handlePagingFenceRequests(std::unique_lock<std::mutex> &lock, bool checkForNewSubmissions);
|
2024-10-23 15:55:31 +00:00
|
|
|
MOCKABLE_VIRTUAL TimeoutElapsedMode timeoutElapsed();
|
|
|
|
|
std::chrono::microseconds getSleepValue() const { return std::chrono::microseconds(this->timeout / this->bcsTimeoutDivisor); }
|
2024-08-06 16:13:06 +00:00
|
|
|
|
2022-06-20 11:02:28 +00:00
|
|
|
uint32_t maxCcsCount = 1u;
|
|
|
|
|
std::array<uint32_t, DeviceBitfield().size()> ccsCount = {};
|
2021-07-30 09:56:58 +00:00
|
|
|
std::unordered_map<CommandStreamReceiver *, DirectSubmissionState> directSubmissions;
|
|
|
|
|
std::mutex directSubmissionsMutex;
|
|
|
|
|
|
2021-09-14 12:00:16 +00:00
|
|
|
std::unique_ptr<Thread> directSubmissionControllingThread;
|
2021-07-30 09:56:58 +00:00
|
|
|
std::atomic_bool keepControlling = true;
|
2021-10-29 11:54:52 +00:00
|
|
|
std::atomic_bool runControlling = false;
|
2021-07-30 09:56:58 +00:00
|
|
|
|
2024-08-06 16:13:06 +00:00
|
|
|
SteadyClock::time_point timeSinceLastCheck{};
|
2023-04-06 12:14:02 +00:00
|
|
|
SteadyClock::time_point lastTerminateCpuTimestamp{};
|
2024-10-30 14:02:28 +00:00
|
|
|
HighResolutionClock::time_point lastHangCheckTime{};
|
2025-01-30 02:53:44 +01:00
|
|
|
std::chrono::microseconds maxTimeout{defaultTimeout};
|
|
|
|
|
std::chrono::microseconds timeout{defaultTimeout};
|
2024-10-23 15:55:31 +00:00
|
|
|
int32_t timeoutDivisor = 1;
|
|
|
|
|
int32_t bcsTimeoutDivisor = 1;
|
2024-03-22 11:18:35 +00:00
|
|
|
QueueThrottle lowestThrottleSubmitted = QueueThrottle::HIGH;
|
2024-10-22 11:41:19 +00:00
|
|
|
bool isCsrIdleDetectionEnabled = false;
|
2025-09-12 08:21:40 +00:00
|
|
|
bool isCsrsContextGroupIdleDetectionEnabled = false;
|
2024-08-06 16:13:06 +00:00
|
|
|
|
2025-09-23 16:18:44 +02:00
|
|
|
std::condition_variable condVar;
|
|
|
|
|
std::mutex condVarMutex;
|
2024-08-06 16:13:06 +00:00
|
|
|
|
|
|
|
|
std::queue<WaitForPagingFenceRequest> pagingFenceRequests;
|
2021-07-30 09:56:58 +00:00
|
|
|
};
|
|
|
|
|
} // namespace NEO
|