From patchwork Mon Jan 15 17:55:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 188274 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2614:b0:101:6a76:bbe3 with SMTP id mm20csp1854979dyc; Mon, 15 Jan 2024 09:58:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IGbm8DpWN6Q3BrlONDIvxT0QIR3B3SAWF94UQMIQCkNSAXoA393Z7YHIf/06Q3xkWuxNqWW X-Received: by 2002:a05:620a:4155:b0:783:2691:a4df with SMTP id k21-20020a05620a415500b007832691a4dfmr8973754qko.76.1705341506682; Mon, 15 Jan 2024 09:58:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705341506; cv=none; d=google.com; s=arc-20160816; b=DCej0if0Is8yL5beDRHHj2WkqmVLTttPZ9JC92YW6jcBzF99HUVtjHzeQdHXkILGeZ ciYyQpH2645PwSuwaJDzINaUKK5+v3d0TUs9V4swFkXqHcoN5cXes5wS3mNHo1chr0wS ArGYYv0sheE29uawxFK6eAWnf8NNYWz6z2GCwNnoUECE3etwB15TjXU8sZiwrL7BNk+B rd736IFrMEFDHe5GQGq4Q4ic+Ghy98WWBuh5J1AiezbMNA7luU/HbvilcovYgfco7e8Y C3GA9pEkDNyI6CGHvukgEpEYsooj5a5JeVtoKC+4LuSvdhvQWt7Cr76PQh2cSAjDuarE 6vsA== ARC-Message-Signature: i=1; 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; bh=px2AAIT0BQKCkz/U6mooNr1cDrp2wnRbi+Nhu8MT84E=; fh=Pgalyh3MF5eBPi/IPdZYQ5Sy1NRsybLYs3FsYGRssI0=; b=bRri/ZiCc0puygV0dIK/1mf/dGxZe+fNnfTHSAI0Kt7GD3wr+u5jgXmHIeGjTu9/qX oWkkEsMv9cz+UUo8o0SH6grfF38XQV3iDyf7wbWys3I2fFGrbwtwGNrJ9X8t+rML+Uv5 sVH1haSjJ0Iffj6j5iccTzB4lBCBqFHV3eTGicS0VjtxCGr08SVnlQNUTf82jD5vHKIa fgEmAZvXnzPNL1n1Cy5ecv4Xl+AH+mreUr93I1sVAMNBxuoLEP/+uioMULTev0oKIlGH 7WnToKc6c3Q1you0iB3Zya8+om+iA8w4ra0ITUoiZo1yxi6GHq/GuZ8UEnxaja2mbByQ wn4A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-26336-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26336-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id a16-20020a05620a125000b00780f8f53c87si8307623qkl.695.2024.01.15.09.58.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 09:58:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-26336-ouuuleilei=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; spf=pass (google.com: domain of linux-kernel+bounces-26336-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26336-ouuuleilei=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 793B21C21F33 for ; Mon, 15 Jan 2024 17:58:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A903518C08; Mon, 15 Jan 2024 17:57:45 +0000 (UTC) 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 BFB74182AA; Mon, 15 Jan 2024 17:57:40 +0000 (UTC) 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 5.4.0) id 286ea037ab555c88; Mon, 15 Jan 2024 18:57:32 +0100 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 205486692F2; Mon, 15 Jan 2024 18:57:32 +0100 (CET) From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Daniel Lezcano , Lukasz Luba , Srinivas Pandruvada , Zhang Rui Subject: [PATCH v1 1/2] thermal: gov_fair_share: Fix dependency on trip points ordering Date: Mon, 15 Jan 2024 18:55:13 +0100 Message-ID: <4918593.31r3eYUQgx@kreacher> In-Reply-To: <12389773.O9o76ZdvQC@kreacher> References: <12389773.O9o76ZdvQC@kreacher> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedrvdejuddguddtjecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeeipdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrghdprhgtphhtthhopehluhhkrghsiidrlhhusggrsegrrhhmrdgtohhmpdhrtghpthhtohepshhr ihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=6 Fuz1=6 Fuz2=6 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788180175677074237 X-GMAIL-MSGID: 1788180175677074237 From: Rafael J. Wysocki The computation in the fair share governor's get_trip_level() function currently works under the assumption that the temperature ordering of trips[] in a thermal zone is ascending, which need not be the case. However, get_trip_level() can be made work regardless of whether or not the trips table is ordered by temperature in any way, so change it accordingly. Signed-off-by: Rafael J. Wysocki --- drivers/thermal/gov_fair_share.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) Index: linux-pm/drivers/thermal/gov_fair_share.c =================================================================== --- linux-pm.orig/drivers/thermal/gov_fair_share.c +++ linux-pm/drivers/thermal/gov_fair_share.c @@ -18,22 +18,24 @@ static int get_trip_level(struct thermal_zone_device *tz) { const struct thermal_trip *trip, *level_trip = NULL; - int trip_level; + int trip_level = -1; for_each_trip(tz, trip) { if (trip->temperature >= tz->temperature) - break; + continue; - level_trip = trip; + trip_level++; + + if (!level_trip || trip->temperature > level_trip->temperature) + level_trip = trip; } /* Bail out if the temperature is not greater than any trips. */ - if (!level_trip) + if (trip_level < 0) return 0; - trip_level = thermal_zone_trip_id(tz, level_trip); - - trace_thermal_zone_trip(tz, trip_level, level_trip->type); + trace_thermal_zone_trip(tz, thermal_zone_trip_id(tz, level_trip), + level_trip->type); return trip_level; } From patchwork Mon Jan 15 17:57:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 188273 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2614:b0:101:6a76:bbe3 with SMTP id mm20csp1854879dyc; Mon, 15 Jan 2024 09:58:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IHaLBFhGeRTpEny3LZ5R84defDgjq87g4JNvx9DkJwvKKY9gjhOyux/bYDYksWXmTRGmDHl X-Received: by 2002:a05:6214:4017:b0:681:578c:ef6e with SMTP id kd23-20020a056214401700b00681578cef6emr4136374qvb.99.1705341492347; Mon, 15 Jan 2024 09:58:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705341492; cv=none; d=google.com; s=arc-20160816; b=Ntph6hmrV+RkQiwIOXQyTKfIRmFlQ7HmH2Y/lkN3YFfweydMO05YjXCnYG6k/9ksyJ fYA9WeslWgx+KZeF3fykhrWH9tHBXQgIC1FsGL5VfbWaaHEVWCrgl9DYo2vYuyDmdZ9L x7LHiL8PcCL8Gb+IFJDbf292t72Qj7suQ32lkdANzcR7TVi4F1EzmB9ZvsZoHtiN1oCS IQql4dkcs/7ctT+m1Pr70IKwWW8oZTGQ2oqx+G5Bi0X9Hzn/9aKH39fpDAzQ0ZiX2j1f Gv95nPGvZn/BLKUvvgBoPXjVolq/RfzIIjCpGvsisLRGUpPVllOelgVbGX00oPr56m2e webw== ARC-Message-Signature: i=1; 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; bh=t/EWDzjTWupGkT9a9pMxzGY+5w3N/zX38qBDIDTwMsk=; fh=Pgalyh3MF5eBPi/IPdZYQ5Sy1NRsybLYs3FsYGRssI0=; b=qt+oTta1g4SUPOi4tshayxGU8Iho8ZIAaXBpMga9TkQ9zXpWqWKkIWDGF2R8EU+1+z aS0ZzfOFJU9BYJvHJsUlFytBI7yDHGg4FNN9MdSiyEL+axe7pfkJ4dDkCSi7Kg7GPCOv I20sGTyfyoa3edukRBZ+qPdnMIjmxhQ870ytZ0hkVZk3M7L94YOmx1bRiRtCtNW+taed tdsGglRg8EmK/lwIwQO43j06D0jWi28swpcLff1Mw7/+RZsxY3HaAiZ/ewqzJwBCMcNQ Da+NHddVKR+L9NxrfVq4rGPOuuvpa/w1s+pvfFNPORI1FTCg9nU0MRP4AS4J6SWX/t9d cq6g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-26334-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26334-ouuuleilei=gmail.com@vger.kernel.org" Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id c11-20020a0ca9cb000000b006804af22665si8267270qvb.232.2024.01.15.09.58.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jan 2024 09:58:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-26334-ouuuleilei=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; spf=pass (google.com: domain of linux-kernel+bounces-26334-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-26334-ouuuleilei=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 257511C21F23 for ; Mon, 15 Jan 2024 17:58:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6575018646; Mon, 15 Jan 2024 17:57:44 +0000 (UTC) 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 BD574182A7; Mon, 15 Jan 2024 17:57:40 +0000 (UTC) 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 5.4.0) id 872efcd1a58f9332; Mon, 15 Jan 2024 18:57:31 +0100 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 54BB16692F2; Mon, 15 Jan 2024 18:57:31 +0100 (CET) From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Daniel Lezcano , Lukasz Luba , Srinivas Pandruvada , Zhang Rui Subject: [PATCH v1 2/2] thermal: gov_bang_bang: Fix possible cooling device state ping-pong Date: Mon, 15 Jan 2024 18:57:06 +0100 Message-ID: <2339862.ElGaqSPkdT@kreacher> In-Reply-To: <12389773.O9o76ZdvQC@kreacher> References: <12389773.O9o76ZdvQC@kreacher> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvkedrvdejuddguddtjecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeeipdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrghdprhgtphhtthhopehluhhkrghsiidrlhhusggrsegrrhhmrdgtohhmpdhrtghpthhtohepshhr ihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthgvlhdrtghomhdprhgtphhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=6 Fuz1=6 Fuz2=6 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788180160987692516 X-GMAIL-MSGID: 1788180160987692516 From: Rafael J. Wysocki The current behavior of thermal_zone_trip_update() in the bang-bang thermal governor may be problematic for trip points with 0 hysteresis, because when the zone temperature reaches the trip temperature and stays there, it will then cause the cooling device go "on" and "off" alternately, which is not desirable. Address this by requiring the zone temperature to actually fall below trip->temperature - trip->hysteresis for the cooling device to go off. Signed-off-by: Rafael J. Wysocki --- drivers/thermal/gov_bang_bang.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) Index: linux-pm/drivers/thermal/gov_bang_bang.c =================================================================== --- linux-pm.orig/drivers/thermal/gov_bang_bang.c +++ linux-pm/drivers/thermal/gov_bang_bang.c @@ -49,7 +49,7 @@ static int thermal_zone_trip_update(stru if (instance->target == 0 && tz->temperature >= trip->temperature) instance->target = 1; else if (instance->target == 1 && - tz->temperature <= trip->temperature - trip->hysteresis) + tz->temperature < trip->temperature - trip->hysteresis) instance->target = 0; dev_dbg(&instance->cdev->device, "target=%d\n",