miner.h 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378
  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_USBUTILS
  385. struct cg_usb_device *usbdev;
  386. #endif
  387. };
  388. #ifdef USE_AVALON
  389. struct work **works;
  390. int work_array;
  391. int queued;
  392. int results;
  393. #endif
  394. #ifdef USE_USBUTILS
  395. struct cg_usb_info usbinfo;
  396. #endif
  397. #ifdef USE_MODMINER
  398. char fpgaid;
  399. unsigned char clock;
  400. pthread_mutex_t *modminer_mutex;
  401. #endif
  402. #ifdef USE_BITFORCE
  403. struct timeval work_start_tv;
  404. unsigned int wait_ms;
  405. unsigned int sleep_ms;
  406. double avg_wait_f;
  407. unsigned int avg_wait_d;
  408. uint32_t nonces;
  409. bool nonce_range;
  410. bool polling;
  411. bool flash_led;
  412. #endif /* USE_BITFORCE */
  413. #if defined(USE_BITFORCE) || defined(USE_BFLSC)
  414. pthread_mutex_t device_mutex;
  415. #endif /* USE_BITFORCE || USE_BFLSC */
  416. #ifdef USE_BITFURY
  417. int chip_n;
  418. struct bitfury_device devices[200]; // TODO Move somewhere to appropriate place
  419. #endif
  420. enum dev_enable deven;
  421. int accepted;
  422. int rejected;
  423. int hw_errors;
  424. double rolling;
  425. double total_mhashes;
  426. double utility;
  427. enum alive status;
  428. char init[40];
  429. struct timeval last_message_tv;
  430. int threads;
  431. struct thr_info **thr;
  432. int64_t max_hashes;
  433. const char *kname;
  434. #ifdef HAVE_OPENCL
  435. bool mapped;
  436. int virtual_gpu;
  437. int virtual_adl;
  438. int intensity;
  439. bool dynamic;
  440. cl_uint vwidth;
  441. size_t work_size;
  442. enum cl_kernels kernel;
  443. cl_ulong max_alloc;
  444. #ifdef USE_SCRYPT
  445. int opt_lg, lookup_gap;
  446. size_t opt_tc, thread_concurrency;
  447. size_t shaders;
  448. #endif
  449. struct timeval tv_gpustart;
  450. int intervals;
  451. #endif
  452. bool new_work;
  453. float temp;
  454. int cutofftemp;
  455. #ifdef HAVE_ADL
  456. bool has_adl;
  457. struct gpu_adl adl;
  458. int gpu_engine;
  459. int min_engine;
  460. int gpu_fan;
  461. int min_fan;
  462. int gpu_memclock;
  463. int gpu_memdiff;
  464. int gpu_powertune;
  465. float gpu_vddc;
  466. #endif
  467. int diff1;
  468. double diff_accepted;
  469. double diff_rejected;
  470. int last_share_pool;
  471. time_t last_share_pool_time;
  472. double last_share_diff;
  473. time_t last_device_valid_work;
  474. time_t device_last_well;
  475. time_t device_last_not_well;
  476. enum dev_reason device_not_well_reason;
  477. int thread_fail_init_count;
  478. int thread_zero_hash_count;
  479. int thread_fail_queue_count;
  480. int dev_sick_idle_60_count;
  481. int dev_dead_idle_600_count;
  482. int dev_nostart_count;
  483. int dev_over_heat_count; // It's a warning but worth knowing
  484. int dev_thermal_cutoff_count;
  485. int dev_comms_error_count;
  486. int dev_throttle_count;
  487. struct cgminer_stats cgminer_stats;
  488. pthread_rwlock_t qlock;
  489. struct work *queued_work;
  490. unsigned int queued_count;
  491. bool shutdown;
  492. struct timeval dev_start_tv;
  493. };
  494. extern bool add_cgpu(struct cgpu_info*);
  495. struct thread_q {
  496. struct list_head q;
  497. bool frozen;
  498. pthread_mutex_t mutex;
  499. pthread_cond_t cond;
  500. };
  501. struct thr_info {
  502. int id;
  503. int device_thread;
  504. bool primary_thread;
  505. pthread_t pth;
  506. cgsem_t sem;
  507. struct thread_q *q;
  508. struct cgpu_info *cgpu;
  509. void *cgpu_data;
  510. struct timeval last;
  511. struct timeval sick;
  512. bool pause;
  513. bool getwork;
  514. double rolling;
  515. bool work_restart;
  516. };
  517. struct string_elist {
  518. char *string;
  519. bool free_me;
  520. struct list_head list;
  521. };
  522. static inline void string_elist_add(const char *s, struct list_head *head)
  523. {
  524. struct string_elist *n;
  525. n = calloc(1, sizeof(*n));
  526. n->string = strdup(s);
  527. n->free_me = true;
  528. list_add_tail(&n->list, head);
  529. }
  530. static inline void string_elist_del(struct string_elist *item)
  531. {
  532. if (item->free_me)
  533. free(item->string);
  534. list_del(&item->list);
  535. }
  536. static inline uint32_t swab32(uint32_t v)
  537. {
  538. return bswap_32(v);
  539. }
  540. static inline void swap256(void *dest_p, const void *src_p)
  541. {
  542. uint32_t *dest = dest_p;
  543. const uint32_t *src = src_p;
  544. dest[0] = src[7];
  545. dest[1] = src[6];
  546. dest[2] = src[5];
  547. dest[3] = src[4];
  548. dest[4] = src[3];
  549. dest[5] = src[2];
  550. dest[6] = src[1];
  551. dest[7] = src[0];
  552. }
  553. static inline void swab256(void *dest_p, const void *src_p)
  554. {
  555. uint32_t *dest = dest_p;
  556. const uint32_t *src = src_p;
  557. dest[0] = swab32(src[7]);
  558. dest[1] = swab32(src[6]);
  559. dest[2] = swab32(src[5]);
  560. dest[3] = swab32(src[4]);
  561. dest[4] = swab32(src[3]);
  562. dest[5] = swab32(src[2]);
  563. dest[6] = swab32(src[1]);
  564. dest[7] = swab32(src[0]);
  565. }
  566. static inline void flip32(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 < 8; i++)
  572. dest[i] = swab32(src[i]);
  573. }
  574. static inline void flip64(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 < 16; i++)
  580. dest[i] = swab32(src[i]);
  581. }
  582. static inline void flip80(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 < 20; i++)
  588. dest[i] = swab32(src[i]);
  589. }
  590. static inline void flip128(void *dest_p, const void *src_p)
  591. {
  592. uint32_t *dest = dest_p;
  593. const uint32_t *src = src_p;
  594. int i;
  595. for (i = 0; i < 32; i++)
  596. dest[i] = swab32(src[i]);
  597. }
  598. /* For flipping to the correct endianness if necessary */
  599. #if defined(__BIG_ENDIAN__) || defined(MIPSEB)
  600. static inline void endian_flip32(void *dest_p, const void *src_p)
  601. {
  602. flip32(dest_p, src_p);
  603. }
  604. static inline void endian_flip128(void *dest_p, const void *src_p)
  605. {
  606. flip128(dest_p, src_p);
  607. }
  608. #else
  609. static inline void
  610. endian_flip32(void __maybe_unused *dest_p, const void __maybe_unused *src_p)
  611. {
  612. }
  613. static inline void
  614. endian_flip128(void __maybe_unused *dest_p, const void __maybe_unused *src_p)
  615. {
  616. }
  617. #endif
  618. extern void _quit(int status);
  619. static inline void mutex_lock(pthread_mutex_t *lock)
  620. {
  621. if (unlikely(pthread_mutex_lock(lock)))
  622. quit(1, "WTF MUTEX ERROR ON LOCK!");
  623. }
  624. static inline void mutex_unlock_noyield(pthread_mutex_t *lock)
  625. {
  626. if (unlikely(pthread_mutex_unlock(lock)))
  627. quit(1, "WTF MUTEX ERROR ON UNLOCK!");
  628. }
  629. static inline void mutex_unlock(pthread_mutex_t *lock)
  630. {
  631. mutex_unlock_noyield(lock);
  632. sched_yield();
  633. }
  634. static inline int mutex_trylock(pthread_mutex_t *lock)
  635. {
  636. return pthread_mutex_trylock(lock);
  637. }
  638. static inline void wr_lock(pthread_rwlock_t *lock)
  639. {
  640. if (unlikely(pthread_rwlock_wrlock(lock)))
  641. quit(1, "WTF WRLOCK ERROR ON LOCK!");
  642. }
  643. static inline void rd_lock(pthread_rwlock_t *lock)
  644. {
  645. if (unlikely(pthread_rwlock_rdlock(lock)))
  646. quit(1, "WTF RDLOCK ERROR ON LOCK!");
  647. }
  648. static inline void rw_unlock(pthread_rwlock_t *lock)
  649. {
  650. if (unlikely(pthread_rwlock_unlock(lock)))
  651. quit(1, "WTF RWLOCK ERROR ON UNLOCK!");
  652. sched_yield();
  653. }
  654. static inline void rd_unlock(pthread_rwlock_t *lock)
  655. {
  656. rw_unlock(lock);
  657. }
  658. static inline void wr_unlock(pthread_rwlock_t *lock)
  659. {
  660. rw_unlock(lock);
  661. }
  662. static inline void mutex_init(pthread_mutex_t *lock)
  663. {
  664. if (unlikely(pthread_mutex_init(lock, NULL)))
  665. quit(1, "Failed to pthread_mutex_init");
  666. }
  667. static inline void rwlock_init(pthread_rwlock_t *lock)
  668. {
  669. if (unlikely(pthread_rwlock_init(lock, NULL)))
  670. quit(1, "Failed to pthread_rwlock_init");
  671. }
  672. /* cgminer locks, a write biased variant of rwlocks */
  673. struct cglock {
  674. pthread_mutex_t mutex;
  675. pthread_rwlock_t rwlock;
  676. };
  677. typedef struct cglock cglock_t;
  678. static inline void cglock_init(cglock_t *lock)
  679. {
  680. mutex_init(&lock->mutex);
  681. rwlock_init(&lock->rwlock);
  682. }
  683. /* Read lock variant of cglock */
  684. static inline void cg_rlock(cglock_t *lock)
  685. {
  686. mutex_lock(&lock->mutex);
  687. rd_lock(&lock->rwlock);
  688. mutex_unlock_noyield(&lock->mutex);
  689. }
  690. /* Intermediate variant of cglock */
  691. static inline void cg_ilock(cglock_t *lock)
  692. {
  693. mutex_lock(&lock->mutex);
  694. }
  695. /* Upgrade intermediate variant to a write lock */
  696. static inline void cg_ulock(cglock_t *lock)
  697. {
  698. wr_lock(&lock->rwlock);
  699. }
  700. /* Write lock variant of cglock */
  701. static inline void cg_wlock(cglock_t *lock)
  702. {
  703. mutex_lock(&lock->mutex);
  704. wr_lock(&lock->rwlock);
  705. }
  706. /* Downgrade intermediate variant to a read lock */
  707. static inline void cg_dlock(cglock_t *lock)
  708. {
  709. rd_lock(&lock->rwlock);
  710. mutex_unlock_noyield(&lock->mutex);
  711. }
  712. static inline void cg_runlock(cglock_t *lock)
  713. {
  714. rd_unlock(&lock->rwlock);
  715. }
  716. static inline void cg_wunlock(cglock_t *lock)
  717. {
  718. wr_unlock(&lock->rwlock);
  719. mutex_unlock(&lock->mutex);
  720. }
  721. struct pool;
  722. extern bool opt_protocol;
  723. extern bool have_longpoll;
  724. extern char *opt_kernel_path;
  725. extern char *opt_socks_proxy;
  726. extern char *cgminer_path;
  727. extern bool opt_fail_only;
  728. extern bool opt_autofan;
  729. extern bool opt_autoengine;
  730. extern bool use_curses;
  731. extern char *opt_api_allow;
  732. extern char *opt_api_groups;
  733. extern char *opt_api_description;
  734. extern int opt_api_port;
  735. extern bool opt_api_listen;
  736. extern bool opt_api_network;
  737. extern bool opt_delaynet;
  738. extern bool opt_restart;
  739. extern char *opt_icarus_options;
  740. extern char *opt_icarus_timing;
  741. extern bool opt_worktime;
  742. #ifdef USE_AVALON
  743. extern char *opt_avalon_options;
  744. #endif
  745. #ifdef USE_USBUTILS
  746. extern char *opt_usb_select;
  747. extern int opt_usbdump;
  748. extern bool opt_usb_list_all;
  749. extern cgsem_t usb_resource_sem;
  750. #endif
  751. #ifdef USE_BITFORCE
  752. extern bool opt_bfl_noncerange;
  753. #endif
  754. extern int swork_id;
  755. extern pthread_rwlock_t netacc_lock;
  756. extern const uint32_t sha256_init_state[];
  757. extern json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass,
  758. const char *rpc_req, bool, bool, int *,
  759. struct pool *pool, bool);
  760. extern const char *proxytype(curl_proxytype proxytype);
  761. extern char *get_proxy(char *url, struct pool *pool);
  762. extern char *bin2hex(const unsigned char *p, size_t len);
  763. extern bool hex2bin(unsigned char *p, const char *hexstr, size_t len);
  764. typedef bool (*sha256_func)(struct thr_info*, const unsigned char *pmidstate,
  765. unsigned char *pdata,
  766. unsigned char *phash1, unsigned char *phash,
  767. const unsigned char *ptarget,
  768. uint32_t max_nonce,
  769. uint32_t *last_nonce,
  770. uint32_t nonce);
  771. extern bool fulltest(const unsigned char *hash, const unsigned char *target);
  772. extern int opt_queue;
  773. extern int opt_scantime;
  774. extern int opt_expiry;
  775. #ifdef USE_USBUTILS
  776. extern pthread_mutex_t cgusb_lock;
  777. extern pthread_mutex_t cgusbres_lock;
  778. extern cglock_t cgusb_fd_lock;
  779. #endif
  780. extern cglock_t control_lock;
  781. extern pthread_mutex_t hash_lock;
  782. extern pthread_mutex_t console_lock;
  783. extern cglock_t ch_lock;
  784. extern pthread_rwlock_t mining_thr_lock;
  785. extern pthread_rwlock_t devices_lock;
  786. extern pthread_mutex_t restart_lock;
  787. extern pthread_cond_t restart_cond;
  788. extern void thread_reportin(struct thr_info *thr);
  789. extern void clear_stratum_shares(struct pool *pool);
  790. extern void set_target(unsigned char *dest_target, double diff);
  791. extern int restart_wait(unsigned int mstime);
  792. extern void kill_work(void);
  793. extern void reinit_device(struct cgpu_info *cgpu);
  794. #ifdef HAVE_ADL
  795. extern bool gpu_stats(int gpu, float *temp, int *engineclock, int *memclock, float *vddc, int *activity, int *fanspeed, int *fanpercent, int *powertune);
  796. extern int set_fanspeed(int gpu, int iFanSpeed);
  797. extern int set_vddc(int gpu, float fVddc);
  798. extern int set_engineclock(int gpu, int iEngineClock);
  799. extern int set_memoryclock(int gpu, int iMemoryClock);
  800. #endif
  801. extern void api(int thr_id);
  802. extern struct pool *current_pool(void);
  803. extern int enabled_pools;
  804. extern void get_intrange(char *arg, int *val1, int *val2);
  805. extern bool detect_stratum(struct pool *pool, char *url);
  806. extern void print_summary(void);
  807. extern struct pool *add_pool(void);
  808. extern bool add_pool_details(struct pool *pool, bool live, char *url, char *user, char *pass);
  809. #define MAX_GPUDEVICES 16
  810. #define MAX_DEVICES 4096
  811. #define MIN_INTENSITY -10
  812. #define _MIN_INTENSITY_STR "-10"
  813. #ifdef USE_SCRYPT
  814. #define MAX_INTENSITY 20
  815. #define _MAX_INTENSITY_STR "20"
  816. #else
  817. #define MAX_INTENSITY 14
  818. #define _MAX_INTENSITY_STR "14"
  819. #endif
  820. extern bool hotplug_mode;
  821. extern int hotplug_time;
  822. extern struct list_head scan_devices;
  823. extern int nDevs;
  824. extern int num_processors;
  825. extern int hw_errors;
  826. extern bool use_syslog;
  827. extern bool opt_quiet;
  828. extern struct thr_info *control_thr;
  829. extern struct thr_info **mining_thr;
  830. extern struct cgpu_info gpus[MAX_GPUDEVICES];
  831. extern int gpu_threads;
  832. #ifdef USE_SCRYPT
  833. extern bool opt_scrypt;
  834. #else
  835. #define opt_scrypt (0)
  836. #endif
  837. extern double total_secs;
  838. extern int mining_threads;
  839. extern int total_devices;
  840. extern int zombie_devs;
  841. extern struct cgpu_info **devices;
  842. extern int total_pools;
  843. extern struct pool **pools;
  844. extern struct strategies strategies[];
  845. extern enum pool_strategy pool_strategy;
  846. extern int opt_rotate_period;
  847. extern double total_mhashes_done;
  848. extern unsigned int new_blocks;
  849. extern unsigned int found_blocks;
  850. extern int total_accepted, total_rejected, total_diff1;;
  851. extern int total_getworks, total_stale, total_discarded;
  852. extern double total_diff_accepted, total_diff_rejected, total_diff_stale;
  853. extern unsigned int local_work;
  854. extern unsigned int total_go, total_ro;
  855. extern const int opt_cutofftemp;
  856. extern int opt_log_interval;
  857. extern unsigned long long global_hashrate;
  858. extern char *current_fullhash;
  859. extern double current_diff;
  860. extern uint64_t best_diff;
  861. extern struct timeval block_timeval;
  862. #ifdef HAVE_OPENCL
  863. typedef struct {
  864. cl_uint ctx_a; cl_uint ctx_b; cl_uint ctx_c; cl_uint ctx_d;
  865. cl_uint ctx_e; cl_uint ctx_f; cl_uint ctx_g; cl_uint ctx_h;
  866. cl_uint cty_a; cl_uint cty_b; cl_uint cty_c; cl_uint cty_d;
  867. cl_uint cty_e; cl_uint cty_f; cl_uint cty_g; cl_uint cty_h;
  868. cl_uint merkle; cl_uint ntime; cl_uint nbits; cl_uint nonce;
  869. cl_uint fW0; cl_uint fW1; cl_uint fW2; cl_uint fW3; cl_uint fW15;
  870. cl_uint fW01r; cl_uint fcty_e; cl_uint fcty_e2;
  871. cl_uint W16; cl_uint W17; cl_uint W2;
  872. cl_uint PreVal4; cl_uint T1;
  873. cl_uint C1addK5; cl_uint D1A; cl_uint W2A; cl_uint W17_2;
  874. cl_uint PreVal4addT1; cl_uint T1substate0;
  875. cl_uint PreVal4_2;
  876. cl_uint PreVal0;
  877. cl_uint PreW18;
  878. cl_uint PreW19;
  879. cl_uint PreW31;
  880. cl_uint PreW32;
  881. /* For diakgcn */
  882. cl_uint B1addK6, PreVal0addK7, W16addK16, W17addK17;
  883. cl_uint zeroA, zeroB;
  884. cl_uint oneA, twoA, threeA, fourA, fiveA, sixA, sevenA;
  885. #ifdef USE_SCRYPT
  886. struct work *work;
  887. #endif
  888. } dev_blk_ctx;
  889. #else
  890. typedef struct {
  891. uint32_t nonce;
  892. } dev_blk_ctx;
  893. #endif
  894. struct curl_ent {
  895. CURL *curl;
  896. struct list_head node;
  897. struct timeval tv;
  898. };
  899. /* Disabled needs to be the lowest enum as a freshly calloced value will then
  900. * equal disabled */
  901. enum pool_enable {
  902. POOL_DISABLED,
  903. POOL_ENABLED,
  904. POOL_REJECTING,
  905. };
  906. struct stratum_work {
  907. char *job_id;
  908. char *prev_hash;
  909. char *coinbase1;
  910. char *coinbase2;
  911. char **merkle;
  912. char *bbversion;
  913. char *nbit;
  914. char *ntime;
  915. bool clean;
  916. size_t cb1_len;
  917. size_t cb2_len;
  918. size_t cb_len;
  919. size_t header_len;
  920. int merkles;
  921. double diff;
  922. };
  923. #define RBUFSIZE 8192
  924. #define RECVSIZE (RBUFSIZE - 4)
  925. struct pool {
  926. int pool_no;
  927. int prio;
  928. int accepted, rejected;
  929. int seq_rejects;
  930. int seq_getfails;
  931. int solved;
  932. int diff1;
  933. char diff[8];
  934. double diff_accepted;
  935. double diff_rejected;
  936. double diff_stale;
  937. bool submit_fail;
  938. bool idle;
  939. bool lagging;
  940. bool probed;
  941. enum pool_enable enabled;
  942. bool submit_old;
  943. bool removed;
  944. bool lp_started;
  945. char *hdr_path;
  946. char *lp_url;
  947. unsigned int getwork_requested;
  948. unsigned int stale_shares;
  949. unsigned int discarded_work;
  950. unsigned int getfail_occasions;
  951. unsigned int remotefail_occasions;
  952. struct timeval tv_idle;
  953. double utility;
  954. int last_shares, shares;
  955. char *rpc_req;
  956. char *rpc_url;
  957. char *rpc_userpass;
  958. char *rpc_user, *rpc_pass;
  959. curl_proxytype rpc_proxytype;
  960. char *rpc_proxy;
  961. pthread_mutex_t pool_lock;
  962. cglock_t data_lock;
  963. struct thread_q *submit_q;
  964. struct thread_q *getwork_q;
  965. pthread_t longpoll_thread;
  966. pthread_t test_thread;
  967. bool testing;
  968. int curls;
  969. pthread_cond_t cr_cond;
  970. struct list_head curlring;
  971. time_t last_share_time;
  972. double last_share_diff;
  973. uint64_t best_diff;
  974. struct cgminer_stats cgminer_stats;
  975. struct cgminer_pool_stats cgminer_pool_stats;
  976. /* Stratum variables */
  977. char *stratum_url;
  978. char *stratum_port;
  979. struct addrinfo stratum_hints;
  980. SOCKETTYPE sock;
  981. char *sockbuf;
  982. size_t sockbuf_size;
  983. char *sockaddr_url; /* stripped url used for sockaddr */
  984. char *nonce1;
  985. size_t n1_len;
  986. uint32_t nonce2;
  987. int n2size;
  988. char *sessionid;
  989. bool has_stratum;
  990. bool stratum_active;
  991. bool stratum_init;
  992. bool stratum_notify;
  993. struct stratum_work swork;
  994. pthread_t stratum_sthread;
  995. pthread_t stratum_rthread;
  996. pthread_mutex_t stratum_lock;
  997. struct thread_q *stratum_q;
  998. int sshares; /* stratum shares submitted waiting on response */
  999. /* GBT variables */
  1000. bool has_gbt;
  1001. cglock_t gbt_lock;
  1002. unsigned char previousblockhash[32];
  1003. unsigned char gbt_target[32];
  1004. char *coinbasetxn;
  1005. char *longpollid;
  1006. char *gbt_workid;
  1007. int gbt_expires;
  1008. uint32_t gbt_version;
  1009. uint32_t curtime;
  1010. uint32_t gbt_bits;
  1011. unsigned char *gbt_coinbase;
  1012. unsigned char *txn_hashes;
  1013. int gbt_txns;
  1014. int coinbase_len;
  1015. struct timeval tv_lastwork;
  1016. };
  1017. #define GETWORK_MODE_TESTPOOL 'T'
  1018. #define GETWORK_MODE_POOL 'P'
  1019. #define GETWORK_MODE_LP 'L'
  1020. #define GETWORK_MODE_BENCHMARK 'B'
  1021. #define GETWORK_MODE_STRATUM 'S'
  1022. #define GETWORK_MODE_GBT 'G'
  1023. struct work {
  1024. unsigned char data[128];
  1025. unsigned char midstate[32];
  1026. unsigned char target[32];
  1027. unsigned char hash[32];
  1028. #ifdef USE_SCRYPT
  1029. unsigned char device_target[32];
  1030. #endif
  1031. double device_diff;
  1032. uint64_t share_diff;
  1033. int rolls;
  1034. dev_blk_ctx blk;
  1035. struct thr_info *thr;
  1036. int thr_id;
  1037. struct pool *pool;
  1038. struct timeval tv_staged;
  1039. bool mined;
  1040. bool clone;
  1041. bool cloned;
  1042. int rolltime;
  1043. bool longpoll;
  1044. bool stale;
  1045. bool mandatory;
  1046. bool block;
  1047. bool queued;
  1048. bool stratum;
  1049. char *job_id;
  1050. char *nonce2;
  1051. char *ntime;
  1052. double sdiff;
  1053. char *nonce1;
  1054. bool gbt;
  1055. char *gbt_coinbase;
  1056. int gbt_txns;
  1057. unsigned int work_block;
  1058. int id;
  1059. UT_hash_handle hh;
  1060. double work_difficulty;
  1061. // Allow devices to identify work if multiple sub-devices
  1062. int subid;
  1063. // Allow devices to flag work for their own purposes
  1064. bool devflag;
  1065. struct timeval tv_getwork;
  1066. struct timeval tv_getwork_reply;
  1067. struct timeval tv_cloned;
  1068. struct timeval tv_work_start;
  1069. struct timeval tv_work_found;
  1070. char getwork_mode;
  1071. };
  1072. #ifdef USE_MODMINER
  1073. struct modminer_fpga_state {
  1074. bool work_running;
  1075. struct work running_work;
  1076. struct timeval tv_workstart;
  1077. uint32_t hashes;
  1078. char next_work_cmd[46];
  1079. char fpgaid;
  1080. bool overheated;
  1081. bool new_work;
  1082. uint32_t shares;
  1083. uint32_t shares_last_hw;
  1084. uint32_t hw_errors;
  1085. uint32_t shares_to_good;
  1086. uint32_t timeout_fail;
  1087. uint32_t success_more;
  1088. struct timeval last_changed;
  1089. struct timeval last_nonce;
  1090. struct timeval first_work;
  1091. bool death_stage_one;
  1092. bool tried_two_byte_temp;
  1093. bool one_byte_temp;
  1094. };
  1095. #endif
  1096. extern void get_datestamp(char *, struct timeval *);
  1097. extern void inc_hw_errors(struct thr_info *thr);
  1098. extern bool submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce);
  1099. extern struct work *get_queued(struct cgpu_info *cgpu);
  1100. extern struct work *__find_work_bymidstate(struct work *que, char *midstate, size_t midstatelen, char *data, int offset, size_t datalen);
  1101. extern struct work *find_queued_work_bymidstate(struct cgpu_info *cgpu, char *midstate, size_t midstatelen, char *data, int offset, size_t datalen);
  1102. extern void work_completed(struct cgpu_info *cgpu, struct work *work);
  1103. extern void hash_queued_work(struct thr_info *mythr);
  1104. extern void tailsprintf(char *f, const char *fmt, ...);
  1105. extern void _wlog(const char *str);
  1106. extern void _wlogprint(const char *str);
  1107. extern int curses_int(const char *query);
  1108. extern char *curses_input(const char *query);
  1109. extern void kill_work(void);
  1110. extern void switch_pools(struct pool *selected);
  1111. extern void discard_work(struct work *work);
  1112. extern void remove_pool(struct pool *pool);
  1113. extern void write_config(FILE *fcfg);
  1114. extern void zero_bestshare(void);
  1115. extern void zero_stats(void);
  1116. extern void default_save_file(char *filename);
  1117. extern bool log_curses_only(int prio, const char *datetime, const char *str);
  1118. extern void clear_logwin(void);
  1119. extern void logwin_update(void);
  1120. extern bool pool_tclear(struct pool *pool, bool *var);
  1121. extern struct thread_q *tq_new(void);
  1122. extern void tq_free(struct thread_q *tq);
  1123. extern bool tq_push(struct thread_q *tq, void *data);
  1124. extern void *tq_pop(struct thread_q *tq, const struct timespec *abstime);
  1125. extern void tq_freeze(struct thread_q *tq);
  1126. extern void tq_thaw(struct thread_q *tq);
  1127. extern bool successful_connect;
  1128. extern void adl(void);
  1129. extern void app_restart(void);
  1130. extern void clean_work(struct work *work);
  1131. extern void free_work(struct work *work);
  1132. extern void __copy_work(struct work *work, struct work *base_work);
  1133. extern struct work *copy_work(struct work *base_work);
  1134. extern struct thr_info *get_thread(int thr_id);
  1135. extern struct cgpu_info *get_devices(int id);
  1136. enum api_data_type {
  1137. API_ESCAPE,
  1138. API_STRING,
  1139. API_CONST,
  1140. API_INT,
  1141. API_UINT,
  1142. API_UINT32,
  1143. API_UINT64,
  1144. API_DOUBLE,
  1145. API_ELAPSED,
  1146. API_BOOL,
  1147. API_TIMEVAL,
  1148. API_TIME,
  1149. API_MHS,
  1150. API_MHTOTAL,
  1151. API_TEMP,
  1152. API_UTILITY,
  1153. API_FREQ,
  1154. API_VOLTS,
  1155. API_HS,
  1156. API_DIFF
  1157. };
  1158. struct api_data {
  1159. enum api_data_type type;
  1160. char *name;
  1161. void *data;
  1162. bool data_was_malloc;
  1163. struct api_data *prev;
  1164. struct api_data *next;
  1165. };
  1166. extern struct api_data *api_add_escape(struct api_data *root, char *name, char *data, bool copy_data);
  1167. extern struct api_data *api_add_string(struct api_data *root, char *name, char *data, bool copy_data);
  1168. extern struct api_data *api_add_const(struct api_data *root, char *name, const char *data, bool copy_data);
  1169. extern struct api_data *api_add_int(struct api_data *root, char *name, int *data, bool copy_data);
  1170. extern struct api_data *api_add_uint(struct api_data *root, char *name, unsigned int *data, bool copy_data);
  1171. extern struct api_data *api_add_uint32(struct api_data *root, char *name, uint32_t *data, bool copy_data);
  1172. extern struct api_data *api_add_uint64(struct api_data *root, char *name, uint64_t *data, bool copy_data);
  1173. extern struct api_data *api_add_double(struct api_data *root, char *name, double *data, bool copy_data);
  1174. extern struct api_data *api_add_elapsed(struct api_data *root, char *name, double *data, bool copy_data);
  1175. extern struct api_data *api_add_bool(struct api_data *root, char *name, bool *data, bool copy_data);
  1176. extern struct api_data *api_add_timeval(struct api_data *root, char *name, struct timeval *data, bool copy_data);
  1177. extern struct api_data *api_add_time(struct api_data *root, char *name, time_t *data, bool copy_data);
  1178. extern struct api_data *api_add_mhs(struct api_data *root, char *name, double *data, bool copy_data);
  1179. extern struct api_data *api_add_mhstotal(struct api_data *root, char *name, double *data, bool copy_data);
  1180. extern struct api_data *api_add_temp(struct api_data *root, char *name, float *data, bool copy_data);
  1181. extern struct api_data *api_add_utility(struct api_data *root, char *name, double *data, bool copy_data);
  1182. extern struct api_data *api_add_freq(struct api_data *root, char *name, double *data, bool copy_data);
  1183. extern struct api_data *api_add_volts(struct api_data *root, char *name, float *data, bool copy_data);
  1184. extern struct api_data *api_add_hs(struct api_data *root, char *name, double *data, bool copy_data);
  1185. extern struct api_data *api_add_diff(struct api_data *root, char *name, double *data, bool copy_data);
  1186. #endif /* __MINER_H__ */