wsl/hsakmt: implement ipc signal
IPC Signal only support sys ram backend and CPU&GPU both accessible, IPC Memory only support vram backend and only GPU accessible. Reviewed-by: Flora Cui <flora.cui@amd.com> Signed-off-by: tiancyin <tianci.yin@amd.com>
Этот коммит содержится в:
1 родитель
29ed03ab0a
Коммит
f4390637fb
5 files changed
+202
-18
No files matched your search
@@ -45,6 +45,7 @@
|
||||
|
||||
#include <sys/mman.h>
|
||||
#include <sys/sysinfo.h>
|
||||
#include <sys/stat.h>
|
||||
#include <linux/mman.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
@@ -231,6 +232,52 @@ bool WDDMDevice::DecommitSystemHeapSpace(void* addr, int64_t size) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WDDMDevice::CommitSystemHeapSpaceIPC(void* addr, int64_t size, int &memfd, bool lock) {
|
||||
int fd = -1;
|
||||
|
||||
if (memfd == -1) {
|
||||
fd = memfd_create("rocr4wsl_gtt", MFD_CLOEXEC);
|
||||
if (fd < 0) {
|
||||
pr_err("memfd_create failed\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
ftruncate(fd, size);
|
||||
} else {
|
||||
fd = memfd;
|
||||
}
|
||||
|
||||
int32_t protFlags = PROT_READ | PROT_WRITE;
|
||||
int32_t mapFlags = MAP_SHARED | MAP_FIXED | MAP_NORESERVE |
|
||||
MAP_UNINITIALIZED | (lock ? MAP_LOCKED : 0);
|
||||
|
||||
void* paddr = mmap(addr, size, protFlags, mapFlags, fd, 0);
|
||||
if (paddr == MAP_FAILED) {
|
||||
pr_err("fail to commit %s addr = %p, paddr = %p\n", (lock ? "locked" : ""), addr, paddr);
|
||||
if (memfd == -1)
|
||||
close(fd);
|
||||
return false;
|
||||
}
|
||||
assert(addr == paddr);
|
||||
|
||||
memfd = fd;
|
||||
|
||||
if (madvise(addr, size, MADV_DONTFORK))
|
||||
pr_err("fail to set MADV_DONTFORK for addr = %p\n", addr);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WDDMDevice::DecommitSystemHeapSpaceIPC(void* addr, int64_t size, int &memfd) {
|
||||
if (munmap(addr, size) != 0) {
|
||||
pr_err("fail to unmap = %p \n", addr);
|
||||
return false;
|
||||
}
|
||||
close(memfd);
|
||||
memfd = -1;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WDDMDevice::ReserveSystemHeapSpace() {
|
||||
struct sysinfo info;
|
||||
int ret = sysinfo(&info);
|
||||
@@ -458,6 +505,43 @@ ErrorCode WDDMDevice::FreeGpuVirtualAddress(const thunk_proxy::AllocDomain domai
|
||||
return code;
|
||||
}
|
||||
|
||||
ErrorCode WDDMDevice::ReserveIPCSysMem(gpusize size,
|
||||
gpusize *out_gpu_virt_addr, gpusize alignment,
|
||||
int &memfd, bool lock) {
|
||||
gpusize gpu_addr = 0;
|
||||
ErrorCode code = ErrorCode::Success;
|
||||
|
||||
code = d3dthunk::ReserveGpuVirtualAddress(adapter_, size,
|
||||
system_heap_space_start_,
|
||||
system_heap_space_start_ + system_heap_space_size_,
|
||||
&gpu_addr);
|
||||
if (code != ErrorCode::Success)
|
||||
return code;
|
||||
|
||||
if (!CommitSystemHeapSpaceIPC((void*)gpu_addr, size, memfd, lock)) {
|
||||
d3dthunk::FreeGpuVirtualAddress(adapter_, gpu_addr, size);
|
||||
code = ErrorCode::SyscallFail;
|
||||
}
|
||||
|
||||
*out_gpu_virt_addr = (code == ErrorCode::Success) ? gpu_addr : 0;
|
||||
return code;
|
||||
}
|
||||
|
||||
ErrorCode WDDMDevice::FreeIPCSysMem(gpusize gpu_addr, gpusize size, int &memfd) {
|
||||
auto code = ErrorCode::Success;
|
||||
|
||||
DecommitSystemHeapSpaceIPC((void *)gpu_addr, size, memfd);
|
||||
|
||||
d3dthunk::FreeGpuVirtualAddressArgs free_args{};
|
||||
free_args.hAdapter = adapter_;
|
||||
free_args.BaseAddress = gpu_addr;
|
||||
free_args.Size = size;
|
||||
|
||||
code = d3dthunk::FreeGpuVirtualAddress(&free_args);
|
||||
|
||||
return code;
|
||||
}
|
||||
|
||||
ErrorCode WDDMDevice::HandleApertureAlloc(gpusize size, gpusize *out_gpu_virt_addr) {
|
||||
uint64_t align = DEFAULT_GPU_PAGE_SIZE;
|
||||
|
||||
|
||||
Reference in new issue
Block a user