windfarm_pid.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * Windfarm PowerMac thermal control. Generic PID helpers
  3. *
  4. * (c) Copyright 2005 Benjamin Herrenschmidt, IBM Corp.
  5. * <benh@kernel.crashing.org>
  6. *
  7. * Released under the term of the GNU GPL v2.
  8. *
  9. * This is a pair of generic PID helpers that can be used by
  10. * control loops. One is the basic PID implementation, the
  11. * other one is more specifically tailored to the loops used
  12. * for CPU control with 2 input sample types (temp and power)
  13. */
  14. /*
  15. * *** Simple PID ***
  16. */
  17. #define WF_PID_MAX_HISTORY 32
  18. /* This parameter array is passed to the PID algorithm. Currently,
  19. * we don't support changing parameters on the fly as it's not needed
  20. * but could be implemented (with necessary adjustment of the history
  21. * buffer
  22. */
  23. struct wf_pid_param {
  24. int interval; /* Interval between samples in seconds */
  25. int history_len; /* Size of history buffer */
  26. int additive; /* 1: target relative to previous value */
  27. s32 gd, gp, gr; /* PID gains */
  28. s32 itarget; /* PID input target */
  29. s32 min,max; /* min and max target values */
  30. };
  31. struct wf_pid_state {
  32. int first; /* first run of the loop */
  33. int index; /* index of current sample */
  34. s32 target; /* current target value */
  35. s32 samples[WF_PID_MAX_HISTORY]; /* samples history buffer */
  36. s32 errors[WF_PID_MAX_HISTORY]; /* error history buffer */
  37. struct wf_pid_param param;
  38. };
  39. extern void wf_pid_init(struct wf_pid_state *st, struct wf_pid_param *param);
  40. extern s32 wf_pid_run(struct wf_pid_state *st, s32 sample);
  41. /*
  42. * *** CPU PID ***
  43. */
  44. #define WF_CPU_PID_MAX_HISTORY 32
  45. /* This parameter array is passed to the CPU PID algorithm. Currently,
  46. * we don't support changing parameters on the fly as it's not needed
  47. * but could be implemented (with necessary adjustment of the history
  48. * buffer
  49. */
  50. struct wf_cpu_pid_param {
  51. int interval; /* Interval between samples in seconds */
  52. int history_len; /* Size of history buffer */
  53. s32 gd, gp, gr; /* PID gains */
  54. s32 pmaxadj; /* PID max power adjust */
  55. s32 ttarget; /* PID input target */
  56. s32 tmax; /* PID input max */
  57. s32 min,max; /* min and max target values */
  58. };
  59. struct wf_cpu_pid_state {
  60. int first; /* first run of the loop */
  61. int index; /* index of current power */
  62. int tindex; /* index of current temp */
  63. s32 target; /* current target value */
  64. s32 last_delta; /* last Tactual - Ttarget */
  65. s32 powers[WF_PID_MAX_HISTORY]; /* power history buffer */
  66. s32 errors[WF_PID_MAX_HISTORY]; /* error history buffer */
  67. s32 temps[2]; /* temp. history buffer */
  68. struct wf_cpu_pid_param param;
  69. };
  70. extern void wf_cpu_pid_init(struct wf_cpu_pid_state *st,
  71. struct wf_cpu_pid_param *param);
  72. extern s32 wf_cpu_pid_run(struct wf_cpu_pid_state *st, s32 power, s32 temp);