* [PATCH v3] hwmon: (ibmpowernv) pretty print labels
@ 2015-04-08 7:00 Cédric Le Goater
2015-04-08 13:26 ` Guenter Roeck
0 siblings, 1 reply; 3+ messages in thread
From: Cédric Le Goater @ 2015-04-08 7:00 UTC (permalink / raw)
To: lm-sensors
Cc: Stewart Smith, Cédric Le Goater, Jean Delvare, Neelesh Gupta,
skiboot, linuxppc-dev, Guenter Roeck
The new OPAL device tree adds a few properties which can be used to add
extra information on the sensor label.
In the case of a cpu core sensor, the firmware exposes the physical
identifier of the core in the "ibm,pir" property. The driver
translates this identifier in a linux cpu number and prints out a
range corresponding to the hardware threads of the core (as they
share the same sensor).
The numbering gives a hint on the localization of the core in the
system (which socket, which chip).
Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
---
Changes since v2:
- fix bogus logical cpu retrieval
- use 'threads_per_core' to print out cpu range
Changes since v1:
- check cpu validity before printing out the attribute label.
if invalid, use a "phy" prefix to distinguish a linux cpu
number from a physical cpu number.
drivers/hwmon/ibmpowernv.c | 43 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 43 insertions(+)
Index: linux.git/drivers/hwmon/ibmpowernv.c
===================================================================
--- linux.git.orig/drivers/hwmon/ibmpowernv.c
+++ linux.git/drivers/hwmon/ibmpowernv.c
@@ -30,6 +30,7 @@
#include <linux/platform_device.h>
#include <asm/opal.h>
#include <linux/err.h>
+#include <asm/cputhreads.h>
#define MAX_ATTR_LEN 32
#define MAX_LABEL_LEN 64
@@ -110,12 +111,54 @@ static ssize_t show_label(struct device
return sprintf(buf, "%s\n", sdata->label);
}
+static int __init get_logical_cpu(unsigned int hwcpu)
+{
+ int cpu;
+
+ for_each_possible_cpu(cpu)
+ if (get_hard_smp_processor_id(cpu) == hwcpu)
+ return cpu;
+
+ pr_err("%s: could not find a cpu with physical id 0x%x\n",
+ __func__, hwcpu);
+ return -ENOENT;
+}
+
static void __init make_sensor_label(struct device_node *np,
struct sensor_data *sdata, const char *label)
{
+ u32 id;
size_t n;
n = snprintf(sdata->label, sizeof(sdata->label), "%s", label);
+
+ /*
+ * Core temp pretty print
+ */
+ if (!of_property_read_u32(np, "ibm,pir", &id)) {
+ int cpuid = get_logical_cpu(id);
+
+ if (cpuid >= 0)
+ /*
+ * The digital thermal sensors are associated
+ * with a core. Let's print out the range of
+ * cpu ids corresponding to the hardware
+ * threads of the core.
+ */
+ n += snprintf(sdata->label + n,
+ sizeof(sdata->label) - n, " %d-%d",
+ cpuid, cpuid + threads_per_core - 1);
+ else
+ n += snprintf(sdata->label + n,
+ sizeof(sdata->label) - n, " phy%d", id);
+ }
+
+ /*
+ * Membuffer pretty print
+ */
+ if (!of_property_read_u32(np, "ibm,chip-id", &id))
+ n += snprintf(sdata->label + n, sizeof(sdata->label) - n,
+ " %d", id & 0xffff);
}
static int get_sensor_index_attr(const char *name, u32 *index,
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] hwmon: (ibmpowernv) pretty print labels
2015-04-08 7:00 [PATCH v3] hwmon: (ibmpowernv) pretty print labels Cédric Le Goater
@ 2015-04-08 13:26 ` Guenter Roeck
2015-04-08 13:33 ` Cedric Le Goater
0 siblings, 1 reply; 3+ messages in thread
From: Guenter Roeck @ 2015-04-08 13:26 UTC (permalink / raw)
To: Cédric Le Goater, lm-sensors
Cc: Stewart Smith, Neelesh Gupta, skiboot, linuxppc-dev, Jean Delvare
On 04/08/2015 12:00 AM, Cédric Le Goater wrote:
> The new OPAL device tree adds a few properties which can be used to add
> extra information on the sensor label.
>
> In the case of a cpu core sensor, the firmware exposes the physical
> identifier of the core in the "ibm,pir" property. The driver
> translates this identifier in a linux cpu number and prints out a
> range corresponding to the hardware threads of the core (as they
> share the same sensor).
>
> The numbering gives a hint on the localization of the core in the
> system (which socket, which chip).
>
> Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
> ---
>
> Changes since v2:
>
> - fix bogus logical cpu retrieval
> - use 'threads_per_core' to print out cpu range
>
> Changes since v1:
>
> - check cpu validity before printing out the attribute label.
> if invalid, use a "phy" prefix to distinguish a linux cpu
> number from a physical cpu number.
>
> drivers/hwmon/ibmpowernv.c | 43 +++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 43 insertions(+)
>
> Index: linux.git/drivers/hwmon/ibmpowernv.c
> ===================================================================
> --- linux.git.orig/drivers/hwmon/ibmpowernv.c
> +++ linux.git/drivers/hwmon/ibmpowernv.c
> @@ -30,6 +30,7 @@
> #include <linux/platform_device.h>
> #include <asm/opal.h>
> #include <linux/err.h>
> +#include <asm/cputhreads.h>
>
> #define MAX_ATTR_LEN 32
> #define MAX_LABEL_LEN 64
> @@ -110,12 +111,54 @@ static ssize_t show_label(struct device
> return sprintf(buf, "%s\n", sdata->label);
> }
>
> +static int __init get_logical_cpu(unsigned int hwcpu)
> +{
> + int cpu;
> +
> + for_each_possible_cpu(cpu)
> + if (get_hard_smp_processor_id(cpu) == hwcpu)
> + return cpu;
> +
> + pr_err("%s: could not find a cpu with physical id 0x%x\n",
> + __func__, hwcpu);
I like moving this into a function, but I really dislike this error
message. If the devicetree data is wrong/bad, the log and the console
will be clogged with that message. And the user will not be able
to do anything about it.
Guenter
> + return -ENOENT;
> +}
> +
> static void __init make_sensor_label(struct device_node *np,
> struct sensor_data *sdata, const char *label)
> {
> + u32 id;
> size_t n;
>
> n = snprintf(sdata->label, sizeof(sdata->label), "%s", label);
> +
> + /*
> + * Core temp pretty print
> + */
> + if (!of_property_read_u32(np, "ibm,pir", &id)) {
> + int cpuid = get_logical_cpu(id);
> +
> + if (cpuid >= 0)
> + /*
> + * The digital thermal sensors are associated
> + * with a core. Let's print out the range of
> + * cpu ids corresponding to the hardware
> + * threads of the core.
> + */
> + n += snprintf(sdata->label + n,
> + sizeof(sdata->label) - n, " %d-%d",
> + cpuid, cpuid + threads_per_core - 1);
> + else
> + n += snprintf(sdata->label + n,
> + sizeof(sdata->label) - n, " phy%d", id);
> + }
> +
> + /*
> + * Membuffer pretty print
> + */
> + if (!of_property_read_u32(np, "ibm,chip-id", &id))
> + n += snprintf(sdata->label + n, sizeof(sdata->label) - n,
> + " %d", id & 0xffff);
> }
>
> static int get_sensor_index_attr(const char *name, u32 *index,
>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3] hwmon: (ibmpowernv) pretty print labels
2015-04-08 13:26 ` Guenter Roeck
@ 2015-04-08 13:33 ` Cedric Le Goater
0 siblings, 0 replies; 3+ messages in thread
From: Cedric Le Goater @ 2015-04-08 13:33 UTC (permalink / raw)
To: Guenter Roeck, lm-sensors
Cc: Stewart Smith, Neelesh Gupta, skiboot, linuxppc-dev, Jean Delvare
On 04/08/2015 03:26 PM, Guenter Roeck wrote:
> On 04/08/2015 12:00 AM, Cédric Le Goater wrote:
>> The new OPAL device tree adds a few properties which can be used to add
>> extra information on the sensor label.
>>
>> In the case of a cpu core sensor, the firmware exposes the physical
>> identifier of the core in the "ibm,pir" property. The driver
>> translates this identifier in a linux cpu number and prints out a
>> range corresponding to the hardware threads of the core (as they
>> share the same sensor).
>>
>> The numbering gives a hint on the localization of the core in the
>> system (which socket, which chip).
>>
>> Signed-off-by: Cédric Le Goater <clg@fr.ibm.com>
>> ---
>>
>> Changes since v2:
>>
>> - fix bogus logical cpu retrieval
>> - use 'threads_per_core' to print out cpu range
>>
>> Changes since v1:
>>
>> - check cpu validity before printing out the attribute label.
>> if invalid, use a "phy" prefix to distinguish a linux cpu
>> number from a physical cpu number.
>>
>> drivers/hwmon/ibmpowernv.c | 43 +++++++++++++++++++++++++++++++++++++++++++
>> 1 file changed, 43 insertions(+)
>>
>> Index: linux.git/drivers/hwmon/ibmpowernv.c
>> ===================================================================
>> --- linux.git.orig/drivers/hwmon/ibmpowernv.c
>> +++ linux.git/drivers/hwmon/ibmpowernv.c
>> @@ -30,6 +30,7 @@
>> #include <linux/platform_device.h>
>> #include <asm/opal.h>
>> #include <linux/err.h>
>> +#include <asm/cputhreads.h>
>>
>> #define MAX_ATTR_LEN 32
>> #define MAX_LABEL_LEN 64
>> @@ -110,12 +111,54 @@ static ssize_t show_label(struct device
>> return sprintf(buf, "%s\n", sdata->label);
>> }
>>
>> +static int __init get_logical_cpu(unsigned int hwcpu)
>> +{
>> + int cpu;
>> +
>> + for_each_possible_cpu(cpu)
>> + if (get_hard_smp_processor_id(cpu) == hwcpu)
>> + return cpu;
>> +
>> + pr_err("%s: could not find a cpu with physical id 0x%x\n",
>> + __func__, hwcpu);
>
> I like moving this into a function, but I really dislike this error
> message. If the devicetree data is wrong/bad, the log and the console
> will be clogged with that message. And the user will not be able
> to do anything about it.
yes. It is not super useful anyway and it is redundant with the "phy"
prefix below. Do you want me to kill it in a v4 ?
Thanks,
C.
>
> Guenter
>
>> + return -ENOENT;
>> +}
>> +
>> static void __init make_sensor_label(struct device_node *np,
>> struct sensor_data *sdata, const char *label)
>> {
>> + u32 id;
>> size_t n;
>>
>> n = snprintf(sdata->label, sizeof(sdata->label), "%s", label);
>> +
>> + /*
>> + * Core temp pretty print
>> + */
>> + if (!of_property_read_u32(np, "ibm,pir", &id)) {
>> + int cpuid = get_logical_cpu(id);
>> +
>> + if (cpuid >= 0)
>> + /*
>> + * The digital thermal sensors are associated
>> + * with a core. Let's print out the range of
>> + * cpu ids corresponding to the hardware
>> + * threads of the core.
>> + */
>> + n += snprintf(sdata->label + n,
>> + sizeof(sdata->label) - n, " %d-%d",
>> + cpuid, cpuid + threads_per_core - 1);
>> + else
>> + n += snprintf(sdata->label + n,
>> + sizeof(sdata->label) - n, " phy%d", id);
>> + }
>> +
>> + /*
>> + * Membuffer pretty print
>> + */
>> + if (!of_property_read_u32(np, "ibm,chip-id", &id))
>> + n += snprintf(sdata->label + n, sizeof(sdata->label) - n,
>> + " %d", id & 0xffff);
>> }
>>
>> static int get_sensor_index_attr(const char *name, u32 *index,
>>
>>
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2015-04-08 13:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-08 7:00 [PATCH v3] hwmon: (ibmpowernv) pretty print labels Cédric Le Goater
2015-04-08 13:26 ` Guenter Roeck
2015-04-08 13:33 ` Cedric Le Goater
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).