Change MemoryManager::lastPeriodicTrimFenceValue to a vector

Also start registering OsContext to MemoryManager in
WddmMemoryManagerResidencyTest along with some cleanup in fixture's SetUp

Change-Id: I3f6763ae0cd9bf638cdc5dbbfbc60dfb0fd0ef05
Signed-off-by: Maciej Dziuban <maciej.dziuban@intel.com>
This commit is contained in:
Maciej Dziuban
2018-09-26 13:19:20 +02:00
committed by sys_ocldev
parent cbd017d495
commit ea9e7bea31
6 changed files with 66 additions and 50 deletions

View File

@ -264,7 +264,7 @@ class MemoryManager {
::alignedFree(ptr);
}
void registerOsContext(OsContext *contextToRegister);
virtual void registerOsContext(OsContext *contextToRegister);
size_t getOsContextCount() { return registeredOsContexts.size(); }
protected:

View File

@ -416,6 +416,11 @@ void WddmMemoryManager::cleanOsHandles(OsHandleStorage &handleStorage) {
}
}
void WddmMemoryManager::registerOsContext(OsContext *contextToRegister) {
MemoryManager::registerOsContext(contextToRegister);
this->lastPeriodicTrimFenceValues.resize(this->registeredOsContexts.size());
}
void WddmMemoryManager::obtainGpuAddresFromFragments(WddmAllocation *allocation, OsHandleStorage &handleStorage) {
if (this->force32bitAllocations && (handleStorage.fragmentCount > 0)) {
auto hostPtr = allocation->getUnderlyingBuffer();
@ -652,10 +657,10 @@ void WddmMemoryManager::trimResidency(D3DDDI_TRIMRESIDENCYSET_FLAGS flags, uint6
WddmAllocation *wddmAllocation = nullptr;
while ((wddmAllocation = getTrimCandidateHead()) != nullptr) {
DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "lastPeriodicTrimFenceValue = ", lastPeriodicTrimFenceValue);
DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "lastPeriodicTrimFenceValue = ", lastPeriodicTrimFenceValues[0]);
// allocation was not used from last periodic trim
if (wddmAllocation->getResidencyData().getFenceValueForContextId(0) <= lastPeriodicTrimFenceValue) {
if (wddmAllocation->getResidencyData().getFenceValueForContextId(0) <= lastPeriodicTrimFenceValues[0]) {
DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "allocation: handle =", wddmAllocation->handle, "lastFence =", (wddmAllocation)->getResidencyData().getFenceValueForContextId(0));
@ -667,7 +672,7 @@ void WddmMemoryManager::trimResidency(D3DDDI_TRIMRESIDENCYSET_FLAGS flags, uint6
}
for (uint32_t allocationId = 0; allocationId < wddmAllocation->fragmentsStorage.fragmentCount; allocationId++) {
if (wddmAllocation->fragmentsStorage.fragmentStorageData[allocationId].residency->getFenceValueForContextId(0) <= lastPeriodicTrimFenceValue) {
if (wddmAllocation->fragmentsStorage.fragmentStorageData[allocationId].residency->getFenceValueForContextId(0) <= lastPeriodicTrimFenceValues[0]) {
DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "Evict fragment: handle =", wddmAllocation->fragmentsStorage.fragmentStorageData[allocationId].osHandleStorage->handle, "lastFence =", wddmAllocation->fragmentsStorage.fragmentStorageData[allocationId].residency->getFenceValueForContextId(0));
@ -709,8 +714,8 @@ void WddmMemoryManager::trimResidency(D3DDDI_TRIMRESIDENCYSET_FLAGS flags, uint6
if (!osContext) {
osContext = platform()->getDevice(0)->getOsContext();
}
lastPeriodicTrimFenceValue = *osContext->get()->getMonitoredFence().cpuAddress;
DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "updated lastPeriodicTrimFenceValue =", lastPeriodicTrimFenceValue);
lastPeriodicTrimFenceValues[0] = *osContext->get()->getMonitoredFence().cpuAddress;
DBG_LOG(ResidencyDebugEnable, "Residency:", __FUNCTION__, "updated lastPeriodicTrimFenceValue =", lastPeriodicTrimFenceValues[0]);
}
}

View File

@ -55,6 +55,8 @@ class WddmMemoryManager : public MemoryManager {
AllocationStatus populateOsHandles(OsHandleStorage &handleStorage) override;
void cleanOsHandles(OsHandleStorage &handleStorage) override;
void registerOsContext(OsContext *contextToRegister) override;
void obtainGpuAddresFromFragments(WddmAllocation *allocation, OsHandleStorage &handleStorage);
GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, size_t hostPtrSize, const void *hostPtr) override;
@ -112,7 +114,7 @@ class WddmMemoryManager : public MemoryManager {
ResidencyContainer trimCandidateList;
std::mutex trimCandidateListMutex;
std::atomic<bool> residencyLock;
uint64_t lastPeriodicTrimFenceValue = 0;
std::vector<uint64_t> lastPeriodicTrimFenceValues;
uint32_t trimCandidatesCount = 0;
bool memoryBudgetExhausted = false;
AlignedMallocRestrictions mallocRestrictions;

View File

@ -18,7 +18,7 @@ class MockWddmMemoryManager : public WddmMemoryManager {
using BaseClass::checkTrimCandidateListCompaction;
using BaseClass::compactTrimCandidateList;
using BaseClass::createWddmAllocation;
using BaseClass::lastPeriodicTrimFenceValue;
using BaseClass::lastPeriodicTrimFenceValues;
using BaseClass::removeFromTrimCandidateList;
using BaseClass::trimCandidateList;
using BaseClass::trimCandidatesCount;

View File

@ -25,22 +25,21 @@ using namespace ::testing;
void WddmMemoryManagerFixture::SetUp() {
GmmEnvironmentFixture::SetUp();
GdiDllFixture::SetUp();
wddm.reset(static_cast<WddmMock *>(Wddm::createWddm()));
ASSERT_NE(nullptr, wddm);
wddm = static_cast<WddmMock *>(Wddm::createWddm());
if (platformDevices[0]->capabilityTable.ftrRenderCompressedBuffers || platformDevices[0]->capabilityTable.ftrRenderCompressedImages) {
GMM_DEVICE_CALLBACKS_INT dummyDeviceCallbacks = {};
GMM_TRANSLATIONTABLE_CALLBACKS dummyTTCallbacks = {};
wddm->resetPageTableManager(GmmPageTableMngr::create(&dummyDeviceCallbacks, 0, &dummyTTCallbacks));
}
EXPECT_TRUE(wddm->init());
uint64_t heap32Base = (uint64_t)(0x800000000000);
if (sizeof(uintptr_t) == 4) {
heap32Base = 0x1000;
}
constexpr uint64_t heap32Base = (is32bit) ? 0x1000 : 0x800000000000;
wddm->setHeap32(heap32Base, 1000 * MemoryConstants::pageSize - 1);
memoryManager.reset(new (std::nothrow) MockWddmMemoryManager(wddm.get()));
//assert we have memory manager
ASSERT_NE(nullptr, memoryManager);
osInterface = std::make_unique<OSInterface>();
osInterface->get()->setWddm(wddm);
memoryManager = std::make_unique<MockWddmMemoryManager>(wddm);
}
TEST(WddmMemoryManager, NonCopyable) {
@ -53,6 +52,24 @@ TEST(WddmMemoryManager, NonAssignable) {
EXPECT_FALSE(std::is_copy_assignable<WddmMemoryManager>::value);
}
TEST_F(WddmMemoryManagerTest, givenWddmMemoryManagerWhenRegisteringOsContextThenLastPeriodicTrimFenceValuesIsResizedAccordinglyToContextId) {
memoryManager->registerOsContext(new OsContext(osInterface.get(), 0u));
EXPECT_EQ(1, memoryManager->lastPeriodicTrimFenceValues.size());
EXPECT_EQ(0, memoryManager->lastPeriodicTrimFenceValues[0]);
memoryManager->registerOsContext(new OsContext(osInterface.get(), 2u));
EXPECT_EQ(3, memoryManager->lastPeriodicTrimFenceValues.size());
EXPECT_EQ(0, memoryManager->lastPeriodicTrimFenceValues[0]);
EXPECT_EQ(0, memoryManager->lastPeriodicTrimFenceValues[1]);
EXPECT_EQ(0, memoryManager->lastPeriodicTrimFenceValues[2]);
memoryManager->registerOsContext(new OsContext(osInterface.get(), 1u));
EXPECT_EQ(3, memoryManager->lastPeriodicTrimFenceValues.size());
EXPECT_EQ(0, memoryManager->lastPeriodicTrimFenceValues[0]);
EXPECT_EQ(0, memoryManager->lastPeriodicTrimFenceValues[1]);
EXPECT_EQ(0, memoryManager->lastPeriodicTrimFenceValues[2]);
}
TEST(WddmMemoryManagerAllocator32BitTest, allocator32BitIsCreatedWithCorrectBase) {
std::unique_ptr<WddmMock> wddm(static_cast<WddmMock *>(Wddm::createWddm()));
uint64_t base = 0x56000;
@ -206,7 +223,6 @@ TEST_F(WddmMemoryManagerTest, givenDefaultWddmMemoryManagerWhenAskedForVirtualPa
}
TEST_F(WddmMemoryManagerTest, GivenGraphicsAllocationWhenAddAndRemoveAllocationToHostPtrManagerThenfragmentHasCorrectValues) {
memoryManager.reset(new (std::nothrow) MockWddmMemoryManager(wddm.get()));
void *cpuPtr = (void *)0x30000;
size_t size = 0x1000;
@ -1115,7 +1131,7 @@ TEST_F(WddmMemoryManagerResidencyTest, givenNotUsedAllocationsFromPreviousPeriod
allocation2.getResidencyData().resident = true;
// Set last periodic fence value
memoryManager->lastPeriodicTrimFenceValue = 10;
memoryManager->lastPeriodicTrimFenceValues[0] = 10;
// Set current fence value to greater value
osContext->get()->getMonitoredFence().currentFenceValue = 20;
@ -1151,7 +1167,7 @@ TEST_F(WddmMemoryManagerResidencyTest, givenOneUsedAllocationFromPreviousPeriodi
allocation2.getResidencyData().resident = true;
// Set last periodic fence value
memoryManager->lastPeriodicTrimFenceValue = 10;
memoryManager->lastPeriodicTrimFenceValues[0] = 10;
// Set current fence value to greater value
osContext->get()->getMonitoredFence().currentFenceValue = 20;
@ -1197,7 +1213,7 @@ TEST_F(WddmMemoryManagerResidencyTest, givenTripleAllocationWithUsedAndUnusedFra
allocationTriple->fragmentsStorage.fragmentStorageData[2].residency->resident = true;
// Set last periodic fence value
memoryManager->lastPeriodicTrimFenceValue = 10;
memoryManager->lastPeriodicTrimFenceValues[0] = 10;
// Set current fence value to greater value
osContext->get()->getMonitoredFence().currentFenceValue = 20;
@ -1226,14 +1242,14 @@ TEST_F(WddmMemoryManagerResidencyTest, givenPeriodicTrimWhenTrimCallbackCalledTh
trimNotification.NumBytesToTrim = 0;
// Set last periodic fence value
memoryManager->lastPeriodicTrimFenceValue = 10;
memoryManager->lastPeriodicTrimFenceValues[0] = 10;
// Set current fence value to greater value
*osContext->get()->getMonitoredFence().cpuAddress = 20;
memoryManager->trimCandidateList.resize(0);
memoryManager->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim);
EXPECT_EQ(20u, memoryManager->lastPeriodicTrimFenceValue);
EXPECT_EQ(20u, memoryManager->lastPeriodicTrimFenceValues[0]);
}
TEST_F(WddmMemoryManagerResidencyTest, givenRestartPeriodicTrimWhenTrimCallbackCalledThenLastPeriodicTrimFenceIsSetToCurrentFenceValue) {
@ -1244,14 +1260,14 @@ TEST_F(WddmMemoryManagerResidencyTest, givenRestartPeriodicTrimWhenTrimCallbackC
trimNotification.NumBytesToTrim = 0;
// Set last periodic fence value
memoryManager->lastPeriodicTrimFenceValue = 10;
memoryManager->lastPeriodicTrimFenceValues[0] = 10;
// Set current fence value to greater value
*osContext->get()->getMonitoredFence().cpuAddress = 20;
memoryManager->trimCandidateList.resize(0);
memoryManager->trimResidency(trimNotification.Flags, trimNotification.NumBytesToTrim);
EXPECT_EQ(20u, memoryManager->lastPeriodicTrimFenceValue);
EXPECT_EQ(20u, memoryManager->lastPeriodicTrimFenceValues[0]);
}
TEST_F(WddmMemoryManagerResidencyTest, trimToBudgetWithZeroSizeReturnsTrue) {

View File

@ -32,9 +32,9 @@ class WddmMemoryManagerFixture : public GmmEnvironmentFixture, public GdiDllFixt
GdiDllFixture::TearDown();
GmmEnvironmentFixture::TearDown();
}
std::unique_ptr<OSInterface> osInterface;
std::unique_ptr<MockWddmMemoryManager> memoryManager;
std::unique_ptr<WddmMock> wddm;
WddmMock *wddm;
};
typedef ::Test<WddmMemoryManagerFixture> WddmMemoryManagerTest;
@ -43,32 +43,34 @@ class MockWddmMemoryManagerFixture : public GmmEnvironmentFixture {
public:
void SetUp() {
GmmEnvironmentFixture::SetUp();
wddm = (static_cast<WddmMock *>(Wddm::createWddm()));
gdi = new MockGdi();
wddm = static_cast<WddmMock *>(Wddm::createWddm());
wddm->gdi.reset(gdi);
constexpr uint64_t heap32Base = (is32bit) ? 0x1000 : 0x800000000000;
wddm->setHeap32(heap32Base, 1000 * MemoryConstants::pageSize - 1);
EXPECT_TRUE(wddm->init());
osInterface = std::make_unique<OSInterface>();
osInterface->get()->setWddm(wddm);
gdi = new MockGdi();
wddm->gdi.reset(gdi);
EXPECT_TRUE(wddm->init());
osContext = new OsContext(osInterface.get(), 0u);
osContext->incRefInternal();
uint64_t heap32Base = (uint64_t)(0x800000000000);
if (sizeof(uintptr_t) == 4) {
heap32Base = 0x1000;
}
wddm->setHeap32(heap32Base, 1000 * MemoryConstants::pageSize - 1);
memoryManager.reset(new (std::nothrow) MockWddmMemoryManager(wddm));
//assert we have memory manager
ASSERT_NE(nullptr, memoryManager);
memoryManager = std::make_unique<MockWddmMemoryManager>(wddm);
memoryManager->registerOsContext(osContext);
}
void TearDown() {
osContext->decRefInternal();
GmmEnvironmentFixture::TearDown();
}
std::unique_ptr<OSInterface> osInterface;
std::unique_ptr<MockWddmMemoryManager> memoryManager;
WddmMock *wddm = nullptr;
std::unique_ptr<OSInterface> osInterface;
OsContext *osContext;
OsContext *osContext = nullptr;
MockGdi *gdi = nullptr;
};
@ -145,15 +147,6 @@ class BufferWithWddmMemory : public ::testing::Test,
void SetUp() {
WddmMemoryManagerFixture::SetUp();
tmp = context.getMemoryManager();
EXPECT_TRUE(wddm->init());
uint64_t heap32Base = (uint64_t)(0x800000000000);
if (sizeof(uintptr_t) == 4) {
heap32Base = 0x1000;
}
wddm->setHeap32(heap32Base, 1000 * MemoryConstants::pageSize - 1);
memoryManager.reset(new (std::nothrow) MockWddmMemoryManager(wddm.get()));
//assert we have memory manager
ASSERT_NE(nullptr, memoryManager);
context.setMemoryManager(memoryManager.get());
flags = 0;
}