miner.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. #ifndef __MINER_H__
  2. #define __MINER_H__
  3. #include "config.h"
  4. #include <stdbool.h>
  5. #include <stdint.h>
  6. #include <sys/time.h>
  7. #include <pthread.h>
  8. #include <jansson.h>
  9. #include <curl/curl.h>
  10. #include "elist.h"
  11. #include "uthash.h"
  12. #include "logging.h"
  13. #ifdef HAVE_OPENCL
  14. #include "CL/cl.h"
  15. #endif /* HAVE_OPENCL */
  16. #ifdef STDC_HEADERS
  17. # include <stdlib.h>
  18. # include <stddef.h>
  19. #else
  20. # ifdef HAVE_STDLIB_H
  21. # include <stdlib.h>
  22. # endif
  23. #endif
  24. #ifdef HAVE_ALLOCA_H
  25. # include <alloca.h>
  26. #elif defined __GNUC__
  27. # ifndef WIN32
  28. # define alloca __builtin_alloca
  29. # else
  30. # include <malloc.h>
  31. # endif
  32. #elif defined _AIX
  33. # define alloca __alloca
  34. #elif defined _MSC_VER
  35. # include <malloc.h>
  36. # define alloca _alloca
  37. #else
  38. # ifndef HAVE_ALLOCA
  39. # ifdef __cplusplus
  40. extern "C"
  41. # endif
  42. void *alloca (size_t);
  43. # endif
  44. #endif
  45. #if defined (__linux)
  46. #ifndef LINUX
  47. #define LINUX
  48. #endif
  49. #endif
  50. #ifdef WIN32
  51. #ifndef timersub
  52. #define timersub(a, b, result) \
  53. do { \
  54. (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
  55. (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
  56. if ((result)->tv_usec < 0) { \
  57. --(result)->tv_sec; \
  58. (result)->tv_usec += 1000000; \
  59. } \
  60. } while (0)
  61. #endif
  62. #ifndef timeradd
  63. # define timeradd(a, b, result) \
  64. do { \
  65. (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
  66. (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
  67. if ((result)->tv_usec >= 1000000) \
  68. { \
  69. ++(result)->tv_sec; \
  70. (result)->tv_usec -= 1000000; \
  71. } \
  72. } while (0)
  73. #endif
  74. #endif
  75. #ifdef HAVE_ADL
  76. #include "ADL_SDK/adl_sdk.h"
  77. #endif
  78. #ifdef HAVE_LIBUSB
  79. #include <libusb-1.0/libusb.h>
  80. #endif
  81. #ifdef USE_ZTEX
  82. #include "libztex.h"
  83. #endif
  84. #if !defined(WIN32) && ((__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3))
  85. #define bswap_16 __builtin_bswap16
  86. #define bswap_32 __builtin_bswap32
  87. #define bswap_64 __builtin_bswap64
  88. #else
  89. #if HAVE_BYTESWAP_H
  90. #include <byteswap.h>
  91. #elif defined(USE_SYS_ENDIAN_H)
  92. #include <sys/endian.h>
  93. #elif defined(__APPLE__)
  94. #include <libkern/OSByteOrder.h>
  95. #define bswap_16 OSSwapInt16
  96. #define bswap_32 OSSwapInt32
  97. #define bswap_64 OSSwapInt64
  98. #else
  99. #define bswap_16(value) \
  100. ((((value) & 0xff) << 8) | ((value) >> 8))
  101. #define bswap_32(value) \
  102. (((uint32_t)bswap_16((uint16_t)((value) & 0xffff)) << 16) | \
  103. (uint32_t)bswap_16((uint16_t)((value) >> 16)))
  104. #define bswap_64(value) \
  105. (((uint64_t)bswap_32((uint32_t)((value) & 0xffffffff)) \
  106. << 32) | \
  107. (uint64_t)bswap_32((uint32_t)((value) >> 32)))
  108. #endif
  109. #endif /* !defined(__GLXBYTEORDER_H__) */
  110. /* This assumes htobe32 is a macro in endian.h */
  111. #ifndef htobe32
  112. # if __BYTE_ORDER == __LITTLE_ENDIAN
  113. # define be32toh(x) bswap_32(x)
  114. # define htobe32(x) bswap_32(x)
  115. # elif __BYTE_ORDER == __BIG_ENDIAN
  116. # define be32toh(x) (x)
  117. # define htobe32(x) (x)
  118. #else
  119. #error UNKNOWN BYTE ORDER
  120. #endif
  121. #endif
  122. #undef unlikely
  123. #undef likely
  124. #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
  125. #define unlikely(expr) (__builtin_expect(!!(expr), 0))
  126. #define likely(expr) (__builtin_expect(!!(expr), 1))
  127. #else
  128. #define unlikely(expr) (expr)
  129. #define likely(expr) (expr)
  130. #endif
  131. #define __maybe_unused __attribute__((unused))
  132. #define uninitialised_var(x) x = x
  133. #if defined(__i386__)
  134. #define WANT_CRYPTOPP_ASM32
  135. #endif
  136. #ifndef ARRAY_SIZE
  137. #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
  138. #endif
  139. enum alive {
  140. LIFE_WELL,
  141. LIFE_SICK,
  142. LIFE_DEAD,
  143. LIFE_NOSTART
  144. };
  145. enum pool_strategy {
  146. POOL_FAILOVER,
  147. POOL_ROUNDROBIN,
  148. POOL_ROTATE,
  149. POOL_LOADBALANCE,
  150. };
  151. #define TOP_STRATEGY (POOL_LOADBALANCE)
  152. struct strategies {
  153. const char *s;
  154. };
  155. struct cgpu_info;
  156. #ifdef HAVE_ADL
  157. struct gpu_adl {
  158. ADLTemperature lpTemperature;
  159. int iAdapterIndex;
  160. int lpAdapterID;
  161. int iBusNumber;
  162. char strAdapterName[256];
  163. ADLPMActivity lpActivity;
  164. ADLODParameters lpOdParameters;
  165. ADLODPerformanceLevels *DefPerfLev;
  166. ADLFanSpeedInfo lpFanSpeedInfo;
  167. ADLFanSpeedValue lpFanSpeedValue;
  168. ADLFanSpeedValue DefFanSpeedValue;
  169. int iEngineClock;
  170. int iMemoryClock;
  171. int iVddc;
  172. int iPercentage;
  173. bool autofan;
  174. bool autoengine;
  175. bool managed; /* Were the values ever changed on this card */
  176. int lastengine;
  177. int lasttemp;
  178. int targetfan;
  179. int targettemp;
  180. int overtemp;
  181. int minspeed;
  182. int maxspeed;
  183. int gpu;
  184. bool has_fanspeed;
  185. struct gpu_adl *twin;
  186. };
  187. #endif
  188. struct thr_info;
  189. struct work;
  190. struct device_api {
  191. const char*dname;
  192. const char*name;
  193. // API-global functions
  194. void (*api_detect)();
  195. // Device-specific functions
  196. void (*reinit_device)(struct cgpu_info*);
  197. void (*get_statline_before)(char*, struct cgpu_info*);
  198. void (*get_statline)(char*, struct cgpu_info*);
  199. json_t* (*get_extra_device_detail)(struct cgpu_info*);
  200. json_t* (*get_extra_device_status)(struct cgpu_info*);
  201. json_t* (*get_extra_device_perf_stats)(struct cgpu_info*);
  202. // Thread-specific functions
  203. bool (*thread_prepare)(struct thr_info*);
  204. uint64_t (*can_limit_work)(struct thr_info*);
  205. bool (*thread_init)(struct thr_info*);
  206. void (*free_work)(struct thr_info*, struct work*);
  207. bool (*prepare_work)(struct thr_info*, struct work*);
  208. uint64_t (*scanhash)(struct thr_info*, struct work*, uint64_t);
  209. void (*thread_shutdown)(struct thr_info*);
  210. };
  211. enum dev_enable {
  212. DEV_ENABLED,
  213. DEV_DISABLED,
  214. DEV_RECOVER,
  215. };
  216. enum cl_kernels {
  217. KL_NONE,
  218. KL_POCLBM,
  219. KL_PHATK,
  220. KL_DIAKGCN,
  221. KL_DIABLO,
  222. };
  223. enum dev_reason {
  224. REASON_THREAD_FAIL_INIT,
  225. REASON_THREAD_ZERO_HASH,
  226. REASON_THREAD_FAIL_QUEUE,
  227. REASON_DEV_SICK_IDLE_60,
  228. REASON_DEV_DEAD_IDLE_600,
  229. REASON_DEV_NOSTART,
  230. REASON_DEV_OVER_HEAT,
  231. REASON_DEV_THERMAL_CUTOFF,
  232. };
  233. #define REASON_NONE "None"
  234. #define REASON_THREAD_FAIL_INIT_STR "Thread failed to init"
  235. #define REASON_THREAD_ZERO_HASH_STR "Thread got zero hashes"
  236. #define REASON_THREAD_FAIL_QUEUE_STR "Thread failed to queue work"
  237. #define REASON_DEV_SICK_IDLE_60_STR "Device idle for 60s"
  238. #define REASON_DEV_DEAD_IDLE_600_STR "Device dead - idle for 600s"
  239. #define REASON_DEV_NOSTART_STR "Device failed to start"
  240. #define REASON_DEV_OVER_HEAT_STR "Device over heated"
  241. #define REASON_DEV_THERMAL_CUTOFF_STR "Device reached thermal cutoff"
  242. #define REASON_UNKNOWN_STR "Unknown reason - code bug"
  243. #define MIN_SEC_UNSET 99999999
  244. struct cgminer_stats {
  245. uint32_t getwork_calls;
  246. struct timeval getwork_wait;
  247. struct timeval getwork_wait_max;
  248. struct timeval getwork_wait_min;
  249. };
  250. struct cgpu_info {
  251. int cgminer_id;
  252. const struct device_api *api;
  253. int device_id;
  254. const char *name;
  255. const char *device_path;
  256. FILE *device_file;
  257. union {
  258. #ifdef USE_ZTEX
  259. struct libztex_device *device_ztex;
  260. #endif
  261. int device_fd;
  262. };
  263. enum dev_enable deven;
  264. int accepted;
  265. int rejected;
  266. int hw_errors;
  267. double rolling;
  268. double total_mhashes;
  269. double utility;
  270. enum alive status;
  271. char init[40];
  272. struct timeval last_message_tv;
  273. int threads;
  274. struct thr_info *thread;
  275. unsigned int max_hashes;
  276. bool mapped;
  277. int virtual_gpu;
  278. int virtual_adl;
  279. int intensity;
  280. bool dynamic;
  281. const char *kname;
  282. #ifdef HAVE_OPENCL
  283. cl_uint vwidth;
  284. size_t work_size;
  285. enum cl_kernels kernel;
  286. #endif
  287. float temp;
  288. int cutofftemp;
  289. #ifdef HAVE_ADL
  290. bool has_adl;
  291. struct gpu_adl adl;
  292. int gpu_engine;
  293. int min_engine;
  294. int gpu_fan;
  295. int min_fan;
  296. int gpu_memclock;
  297. int gpu_memdiff;
  298. int gpu_powertune;
  299. float gpu_vddc;
  300. #endif
  301. int last_share_pool;
  302. time_t last_share_pool_time;
  303. time_t device_last_well;
  304. time_t device_last_not_well;
  305. enum dev_reason device_not_well_reason;
  306. int thread_fail_init_count;
  307. int thread_zero_hash_count;
  308. int thread_fail_queue_count;
  309. int dev_sick_idle_60_count;
  310. int dev_dead_idle_600_count;
  311. int dev_nostart_count;
  312. int dev_over_heat_count; // It's a warning but worth knowing
  313. int dev_thermal_cutoff_count;
  314. struct cgminer_stats cgminer_stats;
  315. };
  316. extern bool add_cgpu(struct cgpu_info*);
  317. struct thread_q {
  318. struct list_head q;
  319. bool frozen;
  320. pthread_mutex_t mutex;
  321. pthread_cond_t cond;
  322. };
  323. struct thr_info {
  324. int id;
  325. int device_thread;
  326. pthread_t pth;
  327. struct thread_q *q;
  328. struct cgpu_info *cgpu;
  329. void *cgpu_data;
  330. struct timeval last;
  331. struct timeval sick;
  332. bool pause;
  333. bool getwork;
  334. double rolling;
  335. };
  336. extern int thr_info_create(struct thr_info *thr, pthread_attr_t *attr, void *(*start) (void *), void *arg);
  337. extern void thr_info_cancel(struct thr_info *thr);
  338. extern void thr_info_freeze(struct thr_info *thr);
  339. struct string_elist {
  340. char *string;
  341. bool free_me;
  342. struct list_head list;
  343. };
  344. static inline void string_elist_add(const char *s, struct list_head *head)
  345. {
  346. struct string_elist *n;
  347. n = calloc(1, sizeof(*n));
  348. n->string = strdup(s);
  349. n->free_me = true;
  350. list_add_tail(&n->list, head);
  351. }
  352. static inline void string_elist_del(struct string_elist *item)
  353. {
  354. if (item->free_me)
  355. free(item->string);
  356. list_del(&item->list);
  357. }
  358. static inline uint32_t swab32(uint32_t v)
  359. {
  360. return bswap_32(v);
  361. }
  362. static inline void swap256(void *dest_p, const void *src_p)
  363. {
  364. uint32_t *dest = dest_p;
  365. const uint32_t *src = src_p;
  366. dest[0] = src[7];
  367. dest[1] = src[6];
  368. dest[2] = src[5];
  369. dest[3] = src[4];
  370. dest[4] = src[3];
  371. dest[5] = src[2];
  372. dest[6] = src[1];
  373. dest[7] = src[0];
  374. }
  375. extern void quit(int status, const char *format, ...);
  376. static inline void mutex_lock(pthread_mutex_t *lock)
  377. {
  378. if (unlikely(pthread_mutex_lock(lock)))
  379. quit(1, "WTF MUTEX ERROR ON LOCK!");
  380. }
  381. static inline void mutex_unlock(pthread_mutex_t *lock)
  382. {
  383. if (unlikely(pthread_mutex_unlock(lock)))
  384. quit(1, "WTF MUTEX ERROR ON UNLOCK!");
  385. }
  386. static inline void wr_lock(pthread_rwlock_t *lock)
  387. {
  388. if (unlikely(pthread_rwlock_wrlock(lock)))
  389. quit(1, "WTF WRLOCK ERROR ON LOCK!");
  390. }
  391. static inline void rd_lock(pthread_rwlock_t *lock)
  392. {
  393. if (unlikely(pthread_rwlock_rdlock(lock)))
  394. quit(1, "WTF RDLOCK ERROR ON LOCK!");
  395. }
  396. static inline void rw_unlock(pthread_rwlock_t *lock)
  397. {
  398. if (unlikely(pthread_rwlock_unlock(lock)))
  399. quit(1, "WTF RWLOCK ERROR ON UNLOCK!");
  400. }
  401. static inline void rd_unlock(pthread_rwlock_t *lock)
  402. {
  403. rw_unlock(lock);
  404. }
  405. static inline void wr_unlock(pthread_rwlock_t *lock)
  406. {
  407. rw_unlock(lock);
  408. }
  409. static inline void mutex_init(pthread_mutex_t *lock)
  410. {
  411. if (unlikely(pthread_mutex_init(lock, NULL)))
  412. quit(1, "Failed to pthread_mutex_init");
  413. }
  414. static inline void rwlock_init(pthread_rwlock_t *lock)
  415. {
  416. if (unlikely(pthread_rwlock_init(lock, NULL)))
  417. quit(1, "Failed to pthread_rwlock_init");
  418. }
  419. struct pool;
  420. extern bool opt_protocol;
  421. extern char *opt_kernel_path;
  422. extern char *opt_socks_proxy;
  423. extern char *cgminer_path;
  424. extern bool opt_autofan;
  425. extern bool opt_autoengine;
  426. extern bool use_curses;
  427. extern char *opt_api_allow;
  428. extern char *opt_api_description;
  429. extern int opt_api_port;
  430. extern bool opt_api_listen;
  431. extern bool opt_api_network;
  432. extern bool opt_delaynet;
  433. extern bool opt_restart;
  434. extern char *opt_icarus_timing;
  435. extern pthread_rwlock_t netacc_lock;
  436. extern const uint32_t sha256_init_state[];
  437. extern json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass,
  438. const char *rpc_req, bool, bool, bool *,
  439. struct pool *pool, bool);
  440. extern char *bin2hex(const unsigned char *p, size_t len);
  441. extern bool hex2bin(unsigned char *p, const char *hexstr, size_t len);
  442. typedef bool (*sha256_func)(int thr_id, const unsigned char *pmidstate,
  443. unsigned char *pdata,
  444. unsigned char *phash1, unsigned char *phash,
  445. const unsigned char *ptarget,
  446. uint32_t max_nonce,
  447. uint32_t *last_nonce,
  448. uint32_t nonce);
  449. extern int
  450. timeval_subtract (struct timeval *result, struct timeval *x, struct timeval *y);
  451. extern bool fulltest(const unsigned char *hash, const unsigned char *target);
  452. extern int opt_scantime;
  453. struct work_restart {
  454. volatile unsigned long restart;
  455. char padding[128 - sizeof(unsigned long)];
  456. };
  457. extern void thread_reportin(struct thr_info *thr);
  458. extern void kill_work(void);
  459. extern void reinit_device(struct cgpu_info *cgpu);
  460. #ifdef HAVE_ADL
  461. extern bool gpu_stats(int gpu, float *temp, int *engineclock, int *memclock, float *vddc, int *activity, int *fanspeed, int *fanpercent, int *powertune);
  462. extern int set_fanspeed(int gpu, int iFanSpeed);
  463. extern int set_vddc(int gpu, float fVddc);
  464. extern int set_engineclock(int gpu, int iEngineClock);
  465. extern int set_memoryclock(int gpu, int iMemoryClock);
  466. #endif
  467. extern void api(int thr_id);
  468. extern struct pool *current_pool(void);
  469. extern int active_pools(void);
  470. extern int add_pool_details(bool live, char *url, char *user, char *pass);
  471. #define ADD_POOL_MAXIMUM 1
  472. #define ADD_POOL_OK 0
  473. #define MAX_GPUDEVICES 16
  474. #define MAX_DEVICES 64
  475. #define MAX_POOLS (32)
  476. #define MIN_INTENSITY -10
  477. #define _MIN_INTENSITY_STR "-10"
  478. #define MAX_INTENSITY 14
  479. #define _MAX_INTENSITY_STR "14"
  480. extern struct list_head scan_devices;
  481. extern int nDevs;
  482. extern int opt_n_threads;
  483. extern int num_processors;
  484. extern int hw_errors;
  485. extern bool use_syslog;
  486. extern struct thr_info *thr_info;
  487. extern struct work_restart *work_restart;
  488. extern struct cgpu_info gpus[MAX_GPUDEVICES];
  489. extern int gpu_threads;
  490. extern double total_secs;
  491. extern int mining_threads;
  492. extern struct cgpu_info *cpus;
  493. extern int total_devices;
  494. extern struct cgpu_info *devices[];
  495. extern int total_pools;
  496. extern struct pool *pools[MAX_POOLS];
  497. extern const char *algo_names[];
  498. extern enum sha256_algos opt_algo;
  499. extern struct strategies strategies[];
  500. extern enum pool_strategy pool_strategy;
  501. extern int opt_rotate_period;
  502. extern double total_mhashes_done;
  503. extern unsigned int new_blocks;
  504. extern unsigned int found_blocks;
  505. extern int total_accepted, total_rejected;
  506. extern int total_getworks, total_stale, total_discarded;
  507. extern unsigned int local_work;
  508. extern unsigned int total_go, total_ro;
  509. extern const int opt_cutofftemp;
  510. extern int opt_log_interval;
  511. #ifdef HAVE_OPENCL
  512. typedef struct {
  513. cl_uint ctx_a; cl_uint ctx_b; cl_uint ctx_c; cl_uint ctx_d;
  514. cl_uint ctx_e; cl_uint ctx_f; cl_uint ctx_g; cl_uint ctx_h;
  515. cl_uint cty_a; cl_uint cty_b; cl_uint cty_c; cl_uint cty_d;
  516. cl_uint cty_e; cl_uint cty_f; cl_uint cty_g; cl_uint cty_h;
  517. cl_uint merkle; cl_uint ntime; cl_uint nbits; cl_uint nonce;
  518. cl_uint fW0; cl_uint fW1; cl_uint fW2; cl_uint fW3; cl_uint fW15;
  519. cl_uint fW01r; cl_uint fcty_e; cl_uint fcty_e2;
  520. cl_uint W16; cl_uint W17; cl_uint W2;
  521. cl_uint PreVal4; cl_uint T1;
  522. cl_uint C1addK5; cl_uint D1A; cl_uint W2A; cl_uint W17_2;
  523. cl_uint PreVal4addT1; cl_uint T1substate0;
  524. cl_uint PreVal4_2;
  525. cl_uint PreVal0;
  526. cl_uint PreW18;
  527. cl_uint PreW19;
  528. cl_uint PreW31;
  529. cl_uint PreW32;
  530. /* For diakgcn */
  531. cl_uint B1addK6, PreVal0addK7, W16addK16, W17addK17;
  532. cl_uint zeroA, zeroB;
  533. cl_uint oneA, twoA, threeA, fourA, fiveA, sixA, sevenA;
  534. } dev_blk_ctx;
  535. #else
  536. typedef struct {
  537. uint32_t nonce;
  538. } dev_blk_ctx;
  539. #endif
  540. struct curl_ent {
  541. CURL *curl;
  542. struct list_head node;
  543. struct timeval tv;
  544. };
  545. enum pool_enable {
  546. POOL_ENABLED,
  547. POOL_DISABLED,
  548. POOL_REJECTING,
  549. };
  550. struct pool {
  551. int pool_no;
  552. int prio;
  553. int accepted, rejected;
  554. int seq_rejects;
  555. int solved;
  556. bool submit_fail;
  557. bool idle;
  558. bool lagging;
  559. bool probed;
  560. enum pool_enable enabled;
  561. bool submit_old;
  562. bool removed;
  563. bool lp_started;
  564. char *hdr_path;
  565. char *lp_url;
  566. unsigned int getwork_requested;
  567. unsigned int stale_shares;
  568. unsigned int discarded_work;
  569. unsigned int getfail_occasions;
  570. unsigned int remotefail_occasions;
  571. struct timeval tv_idle;
  572. char *rpc_url;
  573. char *rpc_userpass;
  574. char *rpc_user, *rpc_pass;
  575. pthread_mutex_t pool_lock;
  576. struct thread_q *submit_q;
  577. struct thread_q *getwork_q;
  578. pthread_t longpoll_thread;
  579. pthread_t submit_thread;
  580. pthread_t getwork_thread;
  581. int curls;
  582. pthread_cond_t cr_cond;
  583. struct list_head curlring;
  584. time_t last_share_time;
  585. struct cgminer_stats cgminer_stats;
  586. };
  587. struct work {
  588. unsigned char data[128];
  589. unsigned char hash1[64];
  590. unsigned char midstate[32];
  591. unsigned char target[32];
  592. unsigned char hash[32];
  593. int rolls;
  594. uint32_t output[1];
  595. uint32_t valid;
  596. dev_blk_ctx blk;
  597. struct thr_info *thr;
  598. int thr_id;
  599. struct pool *pool;
  600. struct timeval tv_staged;
  601. bool mined;
  602. bool clone;
  603. bool cloned;
  604. bool rolltime;
  605. bool longpoll;
  606. bool stale;
  607. unsigned int work_block;
  608. int id;
  609. UT_hash_handle hh;
  610. time_t share_found_time;
  611. };
  612. extern void get_datestamp(char *, struct timeval *);
  613. bool submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce);
  614. extern void tailsprintf(char *f, const char *fmt, ...);
  615. extern void wlogprint(const char *f, ...);
  616. extern int curses_int(const char *query);
  617. extern char *curses_input(const char *query);
  618. extern void kill_work(void);
  619. extern void switch_pools(struct pool *selected);
  620. extern void remove_pool(struct pool *pool);
  621. extern void write_config(FILE *fcfg);
  622. extern void log_curses(int prio, const char *f, va_list ap);
  623. extern void clear_logwin(void);
  624. extern bool pool_tclear(struct pool *pool, bool *var);
  625. extern struct thread_q *tq_new(void);
  626. extern void tq_free(struct thread_q *tq);
  627. extern bool tq_push(struct thread_q *tq, void *data);
  628. extern void *tq_pop(struct thread_q *tq, const struct timespec *abstime);
  629. extern void tq_freeze(struct thread_q *tq);
  630. extern void tq_thaw(struct thread_q *tq);
  631. extern bool successful_connect;
  632. extern void adl(void);
  633. extern void app_restart(void);
  634. #endif /* __MINER_H__ */