Received: by 2002:ab2:4a89:0:b0:1f4:a8b6:6e69 with SMTP id w9csp301193lqj; Wed, 10 Apr 2024 10:47:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVj/7+557B4DaWIc49jePKdcM9KiO35Zzo0+jufXgEcirai+NKXysxz8ihvW7MhZBva//oC3adavHpVxzFXVr2IBw6inFa0lGAdgInDaQ== X-Google-Smtp-Source: AGHT+IETFRF8EAQVC8vPb+ufvlFjoKSW1yCIRb1MQW4a/pLnf+7Avpp9cmHrD2N4ugJjB1swJ7UF X-Received: by 2002:a0d:cdc4:0:b0:615:25e8:e789 with SMTP id p187-20020a0dcdc4000000b0061525e8e789mr3132262ywd.11.1712771221071; Wed, 10 Apr 2024 10:47:01 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712771221; cv=pass; d=google.com; s=arc-20160816; b=QmKR7YXfnnFpL1EN5/BauWM0ob6R3AXpATtNKCkBc1XzHWs22vTRmHSv4d140lRk33 zxKW81Hq42W61uUwRH95md4CDNl+8+BkX9749DD2Spk/rAh3n4NleV04Dj7qiYJTcQC5 YV2gVdDoA2pNPXeBp1iiKjNaM9l70vAavCuXFsLExkfPh4snCaDyy0lh5NpvQSNNqis0 IZaGJP8PTr9Rg/THrFpM9QXbkrNNdAUNxtWDl6ltcSAKnmfsDhCbLz8JnUkl/b2kwb63 qX8HNvugbeQskAj4FOhAyxZOXmrfzfqANLAsiYMhFRMc9ngQgqF08nycQzWS1BGAR6V+ 3WUg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=aAjKEhdqLksa1eY7GYJvJB5hcsToOrc/f2H9QlDLPko=; fh=0I/rqIlL4373pOps8oaBYF1ECx5xbCzL9wLU5PgpMhU=; b=BdTepExa6rKQxDqhQPlqR6GF1qihd18tUuggSS4+TOugvNuBEvF/xylCaqCm9ngnhO U0g8vRR5UEaSj3OGYv0yNusKgAmZozRqAt6YndyqnxVttjGlotCkAwKJwJh1Hdtt7QU6 tQXyUWHmnQL5YGgJagO2iSq3vzhikfm77pOcESh9SNp94NtZc2S4aaMdXRIOS8rvrcX5 lNCzDK599E77as6b8WvkzlbspPYZU8Noh0aKRa+82awqif/zjUsHQMDMGDummiVJTpcs bAmGoqaUT1E8FoA7TrtWn9ZEXUn19Hq9rNH6M3RYEwRqUPS5lwy293B+q5j4rpXglhwy dtbg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=fail header.i=@rjwysocki.net header.s=dkim header.b=PFd4Pnfu; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-139127-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139127-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id kk27-20020a056214509b00b0069b0f343646si10000382qvb.296.2024.04.10.10.47.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Apr 2024 10:47:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-139127-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=fail header.i=@rjwysocki.net header.s=dkim header.b=PFd4Pnfu; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-139127-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-139127-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 9CF321C22B9C for ; Wed, 10 Apr 2024 17:47:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 014011836CF; Wed, 10 Apr 2024 17:45:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="PFd4Pnfu" Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 99F4117F386; Wed, 10 Apr 2024 17:44:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712771101; cv=none; b=bo0UvWjvxzKq0vTY019y6JBpbyw36P5QNZOQRgEBEJ8x114vowNVOsI8OQ8GaIQ/AGHmWJ1jEWxU2xc5iPv6YyGcNOxZZeb+ekfDE/puKHjIxAwJpHDVQ+aWUoZFt8Og4XebPl3oYaC1sN7MBLUUdmAjO46e8Ga/31X8Kfd7Hrk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712771101; c=relaxed/simple; bh=LGkyxZF0PHa0nrno/l51CpkO39W2SEJqZy9TmB+6QRg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Fm/D8fiAYJT7zFtunp1eL4bUs6tZN2/nMp/CseU62JUpAd2kPgZCYDDzcQDM+z1kNC27NiUFzJbtMjrXtk/38In9AU0CKcLYLLrwf0OYwBNdh775cJASABhO+LoDTl23i2fvG2TRkN75LCUfFSlgEkUlnyOb00DmXMj/hNgXtfw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; dkim=fail (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=PFd4Pnfu reason="signature verification failed"; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 6.0.0) id 35a41b4e0f4d8a5b; Wed, 10 Apr 2024 19:44:56 +0200 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cloudserver094114.home.pl (Postfix) with ESMTPSA id 0315A66C66F; Wed, 10 Apr 2024 19:44:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1712771096; bh=LGkyxZF0PHa0nrno/l51CpkO39W2SEJqZy9TmB+6QRg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=PFd4PnfuwqoxTeV+/vTulCWAHAsOARQ7KIW2CqYaROB+XDAUqN2JWPJX3aupypiOR +q+0PEGWzfQDmf75DgFPy+xNSECNZswinNIhaoRRypzuRImGqTMETV/14Aa/MTDtcy me+WW3crr8nQwl+2s+27p7ZZ07/EuMC56g1iWi/LHIXe+CRNAluTJDaEgtfv328+Pw BzDy/5umADv/sXkfVq9EkuG7weP9ykvbS5RHWgUkasDlqlSPl5/VJhy9Glc3OcVmiu FCipURR1sGpQeCK3I1tnjdyOV/hBrRX81/anI2tnDRb/lRHIN6GGp8t9n6mWdGGzo8 9qa3ZjlEihoUA== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Daniel Lezcano , Lukasz Luba , Srinivas Pandruvada Subject: [PATCH v1 01/16] thermal: core: Introduce .trip_crossed() callback for thermal governors Date: Wed, 10 Apr 2024 18:10:53 +0200 Message-ID: <2009494.usQuhbGJ8B@kreacher> In-Reply-To: <13515747.uLZWGnKmhe@kreacher> References: <13515747.uLZWGnKmhe@kreacher> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvledrudehiedguddugecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeehpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrghdprhgtphhtthhopehluhhkrghsiidrlhhusggrsegrrhhmrdgtohhmpdhrtghpthhtohepshhr ihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthgvlhdrtghomh X-DCC--Metrics: v370.home.net.pl 1024; Body=5 Fuz1=5 Fuz2=5 From: Rafael J. Wysocki Introduce a new thermal governor callback called .trip_crossed() that will be invoked whenever a trip point is crossed by the zone temperature, either on the way up or on the way down. The trip crossing direction information will be passed to it and if multiple trips are crossed in the same direction during one thermal zone update, the new callback will be invoked for them in temperature order, either ascending or descending, depending on the trip crossing direction. Signed-off-by: Rafael J. Wysocki --- drivers/thermal/thermal_core.c | 19 +++++++++++++++++-- drivers/thermal/thermal_core.h | 4 ++++ 2 files changed, 21 insertions(+), 2 deletions(-) Index: linux-pm/drivers/thermal/thermal_core.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.c +++ linux-pm/drivers/thermal/thermal_core.c @@ -302,11 +302,21 @@ static void monitor_thermal_zone(struct thermal_zone_device_set_polling(tz, tz->polling_delay_jiffies); } +static struct thermal_governor *thermal_get_tz_governor(struct thermal_zone_device *tz) +{ + if (tz->governor) + return tz->governor; + + return def_governor; +} + static void handle_non_critical_trips(struct thermal_zone_device *tz, const struct thermal_trip *trip) { - tz->governor ? tz->governor->throttle(tz, trip) : - def_governor->throttle(tz, trip); + struct thermal_governor *governor = thermal_get_tz_governor(tz); + + if (governor->throttle) + governor->throttle(tz, trip); } void thermal_governor_update_tz(struct thermal_zone_device *tz, @@ -470,6 +480,7 @@ static int thermal_trip_notify_cmp(void void __thermal_zone_device_update(struct thermal_zone_device *tz, enum thermal_notify_event event) { + struct thermal_governor *governor = thermal_get_tz_governor(tz); struct thermal_trip_desc *td; LIST_HEAD(way_down_list); LIST_HEAD(way_up_list); @@ -493,12 +504,16 @@ void __thermal_zone_device_update(struct list_for_each_entry(td, &way_up_list, notify_list_node) { thermal_notify_tz_trip_up(tz, &td->trip); thermal_debug_tz_trip_up(tz, &td->trip); + if (governor->trip_crossed) + governor->trip_crossed(tz, &td->trip, true); } list_sort(NULL, &way_down_list, thermal_trip_notify_cmp); list_for_each_entry(td, &way_down_list, notify_list_node) { thermal_notify_tz_trip_down(tz, &td->trip); thermal_debug_tz_trip_down(tz, &td->trip); + if (governor->trip_crossed) + governor->trip_crossed(tz, &td->trip, false); } monitor_thermal_zone(tz); Index: linux-pm/drivers/thermal/thermal_core.h =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.h +++ linux-pm/drivers/thermal/thermal_core.h @@ -30,6 +30,7 @@ struct thermal_trip_desc { * otherwise it fails. * @unbind_from_tz: callback called when a governor is unbound from a * thermal zone. + * @trip_crossed: called for trip points that have just been crossed * @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. @@ -40,6 +41,9 @@ struct thermal_governor { const char *name; int (*bind_to_tz)(struct thermal_zone_device *tz); void (*unbind_from_tz)(struct thermal_zone_device *tz); + void (*trip_crossed)(struct thermal_zone_device *tz, + const struct thermal_trip *trip, + bool crossed_up); int (*throttle)(struct thermal_zone_device *tz, const struct thermal_trip *trip); void (*update_tz)(struct thermal_zone_device *tz,