x86/cpufreq: Rename cpuid variable/parameters to cpu
PATCH 1/1 x86/cpufreq: Rename cpuid variable/parameters to cpu
Various functions have a parameter or local variable called cpuid, but this triggers a MISRA R5.3 violation because we also have a function called cpuid() which wraps the real CPUID instruction.
In all these cases, it's a Xen cpu index, which is far more commonly named just cpu in our code.
While adjusting these, fix a couple of other issues:
* cpufreq_cpu_init() is on the end of a hypercall (with in-memory parameters, even), making EFAULT the wrong error to use. Use EOPNOTSUPP instead.
* check_est_cpu() is wrong to tie EIST to just Intel, and nowhere else using EIST makes this restriction. Just check the feature itself, which is more succinctly done after being folded into its single caller.
* In powernow_cpufreq_update(), replace an opencoded cpu_online().
---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Nicola Vetrini <[email protected]>
CC: [email protected] <[email protected]>
cpu needs to stay signed for now in set_px_pminfo(), because of get_cpu_id(). This can be cleaned up by making better use of BAD_APICID, but that's a much more involved change.
--- xen/arch/x86/acpi/cpu_idle.c | 14 ++++---- xen/arch/x86/acpi/cpufreq/cpufreq.c | 24 +++---------- xen/arch/x86/acpi/cpufreq/hwp.c | 6 ++-- xen/arch/x86/acpi/cpufreq/powernow.c | 6 ++-- xen/drivers/cpufreq/cpufreq.c | 18 +++++----- xen/drivers/cpufreq/utility.c | 43 +++++++++++------------ xen/include/acpi/cpufreq/cpufreq.h | 6 ++-- xen/include/acpi/cpufreq/processor_perf.h | 8 ++--- xen/include/xen/pmstat.h | 6 ++-- 9 files changed, 57 insertions(+), 74 deletions(-)
xen/arch/x86/acpi/cpu_idle.c +7 -7
@@ -1498,14 +1498,14 @@ static void amd_cpuidle_init(struct acpi_processor_power *power) vendor_override =-1 ; } -uint32_t pmstat_get_cx_nr (uint32_t cpuid) +uint32_t pmstat_get_cx_nr (unsigned int cpu) { -return processor_powers[cpuid] ? processor_powers[cpuid]->count :0 ; +return processor_powers[cpu] ? processor_powers[cpu]->count :0 ; } -int pmstat_get_cx_stat (uint32_t cpuid,struct pm_cx_stat *stat) +int pmstat_get_cx_stat (unsigned int cpu,struct pm_cx_stat *stat) { -struct acpi_processor_power *power = processor_powers[cpuid]; +struct acpi_processor_power *power = processor_powers[cpu];uint64_t idle_usage =0 , idle_res =0 ;uint64_t last_state_update_tick, current_stime, current_tick;uint64_t usage[ACPI_PROCESSOR_MAX_POWER ] = {0 };
@@ -1522,7 +1522,7 @@ int pmstat_get_cx_stat(uint32_t cpuid, struct pm_cx_stat *stat)return 0 ; } - stat->idle_time =get_cpu_idle_time (cpuid); + stat->idle_time =get_cpu_idle_time (cpu); nr =min (stat->nr, power->count);/* mimic the stat when detail info hasn't been registered by dom0 */
@@ -1572,7 +1572,7 @@ int pmstat_get_cx_stat(uint32_t cpuid, struct pm_cx_stat *stat) idle_res += res[i]; } -get_hw_residencies (cpuid, &hw_res); +get_hw_residencies (cpu, &hw_res);#define PUT_xC (what, n) do { \ if ( stat->nr_##what >= n && \
@@ -1613,7 +1613,7 @@ int pmstat_get_cx_stat(uint32_t cpuid, struct pm_cx_stat *stat)return 0 ; } -int pmstat_reset_cx_stat (uint32_t cpuid) +int pmstat_reset_cx_stat (unsigned int cpu) {return 0 ; }
xen/arch/x86/acpi/cpufreq/cpufreq.c +5 -19
@@ -55,17 +55,6 @@ struct acpi_cpufreq_data *cpufreq_drv_data[NR_CPUS];static bool __read_mostly acpi_pstate_strict;boolean_param ("acpi_pstate_strict" , acpi_pstate_strict); -static int check_est_cpu (unsigned int cpuid) -{ -struct cpuinfo_x86 *cpu = &cpu_data[cpuid]; - -if (cpu->x86_vendor !=X86_VENDOR_INTEL || - !cpu_has (cpu,X86_FEATURE_EIST )) -return 0 ; - -return 1 ; -} -static unsigned extract_io (u32 value,struct acpi_cpufreq_data *data) {struct processor_performance *perf;
@@ -530,7 +519,7 @@ static int cf_check acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)if (cpufreq_verbose)printk ("xen_pminfo: @acpi_cpufreq_cpu_init," "HARDWARE addr space\n" ); -if (!check_est_cpu (cpu)) { +if (!cpu_has (c,X86_FEATURE_EIST )) { result = -ENODEV ; goto err_unreg; }
@@ -690,15 +679,12 @@ static int __init cf_check cpufreq_driver_late_init(void) }__initcall (cpufreq_driver_late_init); -int cpufreq_cpu_init (unsigned int cpuid) +int cpufreq_cpu_init (unsigned int cpu) { -int ret; -/* Currently we only handle Intel, AMD and Hygon processor */ if ( boot_cpu_data.x86_vendor & (X86_VENDOR_INTEL |X86_VENDOR_AMD |X86_VENDOR_HYGON ) ) - ret =cpufreq_add_cpu (cpuid); -else - ret = -EFAULT ; -return ret; +return cpufreq_add_cpu (cpu); + +return -EOPNOTSUPP ; }
xen/arch/x86/acpi/cpufreq/hwp.c +3 -3
@@ -506,11 +506,11 @@ static void cf_check hwp_set_misc_turbo(void *info) } } -static int cf_check hwp_cpufreq_update(int cpuid, struct cpufreq_policy *policy) +static int cf_check hwp_cpufreq_update(unsigned int cpu, struct cpufreq_policy *policy) { -on_selected_cpus (cpumask_of (cpuid), hwp_set_misc_turbo, policy,1 ); +on_selected_cpus (cpumask_of (cpu), hwp_set_misc_turbo, policy,1 ); -return per_cpu (hwp_drv_data, cpuid)->ret; +return per_cpu (hwp_drv_data, cpu)->ret; }static const struct cpufreq_driver __initconst_cf_clobber
xen/arch/x86/acpi/cpufreq/powernow.c +3 -3
@@ -68,12 +68,12 @@ static void cf_check update_cpb(void *data) } static int cf_check powernow_cpufreq_update( -int cpuid,struct cpufreq_policy *policy) +unsigned int cpu,struct cpufreq_policy *policy) { -if (!cpumask_test_cpu (cpuid, &cpu_online_map)) +if ( !cpu_online (cpu) )return -EINVAL ; -on_selected_cpus (cpumask_of (cpuid), update_cpb, policy,1 ); +on_selected_cpus (cpumask_of (cpu), update_cpb, policy,1 );return 0 ; }
xen/drivers/cpufreq/cpufreq.c +9 -9
@@ -459,21 +459,21 @@ static void print_PPC(unsigned int platform_limit)int set_px_pminfo (uint32_t acpi_id,struct xen_processor_performance *perf) { -int ret=0 , cpuid; +int ret=0 , cpu;struct processor_pminfo *pmpt;struct processor_performance *pxpt; - cpuid =get_cpu_id (acpi_id); -if ( cpuid <0 || !perf ) + cpu =get_cpu_id (acpi_id); +if ( cpu <0 || !perf ) { ret = -EINVAL ; goto out; }if ( cpufreq_verbose ) -printk ("Set CPU acpi_id(%d) cpuid(%d) Px State info:\n" , +printk ("Set CPU acpi_id(%d) cpu(%d) Px State info:\n" , acpi_id, cpuid); - pmpt = processor_pminfo[cpuid]; + pmpt = processor_pminfo[cpu];if ( !pmpt ) { pmpt = xzalloc(struct processor_pminfo);
@@ -482,11 +482,11 @@ int set_px_pminfo(uint32_t acpi_id, struct xen_processor_performance *perf) ret = -ENOMEM ; goto out; } - processor_pminfo[cpuid] = pmpt; + processor_pminfo[cpu] = pmpt; } pxpt = &pmpt->perf; pmpt->acpi_id = acpi_id; - pmpt->id = cpuid; + pmpt->id = cpu;if ( perf->flags &XEN_PX_PCT ) {
@@ -564,7 +564,7 @@ int set_px_pminfo(uint32_t acpi_id, struct xen_processor_performance *perf)if ( pxpt->init ==XEN_PX_INIT ) { - ret =cpufreq_limit_change (cpuid); + ret =cpufreq_limit_change (cpu); goto out; } }
@@ -573,7 +573,7 @@ int set_px_pminfo(uint32_t acpi_id, struct xen_processor_performance *perf) { pxpt->init =XEN_PX_INIT ; - ret =cpufreq_cpu_init (cpuid); + ret =cpufreq_cpu_init (cpu); goto out; }
xen/drivers/cpufreq/utility.c +20 -23
130 lines not on this page · raw message
xen/include/acpi/cpufreq/cpufreq.h +3 -3
@@ -145,8 +145,8 @@ extern int cpufreq_driver_getavg(unsigned int cpu, unsigned int flag);#define CPUFREQ_TURBO_UNSUPPORTED 0#define CPUFREQ_TURBO_ENABLED 1 -extern int cpufreq_update_turbo (int cpuid,int new_state); -extern int cpufreq_get_turbo_status (int cpuid); +int cpufreq_update_turbo (unsigned int cpu,int new_state); +int cpufreq_get_turbo_status (unsigned int cpu);static inline int __cpufreq_governor (struct cpufreq_policy *policy,unsigned int event)
@@ -167,7 +167,7 @@ struct cpufreq_driver {int (*init)(struct cpufreq_policy *policy);int (*verify)(struct cpufreq_policy *policy);int (*setpolicy)(struct cpufreq_policy *policy); -int (*update)(int cpuid,struct cpufreq_policy *policy); +int (*update)(unsigned int cpu,struct cpufreq_policy *policy);int (*target)(struct cpufreq_policy *policy,unsigned int target_freq,unsigned int relation);
xen/include/acpi/cpufreq/processor_perf.h +4 -4
@@ -12,9 +12,9 @@ unsigned int powernow_register_driver(void);unsigned int get_measured_perf (unsigned int cpu,unsigned int flag);void cpufreq_residency_update (unsigned int cpu,uint8_t state);void cpufreq_statistic_update (unsigned int cpu,uint8_t from,uint8_t to); -int cpufreq_statistic_init (unsigned int cpuid); -void cpufreq_statistic_exit (unsigned int cpuid); -void cpufreq_statistic_reset (unsigned int cpuid); +int cpufreq_statistic_init (unsigned int cpu); +void cpufreq_statistic_exit (unsigned int cpu); +void cpufreq_statistic_reset (unsigned int cpu);int cpufreq_limit_change (unsigned int cpu);
@@ -59,5 +59,5 @@ struct pm_px { DECLARE_PER_CPU(struct pm_px *, cpufreq_statistic_data); -int cpufreq_cpu_init (unsigned int cpuid); +int cpufreq_cpu_init (unsigned int cpu);#endif /* __XEN_PROCESSOR_PM_H__ */
xen/include/xen/pmstat.h +3 -3
@@ -7,9 +7,9 @@int set_px_pminfo (uint32_t acpi_id,struct xen_processor_performance *perf);long set_cx_pminfo (uint32_t acpi_id,struct xen_processor_power *power); -uint32_t pmstat_get_cx_nr (uint32_t cpuid); -int pmstat_get_cx_stat (uint32_t cpuid,struct pm_cx_stat *stat); -int pmstat_reset_cx_stat (uint32_t cpuid); +uint32_t pmstat_get_cx_nr (unsigned int cpu); +int pmstat_get_cx_stat (unsigned int cpu,struct pm_cx_stat *stat); +int pmstat_reset_cx_stat (unsigned int cpu);int do_get_pm_info (struct xen_sysctl_get_pmstat *op);int do_pm_op (struct xen_sysctl_pm_op *op);
Signature · 1 line
2.30.2
Quoted 196 lines · Andrew Cooper
Various functions have a parameter or local variable called cpuid, but this triggers a MISRA R5.3 violation because we also have a function called
cpuid()which wraps the real CPUID instruction.In all these cases, it's a Xen cpu index, which is far more commonly named just cpu in our code.
While adjusting these, fix a couple of other issues:
*
cpufreq_cpu_init()is on the end of a hypercall (with in-memory parameters, even), making EFAULT the wrong error to use. Use EOPNOTSUPP instead.*
check_est_cpu()is wrong to tie EIST to just Intel, and nowhere else using EIST makes this restriction. Just check the feature itself, which is more succinctly done after being folded into its single caller.* In
powernow_cpufreq_update(), replace an opencodedcpu_online().Signed-off-by Andrew Cooper <[email protected]>---
CC: Jan Beulich <[email protected]>
CC: Roger Pau Monné <[email protected]>
CC: Stefano Stabellini <[email protected]>
CC: Nicola Vetrini <[email protected]>
CC: [email protected] <[email protected]>cpu needs to stay signed for now in
set_px_pminfo(), because ofget_cpu_id(). This can be cleaned up by making better use ofBAD_APICID, but that's a much more involved change.--- xen/arch/x86/acpi/cpu_idle.c | 14 ++++---- xen/arch/x86/acpi/cpufreq/cpufreq.c | 24 +++---------- xen/arch/x86/acpi/cpufreq/hwp.c | 6 ++-- xen/arch/x86/acpi/cpufreq/powernow.c | 6 ++-- xen/drivers/cpufreq/cpufreq.c | 18 +++++----- xen/drivers/cpufreq/utility.c | 43 +++++++++++------------ xen/include/acpi/cpufreq/cpufreq.h | 6 ++-- xen/include/acpi/cpufreq/processor_perf.h | 8 ++--- xen/include/xen/pmstat.h | 6 ++-- 9 files changed, 57 insertions(+), 74 deletions(-)xen/arch/x86/acpi/cpu_idle.c +7
-7@@ -1498,14 +1498,14 @@ static void amd_cpuidle_init(struct acpi_processor_power *power) vendor_override =-1 ; } -uint32_t pmstat_get_cx_nr (uint32_t cpuid) +uint32_t pmstat_get_cx_nr (unsigned int cpu) { -return processor_powers[cpuid] ? processor_powers[cpuid]->count :0 ; +return processor_powers[cpu] ? processor_powers[cpu]->count :0 ; } -int pmstat_get_cx_stat (uint32_t cpuid,struct pm_cx_stat *stat) +int pmstat_get_cx_stat (unsigned int cpu,struct pm_cx_stat *stat) { -struct acpi_processor_power *power = processor_powers[cpuid]; +struct acpi_processor_power *power = processor_powers[cpu];uint64_t idle_usage =0 , idle_res =0 ;uint64_t last_state_update_tick, current_stime, current_tick;uint64_t usage[ACPI_PROCESSOR_MAX_POWER ] = {0 };@@ -1522,7 +1522,7 @@ int pmstat_get_cx_stat(uint32_t cpuid, struct pm_cx_stat *stat)return 0 ; } - stat->idle_time =get_cpu_idle_time (cpuid); + stat->idle_time =get_cpu_idle_time (cpu); nr =min (stat->nr, power->count);/* mimic the stat when detail info hasn't been registered by dom0 */ @@ -1572,7 +1572,7 @@ int pmstat_get_cx_stat(uint32_t cpuid, struct pm_cx_stat *stat) idle_res += res[i]; } -get_hw_residencies (cpuid, &hw_res); +get_hw_residencies (cpu, &hw_res);#define PUT_xC (what, n) do { \ if ( stat->nr_##what >= n && \@@ -1613,7 +1613,7 @@ int pmstat_get_cx_stat(uint32_t cpuid, struct pm_cx_stat *stat)return 0 ; } -int pmstat_reset_cx_stat (uint32_t cpuid) +int pmstat_reset_cx_stat (unsigned int cpu) {return 0 ; }xen/arch/x86/acpi/cpufreq/cpufreq.c +5
-19@@ -55,17 +55,6 @@ struct acpi_cpufreq_data *cpufreq_drv_data[NR_CPUS];static bool __read_mostly acpi_pstate_strict;boolean_param ("acpi_pstate_strict" , acpi_pstate_strict); -static int check_est_cpu (unsigned int cpuid) -{ -struct cpuinfo_x86 *cpu = &cpu_data[cpuid]; - -if (cpu->x86_vendor !=X86_VENDOR_INTEL || - !cpu_has (cpu,X86_FEATURE_EIST )) -return 0 ; - -return 1 ; -} -static unsigned extract_io (u32 value,struct acpi_cpufreq_data *data) {struct processor_performance *perf;@@ -530,7 +519,7 @@ static int cf_check acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)if (cpufreq_verbose)printk ("xen_pminfo: @acpi_cpufreq_cpu_init," "HARDWARE addr space\n" ); -if (!check_est_cpu (cpu)) { +if (!cpu_has (c,X86_FEATURE_EIST )) { result = -ENODEV ; goto err_unreg; }@@ -690,15 +679,12 @@ static int __init cf_check cpufreq_driver_late_init(void) }__initcall (cpufreq_driver_late_init); -int cpufreq_cpu_init (unsigned int cpuid) +int cpufreq_cpu_init (unsigned int cpu) { -int ret; -/* Currently we only handle Intel, AMD and Hygon processor */ if ( boot_cpu_data.x86_vendor & (X86_VENDOR_INTEL |X86_VENDOR_AMD |X86_VENDOR_HYGON ) ) - ret =cpufreq_add_cpu (cpuid); -else - ret = -EFAULT ; -return ret; +return cpufreq_add_cpu (cpu); + +return -EOPNOTSUPP ; }xen/arch/x86/acpi/cpufreq/hwp.c +3
-3@@ -506,11 +506,11 @@ static void cf_check hwp_set_misc_turbo(void *info) } } -static int cf_check hwp_cpufreq_update(int cpuid, struct cpufreq_policy *policy) +static int cf_check hwp_cpufreq_update(unsigned int cpu, struct cpufreq_policy *policy) { -on_selected_cpus (cpumask_of (cpuid), hwp_set_misc_turbo, policy,1 ); +on_selected_cpus (cpumask_of (cpu), hwp_set_misc_turbo, policy,1 ); -return per_cpu (hwp_drv_data, cpuid)->ret; +return per_cpu (hwp_drv_data, cpu)->ret; }static const struct cpufreq_driver __initconst_cf_clobberxen/arch/x86/acpi/cpufreq/powernow.c +3
-3@@ -68,12 +68,12 @@ static void cf_check update_cpb(void *data) } static int cf_check powernow_cpufreq_update( -int cpuid,struct cpufreq_policy *policy) +unsigned int cpu,struct cpufreq_policy *policy) { -if (!cpumask_test_cpu (cpuid, &cpu_online_map)) +if ( !cpu_online (cpu) )return -EINVAL ; -on_selected_cpus (cpumask_of (cpuid), update_cpb, policy,1 ); +on_selected_cpus (cpumask_of (cpu), update_cpb, policy,1 );return 0 ; }xen/drivers/cpufreq/cpufreq.c +1
-3@@ -459,21 +459,21 @@ static void print_PPC(unsigned int platform_limit)int set_px_pminfo (uint32_t acpi_id,struct xen_processor_performance *perf) { -int ret=0 , cpuid; +int ret=0 , cpu;struct processor_pminfo *pmpt;struct processor_performance *pxpt; - cpuid =get_cpu_id (acpi_id); -if ( cpuid <0 || !perf )
xen/drivers/cpufreq/cpufreq.c static void print_PPC(unsigned int platform_limit) · line 474
Quoted 10 lines
xen/drivers/cpufreq/cpufreq.c +3
-1+ cpu =get_cpu_id (acpi_id); +if ( cpu <0 || !perf ) { ret = -EINVAL ; goto out; }if ( cpufreq_verbose ) -printk ("Set CPU acpi_id(%d) cpuid(%d) Px State info:\n" , +printk ("Set CPU acpi_id(%d) cpu(%d) Px State info:\n" , acpi_id, cpuid);
This cpuid should be changed as well?
Everything else looks OK to me. You can fix on commit.
Jan Beulich
Reviewed-byQuoted 9 lines · Stefano Stabellini
xen/drivers/cpufreq/cpufreq.c static void print_PPC(unsigned int platform_limit) · line 462
Quoted 8 lines · Andrew Cooper
xen/drivers/cpufreq/cpufreq.c +1
-1@@ -459,21 +459,21 @@ static void print_PPC(unsigned int platform_limit)int set_px_pminfo (uint32_t acpi_id,struct xen_processor_performance *perf) { -int ret=0 , cpuid; +int ret=0 , cpu;
Would be nice if the missing blanks were added here as well, while touching the line.
Quoted 16 lines
Quoted 5 lines
xen/drivers/cpufreq/cpufreq.c +0
-2struct processor_pminfo *pmpt;struct processor_performance *pxpt; - cpuid =get_cpu_id (acpi_id); -if ( cpuid <0 || !perf )xen/drivers/cpufreq/cpufreq.c static void print_PPC(unsigned int platform_limit) · line 474
Quoted 10 lines
xen/drivers/cpufreq/cpufreq.c +3
-1+ cpu =get_cpu_id (acpi_id); +if ( cpu <0 || !perf ) { ret = -EINVAL ; goto out; }if ( cpufreq_verbose ) -printk ("Set CPU acpi_id(%d) cpuid(%d) Px State info:\n" , +printk ("Set CPU acpi_id(%d) cpu(%d) Px State info:\n" , acpi_id, cpuid);
Quoted 1 line
This cpuid should be changed as well?
And with that adjustment
Jan
Quoted 6 lines · Jan Beulich
Quoted 5 lines · Stefano Stabellini
Quoted 4 lines · Andrew Cooper
xen/drivers/cpufreq/cpufreq.c +0
-0@@ -459,21 +459,21 @@ static void print_PPC(unsigned int platform_limit)
Quoted 6 lines
Quoted 4 lines
xen/drivers/cpufreq/cpufreq.c static void print_PPC(unsigned int platform_limit) · line 462
Quoted 4 lines
xen/drivers/cpufreq/cpufreq.c +1
-1int set_px_pminfo (uint32_t acpi_id,struct xen_processor_performance *perf) { -int ret=0 , cpuid; +int ret=0 , cpu;Would be nice if the missing blanks were added here as well, while touching the line.
Will adjust.
Quoted 16 lines
Quoted 16 lines
Quoted 16 lines
xen/drivers/cpufreq/cpufreq.c +3
-3struct processor_pminfo *pmpt;struct processor_performance *pxpt; - cpuid =get_cpu_id (acpi_id); -if ( cpuid <0 || !perf ) + cpu =get_cpu_id (acpi_id); +if ( cpu <0 || !perf ) { ret = -EINVAL ; goto out; }if ( cpufreq_verbose ) -printk ("Set CPU acpi_id(%d) cpuid(%d) Px State info:\n" , +printk ("Set CPU acpi_id(%d) cpu(%d) Px State info:\n" , acpi_id, cpuid);
Quoted 2 lines
Quoted 1 line
This cpuid should be changed as well?
And with that adjustment
Yes - this was a victim of a "trivial" post-test fix. I fixed it just after sending out the email.
Quoted 1 line
Reviewed-by Jan Beulich <[email protected]>
Thanks.
~Andrew