miner.h 33 KB

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