miner.h 32 KB

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