From patchwork Wed Jun 7 00:37:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eduardo Valentin X-Patchwork-Id: 690789 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56062C77B7A for ; Wed, 7 Jun 2023 00:37:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234032AbjFGAhv (ORCPT ); Tue, 6 Jun 2023 20:37:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233518AbjFGAhr (ORCPT ); Tue, 6 Jun 2023 20:37:47 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11B8410F8; Tue, 6 Jun 2023 17:37:47 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A29CE631E0; Wed, 7 Jun 2023 00:37:46 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8DB85C433D2; Wed, 7 Jun 2023 00:37:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1686098266; bh=Jj21BgI4T47Tjh7uvaUnsKqWs81Zaadmc3y9Tu/8suU=; h=From:To:Cc:Subject:Date:From; b=szFRy8r+UfdfgVaMTxwyKm+qeOV4f6Sj1dYhO0dVlJmCNpu816jkqpdZRvCtYC8M0 scqqto4QwxkOEQgDK92ROrJ05loLtKeRa8YrDQ9NjTPdWzSTcyEsLF98WL1JUTEUtd cu3UlI0a4jsn4CFpqIR3GVbofD6MFBdl7MVxCVC0JB2JxeZtY+arOCOq+M2F9JZk/t VV71f0y34iZFWTcZd0PtxMPla3IbmkbJqKt8yAic9DLyeMSyll02fWHasC+BsLtZtm yKIe4ySCZFnL1LUf6tq8ODQ7ypxOi6+AK8MgsDEcFIt4/7y/+mu7uFEaKqSLTxE+tm hDTSiVhBileFg== From: Eduardo Valentin To: evalenti@kernel.org, eduval@amazon.com, rafael@kernel.org, daniel.lezcano@linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Amit Kucheria , Zhang Rui Subject: [PATCH 1/1] thermal: sysfs: avoid actual readings from sysfs Date: Tue, 6 Jun 2023 17:37:21 -0700 Message-Id: <20230607003721.834038-1-evalenti@kernel.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Eduardo Valentin As the thermal zone caches the current and last temperature value, the sysfs interface can use that instead of forcing an actual update or read from the device. This way, if multiple userspace requests are coming in, we avoid storming the device with multiple reads and potentially clogging the timing requirement for the governors. Cc: "Rafael J. Wysocki" (supporter:THERMAL) Cc: Daniel Lezcano (supporter:THERMAL) Cc: Amit Kucheria (reviewer:THERMAL) Cc: Zhang Rui (reviewer:THERMAL) Cc: linux-pm@vger.kernel.org (open list:THERMAL) Cc: linux-kernel@vger.kernel.org (open list) Signed-off-by: Eduardo Valentin --- drivers/thermal/thermal_sysfs.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index b6daea2398da..a240c58d9e08 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -35,12 +35,23 @@ static ssize_t temp_show(struct device *dev, struct device_attribute *attr, char *buf) { struct thermal_zone_device *tz = to_thermal_zone(dev); - int temperature, ret; - - ret = thermal_zone_get_temp(tz, &temperature); + int temperature; - if (ret) - return ret; + /* + * don't force new update from external reads + * This way we avoid messing up with time constraints. + */ + if (tz->mode == THERMAL_DEVICE_DISABLED) { + int r; + + r = thermal_zone_get_temp(tz, &temperature); /* holds tz->lock*/ + if (r) + return r; + } else { + mutex_lock(&tz->lock); + temperature = tz->temperature; + mutex_unlock(&tz->lock); + } return sprintf(buf, "%d\n", temperature); }