Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5049747ybl; Mon, 9 Dec 2019 22:52:11 -0800 (PST) X-Google-Smtp-Source: APXvYqwDeFaZO5vOARknKJP2/YImCWRgvaGAX96KyI6U+hxA3YM5seC4Qbq75TsQu2clfLdkXvT6 X-Received: by 2002:a9d:3f06:: with SMTP id m6mr21038614otc.268.1575960731039; Mon, 09 Dec 2019 22:52:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575960731; cv=none; d=google.com; s=arc-20160816; b=AM2Wg5yc4emjs0q6k8ok49qznA5LPcu1wz4wO/oL/avmAohO/D6LyLBwS969RbI7em +6FUaC45VmR2tlpQjUbuxUcKo/w/aPkmqsCgd0M5Ga/b5FSDKe2FszuVpVqF77PS21Er fDyE2fI2Xn5soh+Z5xF7/I/8JdaRaRLVe7zhT6r7XCyvUiZnGIn/lfbImQqXI/gBOYGs LDS4gL3J9n0hzzcfXjVnCzUmn7P1WL9tHnxBqP8YJK5SRZhhvbREr2EkqqXWnMSK8ebb m2LaVn4eW9cIifTdfj2hmInzCgQssjXR0vw4mLyNa8EAOWveUC92/GWfcphE2o0e0GRO tpEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=ThCXORbwGE9xbug2jutD7MWlrN+Auf/XeZZe6HyXDCI=; b=0aAYu6U0wVVdw/2jpj5DoOSsEEwxHXQ2g7ofPzxyyhwSKwpnbJmAAdoiiYgWG2fapt NN0EhYA+eui3MJG5nNYOvffCYkk8GkQHPb70cmf1PzLIvMK54gPwcSvaIGUBw5OKTm2c Bd74dQ2QqsFGbVPM3OKg3VCcZK52fJtY4tzTYyLrTDOAvI4jVKweB8dKahUL8mJ7T7Lr /NyayazdMOoo2XkjwUnwMIQQ+MVeQzC7LZe0YBIndh2tCDjm/I+LCSt1azRXkTMalEzw VoP8L+FlqJLFNZusyOO+PAMLO6IvR1XbuXfSssFX/omVcehoRN9AgFfYB4g9qb4xY1hT +csw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@verdurent-com.20150623.gappssmtp.com header.s=20150623 header.b="OJg6/Xiq"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i5si1417540oif.211.2019.12.09.22.51.58; Mon, 09 Dec 2019 22:52:11 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@verdurent-com.20150623.gappssmtp.com header.s=20150623 header.b="OJg6/Xiq"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727221AbfLJGva (ORCPT + 99 others); Tue, 10 Dec 2019 01:51:30 -0500 Received: from mail-vs1-f68.google.com ([209.85.217.68]:46768 "EHLO mail-vs1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727119AbfLJGv3 (ORCPT ); Tue, 10 Dec 2019 01:51:29 -0500 Received: by mail-vs1-f68.google.com with SMTP id t12so12248166vso.13 for ; Mon, 09 Dec 2019 22:51:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=verdurent-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ThCXORbwGE9xbug2jutD7MWlrN+Auf/XeZZe6HyXDCI=; b=OJg6/Xiqa76NbusYSxC5X8GD57DM0I7MkUk0t1esPlgDll9GffgM7UtFmfWwrMrHxK qNrl6lSYHJlSAdRr9EapLQs9zMBpxgefxGInziD7WYREkKd9QEmha5KZOrzhQPukdYzq e/IetOsEfK5XeuGJ/rssXcoQDmDEvvmOvfYezBlb9CvcFsoZcGqR1I8PxKJvXWpmpuEk /6MgT5UtEv56Ss3H91seuqI1JrXZgQ6kTtS66kNDo+0VLQNCnyaVhtxGzpmTlOuUNHmA 9Hjx1+eWTpXpixd1u33XZ+/FYkua1n1Q0Nlioz5xJ9oYdbn5xuJDq71iRxH4BfFRpur+ muYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ThCXORbwGE9xbug2jutD7MWlrN+Auf/XeZZe6HyXDCI=; b=mCja+wjf1BSbzROWN/pzzzb/ns/MKEXY66PIlCNEBk0OfauX99M3OmWTfF618Rg8If MIEL9R7V84LXt+/PqZTXSa92cOjtI5V5YMIci562pX2yTNTlhEO9sV0vy3PLuhkgHR7N Y4ch87qHoWy9/+2FDyv7anZfaWz1Fx1m+4Sq+LYLbn5T8BqcP7Lh+fKjvYQWPILDg7YL 7ymaBRPPG1yaIi7Jio3EUcn7baXS7kFfHjBNNnY67fo7KdbpnVQQmAask5nJCQ4v6i9k znRqqCImOdKmaV8aMMbSgSEGDScs2IHJ8Fs+E77gdX+fxE1HipDg6J3HcJodJSxLn/eU GcGA== X-Gm-Message-State: APjAAAVWGn6rpBusqlD4mQCqxeV8MvXAGYEOxHicv5jmMaMdnoYsG77b nClKW09DntoV908taCW5GvuOoRbadX1bLs8bv2jcxi+4YFU= X-Received: by 2002:a67:7acd:: with SMTP id v196mr22065831vsc.95.1575960688036; Mon, 09 Dec 2019 22:51:28 -0800 (PST) MIME-Version: 1.0 References: <8e812065f4a76325097c5f9c17f3386736d8c1d4.1574315190.git.amit.kucheria@linaro.org> In-Reply-To: <8e812065f4a76325097c5f9c17f3386736d8c1d4.1574315190.git.amit.kucheria@linaro.org> From: Amit Kucheria Date: Tue, 10 Dec 2019 12:21:17 +0530 Message-ID: Subject: Re: [PATCH] drivers: thermal: step_wise: add support for hysteresis To: LKML , linux-arm-msm , Bjorn Andersson , Stephen Boyd , Keerthy , Thara Gopinath , Zhang Rui , Daniel Lezcano , Amit Kucheria Cc: Ram Chandrasekar , Lina Iyer , Linux PM list Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Nov 21, 2019 at 11:21 AM Amit Kucheria wrote: > > From: Ram Chandrasekar > > Currently, step wise governor increases the mitigation when the > temperature goes above a threshold and decreases the mitigation when the > temperature goes below the threshold. If there is a case where the > temperature is wavering around the threshold, the mitigation will be > applied and removed every iteration, which is not very efficient. > > The use of hysteresis temperature could avoid this ping-pong of > mitigation by relaxing the mitigation to happen only when the > temperature goes below this lower hysteresis value. > > Signed-off-by: Ram Chandrasekar > Signed-off-by: Lina Iyer > [Rebased patch from downstream] > Signed-off-by: Amit Kucheria Daniel, Rui: ping. Keerthy: This works for you, right? > --- > drivers/thermal/step_wise.c | 35 ++++++++++++++++++++++++----------- > 1 file changed, 24 insertions(+), 11 deletions(-) > > diff --git a/drivers/thermal/step_wise.c b/drivers/thermal/step_wise.c > index 6e051cbd824ff..2c8a34a7cf959 100644 > --- a/drivers/thermal/step_wise.c > +++ b/drivers/thermal/step_wise.c > @@ -24,7 +24,7 @@ > * for this trip point > * d. if the trend is THERMAL_TREND_DROP_FULL, use lower limit > * for this trip point > - * If the temperature is lower than a trip point, > + * If the temperature is lower than a hysteresis temperature, > * a. if the trend is THERMAL_TREND_RAISING, do nothing > * b. if the trend is THERMAL_TREND_DROPPING, use lower cooling > * state for this trip point, if the cooling state already > @@ -115,30 +115,31 @@ static void update_passive_instance(struct thermal_zone_device *tz, > > static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip) > { > - int trip_temp; > + int trip_temp, hyst_temp; > enum thermal_trip_type trip_type; > enum thermal_trend trend; > struct thermal_instance *instance; > - bool throttle = false; > + bool throttle; > int old_target; > > if (trip == THERMAL_TRIPS_NONE) { > - trip_temp = tz->forced_passive; > + hyst_temp = trip_temp = tz->forced_passive; > trip_type = THERMAL_TRIPS_NONE; > } else { > tz->ops->get_trip_temp(tz, trip, &trip_temp); > + hyst_temp = trip_temp; > + if (tz->ops->get_trip_hyst) { > + tz->ops->get_trip_hyst(tz, trip, &hyst_temp); > + hyst_temp = trip_temp - hyst_temp; > + } > tz->ops->get_trip_type(tz, trip, &trip_type); > } > > trend = get_tz_trend(tz, trip); > > - if (tz->temperature >= trip_temp) { > - throttle = true; > - trace_thermal_zone_trip(tz, trip, trip_type); > - } > - > - dev_dbg(&tz->device, "Trip%d[type=%d,temp=%d]:trend=%d,throttle=%d\n", > - trip, trip_type, trip_temp, trend, throttle); > + dev_dbg(&tz->device, > + "Trip%d[type=%d,temp=%d,hyst=%d]:trend=%d,throttle=%d\n", > + trip, trip_type, trip_temp, hyst_temp, trend, throttle); > > mutex_lock(&tz->lock); > > @@ -147,6 +148,18 @@ static void thermal_zone_trip_update(struct thermal_zone_device *tz, int trip) > continue; > > old_target = instance->target; > + throttle = false; > + /* > + * Lower the mitigation only if the temperature > + * goes below the hysteresis temperature. > + */ > + if (tz->temperature >= trip_temp || > + (tz->temperature >= hyst_temp && > + old_target != THERMAL_NO_TARGET)) { > + throttle = true; > + trace_thermal_zone_trip(tz, trip, trip_type); > + } > + > instance->target = get_target_state(instance, trend, throttle); > dev_dbg(&instance->cdev->device, "old_target=%d, target=%d\n", > old_target, (int)instance->target); > -- > 2.17.1 >