feature: add umonitor and umwait synchronization function

Related-To: NEO-9737

Signed-off-by: Zbigniew Zdanowicz <zbigniew.zdanowicz@intel.com>
This commit is contained in:
Zbigniew Zdanowicz
2024-01-18 11:39:39 +00:00
committed by Compute-Runtime-Automation
parent b266f1f3cc
commit b5f698e0c5
12 changed files with 211 additions and 47 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021-2023 Intel Corporation
* Copyright (C) 2021-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -18,8 +18,8 @@ constexpr uint64_t defaultCounterValue = 10000;
constexpr uint32_t defaultControlValue = 0;
constexpr bool defaultEnableWaitPkg = false;
uint64_t counterValue = defaultCounterValue;
uint32_t controlValue = defaultControlValue;
uint64_t waitpkgCounterValue = defaultCounterValue;
uint32_t waitpkgControlValue = defaultControlValue;
uint32_t waitCount = defaultWaitCount;
@@ -45,11 +45,11 @@ void init() {
int64_t overrideWaitPkgCounter = debugManager.flags.WaitpkgCounterValue.get();
if (overrideWaitPkgCounter != -1) {
counterValue = static_cast<uint64_t>(overrideWaitPkgCounter);
waitpkgCounterValue = static_cast<uint64_t>(overrideWaitPkgCounter);
}
int32_t overrideWaitPkgControl = debugManager.flags.WaitpkgControlValue.get();
if (overrideWaitPkgControl != -1) {
controlValue = static_cast<uint32_t>(overrideWaitPkgControl);
waitpkgControlValue = static_cast<uint32_t>(overrideWaitPkgControl);
}
int32_t overrideWaitCount = debugManager.flags.WaitLoopCount.get();

View File

@@ -1,5 +1,5 @@
/*
* Copyright (C) 2021-2023 Intel Corporation
* Copyright (C) 2021-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@@ -19,12 +19,21 @@ namespace WaitUtils {
constexpr uint32_t defaultWaitCount = 1u;
extern uint64_t counterValue;
extern uint32_t controlValue;
extern uint64_t waitpkgCounterValue;
extern uint32_t waitpkgControlValue;
extern uint32_t waitCount;
extern bool waitpkgSupport;
extern bool waitpkgUse;
inline bool monitorWait(volatile void const *monitorAddress, uint64_t counterModifier) {
uint64_t currentCounter = CpuIntrinsics::rdtsc();
currentCounter += (waitpkgCounterValue + counterModifier);
CpuIntrinsics::umonitor(const_cast<void *>(monitorAddress));
bool result = CpuIntrinsics::umwait(waitpkgControlValue, currentCounter) == 0;
return result;
}
template <typename T>
inline bool waitFunctionWithPredicate(volatile T const *pollAddress, T expectedValue, std::function<bool(T, T)> predicate) {
for (uint32_t i = 0; i < waitCount; i++) {
@@ -34,6 +43,13 @@ inline bool waitFunctionWithPredicate(volatile T const *pollAddress, T expectedV
if (predicate(*pollAddress, expectedValue)) {
return true;
}
if (waitpkgUse) {
if (monitorWait(pollAddress, 0)) {
if (predicate(*pollAddress, expectedValue)) {
return true;
}
}
}
}
std::this_thread::yield();
return false;