* [PATCH 0/2] topology/sysfs, cpufreq/intel_pstate: Populate cpu_capacity
@ 2025-04-19 2:55 Ricardo Neri
2025-04-19 2:55 ` [PATCH 1/2] arch_topology: Relocate cpu_scale to topology.[h|c] Ricardo Neri
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Ricardo Neri @ 2025-04-19 2:55 UTC (permalink / raw)
To: Sudeep Holla, Rafael J. Wysocki, Danilo Krummrich,
Srinivas Pandruvada, Len Brown
Cc: linux-kernel, linux-pm, Ricardo Neri, Ricardo Neri
Hi,
Capacity-aware scheduling is now supported on Intel hybrid processors. It
makes sense now to populate the interface /sys/devices/system/cpu/cpuN/
cpu_capacity. User space entities can use this information to implement
policy such as utilization clamps.
This interface currently lives in arch_topology.c. Rather than implementing
the interface again for x86, we can move it to a common location in
topology.c from which other architectures can also benefit and populate
using their own mechanisms.
I tested this patchset on Intel Alder Lake and DragonBoard 845c. The
interfaces are populated correctly.
I'd appreciate any feedback!
Thanks and BR,
Ricardo
Ricardo Neri (2):
arch_topology: Relocate cpu_scale to topology.[h|c]
cpufreq: intel_pstate: Populate the cpu_capacity sysfs entries
drivers/base/arch_topology.c | 52 ----------------------------------
drivers/base/topology.c | 52 ++++++++++++++++++++++++++++++++++
drivers/cpufreq/intel_pstate.c | 2 ++
include/linux/arch_topology.h | 8 ------
include/linux/topology.h | 9 ++++++
5 files changed, 63 insertions(+), 60 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] arch_topology: Relocate cpu_scale to topology.[h|c]
2025-04-19 2:55 [PATCH 0/2] topology/sysfs, cpufreq/intel_pstate: Populate cpu_capacity Ricardo Neri
@ 2025-04-19 2:55 ` Ricardo Neri
2025-04-25 16:31 ` Christian Loehle
2025-04-19 2:55 ` [PATCH 2/2] cpufreq: intel_pstate: Populate the cpu_capacity sysfs entries Ricardo Neri
2025-05-07 20:00 ` [PATCH 0/2] topology/sysfs, cpufreq/intel_pstate: Populate cpu_capacity Rafael J. Wysocki
2 siblings, 1 reply; 6+ messages in thread
From: Ricardo Neri @ 2025-04-19 2:55 UTC (permalink / raw)
To: Sudeep Holla, Rafael J. Wysocki, Danilo Krummrich,
Srinivas Pandruvada, Len Brown
Cc: linux-kernel, linux-pm, Ricardo Neri, Ricardo Neri
arch_topology.c provides functionality to parse and scale CPU capacity. It
also provides a corresponding sysfs interface. Some architectures parse
and scale CPU capacity differently as per their own needs. On Intel
processors, for instance, it is responsibility of the Intel P-state driver.
Relocate the implementation of that interface to a common location in
topology.c. Architectures can use the interface and populate it using their
own mechanisms.
An alternative approach would be to compile arch_topology.c even if not
needed only to get this interface. This approach would create duplicated
and conflicting functionality and data structures.
Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
---
drivers/base/arch_topology.c | 52 -----------------------------------
drivers/base/topology.c | 52 +++++++++++++++++++++++++++++++++++
include/linux/arch_topology.h | 8 ------
include/linux/topology.h | 9 ++++++
4 files changed, 61 insertions(+), 60 deletions(-)
diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c
index af0029d30dbe..1037169abb45 100644
--- a/drivers/base/arch_topology.c
+++ b/drivers/base/arch_topology.c
@@ -154,14 +154,6 @@ void topology_set_freq_scale(const struct cpumask *cpus, unsigned long cur_freq,
per_cpu(arch_freq_scale, i) = scale;
}
-DEFINE_PER_CPU(unsigned long, cpu_scale) = SCHED_CAPACITY_SCALE;
-EXPORT_PER_CPU_SYMBOL_GPL(cpu_scale);
-
-void topology_set_cpu_scale(unsigned int cpu, unsigned long capacity)
-{
- per_cpu(cpu_scale, cpu) = capacity;
-}
-
DEFINE_PER_CPU(unsigned long, hw_pressure);
/**
@@ -207,53 +199,9 @@ void topology_update_hw_pressure(const struct cpumask *cpus,
}
EXPORT_SYMBOL_GPL(topology_update_hw_pressure);
-static ssize_t cpu_capacity_show(struct device *dev,
- struct device_attribute *attr,
- char *buf)
-{
- struct cpu *cpu = container_of(dev, struct cpu, dev);
-
- return sysfs_emit(buf, "%lu\n", topology_get_cpu_scale(cpu->dev.id));
-}
-
static void update_topology_flags_workfn(struct work_struct *work);
static DECLARE_WORK(update_topology_flags_work, update_topology_flags_workfn);
-static DEVICE_ATTR_RO(cpu_capacity);
-
-static int cpu_capacity_sysctl_add(unsigned int cpu)
-{
- struct device *cpu_dev = get_cpu_device(cpu);
-
- if (!cpu_dev)
- return -ENOENT;
-
- device_create_file(cpu_dev, &dev_attr_cpu_capacity);
-
- return 0;
-}
-
-static int cpu_capacity_sysctl_remove(unsigned int cpu)
-{
- struct device *cpu_dev = get_cpu_device(cpu);
-
- if (!cpu_dev)
- return -ENOENT;
-
- device_remove_file(cpu_dev, &dev_attr_cpu_capacity);
-
- return 0;
-}
-
-static int register_cpu_capacity_sysctl(void)
-{
- cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "topology/cpu-capacity",
- cpu_capacity_sysctl_add, cpu_capacity_sysctl_remove);
-
- return 0;
-}
-subsys_initcall(register_cpu_capacity_sysctl);
-
static int update_topology;
int topology_update_cpu_topology(void)
diff --git a/drivers/base/topology.c b/drivers/base/topology.c
index b962da263eee..8b42df05feff 100644
--- a/drivers/base/topology.c
+++ b/drivers/base/topology.c
@@ -208,3 +208,55 @@ static int __init topology_sysfs_init(void)
}
device_initcall(topology_sysfs_init);
+
+DEFINE_PER_CPU(unsigned long, cpu_scale) = SCHED_CAPACITY_SCALE;
+EXPORT_PER_CPU_SYMBOL_GPL(cpu_scale);
+
+void topology_set_cpu_scale(unsigned int cpu, unsigned long capacity)
+{
+ per_cpu(cpu_scale, cpu) = capacity;
+}
+
+static ssize_t cpu_capacity_show(struct device *dev,
+ struct device_attribute *attr,
+ char *buf)
+{
+ struct cpu *cpu = container_of(dev, struct cpu, dev);
+
+ return sysfs_emit(buf, "%lu\n", topology_get_cpu_scale(cpu->dev.id));
+}
+
+static DEVICE_ATTR_RO(cpu_capacity);
+
+static int cpu_capacity_sysctl_add(unsigned int cpu)
+{
+ struct device *cpu_dev = get_cpu_device(cpu);
+
+ if (!cpu_dev)
+ return -ENOENT;
+
+ device_create_file(cpu_dev, &dev_attr_cpu_capacity);
+
+ return 0;
+}
+
+static int cpu_capacity_sysctl_remove(unsigned int cpu)
+{
+ struct device *cpu_dev = get_cpu_device(cpu);
+
+ if (!cpu_dev)
+ return -ENOENT;
+
+ device_remove_file(cpu_dev, &dev_attr_cpu_capacity);
+
+ return 0;
+}
+
+static int register_cpu_capacity_sysctl(void)
+{
+ cpuhp_setup_state(CPUHP_AP_ONLINE_DYN, "topology/cpu-capacity",
+ cpu_capacity_sysctl_add, cpu_capacity_sysctl_remove);
+
+ return 0;
+}
+subsys_initcall(register_cpu_capacity_sysctl);
diff --git a/include/linux/arch_topology.h b/include/linux/arch_topology.h
index 2222e8b03ff4..d72d6e5aa200 100644
--- a/include/linux/arch_topology.h
+++ b/include/linux/arch_topology.h
@@ -14,14 +14,6 @@ int topology_update_cpu_topology(void);
struct device_node;
bool topology_parse_cpu_capacity(struct device_node *cpu_node, int cpu);
-DECLARE_PER_CPU(unsigned long, cpu_scale);
-
-static inline unsigned long topology_get_cpu_scale(int cpu)
-{
- return per_cpu(cpu_scale, cpu);
-}
-
-void topology_set_cpu_scale(unsigned int cpu, unsigned long capacity);
DECLARE_PER_CPU(unsigned long, capacity_freq_ref);
diff --git a/include/linux/topology.h b/include/linux/topology.h
index 24e715f0f6d2..cd6b4bdc9cfd 100644
--- a/include/linux/topology.h
+++ b/include/linux/topology.h
@@ -332,4 +332,13 @@ sched_numa_hop_mask(unsigned int node, unsigned int hops)
!IS_ERR_OR_NULL(mask); \
__hops++)
+DECLARE_PER_CPU(unsigned long, cpu_scale);
+
+static inline unsigned long topology_get_cpu_scale(int cpu)
+{
+ return per_cpu(cpu_scale, cpu);
+}
+
+void topology_set_cpu_scale(unsigned int cpu, unsigned long capacity);
+
#endif /* _LINUX_TOPOLOGY_H */
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/2] cpufreq: intel_pstate: Populate the cpu_capacity sysfs entries
2025-04-19 2:55 [PATCH 0/2] topology/sysfs, cpufreq/intel_pstate: Populate cpu_capacity Ricardo Neri
2025-04-19 2:55 ` [PATCH 1/2] arch_topology: Relocate cpu_scale to topology.[h|c] Ricardo Neri
@ 2025-04-19 2:55 ` Ricardo Neri
2025-05-07 20:00 ` [PATCH 0/2] topology/sysfs, cpufreq/intel_pstate: Populate cpu_capacity Rafael J. Wysocki
2 siblings, 0 replies; 6+ messages in thread
From: Ricardo Neri @ 2025-04-19 2:55 UTC (permalink / raw)
To: Sudeep Holla, Rafael J. Wysocki, Danilo Krummrich,
Srinivas Pandruvada, Len Brown
Cc: linux-kernel, linux-pm, Ricardo Neri, Ricardo Neri
Intel hybrid processors have CPUs of different capacity. Populate the
interface /sys/devices/system/cpu/cpuN/cpu_capacity.
This interface uses the per-CPU variable `cpu_scale`. On x86 this variable
has no other use besides feeding the sysfs entries. Initialize it when
setting CPU capacity for the scheduler and scale-invariant code. Feed it
with arch_scale_cpu_capacity() as it gives capacity normalized to the
interval [0, SCHED_CAPACITY_SCALE].
Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
---
drivers/cpufreq/intel_pstate.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
index 4aad79d26c64..c32312843f19 100644
--- a/drivers/cpufreq/intel_pstate.c
+++ b/drivers/cpufreq/intel_pstate.c
@@ -952,6 +952,8 @@ static void hybrid_set_cpu_capacity(struct cpudata *cpu)
cpu->capacity_perf,
cpu->pstate.max_pstate_physical);
+ topology_set_cpu_scale(cpu->cpu, arch_scale_cpu_capacity(cpu->cpu));
+
pr_debug("CPU%d: perf = %u, max. perf = %u, base perf = %d\n", cpu->cpu,
cpu->capacity_perf, hybrid_max_perf_cpu->capacity_perf,
cpu->pstate.max_pstate_physical);
--
2.43.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] arch_topology: Relocate cpu_scale to topology.[h|c]
2025-04-19 2:55 ` [PATCH 1/2] arch_topology: Relocate cpu_scale to topology.[h|c] Ricardo Neri
@ 2025-04-25 16:31 ` Christian Loehle
2025-05-07 21:18 ` Ricardo Neri
0 siblings, 1 reply; 6+ messages in thread
From: Christian Loehle @ 2025-04-25 16:31 UTC (permalink / raw)
To: Ricardo Neri, Sudeep Holla, Rafael J. Wysocki, Danilo Krummrich,
Srinivas Pandruvada, Len Brown
Cc: linux-kernel, linux-pm, Ricardo Neri
On 4/19/25 03:55, Ricardo Neri wrote:
> arch_topology.c provides functionality to parse and scale CPU capacity. It
> also provides a corresponding sysfs interface. Some architectures parse
> and scale CPU capacity differently as per their own needs. On Intel
> processors, for instance, it is responsibility of the Intel P-state driver.
>
> Relocate the implementation of that interface to a common location in
> topology.c. Architectures can use the interface and populate it using their
> own mechanisms.
>
> An alternative approach would be to compile arch_topology.c even if not
> needed only to get this interface. This approach would create duplicated
> and conflicting functionality and data structures.
>
> Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
Maybe an FYI for the non-x86 folks, this doesn't break anything on the
usual arm64 setup:
Tested-by: Christian Loehle <christian.loehle@arm.com>
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 0/2] topology/sysfs, cpufreq/intel_pstate: Populate cpu_capacity
2025-04-19 2:55 [PATCH 0/2] topology/sysfs, cpufreq/intel_pstate: Populate cpu_capacity Ricardo Neri
2025-04-19 2:55 ` [PATCH 1/2] arch_topology: Relocate cpu_scale to topology.[h|c] Ricardo Neri
2025-04-19 2:55 ` [PATCH 2/2] cpufreq: intel_pstate: Populate the cpu_capacity sysfs entries Ricardo Neri
@ 2025-05-07 20:00 ` Rafael J. Wysocki
2 siblings, 0 replies; 6+ messages in thread
From: Rafael J. Wysocki @ 2025-05-07 20:00 UTC (permalink / raw)
To: Ricardo Neri
Cc: Sudeep Holla, Rafael J. Wysocki, Danilo Krummrich,
Srinivas Pandruvada, Len Brown, linux-kernel, linux-pm,
Ricardo Neri
On Sat, Apr 19, 2025 at 4:49 AM Ricardo Neri
<ricardo.neri-calderon@linux.intel.com> wrote:
>
> Hi,
>
> Capacity-aware scheduling is now supported on Intel hybrid processors. It
> makes sense now to populate the interface /sys/devices/system/cpu/cpuN/
> cpu_capacity. User space entities can use this information to implement
> policy such as utilization clamps.
>
> This interface currently lives in arch_topology.c. Rather than implementing
> the interface again for x86, we can move it to a common location in
> topology.c from which other architectures can also benefit and populate
> using their own mechanisms.
>
> I tested this patchset on Intel Alder Lake and DragonBoard 845c. The
> interfaces are populated correctly.
>
> I'd appreciate any feedback!
>
> Thanks and BR,
> Ricardo
> Ricardo Neri (2):
> arch_topology: Relocate cpu_scale to topology.[h|c]
> cpufreq: intel_pstate: Populate the cpu_capacity sysfs entries
>
> drivers/base/arch_topology.c | 52 ----------------------------------
> drivers/base/topology.c | 52 ++++++++++++++++++++++++++++++++++
> drivers/cpufreq/intel_pstate.c | 2 ++
> include/linux/arch_topology.h | 8 ------
> include/linux/topology.h | 9 ++++++
> 5 files changed, 63 insertions(+), 60 deletions(-)
>
> --
Both patches applied as 6.16 material, thanks!
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] arch_topology: Relocate cpu_scale to topology.[h|c]
2025-04-25 16:31 ` Christian Loehle
@ 2025-05-07 21:18 ` Ricardo Neri
0 siblings, 0 replies; 6+ messages in thread
From: Ricardo Neri @ 2025-05-07 21:18 UTC (permalink / raw)
To: Christian Loehle
Cc: Sudeep Holla, Rafael J. Wysocki, Danilo Krummrich,
Srinivas Pandruvada, Len Brown, linux-kernel, linux-pm,
Ricardo Neri
On Fri, Apr 25, 2025 at 05:31:01PM +0100, Christian Loehle wrote:
> On 4/19/25 03:55, Ricardo Neri wrote:
> > arch_topology.c provides functionality to parse and scale CPU capacity. It
> > also provides a corresponding sysfs interface. Some architectures parse
> > and scale CPU capacity differently as per their own needs. On Intel
> > processors, for instance, it is responsibility of the Intel P-state driver.
> >
> > Relocate the implementation of that interface to a common location in
> > topology.c. Architectures can use the interface and populate it using their
> > own mechanisms.
> >
> > An alternative approach would be to compile arch_topology.c even if not
> > needed only to get this interface. This approach would create duplicated
> > and conflicting functionality and data structures.
> >
> > Signed-off-by: Ricardo Neri <ricardo.neri-calderon@linux.intel.com>
>
> Maybe an FYI for the non-x86 folks, this doesn't break anything on the
> usual arm64 setup:
> Tested-by: Christian Loehle <christian.loehle@arm.com>
Thanks for testing these patches!
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2025-05-07 21:13 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-04-19 2:55 [PATCH 0/2] topology/sysfs, cpufreq/intel_pstate: Populate cpu_capacity Ricardo Neri
2025-04-19 2:55 ` [PATCH 1/2] arch_topology: Relocate cpu_scale to topology.[h|c] Ricardo Neri
2025-04-25 16:31 ` Christian Loehle
2025-05-07 21:18 ` Ricardo Neri
2025-04-19 2:55 ` [PATCH 2/2] cpufreq: intel_pstate: Populate the cpu_capacity sysfs entries Ricardo Neri
2025-05-07 20:00 ` [PATCH 0/2] topology/sysfs, cpufreq/intel_pstate: Populate cpu_capacity Rafael J. Wysocki
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®