[PATCH v7 28/31] x86/resctrl: Enable RDT_RESOURCE_PERF_PKG

Tony Luck posted 31 patches 2 months, 3 weeks ago
There is a newer version of this series
[PATCH v7 28/31] x86/resctrl: Enable RDT_RESOURCE_PERF_PKG
Posted by Tony Luck 2 months, 3 weeks ago
The RDT_RESOURCE_PERF_PKG resource is not marked as "mon_capable" during
early resctrl initialization. This means that the domain lists for the
resource are not built when the CPU hot plug notifiers are registered.

Mark the resource as mon_capable and call domain_add_cpu_mon() for
each online CPU to build the domain lists in the first call to the
resctrl_arch_pre_mount() hook.

Signed-off-by: Tony Luck <tony.luck@intel.com>
---
 arch/x86/kernel/cpu/resctrl/core.c      | 14 +++++++++++++-
 arch/x86/kernel/cpu/resctrl/intel_aet.c |  3 +++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c
index 1a6635cc5b37..1d07c38ed528 100644
--- a/arch/x86/kernel/cpu/resctrl/core.c
+++ b/arch/x86/kernel/cpu/resctrl/core.c
@@ -774,14 +774,26 @@ static int resctrl_arch_offline_cpu(unsigned int cpu)
 
 void resctrl_arch_pre_mount(void)
 {
+	struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_PERF_PKG].r_resctrl;
 	static atomic_t only_once = ATOMIC_INIT(0);
-	int old = 0;
+	int cpu, old = 0;
 
 	if (!atomic_try_cmpxchg(&only_once, &old, 1))
 		return;
 
 	if (!intel_aet_get_events())
 		return;
+
+	/*
+	 * Late discovery of telemetry events means the domains for the
+	 * resource were not built. Do that now.
+	 */
+	cpus_read_lock();
+	mutex_lock(&domain_list_lock);
+	for_each_online_cpu(cpu)
+		domain_add_cpu_mon(cpu, r);
+	mutex_unlock(&domain_list_lock);
+	cpus_read_unlock();
 }
 
 enum {
diff --git a/arch/x86/kernel/cpu/resctrl/intel_aet.c b/arch/x86/kernel/cpu/resctrl/intel_aet.c
index 6958efbf7e81..ea7a782c1661 100644
--- a/arch/x86/kernel/cpu/resctrl/intel_aet.c
+++ b/arch/x86/kernel/cpu/resctrl/intel_aet.c
@@ -264,6 +264,9 @@ static int discover_events(struct event_group *e, struct pmt_feature_group *p)
 	else
 		r->num_rmid = e->num_rmids;
 
+	pr_info("%s %s monitoring detected\n", r->name, e->name);
+	r->mon_capable = true;
+
 	return 0;
 }
 
-- 
2.50.0
Re: [PATCH v7 28/31] x86/resctrl: Enable RDT_RESOURCE_PERF_PKG
Posted by Reinette Chatre 2 months, 1 week ago
Hi Tony,

On 7/11/25 4:53 PM, Tony Luck wrote:
> diff --git a/arch/x86/kernel/cpu/resctrl/core.c b/arch/x86/kernel/cpu/resctrl/core.c
> index 1a6635cc5b37..1d07c38ed528 100644
> --- a/arch/x86/kernel/cpu/resctrl/core.c
> +++ b/arch/x86/kernel/cpu/resctrl/core.c
> @@ -774,14 +774,26 @@ static int resctrl_arch_offline_cpu(unsigned int cpu)
>  
>  void resctrl_arch_pre_mount(void)
>  {
> +	struct rdt_resource *r = &rdt_resources_all[RDT_RESOURCE_PERF_PKG].r_resctrl;
>  	static atomic_t only_once = ATOMIC_INIT(0);
> -	int old = 0;
> +	int cpu, old = 0;
>  
>  	if (!atomic_try_cmpxchg(&only_once, &old, 1))
>  		return;
>  
>  	if (!intel_aet_get_events())
>  		return;
> +
> +	/*
> +	 * Late discovery of telemetry events means the domains for the
> +	 * resource were not built. Do that now.
> +	 */
> +	cpus_read_lock();
> +	mutex_lock(&domain_list_lock);
> +	for_each_online_cpu(cpu)
> +		domain_add_cpu_mon(cpu, r);

Without an explicit "mon_capable" check this change now creates a new "contract" that
"if intel_aet_get_events() succeeds then PERF_PKG is mon_capable". I do not believe this
additional complication justifies saving a line of code.

> +	mutex_unlock(&domain_list_lock);
> +	cpus_read_unlock();
>  }
>  
>  enum {
> diff --git a/arch/x86/kernel/cpu/resctrl/intel_aet.c b/arch/x86/kernel/cpu/resctrl/intel_aet.c
> index 6958efbf7e81..ea7a782c1661 100644
> --- a/arch/x86/kernel/cpu/resctrl/intel_aet.c
> +++ b/arch/x86/kernel/cpu/resctrl/intel_aet.c
> @@ -264,6 +264,9 @@ static int discover_events(struct event_group *e, struct pmt_feature_group *p)
>  	else
>  		r->num_rmid = e->num_rmids;
>  
> +	pr_info("%s %s monitoring detected\n", r->name, e->name);
> +	r->mon_capable = true;
> +
>  	return 0;
>  }
>  

Reinette