tools/thermal/tmon/pid.c
Source file repositories/reference/linux-study-clean/tools/thermal/tmon/pid.c
File Facts
- System
- Linux kernel
- Corpus path
tools/thermal/tmon/pid.c- Extension
.c- Size
- 2933 bytes
- Lines
- 120
- Domain
- Support Tooling And Documentation
- Bucket
- tools
- Inferred role
- Support Tooling And Documentation: implementation source
- Status
- source implementation candidate
Why This File Exists
Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
unistd.hstdio.hstdlib.hstring.hstdint.hsys/types.hdirent.hlibintl.hctype.hassert.htime.hlimits.hmath.hsys/stat.hsyslog.htmon.h
Detected Declarations
function init_thermal_controllerfunction controller_resetfunction controller_handler
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* pid.c PID controller for testing cooling devices
*
* Copyright (C) 2012 Intel Corporation. All rights reserved.
*
* Author Name Jacob Pan <jacob.jun.pan@linux.intel.com>
*/
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <sys/types.h>
#include <dirent.h>
#include <libintl.h>
#include <ctype.h>
#include <assert.h>
#include <time.h>
#include <limits.h>
#include <math.h>
#include <sys/stat.h>
#include <syslog.h>
#include "tmon.h"
/**************************************************************************
* PID (Proportional-Integral-Derivative) controller is commonly used in
* linear control system, consider 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)
{
/* 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 0;
}
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;
Annotation
- Immediate include surface: `unistd.h`, `stdio.h`, `stdlib.h`, `string.h`, `stdint.h`, `sys/types.h`, `dirent.h`, `libintl.h`.
- Detected declarations: `function init_thermal_controller`, `function controller_reset`, `function controller_handler`.
- Atlas domain: Support Tooling And Documentation / tools.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.