miner.h 31 KB

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