Commit afc596cb authored by Ionela Voinescu's avatar Ionela Voinescu
Browse files

Revert "arch_topology: Make cpu_capacity sysfs node as read-only"

This reverts commit 5d777b18.

[ionela.voinescu@arm.com: modify capacity of current CPU only]
parent 5fd90066
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
*/ */
#include <linux/acpi.h> #include <linux/acpi.h>
#include <linux/arch_topology.h>
#include <linux/cpu.h> #include <linux/cpu.h>
#include <linux/cpufreq.h> #include <linux/cpufreq.h>
#include <linux/device.h> #include <linux/device.h>
...@@ -148,6 +149,7 @@ void topology_set_freq_scale(const struct cpumask *cpus, unsigned long cur_freq, ...@@ -148,6 +149,7 @@ 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;
} }
static DEFINE_MUTEX(cpu_scale_mutex);
DEFINE_PER_CPU(unsigned long, cpu_scale) = SCHED_CAPACITY_SCALE; DEFINE_PER_CPU(unsigned long, cpu_scale) = SCHED_CAPACITY_SCALE;
void topology_set_cpu_scale(unsigned int cpu, unsigned long capacity) void topology_set_cpu_scale(unsigned int cpu, unsigned long capacity)
...@@ -178,7 +180,35 @@ static ssize_t cpu_capacity_show(struct device *dev, ...@@ -178,7 +180,35 @@ static ssize_t cpu_capacity_show(struct device *dev,
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 ssize_t cpu_capacity_store(struct device *dev,
struct device_attribute *attr,
const char *buf,
size_t count)
{
struct cpu *cpu = container_of(dev, struct cpu, dev);
int this_cpu = cpu->dev.id;
unsigned long new_capacity;
ssize_t ret;
if (!count)
return 0;
ret = kstrtoul(buf, 0, &new_capacity);
if (ret)
return ret;
if (new_capacity > SCHED_CAPACITY_SCALE)
return -EINVAL;
mutex_lock(&cpu_scale_mutex);
topology_set_cpu_scale(this_cpu, new_capacity);
mutex_unlock(&cpu_scale_mutex);
schedule_work(&update_topology_flags_work);
return count;
}
static DEVICE_ATTR_RW(cpu_capacity);
static int register_cpu_capacity_sysctl(void) static int register_cpu_capacity_sysctl(void)
{ {
...@@ -245,6 +275,7 @@ void topology_normalize_cpu_scale(void) ...@@ -245,6 +275,7 @@ void topology_normalize_cpu_scale(void)
} }
pr_debug("cpu_capacity: capacity_scale=%llu\n", capacity_scale); pr_debug("cpu_capacity: capacity_scale=%llu\n", capacity_scale);
mutex_lock(&cpu_scale_mutex);
for_each_possible_cpu(cpu) { for_each_possible_cpu(cpu) {
capacity = raw_capacity[cpu] * per_cpu(freq_factor, cpu); capacity = raw_capacity[cpu] * per_cpu(freq_factor, cpu);
capacity = div64_u64(capacity << SCHED_CAPACITY_SHIFT, capacity = div64_u64(capacity << SCHED_CAPACITY_SHIFT,
...@@ -253,6 +284,7 @@ void topology_normalize_cpu_scale(void) ...@@ -253,6 +284,7 @@ void topology_normalize_cpu_scale(void)
pr_debug("cpu_capacity: CPU%d cpu_capacity=%lu\n", pr_debug("cpu_capacity: CPU%d cpu_capacity=%lu\n",
cpu, topology_get_cpu_scale(cpu)); cpu, topology_get_cpu_scale(cpu));
} }
mutex_unlock(&cpu_scale_mutex);
} }
bool __init topology_parse_cpu_capacity(struct device_node *cpu_node, int cpu) bool __init topology_parse_cpu_capacity(struct device_node *cpu_node, int cpu)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment