mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-19 16:24:18 +08:00
refactor: share acknowledgeEvent code for I915 and XE
Also remove not needed resumeImp and interruptImp methods from level_zero/tools/source/debug/linux/xe/debug_session.h The correct implementation is in DebugSessionLinux and the overrides in DebugSessionLinuxXe are not needed Related-To: NEO-8407 Signed-off-by: Jitendra Sharma <jitendra.sharma@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
4d797890af
commit
f0bdd5765b
@@ -838,4 +838,84 @@ void DebugSessionLinux::readStateSaveAreaHeader() {
|
||||
}
|
||||
}
|
||||
|
||||
bool DebugSessionLinux::ackIsaEvents(uint32_t deviceIndex, uint64_t isaVa) {
|
||||
std::lock_guard<std::mutex> lock(asyncThreadMutex);
|
||||
|
||||
auto connection = getClientConnection(clientHandle).get();
|
||||
|
||||
auto gmmHelper = connectedDevice->getNEODevice()->getGmmHelper();
|
||||
auto isaVaStart = gmmHelper->decanonize(isaVa);
|
||||
auto isa = connection->isaMap[deviceIndex].find(isaVaStart);
|
||||
|
||||
if (isa != connection->isaMap[deviceIndex].end()) {
|
||||
|
||||
// zebin modules do not store ackEvents per ISA
|
||||
UNRECOVERABLE_IF(isa->second->ackEvents.size() > 0 && isa->second->perKernelModule == false);
|
||||
|
||||
for (auto &event : isa->second->ackEvents) {
|
||||
eventAckIoctl(event);
|
||||
}
|
||||
|
||||
isa->second->ackEvents.clear();
|
||||
isa->second->moduleLoadEventAck = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DebugSessionLinux::ackModuleEvents(uint32_t deviceIndex, uint64_t moduleHandle) {
|
||||
std::lock_guard<std::mutex> lock(asyncThreadMutex);
|
||||
|
||||
auto &module = getModule(moduleHandle);
|
||||
for (auto &event : module.ackEvents[deviceIndex]) {
|
||||
eventAckIoctl(event);
|
||||
}
|
||||
module.ackEvents[deviceIndex].clear();
|
||||
module.moduleLoadEventAcked[deviceIndex] = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
ze_result_t DebugSessionLinux::acknowledgeEvent(const zet_debug_event_t *event) {
|
||||
|
||||
const zet_debug_event_t apiEventToAck = *event;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(asyncThreadMutex);
|
||||
|
||||
for (size_t i = 0; i < eventsToAck.size(); i++) {
|
||||
if (apiEventCompare(apiEventToAck, eventsToAck[i].first)) {
|
||||
|
||||
auto moduleHandle = eventsToAck[i].second;
|
||||
auto iter = eventsToAck.begin() + i;
|
||||
eventsToAck.erase(iter);
|
||||
|
||||
lock.unlock();
|
||||
|
||||
for (uint32_t i = 0; i < NEO::EngineLimits::maxHandleCount; i++) {
|
||||
if (connectedDevice->getNEODevice()->getDeviceBitfield().test(i)) {
|
||||
ackModuleEvents(i, moduleHandle);
|
||||
}
|
||||
}
|
||||
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (apiEventToAck.type == ZET_DEBUG_EVENT_TYPE_MODULE_LOAD) {
|
||||
bool allIsaAcked = true;
|
||||
for (uint32_t i = 0; i < NEO::EngineLimits::maxHandleCount; i++) {
|
||||
if (connectedDevice->getNEODevice()->getDeviceBitfield().test(i)) {
|
||||
if (!ackIsaEvents(i, apiEventToAck.info.module.load)) {
|
||||
allIsaAcked = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (allIsaAcked) {
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
return ZE_RESULT_ERROR_UNINITIALIZED;
|
||||
}
|
||||
|
||||
} // namespace L0
|
||||
|
||||
@@ -43,6 +43,10 @@ struct DebugSessionLinux : DebugSessionImp {
|
||||
virtual int flushVmCache(int vmfd) { return 0; };
|
||||
ze_result_t readGpuMemory(uint64_t memoryHandle, char *output, size_t size, uint64_t gpuVa) override;
|
||||
ze_result_t writeGpuMemory(uint64_t memoryHandle, const char *input, size_t size, uint64_t gpuVa) override;
|
||||
ze_result_t acknowledgeEvent(const zet_debug_event_t *event) override;
|
||||
static bool apiEventCompare(const zet_debug_event_t &event1, const zet_debug_event_t &event2) {
|
||||
return memcmp(&event1, &event2, sizeof(zet_debug_event_t)) == 0;
|
||||
};
|
||||
|
||||
ThreadHelper internalEventThread;
|
||||
std::mutex internalEventThreadMutex;
|
||||
@@ -224,6 +228,10 @@ struct DebugSessionLinux : DebugSessionImp {
|
||||
virtual bool tryAccessIsa(NEO::DeviceBitfield deviceBitfield, const zet_debug_memory_space_desc_t *desc, size_t size, void *buffer, bool write, ze_result_t &status);
|
||||
ze_result_t getISAVMHandle(uint32_t deviceIndex, const zet_debug_memory_space_desc_t *desc, size_t size, uint64_t &vmHandle);
|
||||
bool getIsaInfoForAllInstances(NEO::DeviceBitfield deviceBitfield, const zet_debug_memory_space_desc_t *desc, size_t size, uint64_t vmHandles[], ze_result_t &status);
|
||||
virtual bool ackIsaEvents(uint32_t deviceIndex, uint64_t isaVa);
|
||||
virtual bool ackModuleEvents(uint32_t deviceIndex, uint64_t moduleUuidHandle);
|
||||
virtual int eventAckIoctl(EventToAck &event) = 0;
|
||||
virtual Module &getModule(uint64_t moduleHandle) = 0;
|
||||
|
||||
virtual std::vector<uint64_t> getAllMemoryHandles();
|
||||
|
||||
|
||||
@@ -1320,61 +1320,15 @@ void DebugSessionLinuxi915::printContextVms() {
|
||||
}
|
||||
}
|
||||
|
||||
bool DebugSessionLinuxi915::ackIsaEvents(uint32_t deviceIndex, uint64_t isaVa) {
|
||||
std::lock_guard<std::mutex> lock(asyncThreadMutex);
|
||||
int DebugSessionLinuxi915::eventAckIoctl(EventToAck &event) {
|
||||
prelim_drm_i915_debug_event_ack eventToAck = {};
|
||||
eventToAck.type = event.type;
|
||||
eventToAck.seqno = event.seqno;
|
||||
eventToAck.flags = 0;
|
||||
|
||||
auto connection = clientHandleToConnection[clientHandle].get();
|
||||
|
||||
auto gmmHelper = connectedDevice->getNEODevice()->getGmmHelper();
|
||||
auto isaVaStart = gmmHelper->decanonize(isaVa);
|
||||
auto isa = connection->isaMap[deviceIndex].find(isaVaStart);
|
||||
|
||||
if (isa != connection->isaMap[deviceIndex].end()) {
|
||||
|
||||
// zebin modules do not store ackEvents per ISA
|
||||
UNRECOVERABLE_IF(isa->second->ackEvents.size() > 0 && isa->second->perKernelModule == false);
|
||||
|
||||
for (auto &event : isa->second->ackEvents) {
|
||||
prelim_drm_i915_debug_event_ack eventToAck = {};
|
||||
eventToAck.type = event.type;
|
||||
eventToAck.seqno = event.seqno;
|
||||
eventToAck.flags = 0;
|
||||
|
||||
auto ret = ioctl(PRELIM_I915_DEBUG_IOCTL_ACK_EVENT, &eventToAck);
|
||||
PRINT_DEBUGGER_INFO_LOG("PRELIM_I915_DEBUG_IOCTL_ACK_EVENT seqno = %llu, ret = %d errno = %d\n", (uint64_t)event.seqno, ret, ret != 0 ? errno : 0);
|
||||
}
|
||||
|
||||
isa->second->ackEvents.clear();
|
||||
isa->second->moduleLoadEventAck = true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DebugSessionLinuxi915::ackModuleEvents(uint32_t deviceIndex, uint64_t moduleUuidHandle) {
|
||||
std::lock_guard<std::mutex> lock(asyncThreadMutex);
|
||||
|
||||
auto connection = clientHandleToConnection[clientHandle].get();
|
||||
|
||||
if (connection->uuidToModule.find(moduleUuidHandle) != connection->uuidToModule.end()) {
|
||||
auto &module = connection->uuidToModule[moduleUuidHandle];
|
||||
for (auto &event : module.ackEvents[deviceIndex]) {
|
||||
|
||||
prelim_drm_i915_debug_event_ack eventToAck = {};
|
||||
eventToAck.type = event.type;
|
||||
eventToAck.seqno = event.seqno;
|
||||
eventToAck.flags = 0;
|
||||
|
||||
auto ret = ioctl(PRELIM_I915_DEBUG_IOCTL_ACK_EVENT, &eventToAck);
|
||||
PRINT_DEBUGGER_INFO_LOG("PRELIM_I915_DEBUG_IOCTL_ACK_EVENT seqno = %llu, ret = %d errno = %d\n", (uint64_t)event.seqno, ret, ret != 0 ? errno : 0);
|
||||
}
|
||||
module.ackEvents[deviceIndex].clear();
|
||||
module.moduleLoadEventAcked[deviceIndex] = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
DEBUG_BREAK_IF(true);
|
||||
return false;
|
||||
auto ret = ioctl(PRELIM_I915_DEBUG_IOCTL_ACK_EVENT, &eventToAck);
|
||||
PRINT_DEBUGGER_INFO_LOG("PRELIM_I915_DEBUG_IOCTL_ACK_EVENT seqno = %llu, ret = %d errno = %d\n", (uint64_t)event.seqno, ret, ret != 0 ? errno : 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void DebugSessionLinuxi915::cleanRootSessionAfterDetach(uint32_t deviceIndex) {
|
||||
@@ -1400,49 +1354,6 @@ void DebugSessionLinuxi915::cleanRootSessionAfterDetach(uint32_t deviceIndex) {
|
||||
}
|
||||
}
|
||||
|
||||
ze_result_t DebugSessionLinuxi915::acknowledgeEvent(const zet_debug_event_t *event) {
|
||||
|
||||
const zet_debug_event_t apiEventToAck = *event;
|
||||
{
|
||||
std::unique_lock<std::mutex> lock(asyncThreadMutex);
|
||||
|
||||
for (size_t i = 0; i < eventsToAck.size(); i++) {
|
||||
if (apiEventCompare(apiEventToAck, eventsToAck[i].first)) {
|
||||
|
||||
auto moduleUUID = eventsToAck[i].second;
|
||||
auto iter = eventsToAck.begin() + i;
|
||||
eventsToAck.erase(iter);
|
||||
|
||||
lock.unlock();
|
||||
|
||||
for (uint32_t i = 0; i < NEO::EngineLimits::maxHandleCount; i++) {
|
||||
if (connectedDevice->getNEODevice()->getDeviceBitfield().test(i)) {
|
||||
ackModuleEvents(i, moduleUUID);
|
||||
}
|
||||
}
|
||||
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (apiEventToAck.type == ZET_DEBUG_EVENT_TYPE_MODULE_LOAD) {
|
||||
bool allIsaAcked = true;
|
||||
for (uint32_t i = 0; i < NEO::EngineLimits::maxHandleCount; i++) {
|
||||
if (connectedDevice->getNEODevice()->getDeviceBitfield().test(i)) {
|
||||
if (!ackIsaEvents(i, apiEventToAck.info.module.load)) {
|
||||
allIsaAcked = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (allIsaAcked) {
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
return ZE_RESULT_ERROR_UNINITIALIZED;
|
||||
}
|
||||
|
||||
void TileDebugSessionLinuxi915::readStateSaveAreaHeader() {
|
||||
|
||||
const auto header = rootDebugSession->getStateSaveAreaHeader();
|
||||
|
||||
@@ -42,7 +42,6 @@ struct DebugSessionLinuxi915 : DebugSessionLinux {
|
||||
ze_result_t initialize() override;
|
||||
|
||||
bool closeConnection() override;
|
||||
ze_result_t acknowledgeEvent(const zet_debug_event_t *event) override;
|
||||
|
||||
struct IoctlHandleri915 : DebugSessionLinux::IoctlHandler {
|
||||
int ioctl(int fd, unsigned long request, void *arg) override {
|
||||
@@ -84,10 +83,6 @@ struct DebugSessionLinuxi915 : DebugSessionLinux {
|
||||
uint64_t ptr = 0;
|
||||
};
|
||||
|
||||
static bool apiEventCompare(const zet_debug_event_t &event1, const zet_debug_event_t &event2) {
|
||||
return memcmp(&event1, &event2, sizeof(zet_debug_event_t)) == 0;
|
||||
};
|
||||
|
||||
struct ClientConnectioni915 : public ClientConnection {
|
||||
prelim_drm_i915_debug_event_client client = {};
|
||||
|
||||
@@ -129,8 +124,12 @@ struct DebugSessionLinuxi915 : DebugSessionLinux {
|
||||
void handleAttentionEvent(prelim_drm_i915_debug_event_eu_attention *attention);
|
||||
void handleEnginesEvent(prelim_drm_i915_debug_event_engines *engines);
|
||||
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);
|
||||
int eventAckIoctl(EventToAck &event) override;
|
||||
Module &getModule(uint64_t moduleHandle) override {
|
||||
auto connection = clientHandleToConnection[clientHandle].get();
|
||||
DEBUG_BREAK_IF(connection->uuidToModule.find(moduleHandle) == connection->uuidToModule.end());
|
||||
return connection->uuidToModule[moduleHandle];
|
||||
}
|
||||
|
||||
MOCKABLE_VIRTUAL void processPendingVmBindEvents();
|
||||
|
||||
|
||||
@@ -479,12 +479,8 @@ void DebugSessionLinuxXe::handleVmBind(VmBindData &vmBindData) {
|
||||
}
|
||||
|
||||
if (shouldAckEvent && (vmBindData.vmBindUfence.base.flags & DRM_XE_EUDEBUG_EVENT_NEED_ACK)) {
|
||||
drm_xe_eudebug_ack_event eventToAck = {};
|
||||
eventToAck.type = vmBindData.vmBindUfence.base.type;
|
||||
eventToAck.seqno = vmBindData.vmBindUfence.base.seqno;
|
||||
eventToAck.flags = 0;
|
||||
auto ret = ioctl(DRM_XE_EUDEBUG_IOCTL_ACK_EVENT, &eventToAck);
|
||||
PRINT_DEBUGGER_INFO_LOG("DRM_XE_EUDEBUG_IOCTL_ACK_EVENT seqno = %llu ret = %d errno = %d\n", static_cast<uint64_t>(eventToAck.seqno), ret, ret != 0 ? errno : 0);
|
||||
EventToAck ackEvent(vmBindData.vmBindUfence.base.seqno, vmBindData.vmBindUfence.base.type);
|
||||
eventAckIoctl(ackEvent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -713,4 +709,14 @@ void DebugSessionLinuxXe::updateContextAndLrcHandlesForThreadsWithAttention(EuTh
|
||||
allThreads[threadId]->setLrcHandle(attention.lrcHandle);
|
||||
}
|
||||
|
||||
int DebugSessionLinuxXe::eventAckIoctl(EventToAck &event) {
|
||||
drm_xe_eudebug_ack_event eventToAck = {};
|
||||
eventToAck.type = event.type;
|
||||
eventToAck.seqno = event.seqno;
|
||||
eventToAck.flags = 0;
|
||||
auto ret = ioctl(DRM_XE_EUDEBUG_IOCTL_ACK_EVENT, &eventToAck);
|
||||
PRINT_DEBUGGER_INFO_LOG("DRM_XE_EUDEBUG_IOCTL_ACK_EVENT seqno = %llu ret = %d errno = %d\n", static_cast<uint64_t>(eventToAck.seqno), ret, ret != 0 ? errno : 0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
} // namespace L0
|
||||
@@ -29,11 +29,6 @@ struct DebugSessionLinuxXe : DebugSessionLinux {
|
||||
|
||||
bool closeConnection() override;
|
||||
|
||||
ze_result_t acknowledgeEvent(const zet_debug_event_t *event) override {
|
||||
UNRECOVERABLE_IF(true);
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
struct IoctlHandlerXe : DebugSessionLinux::IoctlHandler {
|
||||
int ioctl(int fd, unsigned long request, void *arg) override {
|
||||
int ret = 0;
|
||||
@@ -79,6 +74,12 @@ struct DebugSessionLinuxXe : DebugSessionLinux {
|
||||
void handleMetadataEvent(drm_xe_eudebug_event_metadata *pMetaData);
|
||||
bool handleMetadataOpEvent(drm_xe_eudebug_event_vm_bind_op_metadata *vmBindOpMetadata);
|
||||
void updateContextAndLrcHandlesForThreadsWithAttention(EuThread::ThreadId threadId, AttentionEventFields &attention) override;
|
||||
int eventAckIoctl(EventToAck &event) override;
|
||||
Module &getModule(uint64_t moduleHandle) override {
|
||||
auto connection = clientHandleToConnection[clientHandle].get();
|
||||
DEBUG_BREAK_IF(connection->metaDataToModule.find(moduleHandle) == connection->metaDataToModule.end());
|
||||
return connection->metaDataToModule[moduleHandle];
|
||||
}
|
||||
|
||||
void startAsyncThread() override;
|
||||
static void *asyncThreadFunction(void *arg);
|
||||
@@ -88,16 +89,6 @@ struct DebugSessionLinuxXe : DebugSessionLinux {
|
||||
UNRECOVERABLE_IF(true);
|
||||
}
|
||||
|
||||
ze_result_t resumeImp(const std::vector<EuThread::ThreadId> &threads, uint32_t deviceIndex) override {
|
||||
UNRECOVERABLE_IF(true);
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
ze_result_t interruptImp(uint32_t deviceIndex) override {
|
||||
UNRECOVERABLE_IF(true);
|
||||
return ZE_RESULT_SUCCESS;
|
||||
}
|
||||
|
||||
int openVmFd(uint64_t vmHandle, bool readOnly) override;
|
||||
int flushVmCache(int vmfd) override;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user