Browse Source

cpu-affinity: fix windows process cpu affinity mask

master
Tanguy Pruvot 9 years ago
parent
commit
833238cae5
  1. 4
      README.txt
  2. 40
      ccminer.cpp

4
README.txt

@ -115,7 +115,7 @@ its command line interface and options.
-b, --api-bind IP/Port for the miner API (default: 127.0.0.1:4068) -b, --api-bind IP/Port for the miner API (default: 127.0.0.1:4068)
--benchmark run in offline benchmark mode --benchmark run in offline benchmark mode
--cputest debug hashes from cpu algorithms --cputest debug hashes from cpu algorithms
--cpu-affinity set process affinity to specific cpu core(s) --cpu-affinity set process affinity to specific cpu core(s) mask
--cpu-priority set process priority (default: 0 idle, 2 normal to 5 highest) --cpu-priority set process priority (default: 0 idle, 2 normal to 5 highest)
-c, --config=FILE load a JSON-format configuration file -c, --config=FILE load a JSON-format configuration file
--no-color disable colored console output --no-color disable colored console output
@ -176,7 +176,7 @@ features.
>>> RELEASE HISTORY <<< >>> RELEASE HISTORY <<<
Jan. 2015 v1.5.2 Jan. 2015 v1.5.2
Add CPU priority and affinity parameters Add process CPU priority and affinity mask parameters
Intelligent duplicate shares check feature (enabled if needed) Intelligent duplicate shares check feature (enabled if needed)
api: Fan RPM (windows), Cuda threads count, linux kernel ver. api: Fan RPM (windows), Cuda threads count, linux kernel ver.
More X11 optimisations from sp and KlausT More X11 optimisations from sp and KlausT

40
ccminer.cpp

@ -68,11 +68,9 @@ nvml_handle *hnvml = NULL;
#ifdef __linux /* Linux specific policy and affinity management */ #ifdef __linux /* Linux specific policy and affinity management */
#include <sched.h> #include <sched.h>
static inline void drop_policy(void) static inline void drop_policy(void) {
{
struct sched_param param; struct sched_param param;
param.sched_priority = 0; param.sched_priority = 0;
#ifdef SCHED_IDLE #ifdef SCHED_IDLE
if (unlikely(sched_setscheduler(0, SCHED_IDLE, &param) == -1)) if (unlikely(sched_setscheduler(0, SCHED_IDLE, &param) == -1))
#endif #endif
@ -80,35 +78,25 @@ static inline void drop_policy(void)
sched_setscheduler(0, SCHED_BATCH, &param); sched_setscheduler(0, SCHED_BATCH, &param);
#endif #endif
} }
static inline void affine_to_cpu(int id, int cpu) {
static inline void affine_to_cpu(int id, int cpu)
{
cpu_set_t set; cpu_set_t set;
CPU_ZERO(&set); CPU_ZERO(&set);
CPU_SET(cpu, &set); CPU_SET(cpu, &set);
sched_setaffinity(0, sizeof(&set), &set); sched_setaffinity(0, sizeof(&set), &set);
} }
#elif defined(__FreeBSD__) /* FreeBSD specific policy and affinity management */ #elif defined(__FreeBSD__) /* FreeBSD specific policy and affinity management */
#include <sys/cpuset.h> #include <sys/cpuset.h>
static inline void drop_policy(void) static inline void drop_policy(void) { }
{ static inline void affine_to_cpu(int id, int cpu) {
}
static inline void affine_to_cpu(int id, int cpu)
{
cpuset_t set; cpuset_t set;
CPU_ZERO(&set); CPU_ZERO(&set);
CPU_SET(cpu, &set); CPU_SET(cpu, &set);
cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof(cpuset_t), &set); cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof(cpuset_t), &set);
} }
#else #else /* Windows */
static inline void drop_policy(void) static inline void drop_policy(void) { }
{ static inline void affine_to_cpu(int id, int cpu) {
} SetThreadAffinityMask(GetCurrentThread(), 1 << cpu);
static inline void affine_to_cpu(int id, int cpu)
{
} }
#endif #endif
@ -322,7 +310,7 @@ Options:\n\
--no-color disable colored output\n\ --no-color disable colored output\n\
-D, --debug enable debug output\n\ -D, --debug enable debug output\n\
-P, --protocol-dump verbose dump of protocol-level activities\n\ -P, --protocol-dump verbose dump of protocol-level activities\n\
--cpu-affinity set process affinity to specific cpu core(s)\n\ --cpu-affinity set process affinity to cpu core(s), mask 0x3 for cores 0 and 1\n\
--cpu-priority set process priority (default: 0 idle, 2 normal to 5 highest)\n\ --cpu-priority set process priority (default: 0 idle, 2 normal to 5 highest)\n\
-b, --api-bind IP/Port for the miner API (default: 127.0.0.1:4068)\n" -b, --api-bind IP/Port for the miner API (default: 127.0.0.1:4068)\n"
@ -2010,8 +1998,8 @@ static void parse_arg(int key, char *arg)
v = atoi(arg); v = atoi(arg);
if (v < -1) if (v < -1)
v = -1; v = -1;
if (v >= num_cpus) if (v > (1<<num_cpus)-1)
v = num_cpus-1; v = -1;
opt_affinity = v; opt_affinity = v;
break; break;
case 1021: case 1021:
@ -2299,6 +2287,12 @@ int main(int argc, char *argv[])
} }
SetPriorityClass(GetCurrentProcess(), prio); SetPriorityClass(GetCurrentProcess(), prio);
} }
if (opt_affinity != -1) {
DWORD_PTR mask = (DWORD_PTR) opt_affinity;
if (!opt_quiet)
applog(LOG_DEBUG, "Binding process to cpu(s) mask %x", opt_affinity);
SetProcessAffinityMask(GetCurrentProcess(), mask);
}
#endif #endif
if (active_gpus == 0) { if (active_gpus == 0) {

Loading…
Cancel
Save