miner.h 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324
  1. #ifndef __MINER_H__
  2. #define __MINER_H__
  3. #include "config.h"
  4. #ifdef WIN32
  5. #include <winsock2.h>
  6. #endif
  7. #include <stdbool.h>
  8. #include <stdint.h>
  9. #include <sys/time.h>
  10. #include <pthread.h>
  11. #include <jansson.h>
  12. #include <curl/curl.h>
  13. #include <blkmaker.h>
  14. #include <blktemplate.h>
  15. #if defined(WORDS_BIGENDIAN) && !defined(__BIG_ENDIAN__)
  16. /* uthash.h depends on __BIG_ENDIAN__ on BE platforms */
  17. #define __BIG_ENDIAN__ 1
  18. #endif
  19. #include "elist.h"
  20. #include "uthash.h"
  21. #include "logging.h"
  22. #include "util.h"
  23. #ifdef HAVE_OPENCL
  24. #include "CL/cl.h"
  25. #endif /* HAVE_OPENCL */
  26. #ifdef STDC_HEADERS
  27. # include <stdlib.h>
  28. # include <stddef.h>
  29. #else
  30. # ifdef HAVE_STDLIB_H
  31. # include <stdlib.h>
  32. # endif
  33. #endif
  34. #ifdef HAVE_ALLOCA_H
  35. # include <alloca.h>
  36. #elif defined __GNUC__
  37. # ifndef WIN32
  38. # define alloca __builtin_alloca
  39. # else
  40. # include <malloc.h>
  41. # endif
  42. #elif defined _AIX
  43. # define alloca __alloca
  44. #elif defined _MSC_VER
  45. # include <malloc.h>
  46. # define alloca _alloca
  47. #else
  48. # ifndef HAVE_ALLOCA
  49. # ifdef __cplusplus
  50. extern "C"
  51. # endif
  52. void *alloca (size_t);
  53. # endif
  54. #endif
  55. #ifdef __MINGW32__
  56. #include <windows.h>
  57. #include <io.h>
  58. static inline int fsync (int fd)
  59. {
  60. return (FlushFileBuffers ((HANDLE) _get_osfhandle (fd))) ? 0 : -1;
  61. }
  62. #ifndef EWOULDBLOCK
  63. # define EWOULDBLOCK EAGAIN
  64. #endif
  65. #ifndef MSG_DONTWAIT
  66. # define MSG_DONTWAIT 0x1000000
  67. #endif
  68. #endif /* __MINGW32__ */
  69. #if defined (__linux)
  70. #ifndef LINUX
  71. #define LINUX
  72. #endif
  73. #endif
  74. #ifdef HAVE_ADL
  75. #include "ADL/adl_sdk.h"
  76. #endif
  77. #ifdef HAVE_LIBUSB
  78. #include <libusb.h>
  79. #endif
  80. #ifdef USE_ZTEX
  81. #include "libztex.h"
  82. #endif
  83. #ifdef HAVE_BYTESWAP_H
  84. #include <byteswap.h>
  85. #endif
  86. #ifdef HAVE_ENDIAN_H
  87. #include <endian.h>
  88. #endif
  89. #ifdef HAVE_SYS_ENDIAN_H
  90. #include <sys/endian.h>
  91. #endif
  92. #ifdef HAVE_LIBKERN_OSBYTEORDER_H
  93. #include <libkern/OSByteOrder.h>
  94. #endif
  95. #ifndef bswap_16
  96. #define bswap_16(value) \
  97. ((((value) & 0xff) << 8) | ((value) >> 8))
  98. #define bswap_32(value) \
  99. (((uint32_t)bswap_16((uint16_t)((value) & 0xffff)) << 16) | \
  100. (uint32_t)bswap_16((uint16_t)((value) >> 16)))
  101. #define bswap_64(value) \
  102. (((uint64_t)bswap_32((uint32_t)((value) & 0xffffffff)) \
  103. << 32) | \
  104. (uint64_t)bswap_32((uint32_t)((value) >> 32)))
  105. #endif
  106. /* This assumes htobe32 is a macro and that if it doesn't exist, then the
  107. * also won't exist */
  108. #ifndef htobe32
  109. # ifndef WORDS_BIGENDIAN
  110. # define htole16(x) (x)
  111. # define htole32(x) (x)
  112. # define htole64(x) (x)
  113. # define htobe32(x) bswap_32(x)
  114. # define htobe64(x) bswap_64(x)
  115. # else
  116. # define htole16(x) bswap_16(x)
  117. # define htole32(x) bswap_32(x)
  118. # define htole64(x) bswap_64(x)
  119. # define htobe32(x) (x)
  120. # define htobe64(x) (x)
  121. # endif
  122. #endif
  123. #ifndef be32toh
  124. # define le32toh(x) htole32(x)
  125. # define le64toh(x) htole64(x)
  126. # define be32toh(x) htobe32(x)
  127. # define be64toh(x) htobe64(x)
  128. #endif
  129. #ifndef max
  130. # define max(a, b) ((a) > (b) ? (a) : (b))
  131. #endif
  132. #undef unlikely
  133. #undef likely
  134. #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
  135. #define unlikely(expr) (__builtin_expect(!!(expr), 0))
  136. #define likely(expr) (__builtin_expect(!!(expr), 1))
  137. #else
  138. #define unlikely(expr) (expr)
  139. #define likely(expr) (expr)
  140. #endif
  141. #ifndef __maybe_unused
  142. #define __maybe_unused __attribute__((unused))
  143. #endif
  144. #define uninitialised_var(x) x = x
  145. #if defined(__i386__)
  146. #define WANT_CRYPTOPP_ASM32
  147. #endif
  148. #ifndef ARRAY_SIZE
  149. #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
  150. #endif
  151. #ifdef HAVE_CURSES
  152. extern int my_cancellable_getch(void);
  153. # ifdef getch
  154. // getch() is a macro
  155. static int __maybe_unused __real_getch(void) {
  156. return getch();
  157. }
  158. # undef getch
  159. # define getch() my_cancellable_getch()
  160. # else
  161. // getch() is a real function
  162. # define __real_getch getch
  163. # define getch() my_cancellable_getch()
  164. # endif
  165. #endif
  166. #ifdef NEED_ROUNDL
  167. #define roundl(x) (long double)((long long)((x==0)?0.0:((x)+(((x)>0)?0.5:-0.5))))
  168. #endif
  169. enum alive {
  170. LIFE_WELL,
  171. LIFE_SICK,
  172. LIFE_DEAD,
  173. LIFE_NOSTART,
  174. LIFE_INIT,
  175. LIFE_WAIT,
  176. };
  177. enum pool_strategy {
  178. POOL_FAILOVER,
  179. POOL_ROUNDROBIN,
  180. POOL_ROTATE,
  181. POOL_LOADBALANCE,
  182. POOL_BALANCE,
  183. };
  184. #define TOP_STRATEGY (POOL_BALANCE)
  185. struct strategies {
  186. const char *s;
  187. };
  188. struct cgpu_info;
  189. #ifdef HAVE_ADL
  190. struct gpu_adl {
  191. ADLTemperature lpTemperature;
  192. int iAdapterIndex;
  193. int lpAdapterID;
  194. int iBusNumber;
  195. char strAdapterName[256];
  196. ADLPMActivity lpActivity;
  197. ADLODParameters lpOdParameters;
  198. ADLODPerformanceLevels *DefPerfLev;
  199. ADLFanSpeedInfo lpFanSpeedInfo;
  200. ADLFanSpeedValue lpFanSpeedValue;
  201. ADLFanSpeedValue DefFanSpeedValue;
  202. int iEngineClock;
  203. int iMemoryClock;
  204. int iVddc;
  205. int iPercentage;
  206. bool autofan;
  207. bool autoengine;
  208. bool managed; /* Were the values ever changed on this card */
  209. int lastengine;
  210. int lasttemp;
  211. int targetfan;
  212. int overtemp;
  213. int minspeed;
  214. int maxspeed;
  215. int gpu;
  216. bool has_fanspeed;
  217. struct gpu_adl *twin;
  218. };
  219. #endif
  220. struct api_data;
  221. struct thr_info;
  222. struct work;
  223. struct device_drv {
  224. const char *dname;
  225. const char *name;
  226. // DRV-global functions
  227. void (*drv_detect)();
  228. // Device-specific functions
  229. void (*get_dev_statline_before)(char *, struct cgpu_info *);
  230. void (*get_dev_statline_after)(char *, struct cgpu_info *);
  231. // Processor-specific functions
  232. void (*reinit_device)(struct cgpu_info *);
  233. void (*get_statline_before)(char *, struct cgpu_info *);
  234. void (*get_statline)(char *, struct cgpu_info *);
  235. struct api_data* (*get_api_extra_device_detail)(struct cgpu_info *);
  236. struct api_data* (*get_api_extra_device_status)(struct cgpu_info *);
  237. struct api_data *(*get_api_stats)(struct cgpu_info *);
  238. bool (*get_stats)(struct cgpu_info *);
  239. bool (*identify_device)(struct cgpu_info *); // e.g. to flash a led
  240. char *(*set_device)(struct cgpu_info *, char *option, char *setting, char *replybuf);
  241. // Thread-specific functions
  242. bool (*thread_prepare)(struct thr_info *);
  243. void (*minerloop)(struct thr_info *);
  244. uint64_t (*can_limit_work)(struct thr_info *);
  245. bool (*thread_init)(struct thr_info *);
  246. bool (*prepare_work)(struct thr_info *, struct work *);
  247. int64_t (*scanhash)(struct thr_info *, struct work *, int64_t);
  248. int64_t (*scanwork)(struct thr_info *);
  249. /* Used to extract work from the hash table of queued work and tell
  250. * the main loop that it should not add any further work to the table.
  251. */
  252. bool (*queue_full)(struct cgpu_info *);
  253. void (*flush_work)(struct cgpu_info *);
  254. void (*hw_error)(struct thr_info *);
  255. void (*thread_shutdown)(struct thr_info *);
  256. void (*thread_enable)(struct thr_info *);
  257. // Can be used per-thread or per-processor (only with minerloop async or queue!)
  258. void (*poll)(struct thr_info *);
  259. // === Implemented by minerloop_async ===
  260. bool (*job_prepare)(struct thr_info*, struct work*, uint64_t);
  261. void (*job_start)(struct thr_info*);
  262. void (*job_get_results)(struct thr_info*, struct work*);
  263. int64_t (*job_process_results)(struct thr_info*, struct work*, bool stopping);
  264. // === Implemented by minerloop_queue ===
  265. bool (*queue_append)(struct thr_info *, struct work *);
  266. void (*queue_flush)(struct thr_info *);
  267. };
  268. enum dev_enable {
  269. DEV_ENABLED,
  270. DEV_DISABLED,
  271. DEV_RECOVER,
  272. DEV_RECOVER_ERR,
  273. };
  274. enum cl_kernels {
  275. KL_NONE,
  276. KL_POCLBM,
  277. KL_PHATK,
  278. KL_DIAKGCN,
  279. KL_DIABLO,
  280. KL_SCRYPT,
  281. };
  282. enum dev_reason {
  283. REASON_THREAD_FAIL_INIT,
  284. REASON_THREAD_ZERO_HASH,
  285. REASON_THREAD_FAIL_QUEUE,
  286. REASON_DEV_SICK_IDLE_60,
  287. REASON_DEV_DEAD_IDLE_600,
  288. REASON_DEV_NOSTART,
  289. REASON_DEV_OVER_HEAT,
  290. REASON_DEV_THERMAL_CUTOFF,
  291. REASON_DEV_COMMS_ERROR,
  292. REASON_DEV_THROTTLE,
  293. };
  294. #define REASON_NONE "None"
  295. #define REASON_THREAD_FAIL_INIT_STR "Thread failed to init"
  296. #define REASON_THREAD_ZERO_HASH_STR "Thread got zero hashes"
  297. #define REASON_THREAD_FAIL_QUEUE_STR "Thread failed to queue work"
  298. #define REASON_DEV_SICK_IDLE_60_STR "Device idle for 60s"
  299. #define REASON_DEV_DEAD_IDLE_600_STR "Device dead - idle for 600s"
  300. #define REASON_DEV_NOSTART_STR "Device failed to start"
  301. #define REASON_DEV_OVER_HEAT_STR "Device over heated"
  302. #define REASON_DEV_THERMAL_CUTOFF_STR "Device reached thermal cutoff"
  303. #define REASON_DEV_COMMS_ERROR_STR "Device comms error"
  304. #define REASON_DEV_THROTTLE_STR "Device throttle"
  305. #define REASON_UNKNOWN_STR "Unknown reason - code bug"
  306. #define MIN_SEC_UNSET 99999999
  307. enum {
  308. MSG_NOPOOL = 8,
  309. MSG_MISPID = 25,
  310. MSG_INVPID = 26,
  311. MSG_DUPPID = 74,
  312. MSG_POOLPRIO = 73,
  313. };
  314. struct cgminer_stats {
  315. uint32_t getwork_calls;
  316. struct timeval getwork_wait;
  317. struct timeval getwork_wait_max;
  318. struct timeval getwork_wait_min;
  319. struct timeval _get_start;
  320. };
  321. // Just the actual network getworks to the pool
  322. struct cgminer_pool_stats {
  323. uint32_t getwork_calls;
  324. uint32_t getwork_attempts;
  325. struct timeval getwork_wait;
  326. struct timeval getwork_wait_max;
  327. struct timeval getwork_wait_min;
  328. double getwork_wait_rolling;
  329. bool hadrolltime;
  330. bool canroll;
  331. bool hadexpire;
  332. uint32_t rolltime;
  333. double min_diff;
  334. double max_diff;
  335. double last_diff;
  336. uint32_t min_diff_count;
  337. uint32_t max_diff_count;
  338. uint64_t times_sent;
  339. uint64_t bytes_sent;
  340. uint64_t net_bytes_sent;
  341. uint64_t times_received;
  342. uint64_t bytes_received;
  343. uint64_t net_bytes_received;
  344. };
  345. #define PRIprepr "-6s"
  346. #define PRIpreprv "s"
  347. struct cgpu_info {
  348. int cgminer_id;
  349. int device_line_id;
  350. struct device_drv *drv;
  351. const char *devtype;
  352. int device_id;
  353. char *dev_repr;
  354. char *dev_repr_ns;
  355. const char *name;
  356. int procs;
  357. int proc_id;
  358. char proc_repr[8];
  359. char proc_repr_ns[8];
  360. struct cgpu_info *device;
  361. struct cgpu_info *next_proc;
  362. const char *device_path;
  363. FILE *device_file;
  364. union {
  365. #ifdef USE_ZTEX
  366. struct libztex_device *device_ztex;
  367. #endif
  368. int device_fd;
  369. #ifdef USE_X6500
  370. struct ft232r_device_handle *device_ft232r;
  371. #endif
  372. };
  373. #ifdef USE_AVALON
  374. struct work **works;
  375. int work_array;
  376. int queued;
  377. #endif
  378. #ifdef USE_BITFORCE
  379. struct timeval work_start_tv;
  380. unsigned int wait_ms;
  381. unsigned int sleep_ms;
  382. double avg_wait_f;
  383. unsigned int avg_wait_d;
  384. uint32_t nonces;
  385. bool polling;
  386. #endif
  387. #if defined(USE_BITFORCE) || defined(USE_ICARUS)
  388. bool flash_led;
  389. #endif
  390. void *cgpu_data;
  391. pthread_mutex_t device_mutex;
  392. pthread_cond_t device_cond;
  393. enum dev_enable deven;
  394. int accepted;
  395. int rejected;
  396. int hw_errors;
  397. double rolling;
  398. double total_mhashes;
  399. double utility;
  400. double utility_diff1;
  401. enum alive status;
  402. char init[40];
  403. struct timeval last_message_tv;
  404. int threads;
  405. struct thr_info **thr;
  406. int64_t max_hashes;
  407. const char *kname;
  408. #ifdef HAVE_OPENCL
  409. bool mapped;
  410. int virtual_gpu;
  411. int virtual_adl;
  412. int intensity;
  413. bool dynamic;
  414. cl_uint vwidth;
  415. size_t work_size;
  416. enum cl_kernels kernel;
  417. cl_ulong max_alloc;
  418. #ifdef USE_SCRYPT
  419. int opt_lg, lookup_gap;
  420. size_t opt_tc, thread_concurrency;
  421. size_t shaders;
  422. #endif
  423. struct timeval tv_gpustart;
  424. int intervals;
  425. #endif
  426. float temp;
  427. int cutofftemp;
  428. int targettemp;
  429. #ifdef HAVE_ADL
  430. bool has_adl;
  431. struct gpu_adl adl;
  432. int gpu_engine;
  433. int min_engine;
  434. int gpu_fan;
  435. int min_fan;
  436. int gpu_memclock;
  437. int gpu_memdiff;
  438. int gpu_powertune;
  439. float gpu_vddc;
  440. #endif
  441. int diff1;
  442. double diff_accepted;
  443. double diff_rejected;
  444. int last_share_pool;
  445. time_t last_share_pool_time;
  446. double last_share_diff;
  447. time_t last_device_valid_work;
  448. time_t device_last_well;
  449. time_t device_last_not_well;
  450. enum dev_reason device_not_well_reason;
  451. float reinit_backoff;
  452. int thread_fail_init_count;
  453. int thread_zero_hash_count;
  454. int thread_fail_queue_count;
  455. int dev_sick_idle_60_count;
  456. int dev_dead_idle_600_count;
  457. int dev_nostart_count;
  458. int dev_over_heat_count; // It's a warning but worth knowing
  459. int dev_thermal_cutoff_count;
  460. int dev_comms_error_count;
  461. int dev_throttle_count;
  462. struct cgminer_stats cgminer_stats;
  463. pthread_rwlock_t qlock;
  464. struct work *queued_work;
  465. unsigned int queued_count;
  466. };
  467. extern void renumber_cgpu(struct cgpu_info *);
  468. extern bool add_cgpu(struct cgpu_info*);
  469. struct thread_q {
  470. struct list_head q;
  471. bool frozen;
  472. pthread_mutex_t mutex;
  473. pthread_cond_t cond;
  474. };
  475. enum thr_busy_state {
  476. TBS_IDLE,
  477. TBS_GETTING_RESULTS,
  478. TBS_STARTING_JOB,
  479. };
  480. struct thr_info {
  481. int id;
  482. int device_thread;
  483. bool primary_thread;
  484. bool has_pth;
  485. pthread_t pth;
  486. struct thread_q *q;
  487. struct cgpu_info *cgpu;
  488. void *cgpu_data;
  489. struct timeval last;
  490. struct timeval sick;
  491. bool scanhash_working;
  492. uint64_t hashes_done;
  493. struct timeval tv_hashes_done;
  494. struct timeval tv_lastupdate;
  495. bool pause;
  496. time_t getwork;
  497. double rolling;
  498. // Used by minerloop_async
  499. struct work *prev_work;
  500. struct work *work;
  501. struct work *next_work;
  502. enum thr_busy_state busy_state;
  503. struct timeval tv_morework;
  504. struct work *results_work;
  505. bool _job_transition_in_progress;
  506. bool _proceed_with_new_job;
  507. struct timeval tv_results_jobstart;
  508. struct timeval tv_jobstart;
  509. struct timeval tv_poll;
  510. notifier_t notifier;
  511. bool starting_next_work;
  512. uint32_t _max_nonce;
  513. notifier_t mutex_request;
  514. // Used by minerloop_queue
  515. struct list_head work_list;
  516. bool queue_full;
  517. bool _last_sbr_state;
  518. bool work_restart;
  519. notifier_t work_restart_notifier;
  520. };
  521. extern int thr_info_create(struct thr_info *thr, pthread_attr_t *attr, void *(*start) (void *), void *arg);
  522. extern void thr_info_cancel(struct thr_info *thr);
  523. extern void thr_info_freeze(struct thr_info *thr);
  524. extern void nmsleep(unsigned int msecs);
  525. extern double us_tdiff(struct timeval *end, struct timeval *start);
  526. extern double tdiff(struct timeval *end, struct timeval *start);
  527. struct string_elist {
  528. char *string;
  529. bool free_me;
  530. struct list_head list;
  531. };
  532. static inline void string_elist_add(const char *s, struct list_head *head)
  533. {
  534. struct string_elist *n;
  535. n = calloc(1, sizeof(*n));
  536. n->string = strdup(s);
  537. n->free_me = true;
  538. list_add_tail(&n->list, head);
  539. }
  540. static inline void string_elist_del(struct string_elist *item)
  541. {
  542. if (item->free_me)
  543. free(item->string);
  544. list_del(&item->list);
  545. free(item);
  546. }
  547. static inline uint32_t swab32(uint32_t v)
  548. {
  549. return bswap_32(v);
  550. }
  551. static inline void swap256(void *dest_p, const void *src_p)
  552. {
  553. uint32_t *dest = dest_p;
  554. const uint32_t *src = src_p;
  555. dest[0] = src[7];
  556. dest[1] = src[6];
  557. dest[2] = src[5];
  558. dest[3] = src[4];
  559. dest[4] = src[3];
  560. dest[5] = src[2];
  561. dest[6] = src[1];
  562. dest[7] = src[0];
  563. }
  564. static inline void swap32yes(void*out, const void*in, size_t sz) {
  565. size_t swapcounter = 0;
  566. for (swapcounter = 0; swapcounter < sz; ++swapcounter)
  567. (((uint32_t*)out)[swapcounter]) = swab32(((uint32_t*)in)[swapcounter]);
  568. }
  569. #define LOCAL_swap32(type, var, sz) \
  570. type __swapped_ ## var[sz * 4 / sizeof(type)]; \
  571. swap32yes(__swapped_ ## var, var, sz); \
  572. var = __swapped_ ## var; \
  573. // end
  574. #ifdef WORDS_BIGENDIAN
  575. # define swap32tobe(out, in, sz) ((out == in) ? (void)0 : memmove(out, in, sz))
  576. # define LOCAL_swap32be(type, var, sz) ;
  577. # define swap32tole(out, in, sz) swap32yes(out, in, sz)
  578. # define LOCAL_swap32le(type, var, sz) LOCAL_swap32(type, var, sz)
  579. #else
  580. # define swap32tobe(out, in, sz) swap32yes(out, in, sz)
  581. # define LOCAL_swap32be(type, var, sz) LOCAL_swap32(type, var, sz)
  582. # define swap32tole(out, in, sz) ((out == in) ? (void)0 : memmove(out, in, sz))
  583. # define LOCAL_swap32le(type, var, sz) ;
  584. #endif
  585. static inline void swab256(void *dest_p, const void *src_p)
  586. {
  587. uint32_t *dest = dest_p;
  588. const uint32_t *src = src_p;
  589. dest[0] = swab32(src[7]);
  590. dest[1] = swab32(src[6]);
  591. dest[2] = swab32(src[5]);
  592. dest[3] = swab32(src[4]);
  593. dest[4] = swab32(src[3]);
  594. dest[5] = swab32(src[2]);
  595. dest[6] = swab32(src[1]);
  596. dest[7] = swab32(src[0]);
  597. }
  598. #define flip32(dest_p, src_p) swap32yes(dest_p, src_p, 32 / 4)
  599. extern void quit(int status, const char *format, ...) NORETURN FORMAT_SYNTAX_CHECK(printf, 2, 3);
  600. static inline void mutex_lock(pthread_mutex_t *lock)
  601. {
  602. if (unlikely(pthread_mutex_lock(lock)))
  603. quit(1, "WTF MUTEX ERROR ON LOCK!");
  604. }
  605. static inline void mutex_unlock(pthread_mutex_t *lock)
  606. {
  607. if (unlikely(pthread_mutex_unlock(lock)))
  608. quit(1, "WTF MUTEX ERROR ON UNLOCK!");
  609. }
  610. static inline int mutex_trylock(pthread_mutex_t *lock)
  611. {
  612. return pthread_mutex_trylock(lock);
  613. }
  614. static inline void wr_lock(pthread_rwlock_t *lock)
  615. {
  616. if (unlikely(pthread_rwlock_wrlock(lock)))
  617. quit(1, "WTF WRLOCK ERROR ON LOCK!");
  618. }
  619. static inline void rd_lock(pthread_rwlock_t *lock)
  620. {
  621. if (unlikely(pthread_rwlock_rdlock(lock)))
  622. quit(1, "WTF RDLOCK ERROR ON LOCK!");
  623. }
  624. static inline void rw_unlock(pthread_rwlock_t *lock)
  625. {
  626. if (unlikely(pthread_rwlock_unlock(lock)))
  627. quit(1, "WTF RWLOCK ERROR ON UNLOCK!");
  628. }
  629. static inline void rd_unlock(pthread_rwlock_t *lock)
  630. {
  631. rw_unlock(lock);
  632. }
  633. static inline void wr_unlock(pthread_rwlock_t *lock)
  634. {
  635. rw_unlock(lock);
  636. }
  637. static inline void mutex_init(pthread_mutex_t *lock)
  638. {
  639. if (unlikely(pthread_mutex_init(lock, NULL)))
  640. quit(1, "Failed to pthread_mutex_init");
  641. }
  642. static inline void rwlock_init(pthread_rwlock_t *lock)
  643. {
  644. if (unlikely(pthread_rwlock_init(lock, NULL)))
  645. quit(1, "Failed to pthread_rwlock_init");
  646. }
  647. /* cgminer locks, a write biased variant of rwlocks */
  648. struct cglock {
  649. pthread_mutex_t mutex;
  650. pthread_rwlock_t rwlock;
  651. };
  652. typedef struct cglock cglock_t;
  653. static inline void cglock_init(cglock_t *lock)
  654. {
  655. mutex_init(&lock->mutex);
  656. rwlock_init(&lock->rwlock);
  657. }
  658. /* Read lock variant of cglock */
  659. static inline void cg_rlock(cglock_t *lock)
  660. {
  661. mutex_lock(&lock->mutex);
  662. rd_lock(&lock->rwlock);
  663. mutex_unlock(&lock->mutex);
  664. }
  665. /* Intermediate variant of cglock */
  666. static inline void cg_ilock(cglock_t *lock)
  667. {
  668. mutex_lock(&lock->mutex);
  669. }
  670. /* Upgrade intermediate variant to a write lock */
  671. static inline void cg_ulock(cglock_t *lock)
  672. {
  673. wr_lock(&lock->rwlock);
  674. }
  675. /* Write lock variant of cglock */
  676. static inline void cg_wlock(cglock_t *lock)
  677. {
  678. mutex_lock(&lock->mutex);
  679. wr_lock(&lock->rwlock);
  680. }
  681. /* Downgrade intermediate variant to a read lock */
  682. static inline void cg_dlock(cglock_t *lock)
  683. {
  684. rd_lock(&lock->rwlock);
  685. mutex_unlock(&lock->mutex);
  686. }
  687. static inline void cg_runlock(cglock_t *lock)
  688. {
  689. rd_unlock(&lock->rwlock);
  690. }
  691. static inline void cg_wunlock(cglock_t *lock)
  692. {
  693. wr_unlock(&lock->rwlock);
  694. mutex_unlock(&lock->mutex);
  695. }
  696. struct pool;
  697. extern bool opt_protocol;
  698. extern char *opt_coinbase_sig;
  699. extern bool have_longpoll;
  700. extern int opt_skip_checks;
  701. extern char *opt_kernel_path;
  702. extern char *opt_socks_proxy;
  703. extern char *cgminer_path;
  704. extern bool opt_fail_only;
  705. extern bool opt_autofan;
  706. extern bool opt_autoengine;
  707. extern bool use_curses;
  708. extern char *opt_api_allow;
  709. extern char *opt_api_groups;
  710. extern char *opt_api_description;
  711. extern int opt_api_port;
  712. extern bool opt_api_listen;
  713. extern bool opt_api_network;
  714. extern bool opt_delaynet;
  715. extern bool opt_restart;
  716. extern char *opt_icarus_options;
  717. extern char *opt_icarus_timing;
  718. extern bool opt_worktime;
  719. #ifdef USE_AVALON
  720. extern char *opt_avalon_options;
  721. #endif
  722. #ifdef USE_BITFORCE
  723. extern bool opt_bfl_noncerange;
  724. #endif
  725. extern int swork_id;
  726. extern pthread_rwlock_t netacc_lock;
  727. extern const uint32_t sha256_init_state[];
  728. extern json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass,
  729. const char *rpc_req, bool, bool, int *,
  730. struct pool *pool, bool);
  731. extern bool our_curl_supports_proxy_uris();
  732. extern char *bin2hex(const unsigned char *p, size_t len);
  733. extern bool hex2bin(unsigned char *p, const char *hexstr, size_t len);
  734. typedef bool (*sha256_func)(struct thr_info*, const unsigned char *pmidstate,
  735. unsigned char *pdata,
  736. unsigned char *phash1, unsigned char *phash,
  737. const unsigned char *ptarget,
  738. uint32_t max_nonce,
  739. uint32_t *last_nonce,
  740. uint32_t nonce);
  741. extern bool fulltest(const unsigned char *hash, const unsigned char *target);
  742. extern int opt_queue;
  743. extern int opt_scantime;
  744. extern int opt_expiry;
  745. extern cglock_t control_lock;
  746. extern pthread_mutex_t hash_lock;
  747. extern pthread_mutex_t console_lock;
  748. extern cglock_t ch_lock;
  749. extern pthread_rwlock_t mining_thr_lock;
  750. extern pthread_rwlock_t devices_lock;
  751. extern void thread_reportin(struct thr_info *thr);
  752. extern void thread_reportout(struct thr_info *);
  753. extern void clear_stratum_shares(struct pool *pool);
  754. extern void hashmeter2(struct thr_info *);
  755. extern bool stale_work(struct work *, bool share);
  756. extern bool stale_work_future(struct work *, bool share, unsigned long ustime);
  757. extern void kill_work(void);
  758. extern void app_restart(void);
  759. extern void mt_enable(struct thr_info *thr);
  760. extern void proc_enable(struct cgpu_info *);
  761. extern void reinit_device(struct cgpu_info *cgpu);
  762. #ifdef HAVE_ADL
  763. extern bool gpu_stats(int gpu, float *temp, int *engineclock, int *memclock, float *vddc, int *activity, int *fanspeed, int *fanpercent, int *powertune);
  764. extern int set_fanspeed(int gpu, int iFanSpeed);
  765. extern int set_vddc(int gpu, float fVddc);
  766. extern int set_engineclock(int gpu, int iEngineClock);
  767. extern int set_memoryclock(int gpu, int iMemoryClock);
  768. #endif
  769. extern void api(int thr_id);
  770. extern struct pool *current_pool(void);
  771. extern int enabled_pools;
  772. extern bool detect_stratum(struct pool *pool, char *url);
  773. extern void print_summary(void);
  774. extern struct pool *add_pool(void);
  775. extern bool add_pool_details(struct pool *pool, bool live, char *url, char *user, char *pass);
  776. #define MAX_GPUDEVICES 16
  777. #define MIN_INTENSITY -10
  778. #define _MIN_INTENSITY_STR "-10"
  779. #ifdef USE_SCRYPT
  780. #define MAX_INTENSITY 20
  781. #define _MAX_INTENSITY_STR "20"
  782. #else
  783. #define MAX_INTENSITY 14
  784. #define _MAX_INTENSITY_STR "14"
  785. #endif
  786. extern struct list_head scan_devices;
  787. extern bool opt_force_dev_init;
  788. extern int nDevs;
  789. extern int opt_n_threads;
  790. extern int num_processors;
  791. extern int hw_errors;
  792. extern bool use_syslog;
  793. extern bool opt_quiet;
  794. extern struct thr_info *control_thr;
  795. extern struct thr_info **mining_thr;
  796. extern struct cgpu_info gpus[MAX_GPUDEVICES];
  797. extern int gpu_threads;
  798. #ifdef USE_SCRYPT
  799. extern bool opt_scrypt;
  800. #else
  801. #define opt_scrypt (0)
  802. #endif
  803. extern double total_secs;
  804. extern int mining_threads;
  805. extern struct cgpu_info *cpus;
  806. extern int total_devices;
  807. extern struct cgpu_info **devices;
  808. extern int total_pools;
  809. extern struct pool **pools;
  810. extern const char *algo_names[];
  811. extern enum sha256_algos opt_algo;
  812. extern struct strategies strategies[];
  813. extern enum pool_strategy pool_strategy;
  814. extern int opt_rotate_period;
  815. extern double total_mhashes_done;
  816. extern unsigned int new_blocks;
  817. extern unsigned int found_blocks;
  818. extern int total_accepted, total_rejected, total_diff1;;
  819. extern int total_getworks, total_stale, total_discarded;
  820. extern uint64_t total_bytes_xfer;
  821. extern double total_diff_accepted, total_diff_rejected, total_diff_stale;
  822. extern unsigned int local_work;
  823. extern unsigned int total_go, total_ro;
  824. extern const int opt_cutofftemp;
  825. extern int opt_hysteresis;
  826. extern int opt_fail_pause;
  827. extern int opt_log_interval;
  828. extern unsigned long long global_hashrate;
  829. extern char *current_fullhash;
  830. extern double current_diff;
  831. extern uint64_t best_diff;
  832. extern struct timeval block_timeval;
  833. #ifdef HAVE_OPENCL
  834. typedef struct {
  835. cl_uint ctx_a; cl_uint ctx_b; cl_uint ctx_c; cl_uint ctx_d;
  836. cl_uint ctx_e; cl_uint ctx_f; cl_uint ctx_g; cl_uint ctx_h;
  837. cl_uint cty_a; cl_uint cty_b; cl_uint cty_c; cl_uint cty_d;
  838. cl_uint cty_e; cl_uint cty_f; cl_uint cty_g; cl_uint cty_h;
  839. cl_uint merkle; cl_uint ntime; cl_uint nbits; cl_uint nonce;
  840. cl_uint fW0; cl_uint fW1; cl_uint fW2; cl_uint fW3; cl_uint fW15;
  841. cl_uint fW01r; cl_uint fcty_e; cl_uint fcty_e2;
  842. cl_uint W16; cl_uint W17; cl_uint W2;
  843. cl_uint PreVal4; cl_uint T1;
  844. cl_uint C1addK5; cl_uint D1A; cl_uint W2A; cl_uint W17_2;
  845. cl_uint PreVal4addT1; cl_uint T1substate0;
  846. cl_uint PreVal4_2;
  847. cl_uint PreVal0;
  848. cl_uint PreW18;
  849. cl_uint PreW19;
  850. cl_uint PreW31;
  851. cl_uint PreW32;
  852. /* For diakgcn */
  853. cl_uint B1addK6, PreVal0addK7, W16addK16, W17addK17;
  854. cl_uint zeroA, zeroB;
  855. cl_uint oneA, twoA, threeA, fourA, fiveA, sixA, sevenA;
  856. #ifdef USE_SCRYPT
  857. struct work *work;
  858. #endif
  859. } dev_blk_ctx;
  860. #else
  861. typedef struct {
  862. uint32_t nonce;
  863. } dev_blk_ctx;
  864. #endif
  865. struct curl_ent {
  866. CURL *curl;
  867. struct list_head node;
  868. struct timeval tv;
  869. };
  870. /* Disabled needs to be the lowest enum as a freshly calloced value will then
  871. * equal disabled */
  872. enum pool_enable {
  873. POOL_DISABLED,
  874. POOL_ENABLED,
  875. POOL_REJECTING,
  876. };
  877. enum pool_protocol {
  878. PLP_NONE,
  879. PLP_GETWORK,
  880. PLP_GETBLOCKTEMPLATE,
  881. };
  882. struct stratum_work {
  883. char *job_id;
  884. char *prev_hash;
  885. char *coinbase1;
  886. char *coinbase2;
  887. char **merkle;
  888. char *bbversion;
  889. char *nbit;
  890. char *ntime;
  891. bool clean;
  892. size_t cb1_len;
  893. size_t cb2_len;
  894. size_t cb_len;
  895. size_t header_len;
  896. int merkles;
  897. double diff;
  898. bool transparency_probed;
  899. time_t transparency_time;
  900. bool opaque;
  901. };
  902. #define RBUFSIZE 8192
  903. #define RECVSIZE (RBUFSIZE - 4)
  904. struct pool {
  905. int pool_no;
  906. int prio;
  907. int accepted, rejected;
  908. int seq_rejects;
  909. int seq_getfails;
  910. int solved;
  911. int diff1;
  912. char diff[8];
  913. double diff_accepted;
  914. double diff_rejected;
  915. double diff_stale;
  916. bool submit_fail;
  917. bool idle;
  918. bool lagging;
  919. bool probed;
  920. int force_rollntime;
  921. enum pool_enable enabled;
  922. bool submit_old;
  923. bool removed;
  924. bool lp_started;
  925. unsigned char work_restart_id;
  926. uint32_t block_id;
  927. enum pool_protocol proto;
  928. char *hdr_path;
  929. char *lp_url;
  930. char *lp_id;
  931. enum pool_protocol lp_proto;
  932. curl_socket_t lp_socket;
  933. unsigned int getwork_requested;
  934. unsigned int stale_shares;
  935. unsigned int discarded_work;
  936. unsigned int getfail_occasions;
  937. unsigned int remotefail_occasions;
  938. struct timeval tv_idle;
  939. double utility;
  940. int last_shares, shares;
  941. char *rpc_url;
  942. char *rpc_userpass;
  943. char *rpc_user, *rpc_pass;
  944. char *rpc_proxy;
  945. pthread_mutex_t pool_lock;
  946. cglock_t data_lock;
  947. struct thread_q *submit_q;
  948. struct thread_q *getwork_q;
  949. pthread_t longpoll_thread;
  950. pthread_t test_thread;
  951. bool testing;
  952. int curls;
  953. pthread_cond_t cr_cond;
  954. struct list_head curlring;
  955. struct submit_work_state *sws_waiting_on_curl;
  956. time_t last_work_time;
  957. time_t last_share_time;
  958. double last_share_diff;
  959. uint64_t best_diff;
  960. struct cgminer_stats cgminer_stats;
  961. struct cgminer_pool_stats cgminer_pool_stats;
  962. /* Stratum variables */
  963. char *stratum_url;
  964. char *stratum_port;
  965. CURL *stratum_curl;
  966. SOCKETTYPE sock;
  967. char *sockbuf;
  968. size_t sockbuf_size;
  969. char *sockaddr_url; /* stripped url used for sockaddr */
  970. char *nonce1;
  971. size_t n1_len;
  972. uint32_t nonce2;
  973. int n2size;
  974. char *sessionid;
  975. bool has_stratum;
  976. bool stratum_active;
  977. bool stratum_init;
  978. bool stratum_notify;
  979. struct stratum_work swork;
  980. pthread_t stratum_thread;
  981. pthread_mutex_t stratum_lock;
  982. char *admin_msg;
  983. pthread_mutex_t last_work_lock;
  984. struct work *last_work_copy;
  985. };
  986. #define GETWORK_MODE_TESTPOOL 'T'
  987. #define GETWORK_MODE_POOL 'P'
  988. #define GETWORK_MODE_LP 'L'
  989. #define GETWORK_MODE_BENCHMARK 'B'
  990. #define GETWORK_MODE_STRATUM 'S'
  991. #define GETWORK_MODE_GBT 'G'
  992. struct work {
  993. unsigned char data[128];
  994. unsigned char midstate[32];
  995. unsigned char target[32];
  996. unsigned char hash[32];
  997. uint64_t share_diff;
  998. int rolls;
  999. dev_blk_ctx blk;
  1000. struct thr_info *thr;
  1001. int thr_id;
  1002. struct pool *pool;
  1003. struct timeval tv_staged;
  1004. bool mined;
  1005. bool clone;
  1006. bool cloned;
  1007. int rolltime;
  1008. bool longpoll;
  1009. bool stale;
  1010. bool mandatory;
  1011. bool block;
  1012. bool queued;
  1013. bool stratum;
  1014. char *job_id;
  1015. char *nonce2;
  1016. char *ntime;
  1017. double sdiff;
  1018. char *nonce1;
  1019. unsigned char work_restart_id;
  1020. int id;
  1021. UT_hash_handle hh;
  1022. double work_difficulty;
  1023. // Allow devices to identify work if multiple sub-devices
  1024. // DEPRECATED: New code should be using multiple processors instead
  1025. char subid;
  1026. blktemplate_t *tmpl;
  1027. int *tmpl_refcount;
  1028. unsigned int dataid;
  1029. bool do_foreign_submit;
  1030. struct timeval tv_getwork;
  1031. struct timeval tv_getwork_reply;
  1032. struct timeval tv_cloned;
  1033. struct timeval tv_work_start;
  1034. struct timeval tv_work_found;
  1035. char getwork_mode;
  1036. /* Used to queue shares in submit_waiting */
  1037. struct list_head list;
  1038. };
  1039. extern void get_datestamp(char *, struct timeval *);
  1040. enum test_nonce2_result {
  1041. TNR_GOOD,
  1042. TNR_HIGH,
  1043. TNR_BAD,
  1044. };
  1045. extern enum test_nonce2_result _test_nonce2(struct work *, uint32_t nonce, bool checktarget);
  1046. #define test_nonce(work, nonce, checktarget) (_test_nonce2(work, nonce, checktarget) == TNR_GOOD)
  1047. #define test_nonce2(work, nonce) (_test_nonce2(work, nonce, true))
  1048. extern void submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce);
  1049. extern struct work *get_queued(struct cgpu_info *cgpu);
  1050. extern struct work *__find_work_bymidstate(struct work *que, char *midstate, size_t midstatelen, char *data, int offset, size_t datalen);
  1051. extern struct work *find_queued_work_bymidstate(struct cgpu_info *cgpu, char *midstate, size_t midstatelen, char *data, int offset, size_t datalen);
  1052. extern void work_completed(struct cgpu_info *cgpu, struct work *work);
  1053. extern bool abandon_work(struct work *, struct timeval *work_runtime, uint64_t hashes);
  1054. extern void hash_queued_work(struct thr_info *mythr);
  1055. extern void tailsprintf(char *f, const char *fmt, ...) FORMAT_SYNTAX_CHECK(printf, 2, 3);
  1056. extern void wlog(const char *f, ...) FORMAT_SYNTAX_CHECK(printf, 1, 2);
  1057. extern void wlogprint(const char *f, ...) FORMAT_SYNTAX_CHECK(printf, 1, 2);
  1058. extern int curses_int(const char *query);
  1059. extern char *curses_input(const char *query);
  1060. extern void kill_work(void);
  1061. extern int prioritize_pools(char *param, int *pid);
  1062. extern void validate_pool_priorities(void);
  1063. extern void switch_pools(struct pool *selected);
  1064. extern void remove_pool(struct pool *pool);
  1065. extern void write_config(FILE *fcfg);
  1066. extern void zero_bestshare(void);
  1067. extern void zero_stats(void);
  1068. extern void default_save_file(char *filename);
  1069. extern bool log_curses_only(int prio, const char *f, va_list ap) FORMAT_SYNTAX_CHECK(printf, 2, 0);
  1070. extern void clear_logwin(void);
  1071. extern bool pool_tclear(struct pool *pool, bool *var);
  1072. extern struct thread_q *tq_new(void);
  1073. extern void tq_free(struct thread_q *tq);
  1074. extern bool tq_push(struct thread_q *tq, void *data);
  1075. extern void *tq_pop(struct thread_q *tq, const struct timespec *abstime);
  1076. extern void tq_freeze(struct thread_q *tq);
  1077. extern void tq_thaw(struct thread_q *tq);
  1078. extern bool successful_connect;
  1079. extern void adl(void);
  1080. extern void clean_work(struct work *work);
  1081. extern void free_work(struct work *work);
  1082. extern void __copy_work(struct work *work, const struct work *base_work);
  1083. extern struct work *copy_work(const struct work *base_work);
  1084. extern struct thr_info *get_thread(int thr_id);
  1085. extern struct cgpu_info *get_devices(int id);
  1086. enum api_data_type {
  1087. API_ESCAPE,
  1088. API_STRING,
  1089. API_CONST,
  1090. API_INT,
  1091. API_UINT,
  1092. API_UINT32,
  1093. API_UINT64,
  1094. API_DOUBLE,
  1095. API_ELAPSED,
  1096. API_BOOL,
  1097. API_TIMEVAL,
  1098. API_TIME,
  1099. API_MHS,
  1100. API_MHTOTAL,
  1101. API_TEMP,
  1102. API_UTILITY,
  1103. API_FREQ,
  1104. API_VOLTS,
  1105. API_HS,
  1106. API_DIFF,
  1107. API_JSON,
  1108. };
  1109. struct api_data {
  1110. enum api_data_type type;
  1111. char *name;
  1112. void *data;
  1113. bool data_was_malloc;
  1114. struct api_data *prev;
  1115. struct api_data *next;
  1116. };
  1117. extern struct api_data *api_add_escape(struct api_data *root, char *name, char *data, bool copy_data);
  1118. extern struct api_data *api_add_string(struct api_data *root, char *name, const char *data, bool copy_data);
  1119. extern struct api_data *api_add_const(struct api_data *root, char *name, const char *data, bool copy_data);
  1120. extern struct api_data *api_add_int(struct api_data *root, char *name, int *data, bool copy_data);
  1121. extern struct api_data *api_add_uint(struct api_data *root, char *name, unsigned int *data, bool copy_data);
  1122. extern struct api_data *api_add_uint32(struct api_data *root, char *name, uint32_t *data, bool copy_data);
  1123. extern struct api_data *api_add_uint64(struct api_data *root, char *name, uint64_t *data, bool copy_data);
  1124. extern struct api_data *api_add_double(struct api_data *root, char *name, double *data, bool copy_data);
  1125. extern struct api_data *api_add_elapsed(struct api_data *root, char *name, double *data, bool copy_data);
  1126. extern struct api_data *api_add_bool(struct api_data *root, char *name, bool *data, bool copy_data);
  1127. extern struct api_data *api_add_timeval(struct api_data *root, char *name, struct timeval *data, bool copy_data);
  1128. extern struct api_data *api_add_time(struct api_data *root, char *name, time_t *data, bool copy_data);
  1129. extern struct api_data *api_add_mhs(struct api_data *root, char *name, double *data, bool copy_data);
  1130. extern struct api_data *api_add_mhstotal(struct api_data *root, char *name, double *data, bool copy_data);
  1131. extern struct api_data *api_add_temp(struct api_data *root, char *name, float *data, bool copy_data);
  1132. extern struct api_data *api_add_utility(struct api_data *root, char *name, double *data, bool copy_data);
  1133. extern struct api_data *api_add_freq(struct api_data *root, char *name, double *data, bool copy_data);
  1134. extern struct api_data *api_add_volts(struct api_data *root, char *name, float *data, bool copy_data);
  1135. extern struct api_data *api_add_hs(struct api_data *root, char *name, double *data, bool copy_data);
  1136. extern struct api_data *api_add_diff(struct api_data *root, char *name, double *data, bool copy_data);
  1137. extern struct api_data *api_add_json(struct api_data *root, char *name, json_t *data, bool copy_data);
  1138. #endif /* __MINER_H__ */