linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Meet Udeshi <mudeshi1209@gmail.com>
To: linux-pm@vger.kernel.org
Cc: Meet Udeshi <mudeshi1209@gmail.com>
Subject: [PATCH] tools/thermal: tmon: Fix sample data update in PID
Date: Tue, 22 Aug 2023 14:49:40 -0400	[thread overview]
Message-ID: <20230822184940.31316-1-mudeshi1209@gmail.com> (raw)

Fixed the order of update for `xk_1` and `xk_2` in the PID controller in
function `controller_handler()`.

The previous timestep data in the PID controller, `xk_1` and `xk_2`,
were updated in the wrong order. `xk_1` was overwritten before `xk_2`
was assigned. This caused both `xk_1` and `xk_2` to take the value of
`xk` when the function `controller_handler()` was called.
This means the D-term of the PID controller was simplified from
a second-order approximation using two previous timesteps to a
first-order approximation using one previous timestep.

    xk - 2 * xk_1 + xk_2 => xk - xk_1

This degraded the performance of the PID controller by making it more
noisy and less accurate.

This bug was found by reverse engineering the tmon binary using the
[REMaQE tool](https://arxiv.org/abs/2305.06902).

Signed-off-by: Meet Udeshi <mudeshi1209@gmail.com>
Fixes: 94f69966faf8 ("tools/thermal: Introduce tmon, a tool for thermal subsystem")
---
 tools/thermal/tmon/pid.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/thermal/tmon/pid.c b/tools/thermal/tmon/pid.c
index da20088285bd..1c02eb675088 100644
--- a/tools/thermal/tmon/pid.c
+++ b/tools/thermal/tmon/pid.c
@@ -103,8 +103,8 @@ void controller_handler(const double xk, double *yk)
 	/* compute output */
 	*yk += p_term + i_term + d_term;
 	/* update sample data */
-	xk_1 = xk;
 	xk_2 = xk_1;
+	xk_1 = xk;
 
 	/* clamp output adjustment range */
 	if (*yk < -LIMIT_HIGH)
-- 
2.34.1


             reply	other threads:[~2023-08-22 18:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-22 18:49 Meet Udeshi [this message]
2023-09-11 21:20 ` [PATCH] tools/thermal: tmon: Fix sample data update in PID Meet Udeshi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230822184940.31316-1-mudeshi1209@gmail.com \
    --to=mudeshi1209@gmail.com \
    --cc=linux-pm@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).