All of lore.kernel.org
 help / color / mirror / Atom feed
From: kan.liang@linux.intel.com
To: peterz@infradead.org, mingo@redhat.com, acme@kernel.org,
	linux-kernel@vger.kernel.org
Cc: ak@linux.intel.com, eranian@google.com, irogers@google.com,
	Kan Liang <kan.liang@linux.intel.com>
Subject: [PATCH V2 5/9] perf/x86/intel: Support Architectural PerfMon Extension leaf
Date: Wed,  4 Jan 2023 12:13:45 -0800	[thread overview]
Message-ID: <20230104201349.1451191-5-kan.liang@linux.intel.com> (raw)
In-Reply-To: <20230104201349.1451191-1-kan.liang@linux.intel.com>

From: Kan Liang <kan.liang@linux.intel.com>

The new CPUID leaf 0x23 reports the "true view" of PMU resources.

The sub-leaf 1 reports the available general-purpose counters and fixed
counters. Update the number of counters and fixed counters when the
sub-leaf is detected.

Signed-off-by: Kan Liang <kan.liang@linux.intel.com>
---

No change since V1

 arch/x86/events/intel/core.c      | 22 ++++++++++++++++++++++
 arch/x86/include/asm/perf_event.h |  8 ++++++++
 2 files changed, 30 insertions(+)

diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index a5678ab6d3e3..29d2d0411caf 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -4588,6 +4588,25 @@ static void flip_smm_bit(void *data)
 	}
 }
 
+static void intel_pmu_check_num_counters(int *num_counters,
+					 int *num_counters_fixed,
+					 u64 *intel_ctrl, u64 fixed_mask);
+
+static void update_pmu_cap(struct x86_hybrid_pmu *pmu)
+{
+	unsigned int sub_bitmaps = cpuid_eax(ARCH_PERFMON_EXT_LEAF);
+	unsigned int eax, ebx, ecx, edx;
+
+	if (sub_bitmaps & ARCH_PERFMON_NUM_COUNTER_LEAF_BIT) {
+		cpuid_count(ARCH_PERFMON_EXT_LEAF, ARCH_PERFMON_NUM_COUNTER_LEAF,
+			    &eax, &ebx, &ecx, &edx);
+		pmu->num_counters = fls(eax);
+		pmu->num_counters_fixed = fls(ebx);
+		intel_pmu_check_num_counters(&pmu->num_counters, &pmu->num_counters_fixed,
+					     &pmu->intel_ctrl, ebx);
+	}
+}
+
 static bool init_hybrid_pmu(int cpu)
 {
 	struct cpu_hw_events *cpuc = &per_cpu(cpu_hw_events, cpu);
@@ -4613,6 +4632,9 @@ static bool init_hybrid_pmu(int cpu)
 	if (!cpumask_empty(&pmu->supported_cpus))
 		goto end;
 
+	if (this_cpu_has(X86_FEATURE_ARCH_PERFMON_EXT))
+		update_pmu_cap(pmu);
+
 	if (!check_hw_exists(&pmu->pmu, pmu->num_counters, pmu->num_counters_fixed))
 		return false;
 
diff --git a/arch/x86/include/asm/perf_event.h b/arch/x86/include/asm/perf_event.h
index 5d0f6891ae61..6496bdbcac98 100644
--- a/arch/x86/include/asm/perf_event.h
+++ b/arch/x86/include/asm/perf_event.h
@@ -159,6 +159,14 @@ union cpuid10_edx {
 	unsigned int full;
 };
 
+/*
+ * Intel "Architectural Performance Monitoring extension" CPUID
+ * detection/enumeration details:
+ */
+#define ARCH_PERFMON_EXT_LEAF			0x00000023
+#define ARCH_PERFMON_NUM_COUNTER_LEAF_BIT	0x1
+#define ARCH_PERFMON_NUM_COUNTER_LEAF		0x1
+
 /*
  * Intel Architectural LBR CPUID detection/enumeration details:
  */
-- 
2.35.1


  parent reply	other threads:[~2023-01-04 20:14 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-04 20:13 [PATCH V2 1/9] perf: Add PMU_FORMAT_ATTR_SHOW kan.liang
2023-01-04 20:13 ` [PATCH V2 2/9] perf/x86: Add Meteor Lake support kan.liang
2023-01-09 17:02   ` [tip: perf/core] " tip-bot2 for Kan Liang
2023-01-04 20:13 ` [PATCH V2 3/9] perf/x86: Support Retire Latency kan.liang
2023-01-09 17:02   ` [tip: perf/core] " tip-bot2 for Kan Liang
2023-01-04 20:13 ` [PATCH V2 4/9] x86/cpufeatures: Add Architectural PerfMon Extension bit kan.liang
2023-01-09 17:02   ` [tip: perf/core] " tip-bot2 for Kan Liang
2023-01-04 20:13 ` kan.liang [this message]
2023-01-09 17:02   ` [tip: perf/core] perf/x86/intel: Support Architectural PerfMon Extension leaf tip-bot2 for Kan Liang
2023-01-04 20:13 ` [PATCH V2 6/9] perf/x86/cstate: Add Meteor Lake support kan.liang
2023-01-09 11:15   ` [tip: perf/urgent] " tip-bot2 for Kan Liang
2023-01-09 17:02   ` [tip: perf/core] " tip-bot2 for Kan Liang
2023-01-04 20:13 ` [PATCH V2 7/9] perf/x86/msr: " kan.liang
2023-01-09 11:15   ` [tip: perf/urgent] " tip-bot2 for Kan Liang
2023-01-09 17:02   ` [tip: perf/core] " tip-bot2 for Kan Liang
2023-02-02  1:47   ` [PATCH V2 7/9] " Arnaldo Carvalho de Melo
2023-02-02 14:34     ` Liang, Kan
2023-02-02 14:45       ` Arnaldo Carvalho de Melo
2023-02-03 20:21       ` Arnaldo Carvalho de Melo
2023-02-03 20:28         ` Arnaldo Carvalho de Melo
2023-02-06 14:32           ` Liang, Kan
2023-02-06 14:51             ` Arnaldo Carvalho de Melo
2023-01-04 20:13 ` [PATCH V2 8/9] perf report: Support Retire Latency kan.liang
2023-01-04 20:13 ` [PATCH V2 9/9] perf script: " kan.liang
2023-01-09 17:02 ` [tip: perf/core] perf: Add PMU_FORMAT_ATTR_SHOW tip-bot2 for Kan Liang

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=20230104201349.1451191-5-kan.liang@linux.intel.com \
    --to=kan.liang@linux.intel.com \
    --cc=acme@kernel.org \
    --cc=ak@linux.intel.com \
    --cc=eranian@google.com \
    --cc=irogers@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    /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.