mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-03 14:55:24 +08:00
feature: Add 3-level wait scheme with tpause intrinsic
Related-To: NEO-14336 Signed-off-by: Lukasz Jobczyk <lukasz.jobczyk@intel.com>
This commit is contained in:
committed by
Compute-Runtime-Automation
parent
4e9afb32e6
commit
8a85a96ed2
@@ -21,7 +21,8 @@ namespace NEO {
|
||||
extern unsigned int testCaseMaxTimeInMs;
|
||||
|
||||
void BaseUltConfigListener::OnTestStart(const ::testing::TestInfo &) {
|
||||
WaitUtils::waitpkgUse = false;
|
||||
WaitUtils::waitpkgUse = WaitUtils::WaitpkgUse::uninitialized;
|
||||
WaitUtils::waitPkgThresholdInMicroSeconds = WaitUtils::defaultWaitPkgThresholdInMicroSeconds;
|
||||
WaitUtils::waitpkgCounterValue = WaitUtils::defaultCounterValue;
|
||||
WaitUtils::waitpkgControlValue = WaitUtils::defaultControlValue;
|
||||
WaitUtils::waitCount = WaitUtils::defaultWaitCount;
|
||||
|
||||
@@ -377,6 +377,7 @@ SkipFlushingEventsOnGetStatusCalls = 0
|
||||
EnableWaitpkg = -1
|
||||
WaitpkgControlValue = -1
|
||||
WaitpkgCounterValue = -1
|
||||
WaitpkgThreshold = -1
|
||||
AllowUnrestrictedSize = 0
|
||||
ForceDefaultThreadArbitrationPolicyIfNotSpecified = 0
|
||||
DoNotFreeResources = 0
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2020-2024 Intel Corporation
|
||||
* Copyright (C) 2020-2025 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -30,6 +30,8 @@ std::atomic<uint32_t> umonitorCounter(0u);
|
||||
|
||||
std::atomic<uint32_t> rdtscCounter(0u);
|
||||
|
||||
std::atomic_uint32_t tpauseCounter{};
|
||||
|
||||
volatile TagAddressType *pauseAddress = nullptr;
|
||||
TaskCountType pauseValue = 0u;
|
||||
uint32_t pauseOffset = 0u;
|
||||
@@ -68,6 +70,11 @@ void pause() {
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t tpause(uint32_t control, uint64_t counter) {
|
||||
CpuIntrinsicsTests::tpauseCounter++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned char umwait(unsigned int ctrl, uint64_t counter) {
|
||||
CpuIntrinsicsTests::lastUmwaitControl = ctrl;
|
||||
CpuIntrinsicsTests::lastUmwaitCounter = counter;
|
||||
|
||||
@@ -1007,7 +1007,7 @@ HWTEST_F(DrmDirectSubmissionTest, givenDirectSubmissionNewResourceTlbFlushZeroAn
|
||||
HWCMDTEST_F(IGFX_XE_HP_CORE, DrmDirectSubmissionTest, givenMultipleActiveTilesWhenWaitingForTagUpdateThenQueryAllActiveTiles) {
|
||||
using Dispatcher = RenderDispatcher<FamilyType>;
|
||||
|
||||
VariableBackup<bool> backupWaitpkgUse(&WaitUtils::waitpkgUse, false);
|
||||
VariableBackup<WaitUtils::WaitpkgUse> backupWaitpkgUse(&WaitUtils::waitpkgUse, WaitUtils::WaitpkgUse::noUse);
|
||||
VariableBackup<uint32_t> backupWaitCount(&WaitUtils::waitCount, 1);
|
||||
|
||||
MockDrmDirectSubmission<FamilyType, Dispatcher> directSubmission(*device->getDefaultEngine().commandStreamReceiver);
|
||||
@@ -1283,7 +1283,7 @@ HWTEST_F(DrmDirectSubmissionTest,
|
||||
HWTEST_F(DrmDirectSubmissionTest, givenGpuHangWhenWaitCalledThenGpuHangDetected) {
|
||||
using Dispatcher = RenderDispatcher<FamilyType>;
|
||||
|
||||
VariableBackup<bool> backupWaitpkgUse(&WaitUtils::waitpkgUse, false);
|
||||
VariableBackup<WaitUtils::WaitpkgUse> backupWaitpkgUse(&WaitUtils::waitpkgUse, WaitUtils::WaitpkgUse::noUse);
|
||||
VariableBackup<uint32_t> backupWaitCount(&WaitUtils::waitCount, 1);
|
||||
|
||||
MockDrmDirectSubmission<FamilyType, Dispatcher> directSubmission(*device->getDefaultEngine().commandStreamReceiver);
|
||||
|
||||
@@ -35,11 +35,11 @@ using WaitPredicateOnlyTest = Test<WaitPredicateOnlyFixture>;
|
||||
TEST_F(WaitPredicateOnlyTest, givenDefaultSettingsWhenNoPollAddressProvidedThenPauseDefaultTimeAndReturnFalse) {
|
||||
EXPECT_EQ(1u, WaitUtils::defaultWaitCount);
|
||||
|
||||
WaitUtils::init(false);
|
||||
WaitUtils::init(WaitUtils::WaitpkgUse::noUse);
|
||||
EXPECT_EQ(WaitUtils::defaultWaitCount, WaitUtils::waitCount);
|
||||
|
||||
uint32_t oldCount = CpuIntrinsicsTests::pauseCounter.load();
|
||||
bool ret = WaitUtils::waitFunction(nullptr, 0u);
|
||||
bool ret = WaitUtils::waitFunction(nullptr, 0u, 0);
|
||||
EXPECT_FALSE(ret);
|
||||
EXPECT_EQ(oldCount + WaitUtils::waitCount, CpuIntrinsicsTests::pauseCounter);
|
||||
}
|
||||
@@ -48,37 +48,37 @@ TEST_F(WaitPredicateOnlyTest, givenDebugFlagOverridesWhenNoPollAddressProvidedTh
|
||||
uint32_t count = 10u;
|
||||
debugManager.flags.WaitLoopCount.set(count);
|
||||
|
||||
WaitUtils::init(false);
|
||||
WaitUtils::init(WaitUtils::WaitpkgUse::noUse);
|
||||
EXPECT_EQ(count, WaitUtils::waitCount);
|
||||
|
||||
uint32_t oldCount = CpuIntrinsicsTests::pauseCounter.load();
|
||||
bool ret = WaitUtils::waitFunction(nullptr, 0u);
|
||||
bool ret = WaitUtils::waitFunction(nullptr, 0u, 0);
|
||||
EXPECT_FALSE(ret);
|
||||
EXPECT_EQ(oldCount + count, CpuIntrinsicsTests::pauseCounter);
|
||||
}
|
||||
|
||||
TEST_F(WaitPredicateOnlyTest, givenDefaultSettingsWhenPollAddressProvidedDoesNotMeetCriteriaThenPauseDefaultTimeAndReturnFalse) {
|
||||
WaitUtils::init(false);
|
||||
WaitUtils::init(WaitUtils::WaitpkgUse::noUse);
|
||||
EXPECT_EQ(WaitUtils::defaultWaitCount, WaitUtils::waitCount);
|
||||
|
||||
volatile TagAddressType pollValue = 1u;
|
||||
TaskCountType expectedValue = 3;
|
||||
|
||||
uint32_t oldCount = CpuIntrinsicsTests::pauseCounter.load();
|
||||
bool ret = WaitUtils::waitFunction(&pollValue, expectedValue);
|
||||
bool ret = WaitUtils::waitFunction(&pollValue, expectedValue, 0);
|
||||
EXPECT_FALSE(ret);
|
||||
EXPECT_EQ(oldCount + WaitUtils::waitCount, CpuIntrinsicsTests::pauseCounter);
|
||||
}
|
||||
|
||||
TEST_F(WaitPredicateOnlyTest, givenDefaultSettingsWhenPollAddressProvidedMeetsCriteriaThenPauseDefaultTimeAndReturnTrue) {
|
||||
WaitUtils::init(false);
|
||||
WaitUtils::init(WaitUtils::WaitpkgUse::noUse);
|
||||
EXPECT_EQ(WaitUtils::defaultWaitCount, WaitUtils::waitCount);
|
||||
|
||||
volatile TagAddressType pollValue = 3u;
|
||||
TaskCountType expectedValue = 1;
|
||||
|
||||
uint32_t oldCount = CpuIntrinsicsTests::pauseCounter.load();
|
||||
bool ret = WaitUtils::waitFunction(&pollValue, expectedValue);
|
||||
bool ret = WaitUtils::waitFunction(&pollValue, expectedValue, 0);
|
||||
EXPECT_TRUE(ret);
|
||||
EXPECT_EQ(oldCount + WaitUtils::waitCount, CpuIntrinsicsTests::pauseCounter);
|
||||
}
|
||||
@@ -87,14 +87,14 @@ TEST_F(WaitPredicateOnlyTest, givenDebugFlagSetZeroWhenPollAddressProvidedMeetsC
|
||||
uint32_t count = 0u;
|
||||
debugManager.flags.WaitLoopCount.set(count);
|
||||
|
||||
WaitUtils::init(false);
|
||||
WaitUtils::init(WaitUtils::WaitpkgUse::noUse);
|
||||
EXPECT_EQ(count, WaitUtils::waitCount);
|
||||
|
||||
volatile TagAddressType pollValue = 3u;
|
||||
TaskCountType expectedValue = 1;
|
||||
|
||||
uint32_t oldCount = CpuIntrinsicsTests::pauseCounter.load();
|
||||
bool ret = WaitUtils::waitFunction(&pollValue, expectedValue);
|
||||
bool ret = WaitUtils::waitFunction(&pollValue, expectedValue, 0);
|
||||
EXPECT_TRUE(ret);
|
||||
EXPECT_EQ(oldCount + WaitUtils::waitCount, CpuIntrinsicsTests::pauseCounter);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ struct WaitPkgFixture {
|
||||
|
||||
backupCpuInfo = std::make_unique<VariableBackup<MockCpuInfo>>(mockCpuInfo);
|
||||
backupWaitpkgSupport = std::make_unique<VariableBackup<bool>>(&WaitUtils::waitpkgSupport);
|
||||
backupWaitpkgUse = std::make_unique<VariableBackup<bool>>(&WaitUtils::waitpkgUse);
|
||||
backupWaitpkgUse = std::make_unique<VariableBackup<WaitUtils::WaitpkgUse>>(&WaitUtils::waitpkgUse);
|
||||
backupWaitpkgCounter = std::make_unique<VariableBackup<uint64_t>>(&WaitUtils::waitpkgCounterValue);
|
||||
backupWaitpkgControl = std::make_unique<VariableBackup<uint32_t>>(&WaitUtils::waitpkgControlValue);
|
||||
backupWaitCount = std::make_unique<VariableBackup<uint32_t>>(&WaitUtils::waitCount);
|
||||
@@ -55,7 +55,7 @@ struct WaitPkgFixture {
|
||||
std::unique_ptr<VariableBackup<MockCpuInfo>> backupCpuInfo;
|
||||
std::unique_ptr<VariableBackup<CpuIdFuncT>> backupCpuIdFunc;
|
||||
std::unique_ptr<VariableBackup<bool>> backupWaitpkgSupport;
|
||||
std::unique_ptr<VariableBackup<bool>> backupWaitpkgUse;
|
||||
std::unique_ptr<VariableBackup<WaitUtils::WaitpkgUse>> backupWaitpkgUse;
|
||||
std::unique_ptr<VariableBackup<uint64_t>> backupWaitpkgCounter;
|
||||
std::unique_ptr<VariableBackup<uint32_t>> backupWaitpkgControl;
|
||||
std::unique_ptr<VariableBackup<uint32_t>> backupWaitCount;
|
||||
@@ -74,22 +74,25 @@ extern std::atomic<uint32_t> umonitorCounter;
|
||||
|
||||
extern std::atomic<uint32_t> rdtscCounter;
|
||||
|
||||
extern std::atomic_uint32_t tpauseCounter;
|
||||
|
||||
extern uint64_t rdtscRetValue;
|
||||
extern unsigned char umwaitRetValue;
|
||||
|
||||
extern std::function<void()> controlUmwait;
|
||||
} // namespace CpuIntrinsicsTests
|
||||
|
||||
template <int32_t waitpkgUse>
|
||||
struct WaitPkgEnabledFixture : public WaitPkgFixture {
|
||||
void setUp() {
|
||||
WaitPkgFixture::setUp();
|
||||
|
||||
debugManager.flags.EnableWaitpkg.set(1);
|
||||
debugManager.flags.EnableWaitpkg.set(waitpkgUse);
|
||||
|
||||
CpuInfo::cpuidFunc = mockCpuidEnableAll;
|
||||
WaitUtils::waitpkgSupport = true;
|
||||
|
||||
WaitUtils::init(false);
|
||||
WaitUtils::init(WaitUtils::WaitpkgUse::noUse);
|
||||
|
||||
CpuIntrinsicsTests::lastUmwaitCounter = 0;
|
||||
CpuIntrinsicsTests::lastUmwaitControl = 0;
|
||||
@@ -97,6 +100,7 @@ struct WaitPkgEnabledFixture : public WaitPkgFixture {
|
||||
CpuIntrinsicsTests::lastUmonitorPtr = 0;
|
||||
CpuIntrinsicsTests::umonitorCounter = 0;
|
||||
CpuIntrinsicsTests::rdtscCounter = 0;
|
||||
CpuIntrinsicsTests::tpauseCounter = 0;
|
||||
|
||||
backupCpuIntrinsicsRdtscRetValue = std::make_unique<VariableBackup<uint64_t>>(&CpuIntrinsicsTests::rdtscRetValue);
|
||||
backupCpuIntrinsicsUmwaitRetValue = std::make_unique<VariableBackup<unsigned char>>(&CpuIntrinsicsTests::umwaitRetValue);
|
||||
@@ -109,7 +113,8 @@ struct WaitPkgEnabledFixture : public WaitPkgFixture {
|
||||
};
|
||||
|
||||
using WaitPkgTest = Test<WaitPkgFixture>;
|
||||
using WaitPkgEnabledTest = Test<WaitPkgEnabledFixture>;
|
||||
using WaitPkgEnabledTest = Test<WaitPkgEnabledFixture<1>>;
|
||||
using WaitPkgTpauseEnabledTest = Test<WaitPkgEnabledFixture<2>>;
|
||||
|
||||
TEST_F(WaitPkgTest, givenDefaultSettingsAndWaitpkgSupportTrueWhenWaitInitializedThenWaitPkgNotEnabled) {
|
||||
CpuInfo::cpuidFunc = mockCpuidEnableAll;
|
||||
@@ -117,17 +122,18 @@ TEST_F(WaitPkgTest, givenDefaultSettingsAndWaitpkgSupportTrueWhenWaitInitialized
|
||||
EXPECT_EQ(WaitUtils::defaultWaitCount, WaitUtils::waitCount);
|
||||
EXPECT_EQ(16000u, WaitUtils::waitpkgCounterValue);
|
||||
EXPECT_EQ(0u, WaitUtils::waitpkgControlValue);
|
||||
EXPECT_FALSE(WaitUtils::waitpkgUse);
|
||||
EXPECT_EQ(WaitUtils::waitpkgUse, WaitUtils::WaitpkgUse::uninitialized);
|
||||
EXPECT_EQ(1, WaitUtils::waitPkgThresholdInMicroSeconds);
|
||||
|
||||
EXPECT_EQ(expectedWaitpkgSupport, WaitUtils::waitpkgSupport);
|
||||
|
||||
WaitUtils::waitpkgSupport = true;
|
||||
|
||||
WaitUtils::init(false);
|
||||
WaitUtils::init(WaitUtils::WaitpkgUse::noUse);
|
||||
EXPECT_EQ(WaitUtils::defaultWaitCount, WaitUtils::waitCount);
|
||||
EXPECT_EQ(16000u, WaitUtils::waitpkgCounterValue);
|
||||
EXPECT_EQ(0u, WaitUtils::waitpkgControlValue);
|
||||
EXPECT_FALSE(WaitUtils::waitpkgUse);
|
||||
EXPECT_EQ(WaitUtils::waitpkgUse, WaitUtils::WaitpkgUse::noUse);
|
||||
}
|
||||
|
||||
TEST_F(WaitPkgTest, givenEnabledWaitPkgSettingsAndWaitpkgSupportFalseWhenWaitInitializedThenWaitPkgNotEnabled) {
|
||||
@@ -135,11 +141,12 @@ TEST_F(WaitPkgTest, givenEnabledWaitPkgSettingsAndWaitpkgSupportFalseWhenWaitIni
|
||||
|
||||
debugManager.flags.EnableWaitpkg.set(1);
|
||||
|
||||
WaitUtils::init(false);
|
||||
WaitUtils::init(WaitUtils::WaitpkgUse::noUse);
|
||||
EXPECT_EQ(WaitUtils::defaultWaitCount, WaitUtils::waitCount);
|
||||
EXPECT_EQ(16000u, WaitUtils::waitpkgCounterValue);
|
||||
EXPECT_EQ(0u, WaitUtils::waitpkgControlValue);
|
||||
EXPECT_FALSE(WaitUtils::waitpkgUse);
|
||||
EXPECT_EQ(WaitUtils::waitpkgUse, WaitUtils::WaitpkgUse::noUse);
|
||||
EXPECT_EQ(1, WaitUtils::waitPkgThresholdInMicroSeconds);
|
||||
}
|
||||
|
||||
TEST_F(WaitPkgTest, givenDisabledWaitPkgSettingsAndWaitpkgSupportTrueWhenWaitInitializedThenWaitPkgNotEnabled) {
|
||||
@@ -147,11 +154,12 @@ TEST_F(WaitPkgTest, givenDisabledWaitPkgSettingsAndWaitpkgSupportTrueWhenWaitIni
|
||||
|
||||
debugManager.flags.EnableWaitpkg.set(0);
|
||||
|
||||
WaitUtils::init(false);
|
||||
WaitUtils::init(WaitUtils::WaitpkgUse::noUse);
|
||||
EXPECT_EQ(WaitUtils::defaultWaitCount, WaitUtils::waitCount);
|
||||
EXPECT_EQ(16000u, WaitUtils::waitpkgCounterValue);
|
||||
EXPECT_EQ(0u, WaitUtils::waitpkgControlValue);
|
||||
EXPECT_FALSE(WaitUtils::waitpkgUse);
|
||||
EXPECT_EQ(WaitUtils::waitpkgUse, WaitUtils::WaitpkgUse::noUse);
|
||||
EXPECT_EQ(1, WaitUtils::waitPkgThresholdInMicroSeconds);
|
||||
}
|
||||
|
||||
TEST_F(WaitPkgTest, givenEnabledWaitPkgSettingsAndWaitpkgSupportTrueWhenWaitInitializedAndCpuDoesNotSupportOperandThenWaitPkgNotEnabled) {
|
||||
@@ -161,11 +169,12 @@ TEST_F(WaitPkgTest, givenEnabledWaitPkgSettingsAndWaitpkgSupportTrueWhenWaitInit
|
||||
|
||||
debugManager.flags.EnableWaitpkg.set(1);
|
||||
|
||||
WaitUtils::init(false);
|
||||
WaitUtils::init(WaitUtils::WaitpkgUse::noUse);
|
||||
EXPECT_EQ(WaitUtils::defaultWaitCount, WaitUtils::waitCount);
|
||||
EXPECT_EQ(16000u, WaitUtils::waitpkgCounterValue);
|
||||
EXPECT_EQ(0u, WaitUtils::waitpkgControlValue);
|
||||
EXPECT_FALSE(WaitUtils::waitpkgUse);
|
||||
EXPECT_EQ(WaitUtils::waitpkgUse, WaitUtils::WaitpkgUse::noUse);
|
||||
EXPECT_EQ(1, WaitUtils::waitPkgThresholdInMicroSeconds);
|
||||
}
|
||||
|
||||
TEST_F(WaitPkgTest, givenEnabledWaitPkgSettingsAndWaitpkgSupportTrueWhenWaitInitializedAndCpuSupportsOperandThenWaitPkgEnabled) {
|
||||
@@ -175,12 +184,46 @@ TEST_F(WaitPkgTest, givenEnabledWaitPkgSettingsAndWaitpkgSupportTrueWhenWaitInit
|
||||
|
||||
debugManager.flags.EnableWaitpkg.set(1);
|
||||
|
||||
WaitUtils::init(false);
|
||||
WaitUtils::init(WaitUtils::WaitpkgUse::noUse);
|
||||
|
||||
EXPECT_EQ(0u, WaitUtils::waitCount);
|
||||
EXPECT_EQ(16000u, WaitUtils::waitpkgCounterValue);
|
||||
EXPECT_EQ(0u, WaitUtils::waitpkgControlValue);
|
||||
EXPECT_TRUE(WaitUtils::waitpkgUse);
|
||||
EXPECT_EQ(WaitUtils::waitpkgUse, WaitUtils::WaitpkgUse::umonitorAndUmwait);
|
||||
EXPECT_EQ(1, WaitUtils::waitPkgThresholdInMicroSeconds);
|
||||
}
|
||||
|
||||
TEST_F(WaitPkgTest, givenEnabledWaitPkgSetToTpauseAndWaitpkgSupportTrueWhenWaitInitializedAndCpuSupportsOperandThenWaitPkgEnabled) {
|
||||
CpuInfo::cpuidFunc = mockCpuidEnableAll;
|
||||
|
||||
WaitUtils::waitpkgSupport = true;
|
||||
|
||||
debugManager.flags.EnableWaitpkg.set(2);
|
||||
|
||||
WaitUtils::init(WaitUtils::WaitpkgUse::noUse);
|
||||
|
||||
EXPECT_EQ(1u, WaitUtils::waitCount);
|
||||
EXPECT_EQ(16000u, WaitUtils::waitpkgCounterValue);
|
||||
EXPECT_EQ(0u, WaitUtils::waitpkgControlValue);
|
||||
EXPECT_EQ(WaitUtils::waitpkgUse, WaitUtils::WaitpkgUse::tpause);
|
||||
EXPECT_EQ(1, WaitUtils::waitPkgThresholdInMicroSeconds);
|
||||
}
|
||||
|
||||
TEST_F(WaitPkgTest, givenEnabledWaitPkgSetToTpauseAndWaitpkgThresholdAndWaitpkgSupportTrueWhenWaitInitializedAndCpuSupportsOperandThenWaitPkgEnabled) {
|
||||
CpuInfo::cpuidFunc = mockCpuidEnableAll;
|
||||
|
||||
WaitUtils::waitpkgSupport = true;
|
||||
|
||||
debugManager.flags.EnableWaitpkg.set(2);
|
||||
debugManager.flags.WaitpkgThreshold.set(56789);
|
||||
|
||||
WaitUtils::init(WaitUtils::WaitpkgUse::noUse);
|
||||
|
||||
EXPECT_EQ(1u, WaitUtils::waitCount);
|
||||
EXPECT_EQ(16000u, WaitUtils::waitpkgCounterValue);
|
||||
EXPECT_EQ(0u, WaitUtils::waitpkgControlValue);
|
||||
EXPECT_EQ(WaitUtils::waitpkgUse, WaitUtils::WaitpkgUse::tpause);
|
||||
EXPECT_EQ(56789, WaitUtils::waitPkgThresholdInMicroSeconds);
|
||||
}
|
||||
|
||||
TEST_F(WaitPkgTest, givenEnabledSetToTrueAndWaitpkgSupportTrueWhenWaitInitializedAndCpuSupportsOperandThenWaitPkgEnabled) {
|
||||
@@ -188,12 +231,27 @@ TEST_F(WaitPkgTest, givenEnabledSetToTrueAndWaitpkgSupportTrueWhenWaitInitialize
|
||||
|
||||
WaitUtils::waitpkgSupport = true;
|
||||
|
||||
WaitUtils::init(true);
|
||||
WaitUtils::init(WaitUtils::WaitpkgUse::umonitorAndUmwait);
|
||||
|
||||
EXPECT_EQ(0u, WaitUtils::waitCount);
|
||||
EXPECT_EQ(16000u, WaitUtils::waitpkgCounterValue);
|
||||
EXPECT_EQ(0u, WaitUtils::waitpkgControlValue);
|
||||
EXPECT_TRUE(WaitUtils::waitpkgUse);
|
||||
EXPECT_EQ(WaitUtils::waitpkgUse, WaitUtils::WaitpkgUse::umonitorAndUmwait);
|
||||
EXPECT_EQ(1, WaitUtils::waitPkgThresholdInMicroSeconds);
|
||||
}
|
||||
|
||||
TEST_F(WaitPkgTest, givenEnabledSetToTpauseAndWaitpkgSupportTrueWhenWaitInitializedAndCpuSupportsOperandThenWaitPkgEnabled) {
|
||||
CpuInfo::cpuidFunc = mockCpuidEnableAll;
|
||||
|
||||
WaitUtils::waitpkgSupport = true;
|
||||
|
||||
WaitUtils::init(WaitUtils::WaitpkgUse::tpause);
|
||||
|
||||
EXPECT_EQ(1u, WaitUtils::waitCount);
|
||||
EXPECT_EQ(16000u, WaitUtils::waitpkgCounterValue);
|
||||
EXPECT_EQ(0u, WaitUtils::waitpkgControlValue);
|
||||
EXPECT_EQ(WaitUtils::waitpkgUse, WaitUtils::WaitpkgUse::tpause);
|
||||
EXPECT_EQ(1, WaitUtils::waitPkgThresholdInMicroSeconds);
|
||||
}
|
||||
|
||||
TEST_F(WaitPkgTest, givenFullyEnabledWaitPkgAndOverrideCounterValueWhenWaitInitializedThenNewCounterValueSet) {
|
||||
@@ -204,11 +262,12 @@ TEST_F(WaitPkgTest, givenFullyEnabledWaitPkgAndOverrideCounterValueWhenWaitIniti
|
||||
debugManager.flags.EnableWaitpkg.set(1);
|
||||
debugManager.flags.WaitpkgCounterValue.set(1234);
|
||||
|
||||
WaitUtils::init(false);
|
||||
WaitUtils::init(WaitUtils::WaitpkgUse::noUse);
|
||||
EXPECT_EQ(0u, WaitUtils::waitCount);
|
||||
EXPECT_EQ(1234u, WaitUtils::waitpkgCounterValue);
|
||||
EXPECT_EQ(0u, WaitUtils::waitpkgControlValue);
|
||||
EXPECT_TRUE(WaitUtils::waitpkgUse);
|
||||
EXPECT_EQ(WaitUtils::waitpkgUse, WaitUtils::WaitpkgUse::umonitorAndUmwait);
|
||||
EXPECT_EQ(1, WaitUtils::waitPkgThresholdInMicroSeconds);
|
||||
}
|
||||
|
||||
TEST_F(WaitPkgTest, givenFullyEnabledWaitPkgAndOverrideControlValueWhenWaitInitializedThenNewControlValueSet) {
|
||||
@@ -219,11 +278,12 @@ TEST_F(WaitPkgTest, givenFullyEnabledWaitPkgAndOverrideControlValueWhenWaitIniti
|
||||
debugManager.flags.EnableWaitpkg.set(1);
|
||||
debugManager.flags.WaitpkgControlValue.set(1);
|
||||
|
||||
WaitUtils::init(false);
|
||||
WaitUtils::init(WaitUtils::WaitpkgUse::noUse);
|
||||
EXPECT_EQ(0u, WaitUtils::waitCount);
|
||||
EXPECT_EQ(16000u, WaitUtils::waitpkgCounterValue);
|
||||
EXPECT_EQ(1u, WaitUtils::waitpkgControlValue);
|
||||
EXPECT_TRUE(WaitUtils::waitpkgUse);
|
||||
EXPECT_EQ(WaitUtils::waitpkgUse, WaitUtils::WaitpkgUse::umonitorAndUmwait);
|
||||
EXPECT_EQ(1, WaitUtils::waitPkgThresholdInMicroSeconds);
|
||||
}
|
||||
|
||||
TEST_F(WaitPkgTest, givenEnabledWaitPkgSettingsAndWaitpkgSupportTrueWhenWaitInitializedTwiceThenInitOnce) {
|
||||
@@ -231,21 +291,23 @@ TEST_F(WaitPkgTest, givenEnabledWaitPkgSettingsAndWaitpkgSupportTrueWhenWaitInit
|
||||
|
||||
WaitUtils::waitpkgSupport = true;
|
||||
|
||||
WaitUtils::init(true);
|
||||
WaitUtils::init(WaitUtils::WaitpkgUse::umonitorAndUmwait);
|
||||
|
||||
EXPECT_EQ(0u, WaitUtils::waitCount);
|
||||
EXPECT_EQ(16000u, WaitUtils::waitpkgCounterValue);
|
||||
EXPECT_EQ(0u, WaitUtils::waitpkgControlValue);
|
||||
EXPECT_TRUE(WaitUtils::waitpkgUse);
|
||||
EXPECT_EQ(WaitUtils::waitpkgUse, WaitUtils::WaitpkgUse::umonitorAndUmwait);
|
||||
EXPECT_EQ(1, WaitUtils::waitPkgThresholdInMicroSeconds);
|
||||
|
||||
debugManager.flags.WaitpkgControlValue.set(1);
|
||||
|
||||
WaitUtils::init(true);
|
||||
WaitUtils::init(WaitUtils::WaitpkgUse::umonitorAndUmwait);
|
||||
|
||||
EXPECT_EQ(0u, WaitUtils::waitCount);
|
||||
EXPECT_EQ(16000u, WaitUtils::waitpkgCounterValue);
|
||||
EXPECT_EQ(0u, WaitUtils::waitpkgControlValue);
|
||||
EXPECT_TRUE(WaitUtils::waitpkgUse);
|
||||
EXPECT_EQ(WaitUtils::waitpkgUse, WaitUtils::WaitpkgUse::umonitorAndUmwait);
|
||||
EXPECT_EQ(1, WaitUtils::waitPkgThresholdInMicroSeconds);
|
||||
}
|
||||
|
||||
TEST_F(WaitPkgEnabledTest, givenMonitoredAddressChangedWhenAddressMatchesPredicateValueThenWaitReturnsTrue) {
|
||||
@@ -259,7 +321,7 @@ TEST_F(WaitPkgEnabledTest, givenMonitoredAddressChangedWhenAddressMatchesPredica
|
||||
pollValue = 1;
|
||||
};
|
||||
|
||||
bool ret = WaitUtils::waitFunction(&pollValue, expectedValue);
|
||||
bool ret = WaitUtils::waitFunction(&pollValue, expectedValue, 0);
|
||||
EXPECT_TRUE(ret);
|
||||
|
||||
EXPECT_EQ(1u, CpuIntrinsicsTests::rdtscCounter);
|
||||
@@ -279,7 +341,7 @@ TEST_F(WaitPkgEnabledTest, givenMonitoredAddressNotChangesWhenMonitorTimeoutsThe
|
||||
CpuIntrinsicsTests::rdtscRetValue = 2500;
|
||||
CpuIntrinsicsTests::umwaitRetValue = 1;
|
||||
|
||||
bool ret = WaitUtils::waitFunction(&pollValue, expectedValue);
|
||||
bool ret = WaitUtils::waitFunction(&pollValue, expectedValue, 0);
|
||||
EXPECT_FALSE(ret);
|
||||
|
||||
EXPECT_EQ(1u, CpuIntrinsicsTests::rdtscCounter);
|
||||
@@ -299,7 +361,7 @@ TEST_F(WaitPkgEnabledTest, givenMonitoredAddressChangedWhenAddressNotMatchesPred
|
||||
CpuIntrinsicsTests::rdtscRetValue = 3700;
|
||||
CpuIntrinsicsTests::umwaitRetValue = 0;
|
||||
|
||||
bool ret = WaitUtils::waitFunction(&pollValue, expectedValue);
|
||||
bool ret = WaitUtils::waitFunction(&pollValue, expectedValue, 0);
|
||||
EXPECT_FALSE(ret);
|
||||
|
||||
EXPECT_EQ(1u, CpuIntrinsicsTests::rdtscCounter);
|
||||
@@ -311,3 +373,43 @@ TEST_F(WaitPkgEnabledTest, givenMonitoredAddressChangedWhenAddressNotMatchesPred
|
||||
EXPECT_EQ(WaitUtils::waitpkgControlValue, CpuIntrinsicsTests::lastUmwaitControl);
|
||||
EXPECT_EQ(1u, CpuIntrinsicsTests::umwaitCounter);
|
||||
}
|
||||
|
||||
TEST_F(WaitPkgEnabledTest, givenTimeElapsedSinceWaitStartedBelowThresholdWhenWaitThenDoNoTpause) {
|
||||
volatile TagAddressType pollValue = 0u;
|
||||
TaskCountType expectedValue = 1;
|
||||
int64_t timeElapsedSinceWaitStarted = 0u;
|
||||
EXPECT_EQ(CpuIntrinsicsTests::tpauseCounter, 0u);
|
||||
|
||||
WaitUtils::waitFunction(&pollValue, expectedValue, timeElapsedSinceWaitStarted);
|
||||
EXPECT_EQ(CpuIntrinsicsTests::tpauseCounter, 0u);
|
||||
}
|
||||
|
||||
TEST_F(WaitPkgEnabledTest, givenTimeElapsedSinceWaitStartedAboveThresholdWhenWaitThenDoNoTpause) {
|
||||
volatile TagAddressType pollValue = 0u;
|
||||
TaskCountType expectedValue = 1;
|
||||
int64_t timeElapsedSinceWaitStarted = 5000u;
|
||||
EXPECT_EQ(CpuIntrinsicsTests::tpauseCounter, 0u);
|
||||
|
||||
WaitUtils::waitFunction(&pollValue, expectedValue, timeElapsedSinceWaitStarted);
|
||||
EXPECT_EQ(CpuIntrinsicsTests::tpauseCounter, 0u);
|
||||
}
|
||||
|
||||
TEST_F(WaitPkgTpauseEnabledTest, givenTimeElapsedSinceWaitStartedBelowThresholdWhenWaitThenDoNoTpause) {
|
||||
volatile TagAddressType pollValue = 0u;
|
||||
TaskCountType expectedValue = 1;
|
||||
int64_t timeElapsedSinceWaitStarted = 0u;
|
||||
EXPECT_EQ(CpuIntrinsicsTests::tpauseCounter, 0u);
|
||||
|
||||
WaitUtils::waitFunction(&pollValue, expectedValue, timeElapsedSinceWaitStarted);
|
||||
EXPECT_EQ(CpuIntrinsicsTests::tpauseCounter, 0u);
|
||||
}
|
||||
|
||||
TEST_F(WaitPkgTpauseEnabledTest, givenTimeElapsedSinceWaitStartedAboveThresholdWhenWaitThenDoTpause) {
|
||||
volatile TagAddressType pollValue = 0u;
|
||||
TaskCountType expectedValue = 1;
|
||||
int64_t timeElapsedSinceWaitStarted = 5000u;
|
||||
EXPECT_EQ(CpuIntrinsicsTests::tpauseCounter, 0u);
|
||||
|
||||
WaitUtils::waitFunction(&pollValue, expectedValue, timeElapsedSinceWaitStarted);
|
||||
EXPECT_EQ(CpuIntrinsicsTests::tpauseCounter, 1u);
|
||||
}
|
||||
Reference in New Issue
Block a user