miner.h 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768
  1. #ifndef __MINER_H__
  2. #define __MINER_H__
  3. #include "config.h"
  4. #ifdef __GNUC__
  5. #ifdef __USE_FORTIFY_LEVEL
  6. #undef __USE_FORTIFY_LEVEL
  7. #endif
  8. // ignore n truncation warnings
  9. #define __USE_FORTIFY_LEVEL 1
  10. #if __GNUC__ >= 7
  11. // ignore the vast number of such non-bug warnings
  12. #pragma GCC diagnostic ignored "-Wunused-variable"
  13. #pragma GCC diagnostic ignored "-Wformat-truncation"
  14. #pragma GCC diagnostic ignored "-Wimplicit-fallthrough"
  15. #pragma GCC diagnostic ignored "-Wtautological-compare"
  16. #endif
  17. #endif
  18. #include <stdbool.h>
  19. #include <stdint.h>
  20. #include <sys/time.h>
  21. #include <pthread.h>
  22. #include <jansson.h>
  23. #include <inttypes.h>
  24. #include <sched.h>
  25. #include "elist.h"
  26. #if HAVE_UTHASH_H
  27. # include <uthash.h>
  28. #else
  29. # include "uthash.h"
  30. #endif
  31. #include "logging.h"
  32. #include "util.h"
  33. #include <sys/types.h>
  34. #ifndef WIN32
  35. # include <sys/socket.h>
  36. # include <netdb.h>
  37. #endif
  38. #ifdef USE_USBUTILS
  39. #include <semaphore.h>
  40. #endif
  41. #ifdef STDC_HEADERS
  42. # include <stdlib.h>
  43. # include <stddef.h>
  44. #else
  45. # ifdef HAVE_STDLIB_H
  46. # include <stdlib.h>
  47. # endif
  48. #endif
  49. #ifdef HAVE_ALLOCA_H
  50. # include <alloca.h>
  51. #elif defined __GNUC__
  52. # ifndef __FreeBSD__ /* FreeBSD has below #define in stdlib.h */
  53. # ifndef WIN32
  54. # define alloca __builtin_alloca
  55. # else
  56. # include <malloc.h>
  57. # endif
  58. # endif
  59. #elif defined _AIX
  60. # define alloca __alloca
  61. #elif defined _MSC_VER
  62. # include <malloc.h>
  63. # define alloca _alloca
  64. #else
  65. # ifndef HAVE_ALLOCA
  66. # ifdef __cplusplus
  67. extern "C"
  68. # endif
  69. void *alloca (size_t);
  70. # endif
  71. #endif
  72. #ifdef HAVE_LIBCURL
  73. #include <curl/curl.h>
  74. #else
  75. typedef char CURL;
  76. extern char *curly;
  77. #define curl_easy_init(curl) (curly)
  78. #define curl_easy_cleanup(curl) {}
  79. #define curl_global_cleanup() {}
  80. #define CURL_GLOBAL_ALL 0
  81. #define curl_global_init(X) (0)
  82. #endif
  83. #ifdef __MINGW32__
  84. #include <io.h>
  85. static inline int fsync (int fd)
  86. {
  87. return (FlushFileBuffers ((HANDLE) _get_osfhandle (fd))) ? 0 : -1;
  88. }
  89. #ifndef EWOULDBLOCK
  90. # define EWOULDBLOCK EAGAIN
  91. #endif
  92. #ifndef MSG_DONTWAIT
  93. # define MSG_DONTWAIT 0x1000000
  94. #endif
  95. #endif /* __MINGW32__ */
  96. #if defined (__linux)
  97. #ifndef LINUX
  98. #define LINUX
  99. #endif
  100. #endif
  101. #ifdef WIN32
  102. #ifndef timersub
  103. #define timersub(a, b, result) \
  104. do { \
  105. (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
  106. (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
  107. if ((result)->tv_usec < 0) { \
  108. --(result)->tv_sec; \
  109. (result)->tv_usec += 1000000; \
  110. } \
  111. } while (0)
  112. #endif
  113. #ifndef timeradd
  114. # define timeradd(a, b, result) \
  115. do { \
  116. (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
  117. (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
  118. if ((result)->tv_usec >= 1000000) \
  119. { \
  120. ++(result)->tv_sec; \
  121. (result)->tv_usec -= 1000000; \
  122. } \
  123. } while (0)
  124. #endif
  125. #endif
  126. #ifdef USE_USBUTILS
  127. #include <libusb.h>
  128. #endif
  129. #ifdef USE_USBUTILS
  130. #include "usbutils.h"
  131. #endif
  132. #if (!defined(WIN32) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))) \
  133. || (defined(WIN32) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)))
  134. #ifndef bswap_16
  135. #define bswap_16 __builtin_bswap16
  136. #define bswap_32 __builtin_bswap32
  137. #define bswap_64 __builtin_bswap64
  138. #endif
  139. #else
  140. #if HAVE_BYTESWAP_H
  141. #include <byteswap.h>
  142. #elif defined(USE_SYS_ENDIAN_H)
  143. #include <sys/endian.h>
  144. #elif defined(__APPLE__)
  145. #include <libkern/OSByteOrder.h>
  146. #define bswap_16 OSSwapInt16
  147. #define bswap_32 OSSwapInt32
  148. #define bswap_64 OSSwapInt64
  149. #else
  150. #define bswap_16(value) \
  151. ((((value) & 0xff) << 8) | ((value) >> 8))
  152. #define bswap_32(value) \
  153. (((uint32_t)bswap_16((uint16_t)((value) & 0xffff)) << 16) | \
  154. (uint32_t)bswap_16((uint16_t)((value) >> 16)))
  155. #define bswap_64(value) \
  156. (((uint64_t)bswap_32((uint32_t)((value) & 0xffffffff)) \
  157. << 32) | \
  158. (uint64_t)bswap_32((uint32_t)((value) >> 32)))
  159. #endif
  160. #endif /* !defined(__GLXBYTEORDER_H__) */
  161. /* This assumes htobe32 is a macro in endian.h, and if it doesn't exist, then
  162. * htobe64 also won't exist */
  163. #ifndef htobe32
  164. # if __BYTE_ORDER == __LITTLE_ENDIAN
  165. # define htole16(x) (x)
  166. # define le16toh(x) (x)
  167. # define htole32(x) (x)
  168. # define htole64(x) (x)
  169. # define le32toh(x) (x)
  170. # define le64toh(x) (x)
  171. # define be32toh(x) bswap_32(x)
  172. # define be64toh(x) bswap_64(x)
  173. # define htobe16(x) bswap_16(x)
  174. # define htobe32(x) bswap_32(x)
  175. # define htobe64(x) bswap_64(x)
  176. # elif __BYTE_ORDER == __BIG_ENDIAN
  177. # define htole16(x) bswap_16(x)
  178. # define le16toh(x) bswap_16(x)
  179. # define htole32(x) bswap_32(x)
  180. # define le32toh(x) bswap_32(x)
  181. # define le64toh(x) bswap_64(x)
  182. # define htole64(x) bswap_64(x)
  183. # define be32toh(x) (x)
  184. # define be64toh(x) (x)
  185. # define htobe16(x) (x)
  186. # define htobe32(x) (x)
  187. # define htobe64(x) (x)
  188. #else
  189. #error UNKNOWN BYTE ORDER
  190. #endif
  191. #endif
  192. #undef unlikely
  193. #undef likely
  194. #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
  195. #define unlikely(expr) (__builtin_expect(!!(expr), 0))
  196. #define likely(expr) (__builtin_expect(!!(expr), 1))
  197. #else
  198. #define unlikely(expr) (expr)
  199. #define likely(expr) (expr)
  200. #endif
  201. #define __maybe_unused __attribute__((unused))
  202. #define uninitialised_var(x) x = x
  203. #if defined(__i386__)
  204. #define WANT_CRYPTOPP_ASM32
  205. #endif
  206. #ifndef ARRAY_SIZE
  207. #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
  208. #endif
  209. /* No semtimedop on apple so ignore timeout till we implement one */
  210. #ifdef __APPLE__
  211. #define semtimedop(SEM, SOPS, VAL, TIMEOUT) semop(SEM, SOPS, VAL)
  212. #endif
  213. #ifndef MIN
  214. #define MIN(x, y) ((x) > (y) ? (y) : (x))
  215. #endif
  216. #ifndef MAX
  217. #define MAX(x, y) ((x) > (y) ? (x) : (y))
  218. #endif
  219. #define MACSTR(_num) MACSTR2(_num)
  220. #define MACSTR2(__num) #__num
  221. /* Put avalon last to make it the last device it tries to detect to prevent it
  222. * trying to claim same chip but different devices. Adding a device here will
  223. * update all macros in the code that use the *_PARSE_COMMANDS macros for each
  224. * listed driver. */
  225. #define FPGA_PARSE_COMMANDS(DRIVER_ADD_COMMAND) \
  226. DRIVER_ADD_COMMAND(bitforce) \
  227. DRIVER_ADD_COMMAND(modminer)
  228. #define ASIC_PARSE_COMMANDS(DRIVER_ADD_COMMAND) \
  229. DRIVER_ADD_COMMAND(ants1) \
  230. DRIVER_ADD_COMMAND(ants2) \
  231. DRIVER_ADD_COMMAND(ants3) \
  232. DRIVER_ADD_COMMAND(avalon) \
  233. DRIVER_ADD_COMMAND(avalon2) \
  234. DRIVER_ADD_COMMAND(avalon4) \
  235. DRIVER_ADD_COMMAND(avalon7) \
  236. DRIVER_ADD_COMMAND(avalon8) \
  237. DRIVER_ADD_COMMAND(avalon9) \
  238. DRIVER_ADD_COMMAND(avalonlc3) \
  239. DRIVER_ADD_COMMAND(avalonm) \
  240. DRIVER_ADD_COMMAND(bab) \
  241. DRIVER_ADD_COMMAND(bflsc) \
  242. DRIVER_ADD_COMMAND(bitfury) \
  243. DRIVER_ADD_COMMAND(bitfury16) \
  244. DRIVER_ADD_COMMAND(bitmineA1) \
  245. DRIVER_ADD_COMMAND(blockerupter) \
  246. DRIVER_ADD_COMMAND(cointerra) \
  247. DRIVER_ADD_COMMAND(gekko) \
  248. DRIVER_ADD_COMMAND(dragonmintT1) \
  249. DRIVER_ADD_COMMAND(hashfast) \
  250. DRIVER_ADD_COMMAND(drillbit) \
  251. DRIVER_ADD_COMMAND(hashratio) \
  252. DRIVER_ADD_COMMAND(icarus) \
  253. DRIVER_ADD_COMMAND(klondike) \
  254. DRIVER_ADD_COMMAND(knc) \
  255. DRIVER_ADD_COMMAND(minion) \
  256. DRIVER_ADD_COMMAND(sp10) \
  257. DRIVER_ADD_COMMAND(sp30) \
  258. DRIVER_ADD_COMMAND(bitmain_soc)
  259. #define DRIVER_PARSE_COMMANDS(DRIVER_ADD_COMMAND) \
  260. FPGA_PARSE_COMMANDS(DRIVER_ADD_COMMAND) \
  261. ASIC_PARSE_COMMANDS(DRIVER_ADD_COMMAND)
  262. #define DRIVER_ENUM(X) DRIVER_##X,
  263. #define DRIVER_PROTOTYPE(X) struct device_drv X##_drv;
  264. /* Create drv_driver enum from DRIVER_PARSE_COMMANDS macro */
  265. enum drv_driver {
  266. DRIVER_PARSE_COMMANDS(DRIVER_ENUM)
  267. DRIVER_MAX
  268. };
  269. /* Use DRIVER_PARSE_COMMANDS to generate extern device_drv prototypes */
  270. DRIVER_PARSE_COMMANDS(DRIVER_PROTOTYPE)
  271. enum alive {
  272. LIFE_WELL,
  273. LIFE_SICK,
  274. LIFE_DEAD,
  275. LIFE_NOSTART,
  276. LIFE_INIT,
  277. };
  278. enum pool_strategy {
  279. POOL_FAILOVER,
  280. POOL_ROUNDROBIN,
  281. POOL_ROTATE,
  282. POOL_LOADBALANCE,
  283. POOL_BALANCE,
  284. };
  285. #define TOP_STRATEGY (POOL_BALANCE)
  286. struct strategies {
  287. const char *s;
  288. };
  289. struct cgpu_info;
  290. extern void blank_get_statline_before(char *buf, size_t bufsiz, struct cgpu_info __maybe_unused *cgpu);
  291. struct api_data;
  292. struct thr_info;
  293. struct work;
  294. struct device_drv {
  295. enum drv_driver drv_id;
  296. char *dname;
  297. char *name;
  298. // DRV-global functions
  299. void (*drv_detect)(bool);
  300. // Device-specific functions
  301. void (*reinit_device)(struct cgpu_info *);
  302. void (*get_statline_before)(char *, size_t, struct cgpu_info *);
  303. void (*get_statline)(char *, size_t, struct cgpu_info *);
  304. struct api_data *(*get_api_stats)(struct cgpu_info *);
  305. struct api_data *(*get_api_debug)(struct cgpu_info *);
  306. bool (*get_stats)(struct cgpu_info *);
  307. void (*identify_device)(struct cgpu_info *); // e.g. to flash a led
  308. char *(*set_device)(struct cgpu_info *, char *option, char *setting, char *replybuf, size_t siz);
  309. // Thread-specific functions
  310. bool (*thread_prepare)(struct thr_info *);
  311. uint64_t (*can_limit_work)(struct thr_info *);
  312. bool (*thread_init)(struct thr_info *);
  313. bool (*prepare_work)(struct thr_info *, struct work *);
  314. /* Which hash work loop this driver uses. */
  315. void (*hash_work)(struct thr_info *);
  316. /* Two variants depending on whether the device divides work up into
  317. * small pieces or works with whole work items and may or may not have
  318. * a queue of its own. */
  319. int64_t (*scanhash)(struct thr_info *, struct work *, int64_t);
  320. int64_t (*scanwork)(struct thr_info *);
  321. /* Used to extract work from the hash table of queued work and tell
  322. * the main loop that it should not add any further work to the table.
  323. */
  324. bool (*queue_full)(struct cgpu_info *);
  325. /* Tell the driver of a block change */
  326. void (*flush_work)(struct cgpu_info *);
  327. /* Tell the driver of an updated work template for eg. stratum */
  328. void (*update_work)(struct cgpu_info *);
  329. void (*hw_error)(struct thr_info *);
  330. void (*thread_shutdown)(struct thr_info *);
  331. void (*thread_enable)(struct thr_info *);
  332. /* What should be zeroed in this device when global zero stats is sent */
  333. void (*zero_stats)(struct cgpu_info *);
  334. // Does it need to be free()d?
  335. bool copy;
  336. /* Highest target diff the device supports */
  337. double max_diff;
  338. /* Lowest diff the controller can safely run at */
  339. double min_diff;
  340. /* Does this device generate work itself and not require stratum work generation? */
  341. bool genwork;
  342. };
  343. extern struct device_drv *copy_drv(struct device_drv*);
  344. enum dev_enable {
  345. DEV_ENABLED,
  346. DEV_DISABLED,
  347. DEV_RECOVER,
  348. };
  349. enum dev_reason {
  350. REASON_THREAD_FAIL_INIT,
  351. REASON_THREAD_ZERO_HASH,
  352. REASON_THREAD_FAIL_QUEUE,
  353. REASON_DEV_SICK_IDLE_60,
  354. REASON_DEV_DEAD_IDLE_600,
  355. REASON_DEV_NOSTART,
  356. REASON_DEV_OVER_HEAT,
  357. REASON_DEV_THERMAL_CUTOFF,
  358. REASON_DEV_COMMS_ERROR,
  359. REASON_DEV_THROTTLE,
  360. };
  361. #define REASON_NONE "None"
  362. #define REASON_THREAD_FAIL_INIT_STR "Thread failed to init"
  363. #define REASON_THREAD_ZERO_HASH_STR "Thread got zero hashes"
  364. #define REASON_THREAD_FAIL_QUEUE_STR "Thread failed to queue work"
  365. #define REASON_DEV_SICK_IDLE_60_STR "Device idle for 60s"
  366. #define REASON_DEV_DEAD_IDLE_600_STR "Device dead - idle for 600s"
  367. #define REASON_DEV_NOSTART_STR "Device failed to start"
  368. #define REASON_DEV_OVER_HEAT_STR "Device over heated"
  369. #define REASON_DEV_THERMAL_CUTOFF_STR "Device reached thermal cutoff"
  370. #define REASON_DEV_COMMS_ERROR_STR "Device comms error"
  371. #define REASON_DEV_THROTTLE_STR "Device throttle"
  372. #define REASON_UNKNOWN_STR "Unknown reason - code bug"
  373. #define MIN_SEC_UNSET 99999999
  374. struct cgminer_stats {
  375. uint32_t getwork_calls;
  376. struct timeval getwork_wait;
  377. struct timeval getwork_wait_max;
  378. struct timeval getwork_wait_min;
  379. };
  380. // Just the actual network getworks to the pool
  381. struct cgminer_pool_stats {
  382. uint32_t getwork_calls;
  383. uint32_t getwork_attempts;
  384. struct timeval getwork_wait;
  385. struct timeval getwork_wait_max;
  386. struct timeval getwork_wait_min;
  387. double getwork_wait_rolling;
  388. bool hadrolltime;
  389. bool canroll;
  390. bool hadexpire;
  391. uint32_t rolltime;
  392. double min_diff;
  393. double max_diff;
  394. double last_diff;
  395. uint32_t min_diff_count;
  396. uint32_t max_diff_count;
  397. uint64_t times_sent;
  398. uint64_t bytes_sent;
  399. uint64_t net_bytes_sent;
  400. uint64_t times_received;
  401. uint64_t bytes_received;
  402. uint64_t net_bytes_received;
  403. };
  404. struct cgpu_info {
  405. int cgminer_id;
  406. struct device_drv *drv;
  407. int device_id;
  408. char *name;
  409. char *device_path;
  410. void *device_data;
  411. void *dup_data;
  412. char *unique_id;
  413. #ifdef USE_USBUTILS
  414. struct cg_usb_device *usbdev;
  415. struct cg_usb_info usbinfo;
  416. bool blacklisted;
  417. bool nozlp; // Device prefers no zero length packet
  418. #endif
  419. #if defined(USE_AVALON) || defined(USE_AVALON2) || defined (USE_AVALON_MINER)
  420. struct work **works;
  421. int work_array;
  422. int queued;
  423. int results;
  424. #endif
  425. #ifdef USE_MODMINER
  426. char fpgaid;
  427. unsigned char clock;
  428. pthread_mutex_t *modminer_mutex;
  429. #endif
  430. #ifdef USE_BITFORCE
  431. struct timeval work_start_tv;
  432. unsigned int wait_ms;
  433. unsigned int sleep_ms;
  434. double avg_wait_f;
  435. unsigned int avg_wait_d;
  436. uint32_t nonces;
  437. bool nonce_range;
  438. bool polling;
  439. bool flash_led;
  440. #endif /* USE_BITFORCE */
  441. #if defined(USE_BITFORCE) || defined(USE_BFLSC)
  442. pthread_mutex_t device_mutex;
  443. #endif /* USE_BITFORCE || USE_BFLSC */
  444. enum dev_enable deven;
  445. int accepted;
  446. int rejected;
  447. int hw_errors;
  448. double rolling;
  449. double rolling1;
  450. double rolling5;
  451. double rolling15;
  452. double total_mhashes;
  453. double utility;
  454. enum alive status;
  455. char init[40];
  456. struct timeval last_message_tv;
  457. int threads;
  458. struct thr_info **thr;
  459. int64_t max_hashes;
  460. const char *kname;
  461. bool new_work;
  462. double temp;
  463. #ifdef USE_DRAGONMINT_T1
  464. double temp_max;
  465. double temp_min;
  466. int fan_duty;
  467. int chainNum;
  468. double mhs_av;
  469. #endif
  470. int cutofftemp;
  471. int64_t diff1;
  472. double diff_accepted;
  473. double diff_rejected;
  474. int last_share_pool;
  475. time_t last_share_pool_time;
  476. double last_share_diff;
  477. time_t last_device_valid_work;
  478. uint32_t last_nonce;
  479. time_t device_last_well;
  480. time_t device_last_not_well;
  481. enum dev_reason device_not_well_reason;
  482. int thread_fail_init_count;
  483. int thread_zero_hash_count;
  484. int thread_fail_queue_count;
  485. int dev_sick_idle_60_count;
  486. int dev_dead_idle_600_count;
  487. int dev_nostart_count;
  488. int dev_over_heat_count; // It's a warning but worth knowing
  489. int dev_thermal_cutoff_count;
  490. int dev_comms_error_count;
  491. int dev_throttle_count;
  492. struct cgminer_stats cgminer_stats;
  493. pthread_rwlock_t qlock;
  494. struct work *queued_work;
  495. struct work *unqueued_work;
  496. unsigned int queued_count;
  497. bool shutdown;
  498. struct timeval dev_start_tv;
  499. /* For benchmarking only */
  500. int hidiff;
  501. int lodiff;
  502. int direction;
  503. };
  504. extern bool add_cgpu(struct cgpu_info*);
  505. struct thread_q {
  506. struct list_head q;
  507. bool frozen;
  508. pthread_mutex_t mutex;
  509. pthread_cond_t cond;
  510. };
  511. struct thr_info {
  512. int id;
  513. int device_thread;
  514. bool primary_thread;
  515. pthread_t pth;
  516. cgsem_t sem;
  517. struct thread_q *q;
  518. struct cgpu_info *cgpu;
  519. void *cgpu_data;
  520. struct timeval last;
  521. struct timeval sick;
  522. bool pause;
  523. bool getwork;
  524. bool work_restart;
  525. bool work_update;
  526. #if defined (USE_AVALON2) || defined (USE_AVALON4) || defined (USE_AVALON7) || defined (USE_AVALON8) || defined (USE_AVALON9) || defined (USE_AVALONLC3) || defined (USE_AVALON_MINER) || defined (USE_HASHRATIO)
  527. bool clean_jobs;
  528. #endif
  529. };
  530. struct string_elist {
  531. char *string;
  532. bool free_me;
  533. struct list_head list;
  534. };
  535. static inline void string_elist_add(const char *s, struct list_head *head)
  536. {
  537. struct string_elist *n;
  538. n = cgcalloc(1, sizeof(*n));
  539. n->string = strdup(s);
  540. n->free_me = true;
  541. list_add_tail(&n->list, head);
  542. }
  543. static inline void string_elist_del(struct string_elist *item)
  544. {
  545. if (item->free_me)
  546. free(item->string);
  547. list_del(&item->list);
  548. }
  549. static inline uint32_t swab32(uint32_t v)
  550. {
  551. return bswap_32(v);
  552. }
  553. static inline void swap256(void *dest_p, const void *src_p)
  554. {
  555. uint32_t *dest = dest_p;
  556. const uint32_t *src = src_p;
  557. dest[0] = src[7];
  558. dest[1] = src[6];
  559. dest[2] = src[5];
  560. dest[3] = src[4];
  561. dest[4] = src[3];
  562. dest[5] = src[2];
  563. dest[6] = src[1];
  564. dest[7] = src[0];
  565. }
  566. static inline void swab256(void *dest_p, const void *src_p)
  567. {
  568. uint32_t *dest = dest_p;
  569. const uint32_t *src = src_p;
  570. dest[0] = swab32(src[7]);
  571. dest[1] = swab32(src[6]);
  572. dest[2] = swab32(src[5]);
  573. dest[3] = swab32(src[4]);
  574. dest[4] = swab32(src[3]);
  575. dest[5] = swab32(src[2]);
  576. dest[6] = swab32(src[1]);
  577. dest[7] = swab32(src[0]);
  578. }
  579. static inline void flip12(void *dest_p, const void *src_p)
  580. {
  581. uint32_t *dest = dest_p;
  582. const uint32_t *src = src_p;
  583. int i;
  584. for (i = 0; i < 3; i++)
  585. dest[i] = swab32(src[i]);
  586. }
  587. static inline void flip32(void *dest_p, const void *src_p)
  588. {
  589. uint32_t *dest = dest_p;
  590. const uint32_t *src = src_p;
  591. int i;
  592. for (i = 0; i < 8; i++)
  593. dest[i] = swab32(src[i]);
  594. }
  595. static inline void flip64(void *dest_p, const void *src_p)
  596. {
  597. uint32_t *dest = dest_p;
  598. const uint32_t *src = src_p;
  599. int i;
  600. for (i = 0; i < 16; i++)
  601. dest[i] = swab32(src[i]);
  602. }
  603. static inline void flip80(void *dest_p, const void *src_p)
  604. {
  605. uint32_t *dest = dest_p;
  606. const uint32_t *src = src_p;
  607. int i;
  608. for (i = 0; i < 20; i++)
  609. dest[i] = swab32(src[i]);
  610. }
  611. static inline void flip128(void *dest_p, const void *src_p)
  612. {
  613. uint32_t *dest = dest_p;
  614. const uint32_t *src = src_p;
  615. int i;
  616. for (i = 0; i < 32; i++)
  617. dest[i] = swab32(src[i]);
  618. }
  619. /* For flipping to the correct endianness if necessary */
  620. #if defined(__BIG_ENDIAN__) || defined(MIPSEB)
  621. static inline void endian_flip32(void *dest_p, const void *src_p)
  622. {
  623. flip32(dest_p, src_p);
  624. }
  625. static inline void endian_flip128(void *dest_p, const void *src_p)
  626. {
  627. flip128(dest_p, src_p);
  628. }
  629. #else
  630. static inline void
  631. endian_flip32(void __maybe_unused *dest_p, const void __maybe_unused *src_p)
  632. {
  633. }
  634. static inline void
  635. endian_flip128(void __maybe_unused *dest_p, const void __maybe_unused *src_p)
  636. {
  637. }
  638. #endif
  639. extern double cgpu_runtime(struct cgpu_info *cgpu);
  640. extern double tsince_restart(void);
  641. extern double tsince_update(void);
  642. extern void __quit(int status, bool clean);
  643. extern void _quit(int status);
  644. /*
  645. * Set this to non-zero to enable lock tracking
  646. * Use the API lockstats command to see the locking status on stderr
  647. * i.e. in your log file if you 2> log.log - but not on the screen
  648. * API lockstats is privilidged but will always exist and will return
  649. * success if LOCK_TRACKING is enabled and warning if disabled
  650. * In production code, this should never be enabled since it will slow down all locking
  651. * So, e.g. use it to track down a deadlock - after a reproducable deadlock occurs
  652. * ... Of course if the API code itself deadlocks, it wont help :)
  653. */
  654. #define LOCK_TRACKING 0
  655. #if LOCK_TRACKING
  656. enum cglock_typ {
  657. CGLOCK_MUTEX,
  658. CGLOCK_RW,
  659. CGLOCK_UNKNOWN
  660. };
  661. extern uint64_t api_getlock(void *lock, const char *file, const char *func, const int line);
  662. extern void api_gotlock(uint64_t id, void *lock, const char *file, const char *func, const int line);
  663. extern uint64_t api_trylock(void *lock, const char *file, const char *func, const int line);
  664. extern void api_didlock(uint64_t id, int ret, void *lock, const char *file, const char *func, const int line);
  665. extern void api_gunlock(void *lock, const char *file, const char *func, const int line);
  666. extern void api_initlock(void *lock, enum cglock_typ typ, const char *file, const char *func, const int line);
  667. #define GETLOCK(_lock, _file, _func, _line) uint64_t _id1 = api_getlock((void *)(_lock), _file, _func, _line)
  668. #define GOTLOCK(_lock, _file, _func, _line) api_gotlock(_id1, (void *)(_lock), _file, _func, _line)
  669. #define TRYLOCK(_lock, _file, _func, _line) uint64_t _id2 = api_trylock((void *)(_lock), _file, _func, _line)
  670. #define DIDLOCK(_ret, _lock, _file, _func, _line) api_didlock(_id2, _ret, (void *)(_lock), _file, _func, _line)
  671. #define GUNLOCK(_lock, _file, _func, _line) api_gunlock((void *)(_lock), _file, _func, _line)
  672. #define INITLOCK(_lock, _typ, _file, _func, _line) api_initlock((void *)(_lock), _typ, _file, _func, _line)
  673. #else
  674. #define GETLOCK(_lock, _file, _func, _line)
  675. #define GOTLOCK(_lock, _file, _func, _line)
  676. #define TRYLOCK(_lock, _file, _func, _line)
  677. #define DIDLOCK(_ret, _lock, _file, _func, _line)
  678. #define GUNLOCK(_lock, _file, _func, _line)
  679. #define INITLOCK(_typ, _lock, _file, _func, _line)
  680. #endif
  681. #define mutex_lock(_lock) _mutex_lock(_lock, __FILE__, __func__, __LINE__)
  682. #define mutex_unlock_noyield(_lock) _mutex_unlock_noyield(_lock, __FILE__, __func__, __LINE__)
  683. #define mutex_unlock(_lock) _mutex_unlock(_lock, __FILE__, __func__, __LINE__)
  684. #define mutex_trylock(_lock) _mutex_trylock(_lock, __FILE__, __func__, __LINE__)
  685. #define wr_lock(_lock) _wr_lock(_lock, __FILE__, __func__, __LINE__)
  686. #define wr_trylock(_lock) _wr_trylock(_lock, __FILE__, __func__, __LINE__)
  687. #define rd_lock(_lock) _rd_lock(_lock, __FILE__, __func__, __LINE__)
  688. #define rw_unlock(_lock) _rw_unlock(_lock, __FILE__, __func__, __LINE__)
  689. #define rd_unlock_noyield(_lock) _rd_unlock_noyield(_lock, __FILE__, __func__, __LINE__)
  690. #define wr_unlock_noyield(_lock) _wr_unlock_noyield(_lock, __FILE__, __func__, __LINE__)
  691. #define rd_unlock(_lock) _rd_unlock(_lock, __FILE__, __func__, __LINE__)
  692. #define wr_unlock(_lock) _wr_unlock(_lock, __FILE__, __func__, __LINE__)
  693. #define mutex_init(_lock) _mutex_init(_lock, __FILE__, __func__, __LINE__)
  694. #define rwlock_init(_lock) _rwlock_init(_lock, __FILE__, __func__, __LINE__)
  695. #define cglock_init(_lock) _cglock_init(_lock, __FILE__, __func__, __LINE__)
  696. #define cg_rlock(_lock) _cg_rlock(_lock, __FILE__, __func__, __LINE__)
  697. #define cg_ilock(_lock) _cg_ilock(_lock, __FILE__, __func__, __LINE__)
  698. #define cg_uilock(_lock) _cg_uilock(_lock, __FILE__, __func__, __LINE__)
  699. #define cg_ulock(_lock) _cg_ulock(_lock, __FILE__, __func__, __LINE__)
  700. #define cg_wlock(_lock) _cg_wlock(_lock, __FILE__, __func__, __LINE__)
  701. #define cg_dwlock(_lock) _cg_dwlock(_lock, __FILE__, __func__, __LINE__)
  702. #define cg_dwilock(_lock) _cg_dwilock(_lock, __FILE__, __func__, __LINE__)
  703. #define cg_dlock(_lock) _cg_dlock(_lock, __FILE__, __func__, __LINE__)
  704. #define cg_runlock(_lock) _cg_runlock(_lock, __FILE__, __func__, __LINE__)
  705. #define cg_ruwlock(_lock) _cg_ruwlock(_lock, __FILE__, __func__, __LINE__)
  706. #define cg_wunlock(_lock) _cg_wunlock(_lock, __FILE__, __func__, __LINE__)
  707. static inline void _mutex_lock(pthread_mutex_t *lock, const char *file, const char *func, const int line)
  708. {
  709. GETLOCK(lock, file, func, line);
  710. if (unlikely(pthread_mutex_lock(lock)))
  711. quitfrom(1, file, func, line, "WTF MUTEX ERROR ON LOCK! errno=%d", errno);
  712. GOTLOCK(lock, file, func, line);
  713. }
  714. static inline void _mutex_unlock_noyield(pthread_mutex_t *lock, const char *file, const char *func, const int line)
  715. {
  716. if (unlikely(pthread_mutex_unlock(lock)))
  717. quitfrom(1, file, func, line, "WTF MUTEX ERROR ON UNLOCK! errno=%d", errno);
  718. GUNLOCK(lock, file, func, line);
  719. }
  720. static inline void _mutex_unlock(pthread_mutex_t *lock, const char *file, const char *func, const int line)
  721. {
  722. _mutex_unlock_noyield(lock, file, func, line);
  723. selective_yield();
  724. }
  725. static inline int _mutex_trylock(pthread_mutex_t *lock, __maybe_unused const char *file, __maybe_unused const char *func, __maybe_unused const int line)
  726. {
  727. TRYLOCK(lock, file, func, line);
  728. int ret = pthread_mutex_trylock(lock);
  729. DIDLOCK(ret, lock, file, func, line);
  730. return ret;
  731. }
  732. static inline void _wr_lock(pthread_rwlock_t *lock, const char *file, const char *func, const int line)
  733. {
  734. GETLOCK(lock, file, func, line);
  735. if (unlikely(pthread_rwlock_wrlock(lock)))
  736. quitfrom(1, file, func, line, "WTF WRLOCK ERROR ON LOCK! errno=%d", errno);
  737. GOTLOCK(lock, file, func, line);
  738. }
  739. static inline int _wr_trylock(pthread_rwlock_t *lock, __maybe_unused const char *file, __maybe_unused const char *func, __maybe_unused const int line)
  740. {
  741. TRYLOCK(lock, file, func, line);
  742. int ret = pthread_rwlock_trywrlock(lock);
  743. DIDLOCK(ret, lock, file, func, line);
  744. return ret;
  745. }
  746. static inline void _rd_lock(pthread_rwlock_t *lock, const char *file, const char *func, const int line)
  747. {
  748. GETLOCK(lock, file, func, line);
  749. if (unlikely(pthread_rwlock_rdlock(lock)))
  750. quitfrom(1, file, func, line, "WTF RDLOCK ERROR ON LOCK! errno=%d", errno);
  751. GOTLOCK(lock, file, func, line);
  752. }
  753. static inline void _rw_unlock(pthread_rwlock_t *lock, const char *file, const char *func, const int line)
  754. {
  755. if (unlikely(pthread_rwlock_unlock(lock)))
  756. quitfrom(1, file, func, line, "WTF RWLOCK ERROR ON UNLOCK! errno=%d", errno);
  757. GUNLOCK(lock, file, func, line);
  758. }
  759. static inline void _rd_unlock_noyield(pthread_rwlock_t *lock, const char *file, const char *func, const int line)
  760. {
  761. _rw_unlock(lock, file, func, line);
  762. }
  763. static inline void _wr_unlock_noyield(pthread_rwlock_t *lock, const char *file, const char *func, const int line)
  764. {
  765. _rw_unlock(lock, file, func, line);
  766. }
  767. static inline void _rd_unlock(pthread_rwlock_t *lock, const char *file, const char *func, const int line)
  768. {
  769. _rw_unlock(lock, file, func, line);
  770. selective_yield();
  771. }
  772. static inline void _wr_unlock(pthread_rwlock_t *lock, const char *file, const char *func, const int line)
  773. {
  774. _rw_unlock(lock, file, func, line);
  775. selective_yield();
  776. }
  777. static inline void _mutex_init(pthread_mutex_t *lock, const char *file, const char *func, const int line)
  778. {
  779. if (unlikely(pthread_mutex_init(lock, NULL)))
  780. quitfrom(1, file, func, line, "Failed to pthread_mutex_init errno=%d", errno);
  781. INITLOCK(lock, CGLOCK_MUTEX, file, func, line);
  782. }
  783. static inline void mutex_destroy(pthread_mutex_t *lock)
  784. {
  785. /* Ignore return code. This only invalidates the mutex on linux but
  786. * releases resources on windows. */
  787. pthread_mutex_destroy(lock);
  788. }
  789. static inline void _rwlock_init(pthread_rwlock_t *lock, const char *file, const char *func, const int line)
  790. {
  791. if (unlikely(pthread_rwlock_init(lock, NULL)))
  792. quitfrom(1, file, func, line, "Failed to pthread_rwlock_init errno=%d", errno);
  793. INITLOCK(lock, CGLOCK_RW, file, func, line);
  794. }
  795. static inline void rwlock_destroy(pthread_rwlock_t *lock)
  796. {
  797. pthread_rwlock_destroy(lock);
  798. }
  799. static inline void _cglock_init(cglock_t *lock, const char *file, const char *func, const int line)
  800. {
  801. _mutex_init(&lock->mutex, file, func, line);
  802. _rwlock_init(&lock->rwlock, file, func, line);
  803. }
  804. static inline void cglock_destroy(cglock_t *lock)
  805. {
  806. rwlock_destroy(&lock->rwlock);
  807. mutex_destroy(&lock->mutex);
  808. }
  809. /* Read lock variant of cglock. Cannot be promoted. */
  810. static inline void _cg_rlock(cglock_t *lock, const char *file, const char *func, const int line)
  811. {
  812. _mutex_lock(&lock->mutex, file, func, line);
  813. _rd_lock(&lock->rwlock, file, func, line);
  814. _mutex_unlock_noyield(&lock->mutex, file, func, line);
  815. }
  816. /* Intermediate variant of cglock - behaves as a read lock but can be promoted
  817. * to a write lock or demoted to read lock. */
  818. static inline void _cg_ilock(cglock_t *lock, const char *file, const char *func, const int line)
  819. {
  820. _mutex_lock(&lock->mutex, file, func, line);
  821. }
  822. /* Unlock intermediate variant without changing to read or write version */
  823. static inline void _cg_uilock(cglock_t *lock, const char *file, const char *func, const int line)
  824. {
  825. _mutex_unlock(&lock->mutex, file, func, line);
  826. }
  827. /* Upgrade intermediate variant to a write lock */
  828. static inline void _cg_ulock(cglock_t *lock, const char *file, const char *func, const int line)
  829. {
  830. _wr_lock(&lock->rwlock, file, func, line);
  831. }
  832. /* Write lock variant of cglock */
  833. static inline void _cg_wlock(cglock_t *lock, const char *file, const char *func, const int line)
  834. {
  835. _mutex_lock(&lock->mutex, file, func, line);
  836. _wr_lock(&lock->rwlock, file, func, line);
  837. }
  838. /* Downgrade write variant to a read lock */
  839. static inline void _cg_dwlock(cglock_t *lock, const char *file, const char *func, const int line)
  840. {
  841. _wr_unlock_noyield(&lock->rwlock, file, func, line);
  842. _rd_lock(&lock->rwlock, file, func, line);
  843. _mutex_unlock_noyield(&lock->mutex, file, func, line);
  844. }
  845. /* Demote a write variant to an intermediate variant */
  846. static inline void _cg_dwilock(cglock_t *lock, const char *file, const char *func, const int line)
  847. {
  848. _wr_unlock(&lock->rwlock, file, func, line);
  849. }
  850. /* Downgrade intermediate variant to a read lock */
  851. static inline void _cg_dlock(cglock_t *lock, const char *file, const char *func, const int line)
  852. {
  853. _rd_lock(&lock->rwlock, file, func, line);
  854. _mutex_unlock_noyield(&lock->mutex, file, func, line);
  855. }
  856. static inline void _cg_runlock(cglock_t *lock, const char *file, const char *func, const int line)
  857. {
  858. _rd_unlock(&lock->rwlock, file, func, line);
  859. }
  860. /* This drops the read lock and grabs a write lock. It does NOT protect data
  861. * between the two locks! */
  862. static inline void _cg_ruwlock(cglock_t *lock, const char *file, const char *func, const int line)
  863. {
  864. _rd_unlock_noyield(&lock->rwlock, file, func, line);
  865. _cg_wlock(lock, file, func, line);
  866. }
  867. static inline void _cg_wunlock(cglock_t *lock, const char *file, const char *func, const int line)
  868. {
  869. _wr_unlock_noyield(&lock->rwlock, file, func, line);
  870. _mutex_unlock(&lock->mutex, file, func, line);
  871. }
  872. struct pool;
  873. #define API_LISTEN_ADDR "0.0.0.0"
  874. #define API_MCAST_CODE "FTW"
  875. #define API_MCAST_ADDR "224.0.0.75"
  876. extern bool opt_mac_yield;
  877. extern bool opt_widescreen;
  878. extern bool opt_work_update;
  879. #if defined (USE_AVALON2) || defined (USE_AVALON4) || defined (USE_AVALON7) || defined (USE_AVALON8) || defined (USE_AVALON9) || defined (USE_AVALONLC3) || defined (USE_AVALON_MINER) || defined (USE_HASHRATIO)
  880. extern bool opt_clean_jobs;
  881. extern int opt_force_clean_jobs;
  882. #endif
  883. extern bool opt_protocol;
  884. extern bool have_longpoll;
  885. extern char *opt_kernel_path;
  886. extern char *opt_socks_proxy;
  887. extern int opt_suggest_diff;
  888. extern char *cgminer_path;
  889. extern bool opt_lowmem;
  890. extern bool opt_autofan;
  891. extern bool opt_autoengine;
  892. extern bool use_curses;
  893. extern char *opt_api_allow;
  894. extern bool opt_api_mcast;
  895. extern char *opt_api_mcast_addr;
  896. extern char *opt_api_mcast_code;
  897. extern char *opt_api_mcast_des;
  898. extern int opt_api_mcast_port;
  899. extern char *opt_api_groups;
  900. extern char *opt_api_description;
  901. extern int opt_api_port;
  902. extern char *opt_api_host;
  903. extern bool opt_api_listen;
  904. extern bool opt_api_network;
  905. extern bool opt_delaynet;
  906. extern time_t last_getwork;
  907. extern bool opt_restart;
  908. #ifdef USE_ICARUS
  909. extern char *opt_icarus_options;
  910. extern char *opt_icarus_timing;
  911. extern float opt_anu_freq;
  912. extern float opt_au3_freq;
  913. extern int opt_au3_volt;
  914. extern float opt_rock_freq;
  915. #endif
  916. extern bool opt_worktime;
  917. #ifdef USE_AVALON
  918. extern char *opt_avalon_options;
  919. extern char *opt_bitburner_fury_options;
  920. #endif
  921. #ifdef USE_GEKKO
  922. extern char *opt_gekko_serial;
  923. extern bool opt_gekko_noboost;
  924. extern bool opt_gekko_lowboost;
  925. extern bool opt_gekko_gsc_detect;
  926. extern bool opt_gekko_gsd_detect;
  927. extern bool opt_gekko_gse_detect;
  928. extern bool opt_gekko_gsh_detect;
  929. extern bool opt_gekko_bax_detect;
  930. extern bool opt_gekko_gsi_detect;
  931. extern bool opt_gekko_gsf_detect;
  932. extern bool opt_gekko_r909_detect;
  933. extern float opt_gekko_gsc_freq;
  934. extern float opt_gekko_gsd_freq;
  935. extern float opt_gekko_gse_freq;
  936. extern float opt_gekko_tune_down;
  937. extern float opt_gekko_tune_up;
  938. extern float opt_gekko_wait_factor;
  939. extern float opt_gekko_step_freq;
  940. extern int opt_gekko_bauddiv;
  941. extern int opt_gekko_gsh_freq;
  942. extern int opt_gekko_bax_freq;
  943. extern int opt_gekko_gsi_freq;
  944. extern int opt_gekko_gsf_freq;
  945. extern int opt_gekko_r909_freq;
  946. extern int opt_gekko_gsh_vcore;
  947. extern int opt_gekko_bax_vcore;
  948. extern int opt_gekko_start_freq;
  949. extern int opt_gekko_step_delay;
  950. extern int opt_gekko_tune2;
  951. #endif
  952. #ifdef USE_KLONDIKE
  953. extern char *opt_klondike_options;
  954. #endif
  955. #ifdef USE_DRILLBIT
  956. extern char *opt_drillbit_options;
  957. extern char *opt_drillbit_auto;
  958. #endif
  959. #ifdef USE_BAB
  960. extern char *opt_bab_options;
  961. #endif
  962. #ifdef USE_BITMINE_A1
  963. extern char *opt_bitmine_a1_options;
  964. #endif
  965. #ifdef USE_DRAGONMINT_T1
  966. extern char *opt_dragonmint_t1_options;
  967. extern int opt_T1Pll[];
  968. extern int opt_T1Vol[];
  969. extern int opt_T1VID[];
  970. extern bool opt_T1auto;
  971. extern bool opt_T1_efficient;
  972. extern bool opt_T1_performance;
  973. extern int opt_T1_target;
  974. #endif
  975. #ifdef USE_ANT_S1
  976. extern char *opt_bitmain_options;
  977. extern char *opt_bitmain_freq;
  978. extern bool opt_bitmain_hwerror;
  979. #endif
  980. #if (defined(USE_ANT_S2) || defined(USE_ANT_S3))
  981. #ifndef USE_ANT_S3
  982. extern char *opt_bitmain_dev;
  983. #endif
  984. extern char *opt_bitmain_options;
  985. extern char *opt_bitmain_freq;
  986. extern bool opt_bitmain_hwerror;
  987. extern bool opt_bitmain_checkall;
  988. extern bool opt_bitmain_checkn2diff;
  989. extern bool opt_bitmain_beeper;
  990. extern bool opt_bitmain_tempoverctrl;
  991. extern char *opt_bitmain_voltage;
  992. #endif
  993. #ifdef USE_MINION
  994. extern int opt_minion_chipreport;
  995. extern char *opt_minion_cores;
  996. extern bool opt_minion_extra;
  997. extern char *opt_minion_freq;
  998. extern int opt_minion_freqchange;
  999. extern int opt_minion_freqpercent;
  1000. extern bool opt_minion_idlecount;
  1001. extern int opt_minion_ledcount;
  1002. extern int opt_minion_ledlimit;
  1003. extern bool opt_minion_noautofreq;
  1004. extern bool opt_minion_overheat;
  1005. extern int opt_minion_spidelay;
  1006. extern char *opt_minion_spireset;
  1007. extern int opt_minion_spisleep;
  1008. extern int opt_minion_spiusec;
  1009. extern char *opt_minion_temp;
  1010. #endif
  1011. #ifdef USE_USBUTILS
  1012. extern char *opt_usb_select;
  1013. extern int opt_usbdump;
  1014. extern bool opt_usb_list_all;
  1015. extern cgsem_t usb_resource_sem;
  1016. #endif
  1017. #ifdef USE_BITFORCE
  1018. extern bool opt_bfl_noncerange;
  1019. #endif
  1020. extern int swork_id;
  1021. #if LOCK_TRACKING
  1022. extern pthread_mutex_t lockstat_lock;
  1023. #endif
  1024. extern pthread_rwlock_t netacc_lock;
  1025. extern const uint32_t sha256_init_state[];
  1026. #ifdef HAVE_LIBCURL
  1027. extern json_t *json_web_config(const char *url);
  1028. extern json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass,
  1029. const char *rpc_req, bool, bool, int *,
  1030. struct pool *pool, bool);
  1031. struct pool;
  1032. extern struct pool *opt_btcd;
  1033. #endif
  1034. extern const char *proxytype(proxytypes_t proxytype);
  1035. extern char *get_proxy(char *url, struct pool *pool);
  1036. extern void __bin2hex(char *s, const unsigned char *p, size_t len);
  1037. extern char *bin2hex(const unsigned char *p, size_t len);
  1038. extern bool hex2bin(unsigned char *p, const char *hexstr, size_t len);
  1039. typedef bool (*sha256_func)(struct thr_info*, const unsigned char *pmidstate,
  1040. unsigned char *pdata,
  1041. unsigned char *phash1, unsigned char *phash,
  1042. const unsigned char *ptarget,
  1043. uint32_t max_nonce,
  1044. uint32_t *last_nonce,
  1045. uint32_t nonce);
  1046. extern bool fulltest(const unsigned char *hash, const unsigned char *target);
  1047. extern const int max_scantime;
  1048. extern cglock_t control_lock;
  1049. extern pthread_mutex_t hash_lock;
  1050. extern pthread_mutex_t console_lock;
  1051. extern cglock_t ch_lock;
  1052. extern pthread_rwlock_t mining_thr_lock;
  1053. extern pthread_rwlock_t devices_lock;
  1054. extern pthread_mutex_t restart_lock;
  1055. extern pthread_cond_t restart_cond;
  1056. extern void clear_stratum_shares(struct pool *pool);
  1057. extern void clear_pool_work(struct pool *pool);
  1058. extern void set_target(unsigned char *dest_target, double diff);
  1059. #if defined (USE_AVALON2) || defined (USE_AVALON4) || defined (USE_AVALON7) || defined (USE_AVALON8) || defined (USE_AVALON9) || defined (USE_AVALONLC3) || defined (USE_AVALON_MINER) || defined (USE_HASHRATIO)
  1060. bool submit_nonce2_nonce(struct thr_info *thr, struct pool *pool, struct pool *real_pool,
  1061. uint32_t nonce2, uint32_t nonce, uint32_t ntime);
  1062. uint32_t gen_merkle_root(struct pool *pool, uint64_t nonce2);
  1063. #endif
  1064. #ifdef USE_BITMAIN_SOC
  1065. void get_work_by_nonce2(struct thr_info *thr,
  1066. struct work **work,
  1067. struct pool *pool,
  1068. struct pool *real_pool,
  1069. uint64_t nonce2,
  1070. uint32_t version);
  1071. #endif
  1072. extern int restart_wait(struct thr_info *thr, unsigned int mstime);
  1073. extern void raise_cgminer(void);
  1074. extern void kill_work(void);
  1075. extern void reinit_device(struct cgpu_info *cgpu);
  1076. extern void api(int thr_id);
  1077. extern struct pool *current_pool(void);
  1078. extern int enabled_pools;
  1079. extern void get_intrange(char *arg, int *val1, int *val2);
  1080. extern bool detect_stratum(struct pool *pool, char *url);
  1081. extern void print_summary(void);
  1082. extern void adjust_quota_gcd(void);
  1083. extern struct pool *add_pool(void);
  1084. extern bool add_pool_details(struct pool *pool, bool live, char *url, char *user, char *pass);
  1085. #define MAX_DEVICES 4096
  1086. extern bool hotplug_mode;
  1087. extern int hotplug_time;
  1088. extern struct list_head scan_devices;
  1089. extern int nDevs;
  1090. extern int num_processors;
  1091. extern int hw_errors;
  1092. extern bool use_syslog;
  1093. extern bool opt_quiet;
  1094. extern struct thr_info *control_thr;
  1095. extern struct thr_info **mining_thr;
  1096. extern double total_secs;
  1097. extern int mining_threads;
  1098. extern int total_devices;
  1099. extern int zombie_devs;
  1100. extern struct cgpu_info **devices;
  1101. extern int total_pools;
  1102. extern struct pool **pools;
  1103. extern struct strategies strategies[];
  1104. extern enum pool_strategy pool_strategy;
  1105. extern int opt_rotate_period;
  1106. extern double rolling1, rolling5, rolling15;
  1107. extern double total_rolling;
  1108. extern double total_mhashes_done;
  1109. extern unsigned int new_blocks;
  1110. extern unsigned int found_blocks;
  1111. extern int64_t total_accepted, total_rejected, total_diff1;
  1112. extern int64_t total_getworks, total_stale, total_discarded;
  1113. extern double total_diff_accepted, total_diff_rejected, total_diff_stale;
  1114. extern unsigned int local_work;
  1115. extern unsigned int total_go, total_ro;
  1116. extern const int opt_cutofftemp;
  1117. extern int opt_log_interval;
  1118. extern uint64_t global_hashrate;
  1119. extern char current_hash[68];
  1120. extern double current_diff;
  1121. extern uint64_t best_diff;
  1122. extern struct timeval block_timeval;
  1123. extern char *workpadding;
  1124. #ifdef USE_BITMAIN_SOC
  1125. extern char displayed_hash_rate[16];
  1126. #define NONCE_BUFF 4096
  1127. extern char nonce_num10_string[NONCE_BUFF];
  1128. extern char nonce_num30_string[NONCE_BUFF];
  1129. extern char nonce_num60_string[NONCE_BUFF];
  1130. extern char g_miner_version[256];
  1131. extern char g_miner_compiletime[256];
  1132. extern char g_miner_type[256];
  1133. extern double new_total_mhashes_done;
  1134. extern double new_total_secs;
  1135. extern time_t total_tv_start_sys;
  1136. extern time_t total_tv_end_sys;
  1137. extern void writeInitLogFile(char *logstr);
  1138. #endif
  1139. struct curl_ent {
  1140. CURL *curl;
  1141. struct list_head node;
  1142. struct timeval tv;
  1143. };
  1144. /* Disabled needs to be the lowest enum as a freshly calloced value will then
  1145. * equal disabled */
  1146. enum pool_enable {
  1147. POOL_DISABLED,
  1148. POOL_ENABLED,
  1149. POOL_REJECTING,
  1150. };
  1151. struct stratum_work {
  1152. char *job_id;
  1153. unsigned char **merkle_bin;
  1154. bool clean;
  1155. double diff;
  1156. };
  1157. #define RBUFSIZE 8192
  1158. #define RECVSIZE (RBUFSIZE - 4)
  1159. struct pool {
  1160. int pool_no;
  1161. int prio;
  1162. int64_t accepted, rejected;
  1163. int seq_rejects;
  1164. int seq_getfails;
  1165. int solved;
  1166. int64_t diff1;
  1167. char diff[8];
  1168. int quota;
  1169. int quota_gcd;
  1170. int quota_used;
  1171. int works;
  1172. double diff_accepted;
  1173. double diff_rejected;
  1174. double diff_stale;
  1175. /* Vmask data */
  1176. bool vmask; /* Supports vmask */
  1177. uint32_t vmask_001[16];
  1178. char vmask_002[16][9];
  1179. int vmask_003[4];
  1180. bool submit_fail;
  1181. bool idle;
  1182. bool probed;
  1183. enum pool_enable enabled;
  1184. bool submit_old;
  1185. bool removed;
  1186. bool lp_started;
  1187. bool blocking;
  1188. char *hdr_path;
  1189. char *lp_url;
  1190. unsigned int getwork_requested;
  1191. unsigned int stale_shares;
  1192. unsigned int discarded_work;
  1193. unsigned int getfail_occasions;
  1194. unsigned int remotefail_occasions;
  1195. struct timeval tv_idle;
  1196. double utility;
  1197. int last_shares, shares;
  1198. char *rpc_req;
  1199. char *rpc_url;
  1200. char *rpc_userpass;
  1201. char *rpc_user, *rpc_pass;
  1202. proxytypes_t rpc_proxytype;
  1203. char *rpc_proxy;
  1204. pthread_mutex_t pool_lock;
  1205. cglock_t data_lock;
  1206. struct thread_q *submit_q;
  1207. struct thread_q *getwork_q;
  1208. pthread_t longpoll_thread;
  1209. pthread_t test_thread;
  1210. bool testing;
  1211. int curls;
  1212. pthread_cond_t cr_cond;
  1213. struct list_head curlring;
  1214. time_t last_share_time;
  1215. double last_share_diff;
  1216. uint64_t best_diff;
  1217. uint64_t bad_work;
  1218. struct cgminer_stats cgminer_stats;
  1219. struct cgminer_pool_stats cgminer_pool_stats;
  1220. /* The last block this particular pool knows about */
  1221. char prev_block[32];
  1222. /* Stratum variables */
  1223. char *stratum_url;
  1224. #ifdef USE_XTRANONCE
  1225. bool extranonce_subscribe;
  1226. #endif
  1227. char *stratum_port;
  1228. SOCKETTYPE sock;
  1229. char *sockbuf;
  1230. size_t sockbuf_size;
  1231. char *sockaddr_url; /* stripped url used for sockaddr */
  1232. char *sockaddr_proxy_url;
  1233. char *sockaddr_proxy_port;
  1234. char *nonce1;
  1235. unsigned char *nonce1bin;
  1236. uint64_t nonce2;
  1237. int n2size;
  1238. char *sessionid;
  1239. bool has_stratum;
  1240. bool stratum_active;
  1241. bool stratum_init;
  1242. bool stratum_notify;
  1243. struct stratum_work swork;
  1244. pthread_t stratum_sthread;
  1245. pthread_t stratum_rthread;
  1246. pthread_mutex_t stratum_lock;
  1247. struct thread_q *stratum_q;
  1248. int sshares; /* stratum shares submitted waiting on response */
  1249. /* GBT variables */
  1250. bool has_gbt;
  1251. cglock_t gbt_lock;
  1252. unsigned char previousblockhash[32];
  1253. unsigned char gbt_target[32];
  1254. char *coinbasetxn;
  1255. char *longpollid;
  1256. char *gbt_workid;
  1257. int gbt_expires;
  1258. uint32_t gbt_version;
  1259. uint32_t curtime;
  1260. uint32_t gbt_bits;
  1261. unsigned char *txn_hashes;
  1262. int gbt_txns;
  1263. int height;
  1264. bool gbt_solo;
  1265. unsigned char merklebin[16 * 32];
  1266. int transactions;
  1267. char *txn_data;
  1268. unsigned char scriptsig_base[100];
  1269. unsigned char script_pubkey[25 + 3];
  1270. int nValue;
  1271. CURL *gbt_curl;
  1272. bool gbt_curl_inuse;
  1273. /* Shared by both stratum & GBT */
  1274. size_t n1_len;
  1275. unsigned char *coinbase;
  1276. int coinbase_len;
  1277. int nonce2_offset;
  1278. unsigned char header_bin[128];
  1279. int merkles;
  1280. char prev_hash[68];
  1281. char bbversion[12];
  1282. char nbit[12];
  1283. char ntime[12];
  1284. double next_diff;
  1285. double diff_after;
  1286. double sdiff;
  1287. uint32_t current_height;
  1288. struct timeval tv_lastwork;
  1289. #ifdef USE_BITMAIN_SOC
  1290. bool support_vil;
  1291. int version_num;
  1292. int version[4];
  1293. #endif
  1294. };
  1295. #define GETWORK_MODE_TESTPOOL 'T'
  1296. #define GETWORK_MODE_POOL 'P'
  1297. #define GETWORK_MODE_LP 'L'
  1298. #define GETWORK_MODE_BENCHMARK 'B'
  1299. #define GETWORK_MODE_STRATUM 'S'
  1300. #define GETWORK_MODE_GBT 'G'
  1301. #define GETWORK_MODE_SOLO 'C'
  1302. struct work {
  1303. unsigned char data[128];
  1304. unsigned char midstate[32];
  1305. unsigned char midstate1[32];
  1306. unsigned char midstate2[32];
  1307. unsigned char midstate3[32];
  1308. unsigned char target[32];
  1309. unsigned char hash[32];
  1310. uint16_t micro_job_id;
  1311. /* This is the diff the device is currently aiming for and must be
  1312. * the minimum of work_difficulty & drv->max_diff */
  1313. double device_diff;
  1314. uint64_t share_diff;
  1315. int rolls;
  1316. int drv_rolllimit; /* How much the driver can roll ntime */
  1317. uint32_t nonce; /* For devices that hash sole work */
  1318. struct thr_info *thr;
  1319. int thr_id;
  1320. struct pool *pool;
  1321. struct timeval tv_staged;
  1322. bool mined;
  1323. bool clone;
  1324. bool cloned;
  1325. int rolltime;
  1326. bool longpoll;
  1327. bool stale;
  1328. bool mandatory;
  1329. bool block;
  1330. bool stratum;
  1331. char *job_id;
  1332. uint64_t nonce2;
  1333. size_t nonce2_len;
  1334. char *ntime;
  1335. double sdiff;
  1336. char *nonce1;
  1337. bool gbt;
  1338. char *coinbase;
  1339. int gbt_txns;
  1340. unsigned int work_block;
  1341. uint32_t id;
  1342. UT_hash_handle hh;
  1343. /* This is the diff work we're aiming to submit and should match the
  1344. * work->target binary */
  1345. double work_difficulty;
  1346. // Allow devices to identify work if multiple sub-devices
  1347. int subid;
  1348. // Allow devices to flag work for their own purposes
  1349. bool devflag;
  1350. // Allow devices to timestamp work for their own purposes
  1351. struct timeval tv_stamp;
  1352. struct timeval tv_getwork;
  1353. struct timeval tv_getwork_reply;
  1354. struct timeval tv_cloned;
  1355. struct timeval tv_work_start;
  1356. struct timeval tv_work_found;
  1357. char getwork_mode;
  1358. #ifdef USE_BITMAIN_SOC
  1359. int version;
  1360. #endif
  1361. };
  1362. // enable grossly global stratum work stats
  1363. #define STRATUM_WORK_TIMING 1
  1364. #if STRATUM_WORK_TIMING
  1365. extern cglock_t swt_lock;
  1366. extern uint64_t stratum_work_count;
  1367. extern uint64_t stratum_work_time;
  1368. extern uint64_t stratum_work_min;
  1369. extern uint64_t stratum_work_max;
  1370. extern uint64_t stratum_work_time0;
  1371. extern uint64_t stratum_work_time10;
  1372. extern uint64_t stratum_work_time100;
  1373. #endif
  1374. #ifdef USE_MODMINER
  1375. struct modminer_fpga_state {
  1376. bool work_running;
  1377. struct work running_work;
  1378. struct timeval tv_workstart;
  1379. uint32_t hashes;
  1380. char next_work_cmd[46];
  1381. char fpgaid;
  1382. bool overheated;
  1383. bool new_work;
  1384. uint32_t shares;
  1385. uint32_t shares_last_hw;
  1386. uint32_t hw_errors;
  1387. uint32_t shares_to_good;
  1388. uint32_t timeout_fail;
  1389. uint32_t success_more;
  1390. struct timeval last_changed;
  1391. struct timeval last_nonce;
  1392. struct timeval first_work;
  1393. bool death_stage_one;
  1394. bool tried_two_byte_temp;
  1395. bool one_byte_temp;
  1396. };
  1397. #endif
  1398. #define TAILBUFSIZ 64
  1399. #define tailsprintf(buf, bufsiz, fmt, ...) do { \
  1400. char tmp13[TAILBUFSIZ]; \
  1401. size_t len13, buflen = strlen(buf); \
  1402. snprintf(tmp13, sizeof(tmp13), fmt, ##__VA_ARGS__); \
  1403. len13 = strlen(tmp13); \
  1404. if ((buflen + len13) >= bufsiz) \
  1405. quit(1, "tailsprintf buffer overflow in %s %s line %d", __FILE__, __func__, __LINE__); \
  1406. strcat(buf, tmp13); \
  1407. } while (0)
  1408. extern void get_datestamp(char *, size_t, struct timeval *);
  1409. extern void inc_hw_errors_n(struct thr_info *thr, int n);
  1410. extern void inc_hw_errors(struct thr_info *thr);
  1411. extern bool test_nonce(struct work *work, uint32_t nonce);
  1412. extern bool test_nonce_diff(struct work *work, uint32_t nonce, double diff);
  1413. extern double test_nonce_value(struct work *work, uint32_t nonce);
  1414. extern bool submit_tested_work(struct thr_info *thr, struct work *work);
  1415. extern bool submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce);
  1416. extern bool submit_noffset_nonce(struct thr_info *thr, struct work *work, uint32_t nonce,
  1417. int noffset);
  1418. extern int share_work_tdiff(struct cgpu_info *cgpu);
  1419. extern struct work *get_work(struct thr_info *thr, const int thr_id);
  1420. extern void __add_queued(struct cgpu_info *cgpu, struct work *work);
  1421. extern struct work *get_queued(struct cgpu_info *cgpu);
  1422. extern struct work *__get_queued(struct cgpu_info *cgpu);
  1423. extern void add_queued(struct cgpu_info *cgpu, struct work *work);
  1424. extern struct work *get_queue_work(struct thr_info *thr, struct cgpu_info *cgpu, int thr_id);
  1425. extern struct work *__find_work_bymidstate(struct work *que, char *midstate, size_t midstatelen, char *data, int offset, size_t datalen);
  1426. extern struct work *find_queued_work_bymidstate(struct cgpu_info *cgpu, char *midstate, size_t midstatelen, char *data, int offset, size_t datalen);
  1427. extern struct work *clone_queued_work_bymidstate(struct cgpu_info *cgpu, char *midstate, size_t midstatelen, char *data, int offset, size_t datalen);
  1428. extern struct work *__find_work_byid(struct work *que, uint32_t id);
  1429. extern struct work *find_queued_work_byid(struct cgpu_info *cgpu, uint32_t id);
  1430. extern struct work *clone_queued_work_byid(struct cgpu_info *cgpu, uint32_t id);
  1431. extern void __work_completed(struct cgpu_info *cgpu, struct work *work);
  1432. extern int age_queued_work(struct cgpu_info *cgpu, double secs);
  1433. extern void work_completed(struct cgpu_info *cgpu, struct work *work);
  1434. extern struct work *take_queued_work_bymidstate(struct cgpu_info *cgpu, char *midstate, size_t midstatelen, char *data, int offset, size_t datalen);
  1435. extern void flush_queue(struct cgpu_info *cgpu);
  1436. extern void hash_driver_work(struct thr_info *mythr);
  1437. extern void hash_queued_work(struct thr_info *mythr);
  1438. extern void _wlog(const char *str);
  1439. extern void _wlogprint(const char *str);
  1440. extern int curses_int(const char *query);
  1441. extern char *curses_input(const char *query);
  1442. extern void kill_work(void);
  1443. extern void switch_pools(struct pool *selected);
  1444. extern void _discard_work(struct work **workptr, const char *file, const char *func, const int line);
  1445. #define discard_work(WORK) _discard_work(&(WORK), __FILE__, __func__, __LINE__)
  1446. extern void remove_pool(struct pool *pool);
  1447. extern void write_config(FILE *fcfg);
  1448. extern void zero_bestshare(void);
  1449. extern void zero_stats(void);
  1450. extern void default_save_file(char *filename);
  1451. extern bool log_curses_only(int prio, const char *datetime, const char *str);
  1452. extern void clear_logwin(void);
  1453. extern void logwin_update(void);
  1454. extern bool pool_tclear(struct pool *pool, bool *var);
  1455. extern void stratum_resumed(struct pool *pool);
  1456. extern void pool_died(struct pool *pool);
  1457. extern struct thread_q *tq_new(void);
  1458. extern void tq_free(struct thread_q *tq);
  1459. extern bool tq_push(struct thread_q *tq, void *data);
  1460. #if defined (USE_AVALON2) || defined (USE_AVALON4) || defined (USE_AVALON7) || defined (USE_AVALON8) || defined (USE_AVALON9) || defined (USE_AVALON_MINER) || defined (USE_HASHRATIO)
  1461. extern void *tq_pop(struct thread_q *tq, const struct timespec *abstime);
  1462. #else
  1463. extern void *tq_pop(struct thread_q *tq);
  1464. #endif
  1465. extern void tq_freeze(struct thread_q *tq);
  1466. extern void tq_thaw(struct thread_q *tq);
  1467. extern bool successful_connect;
  1468. extern void adl(void);
  1469. extern void app_restart(void);
  1470. extern void roll_work(struct work *work);
  1471. extern void roll_work_ntime(struct work *work, int noffset);
  1472. extern struct work *make_clone(struct work *work);
  1473. extern void clean_work(struct work *work);
  1474. extern void _free_work(struct work **workptr, const char *file, const char *func, const int line);
  1475. #define free_work(WORK) _free_work(&(WORK), __FILE__, __func__, __LINE__)
  1476. extern void set_work_ntime(struct work *work, int ntime);
  1477. extern struct work *copy_work_noffset(struct work *base_work, int noffset);
  1478. #define copy_work(work_in) copy_work_noffset(work_in, 0)
  1479. extern uint64_t share_diff(const struct work *work);
  1480. extern struct thr_info *get_thread(int thr_id);
  1481. extern struct cgpu_info *get_devices(int id);
  1482. enum api_data_type {
  1483. API_ESCAPE,
  1484. API_STRING,
  1485. API_CONST,
  1486. API_UINT8,
  1487. API_INT16,
  1488. API_UINT16,
  1489. API_INT,
  1490. API_UINT,
  1491. API_UINT32,
  1492. API_HEX32,
  1493. API_UINT64,
  1494. API_INT64,
  1495. API_DOUBLE,
  1496. API_FLOAT,
  1497. API_ELAPSED,
  1498. API_BOOL,
  1499. API_TIMEVAL,
  1500. API_TIME,
  1501. API_MHS,
  1502. API_MHTOTAL,
  1503. API_TEMP,
  1504. API_UTILITY,
  1505. API_FREQ,
  1506. API_VOLTS,
  1507. API_HS,
  1508. API_DIFF,
  1509. API_PERCENT,
  1510. API_AVG
  1511. };
  1512. struct api_data {
  1513. enum api_data_type type;
  1514. char *name;
  1515. void *data;
  1516. bool data_was_malloc;
  1517. struct api_data *prev;
  1518. struct api_data *next;
  1519. };
  1520. extern struct api_data *api_add_escape(struct api_data *root, char *name, char *data, bool copy_data);
  1521. extern struct api_data *api_add_string(struct api_data *root, char *name, char *data, bool copy_data);
  1522. extern struct api_data *api_add_const(struct api_data *root, char *name, const char *data, bool copy_data);
  1523. extern struct api_data *api_add_uint8(struct api_data *root, char *name, uint8_t *data, bool copy_data);
  1524. extern struct api_data *api_add_int16(struct api_data *root, char *name, uint16_t *data, bool copy_data);
  1525. extern struct api_data *api_add_uint16(struct api_data *root, char *name, uint16_t *data, bool copy_data);
  1526. extern struct api_data *api_add_int(struct api_data *root, char *name, int *data, bool copy_data);
  1527. extern struct api_data *api_add_uint(struct api_data *root, char *name, unsigned int *data, bool copy_data);
  1528. extern struct api_data *api_add_uint32(struct api_data *root, char *name, uint32_t *data, bool copy_data);
  1529. extern struct api_data *api_add_hex32(struct api_data *root, char *name, uint32_t *data, bool copy_data);
  1530. extern struct api_data *api_add_uint64(struct api_data *root, char *name, uint64_t *data, bool copy_data);
  1531. extern struct api_data *api_add_int64(struct api_data *root, char *name, int64_t *data, bool copy_data);
  1532. extern struct api_data *api_add_double(struct api_data *root, char *name, double *data, bool copy_data);
  1533. extern struct api_data *api_add_float(struct api_data *root, char *name, float *data, bool copy_data);
  1534. extern struct api_data *api_add_elapsed(struct api_data *root, char *name, double *data, bool copy_data);
  1535. extern struct api_data *api_add_bool(struct api_data *root, char *name, bool *data, bool copy_data);
  1536. extern struct api_data *api_add_timeval(struct api_data *root, char *name, struct timeval *data, bool copy_data);
  1537. extern struct api_data *api_add_time(struct api_data *root, char *name, time_t *data, bool copy_data);
  1538. extern struct api_data *api_add_mhs(struct api_data *root, char *name, double *data, bool copy_data);
  1539. extern struct api_data *api_add_mhstotal(struct api_data *root, char *name, double *data, bool copy_data);
  1540. extern struct api_data *api_add_temp(struct api_data *root, char *name, float *data, bool copy_data);
  1541. extern struct api_data *api_add_utility(struct api_data *root, char *name, double *data, bool copy_data);
  1542. extern struct api_data *api_add_freq(struct api_data *root, char *name, double *data, bool copy_data);
  1543. extern struct api_data *api_add_volts(struct api_data *root, char *name, float *data, bool copy_data);
  1544. extern struct api_data *api_add_hs(struct api_data *root, char *name, double *data, bool copy_data);
  1545. extern struct api_data *api_add_diff(struct api_data *root, char *name, double *data, bool copy_data);
  1546. extern struct api_data *api_add_percent(struct api_data *root, char *name, double *data, bool copy_data);
  1547. extern struct api_data *api_add_avg(struct api_data *root, char *name, float *data, bool copy_data);
  1548. #define ROOT_ADD_API(FUNC, NAME, VAR, BOOL) root = api_add_##FUNC(root, (NAME), &(VAR), (BOOL))
  1549. extern void dupalloc(struct cgpu_info *cgpu, int timelimit);
  1550. extern void dupcounters(struct cgpu_info *cgpu, uint64_t *checked, uint64_t *dups);
  1551. extern bool isdupnonce(struct cgpu_info *cgpu, struct work *work, uint32_t nonce);
  1552. #endif /* __MINER_H__ */