2019-07-04 18:17:42 +08:00
|
|
|
/*
|
2023-07-12 17:18:03 +08:00
|
|
|
* Copyright (C) 2019-2023 Intel Corporation
|
2019-07-04 18:17:42 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2023-07-25 17:01:53 +08:00
|
|
|
#include "shared/source/command_stream/command_stream_receiver.h"
|
|
|
|
#include "shared/source/helpers/engine_node_helper.h"
|
|
|
|
#include "shared/source/os_interface/os_context.h"
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/page_fault_manager/cpu_page_fault_manager.h"
|
2019-07-04 18:17:42 +08:00
|
|
|
|
|
|
|
using namespace NEO;
|
|
|
|
|
|
|
|
class MockPageFaultManager : public PageFaultManager {
|
|
|
|
public:
|
2021-03-08 19:39:07 +08:00
|
|
|
using PageFaultManager::gpuDomainHandler;
|
2019-07-04 18:17:42 +08:00
|
|
|
using PageFaultManager::memoryData;
|
|
|
|
using PageFaultManager::PageFaultData;
|
|
|
|
using PageFaultManager::PageFaultManager;
|
2021-03-08 19:39:07 +08:00
|
|
|
using PageFaultManager::selectGpuDomainHandler;
|
2022-11-17 17:03:18 +08:00
|
|
|
using PageFaultManager::transferAndUnprotectMemory;
|
|
|
|
using PageFaultManager::unprotectAndTransferMemory;
|
2019-07-04 18:17:42 +08:00
|
|
|
using PageFaultManager::verifyPageFault;
|
|
|
|
|
2023-08-04 09:48:26 +08:00
|
|
|
bool checkFaultHandlerFromPageFaultManager() override {
|
|
|
|
checkFaultHandlerCalled++;
|
|
|
|
return (registerFaultHandlerCalled != 0);
|
|
|
|
}
|
|
|
|
void registerFaultHandler() override {
|
|
|
|
registerFaultHandlerCalled++;
|
|
|
|
}
|
2019-07-04 18:17:42 +08:00
|
|
|
void allowCPUMemoryAccess(void *ptr, size_t size) override {
|
|
|
|
allowMemoryAccessCalled++;
|
|
|
|
allowedMemoryAccessAddress = ptr;
|
|
|
|
accessAllowedSize = size;
|
|
|
|
}
|
|
|
|
void protectCPUMemoryAccess(void *ptr, size_t size) override {
|
|
|
|
protectMemoryCalled++;
|
|
|
|
protectedMemoryAccessAddress = ptr;
|
|
|
|
protectedSize = size;
|
|
|
|
}
|
|
|
|
void transferToCpu(void *ptr, size_t size, void *cmdQ) override {
|
|
|
|
transferToCpuCalled++;
|
|
|
|
transferToCpuAddress = ptr;
|
|
|
|
transferToCpuSize = size;
|
|
|
|
}
|
|
|
|
void transferToGpu(void *ptr, void *cmdQ) override {
|
|
|
|
transferToGpuCalled++;
|
|
|
|
transferToGpuAddress = ptr;
|
|
|
|
}
|
2019-11-13 21:19:55 +08:00
|
|
|
void setAubWritable(bool writable, void *ptr, SVMAllocsManager *unifiedMemoryManager) override {
|
|
|
|
isAubWritable = writable;
|
|
|
|
}
|
2023-07-12 17:18:03 +08:00
|
|
|
void setCpuAllocEvictable(bool evictable, void *ptr, SVMAllocsManager *unifiedMemoryManager) override {
|
|
|
|
setCpuAllocEvictableCalled++;
|
|
|
|
isCpuAllocEvictable = evictable;
|
|
|
|
}
|
2023-07-25 17:01:53 +08:00
|
|
|
void allowCPUMemoryEviction(void *ptr, PageFaultData &pageFaultData) override {
|
|
|
|
allowCPUMemoryEvictionCalled++;
|
|
|
|
}
|
2019-11-13 21:19:55 +08:00
|
|
|
void baseAubWritable(bool writable, void *ptr, SVMAllocsManager *unifiedMemoryManager) {
|
|
|
|
PageFaultManager::setAubWritable(writable, ptr, unifiedMemoryManager);
|
|
|
|
}
|
2019-07-04 18:17:42 +08:00
|
|
|
void baseCpuTransfer(void *ptr, size_t size, void *cmdQ) {
|
|
|
|
PageFaultManager::transferToCpu(ptr, size, cmdQ);
|
|
|
|
}
|
|
|
|
void baseGpuTransfer(void *ptr, void *cmdQ) {
|
|
|
|
PageFaultManager::transferToGpu(ptr, cmdQ);
|
|
|
|
}
|
2023-07-12 17:18:03 +08:00
|
|
|
void baseCpuAllocEvictable(bool evictable, void *ptr, SVMAllocsManager *unifiedMemoryManager) {
|
|
|
|
PageFaultManager::setCpuAllocEvictable(evictable, ptr, unifiedMemoryManager);
|
|
|
|
}
|
2023-07-25 17:01:53 +08:00
|
|
|
void baseAllowCPUMemoryEviction(void *ptr, PageFaultData &pageFaultData) {
|
|
|
|
PageFaultManager::allowCPUMemoryEviction(ptr, pageFaultData);
|
|
|
|
}
|
2020-09-15 18:35:17 +08:00
|
|
|
void evictMemoryAfterImplCopy(GraphicsAllocation *allocation, Device *device) override {}
|
2019-07-04 18:17:42 +08:00
|
|
|
|
2023-07-25 17:01:53 +08:00
|
|
|
void allowCPUMemoryEvictionImpl(void *ptr, CommandStreamReceiver &csr, OSInterface *osInterface) override {
|
|
|
|
allowCPUMemoryEvictionImplCalled++;
|
|
|
|
engineType = csr.getOsContext().getEngineType();
|
|
|
|
engineUsage = csr.getOsContext().getEngineUsage();
|
|
|
|
}
|
|
|
|
|
2021-03-08 19:39:07 +08:00
|
|
|
void *getHwHandlerAddress() {
|
2022-11-17 17:03:18 +08:00
|
|
|
return reinterpret_cast<void *>(PageFaultManager::transferAndUnprotectMemory);
|
2021-03-08 19:39:07 +08:00
|
|
|
}
|
|
|
|
|
2021-04-02 22:22:34 +08:00
|
|
|
void *getAubAndTbxHandlerAddress() {
|
2022-11-17 17:03:18 +08:00
|
|
|
return reinterpret_cast<void *>(PageFaultManager::unprotectAndTransferMemory);
|
2021-03-08 19:39:07 +08:00
|
|
|
}
|
2022-05-19 18:06:08 +08:00
|
|
|
void moveAllocationToGpuDomain(void *ptr) override {
|
|
|
|
moveAllocationToGpuDomainCalled++;
|
|
|
|
PageFaultManager::moveAllocationToGpuDomain(ptr);
|
|
|
|
}
|
2021-03-08 19:39:07 +08:00
|
|
|
|
2023-08-04 09:48:26 +08:00
|
|
|
int checkFaultHandlerCalled = 0;
|
|
|
|
int registerFaultHandlerCalled = 0;
|
2019-07-04 18:17:42 +08:00
|
|
|
int allowMemoryAccessCalled = 0;
|
|
|
|
int protectMemoryCalled = 0;
|
|
|
|
int transferToCpuCalled = 0;
|
|
|
|
int transferToGpuCalled = 0;
|
2022-05-19 18:06:08 +08:00
|
|
|
int moveAllocationToGpuDomainCalled = 0;
|
2023-07-12 17:18:03 +08:00
|
|
|
int setCpuAllocEvictableCalled = 0;
|
2023-07-25 17:01:53 +08:00
|
|
|
int allowCPUMemoryEvictionCalled = 0;
|
|
|
|
int allowCPUMemoryEvictionImplCalled = 0;
|
2019-07-04 18:17:42 +08:00
|
|
|
void *transferToCpuAddress = nullptr;
|
|
|
|
void *transferToGpuAddress = nullptr;
|
|
|
|
void *allowedMemoryAccessAddress = nullptr;
|
|
|
|
void *protectedMemoryAccessAddress = nullptr;
|
|
|
|
size_t transferToCpuSize = 0;
|
|
|
|
size_t accessAllowedSize = 0;
|
|
|
|
size_t protectedSize = 0;
|
2019-11-13 21:19:55 +08:00
|
|
|
bool isAubWritable = true;
|
2023-07-12 17:18:03 +08:00
|
|
|
bool isCpuAllocEvictable = true;
|
2023-07-25 17:01:53 +08:00
|
|
|
aub_stream::EngineType engineType = aub_stream::EngineType::NUM_ENGINES;
|
2023-12-11 19:02:15 +08:00
|
|
|
EngineUsage engineUsage = EngineUsage::engineUsageCount;
|
2019-07-04 18:17:42 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template <class T>
|
|
|
|
class MockPageFaultManagerHandlerInvoke : public T {
|
|
|
|
public:
|
|
|
|
using T::allowCPUMemoryAccess;
|
2023-08-04 09:48:26 +08:00
|
|
|
using T::checkFaultHandlerFromPageFaultManager;
|
2020-09-15 18:35:17 +08:00
|
|
|
using T::evictMemoryAfterImplCopy;
|
2019-07-04 18:17:42 +08:00
|
|
|
using T::protectCPUMemoryAccess;
|
2023-08-04 09:48:26 +08:00
|
|
|
using T::registerFaultHandler;
|
2019-07-04 18:17:42 +08:00
|
|
|
using T::T;
|
|
|
|
|
|
|
|
bool verifyPageFault(void *ptr) override {
|
|
|
|
handlerInvoked = true;
|
|
|
|
if (allowCPUMemoryAccessOnPageFault) {
|
|
|
|
this->allowCPUMemoryAccess(ptr, size);
|
|
|
|
}
|
2019-09-06 17:57:39 +08:00
|
|
|
return returnStatus;
|
2019-07-04 18:17:42 +08:00
|
|
|
}
|
|
|
|
|
2019-09-06 17:57:39 +08:00
|
|
|
bool returnStatus = true;
|
2019-07-04 18:17:42 +08:00
|
|
|
bool allowCPUMemoryAccessOnPageFault = false;
|
|
|
|
bool handlerInvoked = false;
|
|
|
|
size_t size = 65536;
|
|
|
|
};
|