miner.h 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363
  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. LIFE_INIT2, // Still initializing, but safe to call functions
  189. LIFE_DEAD2, // Totally dead, NOT safe to call functions
  190. };
  191. enum pool_strategy {
  192. POOL_FAILOVER,
  193. POOL_ROUNDROBIN,
  194. POOL_ROTATE,
  195. POOL_LOADBALANCE,
  196. POOL_BALANCE,
  197. };
  198. #define TOP_STRATEGY (POOL_BALANCE)
  199. struct strategies {
  200. const char *s;
  201. };
  202. struct cgpu_info;
  203. #ifdef HAVE_ADL
  204. struct gpu_adl {
  205. ADLTemperature lpTemperature;
  206. int iAdapterIndex;
  207. int lpAdapterID;
  208. int iBusNumber;
  209. char strAdapterName[256];
  210. ADLPMActivity lpActivity;
  211. ADLODParameters lpOdParameters;
  212. ADLODPerformanceLevels *DefPerfLev;
  213. ADLFanSpeedInfo lpFanSpeedInfo;
  214. ADLFanSpeedValue lpFanSpeedValue;
  215. ADLFanSpeedValue DefFanSpeedValue;
  216. int iEngineClock;
  217. int iMemoryClock;
  218. int iVddc;
  219. int iPercentage;
  220. bool autofan;
  221. bool autoengine;
  222. bool managed; /* Were the values ever changed on this card */
  223. int lastengine;
  224. int lasttemp;
  225. int targetfan;
  226. int overtemp;
  227. int minspeed;
  228. int maxspeed;
  229. int gpu;
  230. bool has_fanspeed;
  231. struct gpu_adl *twin;
  232. };
  233. #endif
  234. struct api_data;
  235. struct thr_info;
  236. struct work;
  237. struct device_drv {
  238. const char *dname;
  239. const char *name;
  240. // DRV-global functions
  241. void (*drv_detect)();
  242. // Device-specific functions
  243. void (*get_dev_statline_before)(char *, struct cgpu_info *);
  244. void (*get_dev_statline_after)(char *, struct cgpu_info *);
  245. // Processor-specific functions
  246. void (*reinit_device)(struct cgpu_info *);
  247. void (*get_statline_before)(char *, struct cgpu_info *);
  248. void (*get_statline)(char *, struct cgpu_info *);
  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. enum dev_reason device_not_well_reason;
  476. float reinit_backoff;
  477. int thread_fail_init_count;
  478. int thread_zero_hash_count;
  479. int thread_fail_queue_count;
  480. int dev_sick_idle_60_count;
  481. int dev_dead_idle_600_count;
  482. int dev_nostart_count;
  483. int dev_over_heat_count; // It's a warning but worth knowing
  484. int dev_thermal_cutoff_count;
  485. int dev_comms_error_count;
  486. int dev_throttle_count;
  487. struct cgminer_stats cgminer_stats;
  488. pthread_rwlock_t qlock;
  489. struct work *queued_work;
  490. unsigned int queued_count;
  491. bool shutdown;
  492. };
  493. extern void renumber_cgpu(struct cgpu_info *);
  494. extern bool add_cgpu(struct cgpu_info*);
  495. struct tq_ent;
  496. struct thread_q {
  497. struct tq_ent *q;
  498. bool frozen;
  499. pthread_mutex_t mutex;
  500. pthread_cond_t cond;
  501. };
  502. enum thr_busy_state {
  503. TBS_IDLE,
  504. TBS_GETTING_RESULTS,
  505. TBS_STARTING_JOB,
  506. };
  507. struct thr_info {
  508. int id;
  509. int device_thread;
  510. bool primary_thread;
  511. bool has_pth;
  512. pthread_t pth;
  513. struct thread_q *q;
  514. struct cgpu_info *cgpu;
  515. void *cgpu_data;
  516. struct timeval last;
  517. struct timeval sick;
  518. bool scanhash_working;
  519. uint64_t hashes_done;
  520. struct timeval tv_hashes_done;
  521. struct timeval tv_lastupdate;
  522. bool pause;
  523. time_t getwork;
  524. double rolling;
  525. // Used by minerloop_async
  526. struct work *prev_work;
  527. struct work *work;
  528. struct work *next_work;
  529. enum thr_busy_state busy_state;
  530. struct timeval tv_morework;
  531. struct work *results_work;
  532. bool _job_transition_in_progress;
  533. bool _proceed_with_new_job;
  534. struct timeval tv_results_jobstart;
  535. struct timeval tv_jobstart;
  536. struct timeval tv_poll;
  537. notifier_t notifier;
  538. bool starting_next_work;
  539. uint32_t _max_nonce;
  540. notifier_t mutex_request;
  541. // Used by minerloop_queue
  542. struct work *work_list;
  543. bool queue_full;
  544. bool _last_sbr_state;
  545. bool work_restart;
  546. notifier_t work_restart_notifier;
  547. };
  548. struct string_elist {
  549. char *string;
  550. bool free_me;
  551. struct string_elist *prev;
  552. struct string_elist *next;
  553. };
  554. static inline void string_elist_add(const char *s, struct string_elist **head)
  555. {
  556. struct string_elist *n;
  557. n = calloc(1, sizeof(*n));
  558. n->string = strdup(s);
  559. n->free_me = true;
  560. DL_APPEND(*head, n);
  561. }
  562. static inline void string_elist_del(struct string_elist **head, struct string_elist *item)
  563. {
  564. if (item->free_me)
  565. free(item->string);
  566. DL_DELETE(*head, item);
  567. free(item);
  568. }
  569. static inline uint32_t swab32(uint32_t v)
  570. {
  571. return bswap_32(v);
  572. }
  573. static inline void swap256(void *dest_p, const void *src_p)
  574. {
  575. uint32_t *dest = dest_p;
  576. const uint32_t *src = src_p;
  577. dest[0] = src[7];
  578. dest[1] = src[6];
  579. dest[2] = src[5];
  580. dest[3] = src[4];
  581. dest[4] = src[3];
  582. dest[5] = src[2];
  583. dest[6] = src[1];
  584. dest[7] = src[0];
  585. }
  586. static inline void swap32yes(void*out, const void*in, size_t sz) {
  587. size_t swapcounter = 0;
  588. for (swapcounter = 0; swapcounter < sz; ++swapcounter)
  589. (((uint32_t*)out)[swapcounter]) = swab32(((uint32_t*)in)[swapcounter]);
  590. }
  591. #define LOCAL_swap32(type, var, sz) \
  592. type __swapped_ ## var[sz * 4 / sizeof(type)]; \
  593. swap32yes(__swapped_ ## var, var, sz); \
  594. var = __swapped_ ## var; \
  595. // end
  596. #ifdef WORDS_BIGENDIAN
  597. # define swap32tobe(out, in, sz) ((out == in) ? (void)0 : memmove(out, in, sz))
  598. # define LOCAL_swap32be(type, var, sz) ;
  599. # define swap32tole(out, in, sz) swap32yes(out, in, sz)
  600. # define LOCAL_swap32le(type, var, sz) LOCAL_swap32(type, var, sz)
  601. #else
  602. # define swap32tobe(out, in, sz) swap32yes(out, in, sz)
  603. # define LOCAL_swap32be(type, var, sz) LOCAL_swap32(type, var, sz)
  604. # define swap32tole(out, in, sz) ((out == in) ? (void)0 : memmove(out, in, sz))
  605. # define LOCAL_swap32le(type, var, sz) ;
  606. #endif
  607. static inline void swab256(void *dest_p, const void *src_p)
  608. {
  609. uint32_t *dest = dest_p;
  610. const uint32_t *src = src_p;
  611. dest[0] = swab32(src[7]);
  612. dest[1] = swab32(src[6]);
  613. dest[2] = swab32(src[5]);
  614. dest[3] = swab32(src[4]);
  615. dest[4] = swab32(src[3]);
  616. dest[5] = swab32(src[2]);
  617. dest[6] = swab32(src[1]);
  618. dest[7] = swab32(src[0]);
  619. }
  620. #define flip32(dest_p, src_p) swap32yes(dest_p, src_p, 32 / 4)
  621. extern void _quit(int status);
  622. static inline void mutex_lock(pthread_mutex_t *lock)
  623. {
  624. if (unlikely(pthread_mutex_lock(lock)))
  625. quit(1, "WTF MUTEX ERROR ON LOCK!");
  626. }
  627. static inline void mutex_unlock(pthread_mutex_t *lock)
  628. {
  629. if (unlikely(pthread_mutex_unlock(lock)))
  630. quit(1, "WTF MUTEX ERROR ON UNLOCK!");
  631. }
  632. static inline int mutex_trylock(pthread_mutex_t *lock)
  633. {
  634. return pthread_mutex_trylock(lock);
  635. }
  636. static inline void wr_lock(pthread_rwlock_t *lock)
  637. {
  638. if (unlikely(pthread_rwlock_wrlock(lock)))
  639. quit(1, "WTF WRLOCK ERROR ON LOCK!");
  640. }
  641. static inline void rd_lock(pthread_rwlock_t *lock)
  642. {
  643. if (unlikely(pthread_rwlock_rdlock(lock)))
  644. quit(1, "WTF RDLOCK ERROR ON LOCK!");
  645. }
  646. static inline void rw_unlock(pthread_rwlock_t *lock)
  647. {
  648. if (unlikely(pthread_rwlock_unlock(lock)))
  649. quit(1, "WTF RWLOCK ERROR ON UNLOCK!");
  650. }
  651. static inline void rd_unlock(pthread_rwlock_t *lock)
  652. {
  653. rw_unlock(lock);
  654. }
  655. static inline void wr_unlock(pthread_rwlock_t *lock)
  656. {
  657. rw_unlock(lock);
  658. }
  659. static inline void mutex_init(pthread_mutex_t *lock)
  660. {
  661. if (unlikely(pthread_mutex_init(lock, NULL)))
  662. quit(1, "Failed to pthread_mutex_init");
  663. }
  664. static inline void rwlock_init(pthread_rwlock_t *lock)
  665. {
  666. if (unlikely(pthread_rwlock_init(lock, NULL)))
  667. quit(1, "Failed to pthread_rwlock_init");
  668. }
  669. /* cgminer locks, a write biased variant of rwlocks */
  670. struct cglock {
  671. pthread_mutex_t mutex;
  672. pthread_rwlock_t rwlock;
  673. };
  674. typedef struct cglock cglock_t;
  675. static inline void cglock_init(cglock_t *lock)
  676. {
  677. mutex_init(&lock->mutex);
  678. rwlock_init(&lock->rwlock);
  679. }
  680. /* Read lock variant of cglock */
  681. static inline void cg_rlock(cglock_t *lock)
  682. {
  683. mutex_lock(&lock->mutex);
  684. rd_lock(&lock->rwlock);
  685. mutex_unlock(&lock->mutex);
  686. }
  687. /* Intermediate variant of cglock */
  688. static inline void cg_ilock(cglock_t *lock)
  689. {
  690. mutex_lock(&lock->mutex);
  691. }
  692. /* Upgrade intermediate variant to a write lock */
  693. static inline void cg_ulock(cglock_t *lock)
  694. {
  695. wr_lock(&lock->rwlock);
  696. }
  697. /* Write lock variant of cglock */
  698. static inline void cg_wlock(cglock_t *lock)
  699. {
  700. mutex_lock(&lock->mutex);
  701. wr_lock(&lock->rwlock);
  702. }
  703. /* Downgrade intermediate variant to a read lock */
  704. static inline void cg_dlock(cglock_t *lock)
  705. {
  706. rd_lock(&lock->rwlock);
  707. mutex_unlock(&lock->mutex);
  708. }
  709. static inline void cg_runlock(cglock_t *lock)
  710. {
  711. rd_unlock(&lock->rwlock);
  712. }
  713. static inline void cg_wunlock(cglock_t *lock)
  714. {
  715. wr_unlock(&lock->rwlock);
  716. mutex_unlock(&lock->mutex);
  717. }
  718. struct pool;
  719. extern bool opt_protocol;
  720. extern bool opt_dev_protocol;
  721. extern char *opt_coinbase_sig;
  722. extern bool have_longpoll;
  723. extern int opt_skip_checks;
  724. extern char *opt_kernel_path;
  725. extern char *opt_socks_proxy;
  726. extern char *cgminer_path;
  727. extern bool opt_fail_only;
  728. extern bool opt_autofan;
  729. extern bool opt_autoengine;
  730. extern bool use_curses;
  731. extern char *opt_api_allow;
  732. extern char *opt_api_groups;
  733. extern char *opt_api_description;
  734. extern int opt_api_port;
  735. extern bool opt_api_listen;
  736. extern bool opt_api_network;
  737. extern bool opt_delaynet;
  738. extern bool opt_restart;
  739. extern char *opt_icarus_options;
  740. extern char *opt_icarus_timing;
  741. extern bool opt_worktime;
  742. #ifdef USE_AVALON
  743. extern char *opt_avalon_options;
  744. #endif
  745. #ifdef USE_BITFORCE
  746. extern bool opt_bfl_noncerange;
  747. #endif
  748. extern int swork_id;
  749. extern pthread_rwlock_t netacc_lock;
  750. extern const uint32_t sha256_init_state[];
  751. extern json_t *json_rpc_call(CURL *curl, const char *url, const char *userpass,
  752. const char *rpc_req, bool, bool, int *,
  753. struct pool *pool, bool);
  754. extern bool our_curl_supports_proxy_uris();
  755. extern void bin2hex(char *out, const void *in, size_t len);
  756. extern bool hex2bin(unsigned char *p, const char *hexstr, size_t len);
  757. typedef bool (*sha256_func)(struct thr_info*, const unsigned char *pmidstate,
  758. unsigned char *pdata,
  759. unsigned char *phash1, unsigned char *phash,
  760. const unsigned char *ptarget,
  761. uint32_t max_nonce,
  762. uint32_t *last_nonce,
  763. uint32_t nonce);
  764. extern bool fulltest(const unsigned char *hash, const unsigned char *target);
  765. extern int opt_queue;
  766. extern int opt_scantime;
  767. extern int opt_expiry;
  768. extern cglock_t control_lock;
  769. extern pthread_mutex_t stats_lock;
  770. extern pthread_mutex_t hash_lock;
  771. extern pthread_mutex_t console_lock;
  772. extern cglock_t ch_lock;
  773. extern pthread_rwlock_t mining_thr_lock;
  774. extern pthread_rwlock_t devices_lock;
  775. extern void thread_reportin(struct thr_info *thr);
  776. extern void thread_reportout(struct thr_info *);
  777. extern void clear_stratum_shares(struct pool *pool);
  778. extern void hashmeter2(struct thr_info *);
  779. extern bool stale_work(struct work *, bool share);
  780. extern bool stale_work_future(struct work *, bool share, unsigned long ustime);
  781. extern void set_target(unsigned char *dest_target, double diff);
  782. extern void kill_work(void);
  783. extern void app_restart(void);
  784. extern void __thr_being_msg(int prio, struct thr_info *, const char *);
  785. extern void mt_enable(struct thr_info *thr);
  786. extern void proc_enable(struct cgpu_info *);
  787. extern void reinit_device(struct cgpu_info *cgpu);
  788. #ifdef HAVE_ADL
  789. extern bool gpu_stats(int gpu, float *temp, int *engineclock, int *memclock, float *vddc, int *activity, int *fanspeed, int *fanpercent, int *powertune);
  790. extern int set_fanspeed(int gpu, int iFanSpeed);
  791. extern int set_vddc(int gpu, float fVddc);
  792. extern int set_engineclock(int gpu, int iEngineClock);
  793. extern int set_memoryclock(int gpu, int iMemoryClock);
  794. #endif
  795. extern void api(int thr_id);
  796. extern struct pool *current_pool(void);
  797. extern int enabled_pools;
  798. extern void get_intrange(char *arg, int *val1, int *val2);
  799. extern bool detect_stratum(struct pool *pool, char *url);
  800. extern void print_summary(void);
  801. extern struct pool *add_pool(void);
  802. extern bool add_pool_details(struct pool *pool, bool live, char *url, char *user, char *pass);
  803. #define MAX_GPUDEVICES 16
  804. #define MAX_DEVICES 4096
  805. #define MIN_INTENSITY -10
  806. #define _MIN_INTENSITY_STR "-10"
  807. #ifdef USE_SCRYPT
  808. #define MAX_INTENSITY 20
  809. #define _MAX_INTENSITY_STR "20"
  810. #else
  811. #define MAX_INTENSITY 14
  812. #define _MAX_INTENSITY_STR "14"
  813. #endif
  814. extern struct string_elist *scan_devices;
  815. extern bool opt_force_dev_init;
  816. extern int nDevs;
  817. extern int opt_n_threads;
  818. extern int num_processors;
  819. extern int hw_errors;
  820. extern bool use_syslog;
  821. extern bool opt_quiet;
  822. extern struct thr_info *control_thr;
  823. extern struct thr_info **mining_thr;
  824. extern struct cgpu_info gpus[MAX_GPUDEVICES];
  825. extern int gpu_threads;
  826. #ifdef USE_SCRYPT
  827. extern bool opt_scrypt;
  828. #else
  829. #define opt_scrypt (0)
  830. #endif
  831. extern double total_secs;
  832. extern int mining_threads;
  833. extern struct cgpu_info *cpus;
  834. extern int total_devices;
  835. extern struct cgpu_info **devices;
  836. extern int total_devices_new;
  837. extern struct cgpu_info **devices_new;
  838. extern int total_pools;
  839. extern struct pool **pools;
  840. extern const char *algo_names[];
  841. extern enum sha256_algos opt_algo;
  842. extern struct strategies strategies[];
  843. extern enum pool_strategy pool_strategy;
  844. extern int opt_rotate_period;
  845. extern double total_mhashes_done;
  846. extern unsigned int new_blocks;
  847. extern unsigned int found_blocks;
  848. extern int total_accepted, total_rejected, total_diff1;;
  849. extern int total_getworks, total_stale, total_discarded;
  850. extern uint64_t total_bytes_xfer;
  851. extern double total_diff_accepted, total_diff_rejected, total_diff_stale;
  852. extern unsigned int local_work;
  853. extern unsigned int total_go, total_ro;
  854. extern const int opt_cutofftemp;
  855. extern int opt_hysteresis;
  856. extern int opt_fail_pause;
  857. extern int opt_log_interval;
  858. extern unsigned long long global_hashrate;
  859. extern char *current_fullhash;
  860. extern double current_diff;
  861. extern uint64_t best_diff;
  862. extern struct timeval block_timeval;
  863. #ifdef HAVE_OPENCL
  864. typedef struct {
  865. cl_uint ctx_a; cl_uint ctx_b; cl_uint ctx_c; cl_uint ctx_d;
  866. cl_uint ctx_e; cl_uint ctx_f; cl_uint ctx_g; cl_uint ctx_h;
  867. cl_uint cty_a; cl_uint cty_b; cl_uint cty_c; cl_uint cty_d;
  868. cl_uint cty_e; cl_uint cty_f; cl_uint cty_g; cl_uint cty_h;
  869. cl_uint merkle; cl_uint ntime; cl_uint nbits; cl_uint nonce;
  870. cl_uint fW0; cl_uint fW1; cl_uint fW2; cl_uint fW3; cl_uint fW15;
  871. cl_uint fW01r; cl_uint fcty_e; cl_uint fcty_e2;
  872. cl_uint W16; cl_uint W17; cl_uint W2;
  873. cl_uint PreVal4; cl_uint T1;
  874. cl_uint C1addK5; cl_uint D1A; cl_uint W2A; cl_uint W17_2;
  875. cl_uint PreVal4addT1; cl_uint T1substate0;
  876. cl_uint PreVal4_2;
  877. cl_uint PreVal0;
  878. cl_uint PreW18;
  879. cl_uint PreW19;
  880. cl_uint PreW31;
  881. cl_uint PreW32;
  882. /* For diakgcn */
  883. cl_uint B1addK6, PreVal0addK7, W16addK16, W17addK17;
  884. cl_uint zeroA, zeroB;
  885. cl_uint oneA, twoA, threeA, fourA, fiveA, sixA, sevenA;
  886. #ifdef USE_SCRYPT
  887. struct work *work;
  888. #endif
  889. } dev_blk_ctx;
  890. #else
  891. typedef struct {
  892. uint32_t nonce;
  893. } dev_blk_ctx;
  894. #endif
  895. struct curl_ent {
  896. CURL *curl;
  897. struct curl_ent *next;
  898. struct timeval tv;
  899. };
  900. /* Disabled needs to be the lowest enum as a freshly calloced value will then
  901. * equal disabled */
  902. enum pool_enable {
  903. POOL_DISABLED,
  904. POOL_ENABLED,
  905. POOL_REJECTING,
  906. };
  907. enum pool_protocol {
  908. PLP_NONE,
  909. PLP_GETWORK,
  910. PLP_GETBLOCKTEMPLATE,
  911. };
  912. struct stratum_work {
  913. char *job_id;
  914. bool clean;
  915. bytes_t coinbase;
  916. size_t nonce2_offset;
  917. int merkles;
  918. bytes_t merkle_bin;
  919. uint8_t header1[36];
  920. uint8_t diffbits[4];
  921. uint8_t ntime[4];
  922. double diff;
  923. bool transparency_probed;
  924. time_t transparency_time;
  925. bool opaque;
  926. };
  927. #define RBUFSIZE 8192
  928. #define RECVSIZE (RBUFSIZE - 4)
  929. struct pool {
  930. int pool_no;
  931. int prio;
  932. int accepted, rejected;
  933. int seq_rejects;
  934. int seq_getfails;
  935. int solved;
  936. int diff1;
  937. char diff[8];
  938. double diff_accepted;
  939. double diff_rejected;
  940. double diff_stale;
  941. bool submit_fail;
  942. bool idle;
  943. bool lagging;
  944. bool probed;
  945. int force_rollntime;
  946. enum pool_enable enabled;
  947. bool submit_old;
  948. bool removed;
  949. bool lp_started;
  950. unsigned char work_restart_id;
  951. uint32_t block_id;
  952. enum pool_protocol proto;
  953. char *hdr_path;
  954. char *lp_url;
  955. char *lp_id;
  956. enum pool_protocol lp_proto;
  957. curl_socket_t lp_socket;
  958. unsigned int getwork_requested;
  959. unsigned int stale_shares;
  960. unsigned int discarded_work;
  961. unsigned int getfail_occasions;
  962. unsigned int remotefail_occasions;
  963. struct timeval tv_idle;
  964. double utility;
  965. int last_shares, shares;
  966. char *rpc_url;
  967. char *rpc_userpass;
  968. char *rpc_user, *rpc_pass;
  969. char *rpc_proxy;
  970. pthread_mutex_t pool_lock;
  971. cglock_t data_lock;
  972. struct thread_q *submit_q;
  973. struct thread_q *getwork_q;
  974. pthread_t longpoll_thread;
  975. pthread_t test_thread;
  976. bool testing;
  977. int curls;
  978. pthread_cond_t cr_cond;
  979. struct curl_ent *curllist;
  980. struct submit_work_state *sws_waiting_on_curl;
  981. time_t last_work_time;
  982. time_t last_share_time;
  983. double last_share_diff;
  984. uint64_t best_diff;
  985. struct cgminer_stats cgminer_stats;
  986. struct cgminer_pool_stats cgminer_pool_stats;
  987. /* Stratum variables */
  988. char *stratum_url;
  989. char *stratum_port;
  990. CURL *stratum_curl;
  991. SOCKETTYPE sock;
  992. char *sockbuf;
  993. size_t sockbuf_size;
  994. char *sockaddr_url; /* stripped url used for sockaddr */
  995. char *nonce1;
  996. size_t n1_len;
  997. uint32_t nonce2;
  998. int n2size;
  999. char *sessionid;
  1000. bool has_stratum;
  1001. bool stratum_active;
  1002. bool stratum_init;
  1003. bool stratum_notify;
  1004. struct stratum_work swork;
  1005. pthread_t stratum_thread;
  1006. pthread_mutex_t stratum_lock;
  1007. char *admin_msg;
  1008. pthread_mutex_t last_work_lock;
  1009. struct work *last_work_copy;
  1010. };
  1011. #define GETWORK_MODE_TESTPOOL 'T'
  1012. #define GETWORK_MODE_POOL 'P'
  1013. #define GETWORK_MODE_LP 'L'
  1014. #define GETWORK_MODE_BENCHMARK 'B'
  1015. #define GETWORK_MODE_STRATUM 'S'
  1016. #define GETWORK_MODE_GBT 'G'
  1017. struct work {
  1018. unsigned char data[128];
  1019. unsigned char midstate[32];
  1020. unsigned char target[32];
  1021. unsigned char hash[32];
  1022. uint64_t share_diff;
  1023. int rolls;
  1024. dev_blk_ctx blk;
  1025. struct thr_info *thr;
  1026. int thr_id;
  1027. struct pool *pool;
  1028. struct timeval tv_staged;
  1029. bool mined;
  1030. bool clone;
  1031. bool cloned;
  1032. int rolltime;
  1033. bool longpoll;
  1034. bool stale;
  1035. bool mandatory;
  1036. bool block;
  1037. bool queued;
  1038. bool stratum;
  1039. char *job_id;
  1040. bytes_t nonce2;
  1041. double sdiff;
  1042. char *nonce1;
  1043. unsigned char work_restart_id;
  1044. int id;
  1045. UT_hash_handle hh;
  1046. double work_difficulty;
  1047. // Allow devices to identify work if multiple sub-devices
  1048. // DEPRECATED: New code should be using multiple processors instead
  1049. unsigned char subid;
  1050. blktemplate_t *tmpl;
  1051. int *tmpl_refcount;
  1052. unsigned int dataid;
  1053. bool do_foreign_submit;
  1054. struct timeval tv_getwork;
  1055. struct timeval tv_getwork_reply;
  1056. struct timeval tv_cloned;
  1057. struct timeval tv_work_start;
  1058. struct timeval tv_work_found;
  1059. char getwork_mode;
  1060. /* Used to queue shares in submit_waiting */
  1061. struct work *prev;
  1062. struct work *next;
  1063. };
  1064. extern void get_datestamp(char *, struct timeval *);
  1065. extern void inc_hw_errors(struct thr_info *, const struct work *, const uint32_t bad_nonce);
  1066. #define inc_hw_errors_only(thr) inc_hw_errors(thr, NULL, 0)
  1067. enum test_nonce2_result {
  1068. TNR_GOOD = 1,
  1069. TNR_HIGH = 0,
  1070. TNR_BAD = -1,
  1071. };
  1072. extern enum test_nonce2_result _test_nonce2(struct work *, uint32_t nonce, bool checktarget);
  1073. #define test_nonce(work, nonce, checktarget) (_test_nonce2(work, nonce, checktarget) == TNR_GOOD)
  1074. #define test_nonce2(work, nonce) (_test_nonce2(work, nonce, true))
  1075. extern bool submit_nonce(struct thr_info *thr, struct work *work, uint32_t nonce);
  1076. extern struct work *get_queued(struct cgpu_info *cgpu);
  1077. extern struct work *__find_work_bymidstate(struct work *que, char *midstate, size_t midstatelen, char *data, int offset, size_t datalen);
  1078. extern struct work *find_queued_work_bymidstate(struct cgpu_info *cgpu, char *midstate, size_t midstatelen, char *data, int offset, size_t datalen);
  1079. extern void work_completed(struct cgpu_info *cgpu, struct work *work);
  1080. extern bool abandon_work(struct work *, struct timeval *work_runtime, uint64_t hashes);
  1081. extern void hash_queued_work(struct thr_info *mythr);
  1082. extern void get_statline3(char *buf, struct cgpu_info *, bool for_curses, bool opt_show_procs);
  1083. extern void tailsprintf(char *f, const char *fmt, ...) FORMAT_SYNTAX_CHECK(printf, 2, 3);
  1084. extern void _wlog(const char *str);
  1085. extern void _wlogprint(const char *str);
  1086. extern int curses_int(const char *query);
  1087. extern char *curses_input(const char *query);
  1088. extern double stats_elapsed(struct cgminer_stats *);
  1089. #define cgpu_runtime(cgpu) stats_elapsed(&((cgpu)->cgminer_stats))
  1090. extern double cgpu_utility(struct cgpu_info *);
  1091. extern void kill_work(void);
  1092. extern int prioritize_pools(char *param, int *pid);
  1093. extern void validate_pool_priorities(void);
  1094. extern void switch_pools(struct pool *selected);
  1095. extern void remove_pool(struct pool *pool);
  1096. extern void write_config(FILE *fcfg);
  1097. extern void zero_bestshare(void);
  1098. extern void zero_stats(void);
  1099. extern void default_save_file(char *filename);
  1100. extern bool log_curses_only(int prio, const char *datetime, const char *str);
  1101. extern void clear_logwin(void);
  1102. extern void logwin_update(void);
  1103. extern bool pool_tclear(struct pool *pool, bool *var);
  1104. extern struct thread_q *tq_new(void);
  1105. extern void tq_free(struct thread_q *tq);
  1106. extern bool tq_push(struct thread_q *tq, void *data);
  1107. extern void *tq_pop(struct thread_q *tq, const struct timespec *abstime);
  1108. extern void tq_freeze(struct thread_q *tq);
  1109. extern void tq_thaw(struct thread_q *tq);
  1110. extern bool successful_connect;
  1111. extern void adl(void);
  1112. extern void clean_work(struct work *work);
  1113. extern void free_work(struct work *work);
  1114. extern void __copy_work(struct work *work, const struct work *base_work);
  1115. extern struct work *copy_work(const struct work *base_work);
  1116. extern struct thr_info *get_thread(int thr_id);
  1117. extern struct cgpu_info *get_devices(int id);
  1118. extern int scan_serial(const char *);
  1119. enum api_data_type {
  1120. API_ESCAPE,
  1121. API_STRING,
  1122. API_CONST,
  1123. API_INT,
  1124. API_UINT,
  1125. API_UINT32,
  1126. API_UINT64,
  1127. API_DOUBLE,
  1128. API_ELAPSED,
  1129. API_BOOL,
  1130. API_TIMEVAL,
  1131. API_TIME,
  1132. API_MHS,
  1133. API_MHTOTAL,
  1134. API_TEMP,
  1135. API_UTILITY,
  1136. API_FREQ,
  1137. API_VOLTS,
  1138. API_HS,
  1139. API_DIFF,
  1140. API_JSON,
  1141. };
  1142. struct api_data {
  1143. enum api_data_type type;
  1144. char *name;
  1145. void *data;
  1146. bool data_was_malloc;
  1147. struct api_data *prev;
  1148. struct api_data *next;
  1149. };
  1150. extern struct api_data *api_add_escape(struct api_data *root, char *name, char *data, bool copy_data);
  1151. extern struct api_data *api_add_string(struct api_data *root, char *name, const char *data, bool copy_data);
  1152. extern struct api_data *api_add_const(struct api_data *root, char *name, const char *data, bool copy_data);
  1153. extern struct api_data *api_add_int(struct api_data *root, char *name, int *data, bool copy_data);
  1154. extern struct api_data *api_add_uint(struct api_data *root, char *name, unsigned int *data, bool copy_data);
  1155. extern struct api_data *api_add_uint32(struct api_data *root, char *name, uint32_t *data, bool copy_data);
  1156. extern struct api_data *api_add_uint64(struct api_data *root, char *name, uint64_t *data, bool copy_data);
  1157. extern struct api_data *api_add_double(struct api_data *root, char *name, double *data, bool copy_data);
  1158. extern struct api_data *api_add_elapsed(struct api_data *root, char *name, double *data, bool copy_data);
  1159. extern struct api_data *api_add_bool(struct api_data *root, char *name, bool *data, bool copy_data);
  1160. extern struct api_data *api_add_timeval(struct api_data *root, char *name, struct timeval *data, bool copy_data);
  1161. extern struct api_data *api_add_time(struct api_data *root, char *name, time_t *data, bool copy_data);
  1162. extern struct api_data *api_add_mhs(struct api_data *root, char *name, double *data, bool copy_data);
  1163. extern struct api_data *api_add_mhstotal(struct api_data *root, char *name, double *data, bool copy_data);
  1164. extern struct api_data *api_add_temp(struct api_data *root, char *name, float *data, bool copy_data);
  1165. extern struct api_data *api_add_utility(struct api_data *root, char *name, double *data, bool copy_data);
  1166. extern struct api_data *api_add_freq(struct api_data *root, char *name, double *data, bool copy_data);
  1167. extern struct api_data *api_add_volts(struct api_data *root, char *name, float *data, bool copy_data);
  1168. extern struct api_data *api_add_hs(struct api_data *root, char *name, double *data, bool copy_data);
  1169. extern struct api_data *api_add_diff(struct api_data *root, char *name, double *data, bool copy_data);
  1170. extern struct api_data *api_add_json(struct api_data *root, char *name, json_t *data, bool copy_data);
  1171. #endif /* __MINER_H__ */