miner.h 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322
  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. int results;
  378. #endif
  379. #ifdef USE_BITFORCE
  380. struct timeval work_start_tv;
  381. unsigned int wait_ms;
  382. unsigned int sleep_ms;
  383. double avg_wait_f;
  384. unsigned int avg_wait_d;
  385. uint32_t nonces;
  386. bool polling;
  387. #endif
  388. #if defined(USE_BITFORCE) || defined(USE_ICARUS)
  389. bool flash_led;
  390. #endif
  391. void *cgpu_data;
  392. pthread_mutex_t device_mutex;
  393. pthread_cond_t device_cond;
  394. enum dev_enable deven;
  395. int accepted;
  396. int rejected;
  397. int stale;
  398. int hw_errors;
  399. double rolling;
  400. double total_mhashes;
  401. double utility;
  402. double utility_diff1;
  403. enum alive status;
  404. char init[40];
  405. struct timeval last_message_tv;
  406. int threads;
  407. struct thr_info **thr;
  408. int64_t max_hashes;
  409. const char *kname;
  410. #ifdef HAVE_OPENCL
  411. bool mapped;
  412. int virtual_gpu;
  413. int virtual_adl;
  414. int intensity;
  415. bool dynamic;
  416. cl_uint vwidth;
  417. size_t work_size;
  418. enum cl_kernels kernel;
  419. cl_ulong max_alloc;
  420. #ifdef USE_SCRYPT
  421. int opt_lg, lookup_gap;
  422. size_t opt_tc, thread_concurrency;
  423. size_t shaders;
  424. #endif
  425. struct timeval tv_gpustart;
  426. int intervals;
  427. #endif
  428. float temp;
  429. int cutofftemp;
  430. int targettemp;
  431. #ifdef HAVE_ADL
  432. bool has_adl;
  433. struct gpu_adl adl;
  434. int gpu_engine;
  435. int min_engine;
  436. int gpu_fan;
  437. int min_fan;
  438. int gpu_memclock;
  439. int gpu_memdiff;
  440. int gpu_powertune;
  441. float gpu_vddc;
  442. #endif
  443. int diff1;
  444. double diff_accepted;
  445. double diff_rejected;
  446. int last_share_pool;
  447. time_t last_share_pool_time;
  448. double last_share_diff;
  449. time_t last_device_valid_work;
  450. time_t device_last_well;
  451. time_t device_last_not_well;
  452. enum dev_reason device_not_well_reason;
  453. float reinit_backoff;
  454. int thread_fail_init_count;
  455. int thread_zero_hash_count;
  456. int thread_fail_queue_count;
  457. int dev_sick_idle_60_count;
  458. int dev_dead_idle_600_count;
  459. int dev_nostart_count;
  460. int dev_over_heat_count; // It's a warning but worth knowing
  461. int dev_thermal_cutoff_count;
  462. int dev_comms_error_count;
  463. int dev_throttle_count;
  464. struct cgminer_stats cgminer_stats;
  465. pthread_rwlock_t qlock;
  466. struct work *queued_work;
  467. unsigned int queued_count;
  468. };
  469. extern void renumber_cgpu(struct cgpu_info *);
  470. extern bool add_cgpu(struct cgpu_info*);
  471. struct thread_q {
  472. struct list_head q;
  473. bool frozen;
  474. pthread_mutex_t mutex;
  475. pthread_cond_t cond;
  476. };
  477. enum thr_busy_state {
  478. TBS_IDLE,
  479. TBS_GETTING_RESULTS,
  480. TBS_STARTING_JOB,
  481. };
  482. struct thr_info {
  483. int id;
  484. int device_thread;
  485. bool primary_thread;
  486. bool has_pth;
  487. pthread_t pth;
  488. struct thread_q *q;
  489. struct cgpu_info *cgpu;
  490. void *cgpu_data;
  491. struct timeval last;
  492. struct timeval sick;
  493. bool scanhash_working;
  494. uint64_t hashes_done;
  495. struct timeval tv_hashes_done;
  496. struct timeval tv_lastupdate;
  497. bool pause;
  498. time_t getwork;
  499. double rolling;
  500. // Used by minerloop_async
  501. struct work *prev_work;
  502. struct work *work;
  503. struct work *next_work;
  504. enum thr_busy_state busy_state;
  505. struct timeval tv_morework;
  506. struct work *results_work;
  507. bool _job_transition_in_progress;
  508. bool _proceed_with_new_job;
  509. struct timeval tv_results_jobstart;
  510. struct timeval tv_jobstart;
  511. struct timeval tv_poll;
  512. notifier_t notifier;
  513. bool starting_next_work;
  514. uint32_t _max_nonce;
  515. notifier_t mutex_request;
  516. // Used by minerloop_queue
  517. struct list_head work_list;
  518. bool queue_full;
  519. bool _last_sbr_state;
  520. bool work_restart;
  521. notifier_t work_restart_notifier;
  522. };
  523. struct string_elist {
  524. char *string;
  525. bool free_me;
  526. struct list_head list;
  527. };
  528. static inline void string_elist_add(const char *s, struct list_head *head)
  529. {
  530. struct string_elist *n;
  531. n = calloc(1, sizeof(*n));
  532. n->string = strdup(s);
  533. n->free_me = true;
  534. list_add_tail(&n->list, head);
  535. }
  536. static inline void string_elist_del(struct string_elist *item)
  537. {
  538. if (item->free_me)
  539. free(item->string);
  540. list_del(&item->list);
  541. free(item);
  542. }
  543. static inline uint32_t swab32(uint32_t v)
  544. {
  545. return bswap_32(v);
  546. }
  547. static inline void swap256(void *dest_p, const void *src_p)
  548. {
  549. uint32_t *dest = dest_p;
  550. const uint32_t *src = src_p;
  551. dest[0] = src[7];
  552. dest[1] = src[6];
  553. dest[2] = src[5];
  554. dest[3] = src[4];
  555. dest[4] = src[3];
  556. dest[5] = src[2];
  557. dest[6] = src[1];
  558. dest[7] = src[0];
  559. }
  560. static inline void swap32yes(void*out, const void*in, size_t sz) {
  561. size_t swapcounter = 0;
  562. for (swapcounter = 0; swapcounter < sz; ++swapcounter)
  563. (((uint32_t*)out)[swapcounter]) = swab32(((uint32_t*)in)[swapcounter]);
  564. }
  565. #define LOCAL_swap32(type, var, sz) \
  566. type __swapped_ ## var[sz * 4 / sizeof(type)]; \
  567. swap32yes(__swapped_ ## var, var, sz); \
  568. var = __swapped_ ## var; \
  569. // end
  570. #ifdef WORDS_BIGENDIAN
  571. # define swap32tobe(out, in, sz) ((out == in) ? (void)0 : memmove(out, in, sz))
  572. # define LOCAL_swap32be(type, var, sz) ;
  573. # define swap32tole(out, in, sz) swap32yes(out, in, sz)
  574. # define LOCAL_swap32le(type, var, sz) LOCAL_swap32(type, var, sz)
  575. #else
  576. # define swap32tobe(out, in, sz) swap32yes(out, in, sz)
  577. # define LOCAL_swap32be(type, var, sz) LOCAL_swap32(type, var, sz)
  578. # define swap32tole(out, in, sz) ((out == in) ? (void)0 : memmove(out, in, sz))
  579. # define LOCAL_swap32le(type, var, sz) ;
  580. #endif
  581. static inline void swab256(void *dest_p, const void *src_p)
  582. {
  583. uint32_t *dest = dest_p;
  584. const uint32_t *src = src_p;
  585. dest[0] = swab32(src[7]);
  586. dest[1] = swab32(src[6]);
  587. dest[2] = swab32(src[5]);
  588. dest[3] = swab32(src[4]);
  589. dest[4] = swab32(src[3]);
  590. dest[5] = swab32(src[2]);
  591. dest[6] = swab32(src[1]);
  592. dest[7] = swab32(src[0]);
  593. }
  594. #define flip32(dest_p, src_p) swap32yes(dest_p, src_p, 32 / 4)
  595. extern void quit(int status, const char *format, ...) NORETURN FORMAT_SYNTAX_CHECK(printf, 2, 3);
  596. static inline void mutex_lock(pthread_mutex_t *lock)
  597. {
  598. if (unlikely(pthread_mutex_lock(lock)))
  599. quit(1, "WTF MUTEX ERROR ON LOCK!");
  600. }
  601. static inline void mutex_unlock(pthread_mutex_t *lock)
  602. {
  603. if (unlikely(pthread_mutex_unlock(lock)))
  604. quit(1, "WTF MUTEX ERROR ON UNLOCK!");
  605. }
  606. static inline int mutex_trylock(pthread_mutex_t *lock)
  607. {
  608. return pthread_mutex_trylock(lock);
  609. }
  610. static inline void wr_lock(pthread_rwlock_t *lock)
  611. {
  612. if (unlikely(pthread_rwlock_wrlock(lock)))
  613. quit(1, "WTF WRLOCK ERROR ON LOCK!");
  614. }
  615. static inline void rd_lock(pthread_rwlock_t *lock)
  616. {
  617. if (unlikely(pthread_rwlock_rdlock(lock)))
  618. quit(1, "WTF RDLOCK ERROR ON LOCK!");
  619. }
  620. static inline void rw_unlock(pthread_rwlock_t *lock)
  621. {
  622. if (unlikely(pthread_rwlock_unlock(lock)))
  623. quit(1, "WTF RWLOCK ERROR ON UNLOCK!");
  624. }
  625. static inline void rd_unlock(pthread_rwlock_t *lock)
  626. {
  627. rw_unlock(lock);
  628. }
  629. static inline void wr_unlock(pthread_rwlock_t *lock)
  630. {
  631. rw_unlock(lock);
  632. }
  633. static inline void mutex_init(pthread_mutex_t *lock)
  634. {
  635. if (unlikely(pthread_mutex_init(lock, NULL)))
  636. quit(1, "Failed to pthread_mutex_init");
  637. }
  638. static inline void rwlock_init(pthread_rwlock_t *lock)
  639. {
  640. if (unlikely(pthread_rwlock_init(lock, NULL)))
  641. quit(1, "Failed to pthread_rwlock_init");
  642. }
  643. /* cgminer locks, a write biased variant of rwlocks */
  644. struct cglock {
  645. pthread_mutex_t mutex;
  646. pthread_rwlock_t rwlock;
  647. };
  648. typedef struct cglock cglock_t;
  649. static inline void cglock_init(cglock_t *lock)
  650. {
  651. mutex_init(&lock->mutex);
  652. rwlock_init(&lock->rwlock);
  653. }
  654. /* Read lock variant of cglock */
  655. static inline void cg_rlock(cglock_t *lock)
  656. {
  657. mutex_lock(&lock->mutex);
  658. rd_lock(&lock->rwlock);
  659. mutex_unlock(&lock->mutex);
  660. }
  661. /* Intermediate variant of cglock */
  662. static inline void cg_ilock(cglock_t *lock)
  663. {
  664. mutex_lock(&lock->mutex);
  665. }
  666. /* Upgrade intermediate variant to a write lock */
  667. static inline void cg_ulock(cglock_t *lock)
  668. {
  669. wr_lock(&lock->rwlock);
  670. }
  671. /* Write lock variant of cglock */
  672. static inline void cg_wlock(cglock_t *lock)
  673. {
  674. mutex_lock(&lock->mutex);
  675. wr_lock(&lock->rwlock);
  676. }
  677. /* Downgrade intermediate variant to a read lock */
  678. static inline void cg_dlock(cglock_t *lock)
  679. {
  680. rd_lock(&lock->rwlock);
  681. mutex_unlock(&lock->mutex);
  682. }
  683. static inline void cg_runlock(cglock_t *lock)
  684. {
  685. rd_unlock(&lock->rwlock);
  686. }
  687. static inline void cg_wunlock(cglock_t *lock)
  688. {
  689. wr_unlock(&lock->rwlock);
  690. mutex_unlock(&lock->mutex);
  691. }
  692. struct pool;
  693. extern bool opt_protocol;
  694. extern char *opt_coinbase_sig;
  695. extern bool have_longpoll;
  696. extern int opt_skip_checks;
  697. extern char *opt_kernel_path;
  698. extern char *opt_socks_proxy;
  699. extern char *cgminer_path;
  700. extern bool opt_fail_only;
  701. extern bool opt_autofan;
  702. extern bool opt_autoengine;
  703. extern bool use_curses;
  704. extern char *opt_api_allow;
  705. extern char *opt_api_groups;
  706. extern char *opt_api_description;
  707. extern int opt_api_port;
  708. extern bool opt_api_listen;
  709. extern bool opt_api_network;
  710. extern bool opt_delaynet;
  711. extern bool opt_restart;
  712. extern char *opt_icarus_options;
  713. extern char *opt_icarus_timing;
  714. extern bool opt_worktime;
  715. #ifdef USE_AVALON
  716. extern char *opt_avalon_options;
  717. #endif
  718. #ifdef USE_BITFORCE
  719. extern bool opt_bfl_noncerange;
  720. #endif
  721. extern int swork_id;
  722. extern pthread_rwlock_t netacc_lock;
  723. extern const uint32_t sha256_init_state[];
  724. extern json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass,
  725. const char *rpc_req, bool, bool, int *,
  726. struct pool *pool, bool);
  727. extern bool our_curl_supports_proxy_uris();
  728. extern char *bin2hex(const unsigned char *p, size_t len);
  729. extern bool hex2bin(unsigned char *p, const char *hexstr, size_t len);
  730. typedef bool (*sha256_func)(struct thr_info*, const unsigned char *pmidstate,
  731. unsigned char *pdata,
  732. unsigned char *phash1, unsigned char *phash,
  733. const unsigned char *ptarget,
  734. uint32_t max_nonce,
  735. uint32_t *last_nonce,
  736. uint32_t nonce);
  737. extern bool fulltest(const unsigned char *hash, const unsigned char *target);
  738. extern int opt_queue;
  739. extern int opt_scantime;
  740. extern int opt_expiry;
  741. extern cglock_t control_lock;
  742. extern pthread_mutex_t stats_lock;
  743. extern pthread_mutex_t hash_lock;
  744. extern pthread_mutex_t console_lock;
  745. extern cglock_t ch_lock;
  746. extern pthread_rwlock_t mining_thr_lock;
  747. extern pthread_rwlock_t devices_lock;
  748. extern void thread_reportin(struct thr_info *thr);
  749. extern void thread_reportout(struct thr_info *);
  750. extern void clear_stratum_shares(struct pool *pool);
  751. extern void hashmeter2(struct thr_info *);
  752. extern bool stale_work(struct work *, bool share);
  753. extern bool stale_work_future(struct work *, bool share, unsigned long ustime);
  754. extern void set_target(unsigned char *dest_target, double diff);
  755. extern void kill_work(void);
  756. extern void app_restart(void);
  757. extern void mt_enable(struct thr_info *thr);
  758. extern void proc_enable(struct cgpu_info *);
  759. extern void reinit_device(struct cgpu_info *cgpu);
  760. #ifdef HAVE_ADL
  761. extern bool gpu_stats(int gpu, float *temp, int *engineclock, int *memclock, float *vddc, int *activity, int *fanspeed, int *fanpercent, int *powertune);
  762. extern int set_fanspeed(int gpu, int iFanSpeed);
  763. extern int set_vddc(int gpu, float fVddc);
  764. extern int set_engineclock(int gpu, int iEngineClock);
  765. extern int set_memoryclock(int gpu, int iMemoryClock);
  766. #endif
  767. extern void api(int thr_id);
  768. extern struct pool *current_pool(void);
  769. extern int enabled_pools;
  770. extern bool detect_stratum(struct pool *pool, char *url);
  771. extern void print_summary(void);
  772. extern struct pool *add_pool(void);
  773. extern bool add_pool_details(struct pool *pool, bool live, char *url, char *user, char *pass);
  774. #define MAX_GPUDEVICES 16
  775. #define MIN_INTENSITY -10
  776. #define _MIN_INTENSITY_STR "-10"
  777. #ifdef USE_SCRYPT
  778. #define MAX_INTENSITY 20
  779. #define _MAX_INTENSITY_STR "20"
  780. #else
  781. #define MAX_INTENSITY 14
  782. #define _MAX_INTENSITY_STR "14"
  783. #endif
  784. extern struct list_head scan_devices;
  785. extern bool opt_force_dev_init;
  786. extern int nDevs;
  787. extern int opt_n_threads;
  788. extern int num_processors;
  789. extern int hw_errors;
  790. extern bool use_syslog;
  791. extern bool opt_quiet;
  792. extern struct thr_info *control_thr;
  793. extern struct thr_info **mining_thr;
  794. extern struct cgpu_info gpus[MAX_GPUDEVICES];
  795. extern int gpu_threads;
  796. #ifdef USE_SCRYPT
  797. extern bool opt_scrypt;
  798. #else
  799. #define opt_scrypt (0)
  800. #endif
  801. extern double total_secs;
  802. extern int mining_threads;
  803. extern struct cgpu_info *cpus;
  804. extern int total_devices;
  805. extern struct cgpu_info **devices;
  806. extern int total_pools;
  807. extern struct pool **pools;
  808. extern const char *algo_names[];
  809. extern enum sha256_algos opt_algo;
  810. extern struct strategies strategies[];
  811. extern enum pool_strategy pool_strategy;
  812. extern int opt_rotate_period;
  813. extern double total_mhashes_done;
  814. extern unsigned int new_blocks;
  815. extern unsigned int found_blocks;
  816. extern int total_accepted, total_rejected, total_diff1;;
  817. extern int total_getworks, total_stale, total_discarded;
  818. extern uint64_t total_bytes_xfer;
  819. extern double total_diff_accepted, total_diff_rejected, total_diff_stale;
  820. extern unsigned int local_work;
  821. extern unsigned int total_go, total_ro;
  822. extern const int opt_cutofftemp;
  823. extern int opt_hysteresis;
  824. extern int opt_fail_pause;
  825. extern int opt_log_interval;
  826. extern unsigned long long global_hashrate;
  827. extern char *current_fullhash;
  828. extern double current_diff;
  829. extern uint64_t best_diff;
  830. extern struct timeval block_timeval;
  831. #ifdef HAVE_OPENCL
  832. typedef struct {
  833. cl_uint ctx_a; cl_uint ctx_b; cl_uint ctx_c; cl_uint ctx_d;
  834. cl_uint ctx_e; cl_uint ctx_f; cl_uint ctx_g; cl_uint ctx_h;
  835. cl_uint cty_a; cl_uint cty_b; cl_uint cty_c; cl_uint cty_d;
  836. cl_uint cty_e; cl_uint cty_f; cl_uint cty_g; cl_uint cty_h;
  837. cl_uint merkle; cl_uint ntime; cl_uint nbits; cl_uint nonce;
  838. cl_uint fW0; cl_uint fW1; cl_uint fW2; cl_uint fW3; cl_uint fW15;
  839. cl_uint fW01r; cl_uint fcty_e; cl_uint fcty_e2;
  840. cl_uint W16; cl_uint W17; cl_uint W2;
  841. cl_uint PreVal4; cl_uint T1;
  842. cl_uint C1addK5; cl_uint D1A; cl_uint W2A; cl_uint W17_2;
  843. cl_uint PreVal4addT1; cl_uint T1substate0;
  844. cl_uint PreVal4_2;
  845. cl_uint PreVal0;
  846. cl_uint PreW18;
  847. cl_uint PreW19;
  848. cl_uint PreW31;
  849. cl_uint PreW32;
  850. /* For diakgcn */
  851. cl_uint B1addK6, PreVal0addK7, W16addK16, W17addK17;
  852. cl_uint zeroA, zeroB;
  853. cl_uint oneA, twoA, threeA, fourA, fiveA, sixA, sevenA;
  854. #ifdef USE_SCRYPT
  855. struct work *work;
  856. #endif
  857. } dev_blk_ctx;
  858. #else
  859. typedef struct {
  860. uint32_t nonce;
  861. } dev_blk_ctx;
  862. #endif
  863. struct curl_ent {
  864. CURL *curl;
  865. struct list_head node;
  866. struct timeval tv;
  867. };
  868. /* Disabled needs to be the lowest enum as a freshly calloced value will then
  869. * equal disabled */
  870. enum pool_enable {
  871. POOL_DISABLED,
  872. POOL_ENABLED,
  873. POOL_REJECTING,
  874. };
  875. enum pool_protocol {
  876. PLP_NONE,
  877. PLP_GETWORK,
  878. PLP_GETBLOCKTEMPLATE,
  879. };
  880. struct stratum_work {
  881. char *job_id;
  882. char *prev_hash;
  883. char *coinbase1;
  884. char *coinbase2;
  885. char **merkle;
  886. char *bbversion;
  887. char *nbit;
  888. char *ntime;
  889. bool clean;
  890. size_t cb1_len;
  891. size_t cb2_len;
  892. size_t cb_len;
  893. size_t header_len;
  894. int merkles;
  895. double diff;
  896. bool transparency_probed;
  897. time_t transparency_time;
  898. bool opaque;
  899. };
  900. #define RBUFSIZE 8192
  901. #define RECVSIZE (RBUFSIZE - 4)
  902. struct pool {
  903. int pool_no;
  904. int prio;
  905. int accepted, rejected;
  906. int seq_rejects;
  907. int seq_getfails;
  908. int solved;
  909. int diff1;
  910. char diff[8];
  911. double diff_accepted;
  912. double diff_rejected;
  913. double diff_stale;
  914. bool submit_fail;
  915. bool idle;
  916. bool lagging;
  917. bool probed;
  918. int force_rollntime;
  919. enum pool_enable enabled;
  920. bool submit_old;
  921. bool removed;
  922. bool lp_started;
  923. unsigned char work_restart_id;
  924. uint32_t block_id;
  925. enum pool_protocol proto;
  926. char *hdr_path;
  927. char *lp_url;
  928. char *lp_id;
  929. enum pool_protocol lp_proto;
  930. curl_socket_t lp_socket;
  931. unsigned int getwork_requested;
  932. unsigned int stale_shares;
  933. unsigned int discarded_work;
  934. unsigned int getfail_occasions;
  935. unsigned int remotefail_occasions;
  936. struct timeval tv_idle;
  937. double utility;
  938. int last_shares, shares;
  939. char *rpc_url;
  940. char *rpc_userpass;
  941. char *rpc_user, *rpc_pass;
  942. char *rpc_proxy;
  943. pthread_mutex_t pool_lock;
  944. cglock_t data_lock;
  945. struct thread_q *submit_q;
  946. struct thread_q *getwork_q;
  947. pthread_t longpoll_thread;
  948. pthread_t test_thread;
  949. bool testing;
  950. int curls;
  951. pthread_cond_t cr_cond;
  952. struct list_head curlring;
  953. struct submit_work_state *sws_waiting_on_curl;
  954. time_t last_work_time;
  955. time_t last_share_time;
  956. double last_share_diff;
  957. uint64_t best_diff;
  958. struct cgminer_stats cgminer_stats;
  959. struct cgminer_pool_stats cgminer_pool_stats;
  960. /* Stratum variables */
  961. char *stratum_url;
  962. char *stratum_port;
  963. CURL *stratum_curl;
  964. SOCKETTYPE sock;
  965. char *sockbuf;
  966. size_t sockbuf_size;
  967. char *sockaddr_url; /* stripped url used for sockaddr */
  968. char *nonce1;
  969. size_t n1_len;
  970. uint32_t nonce2;
  971. int n2size;
  972. char *sessionid;
  973. bool has_stratum;
  974. bool stratum_active;
  975. bool stratum_init;
  976. bool stratum_notify;
  977. struct stratum_work swork;
  978. pthread_t stratum_thread;
  979. pthread_mutex_t stratum_lock;
  980. char *admin_msg;
  981. pthread_mutex_t last_work_lock;
  982. struct work *last_work_copy;
  983. };
  984. #define GETWORK_MODE_TESTPOOL 'T'
  985. #define GETWORK_MODE_POOL 'P'
  986. #define GETWORK_MODE_LP 'L'
  987. #define GETWORK_MODE_BENCHMARK 'B'
  988. #define GETWORK_MODE_STRATUM 'S'
  989. #define GETWORK_MODE_GBT 'G'
  990. struct work {
  991. unsigned char data[128];
  992. unsigned char midstate[32];
  993. unsigned char target[32];
  994. unsigned char hash[32];
  995. uint64_t share_diff;
  996. int rolls;
  997. dev_blk_ctx blk;
  998. struct thr_info *thr;
  999. int thr_id;
  1000. struct pool *pool;
  1001. struct timeval tv_staged;
  1002. bool mined;
  1003. bool clone;
  1004. bool cloned;
  1005. int rolltime;
  1006. bool longpoll;
  1007. bool stale;
  1008. bool mandatory;
  1009. bool block;
  1010. bool queued;
  1011. bool stratum;
  1012. char *job_id;
  1013. char *nonce2;
  1014. char *ntime;
  1015. double sdiff;
  1016. char *nonce1;
  1017. unsigned char work_restart_id;
  1018. int id;
  1019. UT_hash_handle hh;
  1020. double work_difficulty;
  1021. // Allow devices to identify work if multiple sub-devices
  1022. // DEPRECATED: New code should be using multiple processors instead
  1023. unsigned char subid;
  1024. blktemplate_t *tmpl;
  1025. int *tmpl_refcount;
  1026. unsigned int dataid;
  1027. bool do_foreign_submit;
  1028. struct timeval tv_getwork;
  1029. struct timeval tv_getwork_reply;
  1030. struct timeval tv_cloned;
  1031. struct timeval tv_work_start;
  1032. struct timeval tv_work_found;
  1033. char getwork_mode;
  1034. /* Used to queue shares in submit_waiting */
  1035. struct list_head list;
  1036. };
  1037. extern void get_datestamp(char *, struct timeval *);
  1038. extern void inc_hw_errors(struct thr_info *thr);
  1039. enum test_nonce2_result {
  1040. TNR_GOOD = 1,
  1041. TNR_HIGH = 0,
  1042. TNR_BAD = -1,
  1043. };
  1044. extern enum test_nonce2_result _test_nonce2(struct work *, uint32_t nonce, bool checktarget);
  1045. #define test_nonce(work, nonce, checktarget) (_test_nonce2(work, nonce, checktarget) == TNR_GOOD)
  1046. #define test_nonce2(work, nonce) (_test_nonce2(work, nonce, true))
  1047. extern void submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce);
  1048. extern struct work *get_queued(struct cgpu_info *cgpu);
  1049. extern struct work *__find_work_bymidstate(struct work *que, char *midstate, size_t midstatelen, char *data, int offset, size_t datalen);
  1050. extern struct work *find_queued_work_bymidstate(struct cgpu_info *cgpu, char *midstate, size_t midstatelen, char *data, int offset, size_t datalen);
  1051. extern void work_completed(struct cgpu_info *cgpu, struct work *work);
  1052. extern bool abandon_work(struct work *, struct timeval *work_runtime, uint64_t hashes);
  1053. extern void hash_queued_work(struct thr_info *mythr);
  1054. extern void tailsprintf(char *f, const char *fmt, ...) FORMAT_SYNTAX_CHECK(printf, 2, 3);
  1055. extern void wlog(const char *f, ...) FORMAT_SYNTAX_CHECK(printf, 1, 2);
  1056. extern void wlogprint(const char *f, ...) FORMAT_SYNTAX_CHECK(printf, 1, 2);
  1057. extern int curses_int(const char *query);
  1058. extern char *curses_input(const char *query);
  1059. extern void kill_work(void);
  1060. extern int prioritize_pools(char *param, int *pid);
  1061. extern void validate_pool_priorities(void);
  1062. extern void switch_pools(struct pool *selected);
  1063. extern void remove_pool(struct pool *pool);
  1064. extern void write_config(FILE *fcfg);
  1065. extern void zero_bestshare(void);
  1066. extern void zero_stats(void);
  1067. extern void default_save_file(char *filename);
  1068. extern bool log_curses_only(int prio, const char *f, va_list ap) FORMAT_SYNTAX_CHECK(printf, 2, 0);
  1069. extern void clear_logwin(void);
  1070. extern bool pool_tclear(struct pool *pool, bool *var);
  1071. extern struct thread_q *tq_new(void);
  1072. extern void tq_free(struct thread_q *tq);
  1073. extern bool tq_push(struct thread_q *tq, void *data);
  1074. extern void *tq_pop(struct thread_q *tq, const struct timespec *abstime);
  1075. extern void tq_freeze(struct thread_q *tq);
  1076. extern void tq_thaw(struct thread_q *tq);
  1077. extern bool successful_connect;
  1078. extern void adl(void);
  1079. extern void clean_work(struct work *work);
  1080. extern void free_work(struct work *work);
  1081. extern void __copy_work(struct work *work, const struct work *base_work);
  1082. extern struct work *copy_work(const struct work *base_work);
  1083. extern struct thr_info *get_thread(int thr_id);
  1084. extern struct cgpu_info *get_devices(int id);
  1085. enum api_data_type {
  1086. API_ESCAPE,
  1087. API_STRING,
  1088. API_CONST,
  1089. API_INT,
  1090. API_UINT,
  1091. API_UINT32,
  1092. API_UINT64,
  1093. API_DOUBLE,
  1094. API_ELAPSED,
  1095. API_BOOL,
  1096. API_TIMEVAL,
  1097. API_TIME,
  1098. API_MHS,
  1099. API_MHTOTAL,
  1100. API_TEMP,
  1101. API_UTILITY,
  1102. API_FREQ,
  1103. API_VOLTS,
  1104. API_HS,
  1105. API_DIFF,
  1106. API_JSON,
  1107. };
  1108. struct api_data {
  1109. enum api_data_type type;
  1110. char *name;
  1111. void *data;
  1112. bool data_was_malloc;
  1113. struct api_data *prev;
  1114. struct api_data *next;
  1115. };
  1116. extern struct api_data *api_add_escape(struct api_data *root, char *name, char *data, bool copy_data);
  1117. extern struct api_data *api_add_string(struct api_data *root, char *name, const char *data, bool copy_data);
  1118. extern struct api_data *api_add_const(struct api_data *root, char *name, const char *data, bool copy_data);
  1119. extern struct api_data *api_add_int(struct api_data *root, char *name, int *data, bool copy_data);
  1120. extern struct api_data *api_add_uint(struct api_data *root, char *name, unsigned int *data, bool copy_data);
  1121. extern struct api_data *api_add_uint32(struct api_data *root, char *name, uint32_t *data, bool copy_data);
  1122. extern struct api_data *api_add_uint64(struct api_data *root, char *name, uint64_t *data, bool copy_data);
  1123. extern struct api_data *api_add_double(struct api_data *root, char *name, double *data, bool copy_data);
  1124. extern struct api_data *api_add_elapsed(struct api_data *root, char *name, double *data, bool copy_data);
  1125. extern struct api_data *api_add_bool(struct api_data *root, char *name, bool *data, bool copy_data);
  1126. extern struct api_data *api_add_timeval(struct api_data *root, char *name, struct timeval *data, bool copy_data);
  1127. extern struct api_data *api_add_time(struct api_data *root, char *name, time_t *data, bool copy_data);
  1128. extern struct api_data *api_add_mhs(struct api_data *root, char *name, double *data, bool copy_data);
  1129. extern struct api_data *api_add_mhstotal(struct api_data *root, char *name, double *data, bool copy_data);
  1130. extern struct api_data *api_add_temp(struct api_data *root, char *name, float *data, bool copy_data);
  1131. extern struct api_data *api_add_utility(struct api_data *root, char *name, double *data, bool copy_data);
  1132. extern struct api_data *api_add_freq(struct api_data *root, char *name, double *data, bool copy_data);
  1133. extern struct api_data *api_add_volts(struct api_data *root, char *name, float *data, bool copy_data);
  1134. extern struct api_data *api_add_hs(struct api_data *root, char *name, double *data, bool copy_data);
  1135. extern struct api_data *api_add_diff(struct api_data *root, char *name, double *data, bool copy_data);
  1136. extern struct api_data *api_add_json(struct api_data *root, char *name, json_t *data, bool copy_data);
  1137. #endif /* __MINER_H__ */