Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7559E606A32D for ; Mon, 30 Nov 2026 11:59:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=QvS/7rx0 Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id CC2A33E908B for ; Mon, 30 Nov 2026 12:59:47 +0100 (CET) Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id CFA393CE1E7 for ; Mon, 30 Nov 2026 12:59:31 +0100 (CET) Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id 8D9DD1400B85 for ; Mon, 30 Nov 2026 12:59:30 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796039971; x=1827575971; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mPyRYbHnaKYD8B5NWQfSvF3IKasvpSxhybCix9omoX0=; b=QvS/7rx0vss3CNDS1/2h43UkXWO0ka37XFrnT9ydeGblPi3or0gEOQBw uidtfHrJTFa9ZhZ9noWbVijLrZxhsey+bh/Q0zOWinTq8WwXx124+PhG9 FXr8ofvLQw6YL/h0BjHdqWVtA95IiXP0jMJHXIeJRFmFGGAmg4PqkFsOH gPR4D7WWWBba6ehPcX3IME1MqeswKAxXy9LoLDYn5WAC0qpP1geuYrm4M p5x/KV18QVPnTrY1LYWqDu68Gn3+ao2Ss/hceF3P+DyP/ELW1vh3+WOZ5 NIFmDjf4S6UMP7DoHzG7nuT1Weuw7BoPUy79BBrme40WF/A1gB5Ov4/VJ w==; X-CSE-ConnectionGUID: LbOqs2D2SFer5/yCmrcAZQ== X-CSE-MsgGUID: ZVWM4lSMRbm/Zuy+aXQ0Wg== X-IronPort-AV: E=McAfee;i="6800,10657,11982"; a="4757537" X-IronPort-AV: E=Sophos;i="6.27,242,1787036400"; d="scan'208";a="4757537" Received: from orviesa004.jf.intel.com ([10.64.159.144]) by fmvoesa104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2026 03:59:24 -0800 X-CSE-ConnectionGUID: VFV6dzTeRlu7JxDChmuBaw== X-CSE-MsgGUID: 3RUq6cCqQeyhKCnC396ZiA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,242,1787036400"; d="scan'208";a="12790174" Received: from pkubaj-mobl.igk.intel.com (HELO intel.com) ([10.237.142.91]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2026 03:59:22 -0800 From: Piotr Kubaj To: ltp@lists.linux.it Date: Mon, 30 Nov 2026 12:58:59 +0100 Message-ID: <20261130115901.32486-2-piotr.kubaj@intel.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261130115901.32486-1-piotr.kubaj@intel.com> References: <20261130115901.32486-1-piotr.kubaj@intel.com> X-Archived-By: MIME-Version: 1.0 X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_PASS,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Virus-Scanned: clamav-milter 1.0.9 at in-6.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v6 1/3] pmc_core: add test for pkgc_ltr_blocker_show X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Archive: List-Post: List-Help: List-Subscribe: , Cc: helena.anna.dubel@intel.com, tomasz.ossowski@intel.com, rafael.j.wysocki@intel.com, "Claude Fable 5.2" , daniel.niestepski@intel.com Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "ltp" 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_ 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 Co-Authored-By: Claude Fable 5.2 --- 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 + */ + +/*\ + * 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_ token and the value counts how + * many times an LTR posted by 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_ 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 +#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 " 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