Lines Matching refs:st

25 void wf_pid_init(struct wf_pid_state *st, struct wf_pid_param *param)  in wf_pid_init()  argument
27 memset(st, 0, sizeof(struct wf_pid_state)); in wf_pid_init()
28 st->param = *param; in wf_pid_init()
29 st->first = 1; in wf_pid_init()
33 s32 wf_pid_run(struct wf_pid_state *st, s32 new_sample) in wf_pid_run() argument
37 int i, hlen = st->param.history_len; in wf_pid_run()
40 error = new_sample - st->param.itarget; in wf_pid_run()
43 if (st->first) { in wf_pid_run()
45 st->samples[i] = new_sample; in wf_pid_run()
46 st->errors[i] = error; in wf_pid_run()
48 st->first = 0; in wf_pid_run()
49 st->index = 0; in wf_pid_run()
51 st->index = (st->index + 1) % hlen; in wf_pid_run()
52 st->samples[st->index] = new_sample; in wf_pid_run()
53 st->errors[st->index] = error; in wf_pid_run()
58 integ += st->errors[(st->index + hlen - i) % hlen]; in wf_pid_run()
59 integ *= st->param.interval; in wf_pid_run()
62 deriv = st->errors[st->index] - in wf_pid_run()
63 st->errors[(st->index + hlen - 1) % hlen]; in wf_pid_run()
64 deriv /= st->param.interval; in wf_pid_run()
67 target = (s32)((integ * (s64)st->param.gr + deriv * (s64)st->param.gd + in wf_pid_run()
68 error * (s64)st->param.gp) >> 36); in wf_pid_run()
69 if (st->param.additive) in wf_pid_run()
70 target += st->target; in wf_pid_run()
71 target = max(target, st->param.min); in wf_pid_run()
72 target = min(target, st->param.max); in wf_pid_run()
73 st->target = target; in wf_pid_run()
75 return st->target; in wf_pid_run()
79 void wf_cpu_pid_init(struct wf_cpu_pid_state *st, in wf_cpu_pid_init() argument
82 memset(st, 0, sizeof(struct wf_cpu_pid_state)); in wf_cpu_pid_init()
83 st->param = *param; in wf_cpu_pid_init()
84 st->first = 1; in wf_cpu_pid_init()
88 s32 wf_cpu_pid_run(struct wf_cpu_pid_state *st, s32 new_power, s32 new_temp) in wf_cpu_pid_run() argument
92 int i, hlen = st->param.history_len; in wf_cpu_pid_run()
95 error = st->param.pmaxadj - new_power; in wf_cpu_pid_run()
98 if (st->first) { in wf_cpu_pid_run()
100 st->powers[i] = new_power; in wf_cpu_pid_run()
101 st->errors[i] = error; in wf_cpu_pid_run()
103 st->temps[0] = st->temps[1] = new_temp; in wf_cpu_pid_run()
104 st->first = 0; in wf_cpu_pid_run()
105 st->index = st->tindex = 0; in wf_cpu_pid_run()
107 st->index = (st->index + 1) % hlen; in wf_cpu_pid_run()
108 st->powers[st->index] = new_power; in wf_cpu_pid_run()
109 st->errors[st->index] = error; in wf_cpu_pid_run()
110 st->tindex = (st->tindex + 1) % 2; in wf_cpu_pid_run()
111 st->temps[st->tindex] = new_temp; in wf_cpu_pid_run()
116 integ += st->errors[(st->index + hlen - i) % hlen]; in wf_cpu_pid_run()
117 integ *= st->param.interval; in wf_cpu_pid_run()
118 integ *= st->param.gr; in wf_cpu_pid_run()
119 sval = st->param.tmax - (s32)(integ >> 20); in wf_cpu_pid_run()
120 adj = min(st->param.ttarget, sval); in wf_cpu_pid_run()
125 deriv = st->temps[st->tindex] - in wf_cpu_pid_run()
126 st->temps[(st->tindex + 2 - 1) % 2]; in wf_cpu_pid_run()
127 deriv /= st->param.interval; in wf_cpu_pid_run()
128 deriv *= st->param.gd; in wf_cpu_pid_run()
131 prop = st->last_delta = (new_temp - adj); in wf_cpu_pid_run()
132 prop *= st->param.gp; in wf_cpu_pid_run()
137 target = st->target + (s32)((deriv + prop) >> 36); in wf_cpu_pid_run()
138 target = max(target, st->param.min); in wf_cpu_pid_run()
139 target = min(target, st->param.max); in wf_cpu_pid_run()
140 st->target = target; in wf_cpu_pid_run()
142 return st->target; in wf_cpu_pid_run()