Skip to content

Commit f8f8b53

Browse files
Improve OsHandle struct
Signed-off-by: Bartosz Dunajski <[email protected]>
1 parent 5c15a65 commit f8f8b53

17 files changed

+157
-125
lines changed

opencl/test/unit_test/os_interface/linux/drm_command_stream_tests.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -943,14 +943,14 @@ HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, makeResidentTwiceWhenFragmentSt
943943
for (int i = 0; i < maxFragmentsCount; i++) {
944944
ASSERT_EQ(allocation->fragmentsStorage.fragmentStorageData[i].cpuPtr,
945945
reqs.allocationFragments[i].allocationPtr);
946-
auto bo = allocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo;
946+
auto bo = static_cast<OsHandleLinux *>(allocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage)->bo;
947947
EXPECT_TRUE(isResident<FamilyType>(bo));
948948
EXPECT_EQ(1u, bo->getRefCount());
949949
}
950950

951951
csr->makeNonResident(*allocation);
952952
for (int i = 0; i < maxFragmentsCount; i++) {
953-
auto bo = allocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo;
953+
auto bo = static_cast<OsHandleLinux *>(allocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage)->bo;
954954
EXPECT_FALSE(isResident<FamilyType>(bo));
955955
EXPECT_EQ(1u, bo->getRefCount());
956956
}
@@ -1039,13 +1039,13 @@ HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, GivenAllocationCreatedFromThree
10391039
for (int i = 0; i < maxFragmentsCount; i++) {
10401040
ASSERT_EQ(allocation->fragmentsStorage.fragmentStorageData[i].cpuPtr,
10411041
reqs.allocationFragments[i].allocationPtr);
1042-
auto bo = allocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo;
1042+
auto bo = static_cast<OsHandleLinux *>(allocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage)->bo;
10431043
EXPECT_TRUE(isResident<FamilyType>(bo));
10441044
EXPECT_EQ(1u, bo->getRefCount());
10451045
}
10461046
csr->makeNonResident(*allocation);
10471047
for (int i = 0; i < maxFragmentsCount; i++) {
1048-
auto bo = allocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo;
1048+
auto bo = static_cast<OsHandleLinux *>(allocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage)->bo;
10491049
EXPECT_FALSE(isResident<FamilyType>(bo));
10501050
EXPECT_EQ(1u, bo->getRefCount());
10511051
}
@@ -1070,13 +1070,13 @@ HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, GivenAllocationsContainingDiffe
10701070
for (unsigned int i = 0; i < reqs.requiredFragmentsCount; i++) {
10711071
ASSERT_EQ(allocation->fragmentsStorage.fragmentStorageData[i].cpuPtr,
10721072
reqs.allocationFragments[i].allocationPtr);
1073-
auto bo = allocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo;
1073+
auto bo = static_cast<OsHandleLinux *>(allocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage)->bo;
10741074
EXPECT_TRUE(isResident<FamilyType>(bo));
10751075
EXPECT_EQ(1u, bo->getRefCount());
10761076
}
10771077
csr->makeNonResident(*allocation);
10781078
for (unsigned int i = 0; i < reqs.requiredFragmentsCount; i++) {
1079-
auto bo = allocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo;
1079+
auto bo = static_cast<OsHandleLinux *>(allocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage)->bo;
10801080
EXPECT_FALSE(isResident<FamilyType>(bo));
10811081
EXPECT_EQ(1u, bo->getRefCount());
10821082
}
@@ -1095,15 +1095,15 @@ HWTEST_TEMPLATED_F(DrmCommandStreamEnhancedTest, GivenAllocationsContainingDiffe
10951095
for (unsigned int i = 0; i < reqs.requiredFragmentsCount; i++) {
10961096
ASSERT_EQ(allocation2->fragmentsStorage.fragmentStorageData[i].cpuPtr,
10971097
reqs.allocationFragments[i].allocationPtr);
1098-
auto bo = allocation2->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo;
1098+
auto bo = static_cast<OsHandleLinux *>(allocation2->fragmentsStorage.fragmentStorageData[i].osHandleStorage)->bo;
10991099
EXPECT_TRUE(isResident<FamilyType>(bo));
11001100
EXPECT_EQ(1u, bo->getRefCount());
11011101
}
11021102
csr->makeNonResident(*allocation2);
11031103
for (unsigned int i = 0; i < reqs.requiredFragmentsCount; i++) {
1104-
auto bo = allocation2->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo;
1104+
auto bo = static_cast<OsHandleLinux *>(allocation2->fragmentsStorage.fragmentStorageData[i].osHandleStorage)->bo;
11051105
EXPECT_FALSE(isResident<FamilyType>(bo));
1106-
EXPECT_EQ(1u, allocation2->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo->getRefCount());
1106+
EXPECT_EQ(1u, bo->getRefCount());
11071107
}
11081108
mm->freeGraphicsMemory(allocation2);
11091109
}

opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ TEST_F(DrmMemoryManagerTest, GivenGraphicsAllocationWhenAddAndRemoveAllocationTo
152152
EXPECT_EQ(fragment->fragmentCpuPointer, cpuPtr);
153153
EXPECT_EQ(fragment->fragmentSize, size);
154154
EXPECT_NE(fragment->osInternalStorage, nullptr);
155-
EXPECT_EQ(fragment->osInternalStorage->bo, gfxAllocation.getBO());
155+
EXPECT_EQ(static_cast<OsHandleLinux *>(fragment->osInternalStorage)->bo, gfxAllocation.getBO());
156156
EXPECT_NE(fragment->residency, nullptr);
157157

158158
FragmentStorage fragmentStorage = {};
@@ -1036,10 +1036,10 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledHostMemoryValid
10361036
}
10371037

10381038
TEST_F(DrmMemoryManagerTest, GivenNoInputsWhenOsHandleIsCreatedThenAllBoHandlesAreInitializedAsNullPtrs) {
1039-
OsHandle boHandle;
1039+
OsHandleLinux boHandle;
10401040
EXPECT_EQ(nullptr, boHandle.bo);
10411041

1042-
std::unique_ptr<OsHandle> boHandle2(new OsHandle);
1042+
std::unique_ptr<OsHandleLinux> boHandle2(new OsHandleLinux);
10431043
EXPECT_EQ(nullptr, boHandle2->bo);
10441044
}
10451045

@@ -1138,9 +1138,10 @@ TEST_F(DrmMemoryManagerTest, GivenMisalignedHostPtrAndMultiplePagesSizeWhenAsked
11381138
auto reqs = MockHostPtrManager::getAllocationRequirements(rootDeviceIndex, ptr, size);
11391139

11401140
for (int i = 0; i < maxFragmentsCount; i++) {
1141-
ASSERT_NE(nullptr, graphicsAllocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo);
1142-
EXPECT_EQ(reqs.allocationFragments[i].allocationSize, graphicsAllocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo->peekSize());
1143-
EXPECT_EQ(reqs.allocationFragments[i].allocationPtr, reinterpret_cast<void *>(graphicsAllocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo->peekAddress()));
1141+
auto osHandle = static_cast<OsHandleLinux *>(graphicsAllocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage);
1142+
ASSERT_NE(nullptr, osHandle->bo);
1143+
EXPECT_EQ(reqs.allocationFragments[i].allocationSize, osHandle->bo->peekSize());
1144+
EXPECT_EQ(reqs.allocationFragments[i].allocationPtr, reinterpret_cast<void *>(osHandle->bo->peekAddress()));
11441145
}
11451146
memoryManager->freeGraphicsMemory(graphicsAllocation);
11461147

@@ -3232,7 +3233,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDisabledForcePinAndEna
32323233
mock->ioctl_expected.execbuffer2 = 0; // pinning for host memory validation is mocked
32333234

32343235
OsHandleStorage handleStorage;
3235-
OsHandle handle1;
3236+
OsHandleLinux handle1;
32363237
handleStorage.fragmentStorageData[0].osHandleStorage = &handle1;
32373238
handleStorage.fragmentStorageData[0].cpuPtr = reinterpret_cast<void *>(0x1000);
32383239
handleStorage.fragmentStorageData[0].fragmentSize = 4096;
@@ -3254,8 +3255,8 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDisabledForcePinAndEna
32543255
EXPECT_NE(nullptr, handleStorage.fragmentStorageData[1].osHandleStorage);
32553256
EXPECT_NE(nullptr, handleStorage.fragmentStorageData[2].osHandleStorage);
32563257

3257-
EXPECT_EQ(handleStorage.fragmentStorageData[1].osHandleStorage->bo, pinBB->pinnedBoArray[0]);
3258-
EXPECT_EQ(handleStorage.fragmentStorageData[2].osHandleStorage->bo, pinBB->pinnedBoArray[1]);
3258+
EXPECT_EQ(static_cast<OsHandleLinux *>(handleStorage.fragmentStorageData[1].osHandleStorage)->bo, pinBB->pinnedBoArray[0]);
3259+
EXPECT_EQ(static_cast<OsHandleLinux *>(handleStorage.fragmentStorageData[2].osHandleStorage)->bo, pinBB->pinnedBoArray[1]);
32593260

32603261
handleStorage.fragmentStorageData[0].freeTheFragment = false;
32613262
handleStorage.fragmentStorageData[1].freeTheFragment = true;
@@ -3534,7 +3535,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledValidateHostMem
35343535
mock->ioctl_expected.execbuffer2 = 1;
35353536

35363537
OsHandleStorage handleStorage;
3537-
OsHandle handle1;
3538+
OsHandleLinux handle1;
35383539
handleStorage.fragmentStorageData[0].osHandleStorage = &handle1;
35393540
handleStorage.fragmentStorageData[0].cpuPtr = reinterpret_cast<void *>(0x1000);
35403541
handleStorage.fragmentStorageData[0].fragmentSize = 4096;
@@ -3584,7 +3585,7 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenEnabledValidateHostMem
35843585
mock->ioctl_expected.execbuffer2 = 1;
35853586

35863587
OsHandleStorage handleStorage;
3587-
OsHandle handle1;
3588+
OsHandleLinux handle1;
35883589
handleStorage.fragmentStorageData[0].osHandleStorage = &handle1;
35893590
handleStorage.fragmentStorageData[0].cpuPtr = reinterpret_cast<void *>(0x1000);
35903591
handleStorage.fragmentStorageData[0].fragmentSize = 4096;
@@ -3652,12 +3653,12 @@ TEST_F(DrmMemoryManagerWithExplicitExpectationsTest, givenDrmMemoryManagerWhenCl
36523653
auto maxOsContextCount = 1u;
36533654

36543655
OsHandleStorage handleStorage;
3655-
handleStorage.fragmentStorageData[0].osHandleStorage = new OsHandle();
3656+
handleStorage.fragmentStorageData[0].osHandleStorage = new OsHandleLinux();
36563657
handleStorage.fragmentStorageData[0].residency = new ResidencyData(maxOsContextCount);
36573658
handleStorage.fragmentStorageData[0].cpuPtr = reinterpret_cast<void *>(0x1000);
36583659
handleStorage.fragmentStorageData[0].fragmentSize = 4096;
36593660

3660-
handleStorage.fragmentStorageData[1].osHandleStorage = new OsHandle();
3661+
handleStorage.fragmentStorageData[1].osHandleStorage = new OsHandleLinux();
36613662
handleStorage.fragmentStorageData[1].residency = new ResidencyData(maxOsContextCount);
36623663
handleStorage.fragmentStorageData[1].cpuPtr = reinterpret_cast<void *>(0x1000);
36633664
handleStorage.fragmentStorageData[1].fragmentSize = 4096;
@@ -4377,7 +4378,7 @@ TEST_F(DrmMemoryManagerTest, givenDrmAllocationWithHostPtrWhenItIsCreatedWithCac
43774378
allocation->setCacheAdvice(drm, 1024, CacheRegion::Region1);
43784379

43794380
for (uint32_t i = 0; i < storage.fragmentCount; i++) {
4380-
auto bo = allocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage->bo;
4381+
auto bo = static_cast<OsHandleLinux *>(allocation->fragmentsStorage.fragmentStorageData[i].osHandleStorage)->bo;
43814382
EXPECT_EQ(CacheRegion::Region1, bo->peekCacheRegion());
43824383
}
43834384

opencl/test/unit_test/os_interface/windows/device_command_stream_tests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ TEST_F(WddmCommandStreamTest, givenAddressWithHighestBitSetWhenItIsMappedThenPro
707707
auto expectedAddress = castToUint64(faultyAddress);
708708
EXPECT_EQ(gfxAllocation->getGpuAddress(), expectedAddress);
709709
ASSERT_EQ(gfxAllocation->fragmentsStorage.fragmentCount, 1u);
710-
EXPECT_EQ(expectedAddress, gfxAllocation->fragmentsStorage.fragmentStorageData[0].osHandleStorage->gpuPtr);
710+
EXPECT_EQ(expectedAddress, static_cast<OsHandleWin *>(gfxAllocation->fragmentsStorage.fragmentStorageData[0].osHandleStorage)->gpuPtr);
711711

712712
memoryManager->freeGraphicsMemory(gfxAllocation);
713713
}

opencl/test/unit_test/os_interface/windows/wddm20_tests.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -319,9 +319,9 @@ TEST_F(Wddm20Tests, givenGraphicsAllocationWhenItIsMappedInHeap0ThenItHasGpuAddr
319319

320320
TEST_F(Wddm20WithMockGdiDllTests, GivenThreeOsHandlesWhenAskedForDestroyAllocationsThenAllMarkedAllocationsAreDestroyed) {
321321
OsHandleStorage storage;
322-
OsHandle osHandle1 = {0};
323-
OsHandle osHandle2 = {0};
324-
OsHandle osHandle3 = {0};
322+
OsHandleWin osHandle1;
323+
OsHandleWin osHandle2;
324+
OsHandleWin osHandle3;
325325

326326
osHandle1.handle = ALLOCATION_HANDLE;
327327
osHandle2.handle = ALLOCATION_HANDLE;
@@ -822,7 +822,7 @@ TEST_F(Wddm20Tests, givenReadOnlyMemoryWhenCreateAllocationFailsWithNoVideoMemor
822822
gdi->createAllocation = MockCreateAllocation::mockCreateAllocation;
823823

824824
OsHandleStorage handleStorage;
825-
OsHandle handle = {0};
825+
OsHandleWin handle;
826826
auto maxOsContextCount = 1u;
827827
ResidencyData residency(maxOsContextCount);
828828

@@ -832,13 +832,13 @@ TEST_F(Wddm20Tests, givenReadOnlyMemoryWhenCreateAllocationFailsWithNoVideoMemor
832832
handleStorage.fragmentStorageData[0].freeTheFragment = false;
833833
handleStorage.fragmentStorageData[0].osHandleStorage = &handle;
834834
handleStorage.fragmentStorageData[0].residency = &residency;
835-
handleStorage.fragmentStorageData[0].osHandleStorage->gmm = GmmHelperFunctions::getGmm(nullptr, 0, getGmmClientContext());
835+
handle.gmm = GmmHelperFunctions::getGmm(nullptr, 0, getGmmClientContext());
836836

837837
NTSTATUS result = wddm->createAllocationsAndMapGpuVa(handleStorage);
838838

839839
EXPECT_EQ(STATUS_GRAPHICS_NO_VIDEO_MEMORY, result);
840840

841-
delete handleStorage.fragmentStorageData[0].osHandleStorage->gmm;
841+
delete handle.gmm;
842842
}
843843

844844
TEST_F(Wddm20Tests, whenContextIsInitializedThenApplyAdditionalContextFlagsIsCalled) {

opencl/test/unit_test/os_interface/windows/wddm_kmdaf_listener_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,11 @@ TEST_F(WddmKmDafListenerTest, givenWddmWhenCreateAllocation64IsCalledThenKmDafLi
164164

165165
TEST_F(WddmKmDafListenerTest, givenWddmWhenCreateAllocationsAndMapGpuVaIsCalledThenKmDafListenerNotifyWriteTargetAndMapGpuVAIsFedWithCorrectParams) {
166166
OsHandleStorage storage;
167-
OsHandle osHandle = {0};
167+
OsHandleWin osHandle;
168168
auto gmm = std::unique_ptr<Gmm>(new Gmm(rootDeviceEnvironment->getGmmClientContext(), nullptr, 1, false));
169169
storage.fragmentStorageData[0].osHandleStorage = &osHandle;
170170
storage.fragmentStorageData[0].fragmentSize = 100;
171-
storage.fragmentStorageData[0].osHandleStorage->gmm = gmm.get();
171+
static_cast<OsHandleWin *>(storage.fragmentStorageData[0].osHandleStorage)->gmm = gmm.get();
172172

173173
wddmWithKmDafMock->createAllocationsAndMapGpuVa(storage);
174174

0 commit comments

Comments
 (0)