[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] Re: [PATCH v2 11/11] xen/cpufreq: Adapt SET/GET_CPUFREQ_CPPC xen_sysctl_pm_op for amd-cppc driver
On 06.02.2025 09:32, Penny Zheng wrote: > @@ -533,6 +534,114 @@ static int cf_check amd_cppc_epp_set_policy(struct > cpufreq_policy *policy) > return amd_cppc_epp_update_limit(policy); > } > > +int get_amd_cppc_para(unsigned int cpu, > + struct xen_cppc_para *cppc_para) > +{ > + const struct amd_cppc_drv_data *data = per_cpu(amd_cppc_drv_data, cpu); > + > + if ( data == NULL ) > + return -ENODATA; > + > + cppc_para->features = 0; > + cppc_para->lowest = data->caps.lowest_perf; > + cppc_para->lowest_nonlinear = data->caps.lowest_nonlinear_perf; > + cppc_para->nominal = data->caps.nominal_perf; > + cppc_para->highest = data->caps.highest_perf; > + cppc_para->minimum = data->req.min_perf; > + cppc_para->maximum = data->req.max_perf; > + cppc_para->desired = data->req.des_perf; > + cppc_para->energy_perf = data->req.epp; > + > + return 0; > +} > + > +int set_amd_cppc_para(const struct cpufreq_policy *policy, > + const struct xen_set_cppc_para *set_cppc) > +{ > + unsigned int cpu = policy->cpu; > + struct amd_cppc_drv_data *data = per_cpu(amd_cppc_drv_data, cpu); > + uint8_t max_perf, min_perf, des_perf = 0; > + int epp = -1; > + > + if ( data == NULL ) > + return -ENOENT; > + > + /* Validate all parameters - Disallow reserved bits. */ > + if ( set_cppc->minimum > 255 || set_cppc->maximum > 255 || > + set_cppc->desired > 255 || set_cppc->energy_perf > 255 ) > + return -EINVAL; In an earlier patch I just looked at you use UINT8_MAX for bounds checking. I'm not overly fussed which of the two its is, but I'd like to ask for it to be consistent throughout the driver. Unless of course there's a reason for the difference. > + /* Only allow values if params bit is set. */ > + if ( (!(set_cppc->set_params & XEN_SYSCTL_CPPC_SET_DESIRED) && > + set_cppc->desired) || > + (!(set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MINIMUM) && > + set_cppc->minimum) || > + (!(set_cppc->set_params & XEN_SYSCTL_CPPC_SET_MAXIMUM) && > + set_cppc->maximum) || > + (!(set_cppc->set_params & XEN_SYSCTL_CPPC_SET_ENERGY_PERF) && > + set_cppc->energy_perf) ) > + return -EINVAL; > + > + /* Activity window not supported */ > + if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_ACT_WINDOW ) > + return -EINVAL; "not supported" as in "support may appear later"? The -EOPNOTSUPP may be more appropriate. Else the comment may want re-wording. > + /* Return if there is nothing to do. */ > + if ( set_cppc->set_params == 0 ) > + return 0; > + > + /* Apply presets */ > + switch ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_PRESET_MASK ) > + { > + case XEN_SYSCTL_CPPC_SET_PRESET_POWERSAVE: > + if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_DESIRED ) > + return -EINVAL; > + min_perf = data->caps.lowest_perf; > + max_perf = data->caps.highest_perf; These match ... > + epp = CPPC_ENERGY_PERF_MAX_POWERSAVE; > + break; > + > + case XEN_SYSCTL_CPPC_SET_PRESET_PERFORMANCE: > + if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_DESIRED ) > + return -EINVAL; > + min_perf = data->caps.highest_perf; > + max_perf = data->caps.highest_perf; > + epp = CPPC_ENERGY_PERF_MAX_PERFORMANCE; > + break; > + > + case XEN_SYSCTL_CPPC_SET_PRESET_BALANCE: > + if ( set_cppc->set_params & XEN_SYSCTL_CPPC_SET_DESIRED ) > + return -EINVAL; > + min_perf = data->caps.lowest_perf; > + max_perf = data->caps.highest_perf; ... these, which doesn't seem quite right. It feels like I had asked about this on v1 already. If that's really intended, please add a clarifying comment to the POWERSAVE block. > + epp = CPPC_ENERGY_PERF_BALANCE; > + break; > + > + case XEN_SYSCTL_CPPC_SET_PRESET_NONE: > + min_perf = data->caps.lowest_nonlinear_perf; > + max_perf = data->caps.highest_perf; > + break; Similarly I think the use of lowest_nonlinear_perf deserves a comment here. > @@ -551,11 +660,17 @@ static const struct cpufreq_driver > __initconst_cf_clobber amd_cppc_epp_driver = > .exit = amd_cppc_cpufreq_cpu_exit, > }; > > +bool amd_cppc_active(void) > +{ > + return amd_cppc_in_use; > +} > + > int __init amd_cppc_register_driver(void) > { > if ( !cpu_has_cppc ) > return -ENODEV; > > + amd_cppc_in_use = true; Isn't this permature? I.e. wouldn't you better do so only ... > if ( !opt_cpufreq_active ) > return cpufreq_register_driver(&amd_cppc_cpufreq_driver); > else ... after successful driver registration? Jan
|
![]() |
Lists.xenproject.org is hosted with RackSpace, monitoring our |