miner.h 34 KB

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