miner.h 32 KB

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