Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp907044rdb; Wed, 6 Dec 2023 03:31:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IGlACrki4Zw0DirfHHYkOBFa6KKLV+o0bcLiHDsyo7dDoNmmT10EuMz4fqh2Yak60Yc0pFT X-Received: by 2002:a17:90a:f185:b0:286:6cc0:cae7 with SMTP id bv5-20020a17090af18500b002866cc0cae7mr752633pjb.94.1701862273593; Wed, 06 Dec 2023 03:31:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701862273; cv=none; d=google.com; s=arc-20160816; b=mk7X9P19oIQYf6lBA5i+SSg+0L15n/BBk/bwlY0JjaAhIM5pLOEfVj+XvTWQe0Ddx8 KAan0YQFQxPYw7v3RUdXipFnq4i0kEkOgKC9MgP3ltpVubvHGK2XWXVJd9I80rU8ytYS JIXiy+37G52hgp7fumqcta4QPZFcBHnlUsh1dIsbTM28GQFyL44b6Yy990ei9nsf//kK KBD1Qmr9HK3c9icV7r7QFePlXMugzJCyc0Iev5QYy2w3JncXxScbiOocRBvk3q8GMMD/ p8YKE8q+Ak546xCUcPT7NiXFp2oGfdPlvUqkk+w9vKsRWyU0zHWr9qPPJTuRvTmXoWGM lpkw== 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=6SQVp2ey+rT0aZntaXd93NUQv+c9/BZMbrjSeJR4NVY=; fh=8IgpUQ2T6XGOjA/qDosxdUSIIBz0a6nQ23NA8pgv1Tg=; b=F9DaFamlEw7xH5JobU/h4viSSm4GXohhVv1WB8Lyc2RlLIhXx7le2/iPdu/oiv6Fg2 DJk2/QceLq7binAUqizsoIDMumzQ2cHIaiLzv7si2YrFXfBmevV3vnhQTE23iHbQ7jFB 0+tli5+Y+nyBgOXf4+3CT6THSV0Kd6oi66fvSxLNpUR2fOdbc54T1cA+ZW2lnz2O0bE7 WAZLZdUdWrLle2rf6vtfs7pwADvUYc3ul4GsmHxWRQRMU3+Y18z/AbXCsv5KsEMyNC3D E3x2SccvdujavRU6LdA8eyjtQmrIRysSwJQk/G0cgUE9ywau6UBti3H7q5pj9wMrwyOU S5pA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id z12-20020a17090acb0c00b00286b854b672si4950886pjt.157.2023.12.06.03.31.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 03:31:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id 86FAC81A8AB1; Wed, 6 Dec 2023 03:31:08 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377618AbjLFLat (ORCPT + 99 others); Wed, 6 Dec 2023 06:30:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377687AbjLFLam (ORCPT ); Wed, 6 Dec 2023 06:30:42 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D96DADE; Wed, 6 Dec 2023 03:30:45 -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 B8044150C; Wed, 6 Dec 2023 03:31:31 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.1.114]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 762793F5A1; Wed, 6 Dec 2023 03:30:44 -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 1/5] thermal: core: Add callback for governors with cooling instances change Date: Wed, 6 Dec 2023 11:31:34 +0000 Message-Id: <20231206113138.3576492-2-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231206113138.3576492-1-lukasz.luba@arm.com> References: <20231206113138.3576492-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 pete.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 (pete.vger.email [0.0.0.0]); Wed, 06 Dec 2023 03:31:08 -0800 (PST) Allow governors to react to the changes in the cooling instances list. That makes possible to move memory allocations related to the number of cooling instances out of the throttle() callback. The throttle() callback is called much more often thus the cost of managing allocations there is an extra overhead. The list of cooling instances is not changed that often and it can be handled in dedicated callback. That will save CPU cycles in the throttle() code path. Both callbacks code paths are protected with the same thermal zone lock, which guaranties the list of cooling instances is consistent. Signed-off-by: Lukasz Luba --- drivers/thermal/thermal_core.c | 14 ++++++++++++++ include/linux/thermal.h | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index 625ba07cbe2f..c993b86f7fb5 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -314,6 +314,15 @@ 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->instances_update) + return; + + tz->governor->instances_update(tz); +} + void thermal_zone_device_critical(struct thermal_zone_device *tz) { /* @@ -723,6 +732,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 +792,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..e7b2a1f4bab0 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -195,6 +195,9 @@ struct thermal_zone_device { * thermal zone. * @throttle: callback called for every trip point even if temperature is * below the trip point temperature + * @instances_update: callback called when thermal zone instances list + * i has changed (e.g. added new or removed), which + * may help to offload work for governor like allocations * @governor_list: node in thermal_governor_list (in thermal_core.c) */ struct thermal_governor { @@ -203,6 +206,7 @@ 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 (*instances_update)(struct thermal_zone_device *tz); struct list_head governor_list; }; -- 2.25.1