dynclock.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * Copyright 2012-2013 Luke Dashjr
  3. * Copyright 2012 nelisky
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the Free
  7. * Software Foundation; either version 3 of the License, or (at your option)
  8. * any later version. See COPYING for more details.
  9. */
  10. #ifndef DYNCLOCK_H
  11. #define DYNCLOCK_H
  12. #include <stdbool.h>
  13. #include <stdint.h>
  14. struct thr_info;
  15. #define DCLK_MAXMAXERRORRATE 0.05
  16. #define DCLK_ERRORHYSTERESIS 0.1
  17. #define DCLK_OVERHEATTHRESHOLD 0.4
  18. struct dclk_data {
  19. uint8_t freqM;
  20. uint8_t freqMinM;
  21. uint8_t freqMaxM;
  22. uint8_t freqMDefault;
  23. uint8_t minGoodSamples;
  24. double errorCount[256];
  25. double errorWeight[256];
  26. double errorRate[256];
  27. double maxErrorRate[256];
  28. };
  29. typedef bool (*dclk_change_clock_func_t)(struct thr_info *, int multiplier);
  30. extern void dclk_msg_freqchange(const char *, int oldFreq, int newFreq, const char *tail);
  31. // Called to initialize dclk_data at startup
  32. extern void dclk_prepare(struct dclk_data *data);
  33. // Called for every quarter of a second to age error rate info
  34. extern void dclk_gotNonces(struct dclk_data *);
  35. // Called for errors (1.0 "portion" is a quarter second)
  36. extern void dclk_errorCount(struct dclk_data *, double portion);
  37. // Called after a nonce range is completed to update actual error rate
  38. extern void dclk_preUpdate(struct dclk_data *data);
  39. // Called after a nonce range is completed, and error rate updated, to make actual clock adjustments
  40. extern bool dclk_updateFreq(struct dclk_data *, dclk_change_clock_func_t changeclock, struct thr_info *);
  41. #endif