summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpsychocrypt <psychocryptHPC@gmail.com>2017-12-22 20:57:29 +0100
committerGitHub <noreply@github.com>2017-12-22 20:57:29 +0100
commit3f8b269b72c75a2cd42d6b99d5622328ac76e3e2 (patch)
treedd80e15e9d6559967335d42ad07ba64a6e4d35da
parent8f8907254707c6d8bfcb970c130b9be302e27d2d (diff)
parentda1da53fae61bf916924233c5198ebf7b2533f73 (diff)
downloadxmr-stak-3f8b269b72c75a2cd42d6b99d5622328ac76e3e2.zip
xmr-stak-3f8b269b72c75a2cd42d6b99d5622328ac76e3e2.tar.gz
Merge pull request #664 from fireice-uk/topic-fix-clock
Make sure we are using a steady clock
-rw-r--r--xmrstak/backend/amd/minethd.cpp3
-rw-r--r--xmrstak/backend/cpu/minethd.cpp6
-rw-r--r--xmrstak/backend/nvidia/minethd.cpp2
-rw-r--r--xmrstak/cli/cli-miner.cpp8
-rw-r--r--xmrstak/misc/executor.cpp5
-rw-r--r--xmrstak/misc/telemetry.cpp5
-rw-r--r--xmrstak/net/msgstruct.hpp10
7 files changed, 21 insertions, 18 deletions
diff --git a/xmrstak/backend/amd/minethd.cpp b/xmrstak/backend/amd/minethd.cpp
index 103688f..e83527c 100644
--- a/xmrstak/backend/amd/minethd.cpp
+++ b/xmrstak/backend/amd/minethd.cpp
@@ -249,8 +249,7 @@ void minethd::work_main()
}
iCount += pGpuCtx->rawIntensity;
- using namespace std::chrono;
- uint64_t iStamp = time_point_cast<milliseconds>(high_resolution_clock::now()).time_since_epoch().count();
+ uint64_t iStamp = get_timestamp_ms();
iHashCount.store(iCount, std::memory_order_relaxed);
iTimestamp.store(iStamp, std::memory_order_relaxed);
std::this_thread::yield();
diff --git a/xmrstak/backend/cpu/minethd.cpp b/xmrstak/backend/cpu/minethd.cpp
index 1c0e491..143b66f 100644
--- a/xmrstak/backend/cpu/minethd.cpp
+++ b/xmrstak/backend/cpu/minethd.cpp
@@ -427,8 +427,7 @@ void minethd::work_main()
{
if ((iCount++ & 0xF) == 0) //Store stats every 16 hashes
{
- using namespace std::chrono;
- uint64_t iStamp = time_point_cast<milliseconds>(high_resolution_clock::now()).time_since_epoch().count();
+ uint64_t iStamp = get_timestamp_ms();
iHashCount.store(iCount, std::memory_order_relaxed);
iTimestamp.store(iStamp, std::memory_order_relaxed);
}
@@ -614,8 +613,7 @@ void minethd::multiway_work_main(cn_hash_fun_multi hash_fun_multi)
{
if ((iCount++ & 0x7) == 0) //Store stats every 8*N hashes
{
- using namespace std::chrono;
- uint64_t iStamp = time_point_cast<milliseconds>(high_resolution_clock::now()).time_since_epoch().count();
+ uint64_t iStamp = get_timestamp_ms();
iHashCount.store(iCount * N, std::memory_order_relaxed);
iTimestamp.store(iStamp, std::memory_order_relaxed);
}
diff --git a/xmrstak/backend/nvidia/minethd.cpp b/xmrstak/backend/nvidia/minethd.cpp
index 6e628fd..5564596 100644
--- a/xmrstak/backend/nvidia/minethd.cpp
+++ b/xmrstak/backend/nvidia/minethd.cpp
@@ -294,7 +294,7 @@ void minethd::work_main()
iNonce += h_per_round;
using namespace std::chrono;
- uint64_t iStamp = time_point_cast<milliseconds>(high_resolution_clock::now()).time_since_epoch().count();
+ uint64_t iStamp = get_timestamp_ms();
iHashCount.store(iCount, std::memory_order_relaxed);
iTimestamp.store(iStamp, std::memory_order_relaxed);
std::this_thread::yield();
diff --git a/xmrstak/cli/cli-miner.cpp b/xmrstak/cli/cli-miner.cpp
index 145e4e6..b84b783 100644
--- a/xmrstak/cli/cli-miner.cpp
+++ b/xmrstak/cli/cli-miner.cpp
@@ -586,9 +586,7 @@ int main(int argc, char *argv[])
executor::inst()->ex_start(jconf::inst()->DaemonMode());
- using namespace std::chrono;
- uint64_t lastTime = time_point_cast<milliseconds>(high_resolution_clock::now()).time_since_epoch().count();
-
+ uint64_t lastTime = get_timestamp_ms();
int key;
while(true)
{
@@ -609,7 +607,7 @@ int main(int argc, char *argv[])
break;
}
- uint64_t currentTime = time_point_cast<milliseconds>(high_resolution_clock::now()).time_since_epoch().count();
+ uint64_t currentTime = get_timestamp_ms();
/* Hard guard to make sure we never get called more than twice per second */
if( currentTime - lastTime < 500)
@@ -631,7 +629,7 @@ void do_benchmark()
xmrstak::miner_work oWork = xmrstak::miner_work("", work, sizeof(work), 0, false, 0);
pvThreads = xmrstak::BackendConnector::thread_starter(oWork);
- uint64_t iStartStamp = time_point_cast<milliseconds>(high_resolution_clock::now()).time_since_epoch().count();
+ uint64_t iStartStamp = get_timestamp_ms();
std::this_thread::sleep_for(std::chrono::seconds(60));
diff --git a/xmrstak/misc/executor.cpp b/xmrstak/misc/executor.cpp
index 3aeb408..a3088a5 100644
--- a/xmrstak/misc/executor.cpp
+++ b/xmrstak/misc/executor.cpp
@@ -423,10 +423,9 @@ void executor::on_miner_result(size_t pool_id, job_result& oResult)
return;
}
- using namespace std::chrono;
- size_t t_start = time_point_cast<milliseconds>(high_resolution_clock::now()).time_since_epoch().count();
+ size_t t_start = get_timestamp_ms();
bool bResult = pool->cmd_submit(oResult.sJobID, oResult.iNonce, oResult.bResult, pvThreads->at(oResult.iThreadId), is_monero);
- size_t t_len = time_point_cast<milliseconds>(high_resolution_clock::now()).time_since_epoch().count() - t_start;
+ size_t t_len = get_timestamp_ms() - t_start;
if(t_len > 0xFFFF)
t_len = 0xFFFF;
diff --git a/xmrstak/misc/telemetry.cpp b/xmrstak/misc/telemetry.cpp
index c5cce23..738d287 100644
--- a/xmrstak/misc/telemetry.cpp
+++ b/xmrstak/misc/telemetry.cpp
@@ -22,12 +22,12 @@
*/
#include "telemetry.hpp"
+#include "xmrstak/net/msgstruct.hpp"
#include <cmath>
#include <cstring>
#include <chrono>
-
namespace xmrstak
{
@@ -49,8 +49,7 @@ telemetry::telemetry(size_t iThd)
double telemetry::calc_telemetry_data(size_t iLastMilisec, size_t iThread)
{
- using namespace std::chrono;
- uint64_t iTimeNow = time_point_cast<milliseconds>(high_resolution_clock::now()).time_since_epoch().count();
+ uint64_t iTimeNow = get_timestamp_ms();
uint64_t iEarliestHashCnt = 0;
uint64_t iEarliestStamp = 0;
diff --git a/xmrstak/net/msgstruct.hpp b/xmrstak/net/msgstruct.hpp
index 79541a1..a5affc8 100644
--- a/xmrstak/net/msgstruct.hpp
+++ b/xmrstak/net/msgstruct.hpp
@@ -177,3 +177,13 @@ inline size_t get_timestamp()
using namespace std::chrono;
return time_point_cast<seconds>(steady_clock::now()).time_since_epoch().count();
};
+
+//Get milisecond timestamp
+inline size_t get_timestamp_ms()
+{
+ using namespace std::chrono;
+ if(high_resolution_clock::is_steady)
+ return time_point_cast<milliseconds>(high_resolution_clock::now()).time_since_epoch().count();
+ else
+ return time_point_cast<milliseconds>(steady_clock::now()).time_since_epoch().count();
+}
OpenPOWER on IntegriCloud