Make sure we are using a steady clock

This commit is contained in:
fireice-uk
2017-12-22 18:08:30 +00:00
parent bbba9467ad
commit da1da53fae
7 changed files with 21 additions and 18 deletions
+1 -2
View File
@@ -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();
+2 -4
View File
@@ -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);
}
+1 -1
View File
@@ -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();
+3 -5
View File
@@ -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));
+2 -3
View File
@@ -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;
+2 -3
View File
@@ -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;
+10
View File
@@ -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();
}