dynclock.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. // Current frequency multiplier
  20. uint8_t freqM;
  21. // Minimum frequency multiplier to consider (set by driver)
  22. uint8_t freqMinM;
  23. // Maximum frequency multiplier to consider (set by driver)
  24. uint8_t freqMaxM;
  25. // "Default" frequency multiplier to work with (set by driver)
  26. uint8_t freqMDefault;
  27. // Threshold before errorWeight is considered reasonably constant
  28. // NOTE: This is not a mere number of sampling periods (but related)
  29. uint8_t minGoodSamples;
  30. // Numerator of errorWeight after dclk_errorCount
  31. double errorCount[256];
  32. // Approaches 200
  33. double errorWeight[256];
  34. // Error rate (0.0 - 1.0) as of end of last sampling period
  35. double errorRate[256];
  36. // Highest error rate (0.0 - 1.0) encountered
  37. double maxErrorRate[256];
  38. };
  39. typedef bool (*dclk_change_clock_func_t)(struct thr_info *, int multiplier);
  40. // Standard applog message called by driver frequency-change functions
  41. extern void dclk_msg_freqchange(const char *, int oldFreq, int newFreq, const char *tail);
  42. // Called to initialize dclk_data at startup
  43. extern void dclk_prepare(struct dclk_data *data);
  44. // Called to start a sampling period
  45. extern void dclk_gotNonces(struct dclk_data *);
  46. // Called to increment the current sampling period's error rate (1.0 "portion" is 100% errors)
  47. extern void dclk_errorCount(struct dclk_data *, double portion);
  48. // Called after a sampling period is completed to update actual error rate
  49. extern void dclk_preUpdate(struct dclk_data *data);
  50. // Called after a sampling period is completed, and error rate updated, to make actual clock adjustments
  51. extern bool dclk_updateFreq(struct dclk_data *, dclk_change_clock_func_t changeclock, struct thr_info *);
  52. #endif