mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-10 15:12:56 +08:00
Add ULT for OSMemoryLinux
- ensure OSMemoryLinux::reserveCpuAddressRange() calls mmap() with -1 as fd param Related-To: NEO-2877, NEO-3530 Change-Id: I2d5903291726b086af8b913f92b64e8c38c23462 Signed-off-by: Venevtsev, Igor <igor.venevtsev@intel.com>
This commit is contained in:
committed by
sys_ocldev
parent
f0d3b47886
commit
8169347aa9
@@ -8,7 +8,6 @@
|
||||
#include "runtime/memory_manager/gfx_partition.h"
|
||||
|
||||
#include "runtime/helpers/aligned_memory.h"
|
||||
#include "runtime/os_interface/os_memory.h"
|
||||
|
||||
namespace NEO {
|
||||
|
||||
@@ -23,9 +22,12 @@ const std::array<HeapIndex, 6> GfxPartition::heapNonSvmNames{{HeapIndex::HEAP_IN
|
||||
HeapIndex::HEAP_EXTERNAL,
|
||||
HeapIndex::HEAP_STANDARD,
|
||||
HeapIndex::HEAP_STANDARD64KB}};
|
||||
|
||||
GfxPartition::GfxPartition() : osMemory(OSMemory::create()) {}
|
||||
|
||||
GfxPartition::~GfxPartition() {
|
||||
if (reservedCpuAddressRange) {
|
||||
OSMemory::releaseCpuAddressRange(reservedCpuAddressRange, reservedCpuAddressRangeSize);
|
||||
osMemory->releaseCpuAddressRange(reservedCpuAddressRange, reservedCpuAddressRangeSize);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,7 +115,7 @@ void GfxPartition::init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToRe
|
||||
} else if (gpuAddressSpace == maxNBitValue<47>) {
|
||||
reservedCpuAddressRangeSize = cpuAddressRangeSizeToReserve;
|
||||
UNRECOVERABLE_IF(reservedCpuAddressRangeSize == 0);
|
||||
reservedCpuAddressRange = OSMemory::reserveCpuAddressRange(reservedCpuAddressRangeSize);
|
||||
reservedCpuAddressRange = osMemory->reserveCpuAddressRange(reservedCpuAddressRangeSize);
|
||||
UNRECOVERABLE_IF(reservedCpuAddressRange == nullptr);
|
||||
UNRECOVERABLE_IF(!isAligned<GfxPartition::heapGranularity>(reservedCpuAddressRange));
|
||||
gfxBase = reinterpret_cast<uint64_t>(reservedCpuAddressRange);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
#include "runtime/memory_manager/memory_constants.h"
|
||||
#include "runtime/os_interface/os_memory.h"
|
||||
#include "runtime/utilities/heap_allocator.h"
|
||||
|
||||
#include <array>
|
||||
@@ -30,7 +31,7 @@ constexpr auto internalHeapIndex = is32bit ? HeapIndex::HEAP_INTERNAL : HeapInde
|
||||
|
||||
class GfxPartition {
|
||||
public:
|
||||
GfxPartition() {}
|
||||
GfxPartition();
|
||||
MOCKABLE_VIRTUAL ~GfxPartition();
|
||||
|
||||
void init(uint64_t gpuAddressSpace, size_t cpuAddressRangeSizeToReserve);
|
||||
@@ -92,6 +93,7 @@ class GfxPartition {
|
||||
|
||||
void *reservedCpuAddressRange = nullptr;
|
||||
size_t reservedCpuAddressRangeSize = 0;
|
||||
std::unique_ptr<OSMemory> osMemory;
|
||||
};
|
||||
|
||||
} // namespace NEO
|
||||
|
||||
@@ -45,6 +45,7 @@ set(RUNTIME_SRCS_OS_INTERFACE_LINUX
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_library.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_library.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_memory_linux.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_memory_linux.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_metrics_library.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_thread_linux.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_thread_linux.h
|
||||
|
||||
@@ -5,19 +5,28 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "runtime/os_interface/os_memory.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
#include "runtime/os_interface/linux/os_memory_linux.h"
|
||||
|
||||
namespace NEO {
|
||||
|
||||
void *OSMemory::reserveCpuAddressRange(size_t sizeToReserve) {
|
||||
return mmap(0, sizeToReserve, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE | MAP_HUGETLB, -1, 0);
|
||||
std::unique_ptr<OSMemory> OSMemory::create() {
|
||||
return std::make_unique<OSMemoryLinux>();
|
||||
}
|
||||
|
||||
void OSMemory::releaseCpuAddressRange(void *reservedCpuAddressRange, size_t reservedSize) {
|
||||
munmap(reservedCpuAddressRange, reservedSize);
|
||||
void *OSMemoryLinux::reserveCpuAddressRange(size_t sizeToReserve) {
|
||||
return mmapWrapper(0, sizeToReserve, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE | MAP_HUGETLB, -1, 0);
|
||||
}
|
||||
|
||||
void OSMemoryLinux::releaseCpuAddressRange(void *reservedCpuAddressRange, size_t reservedSize) {
|
||||
munmapWrapper(reservedCpuAddressRange, reservedSize);
|
||||
}
|
||||
|
||||
void *OSMemoryLinux::mmapWrapper(void *addr, size_t size, int prot, int flags, int fd, off_t off) {
|
||||
return mmap(addr, size, prot, flags, fd, off);
|
||||
}
|
||||
|
||||
int OSMemoryLinux::munmapWrapper(void *addr, size_t size) {
|
||||
return munmap(addr, size);
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
|
||||
26
runtime/os_interface/linux/os_memory_linux.h
Normal file
26
runtime/os_interface/linux/os_memory_linux.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "runtime/os_interface/os_memory.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
namespace NEO {
|
||||
|
||||
class OSMemoryLinux : public OSMemory {
|
||||
public:
|
||||
OSMemoryLinux() = default;
|
||||
void *reserveCpuAddressRange(size_t sizeToReserve) override;
|
||||
void releaseCpuAddressRange(void *reservedCpuAddressRange, size_t reservedSize) override;
|
||||
|
||||
protected:
|
||||
MOCKABLE_VIRTUAL void *mmapWrapper(void *, size_t, int, int, int, off_t);
|
||||
MOCKABLE_VIRTUAL int munmapWrapper(void *, size_t);
|
||||
};
|
||||
|
||||
} // namespace NEO
|
||||
@@ -7,13 +7,17 @@
|
||||
|
||||
#pragma once
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
|
||||
namespace NEO {
|
||||
|
||||
struct OSMemory {
|
||||
public:
|
||||
static void *reserveCpuAddressRange(size_t sizeToReserve);
|
||||
static void releaseCpuAddressRange(void *reservedCpuAddressRange, size_t reservedSize);
|
||||
static std::unique_ptr<OSMemory> create();
|
||||
|
||||
virtual ~OSMemory() = default;
|
||||
virtual void *reserveCpuAddressRange(size_t sizeToReserve) = 0;
|
||||
virtual void releaseCpuAddressRange(void *reservedCpuAddressRange, size_t reservedSize) = 0;
|
||||
};
|
||||
|
||||
} // namespace NEO
|
||||
|
||||
@@ -36,6 +36,7 @@ set(RUNTIME_SRCS_OS_INTERFACE_WINDOWS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_library.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_library.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_memory_win.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_memory_win.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_metrics_library.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_socket.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/os_thread_win.cpp
|
||||
|
||||
@@ -5,18 +5,28 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include "runtime/os_interface/os_memory.h"
|
||||
|
||||
#include <windows.h>
|
||||
#include "runtime/os_interface/windows/os_memory_win.h"
|
||||
|
||||
namespace NEO {
|
||||
|
||||
void *OSMemory::reserveCpuAddressRange(size_t sizeToReserve) {
|
||||
return VirtualAlloc(0, sizeToReserve, MEM_RESERVE, PAGE_READWRITE);
|
||||
std::unique_ptr<OSMemory> OSMemory::create() {
|
||||
return std::make_unique<OSMemoryWindows>();
|
||||
}
|
||||
|
||||
void OSMemory::releaseCpuAddressRange(void *reservedCpuAddressRange, size_t /* reservedSize */) {
|
||||
VirtualFree(reservedCpuAddressRange, 0, MEM_RELEASE);
|
||||
void *OSMemoryWindows::reserveCpuAddressRange(size_t sizeToReserve) {
|
||||
return virtualAllocWrapper(0, sizeToReserve, MEM_RESERVE, PAGE_READWRITE);
|
||||
}
|
||||
|
||||
void OSMemoryWindows::releaseCpuAddressRange(void *reservedCpuAddressRange, size_t /* reservedSize */) {
|
||||
virtualFreeWrapper(reservedCpuAddressRange, 0, MEM_RELEASE);
|
||||
}
|
||||
|
||||
LPVOID OSMemoryWindows::virtualAllocWrapper(LPVOID lpAddress, SIZE_T dwSize, DWORD flAllocationType, DWORD flProtect) {
|
||||
return VirtualAlloc(lpAddress, dwSize, flAllocationType, flProtect);
|
||||
}
|
||||
|
||||
BOOL OSMemoryWindows::virtualFreeWrapper(LPVOID lpAddress, SIZE_T dwSize, DWORD dwFreeType) {
|
||||
return VirtualFree(lpAddress, dwSize, dwFreeType);
|
||||
}
|
||||
|
||||
} // namespace NEO
|
||||
|
||||
25
runtime/os_interface/windows/os_memory_win.h
Normal file
25
runtime/os_interface/windows/os_memory_win.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
*/
|
||||
|
||||
#include "runtime/os_interface/os_memory.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
namespace NEO {
|
||||
|
||||
class OSMemoryWindows : public OSMemory {
|
||||
public:
|
||||
OSMemoryWindows() = default;
|
||||
void *reserveCpuAddressRange(size_t sizeToReserve) override;
|
||||
void releaseCpuAddressRange(void *reservedCpuAddressRange, size_t reservedSize) override;
|
||||
|
||||
protected:
|
||||
MOCKABLE_VIRTUAL LPVOID virtualAllocWrapper(LPVOID, SIZE_T, DWORD, DWORD);
|
||||
MOCKABLE_VIRTUAL BOOL virtualFreeWrapper(LPVOID, SIZE_T, DWORD);
|
||||
};
|
||||
|
||||
}; // namespace NEO
|
||||
Reference in New Issue
Block a user