Discussion:
[Xen-changelog] [xen master] cpufreq: convert to a single post-init driver (hooks) instance
p***@xen.org
2018-11-19 11:52:53 UTC
Permalink
commit afe08486589347eb523038abda5ad4a0a0289ce1
Author: Jan Beulich <***@suse.com>
AuthorDate: Fri Nov 9 11:42:10 2018 +0100
Commit: Jan Beulich <***@suse.com>
CommitDate: Fri Nov 9 11:42:10 2018 +0100

cpufreq: convert to a single post-init driver (hooks) instance

This reduces the post-init memory footprint, eliminates a pointless
level of indirection at the use sites, and allows for subsequent
alternatives call patching.

Take the opportunity and also add a name to the PowerNow! instance.

Signed-off-by: Jan Beulich <***@suse.com>
Reviewed-by: Wei Liu <***@citrix.com>
Reviewed-by: Andrew Cooper <***@citrix.com>
---
xen/arch/x86/acpi/cpufreq/cpufreq.c | 10 ++++------
xen/arch/x86/acpi/cpufreq/powernow.c | 7 +++----
xen/drivers/acpi/pmstat.c | 8 ++++----
xen/drivers/cpufreq/cpufreq.c | 14 +++++++-------
xen/drivers/cpufreq/utility.c | 20 ++++++++++----------
xen/include/acpi/cpufreq/cpufreq.h | 6 +++---
6 files changed, 31 insertions(+), 34 deletions(-)

diff --git a/xen/arch/x86/acpi/cpufreq/cpufreq.c b/xen/arch/x86/acpi/cpufreq/cpufreq.c
index 1f8d02aab9..844ab85cd3 100644
--- a/xen/arch/x86/acpi/cpufreq/cpufreq.c
+++ b/xen/arch/x86/acpi/cpufreq/cpufreq.c
@@ -53,8 +53,6 @@ enum {

struct acpi_cpufreq_data *cpufreq_drv_data[NR_CPUS];

-static struct cpufreq_driver acpi_cpufreq_driver;
-
static bool __read_mostly acpi_pstate_strict;
boolean_param("acpi_pstate_strict", acpi_pstate_strict);

@@ -355,7 +353,7 @@ static void feature_detect(void *info)
if ( cpu_has_aperfmperf )
{
policy->aperf_mperf = 1;
- acpi_cpufreq_driver.getavg = get_measured_perf;
+ cpufreq_driver.getavg = get_measured_perf;
}

eax = cpuid_eax(6);
@@ -593,7 +591,7 @@ acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
break;
case ACPI_ADR_SPACE_FIXED_HARDWARE:
- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
+ cpufreq_driver.get = get_cur_freq_on_cpu;
policy->cur = get_cur_freq_on_cpu(cpu);
break;
default:
@@ -635,7 +633,7 @@ static int acpi_cpufreq_cpu_exit(struct cpufreq_policy *policy)
return 0;
}

-static struct cpufreq_driver acpi_cpufreq_driver = {
+static const struct cpufreq_driver __initconstrel acpi_cpufreq_driver = {
.name = "acpi-cpufreq",
.verify = acpi_cpufreq_verify,
.target = acpi_cpufreq_target,
@@ -656,7 +654,7 @@ static int __init cpufreq_driver_init(void)

return ret;
}
-__initcall(cpufreq_driver_init);
+presmp_initcall(cpufreq_driver_init);

int cpufreq_cpu_init(unsigned int cpuid)
{
diff --git a/xen/arch/x86/acpi/cpufreq/powernow.c b/xen/arch/x86/acpi/cpufreq/powernow.c
index 8f1ac74f0f..025b37da03 100644
--- a/xen/arch/x86/acpi/cpufreq/powernow.c
+++ b/xen/arch/x86/acpi/cpufreq/powernow.c
@@ -52,8 +52,6 @@

#define ARCH_CPU_FLAG_RESUME 1

-static struct cpufreq_driver powernow_cpufreq_driver;
-
static void transition_pstate(void *pstate)
{
wrmsrl(MSR_PSTATE_CTRL, *(unsigned int *)pstate);
@@ -215,7 +213,7 @@ static void feature_detect(void *info)
if ( cpu_has_aperfmperf )
{
policy->aperf_mperf = 1;
- powernow_cpufreq_driver.getavg = get_measured_perf;
+ cpufreq_driver.getavg = get_measured_perf;
}

edx = cpuid_edx(CPUID_FREQ_VOLT_CAPABILITIES);
@@ -347,7 +345,8 @@ static int powernow_cpufreq_cpu_exit(struct cpufreq_policy *policy)
return 0;
}

-static struct cpufreq_driver powernow_cpufreq_driver = {
+static const struct cpufreq_driver __initconstrel powernow_cpufreq_driver = {
+ .name = "powernow",
.verify = powernow_cpufreq_verify,
.target = powernow_cpufreq_target,
.init = powernow_cpufreq_cpu_init,
diff --git a/xen/drivers/acpi/pmstat.c b/xen/drivers/acpi/pmstat.c
index a8fc52a35f..bb80506ad6 100644
--- a/xen/drivers/acpi/pmstat.c
+++ b/xen/drivers/acpi/pmstat.c
@@ -64,7 +64,7 @@ int do_get_pm_info(struct xen_sysctl_get_pmstat *op)
case PMSTAT_PX:
if ( !(xen_processor_pmbits & XEN_PROCESSOR_PM_PX) )
return -ENODEV;
- if ( !cpufreq_driver )
+ if ( !cpufreq_driver.init )
return -ENODEV;
if ( !pmpt || !(pmpt->perf.init & XEN_PX_INIT) )
return -EINVAL;
@@ -255,16 +255,16 @@ static int get_cpufreq_para(struct xen_sysctl_pm_op *op)
return ret;

op->u.get_para.cpuinfo_cur_freq =
- cpufreq_driver->get ? cpufreq_driver->get(op->cpuid) : policy->cur;
+ cpufreq_driver.get ? cpufreq_driver.get(op->cpuid) : policy->cur;
op->u.get_para.cpuinfo_max_freq = policy->cpuinfo.max_freq;
op->u.get_para.cpuinfo_min_freq = policy->cpuinfo.min_freq;
op->u.get_para.scaling_cur_freq = policy->cur;
op->u.get_para.scaling_max_freq = policy->max;
op->u.get_para.scaling_min_freq = policy->min;

- if ( cpufreq_driver->name[0] )
+ if ( cpufreq_driver.name[0] )
strlcpy(op->u.get_para.scaling_driver,
- cpufreq_driver->name, CPUFREQ_NAME_LEN);
+ cpufreq_driver.name, CPUFREQ_NAME_LEN);
else
strlcpy(op->u.get_para.scaling_driver, "Unknown", CPUFREQ_NAME_LEN);

diff --git a/xen/drivers/cpufreq/cpufreq.c b/xen/drivers/cpufreq/cpufreq.c
index 212f48f9f4..4d6badc663 100644
--- a/xen/drivers/cpufreq/cpufreq.c
+++ b/xen/drivers/cpufreq/cpufreq.c
@@ -172,7 +172,7 @@ int cpufreq_add_cpu(unsigned int cpu)
if ( !(perf->init & XEN_PX_INIT) )
return -EINVAL;

- if (!cpufreq_driver)
+ if (!cpufreq_driver.init)
return 0;

if (per_cpu(cpufreq_cpu_policy, cpu))
@@ -239,7 +239,7 @@ int cpufreq_add_cpu(unsigned int cpu)
policy->cpu = cpu;
per_cpu(cpufreq_cpu_policy, cpu) = policy;

- ret = cpufreq_driver->init(policy);
+ ret = cpufreq_driver.init(policy);
if (ret) {
free_cpumask_var(policy->cpus);
xfree(policy);
@@ -298,7 +298,7 @@ err1:
cpumask_clear_cpu(cpu, cpufreq_dom->map);

if (cpumask_empty(policy->cpus)) {
- cpufreq_driver->exit(policy);
+ cpufreq_driver.exit(policy);
free_cpumask_var(policy->cpus);
xfree(policy);
}
@@ -362,7 +362,7 @@ int cpufreq_del_cpu(unsigned int cpu)
cpumask_clear_cpu(cpu, cpufreq_dom->map);

if (cpumask_empty(policy->cpus)) {
- cpufreq_driver->exit(policy);
+ cpufreq_driver.exit(policy);
free_cpumask_var(policy->cpus);
xfree(policy);
}
@@ -663,17 +663,17 @@ static int __init cpufreq_presmp_init(void)
}
presmp_initcall(cpufreq_presmp_init);

-int __init cpufreq_register_driver(struct cpufreq_driver *driver_data)
+int __init cpufreq_register_driver(const struct cpufreq_driver *driver_data)
{
if ( !driver_data || !driver_data->init ||
!driver_data->verify || !driver_data->exit ||
(!driver_data->target == !driver_data->setpolicy) )
return -EINVAL;

- if ( cpufreq_driver )
+ if ( cpufreq_driver.init )
return -EBUSY;

- cpufreq_driver = driver_data;
+ cpufreq_driver = *driver_data;

return 0;
}
diff --git a/xen/drivers/cpufreq/utility.c b/xen/drivers/cpufreq/utility.c
index 53879fe8dd..15e15fd458 100644
--- a/xen/drivers/cpufreq/utility.c
+++ b/xen/drivers/cpufreq/utility.c
@@ -31,7 +31,7 @@
#include <acpi/cpufreq/cpufreq.h>
#include <public/sysctl.h>

-struct cpufreq_driver *cpufreq_driver;
+struct cpufreq_driver __read_mostly cpufreq_driver;
struct processor_pminfo *__read_mostly processor_pminfo[NR_CPUS];
DEFINE_PER_CPU_READ_MOSTLY(struct cpufreq_policy *, cpufreq_cpu_policy);

@@ -360,11 +360,11 @@ int __cpufreq_driver_target(struct cpufreq_policy *policy,
{
int retval = -EINVAL;

- if (cpu_online(policy->cpu) && cpufreq_driver->target)
+ if (cpu_online(policy->cpu) && cpufreq_driver.target)
{
unsigned int prev_freq = policy->cur;

- retval = cpufreq_driver->target(policy, target_freq, relation);
+ retval = cpufreq_driver.target(policy, target_freq, relation);
if ( retval == 0 )
TRACE_2D(TRC_PM_FREQ_CHANGE, prev_freq/1000, policy->cur/1000);
}
@@ -380,9 +380,9 @@ int cpufreq_driver_getavg(unsigned int cpu, unsigned int flag)
if (!cpu_online(cpu) || !(policy = per_cpu(cpufreq_cpu_policy, cpu)))
return 0;

- if (cpufreq_driver->getavg)
+ if (cpufreq_driver.getavg)
{
- freq_avg = cpufreq_driver->getavg(cpu, flag);
+ freq_avg = cpufreq_driver.getavg(cpu, flag);
if (freq_avg > 0)
return freq_avg;
}
@@ -412,9 +412,9 @@ int cpufreq_update_turbo(int cpuid, int new_state)
return 0;

policy->turbo = new_state;
- if (cpufreq_driver->update)
+ if (cpufreq_driver.update)
{
- ret = cpufreq_driver->update(cpuid, policy);
+ ret = cpufreq_driver.update(cpuid, policy);
if (ret)
policy->turbo = curr_state;
}
@@ -450,15 +450,15 @@ int __cpufreq_set_policy(struct cpufreq_policy *data,
return -EINVAL;

/* verify the cpu speed can be set within this limit */
- ret = cpufreq_driver->verify(policy);
+ ret = cpufreq_driver.verify(policy);
if (ret)
return ret;

data->min = policy->min;
data->max = policy->max;
data->limits = policy->limits;
- if (cpufreq_driver->setpolicy)
- return cpufreq_driver->setpolicy(data);
+ if (cpufreq_driver.setpolicy)
+ return cpufreq_driver.setpolicy(data);

if (policy->governor != data->governor) {
/* save old, working values */
diff --git a/xen/include/acpi/cpufreq/cpufreq.h b/xen/include/acpi/cpufreq/cpufreq.h
index facbc14346..e88b20bfed 100644
--- a/xen/include/acpi/cpufreq/cpufreq.h
+++ b/xen/include/acpi/cpufreq/cpufreq.h
@@ -153,7 +153,7 @@ __cpufreq_governor(struct cpufreq_policy *policy, unsigned int event)
#define CPUFREQ_RELATION_H 1 /* highest frequency below or at target */

struct cpufreq_driver {
- char name[CPUFREQ_NAME_LEN];
+ const char *name;
int (*init)(struct cpufreq_policy *policy);
int (*verify)(struct cpufreq_policy *policy);
int (*setpolicy)(struct cpufreq_policy *policy);
@@ -166,9 +166,9 @@ struct cpufreq_driver {
int (*exit)(struct cpufreq_policy *policy);
};

-extern struct cpufreq_driver *cpufreq_driver;
+extern struct cpufreq_driver cpufreq_driver;

-int cpufreq_register_driver(struct cpufreq_driver *);
+int cpufreq_register_driver(const struct cpufreq_driver *);

static __inline__
void cpufreq_verify_within_limits(struct cpufreq_policy *policy,
--
generated by git-patchbot for /home/xen/git/xen.git#master

Loading...