Add residency mechanism to OS interface

Change-Id: I323ca856d3c901bdc4d5961cdefa42685b53d4d9
Signed-off-by: Zbigniew Zdanowicz <zbigniew.zdanowicz@intel.com>
This commit is contained in:
Zbigniew Zdanowicz
2019-07-12 16:50:14 +02:00
committed by sys_ocldev
parent 775336df92
commit f01c1d2d49
64 changed files with 742 additions and 253 deletions

View File

@@ -1,5 +1,5 @@
#
# Copyright (C) 2017-2018 Intel Corporation
# Copyright (C) 2017-2019 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
@@ -19,9 +19,12 @@ set(IGDRCL_SRCS_tests_utilities
${CMAKE_CURRENT_SOURCE_DIR}/numeric_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/perf_profiler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/reference_tracked_object_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/spinlock_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/tag_allocator_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/timer_util_tests.cpp
${CMAKE_CURRENT_SOURCE_DIR}/vec_tests.cpp
)
get_property(NEO_CORE_UTILITIES_TESTS GLOBAL PROPERTY NEO_CORE_UTILITIES_TESTS)
list(APPEND IGDRCL_SRCS_tests_utilities ${NEO_CORE_UTILITIES_TESTS})
target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_utilities})

View File

@@ -1,68 +0,0 @@
/*
* Copyright (C) 2017-2019 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "runtime/utilities/spinlock.h"
#include "gtest/gtest.h"
#include <mutex>
#include <thread>
using namespace NEO;
TEST(SpinLockTest, givenTwoThreadsThenVerifyThatTheySynchronizeWithSpinLock) {
std::atomic<bool> threadStarted(false);
std::atomic<bool> threadFinished(false);
SpinLock spinLock;
int sharedCount = 0;
// Initially acquire spin lock so the worker thread will wait
std::unique_lock<SpinLock> lock1{spinLock};
// Start worker thread
std::thread workerThread([&]() {
threadStarted = true;
std::unique_lock<SpinLock> lock2{spinLock};
sharedCount++;
EXPECT_EQ(2, sharedCount);
lock2.unlock();
threadFinished = true;
});
// Wait till worker thread is started
while (!threadStarted)
;
sharedCount++;
EXPECT_EQ(1, sharedCount);
// Release spin lock thus allowing worker thread to proceed
lock1.unlock();
// Wait till worker thread finishes
while (!threadFinished)
;
EXPECT_EQ(2, sharedCount);
workerThread.join();
}
TEST(SpinLockTest, givenSpinLockThenAttemptedLockingWorks) {
SpinLock spinLock;
auto workerThreadFunction = [&spinLock](bool expectedLockAcquired) {
std::unique_lock<SpinLock> lock{spinLock, std::defer_lock};
auto lockAcquired = lock.try_lock();
EXPECT_EQ(expectedLockAcquired, lockAcquired);
};
// Expect locking to fail when lock is already taken
std::unique_lock<SpinLock> lock{spinLock};
std::thread workerThread1(workerThreadFunction, false);
workerThread1.join();
lock.unlock();
std::thread workerThread2(workerThreadFunction, true);
workerThread2.join();
}