On Mon, Aug 31, 2015 at 03:25:35PM +0200, Peter Zijlstra wrote: > On Thu, Aug 27, 2015 at 04:07:43PM +0800, Huang Rui wrote: > > +static ssize_t show_power_acc(struct device *dev, > > + struct device_attribute *attr, char *buf) > > +{ > > + int cpu, cu, cu_num, cores_per_cu; > > + u64 curr_cu_acc_power[MAX_CUS], > > + curr_ptsc[MAX_CUS], jdelta[MAX_CUS]; > > + u64 tdelta, avg_acc; > > + struct fam15h_power_data *data = dev_get_drvdata(dev); > > + > > + cores_per_cu = amd_get_cores_per_cu(); > > + cu_num = boot_cpu_data.x86_max_cores / cores_per_cu; > > + > > + for (cpu = 0, avg_acc = 0; cpu < cu_num * cores_per_cu; cpu += cores_per_cu) { > > + cu = cpu / cores_per_cu; > > + if (rdmsrl_safe_on_cpu(cpu, MSR_F15H_PTSC, &curr_ptsc[cu])) { > > + pr_err("Failed to read PTSC counter MSR on core%d\n", > > + cpu); > > + return 0; > > + } > > + > > + if (rdmsrl_safe_on_cpu(cpu, MSR_F15H_CU_PWR_ACCUMULATOR, > > + &curr_cu_acc_power[cu])) { > > + pr_err("Failed to read compute unit power accumulator MSR on core%d\n", > > + cpu); > > + return 0; > > + } > > + > > + if (curr_cu_acc_power[cu] < data->cu_acc_power[cu]) { > > + jdelta[cu] = data->max_cu_acc_power + curr_cu_acc_power[cu]; > > + jdelta[cu] -= data->cu_acc_power[cu]; > > + } else { > > + jdelta[cu] = curr_cu_acc_power[cu] - data->cu_acc_power[cu]; > > + } > > + tdelta = curr_ptsc[cu] - data->cpu_sw_pwr_ptsc[cu]; > > + jdelta[cu] *= data->cpu_pwr_sample_ratio * 1000; > > + do_div(jdelta[cu], tdelta); > > + > > + mutex_lock(&data->acc_pwr_mutex); > > + data->cu_acc_power[cu] = curr_cu_acc_power[cu]; > > + data->cpu_sw_pwr_ptsc[cu] = curr_ptsc[cu]; > > + mutex_unlock(&data->acc_pwr_mutex); > > + > > + /* the unit is microWatt */ > > + avg_acc += jdelta[cu]; > > + } > > + > > + return sprintf(buf, "%u\n", (unsigned int) avg_acc); > > +} > > +static DEVICE_ATTR(power1_acc, S_IRUGO, show_power_acc, NULL); > > This is a world readable file that sprays IPIs across the entire system, > how is that a good idea? FWIW this driver is also hotplug challenged. Not to mention it relies on cpu number layout in unhealthy ways. _______________________________________________ lm-sensors mailing list lm-sensors@xxxxxxxxxxxxxx http://lists.lm-sensors.org/mailman/listinfo/lm-sensors