miner.h 34 KB

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