From 296ae46ed8f8f6e5f986f978febad302e3df231a Mon Sep 17 00:00:00 2001 From: Antonio Juarez Date: Mon, 3 Mar 2014 22:07:58 +0000 Subject: moved all stuff to github --- tests/performance_tests/performance_utils.h | 55 +++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/performance_tests/performance_utils.h (limited to 'tests/performance_tests/performance_utils.h') diff --git a/tests/performance_tests/performance_utils.h b/tests/performance_tests/performance_utils.h new file mode 100644 index 000000000..b2ac4076f --- /dev/null +++ b/tests/performance_tests/performance_utils.h @@ -0,0 +1,55 @@ +// Copyright (c) 2012-2013 The Cryptonote developers +// Distributed under the MIT/X11 software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#pragma once + +#include + +#include + +#ifdef BOOST_WINDOWS +#include +#endif + +void set_process_affinity(int core) +{ +#if defined(BOOST_WINDOWS) + DWORD_PTR mask = 1; + for (int i = 0; i < core; ++i) + { + mask <<= 1; + } + ::SetProcessAffinityMask(::GetCurrentProcess(), core); +#elif defined(BOOST_HAS_PTHREADS) + cpu_set_t cpuset; + CPU_ZERO(&cpuset); + CPU_SET(core, &cpuset); + if (0 != ::pthread_setaffinity_np(::pthread_self(), sizeof(cpuset), &cpuset)) + { + std::cout << "pthread_setaffinity_np - ERROR" << std::endl; + } +#endif +} + +void set_thread_high_priority() +{ +#if defined(BOOST_WINDOWS) + ::SetPriorityClass(::GetCurrentProcess(), HIGH_PRIORITY_CLASS); +#elif defined(BOOST_HAS_PTHREADS) + pthread_attr_t attr; + int policy = 0; + int max_prio_for_policy = 0; + + ::pthread_attr_init(&attr); + ::pthread_attr_getschedpolicy(&attr, &policy); + max_prio_for_policy = ::sched_get_priority_max(policy); + + if (0 != ::pthread_setschedprio(::pthread_self(), max_prio_for_policy)) + { + std::cout << "pthread_setschedprio - ERROR" << std::endl; + } + + ::pthread_attr_destroy(&attr); +#endif +} -- cgit v1.2.3