From patchwork Fri Dec 15 07:21:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Shilpasri G Bhat X-Patchwork-Id: 849002 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yyhhB6zt5z9ryQ for ; Fri, 15 Dec 2017 18:22:02 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3yyhhB5YGfzDrmx for ; Fri, 15 Dec 2017 18:22:02 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=shilpa.bhat@linux.vnet.ibm.com; receiver=) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3yyhgT2SJzzDrnH for ; Fri, 15 Dec 2017 18:21:25 +1100 (AEDT) Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vBF7Jj6u057620 for ; Fri, 15 Dec 2017 02:21:22 -0500 Received: from e06smtp13.uk.ibm.com (e06smtp13.uk.ibm.com [195.75.94.109]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ev7xpmk2t-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Fri, 15 Dec 2017 02:21:22 -0500 Received: from localhost by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 15 Dec 2017 07:21:19 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp13.uk.ibm.com (192.168.101.143) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Fri, 15 Dec 2017 07:21:17 -0000 Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com [9.149.105.59]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vBF7LHHo34144348; Fri, 15 Dec 2017 07:21:17 GMT Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 73F96A4040; Fri, 15 Dec 2017 07:15:34 +0000 (GMT) Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C753DA404D; Fri, 15 Dec 2017 07:15:33 +0000 (GMT) Received: from oc4502181600.ibm.com (unknown [9.79.203.247]) by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 15 Dec 2017 07:15:33 +0000 (GMT) From: Shilpasri G Bhat To: skiboot@lists.ozlabs.org Date: Fri, 15 Dec 2017 12:51:02 +0530 X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1513322463-24801-1-git-send-email-shilpa.bhat@linux.vnet.ibm.com> References: <1513322463-24801-1-git-send-email-shilpa.bhat@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 17121507-0012-0000-0000-000005996416 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17121507-0013-0000-0000-000019148294 Message-Id: <1513322463-24801-4-git-send-email-shilpa.bhat@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-12-15_03:, , 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-1712150105 Subject: [Skiboot] [PATCH V2 3/4] sensors: occ: Scale the sensor values X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.24 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Scale the sensor values appropriately to match the HWMON requirements. OCC sensor values should be scaled as per "scale_factor' field and then converted to HWMON required unit. Sensors like temperature and power are already scaled by the kernel driver which convert the values to millidegree Celsius and microWatt respectively. So apart from temperature and power the remaining sensors are converted to HWMON standards. Signed-off-by: Shilpasri G Bhat --- hw/occ-sensor.c | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 107 insertions(+), 4 deletions(-) diff --git a/hw/occ-sensor.c b/hw/occ-sensor.c index eb9c7cf..bc5085a 100644 --- a/hw/occ-sensor.c +++ b/hw/occ-sensor.c @@ -275,32 +275,80 @@ enum sensor_attr { OCC_SENSOR_TYPE_TEMPERATURE | \ OCC_SENSOR_TYPE_POWER) +/* + * Standard HWMON linux interface expects the below units for the + * environment sensors: + * - Current : milliampere + * - Voltage : millivolt + * - Temperature : millidegree Celsius (scaled in kernel) + * - Power : microWatt (scaled in kernel) + * - Energy : microJoule + */ + +/* + * OCC sensor units are obtained after scaling the sensor values. + * https://github.com/open-power/occ/blob/master/src/occ_405/sensor/sensor_info.c + */ + static struct str_map { const char *occ_str; const char *opal_str; } str_maps[] = { {"PWRSYS", "System"}, + /* Bulk power of the system: Watt */ {"PWRFAN", "Fan"}, + /* Power consumption of the system fans: Watt */ {"PWRIO", "IO"}, + /* Power consumption of the IO subsystem: Watt */ {"PWRSTORE", "Storage"}, + /* Power comsumption of the storage subsystem: Watt */ {"PWRGPU", "GPU"}, + /* Power consumption for GPUs per socket read from APSS: Watt */ {"PWRAPSSCH", "APSS"}, + /* Power Provided by APSS channel x (where x=0…15): Watt */ {"PWRPROC", ""}, + /* Power consumption for this Processor: Watt */ {"PWRVDD", "Vdd"}, - {"CURVDD", "Vdd"}, - {"VOLTVDDSENSE", "Vdd Remote Sense"}, - {"VOLTVDD", "Vdd"}, + /* Power consumption for this Processor's Vdd(AVSBus readings): Watt */ {"PWRVDN", "Vdn"}, + /* Power consumption for  this Processor's Vdn (nest) + * Calculated from AVSBus readings: Watt */ + {"PWRMEM", "Memory"}, + /* Power consumption for Memory  for this Processor read from APSS: + * Watt */ + {"CURVDD", "Vdd"}, + /* Processor Vdd Current (read from AVSBus): Ampere */ {"CURVDN", "Vdn"}, + /* Processor Vdn Current (read from AVSBus): Ampere */ + {"VOLTVDDSENSE", "Vdd Remote Sense"}, + /* Vdd Voltage at the remote sense. + * AVS reading adjusted for loadline: millivolt */ {"VOLTVDNSENSE", "Vdn Remote Sense"}, + /* Vdn Voltage at the remote sense. + * AVS reading adjusted for loadline: millivolt */ + {"VOLTVDD", "Vdd"}, + /* Processor Vdd Voltage (read from AVSBus): millivolt */ {"VOLTVDN", "Vdn"}, - {"PWRMEM", "Memory"}, + /* Processor Vdn Voltage (read from AVSBus): millivolt */ {"TEMPC", "Core"}, + /* Average temperature of core DTS sensors for Processor's Core y: + * Celsius */ {"TEMPQ", "Quad"}, + /* Average temperature of quad (in cache) DTS sensors for + * Processor’s Quad y: Celsius */ {"TEMPNEST", "Nest"}, + /* Average temperature of nest DTS sensors: Celsius */ {"TEMPPROCTHRMC", "Core"}, + /* The combined weighted core/quad temperature for processor core y: + * Celsius */ {"TEMPDIMM", "DIMM"}, + /* DIMM temperature for DIMM x: Celsius */ {"TEMPGPU", "GPU"}, + /* GPU x (0..2) board temperature: Celsius */ + /* TEMPGPUxMEM: GPU x hottest HBM temperature (individual memory + * temperatures are not available): Celsius */ + {"TEMPVDD", "VRM VDD"}, + /* VRM Vdd temperature: Celsius */ }; static u64 occ_sensor_base; @@ -323,6 +371,52 @@ static inline u32 sensor_handler(int occ_num, int sensor_id, int attr) return sensor_make_handler(SENSOR_OCC, occ_num, sensor_id, attr); } +/* + * The scaling factor for the sensors is encoded in the below format: + * (((UINT32)mantissa << 8) | (UINT32)((UINT8) 256 + (UINT8)exp)) + * https://github.com/open-power/occ/blob/master/src/occ_405/sensor/sensor.h + */ +static void scale_sensor(struct occ_sensor_name *md, u64 *sensor) +{ + u32 factor = md->scale_factor; + int i; + s8 exp; + + if (md->type == OCC_SENSOR_TYPE_CURRENT) + *sensor *= 1000; //convert to mA + + *sensor *= factor >> 8; + exp = factor & 0xFF; + + if (exp > 0) { + for (i = labs(exp); i > 0; i--) + *sensor *= 10; + } else { + for (i = labs(exp); sensor && i > 0; i--) + *sensor /= 10; + } +} + +static void scale_energy(struct occ_sensor_name *md, u64 *sensor) +{ + u32 factor = md->freq; + int i; + s8 exp; + + *sensor *= 1000000; //convert to uJ + + *sensor /= factor >> 8; + exp = factor & 0xFF; + + if (exp > 0) { + for (i = labs(exp); sensor && i > 0; i--) + *sensor /= 10; + } else { + for (i = labs(exp); i > 0; i--) + *sensor *= 10; + } +} + static u64 read_sensor(struct occ_sensor_record *sensor, int attr) { switch (attr) { @@ -393,6 +487,7 @@ static void *select_sensor_buffer(struct occ_sensor_data_header *hb, int id) int occ_sensor_read(u32 handle, u64 *data) { struct occ_sensor_data_header *hb; + struct occ_sensor_name *md; u16 id = sensor_get_rid(handle); u8 occ_num = sensor_get_frc(handle); u8 attr = sensor_get_attr(handle); @@ -417,6 +512,14 @@ int occ_sensor_read(u32 handle, u64 *data) return OPAL_HARDWARE; *data = read_sensor(buff, attr); + if (!*data) + return OPAL_SUCCESS; + + md = get_names_block(hb); + if (md[id].type == OCC_SENSOR_TYPE_POWER && attr == SENSOR_ACCUMULATOR) + scale_energy(&md[id], data); + else + scale_sensor(&md[id], data); return OPAL_SUCCESS; }