miner.h 32 KB

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