From nobody Thu Apr 2 21:30:15 2026 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 AD538ECAAD8 for ; Wed, 21 Sep 2022 09:44:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231815AbiIUJo1 (ORCPT ); Wed, 21 Sep 2022 05:44:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231719AbiIUJnj (ORCPT ); Wed, 21 Sep 2022 05:43:39 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3415792F66 for ; Wed, 21 Sep 2022 02:43:27 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id z6so8961796wrq.1 for ; Wed, 21 Sep 2022 02:43:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=7quZAPuMcAvt+QXLI2xXiL2djdLPPOTNpr/QroOkKRY=; b=sByVIPNDLmDYSFTGYcTERiiNfEOuoQBslOrtQDNC00W2kxzxcRnc6MpaAgAQIXSOVZ 9BSuOjTHh4wSPezXiKS2cSPXVmi0pBTXKd3UKdVufS7dKcX3aPHpdZIdVu+Eycz5UeK1 4BH8wGjDawRKACIEe2xAJm0B3y4NBifmBQsb8CX/aCEv/oC5fndK88GKjWAJr1wP3yfo jtziyV3tXRDrSBgLKbouGMRI+ITgYUeDR7ZKYGxDGDvufPYf+jMrbDBCl5oQvF0az/E/ IUqEh8cjclwOaG04ZAkBCDr3Ly+x4PfvrC+6LLRokHIAR4DBaVAd5ZZMTRtrsHdaDq8m p8qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=7quZAPuMcAvt+QXLI2xXiL2djdLPPOTNpr/QroOkKRY=; b=PjjCkUCfAMgk0WDXhwfWaSprk6EFNym78aM2XgQIPpnpiizlO9mIjWVFRr+dtOpJKF 9q4YBhDgxGSccRXhs54gWlkdAi7D+fqKa+u2xNotiSPjBXbJhcAMq9pvMv7lD34z7spq Lc4ejmUW57pLg82jcEUZfMJA9HzHncPKDgiBcd1W+REbNjNMg9+nkylYqmW8DwhahF2D PyKFo00XBxVDY+aSFOKPn882OfbFdjWhyFdtaEyyPPWWX8a16Tc3B3YfzEi8I2pNmp+s 0mQgjq/zOIBZQiP86zTdPa1/R0bz3fS6NYb9V/nkjoXP6vsqwW1UOnGb3LtgjmJRfV0p lekA== X-Gm-Message-State: ACrzQf0VkP6XsQMJf3UpbXmIzpdsg6EyPdL1ldyve1GTJJRLgpXiStyh en32Ta8MqtJdBGCnzkEJlTdhtA== X-Google-Smtp-Source: AMsMyM4GaTpuAZvarnVQi/zmxslSM+uiX4cFvH3cZ7LGjti0lmceFW62GVIVNv+IyWvariq/nH03/g== X-Received: by 2002:a05:6000:1d9d:b0:22a:745b:9f00 with SMTP id bk29-20020a0560001d9d00b0022a745b9f00mr16509094wrb.280.1663753406662; Wed, 21 Sep 2022 02:43:26 -0700 (PDT) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id r123-20020a1c2b81000000b003a62052053csm2763917wmr.18.2022.09.21.02.43.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Sep 2022 02:43:26 -0700 (PDT) From: Daniel Lezcano To: daniel.lezcano@linaro.org, rafael@kernel.org Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, rui.zhang@intel.com, Amit Kucheria , Lukasz Luba Subject: [PATCH v4 05/30] thermal/core/governors: Use thermal_zone_get_trip() instead of ops functions Date: Wed, 21 Sep 2022 11:42:18 +0200 Message-Id: <20220921094244.606948-6-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220921094244.606948-1-daniel.lezcano@linaro.org> References: <20220921094244.606948-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The governors are using the ops->get_trip_* functions, Replace these calls with thermal_zone_get_trip(). Signed-off-by: Daniel Lezcano Reviewed-by: Lukasz Luba Reviewed-by: Zhang Rui --- drivers/thermal/gov_bang_bang.c | 23 +++++------- drivers/thermal/gov_fair_share.c | 18 ++++------ drivers/thermal/gov_power_allocator.c | 51 ++++++++++++--------------- drivers/thermal/gov_step_wise.c | 22 ++++++------ 4 files changed, 47 insertions(+), 67 deletions(-) diff --git a/drivers/thermal/gov_bang_bang.c b/drivers/thermal/gov_bang_ban= g.c index a08bbe33be96..09234f3d2fb9 100644 --- a/drivers/thermal/gov_bang_bang.c +++ b/drivers/thermal/gov_bang_bang.c @@ -13,26 +13,19 @@ =20 #include "thermal_core.h" =20 -static void thermal_zone_trip_update(struct thermal_zone_device *tz, int t= rip) +static void thermal_zone_trip_update(struct thermal_zone_device *tz, int t= rip_id) { - int trip_temp, trip_hyst; + struct thermal_trip trip; struct thermal_instance *instance; =20 - tz->ops->get_trip_temp(tz, trip, &trip_temp); - - if (!tz->ops->get_trip_hyst) { - pr_warn_once("Undefined get_trip_hyst for thermal zone %s - " - "running with default hysteresis zero\n", tz->type); - trip_hyst =3D 0; - } else - tz->ops->get_trip_hyst(tz, trip, &trip_hyst); + thermal_zone_get_trip(tz, trip_id, &trip); =20 dev_dbg(&tz->device, "Trip%d[temp=3D%d]:temp=3D%d:hyst=3D%d\n", - trip, trip_temp, tz->temperature, - trip_hyst); + trip_id, trip.temperature, tz->temperature, + trip.hysteresis); =20 list_for_each_entry(instance, &tz->thermal_instances, tz_node) { - if (instance->trip !=3D trip) + if (instance->trip !=3D trip_id) continue; =20 /* in case fan is in initial state, switch the fan off */ @@ -50,10 +43,10 @@ static void thermal_zone_trip_update(struct thermal_zon= e_device *tz, int trip) * enable fan when temperature exceeds trip_temp and disable * the fan in case it falls below trip_temp minus hysteresis */ - if (instance->target =3D=3D 0 && tz->temperature >=3D trip_temp) + if (instance->target =3D=3D 0 && tz->temperature >=3D trip.temperature) instance->target =3D 1; else if (instance->target =3D=3D 1 && - tz->temperature <=3D trip_temp - trip_hyst) + tz->temperature <=3D trip.temperature - trip.hysteresis) instance->target =3D 0; =20 dev_dbg(&instance->cdev->device, "target=3D%d\n", diff --git a/drivers/thermal/gov_fair_share.c b/drivers/thermal/gov_fair_sh= are.c index a4ee4661e9cc..c515e7a52294 100644 --- a/drivers/thermal/gov_fair_share.c +++ b/drivers/thermal/gov_fair_share.c @@ -21,16 +21,12 @@ */ static int get_trip_level(struct thermal_zone_device *tz) { - int count =3D 0; - int trip_temp; - enum thermal_trip_type trip_type; - - if (tz->num_trips =3D=3D 0 || !tz->ops->get_trip_temp) - return 0; + struct thermal_trip trip; + int count; =20 for (count =3D 0; count < tz->num_trips; count++) { - tz->ops->get_trip_temp(tz, count, &trip_temp); - if (tz->temperature < trip_temp) + thermal_zone_get_trip(tz, count, &trip); + if (tz->temperature < trip.temperature) break; } =20 @@ -38,10 +34,8 @@ static int get_trip_level(struct thermal_zone_device *tz) * count > 0 only if temperature is greater than first trip * point, in which case, trip_point =3D count - 1 */ - if (count > 0) { - tz->ops->get_trip_type(tz, count - 1, &trip_type); - trace_thermal_zone_trip(tz, count - 1, trip_type); - } + if (count > 0) + trace_thermal_zone_trip(tz, count - 1, trip.type); =20 return count; } diff --git a/drivers/thermal/gov_power_allocator.c b/drivers/thermal/gov_po= wer_allocator.c index 2d1aeaba38a8..2ef86ced4c7c 100644 --- a/drivers/thermal/gov_power_allocator.c +++ b/drivers/thermal/gov_power_allocator.c @@ -125,16 +125,15 @@ static void estimate_pid_constants(struct thermal_zon= e_device *tz, u32 sustainable_power, int trip_switch_on, int control_temp) { + struct thermal_trip trip; + u32 temperature_threshold =3D control_temp; int ret; - int switch_on_temp; - u32 temperature_threshold; s32 k_i; =20 - ret =3D tz->ops->get_trip_temp(tz, trip_switch_on, &switch_on_temp); - if (ret) - switch_on_temp =3D 0; + ret =3D thermal_zone_get_trip(tz, trip_switch_on, &trip); + if (!ret) + temperature_threshold -=3D trip.temperature; =20 - temperature_threshold =3D control_temp - switch_on_temp; /* * estimate_pid_constants() tries to find appropriate default * values for thermal zones that don't provide them. If a @@ -520,10 +519,10 @@ static void get_governor_trips(struct thermal_zone_de= vice *tz, last_passive =3D INVALID_TRIP; =20 for (i =3D 0; i < tz->num_trips; i++) { - enum thermal_trip_type type; + struct thermal_trip trip; int ret; =20 - ret =3D tz->ops->get_trip_type(tz, i, &type); + ret =3D thermal_zone_get_trip(tz, i, &trip); if (ret) { dev_warn(&tz->device, "Failed to get trip point %d type: %d\n", i, @@ -531,14 +530,14 @@ static void get_governor_trips(struct thermal_zone_de= vice *tz, continue; } =20 - if (type =3D=3D THERMAL_TRIP_PASSIVE) { + if (trip.type =3D=3D THERMAL_TRIP_PASSIVE) { if (!found_first_passive) { params->trip_switch_on =3D i; found_first_passive =3D true; } else { last_passive =3D i; } - } else if (type =3D=3D THERMAL_TRIP_ACTIVE) { + } else if (trip.type =3D=3D THERMAL_TRIP_ACTIVE) { last_active =3D i; } else { break; @@ -633,7 +632,7 @@ static int power_allocator_bind(struct thermal_zone_dev= ice *tz) { int ret; struct power_allocator_params *params; - int control_temp; + struct thermal_trip trip; =20 ret =3D check_power_actors(tz); if (ret) @@ -659,13 +658,12 @@ static int power_allocator_bind(struct thermal_zone_d= evice *tz) get_governor_trips(tz, params); =20 if (tz->num_trips > 0) { - ret =3D tz->ops->get_trip_temp(tz, - params->trip_max_desired_temperature, - &control_temp); + ret =3D thermal_zone_get_trip(tz, params->trip_max_desired_temperature, + &trip); if (!ret) estimate_pid_constants(tz, tz->tzp->sustainable_power, params->trip_switch_on, - control_temp); + trip.temperature); } =20 reset_pid_controller(params); @@ -695,11 +693,11 @@ static void power_allocator_unbind(struct thermal_zon= e_device *tz) tz->governor_data =3D NULL; } =20 -static int power_allocator_throttle(struct thermal_zone_device *tz, int tr= ip) +static int power_allocator_throttle(struct thermal_zone_device *tz, int tr= ip_id) { - int ret; - int switch_on_temp, control_temp; struct power_allocator_params *params =3D tz->governor_data; + struct thermal_trip trip; + int ret; bool update; =20 lockdep_assert_held(&tz->lock); @@ -708,13 +706,12 @@ static int power_allocator_throttle(struct thermal_zo= ne_device *tz, int trip) * We get called for every trip point but we only need to do * our calculations once */ - if (trip !=3D params->trip_max_desired_temperature) + if (trip_id !=3D params->trip_max_desired_temperature) return 0; =20 - ret =3D tz->ops->get_trip_temp(tz, params->trip_switch_on, - &switch_on_temp); - if (!ret && (tz->temperature < switch_on_temp)) { - update =3D (tz->last_temperature >=3D switch_on_temp); + ret =3D thermal_zone_get_trip(tz, params->trip_switch_on, &trip); + if (!ret && (tz->temperature < trip.temperature)) { + update =3D (tz->last_temperature >=3D trip.temperature); tz->passive =3D 0; reset_pid_controller(params); allow_maximum_power(tz, update); @@ -723,16 +720,14 @@ static int power_allocator_throttle(struct thermal_zo= ne_device *tz, int trip) =20 tz->passive =3D 1; =20 - ret =3D tz->ops->get_trip_temp(tz, params->trip_max_desired_temperature, - &control_temp); + ret =3D thermal_zone_get_trip(tz, params->trip_max_desired_temperature, &= trip); if (ret) { - dev_warn(&tz->device, - "Failed to get the maximum desired temperature: %d\n", + dev_warn(&tz->device, "Failed to get the maximum desired temperature: %d= \n", ret); return ret; } =20 - return allocate_power(tz, control_temp); + return allocate_power(tz, trip.temperature); } =20 static struct thermal_governor thermal_gov_power_allocator =3D { diff --git a/drivers/thermal/gov_step_wise.c b/drivers/thermal/gov_step_wis= e.c index cdd3354bc27f..3cb16d7e65d1 100644 --- a/drivers/thermal/gov_step_wise.c +++ b/drivers/thermal/gov_step_wise.c @@ -95,30 +95,28 @@ static void update_passive_instance(struct thermal_zone= _device *tz, tz->passive +=3D value; } =20 -static void thermal_zone_trip_update(struct thermal_zone_device *tz, int t= rip) +static void thermal_zone_trip_update(struct thermal_zone_device *tz, int t= rip_id) { - int trip_temp; - enum thermal_trip_type trip_type; enum thermal_trend trend; struct thermal_instance *instance; + struct thermal_trip trip; bool throttle =3D false; int old_target; =20 - tz->ops->get_trip_temp(tz, trip, &trip_temp); - tz->ops->get_trip_type(tz, trip, &trip_type); + thermal_zone_get_trip(tz, trip_id, &trip); =20 - trend =3D get_tz_trend(tz, trip); + trend =3D get_tz_trend(tz, trip_id); =20 - if (tz->temperature >=3D trip_temp) { + if (tz->temperature >=3D trip.temperature) { throttle =3D true; - trace_thermal_zone_trip(tz, trip, trip_type); + trace_thermal_zone_trip(tz, trip_id, trip.type); } =20 dev_dbg(&tz->device, "Trip%d[type=3D%d,temp=3D%d]:trend=3D%d,throttle=3D%= d\n", - trip, trip_type, trip_temp, trend, throttle); + trip_id, trip.type, trip.temperature, trend, throttle); =20 list_for_each_entry(instance, &tz->thermal_instances, tz_node) { - if (instance->trip !=3D trip) + if (instance->trip !=3D trip_id) continue; =20 old_target =3D instance->target; @@ -132,11 +130,11 @@ static void thermal_zone_trip_update(struct thermal_z= one_device *tz, int trip) /* Activate a passive thermal instance */ if (old_target =3D=3D THERMAL_NO_TARGET && instance->target !=3D THERMAL_NO_TARGET) - update_passive_instance(tz, trip_type, 1); + update_passive_instance(tz, trip.type, 1); /* Deactivate a passive thermal instance */ else if (old_target !=3D THERMAL_NO_TARGET && instance->target =3D=3D THERMAL_NO_TARGET) - update_passive_instance(tz, trip_type, -1); + update_passive_instance(tz, trip.type, -1); =20 instance->initialized =3D true; mutex_lock(&instance->cdev->lock); --=20 2.34.1