miner.h 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  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 api_data;
  189. struct thr_info;
  190. struct work;
  191. struct device_api {
  192. const char*dname;
  193. const char*name;
  194. // API-global functions
  195. void (*api_detect)();
  196. // Device-specific functions
  197. void (*reinit_device)(struct cgpu_info*);
  198. void (*get_statline_before)(char*, struct cgpu_info*);
  199. void (*get_statline)(char*, struct cgpu_info*);
  200. struct api_data* (*get_api_extra_device_detail)(struct cgpu_info*);
  201. struct api_data* (*get_api_extra_device_status)(struct cgpu_info*);
  202. struct api_data *(*get_api_stats)(struct cgpu_info*);
  203. // Thread-specific functions
  204. bool (*thread_prepare)(struct thr_info*);
  205. uint64_t (*can_limit_work)(struct thr_info*);
  206. bool (*thread_init)(struct thr_info*);
  207. void (*free_work)(struct thr_info*, struct work*);
  208. bool (*prepare_work)(struct thr_info*, struct work*);
  209. uint64_t (*scanhash)(struct thr_info*, struct work*, uint64_t);
  210. void (*thread_shutdown)(struct thr_info*);
  211. };
  212. enum dev_enable {
  213. DEV_ENABLED,
  214. DEV_DISABLED,
  215. DEV_RECOVER,
  216. };
  217. enum cl_kernels {
  218. KL_NONE,
  219. KL_POCLBM,
  220. KL_PHATK,
  221. KL_DIAKGCN,
  222. KL_DIABLO,
  223. };
  224. enum dev_reason {
  225. REASON_THREAD_FAIL_INIT,
  226. REASON_THREAD_ZERO_HASH,
  227. REASON_THREAD_FAIL_QUEUE,
  228. REASON_DEV_SICK_IDLE_60,
  229. REASON_DEV_DEAD_IDLE_600,
  230. REASON_DEV_NOSTART,
  231. REASON_DEV_OVER_HEAT,
  232. REASON_DEV_THERMAL_CUTOFF,
  233. };
  234. #define REASON_NONE "None"
  235. #define REASON_THREAD_FAIL_INIT_STR "Thread failed to init"
  236. #define REASON_THREAD_ZERO_HASH_STR "Thread got zero hashes"
  237. #define REASON_THREAD_FAIL_QUEUE_STR "Thread failed to queue work"
  238. #define REASON_DEV_SICK_IDLE_60_STR "Device idle for 60s"
  239. #define REASON_DEV_DEAD_IDLE_600_STR "Device dead - idle for 600s"
  240. #define REASON_DEV_NOSTART_STR "Device failed to start"
  241. #define REASON_DEV_OVER_HEAT_STR "Device over heated"
  242. #define REASON_DEV_THERMAL_CUTOFF_STR "Device reached thermal cutoff"
  243. #define REASON_UNKNOWN_STR "Unknown reason - code bug"
  244. #define MIN_SEC_UNSET 99999999
  245. struct cgminer_stats {
  246. uint32_t getwork_calls;
  247. struct timeval getwork_wait;
  248. struct timeval getwork_wait_max;
  249. struct timeval getwork_wait_min;
  250. };
  251. // Just the actual network getworks to the pool
  252. struct cgminer_pool_stats {
  253. uint32_t getwork_calls;
  254. uint32_t getwork_attempts;
  255. struct timeval getwork_wait;
  256. struct timeval getwork_wait_max;
  257. struct timeval getwork_wait_min;
  258. double getwork_wait_rolling;
  259. };
  260. struct cgpu_info {
  261. int cgminer_id;
  262. const struct device_api *api;
  263. const char *devtype;
  264. int device_id;
  265. const char *name;
  266. const char *device_path;
  267. FILE *device_file;
  268. union {
  269. #ifdef USE_ZTEX
  270. struct libztex_device *device_ztex;
  271. #endif
  272. int device_fd;
  273. };
  274. pthread_mutex_t device_mutex;
  275. enum dev_enable deven;
  276. int accepted;
  277. int rejected;
  278. int hw_errors;
  279. double rolling;
  280. double total_mhashes;
  281. double utility;
  282. enum alive status;
  283. char init[40];
  284. struct timeval last_message_tv;
  285. int threads;
  286. struct thr_info **thr;
  287. unsigned int max_hashes;
  288. const char *kname;
  289. #ifdef HAVE_OPENCL
  290. bool mapped;
  291. int virtual_gpu;
  292. int virtual_adl;
  293. int intensity;
  294. bool dynamic;
  295. cl_uint vwidth;
  296. size_t work_size;
  297. enum cl_kernels kernel;
  298. struct timeval tv_gpustart;;
  299. struct timeval tv_gpuend;
  300. double gpu_us_average;
  301. #endif
  302. float temp;
  303. int cutofftemp;
  304. #ifdef HAVE_ADL
  305. bool has_adl;
  306. struct gpu_adl adl;
  307. int gpu_engine;
  308. int min_engine;
  309. int gpu_fan;
  310. int min_fan;
  311. int gpu_memclock;
  312. int gpu_memdiff;
  313. int gpu_powertune;
  314. float gpu_vddc;
  315. #endif
  316. int last_share_pool;
  317. time_t last_share_pool_time;
  318. time_t device_last_well;
  319. time_t device_last_not_well;
  320. enum dev_reason device_not_well_reason;
  321. int thread_fail_init_count;
  322. int thread_zero_hash_count;
  323. int thread_fail_queue_count;
  324. int dev_sick_idle_60_count;
  325. int dev_dead_idle_600_count;
  326. int dev_nostart_count;
  327. int dev_over_heat_count; // It's a warning but worth knowing
  328. int dev_thermal_cutoff_count;
  329. struct cgminer_stats cgminer_stats;
  330. };
  331. extern bool add_cgpu(struct cgpu_info*);
  332. struct thread_q {
  333. struct list_head q;
  334. bool frozen;
  335. pthread_mutex_t mutex;
  336. pthread_cond_t cond;
  337. };
  338. struct thr_info {
  339. int id;
  340. int device_thread;
  341. bool primary_thread;
  342. pthread_t pth;
  343. struct thread_q *q;
  344. struct cgpu_info *cgpu;
  345. void *cgpu_data;
  346. struct timeval last;
  347. struct timeval sick;
  348. bool pause;
  349. bool getwork;
  350. double rolling;
  351. bool work_restart;
  352. int work_restart_fd;
  353. int _work_restart_fd_w;
  354. };
  355. extern int thr_info_create(struct thr_info *thr, pthread_attr_t *attr, void *(*start) (void *), void *arg);
  356. extern void thr_info_cancel(struct thr_info *thr);
  357. extern void thr_info_freeze(struct thr_info *thr);
  358. struct string_elist {
  359. char *string;
  360. bool free_me;
  361. struct list_head list;
  362. };
  363. static inline void string_elist_add(const char *s, struct list_head *head)
  364. {
  365. struct string_elist *n;
  366. n = calloc(1, sizeof(*n));
  367. n->string = strdup(s);
  368. n->free_me = true;
  369. list_add_tail(&n->list, head);
  370. }
  371. static inline void string_elist_del(struct string_elist *item)
  372. {
  373. if (item->free_me)
  374. free(item->string);
  375. list_del(&item->list);
  376. }
  377. static inline uint32_t swab32(uint32_t v)
  378. {
  379. return bswap_32(v);
  380. }
  381. static inline void swap256(void *dest_p, const void *src_p)
  382. {
  383. uint32_t *dest = dest_p;
  384. const uint32_t *src = src_p;
  385. dest[0] = src[7];
  386. dest[1] = src[6];
  387. dest[2] = src[5];
  388. dest[3] = src[4];
  389. dest[4] = src[3];
  390. dest[5] = src[2];
  391. dest[6] = src[1];
  392. dest[7] = src[0];
  393. }
  394. extern void quit(int status, const char *format, ...);
  395. static inline void mutex_lock(pthread_mutex_t *lock)
  396. {
  397. if (unlikely(pthread_mutex_lock(lock)))
  398. quit(1, "WTF MUTEX ERROR ON LOCK!");
  399. }
  400. static inline void mutex_unlock(pthread_mutex_t *lock)
  401. {
  402. if (unlikely(pthread_mutex_unlock(lock)))
  403. quit(1, "WTF MUTEX ERROR ON UNLOCK!");
  404. }
  405. static inline void wr_lock(pthread_rwlock_t *lock)
  406. {
  407. if (unlikely(pthread_rwlock_wrlock(lock)))
  408. quit(1, "WTF WRLOCK ERROR ON LOCK!");
  409. }
  410. static inline void rd_lock(pthread_rwlock_t *lock)
  411. {
  412. if (unlikely(pthread_rwlock_rdlock(lock)))
  413. quit(1, "WTF RDLOCK ERROR ON LOCK!");
  414. }
  415. static inline void rw_unlock(pthread_rwlock_t *lock)
  416. {
  417. if (unlikely(pthread_rwlock_unlock(lock)))
  418. quit(1, "WTF RWLOCK ERROR ON UNLOCK!");
  419. }
  420. static inline void rd_unlock(pthread_rwlock_t *lock)
  421. {
  422. rw_unlock(lock);
  423. }
  424. static inline void wr_unlock(pthread_rwlock_t *lock)
  425. {
  426. rw_unlock(lock);
  427. }
  428. static inline void mutex_init(pthread_mutex_t *lock)
  429. {
  430. if (unlikely(pthread_mutex_init(lock, NULL)))
  431. quit(1, "Failed to pthread_mutex_init");
  432. }
  433. static inline void rwlock_init(pthread_rwlock_t *lock)
  434. {
  435. if (unlikely(pthread_rwlock_init(lock, NULL)))
  436. quit(1, "Failed to pthread_rwlock_init");
  437. }
  438. struct pool;
  439. extern bool opt_protocol;
  440. extern char *opt_kernel_path;
  441. extern char *opt_socks_proxy;
  442. extern char *cgminer_path;
  443. extern bool opt_autofan;
  444. extern bool opt_autoengine;
  445. extern bool use_curses;
  446. extern char *opt_api_allow;
  447. extern char *opt_api_groups;
  448. extern char *opt_api_description;
  449. extern int opt_api_port;
  450. extern bool opt_api_listen;
  451. extern bool opt_api_network;
  452. extern bool opt_delaynet;
  453. extern bool opt_restart;
  454. extern char *opt_icarus_timing;
  455. extern pthread_rwlock_t netacc_lock;
  456. extern const uint32_t sha256_init_state[];
  457. extern json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass,
  458. const char *rpc_req, bool, bool, int *,
  459. struct pool *pool, bool);
  460. extern char *bin2hex(const unsigned char *p, size_t len);
  461. extern bool hex2bin(unsigned char *p, const char *hexstr, size_t len);
  462. typedef bool (*sha256_func)(struct thr_info*, const unsigned char *pmidstate,
  463. unsigned char *pdata,
  464. unsigned char *phash1, unsigned char *phash,
  465. const unsigned char *ptarget,
  466. uint32_t max_nonce,
  467. uint32_t *last_nonce,
  468. uint32_t nonce);
  469. extern bool fulltest(const unsigned char *hash, const unsigned char *target);
  470. extern int opt_scantime;
  471. extern pthread_mutex_t restart_lock;
  472. extern pthread_cond_t restart_cond;
  473. extern void thread_reportin(struct thr_info *thr);
  474. extern bool queue_request(struct thr_info *thr, bool needed);
  475. extern int restart_wait(struct timeval *tdiff);
  476. extern void kill_work(void);
  477. extern void reinit_device(struct cgpu_info *cgpu);
  478. #ifdef HAVE_ADL
  479. extern bool gpu_stats(int gpu, float *temp, int *engineclock, int *memclock, float *vddc, int *activity, int *fanspeed, int *fanpercent, int *powertune);
  480. extern int set_fanspeed(int gpu, int iFanSpeed);
  481. extern int set_vddc(int gpu, float fVddc);
  482. extern int set_engineclock(int gpu, int iEngineClock);
  483. extern int set_memoryclock(int gpu, int iMemoryClock);
  484. #endif
  485. extern void api(int thr_id);
  486. extern struct pool *current_pool(void);
  487. extern int active_pools(void);
  488. extern void add_pool_details(bool live, char *url, char *user, char *pass);
  489. #define MAX_GPUDEVICES 16
  490. #define MIN_INTENSITY -10
  491. #define _MIN_INTENSITY_STR "-10"
  492. #define MAX_INTENSITY 14
  493. #define _MAX_INTENSITY_STR "14"
  494. extern struct list_head scan_devices;
  495. extern int nDevs;
  496. extern int opt_n_threads;
  497. extern int num_processors;
  498. extern int hw_errors;
  499. extern bool use_syslog;
  500. extern struct thr_info *thr_info;
  501. extern struct cgpu_info gpus[MAX_GPUDEVICES];
  502. extern int gpu_threads;
  503. extern double total_secs;
  504. extern int mining_threads;
  505. extern struct cgpu_info *cpus;
  506. extern int total_devices;
  507. extern struct cgpu_info **devices;
  508. extern int total_pools;
  509. extern struct pool **pools;
  510. extern const char *algo_names[];
  511. extern enum sha256_algos opt_algo;
  512. extern struct strategies strategies[];
  513. extern enum pool_strategy pool_strategy;
  514. extern int opt_rotate_period;
  515. extern double total_mhashes_done;
  516. extern unsigned int new_blocks;
  517. extern unsigned int found_blocks;
  518. extern int total_accepted, total_rejected;
  519. extern int total_getworks, total_stale, total_discarded;
  520. extern unsigned int local_work;
  521. extern unsigned int total_go, total_ro;
  522. extern const int opt_cutofftemp;
  523. extern int opt_log_interval;
  524. extern unsigned long long global_hashrate;
  525. #ifdef HAVE_OPENCL
  526. typedef struct {
  527. cl_uint ctx_a; cl_uint ctx_b; cl_uint ctx_c; cl_uint ctx_d;
  528. cl_uint ctx_e; cl_uint ctx_f; cl_uint ctx_g; cl_uint ctx_h;
  529. cl_uint cty_a; cl_uint cty_b; cl_uint cty_c; cl_uint cty_d;
  530. cl_uint cty_e; cl_uint cty_f; cl_uint cty_g; cl_uint cty_h;
  531. cl_uint merkle; cl_uint ntime; cl_uint nbits; cl_uint nonce;
  532. cl_uint fW0; cl_uint fW1; cl_uint fW2; cl_uint fW3; cl_uint fW15;
  533. cl_uint fW01r; cl_uint fcty_e; cl_uint fcty_e2;
  534. cl_uint W16; cl_uint W17; cl_uint W2;
  535. cl_uint PreVal4; cl_uint T1;
  536. cl_uint C1addK5; cl_uint D1A; cl_uint W2A; cl_uint W17_2;
  537. cl_uint PreVal4addT1; cl_uint T1substate0;
  538. cl_uint PreVal4_2;
  539. cl_uint PreVal0;
  540. cl_uint PreW18;
  541. cl_uint PreW19;
  542. cl_uint PreW31;
  543. cl_uint PreW32;
  544. /* For diakgcn */
  545. cl_uint B1addK6, PreVal0addK7, W16addK16, W17addK17;
  546. cl_uint zeroA, zeroB;
  547. cl_uint oneA, twoA, threeA, fourA, fiveA, sixA, sevenA;
  548. } dev_blk_ctx;
  549. #else
  550. typedef struct {
  551. uint32_t nonce;
  552. } dev_blk_ctx;
  553. #endif
  554. struct curl_ent {
  555. CURL *curl;
  556. struct list_head node;
  557. struct timeval tv;
  558. };
  559. enum pool_enable {
  560. POOL_ENABLED,
  561. POOL_DISABLED,
  562. POOL_REJECTING,
  563. };
  564. struct pool {
  565. int pool_no;
  566. int prio;
  567. int accepted, rejected;
  568. int seq_rejects;
  569. int solved;
  570. bool submit_fail;
  571. bool idle;
  572. bool lagging;
  573. bool probed;
  574. enum pool_enable enabled;
  575. bool submit_old;
  576. bool removed;
  577. bool lp_started;
  578. char *hdr_path;
  579. char *lp_url;
  580. unsigned int getwork_requested;
  581. unsigned int stale_shares;
  582. unsigned int discarded_work;
  583. unsigned int getfail_occasions;
  584. unsigned int remotefail_occasions;
  585. struct timeval tv_idle;
  586. char *rpc_url;
  587. char *rpc_userpass;
  588. char *rpc_user, *rpc_pass;
  589. pthread_mutex_t pool_lock;
  590. struct thread_q *submit_q;
  591. struct thread_q *getwork_q;
  592. pthread_t longpoll_thread;
  593. pthread_t submit_thread;
  594. pthread_t getwork_thread;
  595. int curls;
  596. pthread_cond_t cr_cond;
  597. struct list_head curlring;
  598. time_t last_share_time;
  599. struct cgminer_stats cgminer_stats;
  600. struct cgminer_pool_stats cgminer_pool_stats;
  601. };
  602. struct work {
  603. unsigned char data[128];
  604. unsigned char hash1[64];
  605. unsigned char midstate[32];
  606. unsigned char target[32];
  607. unsigned char hash[32];
  608. int rolls;
  609. uint32_t output[1];
  610. uint32_t valid;
  611. dev_blk_ctx blk;
  612. struct thr_info *thr;
  613. int thr_id;
  614. struct pool *pool;
  615. struct timeval tv_staged;
  616. bool mined;
  617. bool clone;
  618. bool cloned;
  619. int rolltime;
  620. bool longpoll;
  621. bool stale;
  622. bool mandatory;
  623. bool block;
  624. unsigned int work_block;
  625. int id;
  626. UT_hash_handle hh;
  627. time_t share_found_time;
  628. };
  629. extern void get_datestamp(char *, struct timeval *);
  630. extern bool test_nonce(struct work *work, uint32_t nonce);
  631. bool submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce);
  632. extern void tailsprintf(char *f, const char *fmt, ...);
  633. extern void wlogprint(const char *f, ...);
  634. extern int curses_int(const char *query);
  635. extern char *curses_input(const char *query);
  636. extern void kill_work(void);
  637. extern void switch_pools(struct pool *selected);
  638. extern void remove_pool(struct pool *pool);
  639. extern void write_config(FILE *fcfg);
  640. extern void default_save_file(char *filename);
  641. extern void log_curses(int prio, const char *f, va_list ap);
  642. extern void clear_logwin(void);
  643. extern bool pool_tclear(struct pool *pool, bool *var);
  644. extern struct thread_q *tq_new(void);
  645. extern void tq_free(struct thread_q *tq);
  646. extern bool tq_push(struct thread_q *tq, void *data);
  647. extern void *tq_pop(struct thread_q *tq, const struct timespec *abstime);
  648. extern void tq_freeze(struct thread_q *tq);
  649. extern void tq_thaw(struct thread_q *tq);
  650. extern bool successful_connect;
  651. extern void adl(void);
  652. extern void app_restart(void);
  653. enum api_data_type {
  654. API_ESCAPE,
  655. API_STRING,
  656. API_CONST,
  657. API_INT,
  658. API_UINT,
  659. API_UINT32,
  660. API_UINT64,
  661. API_DOUBLE,
  662. API_ELAPSED,
  663. API_BOOL,
  664. API_TIMEVAL,
  665. API_TIME,
  666. API_MHS,
  667. API_MHTOTAL,
  668. API_TEMP,
  669. API_UTILITY,
  670. API_FREQ,
  671. API_VOLTS,
  672. API_HS,
  673. API_JSON,
  674. };
  675. struct api_data {
  676. enum api_data_type type;
  677. char *name;
  678. void *data;
  679. bool data_was_malloc;
  680. struct api_data *prev;
  681. struct api_data *next;
  682. };
  683. extern struct api_data *api_add_escape(struct api_data *root, char *name, char *data, bool copy_data);
  684. extern struct api_data *api_add_string(struct api_data *root, char *name, const char *data, bool copy_data);
  685. extern struct api_data *api_add_const(struct api_data *root, char *name, const char *data, bool copy_data);
  686. extern struct api_data *api_add_int(struct api_data *root, char *name, int *data, bool copy_data);
  687. extern struct api_data *api_add_uint(struct api_data *root, char *name, unsigned int *data, bool copy_data);
  688. extern struct api_data *api_add_uint32(struct api_data *root, char *name, uint32_t *data, bool copy_data);
  689. extern struct api_data *api_add_uint64(struct api_data *root, char *name, uint64_t *data, bool copy_data);
  690. extern struct api_data *api_add_double(struct api_data *root, char *name, double *data, bool copy_data);
  691. extern struct api_data *api_add_elapsed(struct api_data *root, char *name, double *data, bool copy_data);
  692. extern struct api_data *api_add_bool(struct api_data *root, char *name, bool *data, bool copy_data);
  693. extern struct api_data *api_add_timeval(struct api_data *root, char *name, struct timeval *data, bool copy_data);
  694. extern struct api_data *api_add_time(struct api_data *root, char *name, time_t *data, bool copy_data);
  695. extern struct api_data *api_add_mhs(struct api_data *root, char *name, double *data, bool copy_data);
  696. extern struct api_data *api_add_mhstotal(struct api_data *root, char *name, double *data, bool copy_data);
  697. extern struct api_data *api_add_temp(struct api_data *root, char *name, float *data, bool copy_data);
  698. extern struct api_data *api_add_utility(struct api_data *root, char *name, double *data, bool copy_data);
  699. extern struct api_data *api_add_freq(struct api_data *root, char *name, double *data, bool copy_data);
  700. extern struct api_data *api_add_volts(struct api_data *root, char *name, float *data, bool copy_data);
  701. extern struct api_data *api_add_hs(struct api_data *root, char *name, double *data, bool copy_data);
  702. extern struct api_data *api_add_json(struct api_data *root, char *name, json_t *data, bool copy_data);
  703. #endif /* __MINER_H__ */