Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: (amd_energy) Move label out of accumulation structure

At present, core & socket labels are defined in struct sensor_accumulator
This patch moves it to the amd_energy_data structure, which will
help in calling memset on struct sensor_accumulator to optimize the code.

Signed-off-by: Akshay Gupta <Akshay.Gupta@amd.com>
Link: https://lore.kernel.org/r/20200929105322.8919-2-nchatrad@amd.com
Signed-off-by: Guenter Roeck <linux@roeck-us.net>

authored by

Akshay Gupta and committed by
Guenter Roeck
6b0c0c83 df885d91

+11 -6
+11 -6
drivers/hwmon/amd_energy.c
··· 35 35 struct sensor_accumulator { 36 36 u64 energy_ctr; 37 37 u64 prev_value; 38 - char label[10]; 39 38 }; 40 39 41 40 struct amd_energy_data { ··· 51 52 int nr_cpus; 52 53 int nr_socks; 53 54 int core_id; 55 + char (*label)[10]; 54 56 }; 55 57 56 58 static int amd_energy_read_labels(struct device *dev, ··· 61 61 { 62 62 struct amd_energy_data *data = dev_get_drvdata(dev); 63 63 64 - *str = data->accums[channel].label; 64 + *str = data->label[channel]; 65 65 return 0; 66 66 } 67 67 ··· 253 253 struct sensor_accumulator *accums; 254 254 int i, num_siblings, cpus, sockets; 255 255 u32 *s_config; 256 + char (*label_l)[10]; 256 257 257 258 /* Identify the number of siblings per core */ 258 259 num_siblings = ((cpuid_ebx(0x8000001e) >> 8) & 0xff) + 1; ··· 277 276 if (!accums) 278 277 return -ENOMEM; 279 278 279 + label_l = devm_kcalloc(dev, cpus + sockets, 280 + sizeof(*label_l), GFP_KERNEL); 281 + if (!label_l) 282 + return -ENOMEM; 283 + 280 284 info->type = type; 281 285 info->config = s_config; 282 286 283 287 data->nr_cpus = cpus; 284 288 data->nr_socks = sockets; 285 289 data->accums = accums; 290 + data->label = label_l; 286 291 287 292 for (i = 0; i < cpus + sockets; i++) { 288 293 s_config[i] = config; 289 294 if (i < cpus) 290 - scnprintf(accums[i].label, 10, 291 - "Ecore%03u", i); 295 + scnprintf(label_l[i], 10, "Ecore%03u", i); 292 296 else 293 - scnprintf(accums[i].label, 10, 294 - "Esocket%u", (i - cpus)); 297 + scnprintf(label_l[i], 10, "Esocket%u", (i - cpus)); 295 298 } 296 299 297 300 return 0;