Received: by 2002:a05:7208:3003:b0:81:def:69cd with SMTP id f3csp4276543rba; Tue, 2 Apr 2024 12:05:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWMMaCaybVGxygvBpb+tOs7dY8WSj/o29T7QBsWVSYdvGtP2YUcXcHBq1xvqeZcs4ldw1cKY3rUsky59KWZs23R+eeKJYfdavy3L+EgHQ== X-Google-Smtp-Source: AGHT+IEYBJkDVLsU1uvGrbBVe1ppGxGKgMAOiraZNJvMRVeI0rt2BVQxxnAYvf0cgSlLeRGq0rUy X-Received: by 2002:a2e:b5da:0:b0:2d6:90e4:1ced with SMTP id g26-20020a2eb5da000000b002d690e41cedmr9211816ljn.22.1712084738689; Tue, 02 Apr 2024 12:05:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712084738; cv=pass; d=google.com; s=arc-20160816; b=bJpXWbRjxs5jdureDd6hDAjYRVg5J78JVJwerJCOvTzon6rF+wyOriBEqjkrhe5auq WRbiw0UUcKmIfUMAXST+9abcTk3Jo/cgE1k1bRSzX5ET8qUpQnkAxTcDlf/PMwJ53sF/ 1E9o9UxgEc47xAkuTmxkVK951rau5g7IGoWtmNmuLgXsM2uDdkGRKrecsRywnzx8p/XV ApuTmCWFrcZn7rfIbHv1sb7oevKSqzkgkIwtYnhSthzYhXrAsUJZyjgJiXN6mVNxnog8 /an3YdEwIMdlvSxfprC4wPlvfVsiJN0dIAoQMeuhYhAxn3LhHH6X8RmS0rflKqFkwsOx t0eg== 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=v0ahqx4E26jiuRfQjNyhxMEjnoTZf2bndMhQui1QepE=; fh=cogxfxmfuty1INqTmQqsiEMMrqp+W8B7xyoJyzbm4Sw=; b=v8ErRjS7qKQGJKN9+PeWqEAenB/kpdAe5fuJMihALih6qRHEVpKMO0JLyc6XuPdYQT uN5gB4d93d57pOaJ9qj3lCA3gHPZeYVwdnMpPNQW4zqsdmUlakvsTAAvcABXYHrDPN3+ nTRUsDwFPn1dye3EZkINQy3rihi71o97/T80+t37pkYmhwmdfIa9NQ9lpFj6nVXYSLDi d2MKbr1dd7Znu7YUPolLgT0BINPxwzUqYt90vLW1oFeEK5af6j6PFLe+Chj/n2a6kePh ukIqkM3tJrneAnPUL57vRoN9b4PK9/xiNTC3nVPfnRKO+5GAqbTBP6A7W0H6lXsMWNYn ntJA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=fail header.i=@rjwysocki.net header.s=dkim header.b=kSHA0010; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-128537-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-128537-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id b28-20020a50ccdc000000b005688537e44asi5918186edj.488.2024.04.02.12.05.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Apr 2024 12:05:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-128537-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=fail header.i=@rjwysocki.net header.s=dkim header.b=kSHA0010; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-128537-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-128537-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 17C5A1F237D3 for ; Tue, 2 Apr 2024 19:05:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0F61A15CD49; Tue, 2 Apr 2024 19:04:53 +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="kSHA0010" 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 DA97715B545; Tue, 2 Apr 2024 19:04:49 +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=1712084692; cv=none; b=eZrh0egYldR9pJNPH7dqmcgUmAyNAbBTA/UbWk9A1Js0TdjAL/wAeGy+wjtkL85tM3WbOoqbSPWf9Kw4rm0jfhyjcCtJmP5ChRM76XKMHq5BSCRtBUc2S5iCluj0bZCULgesy3gKhvmpi3njVb9qq+qM0CMMHzX9uel3P0NNvVk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712084692; c=relaxed/simple; bh=2dcqxo9c6BdB6SEFCjR+IPVn6M6pE3yvQx46EWwBfdM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=D6MJcOzzLTRY2hzcPpV2wCbcr5i0HSs/26+k6wXq0DYISgrkAeSfECdwzgu+vSH7ib3YLWUBQhzDxFZkBij+l1fd8J8OuEvhpmC6iA/PjyTcEUNZB+vN5k+klkuerRf/Rb+FvGD9BNC2vtysgy3lxkwYGvYUB9llZY4tjeNLnrM= 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=kSHA0010 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 3a062e1005967750; Tue, 2 Apr 2024 21:04:42 +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 138A066C5C5; Tue, 2 Apr 2024 21:04:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1712084682; bh=2dcqxo9c6BdB6SEFCjR+IPVn6M6pE3yvQx46EWwBfdM=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=kSHA0010Tl88AoTXE08yRucGzMwtjGZhSRByMzrU0LhaJLKY6dUzoJC4tejRtS9H9 0uanEKn+Rpz9Ow+WvhBdAYUe+XotFnEWuLRm5CQpWcGk1ionX8b+GNx6c8sT/kgaTC 0OSGPbGumTHhJTjJ9j2mSJ9eGMJZOUe02Of4rzSbrY6xU9OGr30V6ljhYPdHlVQvvo h/B2fizeMAwe/bAxfSTvi6iJCtGWRPw03PN7Xo1aoUTNcncBtTHQ35Xw/b5rOqsdio D04ubleazI13t+pdXQRo5OEIu7vscFVG+HBkatfeiYl8+YkfGHUtuD+sUr9WMli51n L1eo3D97uMgMw== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Srinivas Pandruvada , Daniel Lezcano , Lukasz Luba , AngeloGioacchino Del Regno Subject: [PATCH v3 4/6] thermal: core: Send trip crossing notifications at init time if needed Date: Tue, 02 Apr 2024 21:02:10 +0200 Message-ID: <1963742.PYKUYFuaPT@kreacher> In-Reply-To: <4558251.LvFx2qVVIh@kreacher> References: <4558251.LvFx2qVVIh@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: gggruggvucftvghtrhhoucdtuddrgedvledrudefvddgudefvdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeeipdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthgvlhdrtghomhdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgr rhhordhorhhgpdhrtghpthhtoheplhhukhgrshiirdhluhgsrgesrghrmhdrtghomhdprhgtphhtthhopegrnhhgvghlohhgihhorggttghhihhnohdruggvlhhrvghgnhhosegtohhllhgrsghorhgrrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=6 Fuz1=6 Fuz2=6 From: Rafael J. Wysocki If a trip point is already exceeded by the zone temperature at the initialization time, no trip crossing notification is send regarding this even though mitigation should be started then. Address this by rearranging the code in handle_thermal_trip() to send a trip crossing notification for trip points already exceeded by the zone temperature initially which also allows to reduce its size by using the observation that the initialization and regular trip crossing on the way up become the same case then. Signed-off-by: Rafael J. Wysocki --- v2 -> v3: New patch --- drivers/thermal/thermal_core.c | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) Index: linux-pm/drivers/thermal/thermal_core.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.c +++ linux-pm/drivers/thermal/thermal_core.c @@ -364,6 +364,7 @@ static void handle_thermal_trip(struct t struct thermal_trip_desc *td) { const struct thermal_trip *trip = &td->trip; + int old_threshold; if (trip->temperature == THERMAL_TEMP_INVALID) return; @@ -375,25 +376,11 @@ static void handle_thermal_trip(struct t * is what needs to be compared with the previous zone temperature * to decide which action to take. */ - if (tz->last_temperature == THERMAL_TEMP_INVALID) { - /* Initialization. */ - td->threshold = trip->temperature; - if (tz->temperature >= td->threshold) - td->threshold -= trip->hysteresis; - } else if (tz->last_temperature < td->threshold) { - /* - * There is no mitigation under way, so it needs to be started - * if the zone temperature exceeds the trip one. The new - * threshold is then set to the low temperature of the trip. - */ - if (tz->temperature >= trip->temperature) { - thermal_notify_tz_trip_up(tz, trip); - thermal_debug_tz_trip_up(tz, trip); - td->threshold = trip->temperature - trip->hysteresis; - } else { - td->threshold = trip->temperature; - } - } else { + old_threshold = td->threshold; + td->threshold = trip->temperature; + + if (tz->last_temperature >= old_threshold && + tz->last_temperature != THERMAL_TEMP_INVALID) { /* * Mitigation is under way, so it needs to stop if the zone * temperature falls below the low temperature of the trip. @@ -402,10 +389,18 @@ static void handle_thermal_trip(struct t if (tz->temperature < trip->temperature - trip->hysteresis) { thermal_notify_tz_trip_down(tz, trip); thermal_debug_tz_trip_down(tz, trip); - td->threshold = trip->temperature; } else { - td->threshold = trip->temperature - trip->hysteresis; + td->threshold -= trip->hysteresis; } + } else if (tz->temperature >= trip->temperature) { + /* + * There is no mitigation under way, so it needs to be started + * if the zone temperature exceeds the trip one. The new + * threshold is then set to the low temperature of the trip. + */ + thermal_notify_tz_trip_up(tz, trip); + thermal_debug_tz_trip_up(tz, trip); + td->threshold -= trip->hysteresis; } if (trip->type == THERMAL_TRIP_CRITICAL || trip->type == THERMAL_TRIP_HOT)