From: "Cédric Le Goater" <clg@fr.ibm.com>
To: lm-sensors@lm-sensors.org
Cc: "Stewart Smith" <stewart@linux.vnet.ibm.com>,
"Cédric Le Goater" <clg@fr.ibm.com>,
"Jean Delvare" <jdelvare@suse.de>,
"Neelesh Gupta" <neelegup@linux.vnet.ibm.com>,
skiboot@lists.ozlabs.org, linuxppc-dev@lists.ozlabs.org,
"Guenter Roeck" <linux@roeck-us.net>
Subject: [PATCH v4] hwmon: (ibmpowernv) pretty print labels
Date: Wed, 8 Apr 2015 15:42:07 +0200 [thread overview]
Message-ID: <1428500527-7833-1-git-send-email-clg@fr.ibm.com> (raw)
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 v3:
- removed error message in case of an unknown physical cpu number
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 | 41 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 41 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,52 @@ 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;
+
+ 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,
next reply other threads:[~2015-04-08 13:42 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-08 13:42 Cédric Le Goater [this message]
2015-04-08 15:21 ` [v4] hwmon: (ibmpowernv) pretty print labels Guenter Roeck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1428500527-7833-1-git-send-email-clg@fr.ibm.com \
--to=clg@fr.ibm.com \
--cc=jdelvare@suse.de \
--cc=linux@roeck-us.net \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=lm-sensors@lm-sensors.org \
--cc=neelegup@linux.vnet.ibm.com \
--cc=skiboot@lists.ozlabs.org \
--cc=stewart@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).