From patchwork Mon Apr 23 17:53:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kevin DuBois X-Patchwork-Id: 10357885 X-Patchwork-Delegate: rui.zhang@intel.com 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 BF2E960209 for ; Mon, 23 Apr 2018 17:53:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AFB0928BEA for ; Mon, 23 Apr 2018 17:53:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A2F4D28BEE; Mon, 23 Apr 2018 17:53: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=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham 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 3D2CB28BEA for ; Mon, 23 Apr 2018 17:53:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932293AbeDWRx5 (ORCPT ); Mon, 23 Apr 2018 13:53:57 -0400 Received: from mail-ua0-f201.google.com ([209.85.217.201]:49176 "EHLO mail-ua0-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932291AbeDWRxv (ORCPT ); Mon, 23 Apr 2018 13:53:51 -0400 Received: by mail-ua0-f201.google.com with SMTP id f1so13468755ual.16 for ; Mon, 23 Apr 2018 10:53:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:date:message-id:subject:from:to; bh=OdBxvYRSoR5MRYSh8pDaiGb2mVNOtyTy5nGUdgMxIzY=; b=rIrShMuhIaDm40UQ25qnIxFJsKkNbPZCR1pHXq7vPPxUcJrPVjthGbXhlSRWRK9s+h oCbMU/ijBFJBPLe2l8ubIEWXS8GGyZdq/mpaoYGs7ofbfOxUEnmTYxgjffJbqCcEQ21A KqJqFXmZHbbh2jvGU5d5pFm1Gm9s1/i/qP8zX1RsWDOQYva7ztls7/n7Sj8NXU62x6aH 1dkpCH5/XIET1/qLzK/D0AdVvFgT3KvCXwqw2/TCRYOH5Vn8wPYd4j35NnuVAuqxcx+H 47Sbxhh3w1wwNLHigdNuM3mW37MaM3pgppXclDxb84SQhTE7RiiM3FUwIuYKF2CipLKk c+DQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:date:message-id:subject:from:to; bh=OdBxvYRSoR5MRYSh8pDaiGb2mVNOtyTy5nGUdgMxIzY=; b=H3L3t2k9Eg2hlvWBBV9exrrMKrUmoZM5n/qSB63PUoNISBPytst+9PX5JyXF06jGKx GHWSexgVYPpGMcpGM0NOwUZ/kziOTmgXfUZ6q6UsPai7u+pWBF57NkVIDDL3A7SfFztR NNU7npNBgCMYCEEtBz/xfCh9sJpUxT15PzyaaYpryyXi8LII5nEhOSypowPdgKHWWesC 0SH1sP1t0YRQfF5RNiaKevIQpVWswHP9x9zySpTeEbjb9mOXfmgdHZULDZjYRsf1GkO8 kVQsLry5d/Ez+SMnmIiWIhYl2ka61pjTTEMDQiN1r5rMoStY6CZZ/FRvG6oT3o+STS6D +pOA== X-Gm-Message-State: ALQs6tDzl4RixmAUHcLOYGFWN/AviIaE7MlQNDQ5s1jk+i8upyGCH0JO JpE3UHEOz50kYH1N5RsfgI8cG03gd/wWJTBsBuQrWVrsZsBxQ517ID4Gg46mdWwrhRJwILvKHza GsZDksnem/ZzS6R8kDey3kpWFLwaffMVJD60CuN+fh3TklJM3U6nlXa8kN+s9qS9vnsq6BlfHnA 3kLg== X-Google-Smtp-Source: AIpwx49y7gcnqNW3hUb0GLmIbaQpwkfd98qOrYUmALCco7U9ce1lAr+hPQlEJhDdfz9w381o0fVbOcNbJX+anSg1AA== MIME-Version: 1.0 X-Received: by 10.176.71.238 with SMTP id w46mr8259530uac.16.1524506030225; Mon, 23 Apr 2018 10:53:50 -0700 (PDT) Date: Mon, 23 Apr 2018 10:53:40 -0700 Message-Id: <20180423175340.32598-1-kevindubois@google.com> X-Mailer: git-send-email 2.17.0.484.g0c8726318c-goog Subject: [PATCH] thermal: core: fix emulation of subzero temps From: Kevin DuBois To: linux-pm@vger.kernel.org, linux-doc@vger.kernel.org, corbet@lwn.net, rui.zhang@intel.com, edubezval@gmail.com, kevindubois@google.com Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The current implementation casted away its sign. It was also using '0' to disable emulation, but 0C is a valid thermal reading. A large negative value (below absolute zero) now disables the emulation. Test: Build kernel with CONFIG_THERMAL_EMULATION=y, then write negative values to the emul_temp sysfs entry. Check the temp entry, and see the negative value. Write -INT_MAX to emul_temp, and see the proper sensor reading appear. Bug: 77599739 Signed-off-by: Kevin DuBois Change-Id: Iee1a4f0aacf7b4299b67c7f8f4effedf2d7a8425 --- Documentation/thermal/sysfs-api.txt | 2 +- drivers/thermal/thermal_core.c | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/Documentation/thermal/sysfs-api.txt b/Documentation/thermal/sysfs-api.txt index 10f062ea6bc2..e240d9e165a0 100644 --- a/Documentation/thermal/sysfs-api.txt +++ b/Documentation/thermal/sysfs-api.txt @@ -312,7 +312,7 @@ emul_temp this temperature to platform emulation function if registered or cache it locally. This is useful in debugging different temperature threshold and its associated cooling action. This is write only node - and writing 0 on this node should disable emulation. + and writing -INT_MAX on this node should disable emulation. Unit: millidegree Celsius WO, Optional diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 768783ab3dac..650a6b124fc7 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -636,8 +636,8 @@ int get_tz_trend(struct thermal_zone_device *tz, int trip) { enum thermal_trend trend; - if (tz->emul_temperature || !tz->ops->get_trend || - tz->ops->get_trend(tz, trip, &trend)) { + if ((tz->emul_temperature > THERMAL_TEMP_INVALID) || + !tz->ops->get_trend || tz->ops->get_trend(tz, trip, &trend)) { if (tz->temperature > tz->last_temperature) trend = THERMAL_TREND_RAISING; else if (tz->temperature < tz->last_temperature) @@ -904,7 +904,8 @@ int thermal_zone_get_temp(struct thermal_zone_device *tz, int *temp) ret = tz->ops->get_temp(tz, temp); - if (IS_ENABLED(CONFIG_THERMAL_EMULATION) && tz->emul_temperature) { + if (IS_ENABLED(CONFIG_THERMAL_EMULATION) && + (tz->emul_temperature > THERMAL_TEMP_INVALID)) { for (count = 0; count < tz->trips; count++) { ret = tz->ops->get_trip_type(tz, count, &type); if (!ret && type == THERMAL_TRIP_CRITICAL) { @@ -961,6 +962,7 @@ static void thermal_zone_device_reset(struct thermal_zone_device *tz) struct thermal_instance *pos; tz->temperature = THERMAL_TEMP_INVALID; + tz->emul_temperature = THERMAL_TEMP_INVALID; tz->passive = 0; list_for_each_entry(pos, &tz->thermal_instances, tz_node) pos->initialized = false; @@ -1351,9 +1353,9 @@ emul_temp_store(struct device *dev, struct device_attribute *attr, { struct thermal_zone_device *tz = to_thermal_zone(dev); int ret = 0; - unsigned long temperature; + int temperature; - if (kstrtoul(buf, 10, &temperature)) + if (kstrtoint(buf, 10, &temperature)) return -EINVAL; if (!tz->ops->set_emul_temp) { @@ -2296,6 +2298,7 @@ struct thermal_zone_device *thermal_zone_device_register(const char *type, tz->trips = trips; tz->passive_delay = passive_delay; tz->polling_delay = polling_delay; + tz->emul_temperature = THERMAL_TEMP_INVALID; /* A new thermal zone needs to be updated anyway. */ atomic_set(&tz->need_update, 1);