Browse Source

cpu-affinity: fix windows process cpu affinity mask

2upstream
Tanguy Pruvot 10 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. @@ -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)
--benchmark run in offline benchmark mode
--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)
-c, --config=FILE load a JSON-format configuration file
--no-color disable colored console output
@ -176,7 +176,7 @@ features. @@ -176,7 +176,7 @@ features.
>>> RELEASE HISTORY <<<
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)
api: Fan RPM (windows), Cuda threads count, linux kernel ver.
More X11 optimisations from sp and KlausT

40
ccminer.cpp

@ -68,11 +68,9 @@ nvml_handle *hnvml = NULL; @@ -68,11 +68,9 @@ nvml_handle *hnvml = NULL;
#ifdef __linux /* Linux specific policy and affinity management */
#include <sched.h>
static inline void drop_policy(void)
{
static inline void drop_policy(void) {
struct sched_param param;
param.sched_priority = 0;
#ifdef SCHED_IDLE
if (unlikely(sched_setscheduler(0, SCHED_IDLE, &param) == -1))
#endif
@ -80,35 +78,25 @@ static inline void drop_policy(void) @@ -80,35 +78,25 @@ static inline void drop_policy(void)
sched_setscheduler(0, SCHED_BATCH, &param);
#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_ZERO(&set);
CPU_SET(cpu, &set);
sched_setaffinity(0, sizeof(&set), &set);
}
#elif defined(__FreeBSD__) /* FreeBSD specific policy and affinity management */
#include <sys/cpuset.h>
static inline void drop_policy(void)
{
}
static inline void affine_to_cpu(int id, int cpu)
{
static inline void drop_policy(void) { }
static inline void affine_to_cpu(int id, int cpu) {
cpuset_t set;
CPU_ZERO(&set);
CPU_SET(cpu, &set);
cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_TID, -1, sizeof(cpuset_t), &set);
}
#else
static inline void drop_policy(void)
{
}
static inline void affine_to_cpu(int id, int cpu)
{
#else /* Windows */
static inline void drop_policy(void) { }
static inline void affine_to_cpu(int id, int cpu) {
SetThreadAffinityMask(GetCurrentThread(), 1 << cpu);
}
#endif
@ -322,7 +310,7 @@ Options:\n\ @@ -322,7 +310,7 @@ Options:\n\
--no-color disable colored output\n\
-D, --debug enable debug output\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\
-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) @@ -2010,8 +1998,8 @@ static void parse_arg(int key, char *arg)
v = atoi(arg);
if (v < -1)
v = -1;
if (v >= num_cpus)
v = num_cpus-1;
if (v > (1<<num_cpus)-1)
v = -1;
opt_affinity = v;
break;
case 1021:
@ -2299,6 +2287,12 @@ int main(int argc, char *argv[]) @@ -2299,6 +2287,12 @@ int main(int argc, char *argv[])
}
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
if (active_gpus == 0) {

Loading…
Cancel
Save