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. void *device_data;
  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. };
  376. #ifdef USE_AVALON
  377. struct work **works;
  378. int work_array;
  379. int queued;
  380. int results;
  381. #endif
  382. #ifdef USE_USBUTILS
  383. struct cg_usb_info usbinfo;
  384. #endif
  385. #ifdef USE_MODMINER
  386. char fpgaid;
  387. unsigned char clock;
  388. pthread_mutex_t *modminer_mutex;
  389. #endif
  390. #ifdef USE_BITFORCE
  391. struct timeval work_start_tv;
  392. unsigned int wait_ms;
  393. unsigned int sleep_ms;
  394. double avg_wait_f;
  395. unsigned int avg_wait_d;
  396. uint32_t nonces;
  397. bool nonce_range;
  398. bool polling;
  399. bool flash_led;
  400. #endif /* USE_BITFORCE */
  401. #if defined(USE_BITFORCE) || defined(USE_BFLSC)
  402. pthread_mutex_t device_mutex;
  403. #endif /* USE_BITFORCE || USE_BFLSC */
  404. enum dev_enable deven;
  405. int accepted;
  406. int rejected;
  407. int hw_errors;
  408. double rolling;
  409. double total_mhashes;
  410. double utility;
  411. enum alive status;
  412. char init[40];
  413. struct timeval last_message_tv;
  414. int threads;
  415. struct thr_info **thr;
  416. int64_t max_hashes;
  417. const char *kname;
  418. #ifdef HAVE_OPENCL
  419. bool mapped;
  420. int virtual_gpu;
  421. int virtual_adl;
  422. int intensity;
  423. bool dynamic;
  424. cl_uint vwidth;
  425. size_t work_size;
  426. enum cl_kernels kernel;
  427. cl_ulong max_alloc;
  428. #ifdef USE_SCRYPT
  429. int opt_lg, lookup_gap;
  430. size_t opt_tc, thread_concurrency;
  431. size_t shaders;
  432. #endif
  433. struct timeval tv_gpustart;
  434. int intervals;
  435. #endif
  436. bool new_work;
  437. float temp;
  438. int cutofftemp;
  439. #ifdef HAVE_ADL
  440. bool has_adl;
  441. struct gpu_adl adl;
  442. int gpu_engine;
  443. int min_engine;
  444. int gpu_fan;
  445. int min_fan;
  446. int gpu_memclock;
  447. int gpu_memdiff;
  448. int gpu_powertune;
  449. float gpu_vddc;
  450. #endif
  451. int diff1;
  452. double diff_accepted;
  453. double diff_rejected;
  454. int last_share_pool;
  455. time_t last_share_pool_time;
  456. double last_share_diff;
  457. time_t last_device_valid_work;
  458. time_t device_last_well;
  459. time_t device_last_not_well;
  460. enum dev_reason device_not_well_reason;
  461. int thread_fail_init_count;
  462. int thread_zero_hash_count;
  463. int thread_fail_queue_count;
  464. int dev_sick_idle_60_count;
  465. int dev_dead_idle_600_count;
  466. int dev_nostart_count;
  467. int dev_over_heat_count; // It's a warning but worth knowing
  468. int dev_thermal_cutoff_count;
  469. int dev_comms_error_count;
  470. int dev_throttle_count;
  471. struct cgminer_stats cgminer_stats;
  472. pthread_rwlock_t qlock;
  473. struct work *queued_work;
  474. unsigned int queued_count;
  475. };
  476. extern bool add_cgpu(struct cgpu_info*);
  477. struct thread_q {
  478. struct list_head q;
  479. bool frozen;
  480. pthread_mutex_t mutex;
  481. pthread_cond_t cond;
  482. };
  483. struct thr_info {
  484. int id;
  485. int device_thread;
  486. bool primary_thread;
  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 pause;
  494. bool getwork;
  495. double rolling;
  496. bool work_restart;
  497. };
  498. struct string_elist {
  499. char *string;
  500. bool free_me;
  501. struct list_head list;
  502. };
  503. static inline void string_elist_add(const char *s, struct list_head *head)
  504. {
  505. struct string_elist *n;
  506. n = calloc(1, sizeof(*n));
  507. n->string = strdup(s);
  508. n->free_me = true;
  509. list_add_tail(&n->list, head);
  510. }
  511. static inline void string_elist_del(struct string_elist *item)
  512. {
  513. if (item->free_me)
  514. free(item->string);
  515. list_del(&item->list);
  516. }
  517. static inline uint32_t swab32(uint32_t v)
  518. {
  519. return bswap_32(v);
  520. }
  521. static inline void swap256(void *dest_p, const void *src_p)
  522. {
  523. uint32_t *dest = dest_p;
  524. const uint32_t *src = src_p;
  525. dest[0] = src[7];
  526. dest[1] = src[6];
  527. dest[2] = src[5];
  528. dest[3] = src[4];
  529. dest[4] = src[3];
  530. dest[5] = src[2];
  531. dest[6] = src[1];
  532. dest[7] = src[0];
  533. }
  534. static inline void swab256(void *dest_p, const void *src_p)
  535. {
  536. uint32_t *dest = dest_p;
  537. const uint32_t *src = src_p;
  538. dest[0] = swab32(src[7]);
  539. dest[1] = swab32(src[6]);
  540. dest[2] = swab32(src[5]);
  541. dest[3] = swab32(src[4]);
  542. dest[4] = swab32(src[3]);
  543. dest[5] = swab32(src[2]);
  544. dest[6] = swab32(src[1]);
  545. dest[7] = swab32(src[0]);
  546. }
  547. static inline void flip32(void *dest_p, const void *src_p)
  548. {
  549. uint32_t *dest = dest_p;
  550. const uint32_t *src = src_p;
  551. int i;
  552. for (i = 0; i < 8; i++)
  553. dest[i] = swab32(src[i]);
  554. }
  555. static inline void flip64(void *dest_p, const void *src_p)
  556. {
  557. uint32_t *dest = dest_p;
  558. const uint32_t *src = src_p;
  559. int i;
  560. for (i = 0; i < 16; i++)
  561. dest[i] = swab32(src[i]);
  562. }
  563. static inline void flip80(void *dest_p, const void *src_p)
  564. {
  565. uint32_t *dest = dest_p;
  566. const uint32_t *src = src_p;
  567. int i;
  568. for (i = 0; i < 20; i++)
  569. dest[i] = swab32(src[i]);
  570. }
  571. static inline void flip128(void *dest_p, const void *src_p)
  572. {
  573. uint32_t *dest = dest_p;
  574. const uint32_t *src = src_p;
  575. int i;
  576. for (i = 0; i < 32; i++)
  577. dest[i] = swab32(src[i]);
  578. }
  579. /* For flipping to the correct endianness if necessary */
  580. #if defined(__BIG_ENDIAN__) || defined(MIPSEB)
  581. static inline void endian_flip32(void *dest_p, const void *src_p)
  582. {
  583. flip32(dest_p, src_p);
  584. }
  585. static inline void endian_flip128(void *dest_p, const void *src_p)
  586. {
  587. flip128(dest_p, src_p);
  588. }
  589. #else
  590. static inline void
  591. endian_flip32(void __maybe_unused *dest_p, const void __maybe_unused *src_p)
  592. {
  593. }
  594. static inline void
  595. endian_flip128(void __maybe_unused *dest_p, const void __maybe_unused *src_p)
  596. {
  597. }
  598. #endif
  599. extern void quit(int status, const char *format, ...);
  600. static inline void mutex_lock(pthread_mutex_t *lock)
  601. {
  602. if (unlikely(pthread_mutex_lock(lock)))
  603. quit(1, "WTF MUTEX ERROR ON LOCK!");
  604. }
  605. static inline void mutex_unlock(pthread_mutex_t *lock)
  606. {
  607. if (unlikely(pthread_mutex_unlock(lock)))
  608. quit(1, "WTF MUTEX ERROR ON UNLOCK!");
  609. }
  610. static inline int mutex_trylock(pthread_mutex_t *lock)
  611. {
  612. return pthread_mutex_trylock(lock);
  613. }
  614. static inline void wr_lock(pthread_rwlock_t *lock)
  615. {
  616. if (unlikely(pthread_rwlock_wrlock(lock)))
  617. quit(1, "WTF WRLOCK ERROR ON LOCK!");
  618. }
  619. static inline void rd_lock(pthread_rwlock_t *lock)
  620. {
  621. if (unlikely(pthread_rwlock_rdlock(lock)))
  622. quit(1, "WTF RDLOCK ERROR ON LOCK!");
  623. }
  624. static inline void rw_unlock(pthread_rwlock_t *lock)
  625. {
  626. if (unlikely(pthread_rwlock_unlock(lock)))
  627. quit(1, "WTF RWLOCK ERROR ON UNLOCK!");
  628. }
  629. static inline void rd_unlock(pthread_rwlock_t *lock)
  630. {
  631. rw_unlock(lock);
  632. }
  633. static inline void wr_unlock(pthread_rwlock_t *lock)
  634. {
  635. rw_unlock(lock);
  636. }
  637. static inline void mutex_init(pthread_mutex_t *lock)
  638. {
  639. if (unlikely(pthread_mutex_init(lock, NULL)))
  640. quit(1, "Failed to pthread_mutex_init");
  641. }
  642. static inline void rwlock_init(pthread_rwlock_t *lock)
  643. {
  644. if (unlikely(pthread_rwlock_init(lock, NULL)))
  645. quit(1, "Failed to pthread_rwlock_init");
  646. }
  647. /* cgminer locks, a write biased variant of rwlocks */
  648. struct cglock {
  649. pthread_mutex_t mutex;
  650. pthread_rwlock_t rwlock;
  651. };
  652. typedef struct cglock cglock_t;
  653. static inline void cglock_init(cglock_t *lock)
  654. {
  655. mutex_init(&lock->mutex);
  656. rwlock_init(&lock->rwlock);
  657. }
  658. /* Read lock variant of cglock */
  659. static inline void cg_rlock(cglock_t *lock)
  660. {
  661. mutex_lock(&lock->mutex);
  662. rd_lock(&lock->rwlock);
  663. mutex_unlock(&lock->mutex);
  664. }
  665. /* Intermediate variant of cglock */
  666. static inline void cg_ilock(cglock_t *lock)
  667. {
  668. mutex_lock(&lock->mutex);
  669. }
  670. /* Upgrade intermediate variant to a write lock */
  671. static inline void cg_ulock(cglock_t *lock)
  672. {
  673. wr_lock(&lock->rwlock);
  674. }
  675. /* Write lock variant of cglock */
  676. static inline void cg_wlock(cglock_t *lock)
  677. {
  678. mutex_lock(&lock->mutex);
  679. wr_lock(&lock->rwlock);
  680. }
  681. /* Downgrade intermediate variant to a read lock */
  682. static inline void cg_dlock(cglock_t *lock)
  683. {
  684. rd_lock(&lock->rwlock);
  685. mutex_unlock(&lock->mutex);
  686. }
  687. static inline void cg_runlock(cglock_t *lock)
  688. {
  689. rd_unlock(&lock->rwlock);
  690. }
  691. static inline void cg_wunlock(cglock_t *lock)
  692. {
  693. wr_unlock(&lock->rwlock);
  694. mutex_unlock(&lock->mutex);
  695. }
  696. struct pool;
  697. extern bool opt_protocol;
  698. extern bool have_longpoll;
  699. extern char *opt_kernel_path;
  700. extern char *opt_socks_proxy;
  701. extern char *cgminer_path;
  702. extern bool opt_fail_only;
  703. extern bool opt_autofan;
  704. extern bool opt_autoengine;
  705. extern bool use_curses;
  706. extern char *opt_api_allow;
  707. extern char *opt_api_groups;
  708. extern char *opt_api_description;
  709. extern int opt_api_port;
  710. extern bool opt_api_listen;
  711. extern bool opt_api_network;
  712. extern bool opt_delaynet;
  713. extern bool opt_restart;
  714. extern char *opt_icarus_options;
  715. extern char *opt_icarus_timing;
  716. extern bool opt_worktime;
  717. #ifdef USE_AVALON
  718. extern char *opt_avalon_options;
  719. #endif
  720. #ifdef USE_USBUTILS
  721. extern char *opt_usb_select;
  722. extern int opt_usbdump;
  723. extern bool opt_usb_list_all;
  724. #endif
  725. #ifdef USE_BITFORCE
  726. extern bool opt_bfl_noncerange;
  727. #endif
  728. extern bool ping;
  729. extern int swork_id;
  730. extern pthread_rwlock_t netacc_lock;
  731. extern const uint32_t sha256_init_state[];
  732. extern json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass,
  733. const char *rpc_req, bool, bool, int *,
  734. struct pool *pool, bool);
  735. extern const char *proxytype(curl_proxytype proxytype);
  736. extern char *get_proxy(char *url, struct pool *pool);
  737. extern char *bin2hex(const unsigned char *p, size_t len);
  738. extern bool hex2bin(unsigned char *p, const char *hexstr, size_t len);
  739. typedef bool (*sha256_func)(struct thr_info*, const unsigned char *pmidstate,
  740. unsigned char *pdata,
  741. unsigned char *phash1, unsigned char *phash,
  742. const unsigned char *ptarget,
  743. uint32_t max_nonce,
  744. uint32_t *last_nonce,
  745. uint32_t nonce);
  746. extern bool fulltest(const unsigned char *hash, const unsigned char *target);
  747. extern int opt_queue;
  748. extern int opt_scantime;
  749. extern int opt_expiry;
  750. #ifdef USE_USBUTILS
  751. extern pthread_mutex_t cgusb_lock;
  752. #endif
  753. extern cglock_t control_lock;
  754. extern pthread_mutex_t hash_lock;
  755. extern pthread_mutex_t console_lock;
  756. extern cglock_t ch_lock;
  757. extern pthread_rwlock_t mining_thr_lock;
  758. extern pthread_rwlock_t devices_lock;
  759. extern pthread_mutex_t restart_lock;
  760. extern pthread_cond_t restart_cond;
  761. extern void thread_reportin(struct thr_info *thr);
  762. extern void clear_stratum_shares(struct pool *pool);
  763. extern void set_target(unsigned char *dest_target, double diff);
  764. extern int restart_wait(unsigned int mstime);
  765. extern void kill_work(void);
  766. extern void reinit_device(struct cgpu_info *cgpu);
  767. #ifdef HAVE_ADL
  768. extern bool gpu_stats(int gpu, float *temp, int *engineclock, int *memclock, float *vddc, int *activity, int *fanspeed, int *fanpercent, int *powertune);
  769. extern int set_fanspeed(int gpu, int iFanSpeed);
  770. extern int set_vddc(int gpu, float fVddc);
  771. extern int set_engineclock(int gpu, int iEngineClock);
  772. extern int set_memoryclock(int gpu, int iMemoryClock);
  773. #endif
  774. extern void api(int thr_id);
  775. extern struct pool *current_pool(void);
  776. extern int enabled_pools;
  777. extern bool detect_stratum(struct pool *pool, char *url);
  778. extern void print_summary(void);
  779. extern struct pool *add_pool(void);
  780. extern bool add_pool_details(struct pool *pool, bool live, char *url, char *user, char *pass);
  781. #define MAX_GPUDEVICES 16
  782. #define MIN_INTENSITY -10
  783. #define _MIN_INTENSITY_STR "-10"
  784. #ifdef USE_SCRYPT
  785. #define MAX_INTENSITY 20
  786. #define _MAX_INTENSITY_STR "20"
  787. #else
  788. #define MAX_INTENSITY 14
  789. #define _MAX_INTENSITY_STR "14"
  790. #endif
  791. extern bool hotplug_mode;
  792. extern int hotplug_time;
  793. extern struct list_head scan_devices;
  794. extern int nDevs;
  795. extern int num_processors;
  796. extern int hw_errors;
  797. extern bool use_syslog;
  798. extern bool opt_quiet;
  799. extern struct thr_info *control_thr;
  800. extern struct thr_info **mining_thr;
  801. extern struct cgpu_info gpus[MAX_GPUDEVICES];
  802. extern int gpu_threads;
  803. #ifdef USE_SCRYPT
  804. extern bool opt_scrypt;
  805. #else
  806. #define opt_scrypt (0)
  807. #endif
  808. extern double total_secs;
  809. extern int mining_threads;
  810. extern int total_devices;
  811. extern struct cgpu_info **devices;
  812. extern int total_pools;
  813. extern struct pool **pools;
  814. extern struct strategies strategies[];
  815. extern enum pool_strategy pool_strategy;
  816. extern int opt_rotate_period;
  817. extern double total_mhashes_done;
  818. extern unsigned int new_blocks;
  819. extern unsigned int found_blocks;
  820. extern int total_accepted, total_rejected, total_diff1;;
  821. extern int total_getworks, total_stale, total_discarded;
  822. extern double total_diff_accepted, total_diff_rejected, total_diff_stale;
  823. extern unsigned int local_work;
  824. extern unsigned int total_go, total_ro;
  825. extern const int opt_cutofftemp;
  826. extern int opt_log_interval;
  827. extern unsigned long long global_hashrate;
  828. extern char *current_fullhash;
  829. extern double current_diff;
  830. extern uint64_t best_diff;
  831. extern struct timeval block_timeval;
  832. #ifdef HAVE_OPENCL
  833. typedef struct {
  834. cl_uint ctx_a; cl_uint ctx_b; cl_uint ctx_c; cl_uint ctx_d;
  835. cl_uint ctx_e; cl_uint ctx_f; cl_uint ctx_g; cl_uint ctx_h;
  836. cl_uint cty_a; cl_uint cty_b; cl_uint cty_c; cl_uint cty_d;
  837. cl_uint cty_e; cl_uint cty_f; cl_uint cty_g; cl_uint cty_h;
  838. cl_uint merkle; cl_uint ntime; cl_uint nbits; cl_uint nonce;
  839. cl_uint fW0; cl_uint fW1; cl_uint fW2; cl_uint fW3; cl_uint fW15;
  840. cl_uint fW01r; cl_uint fcty_e; cl_uint fcty_e2;
  841. cl_uint W16; cl_uint W17; cl_uint W2;
  842. cl_uint PreVal4; cl_uint T1;
  843. cl_uint C1addK5; cl_uint D1A; cl_uint W2A; cl_uint W17_2;
  844. cl_uint PreVal4addT1; cl_uint T1substate0;
  845. cl_uint PreVal4_2;
  846. cl_uint PreVal0;
  847. cl_uint PreW18;
  848. cl_uint PreW19;
  849. cl_uint PreW31;
  850. cl_uint PreW32;
  851. /* For diakgcn */
  852. cl_uint B1addK6, PreVal0addK7, W16addK16, W17addK17;
  853. cl_uint zeroA, zeroB;
  854. cl_uint oneA, twoA, threeA, fourA, fiveA, sixA, sevenA;
  855. #ifdef USE_SCRYPT
  856. struct work *work;
  857. #endif
  858. } dev_blk_ctx;
  859. #else
  860. typedef struct {
  861. uint32_t nonce;
  862. } dev_blk_ctx;
  863. #endif
  864. struct curl_ent {
  865. CURL *curl;
  866. struct list_head node;
  867. struct timeval tv;
  868. };
  869. /* Disabled needs to be the lowest enum as a freshly calloced value will then
  870. * equal disabled */
  871. enum pool_enable {
  872. POOL_DISABLED,
  873. POOL_ENABLED,
  874. POOL_REJECTING,
  875. };
  876. struct stratum_work {
  877. char *job_id;
  878. char *prev_hash;
  879. char *coinbase1;
  880. char *coinbase2;
  881. char **merkle;
  882. char *bbversion;
  883. char *nbit;
  884. char *ntime;
  885. bool clean;
  886. size_t cb1_len;
  887. size_t cb2_len;
  888. size_t cb_len;
  889. size_t header_len;
  890. int merkles;
  891. double diff;
  892. };
  893. #define RBUFSIZE 8192
  894. #define RECVSIZE (RBUFSIZE - 4)
  895. struct pool {
  896. int pool_no;
  897. int prio;
  898. int accepted, rejected;
  899. int seq_rejects;
  900. int seq_getfails;
  901. int solved;
  902. int diff1;
  903. char diff[8];
  904. double diff_accepted;
  905. double diff_rejected;
  906. double diff_stale;
  907. bool submit_fail;
  908. bool idle;
  909. bool lagging;
  910. bool probed;
  911. enum pool_enable enabled;
  912. bool submit_old;
  913. bool removed;
  914. bool lp_started;
  915. char *hdr_path;
  916. char *lp_url;
  917. unsigned int getwork_requested;
  918. unsigned int stale_shares;
  919. unsigned int discarded_work;
  920. unsigned int getfail_occasions;
  921. unsigned int remotefail_occasions;
  922. struct timeval tv_idle;
  923. double utility;
  924. int last_shares, shares;
  925. char *rpc_req;
  926. char *rpc_url;
  927. char *rpc_userpass;
  928. char *rpc_user, *rpc_pass;
  929. curl_proxytype rpc_proxytype;
  930. char *rpc_proxy;
  931. pthread_mutex_t pool_lock;
  932. cglock_t data_lock;
  933. struct thread_q *submit_q;
  934. struct thread_q *getwork_q;
  935. pthread_t longpoll_thread;
  936. pthread_t test_thread;
  937. bool testing;
  938. int curls;
  939. pthread_cond_t cr_cond;
  940. struct list_head curlring;
  941. time_t last_share_time;
  942. double last_share_diff;
  943. uint64_t best_diff;
  944. struct cgminer_stats cgminer_stats;
  945. struct cgminer_pool_stats cgminer_pool_stats;
  946. /* Stratum variables */
  947. char *stratum_url;
  948. char *stratum_port;
  949. struct addrinfo stratum_hints;
  950. SOCKETTYPE sock;
  951. char *sockbuf;
  952. size_t sockbuf_size;
  953. char *sockaddr_url; /* stripped url used for sockaddr */
  954. char *nonce1;
  955. size_t n1_len;
  956. uint32_t nonce2;
  957. int n2size;
  958. char *sessionid;
  959. bool has_stratum;
  960. bool stratum_active;
  961. bool stratum_init;
  962. bool stratum_notify;
  963. struct stratum_work swork;
  964. pthread_t stratum_sthread;
  965. pthread_t stratum_rthread;
  966. pthread_mutex_t stratum_lock;
  967. struct thread_q *stratum_q;
  968. int sshares; /* stratum shares submitted waiting on response */
  969. /* GBT variables */
  970. bool has_gbt;
  971. cglock_t gbt_lock;
  972. unsigned char previousblockhash[32];
  973. unsigned char gbt_target[32];
  974. char *coinbasetxn;
  975. char *longpollid;
  976. char *gbt_workid;
  977. int gbt_expires;
  978. uint32_t gbt_version;
  979. uint32_t curtime;
  980. uint32_t gbt_bits;
  981. unsigned char *gbt_coinbase;
  982. unsigned char *txn_hashes;
  983. int gbt_txns;
  984. int coinbase_len;
  985. struct timeval tv_lastwork;
  986. };
  987. #define GETWORK_MODE_TESTPOOL 'T'
  988. #define GETWORK_MODE_POOL 'P'
  989. #define GETWORK_MODE_LP 'L'
  990. #define GETWORK_MODE_BENCHMARK 'B'
  991. #define GETWORK_MODE_STRATUM 'S'
  992. #define GETWORK_MODE_GBT 'G'
  993. struct work {
  994. unsigned char data[128];
  995. unsigned char midstate[32];
  996. unsigned char target[32];
  997. unsigned char hash[32];
  998. #ifdef USE_SCRYPT
  999. unsigned char device_target[32];
  1000. #endif
  1001. double device_diff;
  1002. uint64_t share_diff;
  1003. int rolls;
  1004. dev_blk_ctx blk;
  1005. struct thr_info *thr;
  1006. int thr_id;
  1007. struct pool *pool;
  1008. struct timeval tv_staged;
  1009. bool mined;
  1010. bool clone;
  1011. bool cloned;
  1012. int rolltime;
  1013. bool longpoll;
  1014. bool stale;
  1015. bool mandatory;
  1016. bool block;
  1017. bool queued;
  1018. bool stratum;
  1019. char *job_id;
  1020. char *nonce2;
  1021. char *ntime;
  1022. double sdiff;
  1023. char *nonce1;
  1024. bool gbt;
  1025. char *gbt_coinbase;
  1026. int gbt_txns;
  1027. unsigned int work_block;
  1028. int id;
  1029. UT_hash_handle hh;
  1030. double work_difficulty;
  1031. // Allow devices to identify work if multiple sub-devices
  1032. int subid;
  1033. // Allow devices to flag work for their own purposes
  1034. bool devflag;
  1035. struct timeval tv_getwork;
  1036. struct timeval tv_getwork_reply;
  1037. struct timeval tv_cloned;
  1038. struct timeval tv_work_start;
  1039. struct timeval tv_work_found;
  1040. char getwork_mode;
  1041. };
  1042. #ifdef USE_MODMINER
  1043. struct modminer_fpga_state {
  1044. bool work_running;
  1045. struct work running_work;
  1046. struct timeval tv_workstart;
  1047. uint32_t hashes;
  1048. char next_work_cmd[46];
  1049. char fpgaid;
  1050. bool overheated;
  1051. bool new_work;
  1052. uint32_t shares;
  1053. uint32_t shares_last_hw;
  1054. uint32_t hw_errors;
  1055. uint32_t shares_to_good;
  1056. uint32_t timeout_fail;
  1057. uint32_t success_more;
  1058. struct timeval last_changed;
  1059. struct timeval last_nonce;
  1060. struct timeval first_work;
  1061. bool death_stage_one;
  1062. bool tried_two_byte_temp;
  1063. bool one_byte_temp;
  1064. };
  1065. #endif
  1066. extern void get_datestamp(char *, struct timeval *);
  1067. extern void inc_hw_errors(struct thr_info *thr);
  1068. extern bool submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce);
  1069. extern struct work *get_queued(struct cgpu_info *cgpu);
  1070. extern struct work *__find_work_bymidstate(struct work *que, char *midstate, size_t midstatelen, char *data, int offset, size_t datalen);
  1071. extern struct work *find_queued_work_bymidstate(struct cgpu_info *cgpu, char *midstate, size_t midstatelen, char *data, int offset, size_t datalen);
  1072. extern void work_completed(struct cgpu_info *cgpu, struct work *work);
  1073. extern void hash_queued_work(struct thr_info *mythr);
  1074. extern void tailsprintf(char *f, const char *fmt, ...);
  1075. extern void wlogprint(const char *f, ...);
  1076. extern int curses_int(const char *query);
  1077. extern char *curses_input(const char *query);
  1078. extern void kill_work(void);
  1079. extern void switch_pools(struct pool *selected);
  1080. extern void discard_work(struct work *work);
  1081. extern void remove_pool(struct pool *pool);
  1082. extern void write_config(FILE *fcfg);
  1083. extern void zero_bestshare(void);
  1084. extern void zero_stats(void);
  1085. extern void default_save_file(char *filename);
  1086. extern bool log_curses_only(int prio, const char *f, va_list ap);
  1087. extern void clear_logwin(void);
  1088. extern void logwin_update(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__ */