Browse Source

affinity: allow more than 8 cores values (and hexa)

master
Tanguy Pruvot 9 years ago
parent
commit
c9ef0b6b39
  1. 38
      ccminer.cpp

38
ccminer.cpp

@ -190,7 +190,7 @@ static json_t *opt_config;
static const bool opt_time = true; static const bool opt_time = true;
static enum sha_algos opt_algo = ALGO_X11; static enum sha_algos opt_algo = ALGO_X11;
int opt_n_threads = 0; int opt_n_threads = 0;
int opt_affinity = -1; int64_t opt_affinity = -1L;
int opt_priority = 0; int opt_priority = 0;
static double opt_difficulty = 1.; static double opt_difficulty = 1.;
bool opt_extranonce = true; bool opt_extranonce = true;
@ -487,12 +487,12 @@ static inline void drop_policy(void) {
#endif #endif
} }
static void affine_to_cpu_mask(int id, uint8_t mask) { static void affine_to_cpu_mask(int id, unsigned long mask) {
cpu_set_t set; cpu_set_t set;
CPU_ZERO(&set); CPU_ZERO(&set);
for (uint8_t i = 0; i < num_cpus; i++) { for (uint8_t i = 0; i < num_cpus; i++) {
// cpu mask // cpu mask
if (mask & (1<<i)) { CPU_SET(i, &set); } if (mask & (1UL<<i)) { CPU_SET(i, &set); }
} }
if (id == -1) { if (id == -1) {
// process affinity // process affinity
@ -505,17 +505,17 @@ static void affine_to_cpu_mask(int id, uint8_t mask) {
#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 void affine_to_cpu_mask(int id, uint8_t mask) { static void affine_to_cpu_mask(int id, unsigned long mask) {
cpuset_t set; cpuset_t set;
CPU_ZERO(&set); CPU_ZERO(&set);
for (uint8_t i = 0; i < num_cpus; i++) { for (uint8_t i = 0; i < num_cpus; i++) {
if (mask & (1<<i)) CPU_SET(i, &set); if (mask & (1UL<<i)) CPU_SET(i, &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);
} }
#elif defined(WIN32) /* Windows */ #elif defined(WIN32) /* Windows */
static inline void drop_policy(void) { } static inline void drop_policy(void) { }
static void affine_to_cpu_mask(int id, uint8_t mask) { static void affine_to_cpu_mask(int id, unsigned long mask) {
if (id == -1) if (id == -1)
SetProcessAffinityMask(GetCurrentProcess(), mask); SetProcessAffinityMask(GetCurrentProcess(), mask);
else else
@ -1568,16 +1568,16 @@ static void *miner_thread(void *userdata)
/* Cpu thread affinity */ /* Cpu thread affinity */
if (num_cpus > 1) { if (num_cpus > 1) {
if (opt_affinity == -1 && opt_n_threads > 1) { if (opt_affinity == -1L && opt_n_threads > 1) {
if (opt_debug) if (opt_debug)
applog(LOG_DEBUG, "Binding thread %d to cpu %d (mask %x)", thr_id, applog(LOG_DEBUG, "Binding thread %d to cpu %d (mask %x)", thr_id,
thr_id % num_cpus, (1 << (thr_id % num_cpus))); thr_id % num_cpus, (1UL << (thr_id % num_cpus)));
affine_to_cpu_mask(thr_id, 1 << (thr_id % num_cpus)); affine_to_cpu_mask(thr_id, 1 << (thr_id % num_cpus));
} else if (opt_affinity != -1) { } else if (opt_affinity != -1L) {
if (opt_debug) if (opt_debug)
applog(LOG_DEBUG, "Binding thread %d to cpu mask %x", thr_id, applog(LOG_DEBUG, "Binding thread %d to cpu mask %lx", thr_id,
opt_affinity); (long) opt_affinity);
affine_to_cpu_mask(thr_id, opt_affinity); affine_to_cpu_mask(thr_id, (unsigned long) opt_affinity);
} }
} }
@ -2444,6 +2444,7 @@ void parse_arg(int key, char *arg)
{ {
char *p = arg; char *p = arg;
int v, i; int v, i;
uint64_t ul;
double d; double d;
switch(key) { switch(key) {
@ -2839,12 +2840,11 @@ void parse_arg(int key, char *arg)
} }
break; break;
case 1020: case 1020:
v = atoi(arg); p = strstr(arg, "0x");
if (v < -1) ul = p ? strtoul(p, NULL, 16) : atol(arg);
v = -1; if (ul > (1UL<<num_cpus)-1)
if (v > (1<<num_cpus)-1) ul = -1L;
v = -1; opt_affinity = ul;
opt_affinity = v;
break; break;
case 1021: case 1021:
v = atoi(arg); v = atoi(arg);
@ -3241,7 +3241,7 @@ int main(int argc, char *argv[])
if (opt_affinity != -1) { if (opt_affinity != -1) {
if (!opt_quiet) if (!opt_quiet)
applog(LOG_DEBUG, "Binding process to cpu mask %x", opt_affinity); applog(LOG_DEBUG, "Binding process to cpu mask %x", opt_affinity);
affine_to_cpu_mask(-1, opt_affinity); affine_to_cpu_mask(-1, (unsigned long)opt_affinity);
} }
if (active_gpus == 0) { if (active_gpus == 0) {
applog(LOG_ERR, "No CUDA devices found! terminating."); applog(LOG_ERR, "No CUDA devices found! terminating.");

Loading…
Cancel
Save