Skip to content

Commit

Permalink
__int128 to support more than 64 CPUs
Browse files Browse the repository at this point in the history
Credits to: Louis Jeng <louisje@gmail.com>
  • Loading branch information
holyangel committed Dec 5, 2017
1 parent c720d9c commit 7978505
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cpu-miner.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,11 @@ static int opt_scrypt_n = 1024;
static int opt_pluck_n = 128;
static unsigned int opt_nfactor = 6;
int opt_n_threads = 0;
#ifdef __GNUC__
__int128 opt_affinity = -1L;
#elif
int64_t opt_affinity = -1L;
#endif
int opt_priority = 0;
int num_cpus;
char *rpc_url;
Expand Down Expand Up @@ -477,12 +481,20 @@ static inline void drop_policy(void)
#define pthread_setaffinity_np(tid,sz,s) {} /* only do process affinity */
#endif

#ifdef __GNUC__
static void affine_to_cpu_mask(int id, unsigned __int128 mask) {
#elif
static void affine_to_cpu_mask(int id, unsigned long mask) {
#endif
cpu_set_t set;
CPU_ZERO(&set);
for (uint8_t i = 0; i < num_cpus; i++) {
// cpu mask
#ifdef __GNUC__
if (mask & ((unsigned __int128)1UL<<i)) { CPU_SET(i, &set); }
#elif
if (mask & (1UL<<i)) { CPU_SET(i, &set); }
#endif
}
if (id == -1) {
// process affinity
Expand Down Expand Up @@ -1926,7 +1938,11 @@ static void *miner_thread(void *userdata)
if (opt_debug)
applog(LOG_DEBUG, "Binding thread %d to cpu %d (mask %x)", thr_id,
thr_id % num_cpus, (1 << (thr_id % num_cpus)));
#ifdef __GNUC__
affine_to_cpu_mask(thr_id, (unsigned __int128)1UL << (thr_id % num_cpus));
#elif
affine_to_cpu_mask(thr_id, 1UL << (thr_id % num_cpus));
#endif
} else if (opt_affinity != -1L) {
if (opt_debug)
applog(LOG_DEBUG, "Binding thread %d to cpu mask %x", thr_id,
Expand Down

0 comments on commit 7978505

Please sign in to comment.