dynclock.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 freqMaxM;
  21. uint8_t freqMDefault;
  22. uint8_t minGoodSamples;
  23. double errorCount[256];
  24. double errorWeight[256];
  25. double errorRate[256];
  26. double maxErrorRate[256];
  27. };
  28. typedef bool (*dclk_change_clock_func_t)(struct thr_info *, int multiplier);
  29. extern void dclk_msg_freqchange(const char *, int oldFreq, int newFreq, const char *tail);
  30. // Called to initialize dclk_data at startup
  31. extern void dclk_prepare(struct dclk_data *data);
  32. // Called for every quarter of a second to age error rate info
  33. extern void dclk_gotNonces(struct dclk_data *);
  34. // Called for errors (1.0 "portion" is a quarter second)
  35. extern void dclk_errorCount(struct dclk_data *, double portion);
  36. // Called after a nonce range is completed to update actual error rate
  37. extern void dclk_preUpdate(struct dclk_data *data);
  38. // Called after a nonce range is completed, and error rate updated, to make actual clock adjustments
  39. extern bool dclk_updateFreq(struct dclk_data *, dclk_change_clock_func_t changeclock, struct thr_info *);
  40. #endif