miner.h 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340
  1. /*
  2. * Copyright 2012-2013 Luke Dashjr
  3. * Copyright 2011-2013 Con Kolivas
  4. * Copyright 2012-2013 Andrew Smith
  5. * Copyright 2011 Glenn Francis Murray
  6. * Copyright 2010-2011 Jeff Garzik
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License as published by the Free
  10. * Software Foundation; either version 3 of the License, or (at your option)
  11. * any later version. See COPYING for more details.
  12. */
  13. #ifndef __MINER_H__
  14. #define __MINER_H__
  15. #include "config.h"
  16. #ifdef WIN32
  17. #include <winsock2.h>
  18. #endif
  19. #include <stdbool.h>
  20. #include <stdint.h>
  21. #include <sys/time.h>
  22. #include <pthread.h>
  23. #include <jansson.h>
  24. #include <curl/curl.h>
  25. #include <blkmaker.h>
  26. #include <blktemplate.h>
  27. #if defined(WORDS_BIGENDIAN) && !defined(__BIG_ENDIAN__)
  28. /* uthash.h depends on __BIG_ENDIAN__ on BE platforms */
  29. #define __BIG_ENDIAN__ 1
  30. #endif
  31. #include "elist.h"
  32. #include "uthash.h"
  33. #include "logging.h"
  34. #include "util.h"
  35. #include "utlist.h"
  36. #ifdef HAVE_OPENCL
  37. #include "CL/cl.h"
  38. #endif /* HAVE_OPENCL */
  39. #ifdef STDC_HEADERS
  40. # include <stdlib.h>
  41. # include <stddef.h>
  42. #else
  43. # ifdef HAVE_STDLIB_H
  44. # include <stdlib.h>
  45. # endif
  46. #endif
  47. #ifdef HAVE_ALLOCA_H
  48. # include <alloca.h>
  49. #elif defined __GNUC__
  50. # ifndef WIN32
  51. # define alloca __builtin_alloca
  52. # else
  53. # include <malloc.h>
  54. # endif
  55. #elif defined _AIX
  56. # define alloca __alloca
  57. #elif defined _MSC_VER
  58. # include <malloc.h>
  59. # define alloca _alloca
  60. #else
  61. # ifndef HAVE_ALLOCA
  62. # ifdef __cplusplus
  63. extern "C"
  64. # endif
  65. void *alloca (size_t);
  66. # endif
  67. #endif
  68. #ifdef __MINGW32__
  69. #include <windows.h>
  70. #include <io.h>
  71. static inline int fsync (int fd)
  72. {
  73. return (FlushFileBuffers ((HANDLE) _get_osfhandle (fd))) ? 0 : -1;
  74. }
  75. #ifndef EWOULDBLOCK
  76. # define EWOULDBLOCK EAGAIN
  77. #endif
  78. #ifndef MSG_DONTWAIT
  79. # define MSG_DONTWAIT 0x1000000
  80. #endif
  81. #endif /* __MINGW32__ */
  82. #if defined (__linux)
  83. #ifndef LINUX
  84. #define LINUX
  85. #endif
  86. #endif
  87. #ifdef HAVE_ADL
  88. #include "ADL/adl_sdk.h"
  89. #endif
  90. #ifdef HAVE_LIBUSB
  91. #include <libusb.h>
  92. #endif
  93. #ifdef USE_ZTEX
  94. #include "libztex.h"
  95. #endif
  96. #ifdef HAVE_BYTESWAP_H
  97. #include <byteswap.h>
  98. #endif
  99. #ifdef HAVE_ENDIAN_H
  100. #include <endian.h>
  101. #endif
  102. #ifdef HAVE_SYS_ENDIAN_H
  103. #include <sys/endian.h>
  104. #endif
  105. #ifdef HAVE_LIBKERN_OSBYTEORDER_H
  106. #include <libkern/OSByteOrder.h>
  107. #endif
  108. #ifndef bswap_16
  109. #define bswap_16(value) \
  110. ((((value) & 0xff) << 8) | ((value) >> 8))
  111. #define bswap_32(value) \
  112. (((uint32_t)bswap_16((uint16_t)((value) & 0xffff)) << 16) | \
  113. (uint32_t)bswap_16((uint16_t)((value) >> 16)))
  114. #define bswap_64(value) \
  115. (((uint64_t)bswap_32((uint32_t)((value) & 0xffffffff)) \
  116. << 32) | \
  117. (uint64_t)bswap_32((uint32_t)((value) >> 32)))
  118. #endif
  119. /* This assumes htobe32 is a macro and that if it doesn't exist, then the
  120. * also won't exist */
  121. #ifndef htobe32
  122. # ifndef WORDS_BIGENDIAN
  123. # define htole16(x) (x)
  124. # define htole32(x) (x)
  125. # define htole64(x) (x)
  126. # define htobe32(x) bswap_32(x)
  127. # define htobe64(x) bswap_64(x)
  128. # else
  129. # define htole16(x) bswap_16(x)
  130. # define htole32(x) bswap_32(x)
  131. # define htole64(x) bswap_64(x)
  132. # define htobe32(x) (x)
  133. # define htobe64(x) (x)
  134. # endif
  135. #endif
  136. #ifndef be32toh
  137. # define le32toh(x) htole32(x)
  138. # define le64toh(x) htole64(x)
  139. # define be32toh(x) htobe32(x)
  140. # define be64toh(x) htobe64(x)
  141. #endif
  142. #ifndef max
  143. # define max(a, b) ((a) > (b) ? (a) : (b))
  144. #endif
  145. #undef unlikely
  146. #undef likely
  147. #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
  148. #define unlikely(expr) (__builtin_expect(!!(expr), 0))
  149. #define likely(expr) (__builtin_expect(!!(expr), 1))
  150. #else
  151. #define unlikely(expr) (expr)
  152. #define likely(expr) (expr)
  153. #endif
  154. #ifndef __maybe_unused
  155. #define __maybe_unused __attribute__((unused))
  156. #endif
  157. #define uninitialised_var(x) x = x
  158. #if defined(__i386__)
  159. #define WANT_CRYPTOPP_ASM32
  160. #endif
  161. #ifndef ARRAY_SIZE
  162. #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
  163. #endif
  164. #ifdef HAVE_CURSES
  165. extern int my_cancellable_getch(void);
  166. # ifdef getch
  167. // getch() is a macro
  168. static int __maybe_unused __real_getch(void) {
  169. return getch();
  170. }
  171. # undef getch
  172. # define getch() my_cancellable_getch()
  173. # else
  174. // getch() is a real function
  175. # define __real_getch getch
  176. # define getch() my_cancellable_getch()
  177. # endif
  178. #endif
  179. #ifdef NEED_ROUNDL
  180. #define roundl(x) (long double)((long long)((x==0)?0.0:((x)+(((x)>0)?0.5:-0.5))))
  181. #endif
  182. enum alive {
  183. LIFE_WELL,
  184. LIFE_SICK,
  185. LIFE_DEAD,
  186. LIFE_NOSTART,
  187. LIFE_INIT,
  188. LIFE_WAIT,
  189. };
  190. enum pool_strategy {
  191. POOL_FAILOVER,
  192. POOL_ROUNDROBIN,
  193. POOL_ROTATE,
  194. POOL_LOADBALANCE,
  195. POOL_BALANCE,
  196. };
  197. #define TOP_STRATEGY (POOL_BALANCE)
  198. struct strategies {
  199. const char *s;
  200. };
  201. struct cgpu_info;
  202. #ifdef HAVE_ADL
  203. struct gpu_adl {
  204. ADLTemperature lpTemperature;
  205. int iAdapterIndex;
  206. int lpAdapterID;
  207. int iBusNumber;
  208. char strAdapterName[256];
  209. ADLPMActivity lpActivity;
  210. ADLODParameters lpOdParameters;
  211. ADLODPerformanceLevels *DefPerfLev;
  212. ADLFanSpeedInfo lpFanSpeedInfo;
  213. ADLFanSpeedValue lpFanSpeedValue;
  214. ADLFanSpeedValue DefFanSpeedValue;
  215. int iEngineClock;
  216. int iMemoryClock;
  217. int iVddc;
  218. int iPercentage;
  219. bool autofan;
  220. bool autoengine;
  221. bool managed; /* Were the values ever changed on this card */
  222. int lastengine;
  223. int lasttemp;
  224. int targetfan;
  225. int overtemp;
  226. int minspeed;
  227. int maxspeed;
  228. int gpu;
  229. bool has_fanspeed;
  230. struct gpu_adl *twin;
  231. };
  232. #endif
  233. struct api_data;
  234. struct thr_info;
  235. struct work;
  236. struct device_drv {
  237. const char *dname;
  238. const char *name;
  239. // DRV-global functions
  240. void (*drv_detect)();
  241. // Device-specific functions
  242. void (*get_dev_statline_before)(char *, struct cgpu_info *);
  243. void (*get_dev_statline_after)(char *, struct cgpu_info *);
  244. // Processor-specific functions
  245. void (*reinit_device)(struct cgpu_info *);
  246. void (*get_statline_before)(char *, struct cgpu_info *);
  247. void (*get_statline)(char *, struct cgpu_info *);
  248. struct api_data* (*get_api_extra_device_detail)(struct cgpu_info *);
  249. struct api_data* (*get_api_extra_device_status)(struct cgpu_info *);
  250. struct api_data *(*get_api_stats)(struct cgpu_info *);
  251. bool (*get_stats)(struct cgpu_info *);
  252. bool (*identify_device)(struct cgpu_info *); // e.g. to flash a led
  253. char *(*set_device)(struct cgpu_info *, char *option, char *setting, char *replybuf);
  254. // Thread-specific functions
  255. bool (*thread_prepare)(struct thr_info *);
  256. void (*minerloop)(struct thr_info *);
  257. uint64_t (*can_limit_work)(struct thr_info *);
  258. bool (*thread_init)(struct thr_info *);
  259. bool (*prepare_work)(struct thr_info *, struct work *);
  260. int64_t (*scanhash)(struct thr_info *, struct work *, int64_t);
  261. int64_t (*scanwork)(struct thr_info *);
  262. /* Used to extract work from the hash table of queued work and tell
  263. * the main loop that it should not add any further work to the table.
  264. */
  265. bool (*queue_full)(struct cgpu_info *);
  266. void (*flush_work)(struct cgpu_info *);
  267. void (*hw_error)(struct thr_info *);
  268. void (*thread_shutdown)(struct thr_info *);
  269. void (*thread_enable)(struct thr_info *);
  270. // Can be used per-thread or per-processor (only with minerloop async or queue!)
  271. void (*poll)(struct thr_info *);
  272. // === Implemented by minerloop_async ===
  273. bool (*job_prepare)(struct thr_info*, struct work*, uint64_t);
  274. void (*job_start)(struct thr_info*);
  275. void (*job_get_results)(struct thr_info*, struct work*);
  276. int64_t (*job_process_results)(struct thr_info*, struct work*, bool stopping);
  277. // === Implemented by minerloop_queue ===
  278. bool (*queue_append)(struct thr_info *, struct work *);
  279. void (*queue_flush)(struct thr_info *);
  280. };
  281. enum dev_enable {
  282. DEV_ENABLED,
  283. DEV_DISABLED,
  284. DEV_RECOVER,
  285. DEV_RECOVER_ERR,
  286. };
  287. enum cl_kernels {
  288. KL_NONE,
  289. KL_POCLBM,
  290. KL_PHATK,
  291. KL_DIAKGCN,
  292. KL_DIABLO,
  293. KL_SCRYPT,
  294. };
  295. enum dev_reason {
  296. REASON_THREAD_FAIL_INIT,
  297. REASON_THREAD_ZERO_HASH,
  298. REASON_THREAD_FAIL_QUEUE,
  299. REASON_DEV_SICK_IDLE_60,
  300. REASON_DEV_DEAD_IDLE_600,
  301. REASON_DEV_NOSTART,
  302. REASON_DEV_OVER_HEAT,
  303. REASON_DEV_THERMAL_CUTOFF,
  304. REASON_DEV_COMMS_ERROR,
  305. REASON_DEV_THROTTLE,
  306. };
  307. #define REASON_NONE "None"
  308. #define REASON_THREAD_FAIL_INIT_STR "Thread failed to init"
  309. #define REASON_THREAD_ZERO_HASH_STR "Thread got zero hashes"
  310. #define REASON_THREAD_FAIL_QUEUE_STR "Thread failed to queue work"
  311. #define REASON_DEV_SICK_IDLE_60_STR "Device idle for 60s"
  312. #define REASON_DEV_DEAD_IDLE_600_STR "Device dead - idle for 600s"
  313. #define REASON_DEV_NOSTART_STR "Device failed to start"
  314. #define REASON_DEV_OVER_HEAT_STR "Device over heated"
  315. #define REASON_DEV_THERMAL_CUTOFF_STR "Device reached thermal cutoff"
  316. #define REASON_DEV_COMMS_ERROR_STR "Device comms error"
  317. #define REASON_DEV_THROTTLE_STR "Device throttle"
  318. #define REASON_UNKNOWN_STR "Unknown reason - code bug"
  319. #define MIN_SEC_UNSET 99999999
  320. enum {
  321. MSG_NOPOOL = 8,
  322. MSG_MISPID = 25,
  323. MSG_INVPID = 26,
  324. MSG_DUPPID = 74,
  325. MSG_POOLPRIO = 73,
  326. };
  327. struct cgminer_stats {
  328. uint32_t getwork_calls;
  329. struct timeval getwork_wait;
  330. struct timeval getwork_wait_max;
  331. struct timeval getwork_wait_min;
  332. struct timeval _get_start;
  333. };
  334. // Just the actual network getworks to the pool
  335. struct cgminer_pool_stats {
  336. uint32_t getwork_calls;
  337. uint32_t getwork_attempts;
  338. struct timeval getwork_wait;
  339. struct timeval getwork_wait_max;
  340. struct timeval getwork_wait_min;
  341. double getwork_wait_rolling;
  342. bool hadrolltime;
  343. bool canroll;
  344. bool hadexpire;
  345. uint32_t rolltime;
  346. double min_diff;
  347. double max_diff;
  348. double last_diff;
  349. uint32_t min_diff_count;
  350. uint32_t max_diff_count;
  351. uint64_t times_sent;
  352. uint64_t bytes_sent;
  353. uint64_t net_bytes_sent;
  354. uint64_t times_received;
  355. uint64_t bytes_received;
  356. uint64_t net_bytes_received;
  357. };
  358. #define PRIprepr "-6s"
  359. #define PRIpreprv "s"
  360. struct cgpu_info {
  361. int cgminer_id;
  362. int device_line_id;
  363. struct device_drv *drv;
  364. const char *devtype;
  365. int device_id;
  366. char *dev_repr;
  367. char *dev_repr_ns;
  368. const char *name;
  369. int procs;
  370. int proc_id;
  371. char proc_repr[8];
  372. char proc_repr_ns[8];
  373. struct cgpu_info *device;
  374. struct cgpu_info *next_proc;
  375. const char *device_path;
  376. FILE *device_file;
  377. union {
  378. #ifdef USE_ZTEX
  379. struct libztex_device *device_ztex;
  380. #endif
  381. int device_fd;
  382. #ifdef USE_X6500
  383. struct ft232r_device_handle *device_ft232r;
  384. #endif
  385. };
  386. #ifdef USE_AVALON
  387. struct work **works;
  388. int work_array;
  389. int queued;
  390. int results;
  391. #endif
  392. #ifdef USE_BITFORCE
  393. struct timeval work_start_tv;
  394. unsigned int wait_ms;
  395. unsigned int sleep_ms;
  396. double avg_wait_f;
  397. unsigned int avg_wait_d;
  398. uint32_t nonces;
  399. bool polling;
  400. #endif
  401. #if defined(USE_BITFORCE) || defined(USE_ICARUS)
  402. bool flash_led;
  403. #endif
  404. void *cgpu_data;
  405. pthread_mutex_t device_mutex;
  406. pthread_cond_t device_cond;
  407. enum dev_enable deven;
  408. int accepted;
  409. int rejected;
  410. int stale;
  411. int hw_errors;
  412. double rolling;
  413. double total_mhashes;
  414. double utility;
  415. double utility_diff1;
  416. enum alive status;
  417. char init[40];
  418. struct timeval last_message_tv;
  419. int threads;
  420. struct thr_info **thr;
  421. int64_t max_hashes;
  422. const char *kname;
  423. #ifdef HAVE_OPENCL
  424. bool mapped;
  425. int virtual_gpu;
  426. int virtual_adl;
  427. int intensity;
  428. bool dynamic;
  429. cl_uint vwidth;
  430. size_t work_size;
  431. enum cl_kernels kernel;
  432. cl_ulong max_alloc;
  433. #ifdef USE_SCRYPT
  434. int opt_lg, lookup_gap;
  435. size_t opt_tc, thread_concurrency;
  436. size_t shaders;
  437. #endif
  438. struct timeval tv_gpustart;
  439. int intervals;
  440. #endif
  441. float temp;
  442. int cutofftemp;
  443. int targettemp;
  444. #ifdef HAVE_ADL
  445. bool has_adl;
  446. struct gpu_adl adl;
  447. int gpu_engine;
  448. int min_engine;
  449. int gpu_fan;
  450. int min_fan;
  451. int gpu_memclock;
  452. int gpu_memdiff;
  453. int gpu_powertune;
  454. float gpu_vddc;
  455. #endif
  456. int diff1;
  457. double diff_accepted;
  458. double diff_rejected;
  459. int last_share_pool;
  460. time_t last_share_pool_time;
  461. double last_share_diff;
  462. time_t last_device_valid_work;
  463. time_t device_last_well;
  464. time_t device_last_not_well;
  465. enum dev_reason device_not_well_reason;
  466. float reinit_backoff;
  467. int thread_fail_init_count;
  468. int thread_zero_hash_count;
  469. int thread_fail_queue_count;
  470. int dev_sick_idle_60_count;
  471. int dev_dead_idle_600_count;
  472. int dev_nostart_count;
  473. int dev_over_heat_count; // It's a warning but worth knowing
  474. int dev_thermal_cutoff_count;
  475. int dev_comms_error_count;
  476. int dev_throttle_count;
  477. struct cgminer_stats cgminer_stats;
  478. pthread_rwlock_t qlock;
  479. struct work *queued_work;
  480. unsigned int queued_count;
  481. };
  482. extern void renumber_cgpu(struct cgpu_info *);
  483. extern bool add_cgpu(struct cgpu_info*);
  484. struct tq_ent;
  485. struct thread_q {
  486. struct tq_ent *q;
  487. bool frozen;
  488. pthread_mutex_t mutex;
  489. pthread_cond_t cond;
  490. };
  491. enum thr_busy_state {
  492. TBS_IDLE,
  493. TBS_GETTING_RESULTS,
  494. TBS_STARTING_JOB,
  495. };
  496. struct thr_info {
  497. int id;
  498. int device_thread;
  499. bool primary_thread;
  500. bool has_pth;
  501. pthread_t pth;
  502. struct thread_q *q;
  503. struct cgpu_info *cgpu;
  504. void *cgpu_data;
  505. struct timeval last;
  506. struct timeval sick;
  507. bool scanhash_working;
  508. uint64_t hashes_done;
  509. struct timeval tv_hashes_done;
  510. struct timeval tv_lastupdate;
  511. bool pause;
  512. time_t getwork;
  513. double rolling;
  514. // Used by minerloop_async
  515. struct work *prev_work;
  516. struct work *work;
  517. struct work *next_work;
  518. enum thr_busy_state busy_state;
  519. struct timeval tv_morework;
  520. struct work *results_work;
  521. bool _job_transition_in_progress;
  522. bool _proceed_with_new_job;
  523. struct timeval tv_results_jobstart;
  524. struct timeval tv_jobstart;
  525. struct timeval tv_poll;
  526. notifier_t notifier;
  527. bool starting_next_work;
  528. uint32_t _max_nonce;
  529. notifier_t mutex_request;
  530. // Used by minerloop_queue
  531. struct work *work_list;
  532. bool queue_full;
  533. bool _last_sbr_state;
  534. bool work_restart;
  535. notifier_t work_restart_notifier;
  536. };
  537. struct string_elist {
  538. char *string;
  539. bool free_me;
  540. struct string_elist *prev;
  541. struct string_elist *next;
  542. };
  543. static inline void string_elist_add(const char *s, struct string_elist **head)
  544. {
  545. struct string_elist *n;
  546. n = calloc(1, sizeof(*n));
  547. n->string = strdup(s);
  548. n->free_me = true;
  549. DL_APPEND(*head, n);
  550. }
  551. static inline void string_elist_del(struct string_elist **head, struct string_elist *item)
  552. {
  553. if (item->free_me)
  554. free(item->string);
  555. DL_DELETE(*head, item);
  556. free(item);
  557. }
  558. static inline uint32_t swab32(uint32_t v)
  559. {
  560. return bswap_32(v);
  561. }
  562. static inline void swap256(void *dest_p, const void *src_p)
  563. {
  564. uint32_t *dest = dest_p;
  565. const uint32_t *src = src_p;
  566. dest[0] = src[7];
  567. dest[1] = src[6];
  568. dest[2] = src[5];
  569. dest[3] = src[4];
  570. dest[4] = src[3];
  571. dest[5] = src[2];
  572. dest[6] = src[1];
  573. dest[7] = src[0];
  574. }
  575. static inline void swap32yes(void*out, const void*in, size_t sz) {
  576. size_t swapcounter = 0;
  577. for (swapcounter = 0; swapcounter < sz; ++swapcounter)
  578. (((uint32_t*)out)[swapcounter]) = swab32(((uint32_t*)in)[swapcounter]);
  579. }
  580. #define LOCAL_swap32(type, var, sz) \
  581. type __swapped_ ## var[sz * 4 / sizeof(type)]; \
  582. swap32yes(__swapped_ ## var, var, sz); \
  583. var = __swapped_ ## var; \
  584. // end
  585. #ifdef WORDS_BIGENDIAN
  586. # define swap32tobe(out, in, sz) ((out == in) ? (void)0 : memmove(out, in, sz))
  587. # define LOCAL_swap32be(type, var, sz) ;
  588. # define swap32tole(out, in, sz) swap32yes(out, in, sz)
  589. # define LOCAL_swap32le(type, var, sz) LOCAL_swap32(type, var, sz)
  590. #else
  591. # define swap32tobe(out, in, sz) swap32yes(out, in, sz)
  592. # define LOCAL_swap32be(type, var, sz) LOCAL_swap32(type, var, sz)
  593. # define swap32tole(out, in, sz) ((out == in) ? (void)0 : memmove(out, in, sz))
  594. # define LOCAL_swap32le(type, var, sz) ;
  595. #endif
  596. static inline void swab256(void *dest_p, const void *src_p)
  597. {
  598. uint32_t *dest = dest_p;
  599. const uint32_t *src = src_p;
  600. dest[0] = swab32(src[7]);
  601. dest[1] = swab32(src[6]);
  602. dest[2] = swab32(src[5]);
  603. dest[3] = swab32(src[4]);
  604. dest[4] = swab32(src[3]);
  605. dest[5] = swab32(src[2]);
  606. dest[6] = swab32(src[1]);
  607. dest[7] = swab32(src[0]);
  608. }
  609. #define flip32(dest_p, src_p) swap32yes(dest_p, src_p, 32 / 4)
  610. extern void quit(int status, const char *format, ...) NORETURN FORMAT_SYNTAX_CHECK(printf, 2, 3);
  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. }
  621. static inline int mutex_trylock(pthread_mutex_t *lock)
  622. {
  623. return pthread_mutex_trylock(lock);
  624. }
  625. static inline void wr_lock(pthread_rwlock_t *lock)
  626. {
  627. if (unlikely(pthread_rwlock_wrlock(lock)))
  628. quit(1, "WTF WRLOCK ERROR ON LOCK!");
  629. }
  630. static inline void rd_lock(pthread_rwlock_t *lock)
  631. {
  632. if (unlikely(pthread_rwlock_rdlock(lock)))
  633. quit(1, "WTF RDLOCK ERROR ON LOCK!");
  634. }
  635. static inline void rw_unlock(pthread_rwlock_t *lock)
  636. {
  637. if (unlikely(pthread_rwlock_unlock(lock)))
  638. quit(1, "WTF RWLOCK ERROR ON UNLOCK!");
  639. }
  640. static inline void rd_unlock(pthread_rwlock_t *lock)
  641. {
  642. rw_unlock(lock);
  643. }
  644. static inline void wr_unlock(pthread_rwlock_t *lock)
  645. {
  646. rw_unlock(lock);
  647. }
  648. static inline void mutex_init(pthread_mutex_t *lock)
  649. {
  650. if (unlikely(pthread_mutex_init(lock, NULL)))
  651. quit(1, "Failed to pthread_mutex_init");
  652. }
  653. static inline void rwlock_init(pthread_rwlock_t *lock)
  654. {
  655. if (unlikely(pthread_rwlock_init(lock, NULL)))
  656. quit(1, "Failed to pthread_rwlock_init");
  657. }
  658. /* cgminer locks, a write biased variant of rwlocks */
  659. struct cglock {
  660. pthread_mutex_t mutex;
  661. pthread_rwlock_t rwlock;
  662. };
  663. typedef struct cglock cglock_t;
  664. static inline void cglock_init(cglock_t *lock)
  665. {
  666. mutex_init(&lock->mutex);
  667. rwlock_init(&lock->rwlock);
  668. }
  669. /* Read lock variant of cglock */
  670. static inline void cg_rlock(cglock_t *lock)
  671. {
  672. mutex_lock(&lock->mutex);
  673. rd_lock(&lock->rwlock);
  674. mutex_unlock(&lock->mutex);
  675. }
  676. /* Intermediate variant of cglock */
  677. static inline void cg_ilock(cglock_t *lock)
  678. {
  679. mutex_lock(&lock->mutex);
  680. }
  681. /* Upgrade intermediate variant to a write lock */
  682. static inline void cg_ulock(cglock_t *lock)
  683. {
  684. wr_lock(&lock->rwlock);
  685. }
  686. /* Write lock variant of cglock */
  687. static inline void cg_wlock(cglock_t *lock)
  688. {
  689. mutex_lock(&lock->mutex);
  690. wr_lock(&lock->rwlock);
  691. }
  692. /* Downgrade intermediate variant to a read lock */
  693. static inline void cg_dlock(cglock_t *lock)
  694. {
  695. rd_lock(&lock->rwlock);
  696. mutex_unlock(&lock->mutex);
  697. }
  698. static inline void cg_runlock(cglock_t *lock)
  699. {
  700. rd_unlock(&lock->rwlock);
  701. }
  702. static inline void cg_wunlock(cglock_t *lock)
  703. {
  704. wr_unlock(&lock->rwlock);
  705. mutex_unlock(&lock->mutex);
  706. }
  707. struct pool;
  708. extern bool opt_protocol;
  709. extern char *opt_coinbase_sig;
  710. extern bool have_longpoll;
  711. extern int opt_skip_checks;
  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_BITFORCE
  734. extern bool opt_bfl_noncerange;
  735. #endif
  736. extern int swork_id;
  737. extern pthread_rwlock_t netacc_lock;
  738. extern const uint32_t sha256_init_state[];
  739. extern json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass,
  740. const char *rpc_req, bool, bool, int *,
  741. struct pool *pool, bool);
  742. extern bool our_curl_supports_proxy_uris();
  743. extern char *bin2hex(const unsigned char *p, size_t len);
  744. extern bool hex2bin(unsigned char *p, const char *hexstr, size_t len);
  745. typedef bool (*sha256_func)(struct thr_info*, const unsigned char *pmidstate,
  746. unsigned char *pdata,
  747. unsigned char *phash1, unsigned char *phash,
  748. const unsigned char *ptarget,
  749. uint32_t max_nonce,
  750. uint32_t *last_nonce,
  751. uint32_t nonce);
  752. extern bool fulltest(const unsigned char *hash, const unsigned char *target);
  753. extern int opt_queue;
  754. extern int opt_scantime;
  755. extern int opt_expiry;
  756. extern cglock_t control_lock;
  757. extern pthread_mutex_t stats_lock;
  758. extern pthread_mutex_t hash_lock;
  759. extern pthread_mutex_t console_lock;
  760. extern cglock_t ch_lock;
  761. extern pthread_rwlock_t mining_thr_lock;
  762. extern pthread_rwlock_t devices_lock;
  763. extern void thread_reportin(struct thr_info *thr);
  764. extern void thread_reportout(struct thr_info *);
  765. extern void clear_stratum_shares(struct pool *pool);
  766. extern void hashmeter2(struct thr_info *);
  767. extern bool stale_work(struct work *, bool share);
  768. extern bool stale_work_future(struct work *, bool share, unsigned long ustime);
  769. extern void set_target(unsigned char *dest_target, double diff);
  770. extern void kill_work(void);
  771. extern void app_restart(void);
  772. extern void mt_enable(struct thr_info *thr);
  773. extern void proc_enable(struct cgpu_info *);
  774. extern void reinit_device(struct cgpu_info *cgpu);
  775. #ifdef HAVE_ADL
  776. extern bool gpu_stats(int gpu, float *temp, int *engineclock, int *memclock, float *vddc, int *activity, int *fanspeed, int *fanpercent, int *powertune);
  777. extern int set_fanspeed(int gpu, int iFanSpeed);
  778. extern int set_vddc(int gpu, float fVddc);
  779. extern int set_engineclock(int gpu, int iEngineClock);
  780. extern int set_memoryclock(int gpu, int iMemoryClock);
  781. #endif
  782. extern void api(int thr_id);
  783. extern struct pool *current_pool(void);
  784. extern int enabled_pools;
  785. extern bool detect_stratum(struct pool *pool, char *url);
  786. extern void print_summary(void);
  787. extern struct pool *add_pool(void);
  788. extern bool add_pool_details(struct pool *pool, bool live, char *url, char *user, char *pass);
  789. #define MAX_GPUDEVICES 16
  790. #define MIN_INTENSITY -10
  791. #define _MIN_INTENSITY_STR "-10"
  792. #ifdef USE_SCRYPT
  793. #define MAX_INTENSITY 20
  794. #define _MAX_INTENSITY_STR "20"
  795. #else
  796. #define MAX_INTENSITY 14
  797. #define _MAX_INTENSITY_STR "14"
  798. #endif
  799. extern struct string_elist *scan_devices;
  800. extern bool opt_force_dev_init;
  801. extern int nDevs;
  802. extern int opt_n_threads;
  803. extern int num_processors;
  804. extern int hw_errors;
  805. extern bool use_syslog;
  806. extern bool opt_quiet;
  807. extern struct thr_info *control_thr;
  808. extern struct thr_info **mining_thr;
  809. extern struct cgpu_info gpus[MAX_GPUDEVICES];
  810. extern int gpu_threads;
  811. #ifdef USE_SCRYPT
  812. extern bool opt_scrypt;
  813. #else
  814. #define opt_scrypt (0)
  815. #endif
  816. extern double total_secs;
  817. extern int mining_threads;
  818. extern struct cgpu_info *cpus;
  819. extern int total_devices;
  820. extern struct cgpu_info **devices;
  821. extern int total_pools;
  822. extern struct pool **pools;
  823. extern const char *algo_names[];
  824. extern enum sha256_algos opt_algo;
  825. extern struct strategies strategies[];
  826. extern enum pool_strategy pool_strategy;
  827. extern int opt_rotate_period;
  828. extern double total_mhashes_done;
  829. extern unsigned int new_blocks;
  830. extern unsigned int found_blocks;
  831. extern int total_accepted, total_rejected, total_diff1;;
  832. extern int total_getworks, total_stale, total_discarded;
  833. extern uint64_t total_bytes_xfer;
  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_hysteresis;
  839. extern int opt_fail_pause;
  840. extern int opt_log_interval;
  841. extern unsigned long long global_hashrate;
  842. extern char *current_fullhash;
  843. extern double current_diff;
  844. extern uint64_t best_diff;
  845. extern struct timeval block_timeval;
  846. #ifdef HAVE_OPENCL
  847. typedef struct {
  848. cl_uint ctx_a; cl_uint ctx_b; cl_uint ctx_c; cl_uint ctx_d;
  849. cl_uint ctx_e; cl_uint ctx_f; cl_uint ctx_g; cl_uint ctx_h;
  850. cl_uint cty_a; cl_uint cty_b; cl_uint cty_c; cl_uint cty_d;
  851. cl_uint cty_e; cl_uint cty_f; cl_uint cty_g; cl_uint cty_h;
  852. cl_uint merkle; cl_uint ntime; cl_uint nbits; cl_uint nonce;
  853. cl_uint fW0; cl_uint fW1; cl_uint fW2; cl_uint fW3; cl_uint fW15;
  854. cl_uint fW01r; cl_uint fcty_e; cl_uint fcty_e2;
  855. cl_uint W16; cl_uint W17; cl_uint W2;
  856. cl_uint PreVal4; cl_uint T1;
  857. cl_uint C1addK5; cl_uint D1A; cl_uint W2A; cl_uint W17_2;
  858. cl_uint PreVal4addT1; cl_uint T1substate0;
  859. cl_uint PreVal4_2;
  860. cl_uint PreVal0;
  861. cl_uint PreW18;
  862. cl_uint PreW19;
  863. cl_uint PreW31;
  864. cl_uint PreW32;
  865. /* For diakgcn */
  866. cl_uint B1addK6, PreVal0addK7, W16addK16, W17addK17;
  867. cl_uint zeroA, zeroB;
  868. cl_uint oneA, twoA, threeA, fourA, fiveA, sixA, sevenA;
  869. #ifdef USE_SCRYPT
  870. struct work *work;
  871. #endif
  872. } dev_blk_ctx;
  873. #else
  874. typedef struct {
  875. uint32_t nonce;
  876. } dev_blk_ctx;
  877. #endif
  878. struct curl_ent {
  879. CURL *curl;
  880. struct curl_ent *next;
  881. struct timeval tv;
  882. };
  883. /* Disabled needs to be the lowest enum as a freshly calloced value will then
  884. * equal disabled */
  885. enum pool_enable {
  886. POOL_DISABLED,
  887. POOL_ENABLED,
  888. POOL_REJECTING,
  889. };
  890. enum pool_protocol {
  891. PLP_NONE,
  892. PLP_GETWORK,
  893. PLP_GETBLOCKTEMPLATE,
  894. };
  895. struct stratum_work {
  896. char *job_id;
  897. char *prev_hash;
  898. char *coinbase1;
  899. char *coinbase2;
  900. char **merkle;
  901. char *bbversion;
  902. char *nbit;
  903. char *ntime;
  904. bool clean;
  905. size_t cb1_len;
  906. size_t cb2_len;
  907. size_t cb_len;
  908. size_t header_len;
  909. int merkles;
  910. double diff;
  911. bool transparency_probed;
  912. time_t transparency_time;
  913. bool opaque;
  914. };
  915. #define RBUFSIZE 8192
  916. #define RECVSIZE (RBUFSIZE - 4)
  917. struct pool {
  918. int pool_no;
  919. int prio;
  920. int accepted, rejected;
  921. int seq_rejects;
  922. int seq_getfails;
  923. int solved;
  924. int diff1;
  925. char diff[8];
  926. double diff_accepted;
  927. double diff_rejected;
  928. double diff_stale;
  929. bool submit_fail;
  930. bool idle;
  931. bool lagging;
  932. bool probed;
  933. int force_rollntime;
  934. enum pool_enable enabled;
  935. bool submit_old;
  936. bool removed;
  937. bool lp_started;
  938. unsigned char work_restart_id;
  939. uint32_t block_id;
  940. enum pool_protocol proto;
  941. char *hdr_path;
  942. char *lp_url;
  943. char *lp_id;
  944. enum pool_protocol lp_proto;
  945. curl_socket_t lp_socket;
  946. unsigned int getwork_requested;
  947. unsigned int stale_shares;
  948. unsigned int discarded_work;
  949. unsigned int getfail_occasions;
  950. unsigned int remotefail_occasions;
  951. struct timeval tv_idle;
  952. double utility;
  953. int last_shares, shares;
  954. char *rpc_url;
  955. char *rpc_userpass;
  956. char *rpc_user, *rpc_pass;
  957. char *rpc_proxy;
  958. pthread_mutex_t pool_lock;
  959. cglock_t data_lock;
  960. struct thread_q *submit_q;
  961. struct thread_q *getwork_q;
  962. pthread_t longpoll_thread;
  963. pthread_t test_thread;
  964. bool testing;
  965. int curls;
  966. pthread_cond_t cr_cond;
  967. struct curl_ent *curllist;
  968. struct submit_work_state *sws_waiting_on_curl;
  969. time_t last_work_time;
  970. time_t last_share_time;
  971. double last_share_diff;
  972. uint64_t best_diff;
  973. struct cgminer_stats cgminer_stats;
  974. struct cgminer_pool_stats cgminer_pool_stats;
  975. /* Stratum variables */
  976. char *stratum_url;
  977. char *stratum_port;
  978. CURL *stratum_curl;
  979. SOCKETTYPE sock;
  980. char *sockbuf;
  981. size_t sockbuf_size;
  982. char *sockaddr_url; /* stripped url used for sockaddr */
  983. char *nonce1;
  984. size_t n1_len;
  985. uint32_t nonce2;
  986. int n2size;
  987. char *sessionid;
  988. bool has_stratum;
  989. bool stratum_active;
  990. bool stratum_init;
  991. bool stratum_notify;
  992. struct stratum_work swork;
  993. pthread_t stratum_thread;
  994. pthread_mutex_t stratum_lock;
  995. char *admin_msg;
  996. pthread_mutex_t last_work_lock;
  997. struct work *last_work_copy;
  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. uint64_t share_diff;
  1011. int rolls;
  1012. dev_blk_ctx blk;
  1013. struct thr_info *thr;
  1014. int thr_id;
  1015. struct pool *pool;
  1016. struct timeval tv_staged;
  1017. bool mined;
  1018. bool clone;
  1019. bool cloned;
  1020. int rolltime;
  1021. bool longpoll;
  1022. bool stale;
  1023. bool mandatory;
  1024. bool block;
  1025. bool queued;
  1026. bool stratum;
  1027. char *job_id;
  1028. char *nonce2;
  1029. char *ntime;
  1030. double sdiff;
  1031. char *nonce1;
  1032. unsigned char work_restart_id;
  1033. int id;
  1034. UT_hash_handle hh;
  1035. double work_difficulty;
  1036. // Allow devices to identify work if multiple sub-devices
  1037. // DEPRECATED: New code should be using multiple processors instead
  1038. unsigned char subid;
  1039. blktemplate_t *tmpl;
  1040. int *tmpl_refcount;
  1041. unsigned int dataid;
  1042. bool do_foreign_submit;
  1043. struct timeval tv_getwork;
  1044. struct timeval tv_getwork_reply;
  1045. struct timeval tv_cloned;
  1046. struct timeval tv_work_start;
  1047. struct timeval tv_work_found;
  1048. char getwork_mode;
  1049. /* Used to queue shares in submit_waiting */
  1050. struct work *prev;
  1051. struct work *next;
  1052. };
  1053. extern void get_datestamp(char *, struct timeval *);
  1054. extern void inc_hw_errors(struct thr_info *thr);
  1055. enum test_nonce2_result {
  1056. TNR_GOOD = 1,
  1057. TNR_HIGH = 0,
  1058. TNR_BAD = -1,
  1059. };
  1060. extern enum test_nonce2_result _test_nonce2(struct work *, uint32_t nonce, bool checktarget);
  1061. #define test_nonce(work, nonce, checktarget) (_test_nonce2(work, nonce, checktarget) == TNR_GOOD)
  1062. #define test_nonce2(work, nonce) (_test_nonce2(work, nonce, true))
  1063. extern void submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce);
  1064. extern struct work *get_queued(struct cgpu_info *cgpu);
  1065. extern struct work *__find_work_bymidstate(struct work *que, char *midstate, size_t midstatelen, char *data, int offset, size_t datalen);
  1066. extern struct work *find_queued_work_bymidstate(struct cgpu_info *cgpu, char *midstate, size_t midstatelen, char *data, int offset, size_t datalen);
  1067. extern void work_completed(struct cgpu_info *cgpu, struct work *work);
  1068. extern bool abandon_work(struct work *, struct timeval *work_runtime, uint64_t hashes);
  1069. extern void hash_queued_work(struct thr_info *mythr);
  1070. extern void tailsprintf(char *f, const char *fmt, ...) FORMAT_SYNTAX_CHECK(printf, 2, 3);
  1071. extern void wlog(const char *f, ...) FORMAT_SYNTAX_CHECK(printf, 1, 2);
  1072. extern void wlogprint(const char *f, ...) FORMAT_SYNTAX_CHECK(printf, 1, 2);
  1073. extern int curses_int(const char *query);
  1074. extern char *curses_input(const char *query);
  1075. extern void kill_work(void);
  1076. extern int prioritize_pools(char *param, int *pid);
  1077. extern void validate_pool_priorities(void);
  1078. extern void switch_pools(struct pool *selected);
  1079. extern void remove_pool(struct pool *pool);
  1080. extern void write_config(FILE *fcfg);
  1081. extern void zero_bestshare(void);
  1082. extern void zero_stats(void);
  1083. extern void default_save_file(char *filename);
  1084. extern bool log_curses_only(int prio, const char *f, va_list ap) FORMAT_SYNTAX_CHECK(printf, 2, 0);
  1085. extern void clear_logwin(void);
  1086. extern bool pool_tclear(struct pool *pool, bool *var);
  1087. extern struct thread_q *tq_new(void);
  1088. extern void tq_free(struct thread_q *tq);
  1089. extern bool tq_push(struct thread_q *tq, void *data);
  1090. extern void *tq_pop(struct thread_q *tq, const struct timespec *abstime);
  1091. extern void tq_freeze(struct thread_q *tq);
  1092. extern void tq_thaw(struct thread_q *tq);
  1093. extern bool successful_connect;
  1094. extern void adl(void);
  1095. extern void clean_work(struct work *work);
  1096. extern void free_work(struct work *work);
  1097. extern void __copy_work(struct work *work, const struct work *base_work);
  1098. extern struct work *copy_work(const struct work *base_work);
  1099. extern struct thr_info *get_thread(int thr_id);
  1100. extern struct cgpu_info *get_devices(int id);
  1101. enum api_data_type {
  1102. API_ESCAPE,
  1103. API_STRING,
  1104. API_CONST,
  1105. API_INT,
  1106. API_UINT,
  1107. API_UINT32,
  1108. API_UINT64,
  1109. API_DOUBLE,
  1110. API_ELAPSED,
  1111. API_BOOL,
  1112. API_TIMEVAL,
  1113. API_TIME,
  1114. API_MHS,
  1115. API_MHTOTAL,
  1116. API_TEMP,
  1117. API_UTILITY,
  1118. API_FREQ,
  1119. API_VOLTS,
  1120. API_HS,
  1121. API_DIFF,
  1122. API_JSON,
  1123. };
  1124. struct api_data {
  1125. enum api_data_type type;
  1126. char *name;
  1127. void *data;
  1128. bool data_was_malloc;
  1129. struct api_data *prev;
  1130. struct api_data *next;
  1131. };
  1132. extern struct api_data *api_add_escape(struct api_data *root, char *name, char *data, bool copy_data);
  1133. extern struct api_data *api_add_string(struct api_data *root, char *name, const char *data, bool copy_data);
  1134. extern struct api_data *api_add_const(struct api_data *root, char *name, const char *data, bool copy_data);
  1135. extern struct api_data *api_add_int(struct api_data *root, char *name, int *data, bool copy_data);
  1136. extern struct api_data *api_add_uint(struct api_data *root, char *name, unsigned int *data, bool copy_data);
  1137. extern struct api_data *api_add_uint32(struct api_data *root, char *name, uint32_t *data, bool copy_data);
  1138. extern struct api_data *api_add_uint64(struct api_data *root, char *name, uint64_t *data, bool copy_data);
  1139. extern struct api_data *api_add_double(struct api_data *root, char *name, double *data, bool copy_data);
  1140. extern struct api_data *api_add_elapsed(struct api_data *root, char *name, double *data, bool copy_data);
  1141. extern struct api_data *api_add_bool(struct api_data *root, char *name, bool *data, bool copy_data);
  1142. extern struct api_data *api_add_timeval(struct api_data *root, char *name, struct timeval *data, bool copy_data);
  1143. extern struct api_data *api_add_time(struct api_data *root, char *name, time_t *data, bool copy_data);
  1144. extern struct api_data *api_add_mhs(struct api_data *root, char *name, double *data, bool copy_data);
  1145. extern struct api_data *api_add_mhstotal(struct api_data *root, char *name, double *data, bool copy_data);
  1146. extern struct api_data *api_add_temp(struct api_data *root, char *name, float *data, bool copy_data);
  1147. extern struct api_data *api_add_utility(struct api_data *root, char *name, double *data, bool copy_data);
  1148. extern struct api_data *api_add_freq(struct api_data *root, char *name, double *data, bool copy_data);
  1149. extern struct api_data *api_add_volts(struct api_data *root, char *name, float *data, bool copy_data);
  1150. extern struct api_data *api_add_hs(struct api_data *root, char *name, double *data, bool copy_data);
  1151. extern struct api_data *api_add_diff(struct api_data *root, char *name, double *data, bool copy_data);
  1152. extern struct api_data *api_add_json(struct api_data *root, char *name, json_t *data, bool copy_data);
  1153. #endif /* __MINER_H__ */