Received: by 2002:ab2:7a55:0:b0:1f4:4a7d:290d with SMTP id u21csp357827lqp; Thu, 4 Apr 2024 15:55:50 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUc3WhVECnOeNUgyQ3lzoEdOzyFw6Nr+MqlxE/CLS4EbIdurI1d/88CUXImCiuAwkOzW+0pki0arvKTIrg5ysyiRCJMGO3Nzm8HHtrPtw== X-Google-Smtp-Source: AGHT+IHANiAH5rs29l6vUO9x0ZVEDJdBQmR2yo/JOvhLu4hXTC7DPTIQdJaMK88YAGCRVm1w51Wx X-Received: by 2002:a50:cd56:0:b0:568:9d96:b2d1 with SMTP id d22-20020a50cd56000000b005689d96b2d1mr2261134edj.32.1712271350530; Thu, 04 Apr 2024 15:55:50 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712271350; cv=pass; d=google.com; s=arc-20160816; b=d6pVn3zojyMKKoKoLnj2M/stm5RyvExYdZPq3UZi4A4vEqsmoMsEGVU52qWH1N4IsH VVjQW8sSi8XBbZ34cSFzwWvihQ84+L6N+UpQrNL+jwbVcRayQzr6aLouUN7oeia6KBkH +AndbLg3rQ7wRrsyd4UMoagmI2aQhdwF8+QKDQDUOcf/Lc/Rt2SOaSGfhx0eZoVxXHTI EjBnB9NZSTfA/BWATtWkA8G6kp5k9pWxRhu9z9PVXAtTXtoxfCtBfYtYRYlA140HvYZF cWe0ohj1rGq55nD+aDxAvUDUvPmUVp5oIneyUoav6RIJ60qh6dM/7XE28pZLSsStWHJ+ HtYg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id; bh=Zs+QJp4+udAP0Wbu5IxQl0ZET+HqXPzYjY3F5Jf1ci0=; fh=OnjlES3ltT1rfj1xqWlPH5gHLUiiHEk+YdAUQDlLl9M=; b=CDcnYe6N/NNe2bYhATm/oJspCeDj5H/OlneFMHOHsz7Iqg1xotg47gryLSWeT7Ddyl 1gBWJuuXcSpJqnVbs6s1VbJ0aAmy+zcMlh0C18S5dHMF6MoVkIIqQqttiL/EKHCO1RGw HUDqcPCeIg2f5IcmRhfqPrGWGewWAB1gtddqirFyY8E6baVTZ3UXTZQ+dOr0uLoPdRiA wmeOpVIn48uy36pdHg2zoxe++FD7Ccp+DsSTPXdNrLiiWm/iPZSHtewDt9gjmOzQdYMq GYqmuPAyJQIwxPSvH3RMJ2FzRDniQqcbefbJ5OCrVe01Iib9Le/+xkcbkjUB/uDqX6ua 75iw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-132226-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-132226-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id v19-20020a50a453000000b0056c366daf26si109265edb.211.2024.04.04.15.55.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Apr 2024 15:55:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-132226-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-132226-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-132226-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com 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 8A4231F245EE for ; Thu, 4 Apr 2024 22:55:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 57575130E57; Thu, 4 Apr 2024 22:55:32 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 37C256FE10; Thu, 4 Apr 2024 22:55:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712271331; cv=none; b=DWs6LwEW9GIgluh3KKIuUL6m8x013AmweDsef/yYcslk1ykCFgCtpcmnhA90/wEGWiFhzYWiKh9JhxluCABbRsTIsNOJJkio2J5/qe9T3Wn0xXMpMtMhPFyhqMPZcyaI/guuPUGLhxLz8VUxHQnFMS8z35k7qfDscwL9rY++j+Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712271331; c=relaxed/simple; bh=3BrtSsu4JmIxtpA3OukraRS6gbk129BBLvWSTnlks/k=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=Rf7pRGzNpi0pQ8tZ3CEtPoSrpc4O584WikP9QZ/6tiGb0TpdT15UDxt6l+8LZCM/sfM91T+YI7K4oBQWi2yZJs8NBWrYW5w00wZuzapDLN1Gt3HulyZyHH3GMjiD6RX4N93C64GO2BxcsM+WbeW54isWV60T5+1TOhdi4wksFv0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 292ABFEC; Thu, 4 Apr 2024 15:55:59 -0700 (PDT) Received: from [10.57.73.43] (unknown [10.57.73.43]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 728E43F64C; Thu, 4 Apr 2024 15:55:27 -0700 (PDT) Message-ID: <69975465-0477-4f15-a4fe-899642c31a3d@arm.com> Date: Thu, 4 Apr 2024 23:55:30 +0100 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 4/6] thermal: core: Send trip crossing notifications at init time if needed Content-Language: en-US To: "Rafael J. Wysocki" Cc: LKML , Linux PM , Srinivas Pandruvada , Daniel Lezcano , AngeloGioacchino Del Regno References: <4558251.LvFx2qVVIh@kreacher> <1963742.PYKUYFuaPT@kreacher> From: Lukasz Luba In-Reply-To: <1963742.PYKUYFuaPT@kreacher> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 4/2/24 20:02, Rafael J. Wysocki wrote: > 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) > > > Reviewed-by: Lukasz Luba