Skip to content

Commit

Permalink
Merge pull request #664 from fireice-uk/topic-fix-clock
Browse files Browse the repository at this point in the history
Make sure we are using a steady clock
  • Loading branch information
psychocrypt authored Dec 22, 2017
2 parents 8f89072 + da1da53 commit 3f8b269
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 18 deletions.
3 changes: 1 addition & 2 deletions xmrstak/backend/amd/minethd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 2 additions & 4 deletions xmrstak/backend/cpu/minethd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion xmrstak/backend/nvidia/minethd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 3 additions & 5 deletions xmrstak/cli/cli-miner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
Expand All @@ -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));

Expand Down
5 changes: 2 additions & 3 deletions xmrstak/misc/executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions xmrstak/misc/telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
*/

#include "telemetry.hpp"
#include "xmrstak/net/msgstruct.hpp"

#include <cmath>
#include <cstring>
#include <chrono>


namespace xmrstak
{

Expand All @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions xmrstak/net/msgstruct.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

0 comments on commit 3f8b269

Please sign in to comment.