Re: [PATCH] hwmon: (fam15h_power) Disable preemption when reading registers

From: Thomas Gleixner
Date: Thu Jun 02 2016 - 03:50:15 EST


On Thu, 2 Jun 2016, Borislav Petkov wrote:
> static int read_registers(struct fam15h_power_data *data)
> {
> - int this_cpu, ret, cpu;
> int core, this_core;
> cpumask_var_t mask;
> + int ret, cpu;
>
> ret = zalloc_cpumask_var(&mask, GFP_KERNEL);
> if (!ret)
> @@ -183,7 +183,6 @@ static int read_registers(struct fam15h_power_data *data)
> memset(data->cu_on, 0, sizeof(int) * MAX_CUS);
>
> get_online_cpus();
> - this_cpu = smp_processor_id();
>
> /*
> * Choose the first online core of each compute unit, and then
> @@ -205,10 +204,13 @@ static int read_registers(struct fam15h_power_data *data)
> cpumask_set_cpu(cpumask_any(topology_sibling_cpumask(cpu)), mask);
> }
>
> - if (cpumask_test_cpu(this_cpu, mask))
> + preempt_disable();
> + smp_call_function_many(mask, do_read_registers_on_cu, data, true);
> +
> + if (cpumask_test_cpu(smp_processor_id(), mask))
> do_read_registers_on_cu(data);
>
> - smp_call_function_many(mask, do_read_registers_on_cu, data, true);
> + preempt_enable();
> put_online_cpus();

What's wrong with using:

on_each_cpu_mask()

Which does all that magic for you?

Thanks,

tglx