miner.h 32 KB

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