miner.h 17 KB

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