Skip to contentSkip to conversation

thermal: add new test group

PATCH Superseded Piotr Kubaj 3 participants 3 messages Apr 8 – Apr 27

v16 of 21 Superseded Latest is v21 →

lore
Share & tools
lore
#0 lore raw

PATCH v16 1/1 thermal: add new test group

Currently consists of only one test for the CPU package thermal sensor interface for Intel platforms.
It works by checking the initial count of thermal interrupts. Then it decreases the threshold for sending a thermal interrupt to just above the current temperature and runs a workload on the CPU. Finally, it restores the original thermal threshold and checks whether the number of thermal interrupts increased.

---
I previously missed Petr's email, this version addresses his feedback as well.

 runtest/thermal                               |   3 +
 testcases/kernel/Makefile                     |   1 +
 testcases/kernel/thermal/.gitignore           |   1 +
 testcases/kernel/thermal/Makefile             |   9 +
 .../kernel/thermal/thermal_interrupt_events.c | 235 ++++++++++++++++++
 5 files changed, 249 insertions(+)
 create mode 100644 runtest/thermal
 create mode 100644 testcases/kernel/thermal/.gitignore
 create mode 100644 testcases/kernel/thermal/Makefile
 create mode 100644 testcases/kernel/thermal/thermal_interrupt_events.c
runtest/thermal new file +3 -0
new file mode 100644
index 000000000..57e3d29f8
@@ -0,0 +1,3 @@
+# Thermal driver API
+# https://docs.kernel.org/driver-api/thermal/
+thermal_interrupt_events thermal_interrupt_events
testcases/kernel/Makefile +1 -0
index 98fd45a9d..ac816e4e8 100644
@@ -36,6 +36,7 @@ SUBDIRS			+= connectors \
 			   sched \
 			   security \
 			   sound \
+			   thermal \
 			   tracing \
 			   uevents \
 			   watchqueue \
testcases/kernel/thermal/.gitignore new file +1 -0
new file mode 100644
index 000000000..1090bdad8
@@ -0,0 +1 @@
+thermal_interrupt_events
testcases/kernel/thermal/Makefile new file +9 -0
new file mode 100644
index 000000000..4657c3fb3
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2025, Intel Corporation. All rights reserved.
+# Author:Piotr Kubaj <[email protected]>
+
+top_srcdir             ?= ../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/thermal/thermal_interrupt_events.c new file +235 -0

235 lines not on this page · raw message

Signature · 13 lines
2.47.3

---------------------------------------------------------------------
Intel Technology Poland sp. z o.o.
ul. Slowackiego 173 | 80-298 Gdansk | Sad Rejonowy Gdansk Polnoc | VII Wydzial Gospodarczy Krajowego Rejestru Sadowego - KRS 101882 | NIP 957-07-52-316 | Kapital zakladowy 200.000 PLN.
Spolka oswiadcza, ze posiada status duzego przedsiebiorcy w rozumieniu ustawy z dnia 8 marca 2013 r. o przeciwdzialaniu nadmiernym opoznieniom w transakcjach handlowych.

Ta wiadomosc wraz z zalacznikami jest przeznaczona dla okreslonego adresata i moze zawierac informacje poufne. W razie przypadkowego otrzymania tej wiadomosci, prosimy o powiadomienie nadawcy oraz trwale jej usuniecie; jakiekolwiek przegladanie lub rozpowszechnianie jest zabronione.
This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). If you are not the intended recipient, please contact the sender and delete all copies; any review or distribution by others is strictly prohibited.


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
Reviewed-by on v16 1/1
#1 lore raw
Quoted 11 lines

Currently consists of only one test for the CPU package thermal sensor interface for Intel platforms.
It works by checking the initial count of thermal interrupts. Then it decreases the threshold for sending a thermal interrupt to just above the current temperature and runs a workload on the CPU. Finally, it restores the original thermal threshold and checks whether the number of thermal interrupts increased.

---
I previously missed Petr's email, this version addresses his feedback as well.

Thank you!

LGTM, minor formatting notes below (ignore, unless you need to send another version, or it could be done before merge).

We have (after update) few more fixes needed. But that can be done before merge. thermal_interrupt_events.c:64: CHECK: Avoid CamelCase: <PRIu64> thermal_interrupt_events.c:177: CHECK: Blank lines aren't necessary before a close brace '}' thermal_interrupt_events.c:215: CHECK: Blank lines aren't necessary before a close brace '}'

Quoted 91 lines
 runtest/thermal                               |   3 +
 testcases/kernel/Makefile                     |   1 +
 testcases/kernel/thermal/.gitignore           |   1 +
 testcases/kernel/thermal/Makefile             |   9 +
 .../kernel/thermal/thermal_interrupt_events.c | 235 ++++++++++++++++++
 5 files changed, 249 insertions(+)
 create mode 100644 runtest/thermal
 create mode 100644 testcases/kernel/thermal/.gitignore
 create mode 100644 testcases/kernel/thermal/Makefile
 create mode 100644 testcases/kernel/thermal/thermal_interrupt_events.c
runtest/thermal new file +3 -0
new file mode 100644
index 000000000..57e3d29f8
@@ -0,0 +1,3 @@
+# Thermal driver API
+# https://docs.kernel.org/driver-api/thermal/
+thermal_interrupt_events thermal_interrupt_events
testcases/kernel/Makefile +1 -0
index 98fd45a9d..ac816e4e8 100644
@@ -36,6 +36,7 @@ SUBDIRS			+= connectors \
 			   sched \
 			   security \
 			   sound \
+			   thermal \
 			   tracing \
 			   uevents \
 			   watchqueue \
testcases/kernel/thermal/.gitignore new file +1 -0
new file mode 100644
index 000000000..1090bdad8
@@ -0,0 +1 @@
+thermal_interrupt_events
testcases/kernel/thermal/Makefile new file +9 -0
new file mode 100644
index 000000000..4657c3fb3
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2025, Intel Corporation. All rights reserved.
+# Author:Piotr Kubaj <[email protected]>
+
+top_srcdir             ?= ../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/thermal/thermal_interrupt_events.c new file +31 -0
new file mode 100644
index 000000000..e3204784e
@@ -0,0 +1,235 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2026 Intel - http://www.intel.com/
+ */
+
+/*\
+ * Tests the CPU package thermal sensor interface for Intel platforms.
+
+ * Works by checking the initial count of thermal interrupts. Then it
+ * decreases the threshold for sending a thermal interrupt to just above
+ * the current temperature and runs a workload on the CPU. Finally, it restores
+ * the original thermal threshold and checks whether the number of thermal
+ * interrupts increased.
+ */
+
+#include <ctype.h>
+#include <inttypes.h>
+#include "tst_safe_stdio.h"
+#include "tst_test.h"
+#include "tst_timer_test.h"
+
+#define	TEST_RUNTIME	3
+#define	RUNTIME		30
+#define	SLEEP		10
+#define	TEMP_INCREMENT	10
+
+static bool x86_pkg_temp_tz_found, *x86_pkg_temp_tz;
+static char temp_path[PATH_MAX], trip_path[PATH_MAX];
+static int nproc, temp_high, temp, *trip_orig, tz_counter;
+static uint64_t *interrupt_init, *interrupt_later;
+

testcases/kernel/thermal/thermal_interrupt_events.c line 41

Quoted 10 lines
testcases/kernel/thermal/thermal_interrupt_events.c new file +10 -0
+static void read_interrupts(uint64_t *interrupts)
+{
+	bool interrupts_found = false;
+	char line[8192];
+
+	memset(interrupts, 0, nproc * sizeof(*interrupts));
+	FILE *fp = SAFE_FOPEN("/proc/interrupts", "r");
+
+	while (fgets(line, sizeof(line), fp)) {
+		if (strstr(line, "Thermal event interrupts")) {

very nit: reverting the condition would allow to remove one indentation level (helps readability):

	while (fgets(line, sizeof(line), fp)) {
		if (!strstr(line, "Thermal event interrupts"))
			continue;

		interrupts_found = true;
		char *ptr = strchr(line, ':');

The rest LGTM.

Kind regards,
Petr

Quoted 29 lines
testcases/kernel/thermal/thermal_interrupt_events.c new file +29 -0
+			interrupts_found = true;
+			char *ptr = strchr(line, ':');
+
+			for (int i = 0; i < nproc; i++) {
+				char *endptr;
+
+				while (*ptr && !isdigit(*ptr))
+					ptr++;
+
+				errno = 0;
+
+				interrupts[i] = strtoull(ptr, &endptr, 10);
+
+				if (ptr == endptr)
+					tst_brk(TBROK, "CPU %d: interrupt not found", nproc);
+
+				if (errno == ERANGE)
+					tst_brk(TBROK, "CPU %d: interrupt out of range", nproc);
+
+				ptr = endptr;
+				tst_res(TDEBUG, "interrupts[%d]: %" PRIu64, i, interrupts[i]);
+			}
+			break;
+		}
+	}
+	SAFE_FCLOSE(fp);
+	if (!interrupts_found)
+		tst_brk(TCONF, "No Thermal event interrupts line in /proc/interrupts");
+}
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
#2 lore raw
In reply to Piotr Kubaj

Hi Piotr,

testcases/kernel/thermal/thermal_interrupt_events.c line 59

Quoted 7 lines
testcases/kernel/thermal/thermal_interrupt_events.c new file +7 -0
+				interrupts[i] = strtoull(ptr, &endptr, 10);
+
+				if (ptr == endptr)
+					tst_brk(TBROK, "CPU %d: interrupt not found", nproc);
+
+				if (errno == ERANGE)
+					tst_brk(TBROK, "CPU %d: interrupt out of range", nproc);

nproc inside tst_brk() is wrong, we should use i, otherwise we see a wrong error message.

Quoted 6 lines
testcases/kernel/thermal/thermal_interrupt_events.c new file +6 -0
+static void run(void)
+{
+	for (int i = 0; i < tz_counter; i++) {
+		if (x86_pkg_temp_tz[i]) {
+			read_interrupts(interrupt_init);
+			test_zone(i);

testcases/kernel/thermal/thermal_interrupt_events.c line 209

Quoted 10 lines
testcases/kernel/thermal/thermal_interrupt_events.c new file +10 -0
+			read_interrupts(interrupt_later);
+			for (int j = 0; j < nproc; j++) {
+				if (interrupt_later[j] < interrupt_init[j])
+					tst_res(TFAIL, "CPU %d interrupt counter: %" PRIu64 " (previous: %" PRIu64 ")",
+						j, interrupt_later[j], interrupt_init[j]);
+			}
+			if (temp <= temp_high)
+				tst_res(TFAIL, "Zone temperature is not rising as expected");
+			else
+				tst_res(TPASS, "x86 package thermal interrupt triggered");

The interrupt check only flags TFAIL when counters decrease (< ), but never verifies they actually increased. If no new interrupts were triggered (counters stay the same), the test still passes as long as temperature rose. The condition should use <= to catch the "no increase" case, and the TPASS should reflect that interrupts were verified, not just temperature.

The rest LGTM.

--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp