miner.h 32 KB

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