dynclock.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #ifndef DYNCLOCK_H
  2. #define DYNCLOCK_H
  3. #include <stdbool.h>
  4. #include <stdint.h>
  5. struct thr_info;
  6. #define DCLK_MAXMAXERRORRATE 0.05
  7. #define DCLK_ERRORHYSTERESIS 0.1
  8. #define DCLK_OVERHEATTHRESHOLD 0.4
  9. struct dclk_data {
  10. uint8_t freqM;
  11. uint8_t freqMaxM;
  12. uint8_t freqMDefault;
  13. uint8_t minGoodSamples;
  14. double errorCount[256];
  15. double errorWeight[256];
  16. double errorRate[256];
  17. double maxErrorRate[256];
  18. };
  19. typedef bool (*dclk_change_clock_func_t)(struct thr_info *, int multiplier);
  20. extern void dclk_msg_freqchange(const char *, int oldFreq, int newFreq, const char *tail);
  21. // Called to initialize dclk_data at startup
  22. extern void dclk_prepare(struct dclk_data *data);
  23. // Called for every quarter of a second to age error rate info
  24. extern void dclk_gotNonces(struct dclk_data *);
  25. // Called for errors (1.0 "portion" is a quarter second)
  26. extern void dclk_errorCount(struct dclk_data *, double portion);
  27. // Called after a nonce range is completed to update actual error rate
  28. extern void dclk_preUpdate(struct dclk_data *data);
  29. // Called after a nonce range is completed, and error rate updated, to make actual clock adjustments
  30. extern bool dclk_updateFreq(struct dclk_data *, dclk_change_clock_func_t changeclock, struct thr_info *);
  31. #endif