mirror of
https://github.com/xmrig/xmrig.git
synced 2025-01-08 20:09:52 +00:00
Merge pull request #2761 from SChernykh/dev
Refactored Chrono::highResolutionMSecs()
This commit is contained in:
commit
56158779de
5 changed files with 59 additions and 34 deletions
|
@ -132,6 +132,7 @@ set(SOURCES_BASE
|
|||
src/base/net/tools/LineReader.cpp
|
||||
src/base/net/tools/NetBuffer.cpp
|
||||
src/base/tools/Arguments.cpp
|
||||
src/base/tools/Chrono.cpp
|
||||
src/base/tools/cryptonote/BlockTemplate.cpp
|
||||
src/base/tools/cryptonote/crypto-ops-data.c
|
||||
src/base/tools/cryptonote/crypto-ops.c
|
||||
|
|
44
src/base/tools/Chrono.cpp
Normal file
44
src/base/tools/Chrono.cpp
Normal file
|
@ -0,0 +1,44 @@
|
|||
/* XMRig
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "Chrono.h"
|
||||
|
||||
|
||||
#ifdef XMRIG_OS_WIN
|
||||
# include <Windows.h>
|
||||
#endif
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
double Chrono::highResolutionMSecs()
|
||||
{
|
||||
# ifdef XMRIG_OS_WIN
|
||||
LARGE_INTEGER f, t;
|
||||
QueryPerformanceFrequency(&f);
|
||||
QueryPerformanceCounter(&t);
|
||||
return static_cast<double>(t.QuadPart) * 1e3 / f.QuadPart;
|
||||
# else
|
||||
using namespace std::chrono;
|
||||
return static_cast<uint64_t>(duration_cast<nanoseconds>(high_resolution_clock::now().time_since_epoch()).count()) / 1e6;
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
|
@ -29,12 +29,7 @@ namespace xmrig {
|
|||
class Chrono
|
||||
{
|
||||
public:
|
||||
static inline uint64_t highResolutionMSecs()
|
||||
{
|
||||
using namespace std::chrono;
|
||||
|
||||
return static_cast<uint64_t>(time_point_cast<milliseconds>(high_resolution_clock::now()).time_since_epoch().count());
|
||||
}
|
||||
static double highResolutionMSecs();
|
||||
|
||||
|
||||
static inline uint64_t steadyMSecs()
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/io/log/Tags.h"
|
||||
#include "base/tools/Chrono.h"
|
||||
#include "backend/cpu/Cpu.h"
|
||||
#include "crypto/cn/CnHash.h"
|
||||
#include "crypto/cn/CnCtx.h"
|
||||
|
@ -44,7 +45,6 @@
|
|||
|
||||
#include <thread>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <uv.h>
|
||||
|
||||
#ifdef XMRIG_FEATURE_HWLOC
|
||||
|
@ -61,10 +61,6 @@
|
|||
# include <intrin.h>
|
||||
#endif
|
||||
|
||||
#ifdef XMRIG_OS_WIN
|
||||
# include <Windows.h>
|
||||
#endif
|
||||
|
||||
#define CORE_HASH(i, x) static void h##i(const uint8_t* data, size_t size, uint8_t* output) \
|
||||
{ \
|
||||
sph_##x##_context ctx; \
|
||||
|
@ -332,17 +328,6 @@ void benchmark()
|
|||
LOG_VERBOSE("%24s | N | Hashrate", "Algorithm");
|
||||
LOG_VERBOSE("-------------------------|-----|-------------");
|
||||
|
||||
# ifdef XMRIG_OS_WIN
|
||||
LARGE_INTEGER timer_freq;
|
||||
QueryPerformanceFrequency(&timer_freq);
|
||||
auto measure_time = []() { LARGE_INTEGER t; QueryPerformanceCounter(&t); return t.QuadPart; };
|
||||
auto delta_time = [&timer_freq](LONGLONG t1, LONGLONG t2) { return static_cast<double>(t2 - t1) / timer_freq.QuadPart; };
|
||||
# else
|
||||
using namespace std::chrono;
|
||||
auto measure_time = []() { return high_resolution_clock::now(); };
|
||||
auto delta_time = [](const high_resolution_clock::time_point& t1, const high_resolution_clock::time_point& t2) { return duration_cast<nanoseconds>(t2 - t1).count() / 1e9; };
|
||||
# endif
|
||||
|
||||
for (uint32_t algo = 0; algo < 6; ++algo) {
|
||||
for (uint64_t step : { 1, 2, 4}) {
|
||||
const size_t cur_scratchpad_size = cn_sizes[algo] * step;
|
||||
|
@ -352,26 +337,26 @@ void benchmark()
|
|||
|
||||
auto f = CnHash::fn(cn_hash[algo], av[step], Assembly::AUTO);
|
||||
|
||||
auto start_time = measure_time();
|
||||
double start_time = Chrono::highResolutionMSecs();
|
||||
|
||||
double min_dt = 1e10;
|
||||
for (uint32_t iter = 0;; ++iter) {
|
||||
auto t1 = measure_time();
|
||||
double t1 = Chrono::highResolutionMSecs();
|
||||
|
||||
// Stop after 15 milliseconds, but only if at least 10 iterations were done
|
||||
if ((iter >= 10) && (delta_time(start_time, t1) >= 0.015)) {
|
||||
if ((iter >= 10) && (t1 - start_time >= 15.0)) {
|
||||
break;
|
||||
}
|
||||
|
||||
f(buf, sizeof(buf), hash, ctx, 0);
|
||||
|
||||
const double dt = delta_time(t1, measure_time());
|
||||
const double dt = Chrono::highResolutionMSecs() - t1;
|
||||
if (dt < min_dt) {
|
||||
min_dt = dt;
|
||||
}
|
||||
}
|
||||
|
||||
const double hashrate = step / min_dt;
|
||||
const double hashrate = step * 1e3 / min_dt;
|
||||
LOG_VERBOSE("%24s | %" PRIu64 "x1 | %.2f h/s", cn_names[algo], step, hashrate);
|
||||
|
||||
if (hashrate > tune8MB[algo].hashrate) {
|
||||
|
@ -401,14 +386,14 @@ void benchmark()
|
|||
|
||||
auto f = CnHash::fn(cn_hash[algo], av[step], Assembly::AUTO);
|
||||
|
||||
auto start_time = measure_time();
|
||||
double start_time = Chrono::highResolutionMSecs();
|
||||
|
||||
double min_dt = 1e10;
|
||||
for (uint32_t iter = 0;; ++iter) {
|
||||
auto t1 = measure_time();
|
||||
double t1 = Chrono::highResolutionMSecs();
|
||||
|
||||
// Stop after 30 milliseconds, but only if at least 10 iterations were done
|
||||
if ((iter >= 10) && (delta_time(start_time, t1) >= 0.03)) {
|
||||
if ((iter >= 10) && (t1 - start_time >= 30.0)) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -416,13 +401,13 @@ void benchmark()
|
|||
f(buf, sizeof(buf), hash, ctx, 0);
|
||||
helper->wait();
|
||||
|
||||
const double dt = delta_time(t1, measure_time());
|
||||
const double dt = Chrono::highResolutionMSecs() - t1;
|
||||
if (dt < min_dt) {
|
||||
min_dt = dt;
|
||||
}
|
||||
}
|
||||
|
||||
const double hashrate = step * 2.0 / min_dt * 1.0075;
|
||||
const double hashrate = step * 2e3 / min_dt * 1.0075;
|
||||
LOG_VERBOSE("%24s | %" PRIu64 "x2 | %.2f h/s", cn_names[algo], step, hashrate);
|
||||
|
||||
if (hashrate > tune8MB[algo].hashrate) {
|
||||
|
|
|
@ -382,7 +382,7 @@ void SelectSoftAESImpl(size_t threadsCount)
|
|||
double fast_speed = 0.0;
|
||||
for (size_t run = 0; run < 3; ++run) {
|
||||
for (size_t i = 0; i < impl.size(); ++i) {
|
||||
const uint64_t t1 = xmrig::Chrono::highResolutionMSecs();
|
||||
const double t1 = xmrig::Chrono::highResolutionMSecs();
|
||||
std::vector<uint32_t> count(threadsCount, 0);
|
||||
std::vector<std::thread> threads;
|
||||
for (size_t t = 0; t < threadsCount; ++t) {
|
||||
|
@ -401,7 +401,7 @@ void SelectSoftAESImpl(size_t threadsCount)
|
|||
threads[t].join();
|
||||
total += count[t];
|
||||
}
|
||||
const uint64_t t2 = xmrig::Chrono::highResolutionMSecs();
|
||||
const double t2 = xmrig::Chrono::highResolutionMSecs();
|
||||
const double speed = total * 1e3 / (t2 - t1);
|
||||
if (speed > fast_speed) {
|
||||
fast_idx = i;
|
||||
|
|
Loading…
Reference in a new issue