2018-08-24 14:48:59 +08:00
|
|
|
/*
|
2022-02-04 21:59:01 +08:00
|
|
|
* Copyright (C) 2018-2022 Intel Corporation
|
2018-08-24 14:48:59 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2018-08-24 14:48:59 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/command_container/command_encoder.h"
|
2021-03-11 21:48:04 +08:00
|
|
|
#include "shared/source/command_stream/command_stream_receiver.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/command_stream/csr_deps.h"
|
|
|
|
#include "shared/source/helpers/aux_translation.h"
|
2020-03-09 20:48:30 +08:00
|
|
|
#include "shared/source/helpers/hw_helper.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/helpers/non_copyable_or_moveable.h"
|
2021-12-22 22:11:05 +08:00
|
|
|
#include "shared/source/helpers/pipe_control_args.h"
|
2021-03-22 23:14:49 +08:00
|
|
|
#include "shared/source/helpers/string.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/utilities/tag_allocator.h"
|
2018-10-03 05:37:30 +08:00
|
|
|
|
2019-02-27 18:39:32 +08:00
|
|
|
#include <cstdint>
|
2018-10-03 05:37:30 +08:00
|
|
|
#include <vector>
|
2018-08-24 14:48:59 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
namespace NEO {
|
2018-10-06 03:51:57 +08:00
|
|
|
class CommandStreamReceiver;
|
|
|
|
class LinearStream;
|
2018-10-03 05:37:30 +08:00
|
|
|
|
2018-11-21 21:05:01 +08:00
|
|
|
namespace TimestampPacketSizeControl {
|
2019-04-17 19:29:50 +08:00
|
|
|
constexpr uint32_t preferredPacketCount = 16u;
|
2018-11-21 21:05:01 +08:00
|
|
|
}
|
|
|
|
|
2018-09-26 06:44:43 +08:00
|
|
|
#pragma pack(1)
|
2020-09-15 15:33:12 +08:00
|
|
|
template <typename TSize>
|
2021-03-25 02:21:13 +08:00
|
|
|
class TimestampPackets : public TagTypeBase {
|
2021-03-27 00:12:19 +08:00
|
|
|
protected:
|
2019-04-17 19:29:50 +08:00
|
|
|
struct Packet {
|
2020-09-15 15:33:12 +08:00
|
|
|
TSize contextStart = 1u;
|
|
|
|
TSize globalStart = 1u;
|
|
|
|
TSize contextEnd = 1u;
|
|
|
|
TSize globalEnd = 1u;
|
2018-08-24 14:48:59 +08:00
|
|
|
};
|
|
|
|
|
2021-03-27 00:12:19 +08:00
|
|
|
public:
|
2022-02-04 21:59:01 +08:00
|
|
|
static constexpr AllocationType getAllocationType() {
|
|
|
|
return AllocationType::TIMESTAMP_PACKET_TAG_BUFFER;
|
2019-02-08 17:27:48 +08:00
|
|
|
}
|
|
|
|
|
2021-03-25 02:21:13 +08:00
|
|
|
static constexpr TagNodeType getTagNodeType() { return TagNodeType::TimestampPacket; }
|
|
|
|
|
2021-03-27 00:12:19 +08:00
|
|
|
static constexpr size_t getSinglePacketSize() { return sizeof(Packet); }
|
2021-03-25 02:21:13 +08:00
|
|
|
|
2018-09-26 06:44:43 +08:00
|
|
|
void initialize() {
|
2019-04-17 19:29:50 +08:00
|
|
|
for (auto &packet : packets) {
|
|
|
|
packet.contextStart = 1u;
|
|
|
|
packet.globalStart = 1u;
|
|
|
|
packet.contextEnd = 1u;
|
|
|
|
packet.globalEnd = 1u;
|
|
|
|
}
|
2018-09-26 06:44:43 +08:00
|
|
|
}
|
|
|
|
|
2021-03-22 23:14:49 +08:00
|
|
|
void assignDataToAllTimestamps(uint32_t packetIndex, void *source) {
|
|
|
|
memcpy_s(&packets[packetIndex], sizeof(Packet), source, sizeof(Packet));
|
|
|
|
}
|
|
|
|
|
2021-03-27 00:12:19 +08:00
|
|
|
static constexpr size_t getGlobalStartOffset() { return offsetof(Packet, globalStart); }
|
|
|
|
static constexpr size_t getContextStartOffset() { return offsetof(Packet, contextStart); }
|
|
|
|
static constexpr size_t getContextEndOffset() { return offsetof(Packet, contextEnd); }
|
|
|
|
static constexpr size_t getGlobalEndOffset() { return offsetof(Packet, globalEnd); }
|
2021-03-22 23:14:49 +08:00
|
|
|
|
|
|
|
uint64_t getContextStartValue(uint32_t packetIndex) const { return static_cast<uint64_t>(packets[packetIndex].contextStart); }
|
|
|
|
uint64_t getGlobalStartValue(uint32_t packetIndex) const { return static_cast<uint64_t>(packets[packetIndex].globalStart); }
|
|
|
|
uint64_t getContextEndValue(uint32_t packetIndex) const { return static_cast<uint64_t>(packets[packetIndex].contextEnd); }
|
|
|
|
uint64_t getGlobalEndValue(uint32_t packetIndex) const { return static_cast<uint64_t>(packets[packetIndex].globalEnd); }
|
|
|
|
|
2021-12-02 00:37:46 +08:00
|
|
|
void const *getContextEndAddress(uint32_t packetIndex) const { return static_cast<void const *>(&packets[packetIndex].contextEnd); }
|
2022-03-18 02:44:34 +08:00
|
|
|
void const *getContextStartAddress(uint32_t packetIndex) const { return static_cast<void const *>(&packets[packetIndex].contextStart); }
|
2021-12-02 00:37:46 +08:00
|
|
|
|
2021-03-22 23:14:49 +08:00
|
|
|
protected:
|
2019-04-17 19:29:50 +08:00
|
|
|
Packet packets[TimestampPacketSizeControl::preferredPacketCount];
|
2018-09-26 06:44:43 +08:00
|
|
|
};
|
|
|
|
#pragma pack()
|
|
|
|
|
2021-07-22 23:27:05 +08:00
|
|
|
static_assert(((4 * TimestampPacketSizeControl::preferredPacketCount) * sizeof(uint32_t)) == sizeof(TimestampPackets<uint32_t>),
|
2018-09-26 06:44:43 +08:00
|
|
|
"This structure is consumed by GPU and has to follow specific restrictions for padding and size");
|
|
|
|
|
2019-11-12 15:31:46 +08:00
|
|
|
class TimestampPacketContainer : public NonCopyableClass {
|
2019-01-25 17:20:32 +08:00
|
|
|
public:
|
|
|
|
TimestampPacketContainer() = default;
|
2019-11-12 15:31:46 +08:00
|
|
|
TimestampPacketContainer(TimestampPacketContainer &&) = default;
|
|
|
|
TimestampPacketContainer &operator=(TimestampPacketContainer &&) = default;
|
2019-01-25 17:20:32 +08:00
|
|
|
MOCKABLE_VIRTUAL ~TimestampPacketContainer();
|
|
|
|
|
2022-03-03 02:51:53 +08:00
|
|
|
const StackVec<TagNodeBase *, 32u> &peekNodes() const { return timestampPacketNodes; }
|
2021-03-25 02:21:13 +08:00
|
|
|
void add(TagNodeBase *timestampPacketNode);
|
2019-01-25 17:20:32 +08:00
|
|
|
void swapNodes(TimestampPacketContainer ×tampPacketContainer);
|
|
|
|
void assignAndIncrementNodesRefCounts(const TimestampPacketContainer &inputTimestampPacketContainer);
|
|
|
|
void makeResident(CommandStreamReceiver &commandStreamReceiver);
|
2021-06-23 19:04:10 +08:00
|
|
|
void moveNodesToNewContainer(TimestampPacketContainer ×tampPacketContainer);
|
2019-01-25 17:20:32 +08:00
|
|
|
|
|
|
|
protected:
|
2022-03-03 02:51:53 +08:00
|
|
|
StackVec<TagNodeBase *, 32u> timestampPacketNodes;
|
2019-01-25 17:20:32 +08:00
|
|
|
};
|
|
|
|
|
2019-11-13 19:23:29 +08:00
|
|
|
struct TimestampPacketDependencies : public NonCopyableClass {
|
2020-02-27 20:29:15 +08:00
|
|
|
TimestampPacketContainer cacheFlushNodes;
|
2019-11-13 19:23:29 +08:00
|
|
|
TimestampPacketContainer previousEnqueueNodes;
|
|
|
|
TimestampPacketContainer barrierNodes;
|
2019-11-10 02:02:25 +08:00
|
|
|
TimestampPacketContainer auxToNonAuxNodes;
|
|
|
|
TimestampPacketContainer nonAuxToAuxNodes;
|
2021-06-22 01:39:40 +08:00
|
|
|
|
|
|
|
void moveNodesToNewContainer(TimestampPacketContainer ×tampPacketContainer);
|
2019-11-13 19:23:29 +08:00
|
|
|
};
|
|
|
|
|
2018-11-14 22:29:10 +08:00
|
|
|
struct TimestampPacketHelper {
|
2021-03-25 02:21:13 +08:00
|
|
|
static uint64_t getContextEndGpuAddress(const TagNodeBase ×tampPacketNode) {
|
|
|
|
return timestampPacketNode.getGpuAddress() + timestampPacketNode.getContextEndOffset();
|
2021-03-22 23:14:49 +08:00
|
|
|
}
|
2021-03-25 02:21:13 +08:00
|
|
|
static uint64_t getContextStartGpuAddress(const TagNodeBase ×tampPacketNode) {
|
|
|
|
return timestampPacketNode.getGpuAddress() + timestampPacketNode.getContextStartOffset();
|
2021-03-22 23:14:49 +08:00
|
|
|
}
|
2021-03-25 02:21:13 +08:00
|
|
|
static uint64_t getGlobalEndGpuAddress(const TagNodeBase ×tampPacketNode) {
|
|
|
|
return timestampPacketNode.getGpuAddress() + timestampPacketNode.getGlobalEndOffset();
|
2021-03-22 23:14:49 +08:00
|
|
|
}
|
2021-03-25 02:21:13 +08:00
|
|
|
static uint64_t getGlobalStartGpuAddress(const TagNodeBase ×tampPacketNode) {
|
|
|
|
return timestampPacketNode.getGpuAddress() + timestampPacketNode.getGlobalStartOffset();
|
2020-05-19 22:20:41 +08:00
|
|
|
}
|
|
|
|
|
2018-09-26 06:44:43 +08:00
|
|
|
template <typename GfxFamily>
|
2021-06-23 18:34:31 +08:00
|
|
|
static void programSemaphore(LinearStream &cmdStream, TagNodeBase ×tampPacketNode) {
|
2020-01-09 00:42:14 +08:00
|
|
|
using COMPARE_OPERATION = typename GfxFamily::MI_SEMAPHORE_WAIT::COMPARE_OPERATION;
|
2020-01-24 21:58:15 +08:00
|
|
|
using MI_SEMAPHORE_WAIT = typename GfxFamily::MI_SEMAPHORE_WAIT;
|
|
|
|
|
2020-05-19 22:20:41 +08:00
|
|
|
auto compareAddress = getContextEndGpuAddress(timestampPacketNode);
|
2018-09-26 06:44:43 +08:00
|
|
|
|
2021-03-25 02:21:13 +08:00
|
|
|
for (uint32_t packetId = 0; packetId < timestampPacketNode.getPacketsUsed(); packetId++) {
|
|
|
|
uint64_t compareOffset = packetId * timestampPacketNode.getSinglePacketSize();
|
2020-10-01 17:59:59 +08:00
|
|
|
EncodeSempahore<GfxFamily>::addMiSemaphoreWaitCommand(cmdStream, compareAddress + compareOffset, 1, COMPARE_OPERATION::COMPARE_OPERATION_SAD_NOT_EQUAL_SDD);
|
2019-11-07 00:18:47 +08:00
|
|
|
}
|
2018-09-26 06:44:43 +08:00
|
|
|
}
|
2018-10-03 05:37:30 +08:00
|
|
|
|
2019-01-25 17:20:32 +08:00
|
|
|
template <typename GfxFamily>
|
2021-06-23 18:34:31 +08:00
|
|
|
static void programCsrDependenciesForTimestampPacketContainer(LinearStream &cmdStream, const CsrDependencies &csrDependencies) {
|
2021-03-11 21:48:04 +08:00
|
|
|
for (auto timestampPacketContainer : csrDependencies.timestampPacketContainer) {
|
2019-01-25 17:20:32 +08:00
|
|
|
for (auto &node : timestampPacketContainer->peekNodes()) {
|
2021-06-23 18:34:31 +08:00
|
|
|
TimestampPacketHelper::programSemaphore<GfxFamily>(cmdStream, *node);
|
2019-01-25 17:20:32 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-10-03 05:37:30 +08:00
|
|
|
|
2021-03-11 21:48:04 +08:00
|
|
|
template <typename GfxFamily>
|
|
|
|
static void programCsrDependenciesForForTaskCountContainer(LinearStream &cmdStream, const CsrDependencies &csrDependencies) {
|
2022-04-27 20:31:11 +08:00
|
|
|
auto &taskCountContainer = csrDependencies.taskCountContainer;
|
2021-03-11 21:48:04 +08:00
|
|
|
|
|
|
|
for (auto &[taskCountPreviousRootDevice, tagAddressPreviousRootDevice] : taskCountContainer) {
|
|
|
|
using COMPARE_OPERATION = typename GfxFamily::MI_SEMAPHORE_WAIT::COMPARE_OPERATION;
|
|
|
|
using MI_SEMAPHORE_WAIT = typename GfxFamily::MI_SEMAPHORE_WAIT;
|
|
|
|
|
|
|
|
EncodeSempahore<GfxFamily>::addMiSemaphoreWaitCommand(cmdStream,
|
|
|
|
static_cast<uint64_t>(tagAddressPreviousRootDevice),
|
|
|
|
taskCountPreviousRootDevice,
|
|
|
|
COMPARE_OPERATION::COMPARE_OPERATION_SAD_GREATER_THAN_OR_EQUAL_SDD);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-10 02:02:25 +08:00
|
|
|
template <typename GfxFamily, AuxTranslationDirection auxTranslationDirection>
|
2021-06-23 18:34:31 +08:00
|
|
|
static void programSemaphoreForAuxTranslation(LinearStream &cmdStream,
|
|
|
|
const TimestampPacketDependencies *timestampPacketDependencies,
|
|
|
|
const HardwareInfo &hwInfo) {
|
2019-11-10 02:02:25 +08:00
|
|
|
auto &container = (auxTranslationDirection == AuxTranslationDirection::AuxToNonAux)
|
|
|
|
? timestampPacketDependencies->auxToNonAuxNodes
|
|
|
|
: timestampPacketDependencies->nonAuxToAuxNodes;
|
|
|
|
|
2020-03-09 20:48:30 +08:00
|
|
|
// cache flush after NDR, before NonAuxToAux
|
|
|
|
if (auxTranslationDirection == AuxTranslationDirection::NonAuxToAux && timestampPacketDependencies->cacheFlushNodes.peekNodes().size() > 0) {
|
|
|
|
UNRECOVERABLE_IF(timestampPacketDependencies->cacheFlushNodes.peekNodes().size() != 1);
|
2020-05-19 22:20:41 +08:00
|
|
|
auto cacheFlushTimestampPacketGpuAddress = getContextEndGpuAddress(*timestampPacketDependencies->cacheFlushNodes.peekNodes()[0]);
|
2020-03-09 20:48:30 +08:00
|
|
|
|
2021-12-21 05:37:45 +08:00
|
|
|
PipeControlArgs args;
|
2021-12-22 22:25:58 +08:00
|
|
|
args.dcFlushEnable = MemorySynchronizationCommands<GfxFamily>::getDcFlushEnable(true, hwInfo);
|
2020-04-27 03:48:59 +08:00
|
|
|
MemorySynchronizationCommands<GfxFamily>::addPipeControlAndProgramPostSyncOperation(
|
2020-03-09 20:48:30 +08:00
|
|
|
cmdStream, GfxFamily::PIPE_CONTROL::POST_SYNC_OPERATION::POST_SYNC_OPERATION_WRITE_IMMEDIATE_DATA,
|
2020-04-27 03:48:59 +08:00
|
|
|
cacheFlushTimestampPacketGpuAddress, 0, hwInfo, args);
|
2020-03-09 20:48:30 +08:00
|
|
|
}
|
|
|
|
|
2019-11-10 02:02:25 +08:00
|
|
|
for (auto &node : container.peekNodes()) {
|
2021-06-23 18:34:31 +08:00
|
|
|
TimestampPacketHelper::programSemaphore<GfxFamily>(cmdStream, *node);
|
2019-11-10 02:02:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-09 20:48:30 +08:00
|
|
|
template <typename GfxFamily, AuxTranslationDirection auxTranslationDirection>
|
|
|
|
static size_t getRequiredCmdStreamSizeForAuxTranslationNodeDependency(size_t count, const HardwareInfo &hwInfo, bool cacheFlushForBcsRequired) {
|
|
|
|
size_t size = count * TimestampPacketHelper::getRequiredCmdStreamSizeForNodeDependencyWithBlitEnqueue<GfxFamily>();
|
|
|
|
|
|
|
|
if (auxTranslationDirection == AuxTranslationDirection::NonAuxToAux && cacheFlushForBcsRequired) {
|
|
|
|
size += MemorySynchronizationCommands<GfxFamily>::getSizeForPipeControlWithPostSyncOperation(hwInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
2019-11-10 02:02:25 +08:00
|
|
|
}
|
|
|
|
|
2019-06-24 16:45:49 +08:00
|
|
|
template <typename GfxFamily>
|
2019-11-07 00:18:47 +08:00
|
|
|
static size_t getRequiredCmdStreamSizeForNodeDependencyWithBlitEnqueue() {
|
2021-06-23 18:34:31 +08:00
|
|
|
return sizeof(typename GfxFamily::MI_SEMAPHORE_WAIT);
|
2019-06-24 16:45:49 +08:00
|
|
|
}
|
|
|
|
|
2019-11-07 00:18:47 +08:00
|
|
|
template <typename GfxFamily>
|
2021-03-25 02:21:13 +08:00
|
|
|
static size_t getRequiredCmdStreamSizeForNodeDependency(TagNodeBase ×tampPacketNode) {
|
2021-06-23 18:34:31 +08:00
|
|
|
return (timestampPacketNode.getPacketsUsed() * sizeof(typename GfxFamily::MI_SEMAPHORE_WAIT));
|
2019-11-07 00:18:47 +08:00
|
|
|
}
|
|
|
|
|
2019-01-25 17:20:32 +08:00
|
|
|
template <typename GfxFamily>
|
|
|
|
static size_t getRequiredCmdStreamSize(const CsrDependencies &csrDependencies) {
|
2019-11-07 00:18:47 +08:00
|
|
|
size_t totalCommandsSize = 0;
|
2021-03-11 21:48:04 +08:00
|
|
|
for (auto timestampPacketContainer : csrDependencies.timestampPacketContainer) {
|
2019-11-07 00:18:47 +08:00
|
|
|
for (auto &node : timestampPacketContainer->peekNodes()) {
|
|
|
|
totalCommandsSize += getRequiredCmdStreamSizeForNodeDependency<GfxFamily>(*node);
|
|
|
|
}
|
2019-01-25 17:20:32 +08:00
|
|
|
}
|
2018-10-03 05:37:30 +08:00
|
|
|
|
2019-11-07 00:18:47 +08:00
|
|
|
return totalCommandsSize;
|
2019-01-25 17:20:32 +08:00
|
|
|
}
|
2021-03-11 21:48:04 +08:00
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
static size_t getRequiredCmdStreamSizeForTaskCountContainer(const CsrDependencies &csrDependencies) {
|
|
|
|
return csrDependencies.taskCountContainer.size() * sizeof(typename GfxFamily::MI_SEMAPHORE_WAIT);
|
|
|
|
}
|
2018-10-03 05:37:30 +08:00
|
|
|
};
|
2019-11-10 02:02:25 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
} // namespace NEO
|