miner.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967
  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/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. #ifdef WIN32
  111. #ifndef __LITTLE_ENDIAN
  112. #define __LITTLE_ENDIAN 1234
  113. #define __BIG_ENDIAN 4321
  114. #endif
  115. #ifndef __BYTE_ORDER
  116. #define __BYTE_ORDER __LITTLE_ENDIAN
  117. #endif
  118. #else
  119. #include <endian.h>
  120. #endif
  121. /* This assumes htobe32 is a macro in endian.h */
  122. #ifndef htobe32
  123. # if __BYTE_ORDER == __LITTLE_ENDIAN
  124. # define be32toh(x) bswap_32(x)
  125. # define htobe32(x) bswap_32(x)
  126. # define le32toh(x) (x)
  127. # define htole32(x) (x)
  128. # elif __BYTE_ORDER == __BIG_ENDIAN
  129. # define be32toh(x) (x)
  130. # define htobe32(x) (x)
  131. # define le32toh(x) bswap_32(x)
  132. # define htole32(x) bswap_32(x)
  133. #else
  134. #error UNKNOWN BYTE ORDER
  135. #endif
  136. #endif
  137. #ifndef max
  138. # define max(a, b) ((a) > (b) ? (a) : (b))
  139. #endif
  140. #undef unlikely
  141. #undef likely
  142. #if defined(__GNUC__) && (__GNUC__ > 2) && defined(__OPTIMIZE__)
  143. #define unlikely(expr) (__builtin_expect(!!(expr), 0))
  144. #define likely(expr) (__builtin_expect(!!(expr), 1))
  145. #else
  146. #define unlikely(expr) (expr)
  147. #define likely(expr) (expr)
  148. #endif
  149. #define __maybe_unused __attribute__((unused))
  150. #define uninitialised_var(x) x = x
  151. #if defined(__i386__)
  152. #define WANT_CRYPTOPP_ASM32
  153. #endif
  154. #ifndef ARRAY_SIZE
  155. #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
  156. #endif
  157. #ifdef HAVE_CURSES
  158. extern int my_cancellable_getch(void);
  159. # ifdef getch
  160. // getch() is a macro
  161. static int __maybe_unused __real_getch(void) {
  162. return getch();
  163. }
  164. # undef getch
  165. # define getch() my_cancellable_getch()
  166. # else
  167. // getch() is a real function
  168. # define __real_getch getch
  169. # define getch() my_cancellable_getch()
  170. # endif
  171. #endif
  172. enum alive {
  173. LIFE_WELL,
  174. LIFE_SICK,
  175. LIFE_DEAD,
  176. LIFE_NOSTART,
  177. LIFE_INIT,
  178. LIFE_WAIT,
  179. };
  180. enum pool_strategy {
  181. POOL_FAILOVER,
  182. POOL_ROUNDROBIN,
  183. POOL_ROTATE,
  184. POOL_LOADBALANCE,
  185. POOL_BALANCE,
  186. };
  187. #define TOP_STRATEGY (POOL_BALANCE)
  188. struct strategies {
  189. const char *s;
  190. };
  191. struct cgpu_info;
  192. #ifdef HAVE_ADL
  193. struct gpu_adl {
  194. ADLTemperature lpTemperature;
  195. int iAdapterIndex;
  196. int lpAdapterID;
  197. int iBusNumber;
  198. char strAdapterName[256];
  199. ADLPMActivity lpActivity;
  200. ADLODParameters lpOdParameters;
  201. ADLODPerformanceLevels *DefPerfLev;
  202. ADLFanSpeedInfo lpFanSpeedInfo;
  203. ADLFanSpeedValue lpFanSpeedValue;
  204. ADLFanSpeedValue DefFanSpeedValue;
  205. int iEngineClock;
  206. int iMemoryClock;
  207. int iVddc;
  208. int iPercentage;
  209. bool autofan;
  210. bool autoengine;
  211. bool managed; /* Were the values ever changed on this card */
  212. int lastengine;
  213. int lasttemp;
  214. int targetfan;
  215. int targettemp;
  216. int overtemp;
  217. int minspeed;
  218. int maxspeed;
  219. int gpu;
  220. bool has_fanspeed;
  221. struct gpu_adl *twin;
  222. };
  223. #endif
  224. struct api_data;
  225. struct thr_info;
  226. struct work;
  227. struct device_api {
  228. const char*dname;
  229. const char*name;
  230. // API-global functions
  231. void (*api_detect)();
  232. // Device-specific functions
  233. void (*reinit_device)(struct cgpu_info*);
  234. void (*get_statline_before)(char*, struct cgpu_info*);
  235. void (*get_statline)(char*, struct cgpu_info*);
  236. struct api_data* (*get_api_extra_device_detail)(struct cgpu_info*);
  237. struct api_data* (*get_api_extra_device_status)(struct cgpu_info*);
  238. struct api_data *(*get_api_stats)(struct cgpu_info*);
  239. bool (*get_stats)(struct cgpu_info*);
  240. // Thread-specific functions
  241. bool (*thread_prepare)(struct thr_info*);
  242. uint64_t (*can_limit_work)(struct thr_info*);
  243. bool (*thread_init)(struct thr_info*);
  244. void (*free_work)(struct thr_info*, struct work*);
  245. bool (*prepare_work)(struct thr_info*, struct work*);
  246. int64_t (*scanhash)(struct thr_info*, struct work*, int64_t);
  247. void (*thread_shutdown)(struct thr_info*);
  248. void (*thread_enable)(struct thr_info*);
  249. };
  250. enum dev_enable {
  251. DEV_ENABLED,
  252. DEV_DISABLED,
  253. DEV_RECOVER,
  254. };
  255. enum cl_kernels {
  256. KL_NONE,
  257. KL_POCLBM,
  258. KL_PHATK,
  259. KL_DIAKGCN,
  260. KL_DIABLO,
  261. KL_SCRYPT,
  262. };
  263. enum dev_reason {
  264. REASON_THREAD_FAIL_INIT,
  265. REASON_THREAD_ZERO_HASH,
  266. REASON_THREAD_FAIL_QUEUE,
  267. REASON_DEV_SICK_IDLE_60,
  268. REASON_DEV_DEAD_IDLE_600,
  269. REASON_DEV_NOSTART,
  270. REASON_DEV_OVER_HEAT,
  271. REASON_DEV_THERMAL_CUTOFF,
  272. REASON_DEV_COMMS_ERROR,
  273. };
  274. #define REASON_NONE "None"
  275. #define REASON_THREAD_FAIL_INIT_STR "Thread failed to init"
  276. #define REASON_THREAD_ZERO_HASH_STR "Thread got zero hashes"
  277. #define REASON_THREAD_FAIL_QUEUE_STR "Thread failed to queue work"
  278. #define REASON_DEV_SICK_IDLE_60_STR "Device idle for 60s"
  279. #define REASON_DEV_DEAD_IDLE_600_STR "Device dead - idle for 600s"
  280. #define REASON_DEV_NOSTART_STR "Device failed to start"
  281. #define REASON_DEV_OVER_HEAT_STR "Device over heated"
  282. #define REASON_DEV_THERMAL_CUTOFF_STR "Device reached thermal cutoff"
  283. #define REASON_DEV_COMMS_ERROR_STR "Device comms error"
  284. #define REASON_UNKNOWN_STR "Unknown reason - code bug"
  285. #define MIN_SEC_UNSET 99999999
  286. struct cgminer_stats {
  287. uint32_t getwork_calls;
  288. struct timeval getwork_wait;
  289. struct timeval getwork_wait_max;
  290. struct timeval getwork_wait_min;
  291. };
  292. // Just the actual network getworks to the pool
  293. struct cgminer_pool_stats {
  294. uint32_t getwork_calls;
  295. uint32_t getwork_attempts;
  296. struct timeval getwork_wait;
  297. struct timeval getwork_wait_max;
  298. struct timeval getwork_wait_min;
  299. double getwork_wait_rolling;
  300. bool hadrolltime;
  301. bool canroll;
  302. bool hadexpire;
  303. uint32_t rolltime;
  304. };
  305. struct cgpu_info {
  306. int cgminer_id;
  307. const struct device_api *api;
  308. const char *devtype;
  309. int device_id;
  310. const char *name;
  311. const char *device_path;
  312. FILE *device_file;
  313. union {
  314. #ifdef USE_ZTEX
  315. struct libztex_device *device_ztex;
  316. #endif
  317. int device_fd;
  318. };
  319. #ifdef USE_BITFORCE
  320. struct timeval work_start_tv;
  321. unsigned int wait_ms;
  322. unsigned int sleep_ms;
  323. double avg_wait_f;
  324. unsigned int avg_wait_d;
  325. uint32_t nonces;
  326. bool nonce_range;
  327. bool polling;
  328. #endif
  329. void *cgpu_data;
  330. pthread_mutex_t device_mutex;
  331. enum dev_enable deven;
  332. int accepted;
  333. double accepted_weighed;
  334. int rejected;
  335. int hw_errors;
  336. double rolling;
  337. double total_mhashes;
  338. double utility;
  339. double utility_diff1;
  340. enum alive status;
  341. char init[40];
  342. struct timeval last_message_tv;
  343. int threads;
  344. struct thr_info **thr;
  345. int64_t max_hashes;
  346. const char *kname;
  347. #ifdef HAVE_OPENCL
  348. bool mapped;
  349. int virtual_gpu;
  350. int virtual_adl;
  351. int intensity;
  352. bool dynamic;
  353. cl_uint vwidth;
  354. size_t work_size;
  355. enum cl_kernels kernel;
  356. cl_ulong max_alloc;
  357. #ifdef USE_SCRYPT
  358. int opt_lg, lookup_gap;
  359. int opt_tc, thread_concurrency;
  360. int shaders;
  361. #endif
  362. struct timeval tv_gpustart;;
  363. struct timeval tv_gpuend;
  364. double gpu_us_average;
  365. #endif
  366. bool new_work;
  367. float temp;
  368. int cutofftemp;
  369. #ifdef HAVE_ADL
  370. bool has_adl;
  371. struct gpu_adl adl;
  372. int gpu_engine;
  373. int min_engine;
  374. int gpu_fan;
  375. int min_fan;
  376. int gpu_memclock;
  377. int gpu_memdiff;
  378. int gpu_powertune;
  379. float gpu_vddc;
  380. #endif
  381. int diff1;
  382. int last_share_pool;
  383. time_t last_share_pool_time;
  384. time_t device_last_well;
  385. time_t device_last_not_well;
  386. enum dev_reason device_not_well_reason;
  387. int thread_fail_init_count;
  388. int thread_zero_hash_count;
  389. int thread_fail_queue_count;
  390. int dev_sick_idle_60_count;
  391. int dev_dead_idle_600_count;
  392. int dev_nostart_count;
  393. int dev_over_heat_count; // It's a warning but worth knowing
  394. int dev_thermal_cutoff_count;
  395. int dev_comms_error_count;
  396. struct cgminer_stats cgminer_stats;
  397. };
  398. extern void renumber_cgpu(struct cgpu_info *);
  399. extern bool add_cgpu(struct cgpu_info*);
  400. struct thread_q {
  401. struct list_head q;
  402. bool frozen;
  403. pthread_mutex_t mutex;
  404. pthread_cond_t cond;
  405. };
  406. struct thr_info {
  407. int id;
  408. int device_thread;
  409. bool primary_thread;
  410. pthread_t pth;
  411. struct thread_q *q;
  412. struct cgpu_info *cgpu;
  413. void *cgpu_data;
  414. struct timeval last;
  415. struct timeval sick;
  416. bool pause;
  417. time_t getwork;
  418. double rolling;
  419. bool work_restart;
  420. int work_restart_fd;
  421. int _work_restart_fd_w;
  422. };
  423. extern int thr_info_create(struct thr_info *thr, pthread_attr_t *attr, void *(*start) (void *), void *arg);
  424. extern void thr_info_cancel(struct thr_info *thr);
  425. extern void thr_info_freeze(struct thr_info *thr);
  426. extern void nmsleep(unsigned int msecs);
  427. extern void rename_thr(const char* name);
  428. struct string_elist {
  429. char *string;
  430. bool free_me;
  431. struct list_head list;
  432. };
  433. static inline void string_elist_add(const char *s, struct list_head *head)
  434. {
  435. struct string_elist *n;
  436. n = calloc(1, sizeof(*n));
  437. n->string = strdup(s);
  438. n->free_me = true;
  439. list_add_tail(&n->list, head);
  440. }
  441. static inline void string_elist_del(struct string_elist *item)
  442. {
  443. if (item->free_me)
  444. free(item->string);
  445. list_del(&item->list);
  446. free(item);
  447. }
  448. static inline uint32_t swab32(uint32_t v)
  449. {
  450. return bswap_32(v);
  451. }
  452. static inline void swap256(void *dest_p, const void *src_p)
  453. {
  454. uint32_t *dest = dest_p;
  455. const uint32_t *src = src_p;
  456. dest[0] = src[7];
  457. dest[1] = src[6];
  458. dest[2] = src[5];
  459. dest[3] = src[4];
  460. dest[4] = src[3];
  461. dest[5] = src[2];
  462. dest[6] = src[1];
  463. dest[7] = src[0];
  464. }
  465. static inline void swap32yes(void*out, const void*in, size_t sz) {
  466. size_t swapcounter = 0;
  467. for (swapcounter = 0; swapcounter < sz; ++swapcounter)
  468. (((uint32_t*)out)[swapcounter]) = swab32(((uint32_t*)in)[swapcounter]);
  469. }
  470. #ifdef __BIG_ENDIAN__
  471. # define swap32tobe(out, in, sz) (void)0
  472. # define swap32tole(out, in, sz) swap32yes(out, in, sz)
  473. #else
  474. # define swap32tobe(out, in, sz) swap32yes(out, in, sz)
  475. # define swap32tole(out, in, sz) (void)0
  476. #endif
  477. extern void quit(int status, const char *format, ...);
  478. static inline void mutex_lock(pthread_mutex_t *lock)
  479. {
  480. if (unlikely(pthread_mutex_lock(lock)))
  481. quit(1, "WTF MUTEX ERROR ON LOCK!");
  482. }
  483. static inline void mutex_unlock(pthread_mutex_t *lock)
  484. {
  485. if (unlikely(pthread_mutex_unlock(lock)))
  486. quit(1, "WTF MUTEX ERROR ON UNLOCK!");
  487. }
  488. static inline int mutex_trylock(pthread_mutex_t *lock)
  489. {
  490. return pthread_mutex_trylock(lock);
  491. }
  492. static inline void wr_lock(pthread_rwlock_t *lock)
  493. {
  494. if (unlikely(pthread_rwlock_wrlock(lock)))
  495. quit(1, "WTF WRLOCK ERROR ON LOCK!");
  496. }
  497. static inline void rd_lock(pthread_rwlock_t *lock)
  498. {
  499. if (unlikely(pthread_rwlock_rdlock(lock)))
  500. quit(1, "WTF RDLOCK ERROR ON LOCK!");
  501. }
  502. static inline void rw_unlock(pthread_rwlock_t *lock)
  503. {
  504. if (unlikely(pthread_rwlock_unlock(lock)))
  505. quit(1, "WTF RWLOCK ERROR ON UNLOCK!");
  506. }
  507. static inline void rd_unlock(pthread_rwlock_t *lock)
  508. {
  509. rw_unlock(lock);
  510. }
  511. static inline void wr_unlock(pthread_rwlock_t *lock)
  512. {
  513. rw_unlock(lock);
  514. }
  515. static inline void mutex_init(pthread_mutex_t *lock)
  516. {
  517. if (unlikely(pthread_mutex_init(lock, NULL)))
  518. quit(1, "Failed to pthread_mutex_init");
  519. }
  520. static inline void rwlock_init(pthread_rwlock_t *lock)
  521. {
  522. if (unlikely(pthread_rwlock_init(lock, NULL)))
  523. quit(1, "Failed to pthread_rwlock_init");
  524. }
  525. struct pool;
  526. extern bool opt_protocol;
  527. extern bool have_longpoll;
  528. extern char *opt_kernel_path;
  529. extern char *opt_socks_proxy;
  530. extern char *cgminer_path;
  531. extern bool opt_fail_only;
  532. extern bool opt_autofan;
  533. extern bool opt_autoengine;
  534. extern bool use_curses;
  535. extern char *opt_api_allow;
  536. extern char *opt_api_groups;
  537. extern char *opt_api_description;
  538. extern int opt_api_port;
  539. extern bool opt_api_listen;
  540. extern bool opt_api_network;
  541. extern bool opt_delaynet;
  542. extern bool opt_restart;
  543. extern char *opt_icarus_options;
  544. extern char *opt_icarus_timing;
  545. #ifdef USE_BITFORCE
  546. extern bool opt_bfl_noncerange;
  547. #endif
  548. extern pthread_rwlock_t netacc_lock;
  549. extern const uint32_t sha256_init_state[];
  550. extern json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass,
  551. const char *rpc_req, bool, bool, int *,
  552. struct pool *pool, bool);
  553. extern bool our_curl_supports_proxy_uris();
  554. extern char *bin2hex(const unsigned char *p, size_t len);
  555. extern bool hex2bin(unsigned char *p, const char *hexstr, size_t len);
  556. typedef bool (*sha256_func)(struct thr_info*, const unsigned char *pmidstate,
  557. unsigned char *pdata,
  558. unsigned char *phash1, unsigned char *phash,
  559. const unsigned char *ptarget,
  560. uint32_t max_nonce,
  561. uint32_t *last_nonce,
  562. uint32_t nonce);
  563. extern bool fulltest(const unsigned char *hash, const unsigned char *target);
  564. extern int opt_queue;
  565. extern int opt_scantime;
  566. extern int opt_expiry;
  567. extern pthread_mutex_t console_lock;
  568. extern pthread_mutex_t ch_lock;
  569. extern pthread_mutex_t restart_lock;
  570. extern pthread_cond_t restart_cond;
  571. extern void thread_reportin(struct thr_info *thr);
  572. extern int restart_wait(unsigned int mstime);
  573. extern int stale_wait(unsigned int mstime, struct work*, bool checkend);
  574. extern void kill_work(void);
  575. extern void reinit_device(struct cgpu_info *cgpu);
  576. #ifdef HAVE_ADL
  577. extern bool gpu_stats(int gpu, float *temp, int *engineclock, int *memclock, float *vddc, int *activity, int *fanspeed, int *fanpercent, int *powertune);
  578. extern int set_fanspeed(int gpu, int iFanSpeed);
  579. extern int set_vddc(int gpu, float fVddc);
  580. extern int set_engineclock(int gpu, int iEngineClock);
  581. extern int set_memoryclock(int gpu, int iMemoryClock);
  582. #endif
  583. extern void api(int thr_id);
  584. extern struct pool *current_pool(void);
  585. extern int enabled_pools;
  586. extern void add_pool_details5(bool live, char *url, char *user, char *pass, char *proxy);
  587. extern void add_pool_details(bool live, char *url, char *user, char *pass);
  588. #define MAX_GPUDEVICES 16
  589. #define MIN_INTENSITY -10
  590. #define _MIN_INTENSITY_STR "-10"
  591. #ifdef USE_SCRYPT
  592. #define MAX_INTENSITY 20
  593. #define _MAX_INTENSITY_STR "20"
  594. #else
  595. #define MAX_INTENSITY 14
  596. #define _MAX_INTENSITY_STR "14"
  597. #endif
  598. extern struct list_head scan_devices;
  599. extern int nDevs;
  600. extern int opt_n_threads;
  601. extern int num_processors;
  602. extern int hw_errors;
  603. extern bool use_syslog;
  604. extern bool opt_quiet;
  605. extern struct thr_info *thr_info;
  606. extern struct cgpu_info gpus[MAX_GPUDEVICES];
  607. extern int gpu_threads;
  608. #ifdef USE_SCRYPT
  609. extern bool opt_scrypt;
  610. #else
  611. #define opt_scrypt (0)
  612. #endif
  613. extern double total_secs;
  614. extern int mining_threads;
  615. extern struct cgpu_info *cpus;
  616. extern int total_devices;
  617. extern struct cgpu_info **devices;
  618. extern int total_pools;
  619. extern struct pool **pools;
  620. extern const char *algo_names[];
  621. extern enum sha256_algos opt_algo;
  622. extern struct strategies strategies[];
  623. extern enum pool_strategy pool_strategy;
  624. extern int opt_rotate_period;
  625. extern double total_mhashes_done;
  626. extern unsigned int new_blocks;
  627. extern unsigned int found_blocks;
  628. extern int total_accepted, total_rejected, total_diff1;;
  629. extern int total_getworks, total_stale, total_discarded;
  630. extern unsigned int local_work;
  631. extern unsigned int total_go, total_ro;
  632. extern const int opt_cutofftemp;
  633. extern int opt_fail_pause;
  634. extern int opt_log_interval;
  635. extern unsigned long long global_hashrate;
  636. extern char *current_fullhash;
  637. extern struct timeval block_timeval;
  638. #ifdef HAVE_OPENCL
  639. typedef struct {
  640. cl_uint ctx_a; cl_uint ctx_b; cl_uint ctx_c; cl_uint ctx_d;
  641. cl_uint ctx_e; cl_uint ctx_f; cl_uint ctx_g; cl_uint ctx_h;
  642. cl_uint cty_a; cl_uint cty_b; cl_uint cty_c; cl_uint cty_d;
  643. cl_uint cty_e; cl_uint cty_f; cl_uint cty_g; cl_uint cty_h;
  644. cl_uint merkle; cl_uint ntime; cl_uint nbits; cl_uint nonce;
  645. cl_uint fW0; cl_uint fW1; cl_uint fW2; cl_uint fW3; cl_uint fW15;
  646. cl_uint fW01r; cl_uint fcty_e; cl_uint fcty_e2;
  647. cl_uint W16; cl_uint W17; cl_uint W2;
  648. cl_uint PreVal4; cl_uint T1;
  649. cl_uint C1addK5; cl_uint D1A; cl_uint W2A; cl_uint W17_2;
  650. cl_uint PreVal4addT1; cl_uint T1substate0;
  651. cl_uint PreVal4_2;
  652. cl_uint PreVal0;
  653. cl_uint PreW18;
  654. cl_uint PreW19;
  655. cl_uint PreW31;
  656. cl_uint PreW32;
  657. /* For diakgcn */
  658. cl_uint B1addK6, PreVal0addK7, W16addK16, W17addK17;
  659. cl_uint zeroA, zeroB;
  660. cl_uint oneA, twoA, threeA, fourA, fiveA, sixA, sevenA;
  661. #ifdef USE_SCRYPT
  662. struct work *work;
  663. #endif
  664. } dev_blk_ctx;
  665. #else
  666. typedef struct {
  667. uint32_t nonce;
  668. } dev_blk_ctx;
  669. #endif
  670. struct curl_ent {
  671. CURL *curl;
  672. struct list_head node;
  673. struct timeval tv;
  674. };
  675. /* Disabled needs to be the lowest enum as a freshly calloced value will then
  676. * equal disabled */
  677. enum pool_enable {
  678. POOL_DISABLED,
  679. POOL_ENABLED,
  680. POOL_REJECTING,
  681. };
  682. struct pool {
  683. int pool_no;
  684. int prio;
  685. int accepted, rejected;
  686. int seq_rejects;
  687. int solved;
  688. int diff1;
  689. int queued;
  690. int staged;
  691. bool submit_fail;
  692. bool idle;
  693. bool lagging;
  694. bool probed;
  695. enum pool_enable enabled;
  696. bool submit_old;
  697. bool removed;
  698. bool lp_started;
  699. unsigned char work_restart_id;
  700. uint32_t block_id;
  701. char *hdr_path;
  702. char *lp_url;
  703. unsigned int getwork_requested;
  704. unsigned int stale_shares;
  705. unsigned int discarded_work;
  706. unsigned int getfail_occasions;
  707. unsigned int remotefail_occasions;
  708. struct timeval tv_idle;
  709. double utility;
  710. int last_shares, shares;
  711. char *rpc_url;
  712. char *rpc_userpass;
  713. char *rpc_user, *rpc_pass;
  714. char *rpc_proxy;
  715. pthread_mutex_t pool_lock;
  716. struct thread_q *submit_q;
  717. struct thread_q *getwork_q;
  718. pthread_t longpoll_thread;
  719. pthread_t submit_thread;
  720. pthread_t getwork_thread;
  721. int curls;
  722. pthread_cond_t cr_cond;
  723. struct list_head curlring;
  724. time_t last_share_time;
  725. struct cgminer_stats cgminer_stats;
  726. struct cgminer_pool_stats cgminer_pool_stats;
  727. };
  728. struct work {
  729. unsigned char data[128];
  730. unsigned char hash1[64];
  731. unsigned char midstate[32];
  732. unsigned char target[32];
  733. unsigned char hash[32];
  734. int rolls;
  735. uint32_t output[1];
  736. uint32_t valid;
  737. dev_blk_ctx blk;
  738. struct thr_info *thr;
  739. int thr_id;
  740. struct pool *pool;
  741. struct timeval tv_staged;
  742. bool mined;
  743. bool clone;
  744. bool cloned;
  745. int rolltime;
  746. bool longpoll;
  747. bool stale;
  748. bool mandatory;
  749. bool block;
  750. bool queued;
  751. unsigned char work_restart_id;
  752. int id;
  753. UT_hash_handle hh;
  754. float difficulty;
  755. time_t share_found_time;
  756. };
  757. extern void get_datestamp(char *, struct timeval *);
  758. extern bool test_nonce(struct work *work, uint32_t nonce, bool checktarget);
  759. bool submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce);
  760. extern void tailsprintf(char *f, const char *fmt, ...);
  761. extern void wlogprint(const char *f, ...);
  762. extern int curses_int(const char *query);
  763. extern char *curses_input(const char *query);
  764. extern void kill_work(void);
  765. extern void switch_pools(struct pool *selected);
  766. extern void remove_pool(struct pool *pool);
  767. extern void write_config(FILE *fcfg);
  768. extern void default_save_file(char *filename);
  769. extern bool log_curses_only(int prio, const char *f, va_list ap);
  770. extern void clear_logwin(void);
  771. extern bool pool_tclear(struct pool *pool, bool *var);
  772. extern struct thread_q *tq_new(void);
  773. extern void tq_free(struct thread_q *tq);
  774. extern bool tq_push(struct thread_q *tq, void *data);
  775. extern void *tq_pop(struct thread_q *tq, const struct timespec *abstime);
  776. extern void tq_freeze(struct thread_q *tq);
  777. extern void tq_thaw(struct thread_q *tq);
  778. extern bool successful_connect;
  779. extern void adl(void);
  780. enum api_data_type {
  781. API_ESCAPE,
  782. API_STRING,
  783. API_CONST,
  784. API_INT,
  785. API_UINT,
  786. API_UINT32,
  787. API_UINT64,
  788. API_DOUBLE,
  789. API_ELAPSED,
  790. API_BOOL,
  791. API_TIMEVAL,
  792. API_TIME,
  793. API_MHS,
  794. API_MHTOTAL,
  795. API_TEMP,
  796. API_UTILITY,
  797. API_FREQ,
  798. API_VOLTS,
  799. API_HS,
  800. API_JSON,
  801. };
  802. struct api_data {
  803. enum api_data_type type;
  804. char *name;
  805. void *data;
  806. bool data_was_malloc;
  807. struct api_data *prev;
  808. struct api_data *next;
  809. };
  810. extern struct api_data *api_add_escape(struct api_data *root, char *name, char *data, bool copy_data);
  811. extern struct api_data *api_add_string(struct api_data *root, char *name, const char *data, bool copy_data);
  812. extern struct api_data *api_add_const(struct api_data *root, char *name, const char *data, bool copy_data);
  813. extern struct api_data *api_add_int(struct api_data *root, char *name, int *data, bool copy_data);
  814. extern struct api_data *api_add_uint(struct api_data *root, char *name, unsigned int *data, bool copy_data);
  815. extern struct api_data *api_add_uint32(struct api_data *root, char *name, uint32_t *data, bool copy_data);
  816. extern struct api_data *api_add_uint64(struct api_data *root, char *name, uint64_t *data, bool copy_data);
  817. extern struct api_data *api_add_double(struct api_data *root, char *name, double *data, bool copy_data);
  818. extern struct api_data *api_add_elapsed(struct api_data *root, char *name, double *data, bool copy_data);
  819. extern struct api_data *api_add_bool(struct api_data *root, char *name, bool *data, bool copy_data);
  820. extern struct api_data *api_add_timeval(struct api_data *root, char *name, struct timeval *data, bool copy_data);
  821. extern struct api_data *api_add_time(struct api_data *root, char *name, time_t *data, bool copy_data);
  822. extern struct api_data *api_add_mhs(struct api_data *root, char *name, double *data, bool copy_data);
  823. extern struct api_data *api_add_mhstotal(struct api_data *root, char *name, double *data, bool copy_data);
  824. extern struct api_data *api_add_temp(struct api_data *root, char *name, float *data, bool copy_data);
  825. extern struct api_data *api_add_utility(struct api_data *root, char *name, double *data, bool copy_data);
  826. extern struct api_data *api_add_freq(struct api_data *root, char *name, double *data, bool copy_data);
  827. extern struct api_data *api_add_volts(struct api_data *root, char *name, float *data, bool copy_data);
  828. extern struct api_data *api_add_hs(struct api_data *root, char *name, double *data, bool copy_data);
  829. extern struct api_data *api_add_json(struct api_data *root, char *name, json_t *data, bool copy_data);
  830. #endif /* __MINER_H__ */