2020-03-06 18:09:57 +08:00
|
|
|
/*
|
2022-02-10 00:07:36 +08:00
|
|
|
* Copyright (C) 2020-2022 Intel Corporation
|
2020-03-06 18:09:57 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#include "shared/source/debugger/debugger.h"
|
2020-06-18 23:08:55 +08:00
|
|
|
#include "shared/source/helpers/non_copyable_or_moveable.h"
|
2020-07-22 16:17:18 +08:00
|
|
|
#include "shared/source/memory_manager/memory_manager.h"
|
2020-06-18 23:08:55 +08:00
|
|
|
|
2022-03-23 16:57:31 +08:00
|
|
|
#include <cstdint>
|
2020-06-18 23:08:55 +08:00
|
|
|
#include <memory>
|
2020-07-22 16:17:18 +08:00
|
|
|
#include <unordered_map>
|
2020-06-18 23:08:55 +08:00
|
|
|
|
|
|
|
namespace NEO {
|
|
|
|
class Device;
|
2020-06-29 22:30:34 +08:00
|
|
|
class GraphicsAllocation;
|
2020-07-27 23:37:51 +08:00
|
|
|
class LinearStream;
|
2020-11-19 22:11:37 +08:00
|
|
|
class OSInterface;
|
2020-03-06 18:09:57 +08:00
|
|
|
|
2020-07-22 16:17:18 +08:00
|
|
|
#pragma pack(1)
|
2020-06-29 22:30:34 +08:00
|
|
|
struct SbaTrackedAddresses {
|
2020-07-22 16:17:18 +08:00
|
|
|
char magic[8] = "sbaarea";
|
|
|
|
uint64_t Reserved1 = 0;
|
|
|
|
uint8_t Version = 0;
|
|
|
|
uint8_t Reserved2[7];
|
|
|
|
uint64_t GeneralStateBaseAddress = 0;
|
|
|
|
uint64_t SurfaceStateBaseAddress = 0;
|
|
|
|
uint64_t DynamicStateBaseAddress = 0;
|
|
|
|
uint64_t IndirectObjectBaseAddress = 0;
|
|
|
|
uint64_t InstructionBaseAddress = 0;
|
|
|
|
uint64_t BindlessSurfaceStateBaseAddress = 0;
|
|
|
|
uint64_t BindlessSamplerStateBaseAddress = 0;
|
2020-06-29 22:30:34 +08:00
|
|
|
};
|
2020-10-14 22:46:11 +08:00
|
|
|
|
|
|
|
struct DebugAreaHeader {
|
|
|
|
char magic[8] = "dbgarea";
|
2022-03-12 08:52:01 +08:00
|
|
|
uint64_t reserved1 = 0;
|
|
|
|
uint8_t version = 0;
|
|
|
|
uint8_t pgsize = 0;
|
|
|
|
uint8_t size = 0;
|
|
|
|
uint8_t reserved2 = 0;
|
|
|
|
uint16_t scratchBegin = 0;
|
|
|
|
uint16_t scratchEnd = 0;
|
|
|
|
union {
|
|
|
|
uint64_t isSharedBitfield = 0;
|
|
|
|
struct {
|
|
|
|
uint64_t isShared : 1;
|
|
|
|
uint64_t reserved3 : 63;
|
|
|
|
};
|
|
|
|
};
|
2020-10-14 22:46:11 +08:00
|
|
|
};
|
2022-03-12 08:52:01 +08:00
|
|
|
static_assert(sizeof(DebugAreaHeader) == 32u * sizeof(uint8_t));
|
|
|
|
|
2021-03-31 10:31:58 +08:00
|
|
|
struct alignas(4) DebuggerVersion {
|
|
|
|
uint8_t major;
|
|
|
|
uint8_t minor;
|
|
|
|
uint16_t patch;
|
|
|
|
};
|
|
|
|
struct alignas(8) StateSaveAreaHeader {
|
|
|
|
char magic[8] = "tssarea";
|
|
|
|
uint64_t reserved1;
|
|
|
|
struct DebuggerVersion version;
|
|
|
|
uint8_t size;
|
|
|
|
uint8_t reserved2[3];
|
|
|
|
};
|
2020-10-14 22:46:11 +08:00
|
|
|
|
2020-07-22 16:17:18 +08:00
|
|
|
#pragma pack()
|
2020-06-29 22:30:34 +08:00
|
|
|
|
2020-06-18 23:08:55 +08:00
|
|
|
class DebuggerL0 : public NEO::Debugger, NEO::NonCopyableOrMovableClass {
|
2020-03-06 18:09:57 +08:00
|
|
|
public:
|
2020-06-18 23:08:55 +08:00
|
|
|
static std::unique_ptr<Debugger> create(NEO::Device *device);
|
|
|
|
|
2020-06-29 22:30:34 +08:00
|
|
|
DebuggerL0(NEO::Device *device);
|
|
|
|
~DebuggerL0() override;
|
|
|
|
|
2020-07-22 16:17:18 +08:00
|
|
|
NEO::GraphicsAllocation *getSbaTrackingBuffer(uint32_t contextId) {
|
|
|
|
return perContextSbaAllocations[contextId];
|
|
|
|
}
|
|
|
|
|
2020-10-14 22:46:11 +08:00
|
|
|
NEO::GraphicsAllocation *getModuleDebugArea() {
|
|
|
|
return moduleDebugArea;
|
|
|
|
}
|
|
|
|
|
2020-07-22 16:17:18 +08:00
|
|
|
uint64_t getSbaTrackingGpuVa() {
|
|
|
|
return sbaTrackingGpuVa.address;
|
2020-06-18 23:08:55 +08:00
|
|
|
}
|
|
|
|
|
2022-04-20 22:12:20 +08:00
|
|
|
void captureStateBaseAddress(NEO::LinearStream &cmdStream, SbaAddresses sba) override;
|
2020-08-18 23:47:12 +08:00
|
|
|
void printTrackedAddresses(uint32_t contextId);
|
2020-10-17 06:52:18 +08:00
|
|
|
MOCKABLE_VIRTUAL void registerElf(NEO::DebugData *debugData, NEO::GraphicsAllocation *isaAllocation);
|
2022-07-22 00:18:44 +08:00
|
|
|
MOCKABLE_VIRTUAL void notifyCommandQueueCreated();
|
|
|
|
MOCKABLE_VIRTUAL void notifyCommandQueueDestroyed();
|
2022-04-08 00:50:41 +08:00
|
|
|
MOCKABLE_VIRTUAL void notifyModuleLoadAllocations(const StackVec<NEO::GraphicsAllocation *, 32> &allocs);
|
2022-07-05 21:40:15 +08:00
|
|
|
MOCKABLE_VIRTUAL void notifyModuleCreate(void *module, uint32_t moduleSize, uint64_t moduleLoadAddress);
|
|
|
|
MOCKABLE_VIRTUAL void registerAllocationType(GraphicsAllocation *allocation);
|
2022-05-28 07:37:00 +08:00
|
|
|
void initSbaTrackingMode();
|
2020-07-27 23:37:51 +08:00
|
|
|
|
2020-11-16 23:24:54 +08:00
|
|
|
virtual void programSbaTrackingCommands(NEO::LinearStream &cmdStream, const SbaAddresses &sba) = 0;
|
2022-03-23 16:57:31 +08:00
|
|
|
virtual size_t getSbaAddressLoadCommandsSize() = 0;
|
|
|
|
virtual void programSbaAddressLoad(NEO::LinearStream &cmdStream, uint64_t sbaGpuVa) = 0;
|
2020-07-27 23:37:51 +08:00
|
|
|
|
2022-02-10 00:07:36 +08:00
|
|
|
MOCKABLE_VIRTUAL bool attachZebinModuleToSegmentAllocations(const StackVec<NEO::GraphicsAllocation *, 32> &kernelAlloc, uint32_t &moduleHandle);
|
|
|
|
MOCKABLE_VIRTUAL bool removeZebinModule(uint32_t moduleHandle);
|
|
|
|
|
2022-03-23 16:57:31 +08:00
|
|
|
void setSingleAddressSpaceSbaTracking(bool value) {
|
|
|
|
singleAddressSpaceSbaTracking = value;
|
|
|
|
}
|
2022-05-28 07:37:00 +08:00
|
|
|
bool getSingleAddressSpaceSbaTracking() { return singleAddressSpaceSbaTracking; }
|
2022-03-23 16:57:31 +08:00
|
|
|
|
2020-06-18 23:08:55 +08:00
|
|
|
protected:
|
2020-08-24 15:27:30 +08:00
|
|
|
static bool isAnyTrackedAddressChanged(SbaAddresses sba) {
|
|
|
|
return sba.GeneralStateBaseAddress != 0 ||
|
|
|
|
sba.SurfaceStateBaseAddress != 0 ||
|
|
|
|
sba.BindlessSurfaceStateBaseAddress != 0;
|
|
|
|
}
|
2020-11-23 22:31:20 +08:00
|
|
|
static bool initDebuggingInOs(NEO::OSInterface *osInterface);
|
2020-08-24 15:27:30 +08:00
|
|
|
|
2020-11-19 22:11:37 +08:00
|
|
|
void initialize();
|
2020-09-14 19:28:47 +08:00
|
|
|
|
2020-06-18 23:08:55 +08:00
|
|
|
NEO::Device *device = nullptr;
|
2020-06-29 22:30:34 +08:00
|
|
|
NEO::GraphicsAllocation *sbaAllocation = nullptr;
|
2020-07-22 16:17:18 +08:00
|
|
|
std::unordered_map<uint32_t, NEO::GraphicsAllocation *> perContextSbaAllocations;
|
2022-03-23 16:57:31 +08:00
|
|
|
NEO::AddressRange sbaTrackingGpuVa{};
|
2020-10-14 22:46:11 +08:00
|
|
|
NEO::GraphicsAllocation *moduleDebugArea = nullptr;
|
2022-07-22 00:18:44 +08:00
|
|
|
std::atomic<uint32_t> commandQueueCount = 0u;
|
|
|
|
uint32_t uuidL0CommandQueueHandle = 0;
|
2022-03-23 16:57:31 +08:00
|
|
|
bool singleAddressSpaceSbaTracking = false;
|
2022-07-05 23:54:09 +08:00
|
|
|
std::mutex debuggerL0Mutex;
|
2020-03-06 18:09:57 +08:00
|
|
|
};
|
2020-07-27 23:37:51 +08:00
|
|
|
|
|
|
|
using DebugerL0CreateFn = DebuggerL0 *(*)(NEO::Device *device);
|
|
|
|
extern DebugerL0CreateFn debuggerL0Factory[];
|
|
|
|
|
|
|
|
template <typename GfxFamily>
|
|
|
|
class DebuggerL0Hw : public DebuggerL0 {
|
|
|
|
public:
|
|
|
|
static DebuggerL0 *allocate(NEO::Device *device);
|
|
|
|
|
2020-11-16 23:24:54 +08:00
|
|
|
size_t getSbaTrackingCommandsSize(size_t trackedAddressCount) override;
|
|
|
|
void programSbaTrackingCommands(NEO::LinearStream &cmdStream, const SbaAddresses &sba) override;
|
2022-03-23 16:57:31 +08:00
|
|
|
size_t getSbaAddressLoadCommandsSize() override;
|
|
|
|
void programSbaAddressLoad(NEO::LinearStream &cmdStream, uint64_t sbaGpuVa) override;
|
|
|
|
|
|
|
|
void programSbaTrackingCommandsSingleAddressSpace(NEO::LinearStream &cmdStream, const SbaAddresses &sba);
|
2020-07-27 23:37:51 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
DebuggerL0Hw(NEO::Device *device) : DebuggerL0(device){};
|
|
|
|
};
|
|
|
|
|
2022-02-28 21:21:16 +08:00
|
|
|
template <uint32_t coreFamily, typename GfxFamily>
|
2020-07-27 23:37:51 +08:00
|
|
|
struct DebuggerL0PopulateFactory {
|
|
|
|
DebuggerL0PopulateFactory() {
|
2022-02-28 21:21:16 +08:00
|
|
|
debuggerL0Factory[coreFamily] = DebuggerL0Hw<GfxFamily>::allocate;
|
2020-07-27 23:37:51 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-06-15 05:24:58 +08:00
|
|
|
} // namespace NEO
|