miner.h 32 KB

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