Skip to content

Commit ea6e298

Browse files
Query free memory info inside zesMemoryGetState API
Signed-off-by: Jitendra Sharma <jitendra.sharma@intel.com>
1 parent 571007c commit ea6e298

File tree

4 files changed

+51
-17
lines changed

4 files changed

+51
-17
lines changed

level_zero/tools/source/sysman/memory/linux/dg1/os_memory_imp.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,10 @@
1313

1414
namespace L0 {
1515

16-
void LinuxMemoryImp::init() {
17-
auto memoryInfo = static_cast<NEO::MemoryInfoImpl *>(pDrm->getMemoryInfo());
18-
if (!memoryInfo) {
19-
return;
20-
}
21-
for (auto region : memoryInfo->regions) {
22-
if (region.region.memory_class == I915_MEMORY_CLASS_DEVICE) {
23-
deviceRegions.push_back(region);
24-
}
25-
}
26-
}
27-
2816
LinuxMemoryImp::LinuxMemoryImp(OsSysman *pOsSysman, ze_bool_t onSubdevice, uint32_t subdeviceId) : isSubdevice(onSubdevice), subdeviceId(subdeviceId) {
2917
LinuxSysmanImp *pLinuxSysmanImp = static_cast<LinuxSysmanImp *>(pOsSysman);
3018
pDrm = &pLinuxSysmanImp->getDrm();
3119
pDevice = pLinuxSysmanImp->getDeviceHandle();
32-
init();
3320
}
3421

3522
bool LinuxMemoryImp::isMemoryModuleSupported() {
@@ -53,9 +40,23 @@ ze_result_t LinuxMemoryImp::getBandwidth(zes_mem_bandwidth_t *pBandwidth) {
5340
}
5441

5542
ze_result_t LinuxMemoryImp::getState(zes_mem_state_t *pState) {
56-
pState->health = ZES_MEM_HEALTH_OK;
43+
std::vector<drm_i915_memory_region_info> deviceRegions;
44+
if (pDrm->queryMemoryInfo() == false) {
45+
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
46+
}
47+
48+
auto memoryInfo = static_cast<NEO::MemoryInfoImpl *>(pDrm->getMemoryInfo());
49+
if (!memoryInfo) {
50+
return ZE_RESULT_ERROR_UNSUPPORTED_FEATURE;
51+
}
52+
for (auto region : memoryInfo->regions) {
53+
if (region.region.memory_class == I915_MEMORY_CLASS_DEVICE) {
54+
deviceRegions.push_back(region);
55+
}
56+
}
5757
pState->free = deviceRegions[subdeviceId].unallocated_size;
5858
pState->size = deviceRegions[subdeviceId].probed_size;
59+
pState->health = ZES_MEM_HEALTH_OK;
5960

6061
return ZE_RESULT_SUCCESS;
6162
}

level_zero/tools/source/sysman/memory/linux/dg1/os_memory_imp.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,5 @@ class LinuxMemoryImp : public OsMemory, NEO::NonCopyableOrMovableClass {
3333
private:
3434
bool isSubdevice = false;
3535
uint32_t subdeviceId = 0;
36-
void init();
37-
std::vector<drm_i915_memory_region_info> deviceRegions;
3836
};
3937
} // namespace L0

level_zero/tools/test/unit_tests/sources/sysman/memory/linux/dg1/mock_memory.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ struct Mock<MemoryNeoDrm> : public MemoryNeoDrm {
6060
return true;
6161
}
6262

63+
bool queryMemoryInfoMockReturnFalse() {
64+
return false;
65+
}
66+
67+
bool queryMemoryInfoMockReturnFakeTrue() {
68+
return true;
69+
}
70+
6371
MOCK_METHOD(bool, queryMemoryInfo, (), (override));
6472
};
6573

level_zero/tools/test/unit_tests/sources/sysman/memory/linux/dg1/test_sysman_memory.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ class SysmanDeviceMemoryFixture : public SysmanDeviceFixture {
5353
deviceHandles.resize(subDeviceCount, nullptr);
5454
Device::fromHandle(device->toHandle())->getSubDevices(&subDeviceCount, deviceHandles.data());
5555
}
56-
pDrm->queryMemoryInfo();
5756
pSysmanDeviceImp->pMemoryHandleContext->init(deviceHandles);
5857
}
5958

@@ -208,6 +207,34 @@ TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzetSysmanMemo
208207
}
209208
}
210209

210+
TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzetSysmanMemoryGetStateAndIfQueryMemoryInfoFailsThenErrorIsReturned) {
211+
setLocalSupportedAndReinit(true);
212+
213+
ON_CALL(*pDrm, queryMemoryInfo())
214+
.WillByDefault(::testing::Invoke(pDrm, &Mock<MemoryNeoDrm>::queryMemoryInfoMockReturnFalse));
215+
216+
auto handles = get_memory_handles(memoryHandleComponentCount);
217+
218+
for (auto handle : handles) {
219+
zes_mem_state_t state;
220+
EXPECT_EQ(zesMemoryGetState(handle, &state), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
221+
}
222+
}
223+
224+
TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzetSysmanMemoryGetStateAndIfQueryMemoryInfoAndIfMemoryInfoIsNotCorrectThenErrorIsReturned) {
225+
setLocalSupportedAndReinit(true);
226+
227+
ON_CALL(*pDrm, queryMemoryInfo())
228+
.WillByDefault(::testing::Invoke(pDrm, &Mock<MemoryNeoDrm>::queryMemoryInfoMockReturnFakeTrue));
229+
230+
auto handles = get_memory_handles(memoryHandleComponentCount);
231+
232+
for (auto handle : handles) {
233+
zes_mem_state_t state;
234+
EXPECT_EQ(zesMemoryGetState(handle, &state), ZE_RESULT_ERROR_UNSUPPORTED_FEATURE);
235+
}
236+
}
237+
211238
TEST_F(SysmanDeviceMemoryFixture, GivenValidMemoryHandleWhenCallingzetSysmanMemoryGetBandwidthhenVerifySysmanMemoryGetBandwidthCallReturnUnsupportedFeature) {
212239
setLocalSupportedAndReinit(true);
213240

0 commit comments

Comments
 (0)