Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp5988599rwd; Mon, 19 Jun 2023 00:06:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5NCfxkir8X5tIr7yPDvZmU/aUqC5ffZh7IEUPeCR8nDPNoAWVcWqkZbRSgSEpmRIl9b1IG X-Received: by 2002:a67:f99a:0:b0:440:339f:b1d3 with SMTP id b26-20020a67f99a000000b00440339fb1d3mr1158348vsq.31.1687158417804; Mon, 19 Jun 2023 00:06:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687158417; cv=none; d=google.com; s=arc-20160816; b=zan0HnnISQW3kdO2NxDxco8I40WWOxAR0HkAaZ6SA8bi/7kyfIiEk9mQLhOi14jnvp UIcD0bZbaPIHjzsahjnnd22uvFULT+knObNwHgpwMC7vRBvQtql8Zf2+Op3Xy0KNKjnZ 5dbza/a9x0LEdvG3XnvE04v5Jrg1O1OeCPX73GB561a4P46wsxp59NCpscnogRN4C7Ht 04w4S/awMgRCE1Twfv7tXkiVgzwW803pfrCoWuI6Qxipk+q3M2KPNscW0rvnecwNXGgA APqHUSkeZDXXTRzCXpg0WEJrdU04FHU+gQ4lffhX2cs9Pxu5+kOp8kniPL2eQIqz/HZQ peMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=hQFuTlU7iAR7xgZYo3q7VYkHh3UnJiJMFrUsr60fj8k=; b=zBsPSVcIcFLFvQX3/tIeYa3+M9unPG9WWoNXRIqKKE7tpW82/FA8qaXVtPEWvSzTVz NDJDYHcdz7qUYtrvrAml9lC3rlG70BReyvxSckWCIOM/cD/HTVIWyNTydDogPJqVM2ZR 0P+6ddalq7mT2BOcLu4fQnVNk8IE2u40jl9cRbC1J9rmuxLR6XLwPMuTvpt1+o1+wuym JeOZ55WDR5edH7VBcUORcUQbLgOrzW6MEDIbw7mwQM+Jo7jF2Nvi4DzM1vBxqZnchhDX QvlB8URQ+BJ211BNSwtULVmkx0W7MauhsFBB7QSsXNOY64QqG+bE/OkbS215Lg6SCMQP cm7w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q1-20020a656a81000000b0050be067284bsi10128035pgu.556.2023.06.19.00.06.28; Mon, 19 Jun 2023 00:06:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229999AbjFSGgg (ORCPT + 99 others); Mon, 19 Jun 2023 02:36:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229679AbjFSGgf (ORCPT ); Mon, 19 Jun 2023 02:36:35 -0400 Received: from SHSQR01.spreadtrum.com (unknown [222.66.158.135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B1A0123; Sun, 18 Jun 2023 23:36:32 -0700 (PDT) Received: from dlp.unisoc.com ([10.29.3.86]) by SHSQR01.spreadtrum.com with ESMTP id 35J6Zc1M009285; Mon, 19 Jun 2023 14:35:38 +0800 (+08) (envelope-from Di.Shen@unisoc.com) Received: from SHDLP.spreadtrum.com (bjmbx01.spreadtrum.com [10.0.64.7]) by dlp.unisoc.com (SkyGuard) with ESMTPS id 4Ql0Pj1WnWz2KlGkP; Mon, 19 Jun 2023 14:35:21 +0800 (CST) Received: from bj10906pcu1.spreadtrum.com (10.0.73.63) by BJMBX01.spreadtrum.com (10.0.64.7) with Microsoft SMTP Server (TLS) id 15.0.1497.23; Mon, 19 Jun 2023 14:35:36 +0800 From: Di Shen To: , , , CC: , , , , , , , Subject: [PATCH V4] thermal/core/power_allocator: reset thermal governor when trip point is changed Date: Mon, 19 Jun 2023 14:35:34 +0800 Message-ID: <20230619063534.12831-1-di.shen@unisoc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <6aad180f-410c-5b11-b30b-c7bc02cbe054@linaro.org> References: <6aad180f-410c-5b11-b30b-c7bc02cbe054@linaro.org> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.0.73.63] X-ClientProxiedBy: SHCAS03.spreadtrum.com (10.0.1.207) To BJMBX01.spreadtrum.com (10.0.64.7) X-MAIL: SHSQR01.spreadtrum.com 35J6Zc1M009285 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When the thermal trip point is changed, the governor should be reset so that the policy algorithm be updated to adapt to the new trip point. This patch adds an ops for thermal the governor structure to reset the governor. The ops is called when the trip point is changed. For power allocator, the parameters of pid controller and the states of power cooling devices can be reset when the passive trip point is changed. Signed-off-by: Di Shen --- V4: - Compared to V3, handle it in thermal core instead of in governor. - Add an ops to the governor structure, and call it when a trip point is changed. - Define reset ops for power allocator. V3: - Add fix tag. V2: - Compared to v1, do not revert. - Add a variable(last_switch_on_temp) in power_allocator_params to record the last switch_on_temp value. - Adds a function to renew the update flag and update the last_switch_on_temp when thermal trips are writable. V1: - Revert commit 0952177f2a1f. --- --- drivers/thermal/gov_power_allocator.c | 21 +++++++++++++++++++++ drivers/thermal/thermal_trip.c | 6 ++++++ include/linux/thermal.h | 1 + 3 files changed, 28 insertions(+) diff --git a/drivers/thermal/gov_power_allocator.c b/drivers/thermal/gov_power_allocator.c index 8642f1096b91..41d155adc616 100644 --- a/drivers/thermal/gov_power_allocator.c +++ b/drivers/thermal/gov_power_allocator.c @@ -729,10 +729,31 @@ static int power_allocator_throttle(struct thermal_zone_device *tz, int trip_id) return allocate_power(tz, trip.temperature); } +static int power_allocator_reset(struct thermal_zone_device *tz, int trip_id) +{ + int ret = 0; + struct thermal_trip trip; + struct power_allocator_params *params = tz->governor_data; + + ret = __thermal_zone_get_trip(tz, trip_id, &trip); + if (ret) + return ret; + + /* Only need reset for passive trips */ + if (trip.type != THERMAL_TRIP_PASSIVE) + return -EINVAL; + + reset_pid_controller(params); + allow_maximum_power(tz, true); + + return ret; +} + static struct thermal_governor thermal_gov_power_allocator = { .name = "power_allocator", .bind_to_tz = power_allocator_bind, .unbind_from_tz = power_allocator_unbind, .throttle = power_allocator_throttle, + .reset = power_allocator_reset, }; THERMAL_GOVERNOR_DECLARE(thermal_gov_power_allocator); diff --git a/drivers/thermal/thermal_trip.c b/drivers/thermal/thermal_trip.c index 907f3a4d7bc8..52eb768fada8 100644 --- a/drivers/thermal/thermal_trip.c +++ b/drivers/thermal/thermal_trip.c @@ -173,6 +173,12 @@ int thermal_zone_set_trip(struct thermal_zone_device *tz, int trip_id, if (tz->trips && (t.temperature != trip->temperature || t.hysteresis != trip->hysteresis)) tz->trips[trip_id] = *trip; + if (t.temperature != trip->temperature && tz->governor && tz->governor->reset) { + ret = tz->governor->reset(tz, trip_id); + if (ret) + pr_warn_once("Failed to reset thermal governor\n"); + } + thermal_notify_tz_trip_change(tz->id, trip_id, trip->type, trip->temperature, trip->hysteresis); diff --git a/include/linux/thermal.h b/include/linux/thermal.h index 87837094d549..155ce2291fa5 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -204,6 +204,7 @@ struct thermal_governor { int (*bind_to_tz)(struct thermal_zone_device *tz); void (*unbind_from_tz)(struct thermal_zone_device *tz); int (*throttle)(struct thermal_zone_device *tz, int trip); + int (*reset)(struct thermal_zone_device *tz, int trip); struct list_head governor_list; }; -- 2.17.1