miner.h 31 KB

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