Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4647064rdb; Tue, 12 Dec 2023 05:48:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IGSlNKzN5JbfPCLiHtK+3d5Jp2TNI1fjAvj4xtdBXCGXkA2UYUQyC46nDpqb/kUke345Jzc X-Received: by 2002:a05:6358:6f13:b0:16e:292:2af2 with SMTP id r19-20020a0563586f1300b0016e02922af2mr3934619rwn.21.1702388915705; Tue, 12 Dec 2023 05:48:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702388915; cv=none; d=google.com; s=arc-20160816; b=ie/kIhncX+ecgbCw0XVRWTMlVPjr6NQIiJCyRL8RULywQCqsxZAj0e5MMKLBGqlLOy 2vBcLbVWsmpK89VHG0R3Bo2erL6EYqLxQEEDuOYfUz96aobzqTr6h9CgwRk5cn3N+oWN c++e+ew1imQt/gW3m+STjbwggIglmyGHFl09/szieSwgIwoB1AEOfK6xgfR1LQ4A+FXz 4qwRC+t9xzWjy24ZmMmvktJ2liC8eYZHuFr+NBQT8W+P0KPHdsZSZVvQyA5MCq09jete lB3L/iaGCSI8yuD6p0ACXyQ//ptrRiMH+7YuTF2NtF96yvoNmvsX8WI32QwEWS8x0QQ2 FKqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=TZcva+crHgAqKdFQm6j6RFE8vCgEu5sbqab2pkUUVDs=; fh=8IgpUQ2T6XGOjA/qDosxdUSIIBz0a6nQ23NA8pgv1Tg=; b=pnNCk6cYfUxCWz8B3iojIUyUxdg8LlqCuN41WaJxRXpDYQRXFJyFiB+5YXRLxg3iVi HXULwuEhzWGtXfIbJHJ+z6Ey1cu9VTdZTA3y1Y+2pa0CfLxTJ5A6QwAv62t7hkVXXpLb LB4B9kQxQuWvYvWylcyqR6tavQ7Si+qDPIOmyR1OgKsnfsMG2lWbNZvtdIPTnI3pPR5q cFdZb8pzRfSjAHdh0PxB4xlJYrVPm3y/3W64Tf6xbzxjajWdyEUBm9mfadsKVFuggJgK xmzP0VVPVyzvCyAJQQwQAmjTS/GPogqOYrazBkMGsMemkRnAo7HDBFtILDd92rGMn7GG hx0Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id q19-20020a632a13000000b005b96e63bc5esi7675874pgq.631.2023.12.12.05.48.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 05:48:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id E79198055557; Tue, 12 Dec 2023 05:48:32 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376347AbjLLNrz (ORCPT + 99 others); Tue, 12 Dec 2023 08:47:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346686AbjLLNrx (ORCPT ); Tue, 12 Dec 2023 08:47:53 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9D6F6CD; Tue, 12 Dec 2023 05:47:58 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id AE0491474; Tue, 12 Dec 2023 05:48:44 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.82.227]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 298873F738; Tue, 12 Dec 2023 05:47:57 -0800 (PST) From: Lukasz Luba To: linux-kernel@vger.kernel.org, daniel.lezcano@linaro.org, rafael@kernel.org Cc: linux-pm@vger.kernel.org, rui.zhang@intel.com, lukasz.luba@arm.com Subject: [PATCH v2 1/8] thermal: core: Add governor callback for thermal zone change Date: Tue, 12 Dec 2023 13:48:37 +0000 Message-Id: <20231212134844.1213381-2-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231212134844.1213381-1-lukasz.luba@arm.com> References: <20231212134844.1213381-1-lukasz.luba@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Tue, 12 Dec 2023 05:48:33 -0800 (PST) Add a new callback which can update governors when there is a change in the thermal zone internals, e.g. thermal cooling instance list changed. That makes possible to move some heavy operations like memory allocations related to the number of cooling instances out of the throttle() callback. Reuse the 'enum thermal_notify_event' and extend it with a new event: THERMAL_INSTANCE_LIST_UPDATE. Both callback code paths (throttle() and update_tz()) are protected with the same thermal zone lock, which guaranties the consistency. Signed-off-by: Lukasz Luba --- drivers/thermal/thermal_core.c | 13 +++++++++++++ include/linux/thermal.h | 5 +++++ 2 files changed, 18 insertions(+) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 625ba07cbe2f..592c956f6fd5 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -314,6 +314,14 @@ static void handle_non_critical_trips(struct thermal_zone_device *tz, def_governor->throttle(tz, trip); } +static void handle_instances_list_update(struct thermal_zone_device *tz) +{ + if (!tz->governor || !tz->governor->update_tz) + return; + + tz->governor->update_tz(tz, THERMAL_INSTANCE_LIST_UPDATE); +} + void thermal_zone_device_critical(struct thermal_zone_device *tz) { /* @@ -723,6 +731,8 @@ int thermal_bind_cdev_to_trip(struct thermal_zone_device *tz, list_add_tail(&dev->tz_node, &tz->thermal_instances); list_add_tail(&dev->cdev_node, &cdev->thermal_instances); atomic_set(&tz->need_update, 1); + + handle_instances_list_update(tz); } mutex_unlock(&cdev->lock); mutex_unlock(&tz->lock); @@ -781,6 +791,9 @@ int thermal_unbind_cdev_from_trip(struct thermal_zone_device *tz, if (pos->tz == tz && pos->trip == trip && pos->cdev == cdev) { list_del(&pos->tz_node); list_del(&pos->cdev_node); + + handle_instances_list_update(tz); + mutex_unlock(&cdev->lock); mutex_unlock(&tz->lock); goto unbind; diff --git a/include/linux/thermal.h b/include/linux/thermal.h index c7190e2dfcb4..9fd0d3fb234a 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -51,6 +51,7 @@ enum thermal_notify_event { THERMAL_DEVICE_POWER_CAPABILITY_CHANGED, /* power capability changed */ THERMAL_TABLE_CHANGED, /* Thermal table(s) changed */ THERMAL_EVENT_KEEP_ALIVE, /* Request for user space handler to respond */ + THERMAL_INSTANCE_LIST_UPDATE, /* List of thermal instances changed */ }; /** @@ -195,6 +196,8 @@ struct thermal_zone_device { * thermal zone. * @throttle: callback called for every trip point even if temperature is * below the trip point temperature + * @update_tz: callback called when thermal zone internals have changed, e.g. + * thermal cooling instance was added/removed * @governor_list: node in thermal_governor_list (in thermal_core.c) */ struct thermal_governor { @@ -203,6 +206,8 @@ struct thermal_governor { void (*unbind_from_tz)(struct thermal_zone_device *tz); int (*throttle)(struct thermal_zone_device *tz, const struct thermal_trip *trip); + void (*update_tz)(struct thermal_zone_device *tz, + enum thermal_notify_event reason); struct list_head governor_list; }; -- 2.25.1