pmc_core: cover the PkgC LTR blocker counters
v2 cover pmc_core: cover the PkgC LTR blocker counters
The intel_pmc_core driver gained a pkgc_ltr_blocker_show debugfs file in kernel commit 38c79dd63b72 ("platform/x86/intel/pmc: Enable PkgC LTR blocking counter"), first released in v7.2, and nothing covers it yet. It reports, per source, how many times an LTR posted by that source blocked a package C-state entry.
Both tests added here need debugfs mounted, so the first patch moves the mount handling into the test library instead of open coding it twice.
1/3 adds tst_test.needs_debugfs: the library mounts debugfs at
/sys/kernel/debug during setup unless it is mounted there already, reports TCONF if it cannot, and unmounts it afterwards only if it did the mount. A lib/newlib_tests self-test covers both cases. Tests reading any other debugfs file can use it as well.
2/3 checks what the file says: every line is a PKGC_PREVENT_LTR_<SOURCE>
token followed by one u32 value, the file reads to EOF rather than erroring out mid-way, the counter set is stable across two reads, and no counter advances by more entries than the package could have attempted over the interval.
3/3 checks the invariant behind the counters: a package C-state entry is
only attempted once every CPU in the package is idle, so counters that keep advancing with every CPU busy are not counting blocked entries. The test proves the counters are alive while idling first, so that a counter stuck at a constant value cannot pass for free.
Both tests bound what they accept in time rather than against a hardcoded counter list, because the counter set is platform specific. That is what catches a telemetry region read at the wrong offset, which overshoots the bounds by orders of magnitude.
Tested on Nova Lake running 7.3.0-rc1, with debugfs both mounted and unmounted beforehand, and in the latter case the mount state is restored after the run. The TFAIL and TCONF paths were exercised against fake counter files.
Piotr Kubaj (3):
lib: add tst_test.needs_debugfs flag
pmc_core: add test for pkgc_ltr_blocker_show
pmc_core: add ltr_counter test
doc/developers/writing_tests.rst | 3 + include/tst_fs.h | 4 + include/tst_test.h | 8 + lib/newlib_tests/.gitignore | 1 + lib/newlib_tests/runtest.sh | 1 + lib/newlib_tests/tst_needs_debugfs.c | 37 ++ lib/tst_test.c | 35 ++ metadata/metaparse.c | 1 + runtest/power_management_tests | 2 + testcases/kernel/power_management/.gitignore | 2 + .../kernel/power_management/ltr_counter.c | 358 ++++++++++++++++++ .../power_management/pkgc_ltr_blocker_show.c | 294 ++++++++++++++ 12 files changed, 746 insertions(+) create mode 100644 lib/newlib_tests/tst_needs_debugfs.c create mode 100644 testcases/kernel/power_management/ltr_counter.c create mode 100644 testcases/kernel/power_management/pkgc_ltr_blocker_show.c
base-commit: 463b33ad464b6840d0a1df5d41939e50d55d542c
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
PATCH v2 1/3 lib: add tst_test.needs_debugfs flag
Tests that read debugfs files have to check that debugfs is mounted at /sys/kernel/debug and mount it when it is not. The mount point exists as a plain sysfs directory whenever CONFIG_DEBUG_FS is enabled, whether or not debugfs is mounted on it, so a test that only checks that the path is there reports the platform as unsupported when debugfs simply is not mounted, and each test ends up carrying the same statfs() and mount() dance.
Move it into the library: with tst_test.needs_debugfs set the library mounts debugfs during setup, exits with TCONF if it cannot, and unmounts it at the end of the test if it was the one that mounted it. Add TST_DEBUGFS_PATH so that tests build their paths from the library constant, register the flag in the metadata parser, and add a lib/newlib_tests self-test that covers both the mounted and the unmounted case.
--- doc/developers/writing_tests.rst | 3 +++ include/tst_fs.h | 4 +++ include/tst_test.h | 8 ++++++ lib/newlib_tests/.gitignore | 1 + lib/newlib_tests/runtest.sh | 1 + lib/newlib_tests/tst_needs_debugfs.c | 37 ++++++++++++++++++++++++++++ lib/tst_test.c | 35 ++++++++++++++++++++++++++ metadata/metaparse.c | 1 + 8 files changed, 90 insertions(+) create mode 100644 lib/newlib_tests/tst_needs_debugfs.c
doc/developers/writing_tests.rst +3 -0
@@ -440,6 +440,9 @@ LTP C And Shell Test API Comparison * - .needs_cmds - TST_NEEDS_CMDS + * - .needs_debugfs + - \- + * - .needs_devfs - \-
include/tst_fs.h +4 -0
@@ -8,6 +8,7 @@/* man 2 statfs or kernel-source/include/uapi/linux/magic.h */ #define TST_BTRFS_MAGIC 0x9123683E +#define TST_DEBUGFS_MAGIC 0x64626720#define TST_NFS_MAGIC 0x6969#define TST_RAMFS_MAGIC 0x858458f6#define TST_TMPFS_MAGIC 0x01021994
@@ -58,6 +59,9 @@ enum {#define OVL_WORK OVL_BASE_MNTPOINT"/work"#define OVL_MNT OVL_BASE_MNTPOINT"/ovl" +/* Where debugfs is mounted by the tst_test.needs_debugfs flag */ +#define TST_DEBUGFS_PATH "/sys/kernel/debug" +/* * @path: path is the pathname of any file within the mounted file system * @mult: mult should be TST_KB, TST_MB or TST_GB
include/tst_test.h +8 -0
@@ -358,6 +358,13 @@ struct tst_fs {* needed for tests that need to create device files since tmpfs * at /tmp is usually mounted with 'nodev' option. * +* @needs_debugfs: If set debugfs is mounted at TST_DEBUGFS_PATH i.e. +* /sys/kernel/debug, unless it is mounted there already, and +* the test exits with TCONF if it cannot be. The library +* unmounts it at the end of the test if it mounted it. Note +* that both mounting debugfs and reading its content require +* root, so tests using this also set tst_test.needs_root. +* * @restore_wallclock: Saves wall clock at the start of the test and restores * it at the end with the help of monotonic timers. * Testcases that modify system wallclock use this to
@@ -573,6 +580,7 @@ struct tst_fs { unsigned int child_needs_reinit:1; unsigned int runs_script:1; unsigned int needs_devfs:1; + unsigned int needs_debugfs:1; unsigned int restore_wallclock:1; unsigned int all_filesystems:1;
lib/newlib_tests/.gitignore +1 -0
@@ -60,6 +60,7 @@ tst_needs_cmds05 tst_needs_cmds06 tst_needs_cmds07 tst_needs_cmds08 +tst_needs_debugfs test_runtime01 test_runtime02 test_children_cleanup
lib/newlib_tests/runtest.sh +1 -0
@@ -27,6 +27,7 @@ tst_expiration_timer tst_filesystems01 tst_fuzzy_sync0[1-3] tst_needs_cmds0[1-36-8] +tst_needs_debugfs tst_res_hexd tst_safe_sscanf tst_strstatus}"
lib/newlib_tests/tst_needs_debugfs.c new file +37 -0
@@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Copyright (C) 2026 Piotr Kubaj <[email protected]> +*/ + +/* +* Test that tst_test.needs_debugfs gets debugfs mounted for the test. +* +* Run it both with debugfs mounted and with it unmounted, it has to pass either +* way. In the latter case the library reports mounting debugfs and has to leave +* it unmounted once the test is over. +*/ + +#include <sys/vfs.h> +#include "tst_test.h" + +static void run (void ) +{ +struct statfs sfs; + +SAFE_STATFS (TST_DEBUGFS_PATH , &sfs); + +if (sfs.f_type ==TST_DEBUGFS_MAGIC ) +tst_res (TPASS ,"debugfs is mounted at %s" ,TST_DEBUGFS_PATH ); +else +tst_res (TFAIL ,"debugfs is not mounted at %s" ,TST_DEBUGFS_PATH ); +} + +static struct tst_test test = { + .needs_root =1 , + .needs_debugfs =1 , + .needs_kconfigs = (const char *const []) { +"CONFIG_DEBUG_FS" , +NULL + }, + .test_all = run, +};
lib/tst_test.c +35 -0
@@ -15,6 +15,7 @@#include <errno.h> #include <sys/mount.h> #include <sys/types.h> +#include <sys/vfs.h> #include <sys/utsname.h> #include <sys/wait.h> #include <math.h>
@@ -82,6 +83,7 @@ struct context {tst_atomic_t abort_flag; uint32_t mntpoint_mounted:1; uint32_t ovl_mounted:1; + uint32_t debugfs_mounted:1;uint32_t tdebug; };
@@ -1210,6 +1212,31 @@ static void prepare_and_mount_dev_fs(const char *mntpoint) } } +static void mount_debugfs (void ) +{ +struct statfs sfs; + +/* +* TST_DEBUGFS_PATH exists as a plain sysfs directory whenever +* CONFIG_DEBUG_FS is enabled, whether or not debugfs is mounted on it, +* so the filesystem type has to be checked rather than the directory +* being present. +*/ +if (statfs (TST_DEBUGFS_PATH , &sfs)) +tst_brk (TCONF |TERRNO ,"Can't statfs %s" ,TST_DEBUGFS_PATH ); + +if (sfs.f_type ==TST_DEBUGFS_MAGIC ) +return ; + +if (mount ("debugfs" ,TST_DEBUGFS_PATH ,"debugfs" ,0 ,NULL )) { +tst_brk (TCONF |TERRNO ,"Can't mount debugfs at %s" , +TST_DEBUGFS_PATH ); + } + +tst_res (TINFO ,"Mounted debugfs at %s" ,TST_DEBUGFS_PATH ); + context->debugfs_mounted =1 ; +} +static void prepare_and_mount_hugetlb_fs (void ) {if (access (PATH_MM_HUGEPAGES ,F_OK ))
@@ -1546,6 +1573,9 @@ static void do_setup(int argc, char *argv[]) "Two or more of needs_{rofs, devfs, device, hugetlbfs} are set"); } +if (tst_test->needs_debugfs) +mount_debugfs (); +if (tst_test->needs_devfs)prepare_and_mount_dev_fs (tst_test->mntpoint);
@@ -1657,6 +1687,11 @@ static void do_cleanup(void)if (context->mntpoint_mounted)tst_umount (tst_test->mntpoint); +if (context->debugfs_mounted) { +tst_umount (TST_DEBUGFS_PATH ); + context->debugfs_mounted =0 ; + } +if (tst_test->needs_device && tdev.dev)tst_release_device (tdev.dev);
metadata/metaparse.c +1 -0
@@ -1169,6 +1169,7 @@ static struct typemap tst_test_typemap[] = { {.id = "child_needs_reinit", .type = DATA_BOOL}, {.id = "runs_script", .type = DATA_BOOL}, {.id = "needs_devfs", .type = DATA_BOOL}, + {.id = "needs_debugfs", .type = DATA_BOOL}, {.id = "restore_wallclock", .type = DATA_BOOL}, {.id = "all_filesystems", .type = DATA_BOOL}, {.id = "skip_in_lockdown", .type = DATA_BOOL},
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
PATCH v2 2/3 pmc_core: add test for pkgc_ltr_blocker_show
In reply to Piotr KubajAdd coverage for the pkgc_ltr_blocker_show debugfs file added in kernel commit 38c79dd63b72 ("platform/x86/intel/pmc: Enable PkgC LTR blocking counter") and first released in v7.2. The counters report how many times an LTR posted by each source blocked a package C-state entry, and so far nothing checked that the driver exports them correctly.
The counter set is platform specific, so instead of a hardcoded list of names the test samples the file twice and checks that it can be read in full, that every line is a PKGC_PREVENT_LTR_<SOURCE> token followed by exactly one value that fits in u32, that the counter set does not change between the reads, and that no counter advances by more entries than the package could have attempted over the interval.
The last check is the one that catches a telemetry region read at the wrong offset. The values wrap, so the advance is evaluated modulo 2^32 and bounded by the time the counter had to advance over, widened by how stale the first sample can be, because the PMC refreshes the telemetry region behind the counters asynchronously. An arbitrary u32 read out of the wrong offset overshoots that bound by orders of magnitude.
Tested on Nova Lake running 7.3.0-rc1.
--- runtest/power_management_tests | 1 + testcases/kernel/power_management/.gitignore | 1 + .../power_management/pkgc_ltr_blocker_show.c | 294 ++++++++++++++++++ 3 files changed, 296 insertions(+) create mode 100644 testcases/kernel/power_management/pkgc_ltr_blocker_show.c
runtest/power_management_tests +1 -0
@@ -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
testcases/kernel/power_management/.gitignore +1 -0
@@ -1,3 +1,4 @@ high_freq_hwp_cap_cppc cpufreq_intel rfim01 +pkgc_ltr_blocker_show
testcases/kernel/power_management/pkgc_ltr_blocker_show.c new file +294 -0
294 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
PATCH v2 3/3 pmc_core: add ltr_counter test
In reply to Piotr KubajAdd a test for 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 to be idle. A counter that keeps advancing with every CPU busy 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, and then pins a busy loop to every CPU it may run on and requires the counters to hold still.
The counters are backed by a PMT telemetry region that the PMC refreshes asynchronously and in bursts - roughly six seconds apart on Nova Lake - 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 surface in a later refresh, while a counter that is not tracking blocked entries never goes quiet at all and runs the window out.
Tested on Nova Lake running 7.3.0-rc1.
--- runtest/power_management_tests | 1 + testcases/kernel/power_management/.gitignore | 1 + .../kernel/power_management/ltr_counter.c | 358 ++++++++++++++++++ 3 files changed, 360 insertions(+) create mode 100644 testcases/kernel/power_management/ltr_counter.c
runtest/power_management_tests +1 -0
@@ -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
testcases/kernel/power_management/.gitignore +1 -0
@@ -2,3 +2,4 @@ high_freq_hwp_cap_cppc cpufreq_intel rfim01 pkgc_ltr_blocker_show +ltr_counter
testcases/kernel/power_management/ltr_counter.c new file +358 -0
358 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
Re: [LTP] [PATCH v2 3/3] pmc_core: add ltr_counter test
W dniu pon, 07.09.2026 o godzinie 14∶10 +0200, użytkownik Piotr Kubaj
Quoted 479 lines · napisał:
Add a test for the invariant behind the
pkgc_ltr_blocker_showcounters:
they only advance while a package C-state entry can be attempted, which
needs every CPU in the package to be idle. A counter that keeps advancing
with every CPU busy 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, and then pins a busy loop to every CPU it may run on and requires
the counters to hold still.The counters are backed by a PMT telemetry region that the PMC refreshes
asynchronously and in bursts - roughly six seconds apart on Nova Lake -
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 surface in a later refresh, while a counter that is not tracking blocked
entries never goes quiet at all and runs the window out.Tested on Nova Lake running 7.3.0-rc1.
Signed-off-by Piotr Kubaj <[email protected]>---
runtest/power_management_tests | 1 + testcases/kernel/power_management/.gitignore | 1 + .../kernel/power_management/ltr_counter.c | 358
++++++++++++++++++3 files changed, 360 insertions(+)create mode 100644
testcases/kernel/power_management/ltr_counter.cruntest/power_management_tests +0
-0@@ -3,6 +3,7 @@ cpufreq_intel cpufreq_intelrfim01 rfim01
high_freq_hwp_cap_cppchigh_freq_hwp_cap_cppc
pkgc_ltr_blocker_showpkgc_ltr_blocker_show
+ltr_counterltr_counter
runpwtests03runpwtests03.sh
runpwtests04runpwtests04.sh
runpwtests06runpwtests06.shtestcases/kernel/power_management/.gitignore +0
-0@@ -2,3 +2,4 @@ high_freq_hwp_cap_cppccpufreq_intel
rfim01
pkgc_ltr_blocker_showtestcases/kernel/power_management/.gitignore +1
-0+ltr_countertestcases/kernel/power_management/ltr_counter.c new file +8
-0@@ -0,0 +1,358 @@ +// 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.
+ *
+ * Thepkgc_ltr_blocker_showdebugfs 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.
+ *
+ * The counters are backed by a PMT telemetry region that the PMC refreshes
+ * asynchronously and in bursts - roughly six seconds apart on Nova Lake - 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 surface in a
+ * later refresh, 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/debugis 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.
+ */testcases/kernel/power_management/ltr_counter.c new file +21
-0+ +#define _GNU_SOURCE + +#include <sched.h> +#include <signal.h> +#include <time.h> +#include "tst_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" + +/* 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. The bursts
+ * are 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.
+ */testcases/kernel/power_management/ltr_counter.c new file +4
-0+#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. One burst period of silence is what tells a
+ * stopped counter from one that is merely between refreshes, and the cap has to
+ * be long enough on top of that for a burst counted before the load took hold
+ * to arrive and drain.
+ */testcases/kernel/power_management/ltr_counter.c new file +11
-0+#define QUIET_WINDOW 6 +#define LOAD_WINDOW 20 + +static char names[MAX_COUNTERS ][NAME_LEN ]; +static int cnt; +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
+ * sincesetup(). Only the values are of interest here - the format of the file
+ * is what thepkgc_ltr_blocker_showtest covers - so anything unexpected about
+ * the lines makes this test unable to run rather than failing it.
+ */testcases/kernel/power_management/ltr_counter.c new file +16
-0+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; + + line[strcspn (line,"\n" )] ='\0' ; + +if (n ==MAX_COUNTERS ) + tst_brk(TBROK, "more than %d countersreported",
MAX_COUNTERS);testcases/kernel/power_management/ltr_counter.c new file +3
-0+ +if (sscanf (line,"%63s %u" , name, &value) !=2 ) + tst_brk(TBROK, "unexpected line format:'%s'", line);
testcases/kernel/power_management/ltr_counter.c new file +5
-0+ + values[n] = value; + +if (cnt &&strcmp (name, names[n])) { + tst_brk(TBROK, "counter %d renamed duringthe test: %s -> %s",
testcases/kernel/power_management/ltr_counter.c new file +11
-0+ n, names[n], name); + } + +if (!cnt) +strcpy (names[n], name); + + n++; + } + +/* +* A telemetry read that fails in the driver aborts the
seq_filereadtestcases/kernel/power_management/ltr_counter.c new file +1
-0+* instead of ending it at EOF, so without this the counters lost to the
testcases/kernel/power_management/ltr_counter.c new file +4
-0+* error would look like counters that stopped advancing. +*/ +if (ferror (fp)) + tst_brk(TBROK, "reading " PATH " failed after %dcounters", n);
testcases/kernel/power_management/ltr_counter.c new file +5
-0+ +SAFE_FCLOSE (fp); + +if (cnt && n != cnt) + tst_brk(TBROK, "counter count changed during thetest: %d -> %d", cnt, n);
testcases/kernel/power_management/ltr_counter.c new file +13
-0+ + cnt = n; +} + +static void spin (void ) +{ +/* volatile so that the loop survives optimization */ +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.
+ *
+ * The spinners are pinned one per CPU taken from the test's own affinity mask,
+ * rather than left to the load balancer, so that a CPU is not left idle by a
+ * scheduling decision. Offline CPUs and a restricted mask are handled by
+ * construction.
+ */testcases/kernel/power_management/ltr_counter.c new file +7
-0+static void start_load (void ) +{ +cpu_set_t mask; +int cpu =0 ; + +if (sched_getaffinity (0 ,sizeof (mask), &mask)) + tst_brk(TBROK | TERRNO, "sched_getaffinity()failed");
testcases/kernel/power_management/ltr_counter.c new file +19
-0+ + nr_spinners =CPU_COUNT (&mask); + spinners =SAFE_MALLOC (nr_spinners *sizeof (*spinners)); + +for (int i =0 ; i < nr_spinners; 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); + +if (sched_setaffinity (0 ,sizeof (one), &one)){
testcases/kernel/power_management/ltr_counter.c new file +2
-0+ tst_brk(TBROK | TERRNO, + "sched_setaffinity(CPU %d)failed", cpu);
testcases/kernel/power_management/ltr_counter.c new file +28
-0+ } + +spin (); + } + + spinners[i] = 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 ; +} + +/* +* 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.
+ */testcases/kernel/power_management/ltr_counter.c new file +16
-0+static int wait_for_advance (const uint32_t *baseline) +{ +uint32_t values[MAX_COUNTERS ]; +struct timespec start, now; +int advanced =0 ; + +tst_clock_gettime (CLOCK_MONOTONIC , &start); + +for (;;) { +read_counters (values); + +for (int i =0 ; i < cnt; i++) { +if (values[i] == baseline[i]) +continue ; + + tst_res(TINFO, "%s advanced by %u whileidle", names[i],
testcases/kernel/power_management/ltr_counter.c new file +10
-0+ values[i] - baseline[i]); + advanced++; + } + +if (advanced) +return advanced; + +tst_clock_gettime (CLOCK_MONOTONIC , &now); + + if (tst_timespec_diff_ms(now, start) >= IDLE_WINDOW* 1000)
testcases/kernel/power_management/ltr_counter.c new file +8
-0+return 0 ; + +usleep (POLL_MS *1000 ); + } +} + +/* +* Require the counters to hold still for QUIET_WINDOW seconds of full load.
+ */testcases/kernel/power_management/ltr_counter.c new file +3
-0+static void check_counters_stop (void ) +{ + uint32_t first[MAX_COUNTERS], prev[MAX_COUNTERS],values[MAX_COUNTERS];
testcases/kernel/power_management/ltr_counter.c new file +26
-0+bool moved[MAX_COUNTERS ] = {}; +struct timespec start, last_change, now; + +read_counters (first); +memcpy (prev, first,sizeof (prev)); + +tst_clock_gettime (CLOCK_MONOTONIC , &start); + last_change = start; + +for (;;) { +usleep (POLL_MS *1000 ); + +read_counters (values); +tst_clock_gettime (CLOCK_MONOTONIC , &now); + +for (int i =0 ; i < cnt; i++) { +if (values[i] == prev[i]) +continue ; + + moved[i] = true; + last_change = now; + } + +memcpy (prev, values,sizeof (prev)); + + if (tst_timespec_diff_ms(now, last_change) >=
QUIET_WINDOW* 1000) {testcases/kernel/power_management/ltr_counter.c new file +2
-0+ tst_res(TPASS, + "%d counters held still over %dswith every CPU busy",
testcases/kernel/power_management/ltr_counter.c new file +5
-0+ cnt, QUIET_WINDOW); +return ; + } + + if (tst_timespec_diff_ms(now, start) < LOAD_WINDOW *1000)
testcases/kernel/power_management/ltr_counter.c new file +8
-0+continue ; + +for (int i =0 ; i < cnt; i++) { +if (!moved[i]) +continue ; + + tst_res(TFAIL, + "%s kept advancing over %ds withevery CPU busy: %u -> %u",
testcases/kernel/power_management/ltr_counter.c new file +1
-0+ names[i], LOAD_WINDOW, first[i],values[i]);
testcases/kernel/power_management/ltr_counter.c new file +14
-0+ } + +return ; + } +} + +static void setup (void ) +{ +uint32_t values[MAX_COUNTERS ]; + +if (access (PATH ,R_OK )) +tst_brk (TCONF |TERRNO ,"%s not available" ,PATH ); + +/* Learns the counter set the rest of the test compares against */
testcases/kernel/power_management/ltr_counter.c new file +19
-0+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
testcases/kernel/power_management/ltr_counter.c new file +5
-0+* 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 over%ds of idling",
testcases/kernel/power_management/ltr_counter.c new file +26
-0+ IDLE_WINDOW); + } + +start_load (); +check_counters_stop (); +stop_load (); +} + +static struct tst_test test = { + .min_kver ="7.2" , + .timeout =90 , + .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 + }, + .tags = (const struct tst_tag []) { + {"linux-git" ,"
38c79dd63b72e36919ef097d4e5025ca0fa17f34"},
testcases/kernel/power_management/ltr_counter.c line 358
Quoted 6 lines
testcases/kernel/power_management/ltr_counter.c new file +6
-0+ {} + }, + .setup = setup, + .cleanup = cleanup, + .test_all = run +};
Hi,
the CI results on this series seem to fail from a partial download, not because of a broken patch.
Every job, github-build-doc and all 16 github-build-* containers, stopped in the "Apply Patchwork series" step:
100 3821 100 3821 0 0 17666 0
hint: When you have resolved this problem, run "git am --continue". Patch is empty.
##[error]Process completed with exit code 128.
curl received a complete 3821 byte body for
https://patchwork.kernel.org/series/1159727/mbox/, while that mbox is 44397 bytes, so patchwork answered with an HTML page instead of the series and git am rejected it as an empty patch.
The download works again now and the series applies to current master
with no conflicts, so re-dispatching series 1159727 should be enough.
Could someone re-trigger it? I am happy to resend as v3 instead if that
is easier.
---------------------------------------------------------------------
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.
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp