From 3fa6089097f4f7bd7ee75816f85b7218f3ce92b4 Mon Sep 17 00:00:00 2001 From: Anvesh Bakwad Date: Fri, 27 Jun 2025 09:25:36 +0000 Subject: [PATCH] fix(sysman): Use CPU timestamp instead of PMT timestamp for Memory Bandwidth Related-To: NEO-15385 Signed-off-by: Anvesh Bakwad --- .../bmg/sysman_product_helper_bmg.cpp | 29 ++----------------- .../bmg/sysman_product_helper_bmg.cpp | 17 ++--------- .../sysman_product_helper_memory_tests.cpp | 29 +++++-------------- .../sysman_product_helper_memory_tests.cpp | 28 ++++-------------- 4 files changed, 18 insertions(+), 85 deletions(-) diff --git a/level_zero/sysman/source/shared/linux/product_helper/xe2_hpg_core/bmg/sysman_product_helper_bmg.cpp b/level_zero/sysman/source/shared/linux/product_helper/xe2_hpg_core/bmg/sysman_product_helper_bmg.cpp index 18d33cd4ad..efd98f5a15 100644 --- a/level_zero/sysman/source/shared/linux/product_helper/xe2_hpg_core/bmg/sysman_product_helper_bmg.cpp +++ b/level_zero/sysman/source/shared/linux/product_helper/xe2_hpg_core/bmg/sysman_product_helper_bmg.cpp @@ -782,27 +782,6 @@ static ze_result_t getMemoryMaxBandwidth(const std::map & return ZE_RESULT_SUCCESS; } -static ze_result_t getMemoryBandwidthTimestamp(const std::map &keyOffsetMap, std::unordered_map &keyTelemInfoMap, - zes_mem_bandwidth_t *pBandwidth) { - uint32_t timeStampH = 0; - uint32_t timeStampL = 0; - pBandwidth->timestamp = 0; - - std::string key = "GDDR_TELEM_CAPTURE_TIMESTAMP_UPPER"; - if (!PlatformMonitoringTech::readValue(keyOffsetMap, keyTelemInfoMap[key], key, 0, timeStampH)) { - return ZE_RESULT_ERROR_NOT_AVAILABLE; - } - - key = "GDDR_TELEM_CAPTURE_TIMESTAMP_LOWER"; - if (!PlatformMonitoringTech::readValue(keyOffsetMap, keyTelemInfoMap[key], key, 0, timeStampL)) { - return ZE_RESULT_ERROR_NOT_AVAILABLE; - } - - pBandwidth->timestamp = packInto64Bit(timeStampH, timeStampL) * milliSecsToMicroSecs; - - return ZE_RESULT_SUCCESS; -} - static ze_result_t getCounterValues(const std::vector> ®isterList, const std::string &keyPrefix, const std::map &keyOffsetMap, std::unordered_map &keyTelemInfoMap, uint64_t &totalCounter) { for (const auto ®Pair : registerList) { @@ -927,16 +906,14 @@ ze_result_t SysmanProductHelperHw::getMemoryBandwidth(zes_mem_bandwi return ZE_RESULT_ERROR_NOT_AVAILABLE; } - // Get Timestamp Values - if (ZE_RESULT_SUCCESS != getMemoryBandwidthTimestamp(keyOffsetMap, keyTelemInfoMap, pBandwidth)) { - return ZE_RESULT_ERROR_NOT_AVAILABLE; - } - // Get Max Bandwidth if (ZE_RESULT_SUCCESS != getMemoryMaxBandwidth(keyOffsetMap, keyTelemInfoMap, pBandwidth)) { return ZE_RESULT_ERROR_NOT_AVAILABLE; } + // Get Timestamp + pBandwidth->timestamp = SysmanDevice::getSysmanTimestamp(); + return ZE_RESULT_SUCCESS; } diff --git a/level_zero/sysman/source/shared/windows/product_helper/xe2_hpg_core/bmg/sysman_product_helper_bmg.cpp b/level_zero/sysman/source/shared/windows/product_helper/xe2_hpg_core/bmg/sysman_product_helper_bmg.cpp index 6712592339..079ba1e8b5 100644 --- a/level_zero/sysman/source/shared/windows/product_helper/xe2_hpg_core/bmg/sysman_product_helper_bmg.cpp +++ b/level_zero/sysman/source/shared/windows/product_helper/xe2_hpg_core/bmg/sysman_product_helper_bmg.cpp @@ -875,21 +875,8 @@ ze_result_t SysmanProductHelperHw::getMemoryBandWidth(zes_mem_bandwi // PMT reports maxBandwidth in units of 100 MBps (decimal). Need to convert it into Bytes/sec, unit to be returned by sysman. pBandwidth->maxBandwidth = static_cast(maxBandwidth) * megaBytesToBytes * 100; - // timestamp calculation - uint32_t timeStampL = 0; - uint32_t timeStampH = 0; - - status = pPmt->readValue("GDDR_TELEM_CAPTURE_TIMESTAMP_UPPER", timeStampH); - if (status != ZE_RESULT_SUCCESS) { - return status; - } - status = pPmt->readValue("GDDR_TELEM_CAPTURE_TIMESTAMP_LOWER", timeStampL); - if (status != ZE_RESULT_SUCCESS) { - return status; - } - - // timestamp from PMT is in milli seconds - pBandwidth->timestamp = packInto64Bit(timeStampH, timeStampL) * milliSecsToMicroSecs; + // Get timestamp + pBandwidth->timestamp = SysmanDevice::getSysmanTimestamp(); return status; } diff --git a/level_zero/sysman/test/unit_tests/sources/shared/linux/product_helper/sysman_product_helper_memory_tests.cpp b/level_zero/sysman/test/unit_tests/sources/shared/linux/product_helper/sysman_product_helper_memory_tests.cpp index ed9cfb7f1c..58289cb9b7 100644 --- a/level_zero/sysman/test/unit_tests/sources/shared/linux/product_helper/sysman_product_helper_memory_tests.cpp +++ b/level_zero/sysman/test/unit_tests/sources/shared/linux/product_helper/sysman_product_helper_memory_tests.cpp @@ -1019,23 +1019,17 @@ HWTEST2_F(SysmanProductHelperMemoryTest, GivenSysmanProductHelperInstanceWhenCal memcpy(buf, validOobmsmGuid.data(), count); } else if (fd == 6) { switch (offset) { - case 368: + case 376: count = (readFailCount == 2) ? -1 : sizeof(uint32_t); break; - case 372: + case 380: count = (readFailCount == 3) ? -1 : sizeof(uint32_t); break; - case 376: + case 392: count = (readFailCount == 4) ? -1 : sizeof(uint32_t); break; - case 380: - count = (readFailCount == 5) ? -1 : sizeof(uint32_t); - break; - case 392: - count = (readFailCount == 6) ? -1 : sizeof(uint32_t); - break; case 396: - count = (readFailCount == 7) ? -1 : sizeof(uint32_t); + count = (readFailCount == 5) ? -1 : sizeof(uint32_t); break; case 3688: memcpy(buf, &mockMsuBitMask, count); @@ -1053,7 +1047,7 @@ HWTEST2_F(SysmanProductHelperMemoryTest, GivenSysmanProductHelperInstanceWhenCal uint32_t subdeviceId = 0; auto pSysmanProductHelper = L0::Sysman::SysmanProductHelper::create(defaultHwInfo->platform.eProductFamily); zes_mem_bandwidth_t memBandwidth; - while (readFailCount <= 7) { + while (readFailCount <= 5) { EXPECT_EQ(ZE_RESULT_ERROR_NOT_AVAILABLE, pSysmanProductHelper->getMemoryBandwidth(&memBandwidth, pLinuxSysmanImp, subdeviceId)); readFailCount++; } @@ -1099,8 +1093,6 @@ HWTEST2_F(SysmanProductHelperMemoryTest, GivenSysmanProductHelperInstanceWhenCal static uint32_t writeCounterLower32Bit = 0xa; static uint32_t writeCounterUpper64Bit = 0xf; static uint32_t writeCounterLower64Bit = 0xb; - static uint32_t timeStampUpper = 0xab; - static uint32_t timeStampLower = 0xcd; static uint32_t vramBandwidth = 0x6abc0000; VariableBackup mockReadLink(&NEO::SysCalls::sysCallsReadlink, &mockReadLinkSuccess); @@ -1119,12 +1111,6 @@ HWTEST2_F(SysmanProductHelperMemoryTest, GivenSysmanProductHelperInstanceWhenCal memcpy(buf, validOobmsmGuid.data(), count); } else if (fd == 6) { switch (offset) { - case 368: - memcpy(buf, &timeStampLower, count); - break; - case 372: - memcpy(buf, &timeStampUpper, count); - break; case 376: memcpy(buf, &readCounterUpper32Bit, count); break; @@ -1181,13 +1167,12 @@ HWTEST2_F(SysmanProductHelperMemoryTest, GivenSysmanProductHelperInstanceWhenCal uint64_t outputWriteCounter64Bit = packInto64Bit(writeCounterUpper64Bit, writeCounterLower64Bit) * 64; EXPECT_EQ((outputWriteCounter32Bit + outputWriteCounter64Bit), memBandwidth.writeCounter); - uint64_t outputTimestamp = packInto64Bit(timeStampUpper, timeStampLower) * milliSecsToMicroSecs; - EXPECT_EQ(outputTimestamp, memBandwidth.timestamp); - uint64_t outputMaxBandwidth = vramBandwidth; outputMaxBandwidth = outputMaxBandwidth >> 16; outputMaxBandwidth = static_cast(outputMaxBandwidth) * megaBytesToBytes * 100; EXPECT_EQ(outputMaxBandwidth, memBandwidth.maxBandwidth); + + EXPECT_GT(memBandwidth.timestamp, 0u); } } // namespace ult diff --git a/level_zero/sysman/test/unit_tests/sources/shared/windows/product_helper/sysman_product_helper_memory_tests.cpp b/level_zero/sysman/test/unit_tests/sources/shared/windows/product_helper/sysman_product_helper_memory_tests.cpp index c3f2d8a307..78ab0402df 100644 --- a/level_zero/sysman/test/unit_tests/sources/shared/windows/product_helper/sysman_product_helper_memory_tests.cpp +++ b/level_zero/sysman/test/unit_tests/sources/shared/windows/product_helper/sysman_product_helper_memory_tests.cpp @@ -118,14 +118,6 @@ HWTEST2_F(SysmanDeviceMemoryHelperFixture, GivenValidMemoryHandleWhenGettingBand *lpBytesReturned = 8; *static_cast(lpOutBuffer) = 131072; return true; - case 92: - *lpBytesReturned = 8; - *static_cast(lpOutBuffer) = mockMemoryBandwidthTimestamp; - return true; - case 93: - *lpBytesReturned = 8; - *static_cast(lpOutBuffer) = 0; - return true; default: *lpBytesReturned = 8; if (readRequest->offset % 2 == 0) { @@ -147,12 +139,12 @@ HWTEST2_F(SysmanDeviceMemoryHelperFixture, GivenValidMemoryHandleWhenGettingBand EXPECT_EQ(bandwidth.maxBandwidth, static_cast(mockMemoryMaxBandwidth * megaBytesToBytes * 100)); EXPECT_EQ(bandwidth.readCounter, (6 * mockPmtBandWidthVariableBackupValue * 32) + (6 * mockPmtBandWidthVariableBackupValue * 64)); EXPECT_EQ(bandwidth.writeCounter, (4 * mockPmtBandWidthVariableBackupValue * 32) + (4 * mockPmtBandWidthVariableBackupValue * 64)); - EXPECT_EQ(bandwidth.timestamp, mockMemoryBandwidthTimestamp * milliSecsToMicroSecs); + EXPECT_GT(bandwidth.timestamp, 0u); } } HWTEST2_F(SysmanDeviceMemoryHelperFixture, GivenValidMemoryHandleWhenGettingBandwidthCoveringNegativePathsThenCallFails, IsBMG) { - static uint32_t count = 8; + static uint32_t count = 6; VariableBackup psysCallsCreateFile(&NEO::SysCalls::sysCallsCreateFile, [](LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile) -> HANDLE { return reinterpret_cast(static_cast(0x7)); }); @@ -167,30 +159,22 @@ HWTEST2_F(SysmanDeviceMemoryHelperFixture, GivenValidMemoryHandleWhenGettingBand *lpBytesReturned = 8; *static_cast(lpOutBuffer) = 131072; return count == 2 ? false : true; - case 92: - *lpBytesReturned = 8; - *static_cast(lpOutBuffer) = 1230000; - return count == 4 ? false : true; - case 93: - *lpBytesReturned = 8; - *static_cast(lpOutBuffer) = 0; - return count == 3 ? false : true; case 94: *lpBytesReturned = 8; *static_cast(lpOutBuffer) = 0; - return count == 5 ? false : true; + return count == 3 ? false : true; case 95: *lpBytesReturned = 8; *static_cast(lpOutBuffer) = 10000000; - return count == 6 ? false : true; + return count == 4 ? false : true; case 110: *lpBytesReturned = 8; *static_cast(lpOutBuffer) = 0; - return count == 7 ? false : true; + return count == 5 ? false : true; case 111: *lpBytesReturned = 8; *static_cast(lpOutBuffer) = 10000000; - return count == 8 ? false : true; + return count == 6 ? false : true; default: *lpBytesReturned = 8; if (readRequest->offset % 2 == 0) {