Commit 6b0c0c83 authored by Akshay Gupta's avatar Akshay Gupta Committed by Guenter Roeck

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: default avatarAkshay Gupta <Akshay.Gupta@amd.com>
Link: https://lore.kernel.org/r/20200929105322.8919-2-nchatrad@amd.comSigned-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent df885d91
...@@ -35,7 +35,6 @@ ...@@ -35,7 +35,6 @@
struct sensor_accumulator { struct sensor_accumulator {
u64 energy_ctr; u64 energy_ctr;
u64 prev_value; u64 prev_value;
char label[10];
}; };
struct amd_energy_data { struct amd_energy_data {
...@@ -52,6 +51,7 @@ struct amd_energy_data { ...@@ -52,6 +51,7 @@ struct amd_energy_data {
int nr_cpus; int nr_cpus;
int nr_socks; int nr_socks;
int core_id; int core_id;
char (*label)[10];
}; };
static int amd_energy_read_labels(struct device *dev, static int amd_energy_read_labels(struct device *dev,
...@@ -61,7 +61,7 @@ static int amd_energy_read_labels(struct device *dev, ...@@ -61,7 +61,7 @@ static int amd_energy_read_labels(struct device *dev,
{ {
struct amd_energy_data *data = dev_get_drvdata(dev); struct amd_energy_data *data = dev_get_drvdata(dev);
*str = data->accums[channel].label; *str = data->label[channel];
return 0; return 0;
} }
...@@ -253,6 +253,7 @@ static int amd_create_sensor(struct device *dev, ...@@ -253,6 +253,7 @@ static int amd_create_sensor(struct device *dev,
struct sensor_accumulator *accums; struct sensor_accumulator *accums;
int i, num_siblings, cpus, sockets; int i, num_siblings, cpus, sockets;
u32 *s_config; u32 *s_config;
char (*label_l)[10];
/* Identify the number of siblings per core */ /* Identify the number of siblings per core */
num_siblings = ((cpuid_ebx(0x8000001e) >> 8) & 0xff) + 1; num_siblings = ((cpuid_ebx(0x8000001e) >> 8) & 0xff) + 1;
...@@ -276,21 +277,25 @@ static int amd_create_sensor(struct device *dev, ...@@ -276,21 +277,25 @@ static int amd_create_sensor(struct device *dev,
if (!accums) if (!accums)
return -ENOMEM; return -ENOMEM;
label_l = devm_kcalloc(dev, cpus + sockets,
sizeof(*label_l), GFP_KERNEL);
if (!label_l)
return -ENOMEM;
info->type = type; info->type = type;
info->config = s_config; info->config = s_config;
data->nr_cpus = cpus; data->nr_cpus = cpus;
data->nr_socks = sockets; data->nr_socks = sockets;
data->accums = accums; data->accums = accums;
data->label = label_l;
for (i = 0; i < cpus + sockets; i++) { for (i = 0; i < cpus + sockets; i++) {
s_config[i] = config; s_config[i] = config;
if (i < cpus) if (i < cpus)
scnprintf(accums[i].label, 10, scnprintf(label_l[i], 10, "Ecore%03u", i);
"Ecore%03u", i);
else else
scnprintf(accums[i].label, 10, scnprintf(label_l[i], 10, "Esocket%u", (i - cpus));
"Esocket%u", (i - cpus));
} }
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment