Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

__int128 to support more than 64 CPUs #15

Open
wants to merge 1 commit into
base: linux
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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