* [LTP] [PATCH v6 0/3] pmc_core: cover the PkgC LTR blocker counters
@ 2026-11-30 11:58 Piotr Kubaj
2026-11-30 11:58 ` [LTP] [PATCH v6 1/3] pmc_core: add test for pkgc_ltr_blocker_show Piotr Kubaj
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Piotr Kubaj @ 2026-11-30 11:58 UTC (permalink / raw)
To: ltp; +Cc: helena.anna.dubel, tomasz.ossowski, rafael.j.wysocki,
daniel.niestepski
Tests for the pkgc_ltr_blocker_show debugfs file of intel_pmc_core
(kernel v7.2). Depends on "lib: add tst_test.needs_debugfs flag" (v5 1/3)
with the implied needs_root removed, which is not resent here.
Tested on Nova Lake-S running 7.4.0-rc1.
v5 -> v6:
- Both tests set .needs_root themselves and drop .tags.
- New SAFE_SCHED_GETAFFINITY() and SAFE_SCHED_SETAFFINITY().
- pkgc_ltr_blocker_show: strtoull() end pointer check, no global fails
counter, count check moved into second_sample_differs().
- ltr_counter: idle phase bounded by .runtime, TCONF in a VM or with a
restricted affinity mask, two burst periods of silence required.
- Dropped the claim that the tests catch a wrong telemetry offset.
Piotr Kubaj (3):
pmc_core: add test for pkgc_ltr_blocker_show
lib: add SAFE_SCHED_GETAFFINITY() and SAFE_SCHED_SETAFFINITY()
pmc_core: add ltr_counter test
doc/developers/api_c_tests.rst | 4 +
include/tst_safe_sched.h | 83 ++++
runtest/power_management_tests | 2 +
testcases/kernel/power_management/.gitignore | 2 +
.../kernel/power_management/ltr_counter.c | 363 ++++++++++++++++++
.../power_management/pkgc_ltr_blocker_show.c | 291 ++++++++++++++
6 files changed, 745 insertions(+)
create mode 100644 include/tst_safe_sched.h
create mode 100644 testcases/kernel/power_management/ltr_counter.c
create mode 100644 testcases/kernel/power_management/pkgc_ltr_blocker_show.c
base-commit: 0e2b5ce4294ec8642853688ef47c35eb0e35da08
prerequisite-patch-id: 1d5717365b9b15d4bd8f5e80d78a0498f8ef70c5
--
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* [LTP] [PATCH v6 1/3] pmc_core: add test for pkgc_ltr_blocker_show
2026-11-30 11:58 [LTP] [PATCH v6 0/3] pmc_core: cover the PkgC LTR blocker counters Piotr Kubaj
@ 2026-11-30 11:58 ` Piotr Kubaj
2026-11-30 14:33 ` [LTP] " linuxtestproject.agent
2026-11-30 11:59 ` [LTP] [PATCH v6 2/3] lib: add SAFE_SCHED_GETAFFINITY() and SAFE_SCHED_SETAFFINITY() Piotr Kubaj
2026-11-30 11:59 ` [LTP] [PATCH v6 3/3] pmc_core: add ltr_counter test Piotr Kubaj
2 siblings, 1 reply; 5+ messages in thread
From: Piotr Kubaj @ 2026-11-30 11:58 UTC (permalink / raw)
To: ltp
Cc: helena.anna.dubel, tomasz.ossowski, rafael.j.wysocki,
Claude Fable 5.2, daniel.niestepski
Cover the pkgc_ltr_blocker_show debugfs file added in kernel commit
38c79dd63b72 ("platform/x86/intel/pmc: Enable PkgC LTR blocking
counter"), released in v7.2. It reports how many times an LTR posted by
each source blocked a package C-state entry.
The counter set is platform specific, so rather than matching a list of
names the test samples the file twice and checks that it reads to EOF,
that every line is a PKGC_PREVENT_LTR_<SOURCE> token followed by one u32
value, that the counter set is stable, and that no counter advances by
more entries than the package could have attempted over the interval.
The test validates the format and the rate only. A value that does not
change between the two reads passes whatever it is, so it does not prove
that the driver reads the right telemetry offset.
Tested on Nova Lake-S running 7.4.0-rc1.
Signed-off-by: Piotr Kubaj <piotr.kubaj@intel.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
---
runtest/power_management_tests | 1 +
testcases/kernel/power_management/.gitignore | 1 +
.../power_management/pkgc_ltr_blocker_show.c | 291 ++++++++++++++++++
3 files changed, 293 insertions(+)
create mode 100644 testcases/kernel/power_management/pkgc_ltr_blocker_show.c
diff --git a/runtest/power_management_tests b/runtest/power_management_tests
index 5a22283d6..7708d3fd4 100644
--- a/runtest/power_management_tests
+++ b/runtest/power_management_tests
@@ -2,6 +2,7 @@
cpufreq_intel cpufreq_intel
rfim01 rfim01
high_freq_hwp_cap_cppc high_freq_hwp_cap_cppc
+pkgc_ltr_blocker_show pkgc_ltr_blocker_show
runpwtests03 runpwtests03.sh
runpwtests04 runpwtests04.sh
runpwtests06 runpwtests06.sh
diff --git a/testcases/kernel/power_management/.gitignore b/testcases/kernel/power_management/.gitignore
index 766f07901..b96084eca 100644
--- a/testcases/kernel/power_management/.gitignore
+++ b/testcases/kernel/power_management/.gitignore
@@ -1,3 +1,4 @@
high_freq_hwp_cap_cppc
cpufreq_intel
rfim01
+pkgc_ltr_blocker_show
diff --git a/testcases/kernel/power_management/pkgc_ltr_blocker_show.c b/testcases/kernel/power_management/pkgc_ltr_blocker_show.c
new file mode 100644
index 000000000..432527623
--- /dev/null
+++ b/testcases/kernel/power_management/pkgc_ltr_blocker_show.c
@@ -0,0 +1,291 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+/*
+ * Copyright (C) 2026 Piotr Kubaj <piotr.kubaj@intel.com>
+ */
+
+/*\
+ * Verify that pkgc_ltr_blocker_show reports well-formed package C-state LTR
+ * blocker counters that advance at a plausible rate.
+ *
+ * The intel_pmc_core driver prints one line per counter as "%-30s %-30u",
+ * where the name is a PKGC_PREVENT_LTR_<SOURCE> token and the value counts how
+ * many times an LTR posted by <SOURCE> blocked a package C-state entry.
+ *
+ * The counter set is platform specific, so instead of checking a hardcoded
+ * list the test samples the file twice and verifies that
+ *
+ * - the file can be read in full, so that a failing telemetry read in the
+ * driver is not mistaken for a short counter list,
+ * - every line is a PKGC_PREVENT_LTR_<SOURCE> token followed by exactly one
+ * unsigned value that fits in u32,
+ * - the set of counters does not change between the two reads,
+ * - no counter advances by more entries than the package could have attempted
+ * over the interval.
+ *
+ * The last check only validates the rate. The values are u32 and wrap, so the
+ * advance has to be evaluated modulo 2^32, and a wrap is then indistinguishable
+ * from a bogus jump unless the delta is bounded by the time the counter had to
+ * advance over. A value that does not change between the two reads passes
+ * whatever it is, so the test does not prove that the driver reads the right
+ * telemetry offset.
+ *
+ * The debugfs file is only created for a PMC that exposes a package C-state
+ * telemetry endpoint (pc_guid in the driver's pmc_dev_info), so on platforms
+ * without one the test is not applicable.
+ *
+ * The test needs root because /sys/kernel/debug is mode 0700 and owned by
+ * root, so the counter file cannot be opened otherwise, and because the test
+ * library mounts debugfs if it is not mounted already.
+ */
+
+#include <time.h>
+#include "tst_safe_clocks.h"
+#include "tst_safe_stdio.h"
+#include "tst_test.h"
+#include "tst_timer.h"
+
+#define PATH TST_DEBUGFS_PATH "/pmc_core/pkgc_ltr_blocker_show"
+#define PREFIX "PKGC_PREVENT_LTR_"
+
+/* Nova Lake reports 5 counters, leave room for future platforms */
+#define MAX_COUNTERS 64
+#define NAME_LEN 64
+
+/*
+ * Longest gap, in seconds, seen between two advances of the counters on an idle
+ * Nova Lake. How often they move depends on the system, because a blocked entry
+ * needs the package to attempt a C-state entry in the first place: on one
+ * system they advanced in bursts about six seconds apart, on another one
+ * continuously.
+ */
+#define BURST_PERIOD 6
+
+/*
+ * Cap, in seconds, on how long to poll for a second sample that differs from
+ * the first one. TST_RETRY_FN_EXP_BACKOFF() doubles its delay while it is
+ * below the cap, which for 8 adds up to about 8.4 seconds of polling, enough to
+ * span one burst period so that the delta check has something to look at.
+ */
+#define MAX_SAMPLE_DELAY 8
+
+/*
+ * Margin added to the measured interval. The counters advance in bursts, so the
+ * retry can observe a whole burst after only microseconds of measured time,
+ * which a bound scaled by the measured interval alone would reject. Two burst
+ * periods leave room for a system with a slower cadence than the ones tested.
+ */
+#define BURST_MARGIN_US (2 * BURST_PERIOD * 1000000ULL)
+
+/*
+ * Blocked entries per microsecond the bound allows. Each count stands for one
+ * package C-state entry that was blocked, and entries can only be attempted as
+ * fast as the package can cycle between idle and running, which takes
+ * microseconds. Ten per microsecond is therefore already past what the hardware
+ * can produce - the counters were observed advancing by 6 to 185 per second on
+ * idle Nova Lake systems - and the headroom costs the check nothing, because
+ * the bogus jump it exists to catch overshoots it by orders of magnitude
+ * anyway.
+ */
+#define MAX_BLOCKS_PER_US 10
+
+struct snapshot {
+ char names[MAX_COUNTERS][NAME_LEN];
+ uint32_t values[MAX_COUNTERS];
+ int cnt;
+};
+
+static struct snapshot first, second;
+
+/*
+ * Largest advance a counter can plausibly show over two samples taken
+ * @elapsed_us microseconds apart.
+ *
+ * The measured interval is widened by BURST_MARGIN_US, because a burst of
+ * blocked entries can fall into an interval of any length.
+ */
+static unsigned long long max_plausible_delta(unsigned long long elapsed_us)
+{
+ return (elapsed_us + BURST_MARGIN_US) * MAX_BLOCKS_PER_US;
+}
+
+/*
+ * Returns the number of malformed lines, which are reported and left out of
+ * the snapshot.
+ */
+static int read_snapshot(struct snapshot *snap)
+{
+ char line[256];
+ int malformed = 0;
+ FILE *fp;
+
+ snap->cnt = 0;
+ fp = SAFE_FOPEN(PATH, "r");
+
+ while (fgets(line, sizeof(line), fp)) {
+ char name[NAME_LEN], value[NAME_LEN], extra, *end;
+ unsigned long long parsed;
+
+ line[strcspn(line, "\n")] = '\0';
+
+ /*
+ * The value is scanned as a string rather than with %u so that
+ * a non-numeric or out of range value is rejected instead of
+ * being quietly converted. The trailing %c rejects a third
+ * token; the space in front of it skips the padding the driver
+ * emits.
+ */
+ if (sscanf(line, "%63s %63s %c", name, value, &extra) != 2) {
+ tst_res(TFAIL, "malformed counter line: '%s'", line);
+ malformed++;
+ continue;
+ }
+
+ if (strncmp(name, PREFIX, sizeof(PREFIX) - 1) ||
+ !name[sizeof(PREFIX) - 1]) {
+ tst_res(TFAIL, "counter '%s' is not a " PREFIX "<SOURCE> token",
+ name);
+ malformed++;
+ continue;
+ }
+
+ parsed = strtoull(value, &end, 10);
+
+ if (*end || parsed > UINT32_MAX) {
+ tst_res(TFAIL, "counter '%s' value '%s' is not a u32",
+ name, value);
+ malformed++;
+ continue;
+ }
+
+ if (snap->cnt == MAX_COUNTERS)
+ tst_brk(TBROK, "more than %d counters reported", MAX_COUNTERS);
+
+ strcpy(snap->names[snap->cnt], name);
+ snap->values[snap->cnt] = parsed;
+ snap->cnt++;
+ }
+
+ if (ferror(fp))
+ tst_brk(TFAIL, "reading " PATH " failed after %d counters", snap->cnt);
+
+ SAFE_FCLOSE(fp);
+
+ return malformed;
+}
+
+static void setup(void)
+{
+ if (access(PATH, R_OK))
+ tst_brk(TCONF | TERRNO, "%s not available", PATH);
+}
+
+/*
+ * Take the second sample, reporting whether it differs from the first one.
+ *
+ * A blocked entry is a sporadic event, so the second sample is retried until it
+ * observes a change instead of being taken after a fixed delay.
+ */
+static int second_sample_differs(void)
+{
+ int malformed = read_snapshot(&second);
+
+ if (malformed)
+ tst_brk(TFAIL, "%d malformed counter line(s)", malformed);
+
+ if (first.cnt != second.cnt) {
+ tst_brk(TFAIL, "counter count changed between reads: %d -> %d",
+ first.cnt, second.cnt);
+ }
+
+ for (int i = 0; i < first.cnt; i++) {
+ if (first.values[i] != second.values[i])
+ return 1;
+ }
+
+ return 0;
+}
+
+static void run(void)
+{
+ struct timespec start, end;
+ unsigned long long elapsed_us, max_delta;
+ int differs, malformed, fails = 0;
+
+ SAFE_CLOCK_GETTIME(CLOCK_MONOTONIC, &start);
+ malformed = read_snapshot(&first);
+
+ if (malformed)
+ tst_brk(TFAIL, "%d malformed counter line(s)", malformed);
+
+ if (!first.cnt)
+ tst_brk(TFAIL, "no LTR blocker counters reported");
+
+ differs = TST_RETRY_FN_EXP_BACKOFF(second_sample_differs(),
+ TST_RETVAL_NOTNULL, MAX_SAMPLE_DELAY);
+
+ SAFE_CLOCK_GETTIME(CLOCK_MONOTONIC, &end);
+
+ elapsed_us = tst_timespec_diff_us(end, start);
+ max_delta = max_plausible_delta(elapsed_us);
+
+ if (!differs) {
+ tst_res(TINFO, "no counter changed over %lluus, no entry was blocked",
+ elapsed_us);
+ }
+
+ for (int i = 0; i < first.cnt; i++) {
+ uint32_t delta;
+
+ if (strcmp(first.names[i], second.names[i])) {
+ tst_res(TFAIL, "counter %d renamed between reads: %s -> %s",
+ i, first.names[i], second.names[i]);
+ fails++;
+ continue;
+ }
+
+ tst_res(TDEBUG, "%s: %u -> %u", first.names[i],
+ first.values[i], second.values[i]);
+
+ /*
+ * The values are u32 and wrap, so the advance has to be
+ * computed with modular arithmetic rather than by comparing the
+ * second value against the first one. A delta of 0 is normal:
+ * it means no entry was blocked by that source over the
+ * interval, and most counters on an idle system read 0
+ * permanently.
+ */
+ delta = second.values[i] - first.values[i];
+
+ if (delta > max_delta) {
+ tst_res(TFAIL,
+ "%s advanced by %u over %lluus, at most %llu plausible: %u -> %u",
+ first.names[i], delta, elapsed_us, max_delta,
+ first.values[i], second.values[i]);
+ fails++;
+ }
+ }
+
+ if (!fails) {
+ tst_res(TPASS, "%d LTR blocker counters well-formed, advancing plausibly",
+ first.cnt);
+ }
+}
+
+static struct tst_test test = {
+ .min_kver = "7.2",
+ .needs_root = 1,
+ .needs_debugfs = 1,
+ .needs_kconfigs = (const char *const []) {
+ "CONFIG_DEBUG_FS",
+ "CONFIG_INTEL_PMC_CORE",
+ NULL
+ },
+ .supported_archs = (const char *const []) {
+ "x86",
+ "x86_64",
+ NULL
+ },
+ .setup = setup,
+ .test_all = run
+};
--
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [LTP] [PATCH v6 2/3] lib: add SAFE_SCHED_GETAFFINITY() and SAFE_SCHED_SETAFFINITY()
2026-11-30 11:58 [LTP] [PATCH v6 0/3] pmc_core: cover the PkgC LTR blocker counters Piotr Kubaj
2026-11-30 11:58 ` [LTP] [PATCH v6 1/3] pmc_core: add test for pkgc_ltr_blocker_show Piotr Kubaj
@ 2026-11-30 11:59 ` Piotr Kubaj
2026-11-30 11:59 ` [LTP] [PATCH v6 3/3] pmc_core: add ltr_counter test Piotr Kubaj
2 siblings, 0 replies; 5+ messages in thread
From: Piotr Kubaj @ 2026-11-30 11:59 UTC (permalink / raw)
To: ltp
Cc: helena.anna.dubel, tomasz.ossowski, rafael.j.wysocki,
Claude Fable 5.2, daniel.niestepski
Add safe wrappers for sched_getaffinity() and sched_setaffinity() in a
new tst_safe_sched.h header and list it in the C API documentation.
Both calls are GNU extensions, so the header is separate from
tst_safe_macros.h and tests using it have to define _GNU_SOURCE.
Signed-off-by: Piotr Kubaj <piotr.kubaj@intel.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
---
doc/developers/api_c_tests.rst | 4 ++
include/tst_safe_sched.h | 83 ++++++++++++++++++++++++++++++++++
2 files changed, 87 insertions(+)
create mode 100644 include/tst_safe_sched.h
diff --git a/doc/developers/api_c_tests.rst b/doc/developers/api_c_tests.rst
index af7d84ce1..53ff5429f 100644
--- a/doc/developers/api_c_tests.rst
+++ b/doc/developers/api_c_tests.rst
@@ -95,6 +95,10 @@ Safe file operations
--------------------
.. kernel-doc:: ../../include/tst_safe_file_ops.h
+Safe scheduler operations
+-------------------------
+.. kernel-doc:: ../../include/tst_safe_sched.h
+
Saving and restoring /proc|sys values
-------------------------------------
.. kernel-doc:: ../../include/tst_sys_conf.h
diff --git a/include/tst_safe_sched.h b/include/tst_safe_sched.h
new file mode 100644
index 000000000..e1125d2e5
--- /dev/null
+++ b/include/tst_safe_sched.h
@@ -0,0 +1,83 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2026 Piotr Kubaj <piotr.kubaj@intel.com>
+ */
+
+#ifndef TST_SAFE_SCHED_H__
+#define TST_SAFE_SCHED_H__
+
+/*
+ * sched_getaffinity() and sched_setaffinity() are GNU extensions, tests have
+ * to define _GNU_SOURCE before including any header to use these.
+ */
+
+#include <sched.h>
+#include "tst_test.h"
+
+static inline int safe_sched_getaffinity(const char *file, const int lineno,
+ pid_t pid, size_t cpusetsize, cpu_set_t *mask)
+{
+ int rval;
+
+ rval = sched_getaffinity(pid, cpusetsize, mask);
+
+ if (rval == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "sched_getaffinity(%d, %zu, %p) failed",
+ pid, cpusetsize, mask);
+ } else if (rval) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "Invalid sched_getaffinity(%d, %zu, %p) return value %d",
+ pid, cpusetsize, mask, rval);
+ }
+
+ return rval;
+}
+
+/**
+ * SAFE_SCHED_GETAFFINITY() - Reads the CPU affinity mask of a thread.
+ *
+ * @pid: Thread ID, 0 for the calling thread.
+ * @cpusetsize: Size of the mask in bytes.
+ * @mask: Pointer to the CPU set to store the affinity mask into.
+ *
+ * Wrapper for :manpage:`sched_getaffinity(2)`, exits with
+ * :c:enum:`TBROK <tst_res_flags>` on failure.
+ */
+#define SAFE_SCHED_GETAFFINITY(pid, cpusetsize, mask) \
+ safe_sched_getaffinity(__FILE__, __LINE__, (pid), (cpusetsize), (mask))
+
+static inline int safe_sched_setaffinity(const char *file, const int lineno,
+ pid_t pid, size_t cpusetsize, const cpu_set_t *mask)
+{
+ int rval;
+
+ rval = sched_setaffinity(pid, cpusetsize, mask);
+
+ if (rval == -1) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "sched_setaffinity(%d, %zu, %p) failed",
+ pid, cpusetsize, mask);
+ } else if (rval) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "Invalid sched_setaffinity(%d, %zu, %p) return value %d",
+ pid, cpusetsize, mask, rval);
+ }
+
+ return rval;
+}
+
+/**
+ * SAFE_SCHED_SETAFFINITY() - Sets the CPU affinity mask of a thread.
+ *
+ * @pid: Thread ID, 0 for the calling thread.
+ * @cpusetsize: Size of the mask in bytes.
+ * @mask: Pointer to the CPU set with the new affinity mask.
+ *
+ * Wrapper for :manpage:`sched_setaffinity(2)`, exits with
+ * :c:enum:`TBROK <tst_res_flags>` on failure.
+ */
+#define SAFE_SCHED_SETAFFINITY(pid, cpusetsize, mask) \
+ safe_sched_setaffinity(__FILE__, __LINE__, (pid), (cpusetsize), (mask))
+
+#endif /* TST_SAFE_SCHED_H__ */
--
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [LTP] [PATCH v6 3/3] pmc_core: add ltr_counter test
2026-11-30 11:58 [LTP] [PATCH v6 0/3] pmc_core: cover the PkgC LTR blocker counters Piotr Kubaj
2026-11-30 11:58 ` [LTP] [PATCH v6 1/3] pmc_core: add test for pkgc_ltr_blocker_show Piotr Kubaj
2026-11-30 11:59 ` [LTP] [PATCH v6 2/3] lib: add SAFE_SCHED_GETAFFINITY() and SAFE_SCHED_SETAFFINITY() Piotr Kubaj
@ 2026-11-30 11:59 ` Piotr Kubaj
2 siblings, 0 replies; 5+ messages in thread
From: Piotr Kubaj @ 2026-11-30 11:59 UTC (permalink / raw)
To: ltp
Cc: helena.anna.dubel, tomasz.ossowski, rafael.j.wysocki,
Claude Fable 5.2, daniel.niestepski
Test the invariant behind the pkgc_ltr_blocker_show counters: they only
advance while a package C-state entry can be attempted, which needs every
CPU in the package idle. A counter that keeps advancing with every CPU
busy is not counting blocked entries.
The test idles until it sees a counter advance, so that a stuck counter
cannot pass for free, then pins a busy loop to every CPU and requires the
counters to hold still. How often the counters advance while idle depends
on the system, on Nova Lake they were seen moving continuously and in
bursts roughly six seconds apart, so the load phase waits for two burst
periods of silence rather than sampling after a fixed delay: a counter
that keeps running is silent for one period between two bursts. The idle
phase is bounded by the test runtime.
The test cannot keep the package busy when it is confined to a subset of
the online CPUs or runs in a VM, so it exits with TCONF in both cases.
Tested on Nova Lake-S running 7.4.0-rc1.
Signed-off-by: Piotr Kubaj <piotr.kubaj@intel.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
---
runtest/power_management_tests | 1 +
testcases/kernel/power_management/.gitignore | 1 +
.../kernel/power_management/ltr_counter.c | 363 ++++++++++++++++++
3 files changed, 365 insertions(+)
create mode 100644 testcases/kernel/power_management/ltr_counter.c
diff --git a/runtest/power_management_tests b/runtest/power_management_tests
index 7708d3fd4..c4f661257 100644
--- a/runtest/power_management_tests
+++ b/runtest/power_management_tests
@@ -3,6 +3,7 @@ cpufreq_intel cpufreq_intel
rfim01 rfim01
high_freq_hwp_cap_cppc high_freq_hwp_cap_cppc
pkgc_ltr_blocker_show pkgc_ltr_blocker_show
+ltr_counter ltr_counter
runpwtests03 runpwtests03.sh
runpwtests04 runpwtests04.sh
runpwtests06 runpwtests06.sh
diff --git a/testcases/kernel/power_management/.gitignore b/testcases/kernel/power_management/.gitignore
index b96084eca..f54cec368 100644
--- a/testcases/kernel/power_management/.gitignore
+++ b/testcases/kernel/power_management/.gitignore
@@ -2,3 +2,4 @@ high_freq_hwp_cap_cppc
cpufreq_intel
rfim01
pkgc_ltr_blocker_show
+ltr_counter
diff --git a/testcases/kernel/power_management/ltr_counter.c b/testcases/kernel/power_management/ltr_counter.c
new file mode 100644
index 000000000..3b79851a8
--- /dev/null
+++ b/testcases/kernel/power_management/ltr_counter.c
@@ -0,0 +1,363 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+/*
+ * Copyright (C) 2026 Intel - http://www.intel.com/
+ */
+
+/*\
+ * Verify that the package C-state LTR blocker counters only advance while a
+ * package C-state entry can be attempted.
+ *
+ * The pkgc_ltr_blocker_show debugfs file reports, per source, how many times an
+ * LTR posted by that source blocked a package C-state entry. Such an entry is
+ * only attempted once every CPU in the package has gone idle, so a workload
+ * that keeps every CPU busy has to stop the counters. A counter that keeps
+ * advancing under full load is not counting blocked package C-state entries,
+ * which is what a telemetry region read at the wrong offset looks like.
+ *
+ * The test first lets the system idle until it sees a counter advance, so that
+ * a counter stuck at a constant value cannot pass the load phase for free. It
+ * then pins a busy loop to every CPU and requires the counters to hold still.
+ * That only works if the test can load every CPU of the package, so it is
+ * skipped when its affinity mask does not cover all online CPUs and under a
+ * hypervisor, where the guest only sees the CPUs it was given.
+ *
+ * How often the counters advance while idle depends on the system: on Nova Lake
+ * they were seen moving continuously on one system and in bursts roughly six
+ * seconds apart on another, so the load phase waits for the counters to go
+ * quiet rather than sampling them after a fixed delay. Entries blocked before
+ * the load took hold can still surface in a later burst, while a counter that
+ * is not tracking blocked entries never goes quiet at all and runs the window
+ * out.
+ *
+ * The test needs root because /sys/kernel/debug is mode 0700 and owned by
+ * root, so the counter file cannot be opened otherwise, and because the test
+ * library mounts debugfs if it is not mounted already.
+ */
+
+#define _GNU_SOURCE
+
+#include <time.h>
+#include "tst_cpu.h"
+#include "tst_safe_clocks.h"
+#include "tst_safe_sched.h"
+#include "tst_safe_stdio.h"
+#include "tst_test.h"
+#include "tst_timer.h"
+
+#define PATH TST_DEBUGFS_PATH "/pmc_core/pkgc_ltr_blocker_show"
+
+/* Nova Lake reports 5 counters, leave room for future platforms */
+#define MAX_COUNTERS 64
+#define NAME_LEN 64
+
+#define POLL_MS 500
+
+/*
+ * Seconds to wait for a counter to advance while the system idles, used as the
+ * test runtime. The bursts were up to about six seconds apart on Nova Lake, so
+ * this leaves room for two of them before giving up on the platform blocking a
+ * package C-state entry at all.
+ */
+#define IDLE_WINDOW 15
+
+/*
+ * How long, in seconds, the counters have to hold still under load, and the cap
+ * on how long to wait for that. A counter that keeps running is silent for one
+ * burst period between two bursts, so it takes two periods of silence to
+ * tell a stopped counter from it. The cap has to be long enough on top of that
+ * for a burst counted before the load took hold to arrive and drain.
+ *
+ * Both are sized for the slowest cadence seen on Nova Lake, bursts roughly six
+ * seconds apart. A platform whose counters advance less often than every half
+ * QUIET_WINDOW needs it raised, otherwise a counter that is not tracking
+ * blocked entries at all sits still between two bursts and passes the check.
+ */
+#define QUIET_WINDOW 12
+#define LOAD_WINDOW 30
+
+static char names[MAX_COUNTERS][NAME_LEN];
+static int cnt;
+static cpu_set_t mask;
+static int nr_cpus;
+static pid_t *spinners;
+static int nr_spinners;
+static volatile unsigned long long burn;
+
+/*
+ * Read the counter values, checking that the counter set itself has not changed
+ * since setup(). Only the values are of interest here - the format of the file
+ * is what the pkgc_ltr_blocker_show test covers - so anything unexpected about
+ * the lines makes this test unable to run rather than failing it.
+ */
+static void read_counters(uint32_t *values)
+{
+ char line[256];
+ FILE *fp;
+ int n = 0;
+
+ fp = SAFE_FOPEN(PATH, "r");
+
+ while (fgets(line, sizeof(line), fp)) {
+ char name[NAME_LEN];
+ unsigned int value;
+
+ if (sscanf(line, "%63s %u", name, &value) != 2)
+ tst_brk(TBROK, "unexpected line format: '%s'", line);
+
+ values[n] = value;
+
+ if (cnt && strcmp(name, names[n])) {
+ tst_brk(TBROK, "counter %d renamed during the test: %s -> %s",
+ n, names[n], name);
+ }
+
+ if (!cnt)
+ strcpy(names[n], name);
+
+ if (++n == MAX_COUNTERS)
+ tst_brk(TBROK, "too many counters, increase MAX_COUNTERS");
+ }
+
+ if (ferror(fp))
+ tst_brk(TBROK, "reading " PATH " failed after %d counters", n);
+
+ SAFE_FCLOSE(fp);
+
+ if (cnt && n != cnt)
+ tst_brk(TBROK, "counter count changed during the test: %d -> %d", cnt, n);
+
+ cnt = n;
+}
+
+static void spin(void)
+{
+ for (;;)
+ burn++;
+}
+
+/*
+ * Keep every CPU the test may run on busy, so that the package cannot go idle
+ * and no package C-state entry can be attempted.
+ */
+static void start_load(void)
+{
+ int cpu = 0;
+
+ spinners = SAFE_MALLOC(nr_cpus * sizeof(*spinners));
+
+ for (int i = 0; i < nr_cpus; i++) {
+ pid_t pid;
+
+ while (!CPU_ISSET(cpu, &mask))
+ cpu++;
+
+ pid = SAFE_FORK();
+
+ if (!pid) {
+ cpu_set_t one;
+
+ CPU_ZERO(&one);
+ CPU_SET(cpu, &one);
+
+ SAFE_SCHED_SETAFFINITY(0, sizeof(one), &one);
+ spin();
+ }
+
+ spinners[nr_spinners++] = pid;
+ cpu++;
+ }
+
+ tst_res(TINFO, "keeping %d CPUs busy", nr_spinners);
+}
+
+static void stop_load(void)
+{
+ if (!spinners)
+ return;
+
+ for (int i = 0; i < nr_spinners; i++) {
+ SAFE_KILL(spinners[i], SIGKILL);
+ SAFE_WAITPID(spinners[i], NULL, 0);
+ }
+
+ free(spinners);
+ spinners = NULL;
+ nr_spinners = 0;
+}
+
+/*
+ * Wait for a counter to advance while the system idles, reporting how many did.
+ *
+ * This is what tells a counter that stops under load from one that never moves.
+ * On an idle system most counters read 0 permanently, because nothing posts an
+ * LTR that would block a package C-state entry, so a single counter advancing
+ * is enough.
+ */
+static int wait_for_advance(const uint32_t *baseline)
+{
+ uint32_t values[MAX_COUNTERS];
+ int advanced = 0;
+
+ for (;;) {
+ read_counters(values);
+
+ for (int i = 0; i < cnt; i++) {
+ if (values[i] == baseline[i])
+ continue;
+
+ tst_res(TINFO, "%s advanced by %u while idle", names[i],
+ values[i] - baseline[i]);
+ advanced++;
+ }
+
+ if (advanced)
+ return advanced;
+
+ if (!tst_remaining_runtime())
+ return 0;
+
+ usleep(POLL_MS * 1000);
+ }
+}
+
+/*
+ * Require the counters to hold still for QUIET_WINDOW seconds of full load.
+ */
+static void check_counters_stop(void)
+{
+ uint32_t first[MAX_COUNTERS], prev[MAX_COUNTERS], values[MAX_COUNTERS];
+ struct timespec changed_at[MAX_COUNTERS];
+ struct timespec start, last_change, now;
+
+ read_counters(first);
+ memcpy(prev, first, sizeof(prev));
+
+ SAFE_CLOCK_GETTIME(CLOCK_MONOTONIC, &start);
+ last_change = start;
+
+ for (int i = 0; i < cnt; i++)
+ changed_at[i] = start;
+
+ for (;;) {
+ usleep(POLL_MS * 1000);
+
+ read_counters(values);
+ SAFE_CLOCK_GETTIME(CLOCK_MONOTONIC, &now);
+
+ for (int i = 0; i < cnt; i++) {
+ if (values[i] == prev[i])
+ continue;
+
+ changed_at[i] = now;
+ last_change = now;
+ }
+
+ memcpy(prev, values, sizeof(prev));
+
+ if (tst_timespec_diff_ms(now, last_change) >= QUIET_WINDOW * 1000) {
+ tst_res(TPASS,
+ "%d counters held still over %ds with every CPU busy",
+ cnt, QUIET_WINDOW);
+ return;
+ }
+
+ if (tst_timespec_diff_ms(now, start) < LOAD_WINDOW * 1000)
+ continue;
+
+ /*
+ * A counter that last changed a quiet window ago or more was
+ * only draining entries blocked before the load took hold. The
+ * ones that changed since are the ones that never stopped.
+ */
+ for (int i = 0; i < cnt; i++) {
+ if (tst_timespec_diff_ms(now, changed_at[i]) >=
+ QUIET_WINDOW * 1000)
+ continue;
+
+ tst_res(TFAIL,
+ "%s kept advancing over %ds with every CPU busy: %u -> %u",
+ names[i], LOAD_WINDOW, first[i], values[i]);
+ }
+
+ return;
+ }
+}
+
+static void setup(void)
+{
+ uint32_t values[MAX_COUNTERS];
+ long online = tst_ncpus_global();
+
+ if (access(PATH, R_OK))
+ tst_brk(TCONF | TERRNO, "%s not available", PATH);
+
+ /*
+ * A guest cannot keep the host package busy with the CPUs it was
+ * given, and the same goes for a test confined to a subset of CPUs.
+ */
+ if (tst_is_virt(VIRT_ANY))
+ tst_brk(TCONF, "cannot load every CPU of the package in a VM");
+
+ SAFE_SCHED_GETAFFINITY(0, sizeof(mask), &mask);
+ nr_cpus = CPU_COUNT(&mask);
+
+ if (nr_cpus != online) {
+ tst_brk(TCONF, "can only run on %d of %ld online CPUs",
+ nr_cpus, online);
+ }
+
+ /* Learns the counter set the rest of the test compares against */
+ read_counters(values);
+
+ if (!cnt)
+ tst_brk(TBROK, "no LTR blocker counters reported");
+}
+
+static void cleanup(void)
+{
+ stop_load();
+}
+
+static void run(void)
+{
+ uint32_t baseline[MAX_COUNTERS];
+
+ read_counters(baseline);
+
+ /*
+ * Without a counter that moves while idle there is nothing to stop
+ * under load, a stuck counter would look exactly the same.
+ */
+ if (!wait_for_advance(baseline)) {
+ tst_brk(TCONF,
+ "no LTR blocked a package C-state entry while idling");
+ }
+
+ start_load();
+ check_counters_stop();
+ stop_load();
+}
+
+static struct tst_test test = {
+ .min_kver = "7.2",
+ .runtime = IDLE_WINDOW,
+ .min_runtime = IDLE_WINDOW,
+ .timeout = 2 * LOAD_WINDOW,
+ .needs_root = 1,
+ .needs_debugfs = 1,
+ .forks_child = 1,
+ .needs_kconfigs = (const char *const []) {
+ "CONFIG_DEBUG_FS",
+ "CONFIG_INTEL_PMC_CORE",
+ NULL
+ },
+ .supported_archs = (const char *const []) {
+ "x86",
+ "x86_64",
+ NULL
+ },
+ .setup = setup,
+ .cleanup = cleanup,
+ .test_all = run
+};
--
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
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [LTP] pmc_core: add test for pkgc_ltr_blocker_show
2026-11-30 11:58 ` [LTP] [PATCH v6 1/3] pmc_core: add test for pkgc_ltr_blocker_show Piotr Kubaj
@ 2026-11-30 14:33 ` linuxtestproject.agent
0 siblings, 0 replies; 5+ messages in thread
From: linuxtestproject.agent @ 2026-11-30 14:33 UTC (permalink / raw)
To: Piotr Kubaj; +Cc: ltp
Hi Piotr,
On Mon Nov 30 12:58:59 2026 +0100, Piotr Kubaj <piotr.kubaj@intel.com> wrote:
> pmc_core: add test for pkgc_ltr_blocker_show
Verdict - Reviewed
---
Note:
The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-30 14:33 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 11:58 [LTP] [PATCH v6 0/3] pmc_core: cover the PkgC LTR blocker counters Piotr Kubaj
2026-11-30 11:58 ` [LTP] [PATCH v6 1/3] pmc_core: add test for pkgc_ltr_blocker_show Piotr Kubaj
2026-11-30 14:33 ` [LTP] " linuxtestproject.agent
2026-11-30 11:59 ` [LTP] [PATCH v6 2/3] lib: add SAFE_SCHED_GETAFFINITY() and SAFE_SCHED_SETAFFINITY() Piotr Kubaj
2026-11-30 11:59 ` [LTP] [PATCH v6 3/3] pmc_core: add ltr_counter test Piotr Kubaj
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.