From: Eddie James <eajames@linux.vnet.ibm.com>
To: linux-kernel@vger.kernel.org
Cc: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org,
linux-doc@vger.kernel.org, linux@roeck-us.net, jdelvare@suse.com,
corbet@lwn.net, mark.rutland@arm.com, robh+dt@kernel.org,
joel@jms.id.au, eajames@linux.vnet.ibm.com,
"Edward A. James" <eajames@us.ibm.com>
Subject: [PATCH v3 12/12] hwmon (occ): Add sysfs notification for errors and throttling
Date: Mon, 20 Nov 2017 17:53:41 -0600 [thread overview]
Message-ID: <1511222021-562-13-git-send-email-eajames@linux.vnet.ibm.com> (raw)
In-Reply-To: <1511222021-562-1-git-send-email-eajames@linux.vnet.ibm.com>
From: "Edward A. James" <eajames@us.ibm.com>
In order to aid application usage of the error, throttling, and
presence count properties, use sysfs_notify to notify users of change on
these attributes.
Signed-off-by: Edward A. James <eajames@us.ibm.com>
---
drivers/hwmon/occ/common.c | 53 ++++++++++++++++++++++++++++++++++++++++++++--
drivers/hwmon/occ/common.h | 5 +++++
2 files changed, 56 insertions(+), 2 deletions(-)
diff --git a/drivers/hwmon/occ/common.c b/drivers/hwmon/occ/common.c
index 7a0606d..7c97a4c 100644
--- a/drivers/hwmon/occ/common.c
+++ b/drivers/hwmon/occ/common.c
@@ -146,6 +146,8 @@ static ssize_t occ_show_error(struct device *dev,
static DEVICE_ATTR(occ_error, 0444, occ_show_error, NULL);
+static void occ_sysfs_notify(struct occ *occ);
+
static int occ_poll(struct occ *occ)
{
struct occ_poll_response_header *header;
@@ -169,7 +171,7 @@ static int occ_poll(struct occ *occ)
if (occ->error_count++ > OCC_ERROR_COUNT_THRESHOLD)
occ->error = rc;
- return rc;
+ goto done;
}
/* clear error since communication was successful */
@@ -190,7 +192,9 @@ static int occ_poll(struct occ *occ)
occ->last_safe = 0;
}
- return 0;
+done:
+ occ_sysfs_notify(occ);
+ return rc;
}
static int occ_set_user_power_cap(struct occ *occ, u16 user_power_cap)
@@ -1244,6 +1248,51 @@ static ssize_t occ_show_status(struct device *dev,
.attrs = occ_attributes,
};
+static void occ_sysfs_notify(struct occ *occ)
+{
+ const char *name;
+ struct occ_poll_response_header *header =
+ (struct occ_poll_response_header *)occ->resp.data;
+
+ /* sysfs attributes aren't loaded yet; don't proceed */
+ if (!occ->hwmon)
+ goto done;
+
+ if (header->occs_present != occ->previous_occs_present &&
+ (header->status & OCC_STAT_MASTER)) {
+ name = sensor_dev_attr_occs_present.dev_attr.attr.name;
+ sysfs_notify(&occ->bus_dev->kobj, NULL, name);
+ }
+
+ if ((header->ext_status & OCC_EXT_STAT_DVFS_OT) !=
+ (occ->previous_ext_status & OCC_EXT_STAT_DVFS_OT)) {
+ name = sensor_dev_attr_occ_dvfs_ot.dev_attr.attr.name;
+ sysfs_notify(&occ->bus_dev->kobj, NULL, name);
+ }
+
+ if ((header->ext_status & OCC_EXT_STAT_DVFS_POWER) !=
+ (occ->previous_ext_status & OCC_EXT_STAT_DVFS_POWER)) {
+ name = sensor_dev_attr_occ_dvfs_power.dev_attr.attr.name;
+ sysfs_notify(&occ->bus_dev->kobj, NULL, name);
+ }
+
+ if ((header->ext_status & OCC_EXT_STAT_MEM_THROTTLE) !=
+ (occ->previous_ext_status & OCC_EXT_STAT_MEM_THROTTLE)) {
+ name = sensor_dev_attr_occ_mem_throttle.dev_attr.attr.name;
+ sysfs_notify(&occ->bus_dev->kobj, NULL, name);
+ }
+
+ if (occ->error && occ->error != occ->previous_error) {
+ name = dev_attr_occ_error.attr.name;
+ sysfs_notify(&occ->bus_dev->kobj, NULL, name);
+ }
+
+done:
+ occ->previous_error = occ->error;
+ occ->previous_ext_status = header->ext_status;
+ occ->previous_occs_present = header->occs_present;
+}
+
/* only need to do this once at startup, as OCC won't change sensors on us */
static void occ_parse_poll_response(struct occ *occ)
{
diff --git a/drivers/hwmon/occ/common.h b/drivers/hwmon/occ/common.h
index cef2174..ffc809f 100644
--- a/drivers/hwmon/occ/common.h
+++ b/drivers/hwmon/occ/common.h
@@ -111,6 +111,11 @@ struct occ {
int error;
unsigned int error_count; /* number of errors observed */
unsigned long last_safe; /* time OCC entered safe state */
+
+ /* store previous poll state to compare; notify sysfs on change */
+ int previous_error;
+ u8 previous_ext_status;
+ u8 previous_occs_present;
};
int occ_setup(struct occ *occ, const char *name);
--
1.8.3.1
prev parent reply other threads:[~2017-11-20 23:53 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-20 23:53 [PATCH v3 00/12] hwmon: Add On-Chip Controller hwmon driver Eddie James
2017-11-20 23:53 ` [PATCH v3 01/12] Documentation: hwmon: Add OCC documentation Eddie James
2017-11-20 23:53 ` [PATCH v3 02/12] Documentation: ABI: Add occ-hwmon driver sysfs documentation Eddie James
2017-11-22 15:15 ` [v3, " Guenter Roeck
2017-11-20 23:53 ` [PATCH v3 03/12] dt-bindings: i2c: Add P8 OCC hwmon device documentation Eddie James
2017-11-21 18:34 ` Rob Herring
2017-11-20 23:53 ` [PATCH v3 04/12] dt-bindings: fsi: Add P9 " Eddie James
[not found] ` <1511222021-562-5-git-send-email-eajames-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2017-11-21 18:36 ` Rob Herring
2017-11-20 23:53 ` [PATCH v3 05/12] hwmon: Add On-Chip Controller (OCC) hwmon driver Eddie James
2017-11-20 23:53 ` [PATCH v3 07/12] hwmon (occ): Parse OCC poll response Eddie James
2017-11-20 23:53 ` [PATCH v3 08/12] hwmon (occ): Add sensor types and versions Eddie James
2017-11-20 23:53 ` [PATCH v3 09/12] hwmon (occ): Add sensor attributes and register hwmon device Eddie James
2017-11-22 15:22 ` [v3, " Guenter Roeck
[not found] ` <1511222021-562-1-git-send-email-eajames-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2017-11-20 23:53 ` [PATCH v3 06/12] hwmon (occ): Add command transport method for P8 and P9 Eddie James
2017-11-20 23:53 ` [PATCH v3 10/12] hwmon (occ): Add non-hwmon attributes Eddie James
[not found] ` <1511222021-562-11-git-send-email-eajames-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
2017-11-22 15:23 ` [v3,10/12] " Guenter Roeck
2017-11-20 23:53 ` [PATCH v3 11/12] hwmon (occ): Add error handling Eddie James
2017-11-20 23:53 ` Eddie James [this message]
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=1511222021-562-13-git-send-email-eajames@linux.vnet.ibm.com \
--to=eajames@linux.vnet.ibm.com \
--cc=corbet@lwn.net \
--cc=devicetree@vger.kernel.org \
--cc=eajames@us.ibm.com \
--cc=jdelvare@suse.com \
--cc=joel@jms.id.au \
--cc=linux-doc@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=mark.rutland@arm.com \
--cc=robh+dt@kernel.org \
/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).