All of lore.kernel.org
 help / color / mirror / Atom feed
From: Len Brown <lenb@kernel.org>
To: linux-pm@vger.kernel.org
Cc: Patryk Wlazlyn <patryk.wlazlyn@linux.intel.com>,
	Len Brown <len.brown@intel.com>
Subject: [PATCH 24/25] tools/power turbostat: Add CPU%c1e BIC for CWF
Date: Sun,  2 Feb 2025 11:09:40 -0600	[thread overview]
Message-ID: <5ce1e9bbb2a1d43cf9e613cb03e65ecdfd309fe9.1738515889.git.len.brown@intel.com> (raw)
In-Reply-To: <e8a99af68c068865dbac7f3330e97bf8e96edf33.1738515889.git.len.brown@intel.com>

From: Patryk Wlazlyn <patryk.wlazlyn@linux.intel.com>

Intel Clearwater Forest report PMT telemetry with GUID 0x14421519, which
can be used to obtain module c1e residency counter of type tcore clock.

Add early support for the counter by using heuristic that should work
for the Clearwater Forest platforms.

Signed-off-by: Patryk Wlazlyn <patryk.wlazlyn@linux.intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>
---
 tools/power/x86/turbostat/turbostat.c | 68 +++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)

diff --git a/tools/power/x86/turbostat/turbostat.c b/tools/power/x86/turbostat/turbostat.c
index 8df08819e7b4..364a44a7d7ae 100644
--- a/tools/power/x86/turbostat/turbostat.c
+++ b/tools/power/x86/turbostat/turbostat.c
@@ -205,6 +205,7 @@ struct msr_counter bic[] = {
 	{ 0x0, "SysWatt", NULL, 0, 0, 0, NULL, 0 },
 	{ 0x0, "Sys_J", NULL, 0, 0, 0, NULL, 0 },
 	{ 0x0, "NMI", NULL, 0, 0, 0, NULL, 0 },
+	{ 0x0, "CPU%c1e", NULL, 0, 0, 0, NULL, 0 },
 };
 
 #define MAX_BIC (sizeof(bic) / sizeof(struct msr_counter))
@@ -270,6 +271,7 @@ struct msr_counter bic[] = {
 #define	BIC_SysWatt		(1ULL << 59)
 #define	BIC_Sys_J		(1ULL << 60)
 #define	BIC_NMI			(1ULL << 61)
+#define	BIC_CPU_c1e		(1ULL << 62)
 
 #define BIC_TOPOLOGY (BIC_Package | BIC_Node | BIC_CoreCnt | BIC_PkgCnt | BIC_Core | BIC_CPU | BIC_Die)
 #define BIC_THERMAL_PWR (BIC_CoreTmp | BIC_PkgTmp | BIC_PkgWatt | BIC_CorWatt | BIC_GFXWatt | BIC_RAMWatt | BIC_PKG__ | BIC_RAM__ | BIC_SysWatt)
@@ -1538,6 +1540,14 @@ static struct msr_counter_arch_info msr_counter_arch_infos[] = {
 #define PMT_MTL_DC6_GUID           0x1a067102
 #define PMT_MTL_DC6_SEQ            0
 
+#define PMT_COUNTER_CWF_MC1E_OFFSET_BASE          20936
+#define PMT_COUNTER_CWF_MC1E_OFFSET_INCREMENT     24
+#define PMT_COUNTER_CWF_MC1E_NUM_MODULES_PER_FILE 12
+#define PMT_COUNTER_CWF_CPUS_PER_MODULE           4
+#define PMT_COUNTER_CWF_MC1E_LSB                  0
+#define PMT_COUNTER_CWF_MC1E_MSB                  63
+#define PMT_CWF_MC1E_GUID                         0x14421519
+
 unsigned long long tcore_clock_freq_hz = 800000000;
 
 #define PMT_COUNTER_NAME_SIZE_BYTES      16
@@ -9367,11 +9377,69 @@ int pmt_add_counter(unsigned int guid, unsigned int seq, const char *name, enum
 
 void pmt_init(void)
 {
+	int cpu_num;
+	unsigned long seq, offset, mod_num;
+
 	if (BIC_IS_ENABLED(BIC_Diec6)) {
 		pmt_add_counter(PMT_MTL_DC6_GUID, PMT_MTL_DC6_SEQ, "Die%c6", PMT_TYPE_XTAL_TIME,
 				PMT_COUNTER_MTL_DC6_LSB, PMT_COUNTER_MTL_DC6_MSB, PMT_COUNTER_MTL_DC6_OFFSET,
 				SCOPE_PACKAGE, FORMAT_DELTA, 0, PMT_OPEN_TRY);
 	}
+
+	if (BIC_IS_ENABLED(BIC_CPU_c1e)) {
+		seq = 0;
+		offset = PMT_COUNTER_CWF_MC1E_OFFSET_BASE;
+		mod_num = 0;	/* Relative module number for current PMT file. */
+
+		/* Open the counter for each CPU. */
+		for (cpu_num = 0; cpu_num < topo.max_cpu_num;) {
+
+			if (cpu_is_not_allowed(cpu_num))
+				goto next_loop_iter;
+
+			/*
+			 * Set the scope to CPU, even though CWF report the counter per module.
+			 * CPUs inside the same module will read from the same location, instead of reporting zeros.
+			 *
+			 * CWF with newer firmware might require a PMT_TYPE_XTAL_TIME intead of PMT_TYPE_TCORE_CLOCK.
+			 */
+			pmt_add_counter(PMT_CWF_MC1E_GUID, seq, "CPU%c1e", PMT_TYPE_TCORE_CLOCK,
+					PMT_COUNTER_CWF_MC1E_LSB, PMT_COUNTER_CWF_MC1E_MSB, offset, SCOPE_CPU,
+					FORMAT_DELTA, cpu_num, PMT_OPEN_TRY);
+
+			/*
+			 * Rather complex logic for each time we go to the next loop iteration,
+			 * so keep it as a label.
+			 */
+next_loop_iter:
+			/*
+			 * Advance the cpu number and check if we should also advance offset to
+			 * the next counter inside the PMT file.
+			 *
+			 * On Clearwater Forest platform, the counter is reported per module,
+			 * so open the same counter for all of the CPUs inside the module.
+			 * That way, reported table show the correct value for all of the CPUs inside the module,
+			 * instead of zeros.
+			 */
+			++cpu_num;
+			if (cpu_num % PMT_COUNTER_CWF_CPUS_PER_MODULE == 0) {
+				offset += PMT_COUNTER_CWF_MC1E_OFFSET_INCREMENT;
+				++mod_num;
+			}
+
+			/*
+			 * There are PMT_COUNTER_CWF_MC1E_NUM_MODULES_PER_FILE in each PMT file.
+			 *
+			 * If that number is reached, seq must be incremented to advance to the next file in a sequence.
+			 * Offset inside that file and a module counter has to be reset.
+			 */
+			if (mod_num == PMT_COUNTER_CWF_MC1E_NUM_MODULES_PER_FILE) {
+				++seq;
+				offset = PMT_COUNTER_CWF_MC1E_OFFSET_BASE;
+				mod_num = 0;
+			}
+		}
+	}
 }
 
 void turbostat_init()
-- 
2.43.0


  parent reply	other threads:[~2025-02-02 17:13 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-02 17:09 [PATCH 0/25] turbostat-2025.0202 for linux-6.14 Len Brown
2025-02-02 17:09 ` [PATCH 01/25] tools/power turbostat: Add initial support for PantherLake Len Brown
2025-02-02 17:09   ` [PATCH 02/25] tools/power turbostat: Add initial support for ClearwaterForest Len Brown
2025-02-02 17:09   ` [PATCH 03/25] tools/power turbostat: update turbostat(8) Len Brown
2025-02-02 17:09   ` [PATCH 04/25] tools/power turbostat: Exit on unsupported Intel models Len Brown
2025-02-02 17:09   ` [PATCH 05/25] tools/power turbostat: Exit on unsupported Vendors Len Brown
2025-02-02 17:09   ` [PATCH 06/25] tools/power turbostat: Improve --help output Len Brown
2025-02-02 17:09   ` [PATCH 07/25] tools/power turbostat: Introduce --force parameter Len Brown
2025-02-02 17:09   ` [PATCH 08/25] tools/power turbostat: add Busy% to "show idle" Len Brown
2025-02-02 17:09   ` [PATCH 09/25] tools/power turbostat: Add an NMI column Len Brown
2025-02-02 17:09   ` [PATCH 10/25] tools/power turbostat: Remove SysWatt from DISABLED_BY_DEFAULT Len Brown
2025-02-02 17:09   ` [PATCH 11/25] tools/power turbostat: Fix PMT mmaped file size rounding Len Brown
2025-02-02 17:09   ` [PATCH 12/25] tools/power turbostat: Add fixed RAPL PSYS divisor for SPR Len Brown
2025-02-02 17:09   ` [PATCH 13/25] tools/power turbostat: Enhance turbostat self-performance visibility Len Brown
2025-02-02 17:09   ` [PATCH 14/25] tools/power turbostat: Check for non-zero value when MSR probing Len Brown
2025-02-02 17:09   ` [PATCH 15/25] tools/power turbostat: Return default value for unmapped PMT domains Len Brown
2025-02-02 17:09   ` [PATCH 16/25] tools/power turbostat: Extend PMT identification with a sequence number Len Brown
2025-02-02 17:09   ` [PATCH 17/25] tools/power turbostat: Add PMT directory iterator helper Len Brown
2025-02-02 17:09   ` [PATCH 18/25] tools/power turbostat: Allow mapping multiple PMT files with the same GUID Len Brown
2025-02-02 17:09   ` [PATCH 19/25] tools/power turbostat: Allow adding PMT counters directly by sysfs path Len Brown
2025-02-02 17:09   ` [PATCH 20/25] tools/power turbostat: version 2025.01.14 Len Brown
2025-02-02 17:09   ` [PATCH 21/25] tools/power turbostat: Add tcore clock PMT type Len Brown
2025-02-02 17:09   ` [PATCH 22/25] tools/power turbostat: Fix forked child affinity regression Len Brown
2025-02-02 17:09   ` [PATCH 23/25] tools/power turbostat: Harden one-shot mode against cpu offline Len Brown
2025-02-02 17:09   ` Len Brown [this message]
2025-02-02 17:09   ` [PATCH 25/25] tools/power turbostat: version 2025.02.02 Len Brown

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=5ce1e9bbb2a1d43cf9e613cb03e65ecdfd309fe9.1738515889.git.len.brown@intel.com \
    --to=lenb@kernel.org \
    --cc=len.brown@intel.com \
    --cc=linux-pm@vger.kernel.org \
    --cc=patryk.wlazlyn@linux.intel.com \
    /path/to/YOUR_REPLY

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

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is 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.