Added --cpu-priority option.

feature-httpd
XMRig 2017-08-15 08:19:55 +03:00
parent 61859dfe14
commit f05a328474
15 changed files with 136 additions and 6 deletions

View File

@ -82,6 +82,7 @@ App::App(int argc, char **argv) :
# endif
Platform::init();
Platform::setProcessPriority(m_options->priority());
m_network = new Network(m_options);
@ -115,7 +116,7 @@ int App::exec()
Mem::allocate(m_options->algo(), m_options->threads(), m_options->doubleHash());
Summary::print();
Workers::start(m_options->affinity());
Workers::start(m_options->affinity(), m_options->priority());
m_network->connect();

View File

@ -63,6 +63,7 @@ Options:\n\
-r, --retries=N number of times to retry before switch to backup server (default: 5)\n\
-R, --retry-pause=N time to pause between retries (default: 5)\n\
--cpu-affinity set process affinity to CPU core(s), mask 0x3 for cores 0 and 1\n\
--cpu-priority set process priority (0 idle, 2 normal to 5 highest)\n\
--no-color disable colored output\n\
--donate-level=N donate level, default 5%% (5 minutes in 100 minutes)\n\
-B, --background run the miner in the background\n\
@ -91,6 +92,7 @@ static struct option const options[] = {
{ "background", 0, nullptr, 'B' },
{ "config", 1, nullptr, 'c' },
{ "cpu-affinity", 1, nullptr, 1020 },
{ "cpu-priority", 1, nullptr, 1021 },
{ "donate-level", 1, nullptr, 1003 },
{ "help", 0, nullptr, 'h' },
{ "keepalive", 0, nullptr ,'k' },
@ -118,6 +120,7 @@ static struct option const config_options[] = {
{ "av", 1, nullptr, 'v' },
{ "background", 0, nullptr, 'B' },
{ "cpu-affinity", 1, nullptr, 1020 },
{ "cpu-priority", 1, nullptr, 1021 },
{ "donate-level", 1, nullptr, 1003 },
{ "log-file", 1, nullptr, 'l' },
{ "max-cpu-usage", 1, nullptr, 1004 },
@ -211,6 +214,7 @@ Options::Options(int argc, char **argv) :
m_donateLevel(kDonateLevel),
m_maxCpuUsage(75),
m_printTime(60),
m_priority(-1),
m_retries(5),
m_retryPause(5),
m_threads(0),
@ -326,6 +330,7 @@ bool Options::parseArg(int key, const char *arg)
case 1003: /* --donate-level */
case 1004: /* --max-cpu-usage */
case 1007: /* --print-time */
case 1021: /* --cpu-priority */
return parseArg(key, strtol(arg, nullptr, 10));
case 'B': /* --background */
@ -434,6 +439,12 @@ bool Options::parseArg(int key, uint64_t arg)
}
break;
case 1021: /* --cpu-priority */
if (arg <= 5) {
m_priority = (int) arg;
}
break;
default:
break;
}

View File

@ -64,6 +64,7 @@ public:
inline int algoVariant() const { return m_algoVariant; }
inline int donateLevel() const { return m_donateLevel; }
inline int printTime() const { return m_printTime; }
inline int priority() const { return m_priority; }
inline int retries() const { return m_retries; }
inline int retryPause() const { return m_retryPause; }
inline int threads() const { return m_threads; }
@ -109,6 +110,7 @@ private:
int m_donateLevel;
int m_maxCpuUsage;
int m_printTime;
int m_priority;
int m_retries;
int m_retryPause;
int m_threads;

View File

@ -30,6 +30,8 @@ class Platform
public:
static void init();
static void release();
static void setProcessPriority(int priority);
static void setThreadPriority(int priority);
static inline const char *userAgent() { return m_userAgent; }

View File

@ -52,3 +52,15 @@ void Platform::release()
delete [] m_userAgent;
}
void Platform::setProcessPriority(int priority)
{
}
void Platform::setThreadPriority(int priority)
{
}

View File

@ -62,3 +62,15 @@ void Platform::release()
delete [] m_userAgent;
}
void Platform::setProcessPriority(int priority)
{
}
void Platform::setThreadPriority(int priority)
{
}

View File

@ -84,3 +84,77 @@ void Platform::release()
delete [] m_userAgent;
}
void Platform::setProcessPriority(int priority)
{
if (priority == -1) {
return;
}
DWORD prio = IDLE_PRIORITY_CLASS;
switch (priority)
{
case 1:
prio = BELOW_NORMAL_PRIORITY_CLASS;
break;
case 2:
prio = NORMAL_PRIORITY_CLASS;
break;
case 3:
prio = ABOVE_NORMAL_PRIORITY_CLASS;
break;
case 4:
prio = HIGH_PRIORITY_CLASS;
break;
case 5:
prio = REALTIME_PRIORITY_CLASS;
default:
break;
}
SetPriorityClass(GetCurrentProcess(), prio);
}
void Platform::setThreadPriority(int priority)
{
if (priority == -1) {
return;
}
int prio = THREAD_PRIORITY_IDLE;
switch (priority)
{
case 1:
prio = THREAD_PRIORITY_BELOW_NORMAL;
break;
case 2:
prio = THREAD_PRIORITY_NORMAL;
break;
case 3:
prio = THREAD_PRIORITY_ABOVE_NORMAL;
break;
case 4:
prio = THREAD_PRIORITY_HIGHEST;
break;
case 5:
prio = THREAD_PRIORITY_TIME_CRITICAL;
break;
default:
break;
}
SetThreadPriority(GetCurrentThread(), prio);
}

View File

@ -4,6 +4,7 @@
"background": false,
"colors": true,
"cpu-affinity": null,
"cpu-priority": null,
"donate-level": 5,
"log-file": null,
"max-cpu-usage": 75,

View File

@ -42,6 +42,7 @@ public:
inline bool isNicehash() const { return m_nicehash; }
inline bool isValid() const { return m_size > 0 && m_diff > 0; }
inline const char *id() const { return m_id; }
inline const uint32_t *nonce() const { return reinterpret_cast<const uint32_t*>(m_blob + 39); }
inline const uint8_t *blob() const { return m_blob; }
inline int poolId() const { return m_poolId; }
inline size_t size() const { return m_size; }

View File

@ -43,6 +43,15 @@ public:
}
inline JobResult(const Job &job) : poolId(0), diff(0), nonce(0)
{
memcpy(jobId, job.id(), sizeof(jobId));
poolId = job.poolId();
diff = job.diff();
nonce = *job.nonce();
}
inline JobResult &operator=(const Job &job) {
memcpy(jobId, job.id(), sizeof(jobId));
poolId = job.poolId();

View File

@ -25,7 +25,8 @@
#include "workers/Handle.h"
Handle::Handle(int threadId, int threads, int64_t affinity) :
Handle::Handle(int threadId, int threads, int64_t affinity, int priority) :
m_priority(priority),
m_threadId(threadId),
m_threads(threads),
m_affinity(affinity),

View File

@ -35,10 +35,11 @@ class IWorker;
class Handle
{
public:
Handle(int threadId, int threads, int64_t affinity);
Handle(int threadId, int threads, int64_t affinity, int priority);
void join();
void start(void (*callback) (void *));
inline int priority() const { return m_priority; }
inline int threadId() const { return m_threadId; }
inline int threads() const { return m_threads; }
inline int64_t affinity() const { return m_affinity; }
@ -46,6 +47,7 @@ public:
inline void setWorker(IWorker *worker) { m_worker = worker; }
private:
int m_priority;
int m_threadId;
int m_threads;
int64_t m_affinity;

View File

@ -26,6 +26,7 @@
#include "Cpu.h"
#include "Mem.h"
#include "Platform.h"
#include "workers/Handle.h"
#include "workers/Worker.h"
@ -42,6 +43,7 @@ Worker::Worker(Handle *handle) :
Cpu::setAffinity(m_id, handle->affinity());
}
Platform::setThreadPriority(handle->priority());
m_ctx = Mem::create(m_id);
}

View File

@ -98,7 +98,7 @@ void Workers::setJob(const Job &job)
}
void Workers::start(int64_t affinity)
void Workers::start(int64_t affinity, int priority)
{
const int threads = Mem::threads();
m_hashrate = new Hashrate(threads);
@ -114,7 +114,7 @@ void Workers::start(int64_t affinity)
uv_timer_start(&m_timer, Workers::onTick, 500, 500);
for (int i = 0; i < threads; ++i) {
Handle *handle = new Handle(i, threads, affinity);
Handle *handle = new Handle(i, threads, affinity, priority);
m_workers.push_back(handle);
handle->start(Workers::onReady);
}

View File

@ -46,7 +46,7 @@ public:
static void printHashrate(bool detail);
static void setEnabled(bool enabled);
static void setJob(const Job &job);
static void start(int64_t affinity);
static void start(int64_t affinity, int priority);
static void stop();
static void submit(const JobResult &result);