Sync changes.

This commit is contained in:
XMRig 2018-11-20 07:24:14 +07:00
parent 9f6f599d78
commit 2a2712ab90
12 changed files with 114 additions and 33 deletions

View file

@ -4,8 +4,9 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* * Copyright 2018 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -36,7 +37,7 @@
char Platform::m_defaultConfigName[520] = { 0 }; char Platform::m_defaultConfigName[520] = { 0 };
xmrig::c_str Platform::m_userAgent; xmrig::String Platform::m_userAgent;
const char *Platform::defaultConfigName() const char *Platform::defaultConfigName()

View file

@ -4,8 +4,9 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* * Copyright 2018 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -28,7 +29,7 @@
#include <stdint.h> #include <stdint.h>
#include "common/utils/c_str.h" #include "base/tools/String.h"
class Platform class Platform
@ -36,7 +37,9 @@ class Platform
public: public:
static bool setThreadAffinity(uint64_t cpu_id); static bool setThreadAffinity(uint64_t cpu_id);
static const char *defaultConfigName(); static const char *defaultConfigName();
static uint32_t setTimerResolution(uint32_t resolution);
static void init(const char *userAgent); static void init(const char *userAgent);
static void restoreTimerResolution();
static void setProcessPriority(int priority); static void setProcessPriority(int priority);
static void setThreadPriority(int priority); static void setThreadPriority(int priority);
@ -46,7 +49,7 @@ private:
static char *createUserAgent(); static char *createUserAgent();
static char m_defaultConfigName[520]; static char m_defaultConfigName[520];
static xmrig::c_str m_userAgent; static xmrig::String m_userAgent;
}; };

View file

@ -65,9 +65,19 @@ bool Platform::setThreadAffinity(uint64_t cpu_id)
} }
uint32_t Platform::setTimerResolution(uint32_t resolution)
{
return resolution;
}
void Platform::restoreTimerResolution()
{
}
void Platform::setProcessPriority(int priority) void Platform::setProcessPriority(int priority)
{ {
} }

View file

@ -92,6 +92,17 @@ bool Platform::setThreadAffinity(uint64_t cpu_id)
} }
uint32_t Platform::setTimerResolution(uint32_t resolution)
{
return resolution;
}
void Platform::restoreTimerResolution()
{
}
void Platform::setProcessPriority(int priority) void Platform::setProcessPriority(int priority)
{ {
} }

View file

@ -4,8 +4,9 @@
* Copyright 2014 Lucas Jones <https://github.com/lucasjones> * Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2016-2017 XMRig <support@xmrig.com> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* * Copyright 2018 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -22,6 +23,7 @@
*/ */
#include <algorithm>
#include <winsock2.h> #include <winsock2.h>
#include <windows.h> #include <windows.h>
#include <uv.h> #include <uv.h>
@ -37,6 +39,9 @@
#endif #endif
static uint32_t timerResolution = 0;
static inline OSVERSIONINFOEX winOsVersion() static inline OSVERSIONINFOEX winOsVersion()
{ {
typedef NTSTATUS (NTAPI *RtlGetVersionFunction)(LPOSVERSIONINFO); typedef NTSTATUS (NTAPI *RtlGetVersionFunction)(LPOSVERSIONINFO);
@ -94,6 +99,34 @@ bool Platform::setThreadAffinity(uint64_t cpu_id)
} }
uint32_t Platform::setTimerResolution(uint32_t resolution)
{
# ifdef XMRIG_AMD_PROJECT
TIMECAPS tc;
if (timeGetDevCaps(&tc, sizeof(TIMECAPS)) != TIMERR_NOERROR) {
return 0;
}
timerResolution = std::min<uint32_t>(std::max<uint32_t>(tc.wPeriodMin, resolution), tc.wPeriodMax);
return timeBeginPeriod(timerResolution) == TIMERR_NOERROR ? timerResolution : 0;
# else
return resolution;
# endif
}
void Platform::restoreTimerResolution()
{
# ifdef XMRIG_AMD_PROJECT
if (timerResolution) {
timeEndPeriod(timerResolution);
}
# endif
}
void Platform::setProcessPriority(int priority) void Platform::setProcessPriority(int priority)
{ {
if (priority == -1) { if (priority == -1) {
@ -121,6 +154,7 @@ void Platform::setProcessPriority(int priority)
case 5: case 5:
prio = REALTIME_PRIORITY_CLASS; prio = REALTIME_PRIORITY_CLASS;
break;
default: default:
break; break;

View file

@ -212,6 +212,10 @@ const char *Client::tlsVersion() const
int64_t Client::submit(const JobResult &result) int64_t Client::submit(const JobResult &result)
{ {
if (result.clientId != m_rpcId) {
return -1;
}
using namespace rapidjson; using namespace rapidjson;
# ifdef XMRIG_PROXY_PROJECT # ifdef XMRIG_PROXY_PROJECT
@ -355,6 +359,8 @@ bool Client::parseJob(const rapidjson::Value &params, int *code)
return false; return false;
} }
m_job.setClientId(m_rpcId);
if (m_job != job) { if (m_job != job) {
m_jobs++; m_jobs++;
m_job = std::move(job); m_job = std::move(job);

View file

@ -21,8 +21,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __ID_H__ #ifndef XMRIG_ID_H
#define __ID_H__ #define XMRIG_ID_H
#include <string.h> #include <string.h>
@ -95,4 +95,4 @@ private:
} /* namespace xmrig */ } /* namespace xmrig */
#endif /* __ID_H__ */ #endif /* XMRIG_ID_H */

View file

@ -91,6 +91,12 @@ Job::~Job()
} }
bool Job::isEqual(const Job &other) const
{
return m_id == other.m_id && m_clientId == other.m_clientId && memcmp(m_blob, other.m_blob, sizeof(m_blob)) == 0;
}
bool Job::setBlob(const char *blob) bool Job::setBlob(const char *blob)
{ {
if (!blob) { if (!blob) {
@ -214,18 +220,6 @@ char *Job::toHex(const unsigned char* in, unsigned int len)
#endif #endif
bool Job::operator==(const Job &other) const
{
return m_id == other.m_id && memcmp(m_blob, other.m_blob, sizeof(m_blob)) == 0;
}
bool Job::operator!=(const Job &other) const
{
return m_id != other.m_id || memcmp(m_blob, other.m_blob, sizeof(m_blob)) != 0;
}
xmrig::Variant Job::variant() const xmrig::Variant Job::variant() const
{ {
using namespace xmrig; using namespace xmrig;

View file

@ -42,6 +42,7 @@ public:
Job(int poolId, bool nicehash, const xmrig::Algorithm &algorithm, const xmrig::Id &clientId); Job(int poolId, bool nicehash, const xmrig::Algorithm &algorithm, const xmrig::Id &clientId);
~Job(); ~Job();
bool isEqual(const Job &other) const;
bool setBlob(const char *blob); bool setBlob(const char *blob);
bool setTarget(const char *target); bool setTarget(const char *target);
void setAlgorithm(const char *algo); void setAlgorithm(const char *algo);
@ -81,8 +82,8 @@ public:
static char *toHex(const unsigned char* in, unsigned int len); static char *toHex(const unsigned char* in, unsigned int len);
# endif # endif
bool operator==(const Job &other) const; inline bool operator==(const Job &other) const { return isEqual(other); }
bool operator!=(const Job &other) const; inline bool operator!=(const Job &other) const { return !isEqual(other); }
private: private:
xmrig::Variant variant() const; xmrig::Variant variant() const;

View file

@ -31,7 +31,7 @@
namespace xmrig { namespace xmrig {
static inline int64_t currentMSecsSinceEpoch() static inline int64_t steadyTimestamp()
{ {
using namespace std::chrono; using namespace std::chrono;
if (high_resolution_clock::is_steady) { if (high_resolution_clock::is_steady) {
@ -42,6 +42,14 @@ static inline int64_t currentMSecsSinceEpoch()
} }
static inline int64_t currentMSecsSinceEpoch()
{
using namespace std::chrono;
return time_point_cast<milliseconds>(high_resolution_clock::now()).time_since_epoch().count();
}
} /* namespace xmrig */ } /* namespace xmrig */
#endif /* XMRIG_TIMESTAMP_H */ #endif /* XMRIG_TIMESTAMP_H */

View file

@ -21,8 +21,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifndef __JOBRESULT_H__ #ifndef XMRIG_JOBRESULT_H
#define __JOBRESULT_H__ #define XMRIG_JOBRESULT_H
#include <memory.h> #include <memory.h>
@ -36,17 +36,29 @@ class JobResult
{ {
public: public:
inline JobResult() : poolId(0), diff(0), nonce(0) {} inline JobResult() : poolId(0), diff(0), nonce(0) {}
inline JobResult(int poolId, const xmrig::Id &jobId, uint32_t nonce, const uint8_t *result, uint32_t diff, const xmrig::Algorithm &algorithm) : inline JobResult(int poolId, const xmrig::Id &jobId, const xmrig::Id &clientId, uint32_t nonce, const uint8_t *result, uint32_t diff, const xmrig::Algorithm &algorithm) :
poolId(poolId), poolId(poolId),
diff(diff), diff(diff),
nonce(nonce), nonce(nonce),
algorithm(algorithm), algorithm(algorithm),
clientId(clientId),
jobId(jobId) jobId(jobId)
{ {
memcpy(this->result, result, sizeof(this->result)); memcpy(this->result, result, sizeof(this->result));
} }
inline JobResult(const Job &job) : poolId(0), diff(0), nonce(0)
{
jobId = job.id();
clientId = job.clientId();
poolId = job.poolId();
diff = job.diff();
nonce = *job.nonce();
algorithm = job.algorithm();
}
inline uint64_t actualDiff() const inline uint64_t actualDiff() const
{ {
return Job::toDiff(reinterpret_cast<const uint64_t*>(result)[3]); return Job::toDiff(reinterpret_cast<const uint64_t*>(result)[3]);
@ -58,7 +70,8 @@ public:
uint32_t nonce; uint32_t nonce;
uint8_t result[32]; uint8_t result[32];
xmrig::Algorithm algorithm; xmrig::Algorithm algorithm;
xmrig::Id clientId;
xmrig::Id jobId; xmrig::Id jobId;
}; };
#endif /* __JOBRESULT_H__ */ #endif /* XMRIG_JOBRESULT_H */

View file

@ -108,7 +108,7 @@ void MultiWorker<N>::start()
for (size_t i = 0; i < N; ++i) { for (size_t i = 0; i < N; ++i) {
if (*reinterpret_cast<uint64_t*>(m_hash + (i * 32) + 24) < m_state.job.target()) { if (*reinterpret_cast<uint64_t*>(m_hash + (i * 32) + 24) < m_state.job.target()) {
Workers::submit(JobResult(m_state.job.poolId(), m_state.job.id(), *nonce(i), m_hash + (i * 32), m_state.job.diff(), m_state.job.algorithm())); Workers::submit(JobResult(m_state.job.poolId(), m_state.job.id(), m_state.job.clientId(), *nonce(i), m_hash + (i * 32), m_state.job.diff(), m_state.job.algorithm()));
} }
*nonce(i) += 1; *nonce(i) += 1;