/* * pid.c PID controller for testing cooling devices * * * * Copyright (C) 2012 Intel Corporation. All rights reserved. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License version * 2 or later as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * Author Name Jacob Pan * */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "tmon.h" /************************************************************************** * PID (Proportional-Integral-Derivative) controller is commonly used in * linear control system, consider the the process. * G(s) = U(s)/E(s) * kp = proportional gain * ki = integral gain * kd = derivative gain * Ts * We use type C Alan Bradley equation which takes set point off the * output dependency in P and D term. * * y[k] = y[k-1] - kp*(x[k] - x[k-1]) + Ki*Ts*e[k] - Kd*(x[k] * - 2*x[k-1]+x[k-2])/Ts * * ***********************************************************************/ struct pid_params p_param; /* cached data from previous loop */ static double xk_1, xk_2; /* input temperature x[k-#] */ /* * TODO: make PID parameters tuned automatically, * 1. use CPU burn to produce open loop unit step response * 2. calculate PID based on Ziegler-Nichols rule * * add a flag for tuning PID */ int init_thermal_controller(void) { int ret = 0; /* init pid params */ p_param.ts = ticktime; /* TODO: get it from TUI tuning tab */ p_param.kp = .36; p_param.ki = 5.0; p_param.kd = 0.19; p_param.t_target = target_temp_user; return ret; } void controller_reset(void) { /* TODO: relax control data when not over thermal limit */ syslog(LOG_DEBUG, "TC inactive, relax p-state\n"); p_param.y_k = 0.0; xk_1 = 0.0; xk_2 = 0.0; set_ctrl_state(0); } /* To be called at time interval Ts. Type C PID controller. * y[k] = y[k-1] - kp*(x[k] - x[k-1]) + Ki*Ts*e[k] - Kd*(x[k] * - 2*x[k-1]+x[k-2])/Ts * TODO: add low pass filter for D term */ #define GUARD_BAND (2) void controller_handler(const double xk, double *yk) { double ek; double p_term, i_term, d_term; ek = p_param.t_target - xk; /* error */ if (ek >= 3.0) { syslog(LOG_DEBUG, "PID: %3.1f Below set point %3.1f, stop\n", xk, p_param.t_target); controller_reset(); *yk = 0.0; return; } /* compute intermediate PID terms */ p_term = -p_param.kp * (xk - xk_1); i_term = p_param.kp * p_param.ki * p_param.ts * ek; d_term = -p_param.kp * p_param.kd * (xk - 2 * xk_1 + xk_2) / p_param.ts; /* compute output */ *yk += p_term + i_term + d_term; /* update sample data */ xk_1 = xk; xk_2 = xk_1; /* clamp output adjustment range */ if (*yk < -LIMIT_HIGH) *yk = -LIMIT_HIGH; else if (*yk > -LIMIT_LOW) *yk = -LIMIT_LOW; p_param.y_k = *yk; set_ctrl_state(lround(fabs(p_param.y_k))); } ue='5'>5space:mode:
authorThomas Gleixner <tglx@linutronix.de>2017-01-31 23:58:38 +0100
committerIngo Molnar <mingo@kernel.org>2017-02-01 08:37:27 +0100
commitdd86e373e09fb16b83e8adf5c48c421a4ca76468 (patch)
tree55703c2ea8584e303e342090614e0aab3509ab21 /sound/pci
parent0b3589be9b98994ce3d5aeca52445d1f5627c4ba (diff)
perf/x86/intel/rapl: Make package handling more robust
The package management code in RAPL relies on package mapping being available before a CPU is started. This changed with: 9d85eb9119f4 ("x86/smpboot: Make logical package management more robust") because the ACPI/BIOS information turned out to be unreliable, but that left RAPL in broken state. This was not noticed because on a regular boot all CPUs are online before RAPL is initialized. A possible fix would be to reintroduce the mess which allocates a package data structure in CPU prepare and when it turns out to already exist in starting throw it away later in the CPU online callback. But that's a horrible hack and not required at all because RAPL becomes functional for perf only in the CPU online callback. That's correct because user space is not yet informed about the CPU being onlined, so nothing caan rely on RAPL being available on that particular CPU. Move the allocation to the CPU online callback and simplify the hotplug handling. At this point the package mapping is established and correct. This also adds a missing check for available package data in the event_init() function. Reported-by: Yasuaki Ishimatsu <yasu.isimatu@gmail.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Sebastian Siewior <bigeasy@linutronix.de> Cc: Stephane Eranian <eranian@google.com> Cc: Vince Weaver <vincent.weaver@maine.edu> Fixes: 9d85eb9119f4 ("x86/smpboot: Make logical package management more robust") Link: http://lkml.kernel.org/r/20170131230141.212593966@linutronix.de Signed-off-by: Ingo Molnar <mingo@kernel.org>
Diffstat (limited to 'sound/pci')