diff --git a/shared/source/helpers/gfx_core_helper_base.inl b/shared/source/helpers/gfx_core_helper_base.inl index 9154fbf182..f0ca231fa3 100644 --- a/shared/source/helpers/gfx_core_helper_base.inl +++ b/shared/source/helpers/gfx_core_helper_base.inl @@ -717,8 +717,8 @@ char const *GfxCoreHelperHw::getDefaultDeviceHierarchy() const { template uint64_t GfxCoreHelperHw::getGpuTimeStampInNS(uint64_t timeStamp, double resolution) const { - UNRECOVERABLE_IF(resolution > 127.0); - constexpr auto timestampMask = maxNBitValue(57); + auto numBitsForResolution = Math::log2(static_cast(resolution)) + 1u; + auto timestampMask = maxNBitValue(64 - numBitsForResolution); return static_cast(static_cast(timeStamp & timestampMask) * resolution); } diff --git a/shared/test/unit_test/helpers/gfx_core_helper_tests.cpp b/shared/test/unit_test/helpers/gfx_core_helper_tests.cpp index ae4bf6df12..4da1bc7cb1 100644 --- a/shared/test/unit_test/helpers/gfx_core_helper_tests.cpp +++ b/shared/test/unit_test/helpers/gfx_core_helper_tests.cpp @@ -149,14 +149,33 @@ HWTEST2_F(GfxCoreHelperTest, givenGfxCoreHelperWhenGettingThreadsPerEUConfigsThe EXPECT_EQ(0U, configs.size()); } -TEST_F(GfxCoreHelperTest, givenGfxCoreHelperWhenGetGpuTimeStampInNSIsCalledThenCorrectValueIsReturned) { +TEST_F(GfxCoreHelperTest, whenGetGpuTimeStampInNSIsCalledThenTimestampIsMaskedBasedOnResolution) { auto &gfxCoreHelper = getHelper(); + auto timeStamp0 = 0x00ff'ffff'ffff; auto timeStamp1 = 0xfe00'00ff'ffff'ffff; - auto resolution = 123.0; - auto result = static_cast(timeStamp0 * resolution); - EXPECT_EQ(result, gfxCoreHelper.getGpuTimeStampInNS(timeStamp0, resolution)); - EXPECT_EQ(result, gfxCoreHelper.getGpuTimeStampInNS(timeStamp1, resolution)); + auto timeStamp2 = 0xff00'00ff'ffff'ffff; + { + auto resolution = 135.0; + auto result = static_cast(timeStamp0 * resolution); + EXPECT_EQ(result, gfxCoreHelper.getGpuTimeStampInNS(timeStamp0, resolution)); + EXPECT_EQ(result, gfxCoreHelper.getGpuTimeStampInNS(timeStamp1, resolution)); + EXPECT_EQ(result, gfxCoreHelper.getGpuTimeStampInNS(timeStamp2, resolution)); + } + { + auto resolution = 128.0; + auto result = static_cast(timeStamp0 * resolution); + EXPECT_EQ(result, gfxCoreHelper.getGpuTimeStampInNS(timeStamp0, resolution)); + EXPECT_EQ(result, gfxCoreHelper.getGpuTimeStampInNS(timeStamp1, resolution)); + EXPECT_EQ(result, gfxCoreHelper.getGpuTimeStampInNS(timeStamp2, resolution)); + } + { + auto resolution = 127.0; + auto result = static_cast(timeStamp0 * resolution); + EXPECT_EQ(result, gfxCoreHelper.getGpuTimeStampInNS(timeStamp0, resolution)); + EXPECT_EQ(result, gfxCoreHelper.getGpuTimeStampInNS(timeStamp1, resolution)); + EXPECT_NE(result, gfxCoreHelper.getGpuTimeStampInNS(timeStamp2, resolution)); + } } TEST(DwordBuilderTest, WhenSettingNonMaskedBitsThenOnlySelectedBitAreSet) {