Re: [Xen-devel] [PATCH v4 08/12] cpufreq: convert to a single post-init driver (hooks) instance

2018-10-04 Thread Andrew Cooper
On 02/10/18 11:16, Jan Beulich wrote:
> 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 
> Reviewed-by: Wei Liu 

Reviewed-by: Andrew Cooper 

___
Xen-devel mailing list
Xen-devel@lists.xenproject.org
https://lists.xenproject.org/mailman/listinfo/xen-devel

[Xen-devel] [PATCH v4 08/12] cpufreq: convert to a single post-init driver (hooks) instance

2018-10-02 Thread Jan Beulich
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 
Reviewed-by: Wei Liu 
---
v2: New.

--- 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_pol
 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
 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(vo
 
 return ret;
 }
-__initcall(cpufreq_driver_init);
+presmp_initcall(cpufreq_driver_init);
 
 int cpufreq_cpu_init(unsigned int cpuid)
 {
--- 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(str
 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,
--- 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
 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_s
 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);
 
--- 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