Re: [RFC PATCH 6/6] cpufreq: add kvm-cpufreq driver

From: Peter Zijlstra
Date: Wed Apr 05 2023 - 04:23:15 EST


On Thu, Mar 30, 2023 at 03:43:41PM -0700, David Dai wrote:

> +struct remote_data {
> + int ret;
> + struct cpufreq_frequency_table *table;
> +};
> +
> +static void remote_get_freqtbl_num_entries(void *data)
> +{
> + struct arm_smccc_res hvc_res;
> + u32 freq = 1UL;
> + int *idx = data;
> +
> + while (freq != CPUFREQ_TABLE_END) {
> + arm_smccc_1_1_invoke(ARM_SMCCC_VENDOR_HYP_KVM_GET_CPUFREQ_TBL_FUNC_ID,
> + *idx, &hvc_res);
> + if (hvc_res.a0) {
> + *idx = -ENODEV;
> + return;
> + }
> + freq = hvc_res.a1;
> + (*idx)++;
> + }
> +}
> +
> +static int kvm_cpufreq_get_freqtbl_num_entries(int cpu)
> +{
> + int num_entries = 0;
> +
> + smp_call_function_single(cpu, remote_get_freqtbl_num_entries, &num_entries, true);
> + return num_entries;
> +}
> +
> +static void remote_populate_freqtbl(void *data)
> +{
> + struct arm_smccc_res hvc_res;
> + struct remote_data *freq_data = data;
> + struct cpufreq_frequency_table *pos;
> + struct cpufreq_frequency_table *table = freq_data->table;
> + int idx;
> +
> + cpufreq_for_each_entry_idx(pos, table, idx) {
> + arm_smccc_1_1_invoke(ARM_SMCCC_VENDOR_HYP_KVM_GET_CPUFREQ_TBL_FUNC_ID,
> + idx, &hvc_res);
> + if (hvc_res.a0) {
> + freq_data->ret = -ENODEV;
> + return;
> + }
> + pos->frequency = hvc_res.a1;
> + }
> + freq_data->ret = 0;
> +}
> +
> +static int kvm_cpufreq_populate_freqtbl(struct cpufreq_frequency_table *table, int cpu)
> +{
> + struct remote_data freq_data;
> +
> + freq_data.table = table;
> + smp_call_function_single(cpu, remote_populate_freqtbl, &freq_data, true);
> + return freq_data.ret;
> +}

*WHY* are you sending IPIs to do a hypercall ?!?

You can simply have the hypercall tell what vCPU you're doing this for.