Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp1635439rdh; Mon, 25 Sep 2023 21:10:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGk9VuymcsPSF0kvlzO2kek4Djygn3g3R2h+9K643Bt20mIOL92j8lyKaiTdeXOsZuM9aov X-Received: by 2002:a05:6358:c1d:b0:132:ce36:ee31 with SMTP id f29-20020a0563580c1d00b00132ce36ee31mr11965393rwj.6.1695701404190; Mon, 25 Sep 2023 21:10:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695701404; cv=none; d=google.com; s=arc-20160816; b=RHo7OFh8OjWzrdTNYcsMjpqJiETLDXVgudgzj4w3/ZKji54OqN+I/Dhj8lJrkiZYdg RUngQuY1LkdRJCQclR8o5SE2jG1LEdnigQ0uCeqFAG3fgwfJzbLWmOw5DGvFK2V4NJJp +XIWFisHZz1pBtahVZmTdUdcFRaiOwBIYoF8gy+fxC5eBPzCVy3jqeYcGRLsOsqxoDDX NPNeoNYvBzCTmtajKPOXyqHWs8Gce3rmvGG/Gl5uO9ItkRISMuX3b/pINFN82mm/K9GB QnZCGiPvDZ5vnR0OX9eGM3erYwpkwE6f3i962KPpuVpf1YR0xoDBPxMbuGiuDeLQcvMK 37jQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=BC8XzDCC2+ytAVgFt1YH3G2j/bxb2qmBN7aCcRUdHug=; fh=Jgoc1RjTRuI+xL2E58LMPlFslqmvOggIZYg3k5Ya9F0=; b=NQd1eO4gpjdCan1NrqlIc5hrSQ/mbzvyLINVJRy09ZqN2nMni0hJSQ5hD2h2s8IX5V YCvatMLQsH78TFwEd5NkHVA65bItXcrFpyrJ4bR3d0Qgu5tEtWqMcok0RPXr0qJrsZz9 JSdedlWhEB8/SX5RftpBCRn0NH/4LJn6NEmG6d38ky9cwidJFwTpiEVJWENt2FfyPwxR DfTVUWsnKai9fHIff5VNi43VShoNOXnErbVs5wwFB7ragrvZjbqewWB8gK8GaqgC9lUJ Gf9WVhBva0kKzqRbLcSO4pdEvDqQ0KhnwEi65mlWl0a3IjqKLuQ1MBmFa5sttF7ZlvVu SBSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=i9hHKlbf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id a21-20020a63e855000000b00565dd108fd4si11695731pgk.115.2023.09.25.21.10.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Sep 2023 21:10:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=i9hHKlbf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 858CB806AFC4; Mon, 25 Sep 2023 09:20:53 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233195AbjIYQUz (ORCPT + 99 others); Mon, 25 Sep 2023 12:20:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231689AbjIYQUx (ORCPT ); Mon, 25 Sep 2023 12:20:53 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 222BECE; Mon, 25 Sep 2023 09:20:47 -0700 (PDT) Received: from notapiano (zone.collabora.co.uk [167.235.23.81]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: nfraprado) by madras.collabora.co.uk (Postfix) with ESMTPSA id 8AA086607083; Mon, 25 Sep 2023 17:20:44 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1695658845; bh=hLrIxPnIrH+CavuOWQVjMQm2fM6kCBplHnPFlCTy1Fs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=i9hHKlbf+AxbsU9Vfk8qvmq56+Cd8O1+RlbISjcVCQ4M+mAbPiUF7L+/E1dtIYXz6 zBWeW/7XUOOnnx7hlIJ7Y/zCIsYxyh1MlSGprZLj2bxkI+0wScsuFw3nCY3Il2jYIE VDVBpLsDIVu1fAxpbuxmTnSuNJpS+7NiOTpjo91hsDEheYJlarbisBIIGrxJ1pMhnc ezfxL/DybGO3ZEziv44mB17mQVtJEgoAoiNOR/w4Uixuxkl+nb6H0iCbAKxKVrWKEO tnOXU25RBIWzHqBVXHA4irjsQPeKlLd8EjUPOd1TAXAVyDnkXfynqJvzP9i3ztOuOB b6Q46VZn5t6mA== Date: Mon, 25 Sep 2023 12:20:40 -0400 From: =?utf-8?B?TsOtY29sYXMgRi4gUi4gQS4=?= Prado To: Daniel Lezcano Cc: "Rafael J . Wysocki" , kernel@collabora.com, AngeloGioacchino Del Regno , Amit Kucheria , Zhang Rui , linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org Subject: Re: [PATCH] thermal: core: Check correct temperature for thermal trip notification Message-ID: <4b38b84a-7427-45b1-b8e6-c68c5dbce676@notapiano> References: <20230922192724.295129-1-nfraprado@collabora.com> <7558dd96-0d96-9463-9a97-7ea8bac2046e@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <7558dd96-0d96-9463-9a97-7ea8bac2046e@linaro.org> X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Mon, 25 Sep 2023 09:20:53 -0700 (PDT) On Mon, Sep 25, 2023 at 12:19:18PM +0200, Daniel Lezcano wrote: > > Hi Nicolas, > > On 22/09/2023 21:27, Nícolas F. R. A. Prado wrote: > > The thermal trip down notification should be triggered when the > > temperature goes below the trip temperature minus the hysteresis. But > > while the temperature is correctly checked against that, the last > > temperature is instead compared against the trip point temperature. The > > end result is that the notification won't always be triggered, only when > > the temperature happens to drop quick enough so that the last > > temperature was still above the trip point temperature. > > > > Fix the incorrect check. > > > > Fixes: 55cdf0a283b8 ("thermal: core: Add notifications call in the framework") > > Signed-off-by: Nícolas F. R. A. Prado > > > > --- > > > > drivers/thermal/thermal_core.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c > > index 58533ea75cd9..120fcf23b8e5 100644 > > --- a/drivers/thermal/thermal_core.c > > +++ b/drivers/thermal/thermal_core.c > > @@ -361,7 +361,7 @@ static void handle_thermal_trip(struct thermal_zone_device *tz, int trip_id) > > tz->temperature >= trip.temperature) > > thermal_notify_tz_trip_up(tz->id, trip_id, > > tz->temperature); > > - if (tz->last_temperature >= trip.temperature && > > + if (tz->last_temperature >= (trip.temperature - trip.hysteresis) && > > tz->temperature < (trip.temperature - trip.hysteresis)) > > thermal_notify_tz_trip_down(tz->id, trip_id, > > tz->temperature); > > We already did a try to fix the thermal trip cross notification but this is > not sufficient for a full fix. > > We are receiving multiple notifications from the same event, all this due to > the hysteresis. > > Let's say, we have a trip point T and a hysteresis H. > > There is a trip point crossed the way up when: > > last_temperature < T and temperature >= T > > At this point, we send a notification > > Now, the temperature decreases but it stays in the hysteresis: > > last_temperature >= T and temperature > (T - H) > > And then, the temperature increases again and is greater than T. > > last_temperature > (T - H) and temperature >= T > > We send a second notification. Right, I've observed this issue in the logic that updates the trip points, and just sent the v2 fix for it: https://lore.kernel.org/all/20230922184425.290894-1-nfraprado@collabora.com I wasn't aware of the cleanups you pointed to below, but at least in their current form it doesn't seem they would take care of fixing the trip point update logic like I did in that patch. So please do take a look. It was while testing that patch that I stumbled upon this code for the notification and just quickly fixed it. But indeed this patch is not a full fix as the one you pointed to, so let's wait for that one. Thanks, Nícolas > > With the mitigation kicking in at temp >= T, we end up with multiple events > 'temperature crossed the trip point the way up"'. That forces the receiver > of the events to detect duplicate events in order to ignore them. > > More info: > > https://lore.kernel.org/all/20220718145038.1114379-4-daniel.lezcano@linaro.org/ > > We have done a lot of cleanups to use the 'generic trip points' and remove > those get_trip_* ops. So the trip point structure is a core component being > reused by the drivers and registered as an array. > > Next step is to make sure the trip points are ordered in the array, so we > can implement the correct trip point crossing detection. > > > > > -- > Linaro.org │ Open source software for ARM SoCs > > Follow Linaro: Facebook | > Twitter | > Blog >