Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp646785rdh; Thu, 26 Oct 2023 11:37:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFWCX4di4IhA4HwwErGJY+nHyBA8lqVmPAStrDjXrziAoiwUGUHy0WWEs5VwcUeaLOSVpEJ X-Received: by 2002:a25:730c:0:b0:d9a:c22a:6edc with SMTP id o12-20020a25730c000000b00d9ac22a6edcmr216506ybc.30.1698345457169; Thu, 26 Oct 2023 11:37:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698345457; cv=none; d=google.com; s=arc-20160816; b=GOLV2u7oGp3FCshnQcnqz16Qy2THDFgXg0KqTaIaB1XSg12RvQl9aoA6z5s6ODIRN1 JTPCC5GOIvuBvJkNFxrzBkO5ln1uvbtqO/jQZJZxKow4TnAq64hU37BCrCO+6/Ct+Qmg 28YBX7SfipZLjmk8sf1diibEc7wP0vGBPRaVCr0yno7ec4Y5NF2XVL0eV3bmMqPG99aL Ai6cma7Mdc+LbGcoWm81SyWy/Uitk24NPBqg4QTvsFSEYOKMg4wl6GYQPsItJId9fJ0k Eiu8Ni62DCGeA1+ryMmxgufefUTwOhgRRszW62sEgi5vKUJMPSmv+tWdB5M0iy2CfI+q 8L1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=KQFdeF8kIecUIKj9PQy8Qr/Rmh+0tGzyVv4FSgMbfo4=; fh=pNdHsxA/YANpPA+ZPocnjDwVzj7jx7TxoLVsRB+Y3+g=; b=KPl2obEXuy+VAsccDUzpqs9jOAg/1/KlumhmO2wkaaSclme0/Zt7lV2JAIl8SdsX35 Izw4L0odaE4Iw+v56U63ckmxE13V74MWGnEw31rgMUQ/I4rqAwpsDvpCazAihjoZlckC wJ3Sr7T9yyYsyryE41kvHnLuqZn6C1EOBgK6m233gHfGiOuTsphZ3QNiPTXktVX/4yAx Y3yX3t7thpKePxMTdR7G3yPkl91jrvJ2UOks5art8QA9Gf1CHwG1iNTFJw/XcexpMbqq IOQu+8PwHz2RqvPOt5ImVcfj1i4cQe+5FjlU9jQqMw4SjH9iHT8IP3wJY6UxkPAEdOBj wyOw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id e184-20020a25d3c1000000b00d7fd6a7d57esi14540917ybf.625.2023.10.26.11.37.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 26 Oct 2023 11:37:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id E6B748233653; Thu, 26 Oct 2023 11:37:33 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230143AbjJZShZ convert rfc822-to-8bit (ORCPT + 99 others); Thu, 26 Oct 2023 14:37:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229501AbjJZShY (ORCPT ); Thu, 26 Oct 2023 14:37:24 -0400 Received: from mail-oo1-f47.google.com (mail-oo1-f47.google.com [209.85.161.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66C971A5; Thu, 26 Oct 2023 11:37:22 -0700 (PDT) Received: by mail-oo1-f47.google.com with SMTP id 006d021491bc7-581e106fd25so183173eaf.0; Thu, 26 Oct 2023 11:37:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698345441; x=1698950241; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9JI4dp+Kg7iVHX3cVBNafUR1doVjzD9jk5YuxgZ3wiM=; b=dL9bsiRezZjp2j1U55oB60d9nll0FYoAz25VXTobtq42eY1ICLC0F9nA/euChrn66V 7Ibmyez0fLaAahVX958wyxDaCSZx1vEDJyXF14+l0t3kKvMW/ZltLCWdXVL41qeVxdpd SK8yKP2+1C6HaE8pPF07Q/VsSV03ujmCmXQmdu9G+EY+MQRDY6UqvVDq9Ps9+j5hk1a0 9dicN1hHa2lS5lJdj5IIUdjWNF8o/hAaqCuYVGD0it1UWqcQtcH+20UyPcaQ35oQRTxS lGFtD9rr78DLzguXxbkK6YjrGW4QEs1ips1c6BGe+3Er4oTIBfYg8RmpkcQG7/OlfDXd h3BA== X-Gm-Message-State: AOJu0Yycw5o4ZHeSJ1pbwdmRkZzinjXOYqpMwKjTlot8FNkD7j8W9L05 eRwsDDZJcVQ1q3hUC1pB05ScdKr4PtQRJdKXPrk= X-Received: by 2002:a4a:c991:0:b0:586:7095:126d with SMTP id u17-20020a4ac991000000b005867095126dmr386761ooq.0.1698345441597; Thu, 26 Oct 2023 11:37:21 -0700 (PDT) MIME-Version: 1.0 References: <20220715210911.714479-1-daniel.lezcano@linaro.org> <20220715210911.714479-4-daniel.lezcano@linaro.org> In-Reply-To: <20220715210911.714479-4-daniel.lezcano@linaro.org> From: "Rafael J. Wysocki" Date: Thu, 26 Oct 2023 20:37:10 +0200 Message-ID: Subject: Re: [PATCH v3 4/4] thermal/core: Fix thermal trip cross point To: Daniel Lezcano Cc: rafael@kernel.org, quic_manafm@quicinc.com, rui.zhang@intel.com, amitk@kernel.org, lukasz.luba@arm.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on howler.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 (howler.vger.email [0.0.0.0]); Thu, 26 Oct 2023 11:37:34 -0700 (PDT) On Fri, Jul 15, 2022 at 11:09 PM Daniel Lezcano wrote: > > The routine doing trip point crossing the way up or down is actually > wrong. > > A trip point is composed with a trip temperature and a hysteresis. > > The trip temperature is used to detect when the trip point is crossed > the way up. > > The trip temperature minus the hysteresis is used to detect when the > trip point is crossed the way down. > > |-----------low--------high------------| > |<--------->| > | hyst | > | | > | -|--> crossed the way up > | > <---|-- crossed the way down > > For that, there is a two point comparison: the current temperature and > the previous temperature. > > The actual code assumes if the current temperature is greater than the > trip temperature and the previous temperature was lesser, then the > trip point is crossed the way up. That is true only if we crossed the > way down the low temperature boundary from the previous temperature or > if the hysteresis is zero. The temperature can decrease between the > low and high, so the trip point is not crossed the way down and then > increase again and cross the high temperature raising a new trip point > crossed detection which is incorrect. The same scenario happens when > crossing the way down. > > The trip point crossing the way up and down must act as parenthesis, a > trip point down must close a trip point up. Today we have multiple > trip point up without the corresponding trip point down. > > In order to fix that, we store the previous trip point which gives the > information about the previous trip and we change the trip point > browsing order depending on the temperature trend: in the ascending > order when the temperature trend is raising, otherwise in the > descending order. There is an alternative way of addressing this problem which doesn't require using information regarding the previous trip point and so it would work even if the trips were not sorted. Namely, for each trip there can be an effective threshold equal to either its temperature. or its temperature minus its hysteresis (low temperature). If the initial zone temperature is below the trip's temperature, the initial value of its threshold is equal to its temperature. Otherwise, the initial value of the trip's threshold is its low temperature. Then, if the zone temperature crosses the threshold (either up or down), the trip crossing triggers and the threshold value is flipped (that is, if it was equal to the trip's temperature, it becomes its low temperature or the other way around). [Note that if the threshold value is equal to the trip temperature, it can only be crossed on the way up, because it means that the zone temperature was below it at one point and has not grown above it since then. Conversely, if the threshold value is equal to the low temperature of the trip, it can only be crossed on the way down, because it means that the zone temperature was above the trip temperature at one point and it has not fallen below the trip's low temperature since then.] This should not be hard to implement AFAICS and it should also work in the cases when one trip is located in the hysteresis range of another one.