2020-01-14 20:52:06 +08:00
|
|
|
/*
|
2022-04-01 19:47:24 +08:00
|
|
|
* Copyright (C) 2020-2022 Intel Corporation
|
2020-01-14 20:52:06 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MIT
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/utilities/cpuintrinsics.h"
|
2020-01-14 20:52:06 +08:00
|
|
|
|
2021-10-08 02:09:36 +08:00
|
|
|
#include "shared/source/helpers/ptr_math.h"
|
|
|
|
|
2020-01-14 20:52:06 +08:00
|
|
|
#include <atomic>
|
|
|
|
#include <cstdint>
|
2021-12-02 00:37:46 +08:00
|
|
|
#include <functional>
|
2020-01-14 20:52:06 +08:00
|
|
|
|
2021-03-31 02:11:00 +08:00
|
|
|
namespace CpuIntrinsicsTests {
|
2020-01-14 20:52:06 +08:00
|
|
|
//std::atomic is used for sake of sanitation in MT tests
|
|
|
|
std::atomic<uintptr_t> lastClFlushedPtr(0u);
|
2021-12-08 19:12:14 +08:00
|
|
|
std::atomic<uint32_t> clFlushCounter(0u);
|
2020-01-14 20:52:06 +08:00
|
|
|
std::atomic<uint32_t> pauseCounter(0u);
|
2022-04-01 19:47:24 +08:00
|
|
|
std::atomic<uint32_t> sfenceCounter(0u);
|
2020-01-14 20:52:06 +08:00
|
|
|
|
2021-03-31 02:11:00 +08:00
|
|
|
volatile uint32_t *pauseAddress = nullptr;
|
|
|
|
uint32_t pauseValue = 0u;
|
2021-10-08 02:09:36 +08:00
|
|
|
uint32_t pauseOffset = 0u;
|
2021-12-02 00:37:46 +08:00
|
|
|
|
|
|
|
std::function<void()> setupPauseAddress;
|
2021-03-31 02:11:00 +08:00
|
|
|
} // namespace CpuIntrinsicsTests
|
|
|
|
|
2020-01-14 20:52:06 +08:00
|
|
|
namespace NEO {
|
|
|
|
namespace CpuIntrinsics {
|
|
|
|
|
|
|
|
void clFlush(void const *ptr) {
|
2021-12-08 19:12:14 +08:00
|
|
|
CpuIntrinsicsTests::clFlushCounter++;
|
2021-03-31 02:11:00 +08:00
|
|
|
CpuIntrinsicsTests::lastClFlushedPtr = reinterpret_cast<uintptr_t>(ptr);
|
2020-01-14 20:52:06 +08:00
|
|
|
}
|
|
|
|
|
2022-04-01 19:47:24 +08:00
|
|
|
void sfence() {
|
|
|
|
CpuIntrinsicsTests::sfenceCounter++;
|
|
|
|
}
|
|
|
|
|
2020-01-14 20:52:06 +08:00
|
|
|
void pause() {
|
2021-03-31 02:11:00 +08:00
|
|
|
CpuIntrinsicsTests::pauseCounter++;
|
|
|
|
if (CpuIntrinsicsTests::pauseAddress != nullptr) {
|
|
|
|
*CpuIntrinsicsTests::pauseAddress = CpuIntrinsicsTests::pauseValue;
|
2021-12-02 00:37:46 +08:00
|
|
|
if (CpuIntrinsicsTests::setupPauseAddress) {
|
|
|
|
CpuIntrinsicsTests::setupPauseAddress();
|
|
|
|
} else {
|
|
|
|
CpuIntrinsicsTests::pauseAddress = ptrOffset(CpuIntrinsicsTests::pauseAddress, CpuIntrinsicsTests::pauseOffset);
|
|
|
|
}
|
2021-03-31 02:11:00 +08:00
|
|
|
}
|
2020-01-14 20:52:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace CpuIntrinsics
|
|
|
|
} // namespace NEO
|