arch_topology: Relocate cpu_scale to topology.[h|c]
JIRA: https://issues.redhat.com/browse/RHEL-112493 commit 6bceea7a1e076ef9d71b20d8dda2f7dc52bd34d2 Author: Ricardo Neri <ricardo.neri-calderon@linux.intel.com> Date: Fri Apr 18 19:55:03 2025 -0700 arch_topology: Relocate cpu_scale to topology.[h|c] 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> Tested-by: Christian Loehle <christian.loehle@arm.com> Link: https://patch.msgid.link/20250419025504.9760-2-ricardo.neri-calderon@linux.intel.com Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Signed-off-by: David Arcari <darcari@redhat.com>
This commit is contained in:
parent
6504a8361f
commit
06d3ad0e14
|
@ -152,14 +152,6 @@ void topology_set_freq_scale(const struct cpumask *cpus, unsigned long cur_freq,
|
||||||
per_cpu(arch_freq_scale, i) = scale;
|
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);
|
DEFINE_PER_CPU(unsigned long, hw_pressure);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -205,53 +197,9 @@ void topology_update_hw_pressure(const struct cpumask *cpus,
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(topology_update_hw_pressure);
|
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 void update_topology_flags_workfn(struct work_struct *work);
|
||||||
static DECLARE_WORK(update_topology_flags_work, update_topology_flags_workfn);
|
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;
|
static int update_topology;
|
||||||
|
|
||||||
int topology_update_cpu_topology(void)
|
int topology_update_cpu_topology(void)
|
||||||
|
|
|
@ -208,3 +208,55 @@ static int __init topology_sysfs_init(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
device_initcall(topology_sysfs_init);
|
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);
|
||||||
|
|
|
@ -14,14 +14,6 @@ int topology_update_cpu_topology(void);
|
||||||
struct device_node;
|
struct device_node;
|
||||||
bool topology_parse_cpu_capacity(struct device_node *cpu_node, int cpu);
|
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);
|
DECLARE_PER_CPU(unsigned long, capacity_freq_ref);
|
||||||
|
|
||||||
|
|
|
@ -279,4 +279,13 @@ sched_numa_hop_mask(unsigned int node, unsigned int hops)
|
||||||
!IS_ERR_OR_NULL(mask); \
|
!IS_ERR_OR_NULL(mask); \
|
||||||
__hops++)
|
__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 */
|
#endif /* _LINUX_TOPOLOGY_H */
|
||||||
|
|
Loading…
Reference in New Issue