static bool cpu_thread_init(struct thr_info *thr) { const int thr_id = thr->id; struct cgpu_info *cgpu = thr->cgpu; mutex_lock(&cpualgo_lock); switch (opt_algo) { case ALGO_AUTO: case ALGO_FASTAUTO: opt_algo = pick_fastest_algo(); default: break; } mutex_unlock(&cpualgo_lock); cgpu->kname = algo_names[opt_algo]; if (opt_algo == ALGO_SCRYPT) cgpu->min_nonce_diff = 1./0x10000; /* Set worker threads to nice 19 and then preferentially to SCHED_IDLE * and if that fails, then SCHED_BATCH. No need for this to be an * error if it fails */ setpriority(PRIO_PROCESS, 0, 19); drop_policy(); /* Cpu affinity only makes sense if the number of threads is a multiple * of the number of CPUs */ if (!(opt_n_threads % num_processors)) affine_to_cpu(dev_from_id(thr_id), dev_from_id(thr_id) % num_processors); return true; }
/* FIXME: Use asprintf for better errors. */ char *set_algo(const char *arg, enum sha256_algos *algo) { enum sha256_algos i; if (!strcmp(arg, "auto")) { *algo = pick_fastest_algo(); return NULL; } for (i = 0; i < ARRAY_SIZE(algo_names); i++) { if (algo_names[i] && !strcmp(arg, algo_names[i])) { *algo = i; return NULL; } } return "Unknown algorithm"; }