refactor: make Debugger ClientConnection common for xe/i915

- Add base ClientConnection type and derived i915/xe types
- Add accessor function fo retreive ClientConnection
- Move getElfOffset to common linux code
- Add accessor functions for getElfSize and getElfData

Related-to: NEO-9669

Signed-off-by: Brandon Yates <brandon.yates@intel.com>
This commit is contained in:
Brandon Yates
2024-02-13 21:49:56 +00:00
committed by Compute-Runtime-Automation
parent a05cc69a5a
commit 0fb6f4bf3f
10 changed files with 107 additions and 80 deletions

View File

@@ -307,7 +307,7 @@ void DebugSessionLinuxi915::handleEvent(prelim_drm_i915_debug_event *event) {
if (event->flags & PRELIM_DRM_I915_DEBUG_EVENT_CREATE) {
DEBUG_BREAK_IF(clientHandleToConnection.find(clientEvent->handle) != clientHandleToConnection.end());
clientHandleToConnection[clientEvent->handle].reset(new ClientConnection);
clientHandleToConnection[clientEvent->handle].reset(new ClientConnectioni915);
clientHandleToConnection[clientEvent->handle]->client = *clientEvent;
}
@@ -1445,35 +1445,6 @@ void DebugSessionLinuxi915::printContextVms() {
}
}
ze_result_t DebugSessionLinuxi915::getElfOffset(const zet_debug_memory_space_desc_t *desc, size_t size, const char *&elfData, uint64_t &offset) {
auto &elfMap = clientHandleToConnection[clientHandle]->elfMap;
auto accessVA = desc->address;
ze_result_t status = ZE_RESULT_ERROR_UNINITIALIZED;
elfData = nullptr;
if (elfMap.size() > 0) {
uint64_t baseVa;
uint64_t ceilVa;
for (auto &elf : elfMap) {
baseVa = elf.first;
ceilVa = elf.first + clientHandleToConnection[clientHandle]->uuidMap[elf.second].dataSize;
if (accessVA >= baseVa && accessVA < ceilVa) {
if (accessVA + size > ceilVa) {
status = ZE_RESULT_ERROR_INVALID_ARGUMENT;
} else {
DEBUG_BREAK_IF(clientHandleToConnection[clientHandle]->uuidMap[elf.second].data.get() == nullptr);
elfData = clientHandleToConnection[clientHandle]->uuidMap[elf.second].data.get();
offset = accessVA - baseVa;
status = ZE_RESULT_SUCCESS;
}
break;
}
}
}
return status;
}
bool DebugSessionLinuxi915::ackIsaEvents(uint32_t deviceIndex, uint64_t isaVa) {
std::lock_guard<std::mutex> lock(asyncThreadMutex);

View File

@@ -83,12 +83,6 @@ struct DebugSessionLinuxi915 : DebugSessionLinux {
uint64_t ptr = 0;
};
struct BindInfo {
uint64_t gpuVa = 0;
uint64_t size = 0;
};
struct IsaAllocation {
BindInfo bindInfo;
uint64_t elfUuidHandle;
@@ -122,36 +116,31 @@ struct DebugSessionLinuxi915 : DebugSessionLinux {
return memcmp(&event1, &event2, sizeof(zet_debug_event_t)) == 0;
};
struct ClientConnection {
struct ClientConnectioni915 : public ClientConnection {
prelim_drm_i915_debug_event_client client = {};
size_t getElfSize(uint64_t elfHandle) override { return uuidMap[elfHandle].dataSize; };
char *getElfData(uint64_t elfHandle) override { return uuidMap[elfHandle].data.get(); };
std::unordered_map<ContextHandle, ContextParams> contextsCreated;
std::unordered_map<uint64_t, std::pair<std::string, uint32_t>> classHandleToIndex;
std::unordered_map<uint64_t, UuidData> uuidMap;
std::unordered_set<uint64_t> vmIds;
std::unordered_map<uint64_t, BindInfo> vmToModuleDebugAreaBindInfo;
std::unordered_map<uint64_t, BindInfo> vmToContextStateSaveAreaBindInfo;
std::unordered_map<uint64_t, BindInfo> vmToStateBaseAreaBindInfo;
std::unordered_map<uint64_t, uint32_t> vmToTile;
std::unordered_map<uint64_t, std::unique_ptr<IsaAllocation>> isaMap[NEO::EngineLimits::maxHandleCount];
std::unordered_map<uint64_t, uint64_t> elfMap;
std::unordered_map<uint64_t, ContextHandle> lrcToContextHandle;
uint64_t moduleDebugAreaGpuVa = 0;
uint64_t contextStateSaveAreaGpuVa = 0;
uint64_t stateBaseAreaGpuVa = 0;
size_t contextStateSaveAreaSize = 0;
std::unordered_map<uint64_t, Module> uuidToModule;
};
std::shared_ptr<ClientConnection> getClientConnection(uint64_t clientHandle) override {
return clientHandleToConnection[clientHandle];
};
protected:
MOCKABLE_VIRTUAL void handleEvent(prelim_drm_i915_debug_event *event);
bool checkAllEventsCollected();
std::unordered_map<uint64_t, std::unique_ptr<ClientConnection>> clientHandleToConnection;
std::unordered_map<uint64_t, std::shared_ptr<ClientConnectioni915>> clientHandleToConnection;
ze_result_t readEventImp(prelim_drm_i915_debug_event *drmDebugEvent);
void enqueueApiEvent(zet_debug_event_t &debugEvent) override {
@@ -181,16 +170,6 @@ struct DebugSessionLinuxi915 : DebugSessionLinux {
static void *asyncThreadFunction(void *arg);
void startAsyncThread() override;
std::vector<uint64_t> getAllMemoryHandles() override {
std::vector<uint64_t> allVms;
std::unique_lock<std::mutex> memLock(asyncThreadMutex);
auto &vmIds = clientHandleToConnection[clientHandle]->vmIds;
allVms.resize(vmIds.size());
std::copy(vmIds.begin(), vmIds.end(), allVms.begin());
return allVms;
}
void handleEventsAsync();
uint64_t getVmHandleFromClientAndlrcHandle(uint64_t clientHandle, uint64_t lrcHandle);
@@ -201,7 +180,6 @@ struct DebugSessionLinuxi915 : DebugSessionLinux {
void handlePageFaultEvent(prelim_drm_i915_debug_event_page_fault *pf);
virtual bool ackIsaEvents(uint32_t deviceIndex, uint64_t isaVa);
virtual bool ackModuleEvents(uint32_t deviceIndex, uint64_t moduleUuidHandle);
ze_result_t getElfOffset(const zet_debug_memory_space_desc_t *desc, size_t size, const char *&elfData, uint64_t &offset) override;
MOCKABLE_VIRTUAL void processPendingVmBindEvents();