From patchwork Mon May 7 17:55:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lina Iyer X-Patchwork-Id: 10384579 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 1662F60353 for ; Mon, 7 May 2018 17:55:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E32228AA5 for ; Mon, 7 May 2018 17:55:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 12CA528AA6; Mon, 7 May 2018 17:55:15 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 BD7DD28B14 for ; Mon, 7 May 2018 17:55:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752495AbeEGRzM (ORCPT ); Mon, 7 May 2018 13:55:12 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:50166 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751976AbeEGRzL (ORCPT ); Mon, 7 May 2018 13:55:11 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 37E2E60115; Mon, 7 May 2018 17:55:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1525715711; bh=3EzRdOZ2+X3WhEolivtIfeevTyNlMt8WVwQ5HpEWeZg=; h=From:To:Cc:Subject:Date:From; b=ZtfWdppfrOG0v1kXo9t8DmqQWFQgkts7aPSECkgeSvnnI6ERINZ9yYL808n3PIQLW uO5dbC9rbVifo42IMJhxxcgtwnP8fVbLagEu2J0iYeBvhjXNdY9WgdoIol7Z3wkRvg ZHz6KvTsYp4A28l1IrCF7QIvttnYOQ5662azLGaY= Received: from codeaurora.org (i-global254.qualcomm.com [199.106.103.254]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: ilina@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id EFFA26022C; Mon, 7 May 2018 17:55:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1525715710; bh=3EzRdOZ2+X3WhEolivtIfeevTyNlMt8WVwQ5HpEWeZg=; h=From:To:Cc:Subject:Date:From; b=nLFV1SbbzHjEv4YtRhEGTzOt45sVOAPHXmeUyO4yuCVzQiKE0t2jMAvfc6/x5IjxK BAe9DHJ7c6QFa/0n5ZnQwrGQqSLrvjex7BM0d8doVQpwfeKYkJxhMTmKHizpquNd9q /IYrb5bKrhagE/WC4xoWQuIPbSFZGEcSRUDf1cTM= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org EFFA26022C Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=ilina@codeaurora.org From: Lina Iyer To: edubezval@gmail.com, rui.zhang@intel.com Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, Lina Iyer Subject: [PATCH] drivers: thermal: do not clobber cooling dev state from userspace Date: Mon, 7 May 2018 11:55:05 -0600 Message-Id: <20180507175505.2389-1-ilina@codeaurora.org> X-Mailer: git-send-email 2.17.0 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 From: Ram Chandrasekar Let userspace be another voter for cooling device state instead of the overriding authority. It is possible that the thermal governor may find a higher cooling state desirable than what is recommended by the userspace. Separate out the current cooling device state from the userspace request and aggregate the userspace request with the governors' recommendation. Signed-off-by: Lina Iyer --- drivers/thermal/thermal_core.c | 1 + drivers/thermal/thermal_helpers.c | 2 +- drivers/thermal/thermal_sysfs.c | 8 +++++++- include/linux/thermal.h | 1 + 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 589925ac0994..c2e13e122934 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -970,6 +970,7 @@ __thermal_cooling_device_register(struct device_node *np, cdev->updated = false; cdev->device.class = &thermal_class; cdev->devdata = devdata; + cdev->sysfs_req = 0; thermal_cooling_device_setup_sysfs(cdev); dev_set_name(&cdev->device, "cooling_device%d", cdev->id); result = device_register(&cdev->device); diff --git a/drivers/thermal/thermal_helpers.c b/drivers/thermal/thermal_helpers.c index 2ba756af76b7..f550fdee0f9b 100644 --- a/drivers/thermal/thermal_helpers.c +++ b/drivers/thermal/thermal_helpers.c @@ -166,7 +166,7 @@ EXPORT_SYMBOL_GPL(thermal_zone_set_trips); void thermal_cdev_update(struct thermal_cooling_device *cdev) { struct thermal_instance *instance; - unsigned long target = 0; + unsigned long target = cdev->sysfs_req; mutex_lock(&cdev->lock); /* cooling device is updated*/ diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index 275ffee292bf..eddada715ad2 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -719,7 +719,13 @@ thermal_cooling_device_cur_state_store(struct device *dev, result = cdev->ops->set_cur_state(cdev, state); if (result) return result; - thermal_cooling_device_stats_update(cdev, state); + + cdev->sysfs_req = state; + mutex_lock(&cdev->lock); + cdev->updated = false; + mutex_unlock(&cdev->lock); + thermal_cdev_update(cdev); + return count; } diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 5f4705f46c2f..7a133bd6ff86 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -139,6 +139,7 @@ struct thermal_cooling_device { struct mutex lock; /* protect thermal_instances list */ struct list_head thermal_instances; struct list_head node; + unsigned long sysfs_req; }; struct thermal_attr {