2023-10-23 23:35:40 +00:00
|
|
|
/*
|
2024-01-18 18:39:41 +00:00
|
|
|
* Copyright (C) 2023-2024 Intel Corporation
|
2023-10-23 23:35:40 +00:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2023-12-05 21:03:49 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "shared/source/os_interface/linux/sys_calls.h"
|
|
|
|
|
|
|
|
|
|
#include "level_zero/core/source/device/device.h"
|
|
|
|
|
#include "level_zero/core/source/device/device_imp.h"
|
2023-10-23 23:35:40 +00:00
|
|
|
#include "level_zero/tools/source/debug/debug_session.h"
|
|
|
|
|
#include "level_zero/tools/source/debug/debug_session_imp.h"
|
|
|
|
|
|
|
|
|
|
namespace L0 {
|
|
|
|
|
struct DebugSessionLinux : DebugSessionImp {
|
|
|
|
|
|
2023-12-05 21:03:49 +00:00
|
|
|
DebugSessionLinux(const zet_debug_config_t &config, Device *device, int fd) : DebugSessionImp(config, device), fd(fd){};
|
2023-10-23 23:35:40 +00:00
|
|
|
static ze_result_t translateDebuggerOpenErrno(int error);
|
2023-12-05 21:03:49 +00:00
|
|
|
bool closeFd();
|
2024-01-18 18:39:41 +00:00
|
|
|
void closeAsyncThread();
|
2023-12-05 21:03:49 +00:00
|
|
|
|
|
|
|
|
int fd = 0;
|
|
|
|
|
std::atomic<bool> internalThreadHasStarted{false};
|
|
|
|
|
static void *readInternalEventsThreadFunction(void *arg);
|
|
|
|
|
|
|
|
|
|
MOCKABLE_VIRTUAL void startInternalEventsThread() {
|
|
|
|
|
internalEventThread.thread = NEO::Thread::create(readInternalEventsThreadFunction, reinterpret_cast<void *>(this));
|
|
|
|
|
}
|
|
|
|
|
void closeInternalEventsThread() {
|
|
|
|
|
internalEventThread.close();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
virtual void readInternalEventsAsync() = 0;
|
|
|
|
|
MOCKABLE_VIRTUAL std::unique_ptr<uint64_t[]> getInternalEvent();
|
|
|
|
|
MOCKABLE_VIRTUAL float getThreadStartLimitTime() {
|
|
|
|
|
return 0.5;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ThreadHelper internalEventThread;
|
|
|
|
|
std::mutex internalEventThreadMutex;
|
|
|
|
|
std::condition_variable internalEventCondition;
|
|
|
|
|
std::queue<std::unique_ptr<uint64_t[]>> internalEventQueue;
|
|
|
|
|
constexpr static uint64_t invalidClientHandle = std::numeric_limits<uint64_t>::max();
|
|
|
|
|
constexpr static uint64_t invalidHandle = std::numeric_limits<uint64_t>::max();
|
|
|
|
|
uint64_t clientHandle = invalidClientHandle;
|
|
|
|
|
uint64_t clientHandleClosed = invalidClientHandle;
|
|
|
|
|
static constexpr size_t maxEventSize = 4096;
|
|
|
|
|
|
|
|
|
|
struct IoctlHandler {
|
|
|
|
|
virtual ~IoctlHandler() = default;
|
|
|
|
|
virtual int ioctl(int fd, unsigned long request, void *arg) {
|
|
|
|
|
return 0;
|
|
|
|
|
};
|
|
|
|
|
MOCKABLE_VIRTUAL int poll(pollfd *pollFd, unsigned long int numberOfFds, int timeout) {
|
|
|
|
|
return NEO::SysCalls::poll(pollFd, numberOfFds, timeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MOCKABLE_VIRTUAL int64_t pread(int fd, void *buf, size_t count, off_t offset) {
|
|
|
|
|
return NEO::SysCalls::pread(fd, buf, count, offset);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MOCKABLE_VIRTUAL int64_t pwrite(int fd, const void *buf, size_t count, off_t offset) {
|
|
|
|
|
return NEO::SysCalls::pwrite(fd, buf, count, offset);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MOCKABLE_VIRTUAL void *mmap(void *addr, size_t size, int prot, int flags, int fd, off_t off) {
|
|
|
|
|
return NEO::SysCalls::mmap(addr, size, prot, flags, fd, off);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MOCKABLE_VIRTUAL int munmap(void *addr, size_t size) {
|
|
|
|
|
return NEO::SysCalls::munmap(addr, size);
|
|
|
|
|
}
|
|
|
|
|
};
|
2024-02-06 10:47:36 +00:00
|
|
|
|
|
|
|
|
enum class ThreadControlCmd {
|
|
|
|
|
interrupt,
|
|
|
|
|
resume,
|
|
|
|
|
stopped,
|
|
|
|
|
interruptAll
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
virtual int threadControl(const std::vector<EuThread::ThreadId> &threads, uint32_t tile, ThreadControlCmd threadCmd, std::unique_ptr<uint8_t[]> &bitmask, size_t &bitmaskSize) = 0;
|
|
|
|
|
void checkStoppedThreadsAndGenerateEvents(const std::vector<EuThread::ThreadId> &threads, uint64_t memoryHandle, uint32_t deviceIndex) override;
|
|
|
|
|
MOCKABLE_VIRTUAL bool checkForceExceptionBit(uint64_t memoryHandle, EuThread::ThreadId threadId, uint32_t *cr0, const SIP::regset_desc *regDesc);
|
|
|
|
|
ze_result_t resumeImp(const std::vector<EuThread::ThreadId> &threads, uint32_t deviceIndex) override;
|
|
|
|
|
ze_result_t interruptImp(uint32_t deviceIndex) override;
|
2023-10-23 23:35:40 +00:00
|
|
|
};
|
|
|
|
|
} // namespace L0
|