Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp1293785pxb; Fri, 21 Jan 2022 14:35:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJzjZTLx5sfpiq4S1TjDAB996Cnw0ouGRYGdl9C1LRezYhjll7Lbh/oFjtOz/Lb6atlT83Vk X-Received: by 2002:a17:90b:1bce:: with SMTP id oa14mr2686639pjb.209.1642804540605; Fri, 21 Jan 2022 14:35:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642804540; cv=none; d=google.com; s=arc-20160816; b=CtXy5B4VtztHHmWQiT3qE+7rmvDxAkUd9NZDux1MOOB8JEX3ebzxC3x/FUfegMGEl9 whR0GoZh/kE7FcW0g7PQSSxx2gT/x3tK1Ud6QSfwrUrxapcQoz8DnyRQpxIf5XSDaWSg VC0JivIUje7Q71fyHt/l7l91jlb7eqd+vgSIPtW6XJG/vJeARpoDLbCepfdivNI0+8IH c1gBBBEgSXgFNEc79ZWdhM/Fv7qQLPy+7mfpcT3Tf/SRFZNI77S1hgtYL67s/8uJZB+D 5dV2RLVv1DULKVKU+9nVMrCWyGQC7pF7FLgs+xqJFxqPH8oWCbF5O+MH+uMWrc3CRmRh K8PQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from :dkim-signature; bh=HtkLk42w0fWd+6/z9mh2AZD/Xm33fQuNOQj57mIh9Q4=; b=Fwr+aEmd4VCFhpkoHGL1KCJxL3A+19xyLxu2Qw40yb9wLuk3yO7SDigyMS+uMxnN7v xiBArXTLhlxqIcrU+74lW3OWMWq53DNw/Dam92w5eaerVZqsPIzzygdN6btfFCUjN/H5 lAxkwXTrEPhkCMHICZutFb330sZ0/ewayRfid1KpmzzEaMTV9Wt2hiH1f3KgDyoTeo9J 6ZeR5eB1bAvyX/DkLyx75YDmox/E5Kgbe/znI5zA8fImvM5r+5bUCS3PF2vDJiVROvmx dUf9HKkXwRDAkaRrD0FnpRdo38Pe8yQX7wzGZ36GZrKZi68PiMmlmIw8g29MnSjDvisk sUig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@squareup.com header.s=google header.b="M06sFa/2"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=squareup.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m4si7305984pgj.203.2022.01.21.14.35.24; Fri, 21 Jan 2022 14:35:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@squareup.com header.s=google header.b="M06sFa/2"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=squareup.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377538AbiATUCV (ORCPT + 99 others); Thu, 20 Jan 2022 15:02:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377533AbiATUCU (ORCPT ); Thu, 20 Jan 2022 15:02:20 -0500 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28D68C06173F for ; Thu, 20 Jan 2022 12:02:20 -0800 (PST) Received: by mail-pl1-x629.google.com with SMTP id d1so6068092plh.10 for ; Thu, 20 Jan 2022 12:02:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=squareup.com; s=google; h=from:to:cc:subject:date:message-id; bh=HtkLk42w0fWd+6/z9mh2AZD/Xm33fQuNOQj57mIh9Q4=; b=M06sFa/2Shhq7noZOjf2EeS1lXvRx9NRhU+kUJyjKxjuBy2rUaKXy2LIkm7Cyda/16 bGRqiz9HX+frjV6/IMeFaPBpnzNQUlcbiiVOwfbghUOLYoYogqc3cqVkBh2NZhztpOFA II9ZSGRRYLfmadeUXP9jOQCYsEZKc+G9W6w7E= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=HtkLk42w0fWd+6/z9mh2AZD/Xm33fQuNOQj57mIh9Q4=; b=4Gk5XdR7U2yrlzJdhZEcYL9DpmA5uIf+vGGAkVjKZuG5/UrUIlT/rVThcz+6e+vmP8 jwY7araW9S5QaUoA6COFwizKFOdTKYreETsAHWCM89w/hMWd3uD04EK6gs/Fo0yDmbo3 MZVl3spC0B463U2G/BwGtEO7lnzHxd2Bobg4mK3Lgr9AgqG+6nA38Fs2eiTHitfGJv52 Bg/rmosFk0IRqO7FoBwiJUr66AMidZ/PSUBJQZ5t6/mcc+v6m2r3Jxj5ZDbtLHvcomVz jEWZXK9VTWj2hlVjTlFnaIXlOLuAUwoLtklU8xxQrmu2LymB+RtLCsD/nhrV8ekFcX2R vtzQ== X-Gm-Message-State: AOAM5307qSPawfsJ/lGC94WN0hKbOCLEIdrdJOtAUyGQNJrXpGaNDYLl xA5lqY+4NBpgP3At9jGGx7XD9g== X-Received: by 2002:a17:90a:ae15:: with SMTP id t21mr677825pjq.147.1642708939439; Thu, 20 Jan 2022 12:02:19 -0800 (PST) Received: from localhost (99-47-69-49.lightspeed.sntcca.sbcglobal.net. [99.47.69.49]) by smtp.gmail.com with ESMTPSA id em22sm3398862pjb.23.2022.01.20.12.02.17 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 20 Jan 2022 12:02:18 -0800 (PST) From: Benjamin Li To: Amit Kucheria , Thara Gopinath Cc: Bjorn Andersson , Zac Crosby , Benjamin Li , Andy Gross , "Rafael J. Wysocki" , Daniel Lezcano , Zhang Rui , linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3] drivers: thermal: tsens: respect thermal_device_mode in threshold irq reporting Date: Thu, 20 Jan 2022 12:01:53 -0800 Message-Id: <20220120200153.1214-1-benl@squareup.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 'echo disabled > .../thermal_zoneX/mode' will disable the thermal core's polling mechanism to check for threshold trips. This is used sometimes to run performance test cases. However, tsens supports an interrupt mechanism to receive notification of trips, implemented in commit 634e11d5b450 ("drivers: thermal: tsens: Add interrupt support"). Currently the thermal zone mode that's set by userspace is not checked before propagating threshold trip events from IRQs. Let's fix this to restore the abilty to disable thermal throttling at runtime. ==================== Tested on MSM8939 running 5.16.0. This platform has 8 cores; the first four thermal zones control cpu0-3 and the last zone is for the other four CPUs together. for f in /sys/class/thermal/thermal_zone*; do echo "disabled" > $f/mode echo $f | paste - $f/type $f/mode done /sys/class/thermal/thermal_zone0 cpu0-thermal disabled /sys/class/thermal/thermal_zone1 cpu1-thermal disabled /sys/class/thermal/thermal_zone2 cpu2-thermal disabled /sys/class/thermal/thermal_zone3 cpu3-thermal disabled /sys/class/thermal/thermal_zone4 cpu4567-thermal disabled With mitigation thresholds at 75 degC and load running, we can now cruise past temp=75000 without CPU throttling kicking in. watch -n 1 "grep '' /sys/class/thermal/*/temp /sys/class/thermal/*/cur_state /sys/bus/cpu/devices/cpu*/cpufreq/cpuinfo_cur_freq" /sys/class/thermal/thermal_zone0/temp:82000 /sys/class/thermal/thermal_zone1/temp:84000 /sys/class/thermal/thermal_zone2/temp:87000 /sys/class/thermal/thermal_zone3/temp:84000 /sys/class/thermal/thermal_zone4/temp:84000 /sys/class/thermal/cooling_device0/cur_state:0 /sys/class/thermal/cooling_device1/cur_state:0 /sys/bus/cpu/devices/cpu0/cpufreq/cpuinfo_cur_freq:1113600 /sys/bus/cpu/devices/cpu1/cpufreq/cpuinfo_cur_freq:1113600 /sys/bus/cpu/devices/cpu2/cpufreq/cpuinfo_cur_freq:1113600 /sys/bus/cpu/devices/cpu3/cpufreq/cpuinfo_cur_freq:1113600 /sys/bus/cpu/devices/cpu4/cpufreq/cpuinfo_cur_freq:800000 /sys/bus/cpu/devices/cpu5/cpufreq/cpuinfo_cur_freq:800000 /sys/bus/cpu/devices/cpu6/cpufreq/cpuinfo_cur_freq:800000 /sys/bus/cpu/devices/cpu7/cpufreq/cpuinfo_cur_freq:800000 Reported-by: Zac Crosby Reviewed-by: Bjorn Andersson Signed-off-by: Benjamin Li --- Changes in v3: - Upgraded logging to dev_info_ratelimited and revised log message. - Remove unrelated hunk. Some drivers that support thermal zone disabling implement a set_mode operation and simply disable the sensor or the relevant IRQ(s), so they actually don't log anything when zones are disabled. These drivers are imx_thermal.c, intel_quark_dts_thermal.c, and int3400_thermal.c. For tsens.c, implementing a change_mode would require migrating the driver from devm_thermal_zone_of_sensor_register to thermal_zone_device_register (or updating thermal_of.c to add a change_mode operation in thermal_zone_ of_device_ops). stm_thermal.c seems to use this patch's model of not disabling IRQs when the zone is disabled (they still perform the thermal_zone_device_update upon IRQ, but return -EAGAIN from their get_temp). Changes in v2: - Reordered sentences in first part of commit message to make sense. drivers/thermal/qcom/tsens.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c index 99a8d9f3e03c..dd0002829536 100644 --- a/drivers/thermal/qcom/tsens.c +++ b/drivers/thermal/qcom/tsens.c @@ -509,10 +509,14 @@ static irqreturn_t tsens_irq_thread(int irq, void *data) spin_unlock_irqrestore(&priv->ul_lock, flags); if (trigger) { - dev_dbg(priv->dev, "[%u] %s: TZ update trigger (%d mC)\n", - hw_id, __func__, temp); - thermal_zone_device_update(s->tzd, - THERMAL_EVENT_UNSPECIFIED); + if (s->tzd->mode == THERMAL_DEVICE_ENABLED) { + dev_dbg(priv->dev, "[%u] %s: TZ update trigger (%d mC)\n", + hw_id, __func__, temp); + thermal_zone_device_update(s->tzd, THERMAL_EVENT_UNSPECIFIED); + } else { + dev_info_ratelimited(priv->dev, "[%u] %s: TZ update trigger (%d mC) skipped - zone disabled, operating outside of safety limits!\n", + hw_id, __func__, temp); + } } else { dev_dbg(priv->dev, "[%u] %s: no violation: %d\n", hw_id, __func__, temp); -- 2.17.1