forked from nicehash/sgminer
-
Notifications
You must be signed in to change notification settings - Fork 4
/
sgminer.c
9306 lines (7925 loc) · 265 KB
/
sgminer.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright 2013-2014 sgminer developers (see AUTHORS.md)
* Copyright 2011-2013 Con Kolivas
* Copyright 2011-2012 Luke Dashjr
* Copyright 2010 Jeff Garzik
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation; either version 3 of the License, or (at your option)
* any later version. See COPYING for more details.
*/
#include "config.h"
#ifdef HAVE_CURSES
#if defined(__MINGW32__)
#include <ncurses/curses.h>
#else
#include <curses.h>
#endif // defined(__MINGW32__)
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <unistd.h>
#include <sys/time.h>
#include <time.h>
#include <math.h>
#include <stdarg.h>
#include <assert.h>
#include <signal.h>
#include <limits.h>
#include <sys/stat.h>
#include <sys/types.h>
#ifndef WIN32
#include <sys/resource.h>
#else
#include <winsock2.h>
#include <windows.h>
#endif
#include <ccan/opt/opt.h>
#include <jansson.h>
#ifdef HAVE_LIBCURL
#include <curl/curl.h>
#else
char *curly = ":D";
#endif
#include <libgen.h>
#include "sph/sph_sha2.h"
#include "sph/sph_blake.h"
#include "compat.h"
#include "miner.h"
#include "findnonce.h"
#include "adl.h"
#include "driver-opencl.h"
#include "bench_block.h"
#include "algorithm.h"
#include "pool.h"
#include "config_parser.h"
#include "events.h"
#if defined(unix) || defined(__APPLE__)
#include <errno.h>
#include <fcntl.h>
#include <sys/wait.h>
#endif
static char packagename[256];
static bool startup = true; //sgminer is starting up
static bool gpu_initialized = false; //gpu initialized
static int init_pool; //pool used to initialize gpus
static bool on_backup_pool = false; //for simple connect strategy... flag if we're on a backup pool
bool opt_work_update;
bool opt_protocol;
bool have_longpoll;
bool want_per_device_stats;
bool use_syslog;
bool opt_quiet;
bool opt_realquiet;
bool opt_loginput;
bool opt_compact;
bool opt_incognito;
// remote config options...
int opt_remoteconf_retry = 3; // number of retries
int opt_remoteconf_wait = 10; // wait in secs between retries
bool opt_remoteconf_usecache = false; // use last downloaded copy of the config file when download fails
const int opt_cutofftemp = 95;
int opt_log_interval = 5;
int opt_queue = 1;
int opt_scantime = 7;
int opt_expiry = 28;
unsigned long long global_hashrate;
unsigned long global_quota_gcd = 1;
bool opt_show_coindiff = false;
time_t last_getwork;
int nDevs;
int opt_dynamic_interval = 7;
int opt_g_threads = -1;
bool opt_restart = true;
int opt_vote = 0;
/*****************************************
* Xn Algorithm options
*****************************************/
int opt_hamsi_expand_big = 4;
int opt_keccak_unroll = 0;
bool opt_hamsi_short = false;
bool opt_blake_compact = false;
bool opt_luffa_parallel = false;
struct list_head scan_devices;
bool devices_enabled[MAX_DEVICES];
int opt_devs_enabled;
static bool opt_display_devs;
bool opt_removedisabled;
int total_devices;
static int most_devices;
struct cgpu_info **devices;
int mining_threads;
#ifdef HAVE_CURSES
bool use_curses = true;
#else
bool use_curses;
#endif
static bool opt_submit_stale = true;
int opt_shares;
bool opt_fail_only;
int opt_fail_switch_delay = 60;
int opt_watchpool_refresh = 30;
static bool opt_fix_protocol;
static bool opt_lowmem;
static bool opt_morenotices;
bool opt_autofan;
bool opt_autoengine;
bool opt_noadl;
char *opt_api_allow = NULL;
char *opt_api_groups;
char *opt_api_description = PACKAGE_STRING;
int opt_api_port = 4028;
bool opt_api_listen;
bool opt_api_mcast;
char *opt_api_mcast_addr = API_MCAST_ADDR;
char *opt_api_mcast_code = API_MCAST_CODE;
char *opt_api_mcast_des = "";
int opt_api_mcast_port = 4028;
bool opt_api_network;
bool opt_delaynet;
bool opt_disable_pool;
bool opt_disable_client_reconnect = false;
static bool no_work;
bool opt_worktime;
#if defined(HAVE_LIBCURL) && defined(CURL_HAS_KEEPALIVE)
int opt_tcp_keepalive = 30;
#else
int opt_tcp_keepalive;
#endif
double opt_diff_mult = 0.0;
char *opt_kernel_path;
char *sgminer_path;
#define QUIET (opt_quiet || opt_realquiet)
struct thr_info *control_thr;
struct thr_info **mining_thr = NULL;
static int gwsched_thr_id;
static int watchpool_thr_id;
static int watchdog_thr_id;
#ifdef HAVE_CURSES
static int input_thr_id;
#endif
int gpur_thr_id;
static int api_thr_id;
static int total_control_threads;
#if LOCK_TRACKING
pthread_mutex_t lockstat_lock;
#endif
pthread_mutex_t hash_lock;
static pthread_mutex_t *stgd_lock;
pthread_mutex_t console_lock;
cglock_t ch_lock;
static pthread_rwlock_t blk_lock;
static pthread_mutex_t sshare_lock;
pthread_rwlock_t netacc_lock;
pthread_rwlock_t mining_thr_lock;
pthread_rwlock_t devices_lock;
static pthread_mutex_t lp_lock;
static pthread_cond_t lp_cond;
static pthread_mutex_t algo_switch_lock;
static int algo_switch_n = 0;
static unsigned long pool_switch_options = 0;
static pthread_mutex_t algo_switch_wait_lock;
static pthread_cond_t algo_switch_wait_cond;
pthread_mutex_t restart_lock;
pthread_cond_t restart_cond;
pthread_cond_t gws_cond;
double total_rolling;
double total_mhashes_done;
static struct timeval total_tv_start, total_tv_end, launch_time;
cglock_t control_lock;
pthread_mutex_t stats_lock;
static void *restart_mining_threads_thread(void *userdata);
static void apply_initial_gpu_settings(struct pool *pool);
static unsigned long compare_pool_settings(struct pool *oldpool, struct pool *newpool);
static void apply_switcher_options(unsigned long options, struct pool *pool);
static void restart_mining_threads(unsigned int new_n_threads);
static void probe_pools(void);
static bool test_pool(struct pool *pool);
int hw_errors;
int total_accepted, total_rejected;
double total_diff1;
int total_getworks, total_stale, total_discarded;
double total_diff_accepted, total_diff_rejected, total_diff_stale;
static int staged_rollable;
unsigned int new_blocks;
static unsigned int work_block;
unsigned int found_blocks;
unsigned int local_work;
unsigned int total_go, total_ro;
struct pool **pools;
static struct pool *currentpool = NULL;
struct strategies strategies[] = {
{ "Failover" },
{ "Round Robin" },
{ "Rotate" },
{ "Load Balance" },
{ "Balance" },
};
int total_pools, enabled_pools;
enum pool_strategy pool_strategy = POOL_FAILOVER;
int opt_rotate_period;
static int total_urls;
//default mode apply algorithm/gpu settings when pool changes
int opt_switchmode = SWITCH_POOL;
static
#ifndef HAVE_CURSES
const
#endif
bool curses_active;
/* Protected by ch_lock */
char current_hash[68];
static char prev_block[12];
static char current_block[32];
static char datestamp[40];
static char blocktime[32];
struct timeval block_timeval;
static char best_share[8] = "0";
double current_diff = 0xFFFFFFFFFFFFFFFFULL;
static char block_diff[8];
double best_diff = 0;
struct block {
char hash[68];
UT_hash_handle hh;
int block_no;
};
static struct block *blocks = NULL;
int swork_id;
/* For creating a hash database of stratum shares submitted that have not had
* a response yet */
struct stratum_share {
UT_hash_handle hh;
bool block;
struct work *work;
int id;
time_t sshare_time;
time_t sshare_sent;
};
static struct stratum_share *stratum_shares = NULL;
char *opt_socks_proxy = NULL;
#if defined(unix) || defined(__APPLE__)
char *opt_stderr_cmd = NULL;
static int forkpid;
#endif // defined(unix)
#ifndef _MSC_VER
struct sigaction termhandler, inthandler;
#endif
struct thread_q *getq;
static int total_work;
struct work *staged_work = NULL;
struct schedtime schedstart;
struct schedtime schedstop;
bool sched_paused;
static bool time_before(struct tm *tm1, struct tm *tm2)
{
if (tm1->tm_hour < tm2->tm_hour)
return true;
if (tm1->tm_hour == tm2->tm_hour && tm1->tm_min < tm2->tm_min)
return true;
return false;
}
static bool should_run(void)
{
struct timeval tv;
struct tm *tm;
if (!schedstart.enable && !schedstop.enable)
return true;
cgtime(&tv);
const time_t tmp_time = tv.tv_sec;
tm = localtime(&tmp_time);
if (schedstart.enable) {
if (!schedstop.enable) {
if (time_before(tm, &schedstart.tm))
return false;
/* This is a once off event with no stop time set */
schedstart.enable = false;
return true;
}
if (time_before(&schedstart.tm, &schedstop.tm)) {
if (time_before(tm, &schedstop.tm) && !time_before(tm, &schedstart.tm))
return true;
return false;
} /* Times are reversed */
if (time_before(tm, &schedstart.tm)) {
if (time_before(tm, &schedstop.tm))
return true;
return false;
}
return true;
}
/* only schedstop.enable == true */
if (!time_before(tm, &schedstop.tm))
return false;
return true;
}
void get_datestamp(char *f, size_t fsiz, struct timeval *tv)
{
struct tm *tm;
const time_t tmp_time = tv->tv_sec;
tm = localtime(&tmp_time);
snprintf(f, fsiz, "[%d-%02d-%02d %02d:%02d:%02d]",
tm->tm_year + 1900,
tm->tm_mon + 1,
tm->tm_mday,
tm->tm_hour,
tm->tm_min,
tm->tm_sec);
}
static void get_timestamp(char *f, size_t fsiz, struct timeval *tv)
{
struct tm *tm;
const time_t tmp_time = tv->tv_sec;
tm = localtime(&tmp_time);
snprintf(f, fsiz, "[%02d:%02d:%02d]",
tm->tm_hour,
tm->tm_min,
tm->tm_sec);
}
static char exit_buf[512];
static void applog_and_exit(const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
vsnprintf(exit_buf, sizeof(exit_buf), fmt, ap);
va_end(ap);
_applog(LOG_ERR, exit_buf, true);
exit(1);
}
static pthread_mutex_t sharelog_lock;
static FILE *sharelog_file = NULL;
static struct cgpu_info *get_thr_cgpu(int thr_id)
{
struct cgpu_info *cgpu = NULL;
rd_lock(&mining_thr_lock);
if (thr_id < mining_threads && mining_thr[thr_id])
cgpu = mining_thr[thr_id]->cgpu;
rd_unlock(&mining_thr_lock);
return cgpu;
}
struct cgpu_info *get_devices(int id)
{
struct cgpu_info *cgpu = NULL;
rd_lock(&devices_lock);
if (id < total_devices)
cgpu = devices[id];
rd_unlock(&devices_lock);
return cgpu;
}
void enable_device(int i);
static void sharelog(const char*disposition, const struct work*work)
{
char *target, *hash, *data;
struct cgpu_info *cgpu;
unsigned long int t;
struct pool *pool;
int thr_id, rv;
char s[1024];
size_t ret;
if (!sharelog_file)
return;
thr_id = work->thr_id;
cgpu = get_thr_cgpu(thr_id);
pool = work->pool;
t = (unsigned long int)(work->tv_work_found.tv_sec);
target = bin2hex(work->target, sizeof(work->target));
hash = bin2hex(work->hash, sizeof(work->hash));
data = bin2hex(work->data, sizeof(work->data));
// timestamp,disposition,target,pool,dev,thr,sharehash,sharedata
rv = snprintf(s, sizeof(s), "%lu,%s,%s,%s,%s%u,%u,%s,%s\n", t, disposition, target, pool->rpc_url, cgpu->drv->name, cgpu->device_id, thr_id, hash, data);
free(target);
free(hash);
free(data);
if (rv >= (int)(sizeof(s)))
s[sizeof(s) - 1] = '\0';
else if (rv < 0) {
applog(LOG_ERR, "sharelog printf error");
return;
}
mutex_lock(&sharelog_lock);
ret = fwrite(s, rv, 1, sharelog_file);
fflush(sharelog_file);
mutex_unlock(&sharelog_lock);
if (ret != 1)
applog(LOG_ERR, "sharelog fwrite error");
}
static char *getwork_req = "{\"method\": \"getwork\", \"params\": [], \"id\":0}\n";
static char *gbt_req = "{\"id\": 0, \"method\": \"getblocktemplate\", \"params\": [{\"capabilities\": [\"coinbasetxn\", \"workid\", \"coinbase/append\"]}]}\n";
/* Adjust all the pools' quota to the greatest common denominator after a pool
* has been added or the quotas changed. */
void adjust_quota_gcd(void)
{
unsigned long gcd, lowest_quota = ~0UL, quota;
struct pool *pool;
int i;
for (i = 0; i < total_pools; i++) {
pool = pools[i];
quota = pool->quota;
if (!quota)
continue;
if (quota < lowest_quota)
lowest_quota = quota;
}
if (likely(lowest_quota < ~0UL)) {
gcd = lowest_quota;
for (i = 0; i < total_pools; i++) {
pool = pools[i];
quota = pool->quota;
if (!quota)
continue;
while (quota % gcd)
gcd--;
}
} else
gcd = 1;
for (i = 0; i < total_pools; i++) {
pool = pools[i];
pool->quota_used *= global_quota_gcd;
pool->quota_used /= gcd;
pool->quota_gcd = pool->quota / gcd;
}
global_quota_gcd = gcd;
applog(LOG_DEBUG, "Global quota greatest common denominator set to %lu", gcd);
}
/* Return value is ignored if not called from add_pool_details */
struct pool *add_pool(void)
{
struct pool *pool;
pool = (struct pool *)calloc(sizeof(struct pool), 1);
if (!pool)
quit(1, "Failed to calloc pool in add_pool");
pool->pool_no = pool->prio = total_pools;
/* Default pool name is "" (empty string) */
char buf[32];
buf[0] = '\0';
pool->name = strdup(buf);
pool->profile = strdup(buf); //profile blank by default
pool->algorithm.name[0] = '\0'; //blank algorithm name
/* intensities default to blank */
pool->intensity = strdup(buf);
pool->xintensity = strdup(buf);
pool->rawintensity = strdup(buf);
pools = (struct pool **)realloc(pools, sizeof(struct pool *) * (total_pools + 2));
pools[total_pools++] = pool;
mutex_init(&pool->pool_lock);
if (unlikely(pthread_cond_init(&pool->cr_cond, NULL)))
quit(1, "Failed to pthread_cond_init in add_pool");
cglock_init(&pool->data_lock);
mutex_init(&pool->stratum_lock);
cglock_init(&pool->gbt_lock);
INIT_LIST_HEAD(&pool->curlring);
/* Make sure the pool doesn't think we've been idle since time 0 */
pool->tv_idle.tv_sec = ~0UL;
pool->rpc_req = getwork_req;
pool->rpc_proxy = NULL;
pool->quota = 1;
adjust_quota_gcd();
pool->extranonce_subscribe = true;
pool->description = "";
return pool;
}
/* Used in configuration parsing. */
static struct pool* get_current_pool()
{
while ((json_array_index + 1) > total_pools)
add_pool();
if (json_array_index < 0) {
if (!total_pools)
add_pool();
return pools[total_pools - 1];
}
return pools[json_array_index];
}
/* Used everywhere else (to get pool currently mined on). */
struct pool *current_pool(void)
{
struct pool *pool;
cg_rlock(&control_lock);
pool = currentpool;
cg_runlock(&control_lock);
return pool;
}
/* Pool variant of test and set */
static bool pool_tset(struct pool *pool, bool *var)
{
bool ret;
mutex_lock(&pool->pool_lock);
ret = *var;
*var = true;
mutex_unlock(&pool->pool_lock);
return ret;
}
bool pool_tclear(struct pool *pool, bool *var)
{
bool ret;
mutex_lock(&pool->pool_lock);
ret = *var;
*var = false;
mutex_unlock(&pool->pool_lock);
return ret;
}
char *set_int_range(const char *arg, int *i, int min, int max)
{
char *err = opt_set_intval(arg, i);
if (err)
return err;
if (*i < min || *i > max)
return "Value out of range";
return NULL;
}
char *set_int_0_to_9999(const char *arg, int *i)
{
return set_int_range(arg, i, 0, 9999);
}
char *set_int_1_to_65535(const char *arg, int *i)
{
return set_int_range(arg, i, 1, 65535);
}
char *set_int_0_to_10(const char *arg, int *i)
{
return set_int_range(arg, i, 0, 10);
}
char *set_int_1_to_10(const char *arg, int *i)
{
return set_int_range(arg, i, 1, 10);
}
void get_intrange(char *arg, int *val1, int *val2)
{
if (sscanf(arg, "%d-%d", val1, val2) == 1)
*val2 = *val1;
}
char *set_devices(char *arg)
{
int i, val1 = 0, val2 = 0;
char *p, *nextptr;
if(arg[0] != '\0')
{
if(!strcasecmp(arg, "?"))
{
opt_display_devs = true;
return NULL;
}
//all devices enabled
else if(!strcasecmp(arg, "*") || !strcasecmp(arg, "all"))
{
applog(LOG_DEBUG, "set_devices(all)");
opt_devs_enabled = 0;
return NULL;
}
}
else
return "Invalid device parameters";
applog(LOG_DEBUG, "set_devices(%s)", arg);
p = strdup(arg);
nextptr = strtok(p, ",");
do {
if (nextptr == NULL)
{
free(p);
return "Invalid parameters for set devices";
}
get_intrange(nextptr, &val1, &val2);
if (val1 < 0 || val1 > MAX_DEVICES || val2 < 0 || val2 > MAX_DEVICES || val1 > val2)
{
free(p);
return "Invalid value passed to set devices";
}
for (i = val1; i <= val2; i++)
{
devices_enabled[i] = true;
opt_devs_enabled++;
}
} while ((nextptr = strtok(NULL, ",")) != NULL);
applog(LOG_DEBUG, "set_devices(%s) done.", arg);
free(p);
return NULL;
}
static char *set_balance(enum pool_strategy *strategy)
{
*strategy = POOL_BALANCE;
return NULL;
}
static char *set_loadbalance(enum pool_strategy *strategy)
{
*strategy = POOL_LOADBALANCE;
return NULL;
}
static char *set_rotate(const char *arg, int *i)
{
pool_strategy = POOL_ROTATE;
return set_int_range(arg, i, 0, 9999);
}
static char *set_rr(enum pool_strategy *strategy)
{
*strategy = POOL_ROUNDROBIN;
return NULL;
}
/* Detect that url is for a stratum protocol either via the presence of
* stratum+tcp or by detecting a stratum server response */
bool detect_stratum(struct pool *pool, char *url)
{
if (!extract_sockaddr(url, &pool->sockaddr_url, &pool->stratum_port))
return false;
if (!strncasecmp(url, "stratum+tcp://", 14)) {
pool->rpc_url = strdup(url);
pool->has_stratum = true;
pool->stratum_url = pool->sockaddr_url;
return true;
}
return false;
}
static struct pool *add_url(void)
{
total_urls++;
if (total_urls > total_pools)
add_pool();
return pools[total_urls - 1];
}
static void setup_url(struct pool *pool, char *arg)
{
arg = get_proxy(arg, pool);
if (detect_stratum(pool, arg))
return;
opt_set_charp(arg, &pool->rpc_url);
if (strncmp(arg, "http://", 7) && strncmp(arg, "https://", 8)) {
char *httpinput;
httpinput = (char *)malloc(255);
if (!httpinput)
quit(1, "Failed to malloc httpinput");
strcpy(httpinput, "http://");
strncat(httpinput, arg, 248);
pool->rpc_url = httpinput;
}
}
static char *set_url(char *arg)
{
struct pool *pool = add_url();
setup_url(pool, arg);
return NULL;
}
static char *set_pool_algorithm(const char *arg)
{
struct pool *pool = get_current_pool();
applog(LOG_DEBUG, "Setting pool %i algorithm to %s", pool->pool_no, arg);
set_algorithm(&pool->algorithm, arg);
return NULL;
}
static char *set_pool_backup(const char *arg)
{
struct pool *pool = get_current_pool();
pool->backup = TRUE;
return NULL;
}
static char *set_pool_devices(const char *arg)
{
struct pool *pool = get_current_pool();
pool->devices = arg;
return NULL;
}
static char *set_pool_kernelfile(const char *arg)
{
struct pool *pool = get_current_pool();
applog(LOG_DEBUG, "Setting pool %i algorithm kernel file to %s", pool->pool_no, arg);
pool->algorithm.kernelfile = arg;
return NULL;
}
static char *set_pool_lookup_gap(const char *arg)
{
struct pool *pool = get_current_pool();
pool->lookup_gap = arg;
return NULL;
}
static char *set_pool_intensity(const char *arg)
{
struct pool *pool = get_current_pool();
opt_set_charp(arg, &pool->intensity);
return NULL;
}
static char *set_pool_xintensity(const char *arg)
{
struct pool *pool = get_current_pool();
opt_set_charp(arg, &pool->xintensity);
return NULL;
}
static char *set_pool_rawintensity(const char *arg)
{
struct pool *pool = get_current_pool();
opt_set_charp(arg, &pool->rawintensity);
return NULL;
}
static char *set_pool_thread_concurrency(const char *arg)
{
struct pool *pool = get_current_pool();
pool->thread_concurrency = arg;
return NULL;
}
#ifdef HAVE_ADL
static char *set_pool_gpu_engine(const char *arg)
{
struct pool *pool = get_current_pool();
pool->gpu_engine = arg;
return NULL;
}
static char *set_pool_gpu_memclock(const char *arg)
{
struct pool *pool = get_current_pool();
pool->gpu_memclock = arg;
return NULL;
}
static char *set_pool_gpu_threads(const char *arg)
{
struct pool *pool = get_current_pool();
pool->gpu_threads = arg;
return NULL;
}
static char *set_pool_gpu_fan(const char *arg)
{
struct pool *pool = get_current_pool();
pool->gpu_fan = arg;
return NULL;
}
static char *set_pool_gpu_powertune(const char *arg)
{
struct pool *pool = get_current_pool();
pool->gpu_powertune = arg;
return NULL;
}
static char *set_pool_gpu_vddc(const char *arg)
{
struct pool *pool = get_current_pool();
pool->gpu_vddc = arg;
return NULL;
}
#endif
static char *set_pool_nfactor(const char *arg)
{
struct pool *pool = get_current_pool();
applog(LOG_DEBUG, "Setting pool %i N-factor to %s", pool->pool_no, arg);
set_algorithm_nfactor(&pool->algorithm, (const uint8_t) atoi(arg));
return NULL;
}
static char *set_pool_name(char *arg)
{
struct pool *pool = get_current_pool();
applog(LOG_DEBUG, "Setting pool %i name to %s", pool->pool_no, arg);
opt_set_charp(arg, &pool->name);
return NULL;
}
static char *set_pool_profile(char *arg)
{
struct pool *pool = get_current_pool();
applog(LOG_DEBUG, "Setting pool %i profile to %s", pool->pool_no, arg);
opt_set_charp(arg, &pool->profile);
return NULL;
}
static char *set_poolname_deprecated(char *arg)
{
applog(LOG_ERR, "Specifying pool name by --poolname is deprecated. Use --name instead.");
set_pool_name(arg);
return NULL;
}
static char *set_pool_shaders(const char *arg)
{
struct pool *pool = get_current_pool();
pool->shaders = arg;
return NULL;
}
static char *set_pool_worksize(const char *arg)
{
struct pool *pool = get_current_pool();
pool->worksize = arg;
return NULL;
}
static void enable_pool(struct pool *pool)
{
if (pool->state != POOL_ENABLED)
enabled_pools++;
pool->state = POOL_ENABLED;
}
static void disable_pool(struct pool *pool)
{
if (pool->state == POOL_ENABLED)
enabled_pools--;
pool->state = POOL_DISABLED;
}
static void reject_pool(struct pool *pool)
{
if (pool->state == POOL_ENABLED)
enabled_pools--;
pool->state = POOL_REJECTING;
}
/* We can't remove the memory used for this struct pool because there may
* still be work referencing it. We just remove it from the pools list */
void remove_pool(struct pool *pool)
{
int i, last_pool = total_pools - 1;
struct pool *other;
/* Boost priority of any lower prio than this one */
for (i = 0; i < total_pools; i++) {
other = pools[i];
if (other->prio > pool->prio)
other->prio--;
}