From patchwork Mon Nov 20 23:53:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eddie James X-Patchwork-Id: 10067465 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5A9F6601C2 for ; Mon, 20 Nov 2017 23:54:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A88F291DA for ; Mon, 20 Nov 2017 23:54:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3F5CA291E9; Mon, 20 Nov 2017 23:54:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD052291DA for ; Mon, 20 Nov 2017 23:54:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752526AbdKTXyq (ORCPT ); Mon, 20 Nov 2017 18:54:46 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:35398 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752228AbdKTXyK (ORCPT ); Mon, 20 Nov 2017 18:54:10 -0500 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAKNnRtM120380 for ; Mon, 20 Nov 2017 18:54:08 -0500 Received: from e38.co.us.ibm.com (e38.co.us.ibm.com [32.97.110.159]) by mx0b-001b2d01.pphosted.com with ESMTP id 2ec7bw43bf-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 20 Nov 2017 18:54:08 -0500 Received: from localhost by e38.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 20 Nov 2017 16:54:07 -0700 Received: from b03cxnp07029.gho.boulder.ibm.com (9.17.130.16) by e38.co.us.ibm.com (192.168.1.138) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 20 Nov 2017 16:54:05 -0700 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAKNs49q6226256; Mon, 20 Nov 2017 16:54:04 -0700 Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8D856BE040; Mon, 20 Nov 2017 16:54:04 -0700 (MST) Received: from oc3016140333.ibm.com (unknown [9.41.174.252]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP id ECA9FBE03E; Mon, 20 Nov 2017 16:54:03 -0700 (MST) From: Eddie James 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" Subject: [PATCH v3 12/12] hwmon (occ): Add sysfs notification for errors and throttling Date: Mon, 20 Nov 2017 17:53:41 -0600 X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1511222021-562-1-git-send-email-eajames@linux.vnet.ibm.com> References: <1511222021-562-1-git-send-email-eajames@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17112023-0028-0000-0000-000008B04090 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008101; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000240; SDB=6.00948827; UDB=6.00479139; IPR=6.00729107; BA=6.00005702; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018113; XFM=3.00000015; UTC=2017-11-20 23:54:07 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17112023-0029-0000-0000-0000386A88F3 Message-Id: <1511222021-562-13-git-send-email-eajames@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-11-20_12:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711200318 Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: "Edward A. James" 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 --- 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);