From patchwork Fri Jan 10 12:53:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 13934540 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 3FB8C20DD53; Fri, 10 Jan 2025 12:57:59 +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=1736513882; cv=none; b=ZU4s889mjLqPjq974OAIECzgZiP4YE5jNIMJejT3ciFYzfZEfYIichWSSU0XGLgVQsn5kRJV0YeUKMdmE/JXFqZAf+2Rlex22bVa0W0nPx1fR3yeiPOVZ7hGPtfeHAuogrhMDENVccA+E/TKVy9tDV+nFnvmxFzG8W2Q9r/drPw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736513882; c=relaxed/simple; bh=LVbRvsshn0Bs3rOsCebMtDGzdAIaFrarmaICvHLvZXY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YWkcuHCGORtxCDpCPFKRe8dWb/NsOjxrXR6vWv2x9qPa9aPUdPFm43XAgORTxu01aHjoK5k1Gzir9IxIqaBWNoyhG9AccyQmPfzdVH4zJJp64vvw8k9x/J3fZD+qgtAuXimn+xgUnx8+tgjyaji/jlynM4rTspDqCNHEqWmfj6I= 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=pass (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=qeuxRRoi; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="qeuxRRoi" 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.2.1) id c174eccfaff98ff8; Fri, 10 Jan 2025 13:57:58 +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 C9E218E05BD; Fri, 10 Jan 2025 13:57:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1736513878; bh=LVbRvsshn0Bs3rOsCebMtDGzdAIaFrarmaICvHLvZXY=; h=From:Subject:Date; b=qeuxRRoimgov9x5B42OBeP6un08ahbecTIPd8XlU8VVz7M/mHOKh7lVLOGLSddkJz X7J1TGDDDSu3dAwZmWoCQeUDauowx1ZtuLWxuKDuX3IIPPSgWeN93hn9BgMfPfBtl0 wPC/yzVY75BSFVCqwhqMjnKDYdD9hCkkdb375PWmhsnxjoPSlHzs9eSZU/HJLMizD+ fqG2mtEGK2H+obOBVC2masyq0R/2xekZPCbmg3Yov5RFNOzyWBCn2ARn2/nsZQlwYy 1sDehnISXsjbYygslTEjxQC40eVYG/E2GxRpSBUyrL3PsGMOA4fo/BT7zIdf+o/kdv empTo5Wq6bvqw== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Daniel Lezcano , Christian Loehle , Artem Bityutskiy Subject: [PATCH v1 1/4] cpuidle: teo: Add polling flag check to early return path Date: Fri, 10 Jan 2025 13:53:57 +0100 Message-ID: <13679187.uLZWGnKmhe@rjwysocki.net> In-Reply-To: <4953183.GXAFRqVoOG@rjwysocki.net> References: <4953183.GXAFRqVoOG@rjwysocki.net> Precedence: bulk X-Mailing-List: linux-pm@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: gggruggvucftvghtrhhoucdtuddrgeefuddrudegkedggeeiucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomheprhhjfiesrhhjfiihshhotghkihdrnhgvthdpnhgspghrtghpthhtohephedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheptghhrhhishhtihgrnhdrlhhovghhlhgvsegrrhhmrdgtohhmpdhrtghpthhtoheprghrthgvmhdrsghithihuhhtshhkihihsehlihh X-DCC--Metrics: v370.home.net.pl 1024; Body=5 Fuz1=5 Fuz2=5 From: Rafael J. Wysocki After commit 6da8f9ba5a87 ("cpuidle: teo: Skip tick_nohz_get_sleep_length() call in some cases") the teo governor behaves a bit differently on systems where idle state 0 is a "polling" state (that is, it is not really an idle state, but a loop continuously executed by the CPU). Namely, on such systems it skips the tick_nohz_get_sleep_length() call if the target residency of the current candidate idle state is small enough. However, if state 0 itself was to be returned, it would be returned right away without calling tick_nohz_get_sleep_length() even on systems where it was not a "polling" state until commit 4b20b07ce72f ("cpuidle: teo: Don't count non-existent intercepts") that attempted to fix this problem. Unfortunately, commit 4b20b07ce72f has made the governor always call tick_nohz_get_sleep_length() when about to return state 0 early, even if that state is a "polling" one, which is inconsistent and defeats the purpose of commit 6da8f9ba5a87 in that case. Address this by adding a CPUIDLE_FLAG_POLLING check to the path where state 0 is returned early to prevent tick_nohz_get_sleep_length() from being called if it is a "polling" state. Fixes: 4b20b07ce72f ("cpuidle: teo: Don't count non-existent intercepts") Signed-off-by: Rafael J. Wysocki --- drivers/cpuidle/governors/teo.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/drivers/cpuidle/governors/teo.c +++ b/drivers/cpuidle/governors/teo.c @@ -422,7 +422,8 @@ first_suitable_idx = i; } } - if (!idx && prev_intercept_idx) { + if (!idx && prev_intercept_idx && + !(drv->states[0].flags & CPUIDLE_FLAG_POLLING)) { /* * We have to query the sleep length here otherwise we don't * know after wakeup if our guess was correct. From patchwork Fri Jan 10 12:54:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 13934539 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 72C6420B80B; Fri, 10 Jan 2025 12:57:59 +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=1736513881; cv=none; b=SAmXc/1XSYbHTA9wUg6jZUKWvd/UsVWEI8RmUq+EZhGzJGneKjmsiGje8slIKrCUTJlHL3iA7H+nCb0+IJ5W1Jaex9F7Z06tv1Obny/uQ2vUa+w8COyPU9QNCVIJsIQ3M733pnsvIYMBrHcuB56eHrMbOW3PzqmJe5saJmTTDU8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736513881; c=relaxed/simple; bh=aMsxBXTyqbPuNisGPiGLY4/v1IDTWx6PBDk+6e12byE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jt++SN606moTVmeR/GnruDNX+YkGiNSBApwwTLjW97wQumcHSvo4iXBj+AzY0gSLlVOK3jOar1D1/5qYdXeQIjqfDy1HXzXTVRb2254bKbRFI6dOxLFXU/9ddFNx9ptHGSFR9HbFKsxdoY+g0cmEvMVo3vpt5GxvNcCBKY67oCI= 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=pass (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=EdT9RZjs; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="EdT9RZjs" 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.2.1) id d9eaa60ba3037fd8; Fri, 10 Jan 2025 13:57:57 +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 DD46A8E05BD; Fri, 10 Jan 2025 13:57:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1736513877; bh=aMsxBXTyqbPuNisGPiGLY4/v1IDTWx6PBDk+6e12byE=; h=From:Subject:Date; b=EdT9RZjsQwTLft2QkAi8ktta+ynSzWjHBn026Ul7nUfHr3GmKcu5+Zxm2bue4gtFX SQuJZce0+mEYMz4Madt6Mdl5kqJZLEzgGXbh8kz7FnWppMn/4GOdndd2g+i926GZm9 HMqJT2Z8GruSAljHIJ/WrDhpHDbAoiqp3N1tbcxrIuKh2LK310Iqp+ER9xGpYSvBKd L7dTFss52w2Qry3RxOcGo4w6G8H9vpK0ZtQhrWc/2JTFkxNi7EvbD8oX+EDA0qmGW/ F6/Fdl6+GLzl7vy7FXMbrWRIvMKemKhwf50R7vVvLns7Xd9JTQEYnI7wVBN85uorbs eYt8axjfH2bPw== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Daniel Lezcano , Christian Loehle , Artem Bityutskiy Subject: [PATCH v1 2/4] cpuidle: teo: Rearrange idle state lookup code Date: Fri, 10 Jan 2025 13:54:39 +0100 Message-ID: <3332506.aeNJFYEL58@rjwysocki.net> In-Reply-To: <4953183.GXAFRqVoOG@rjwysocki.net> References: <4953183.GXAFRqVoOG@rjwysocki.net> Precedence: bulk X-Mailing-List: linux-pm@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: gggruggvucftvghtrhhoucdtuddrgeefuddrudegkedggeeiucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomheprhhjfiesrhhjfiihshhotghkihdrnhgvthdpnhgspghrtghpthhtohephedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheptghhrhhishhtihgrnhdrlhhovghhlhgvsegrrhhmrdgtohhmpdhrtghpthhtoheprghrthgvmhdrsghithihuhhtshhkihihsehlihh X-DCC--Metrics: v370.home.net.pl 1024; Body=5 Fuz1=5 Fuz2=5 From: Rafael J. Wysocki Rearrange code in the idle state lookup loop in teo_select() to make it somewhat easier to follow and update comments around it. No intentional functional impact. Signed-off-by: Rafael J. Wysocki --- drivers/cpuidle/governors/teo.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) --- a/drivers/cpuidle/governors/teo.c +++ b/drivers/cpuidle/governors/teo.c @@ -367,7 +367,7 @@ * If the sum of the intercepts metric for all of the idle states * shallower than the current candidate one (idx) is greater than the * sum of the intercepts and hits metrics for the candidate state and - * all of the deeper states a shallower idle state is likely to be a + * all of the deeper states, a shallower idle state is likely to be a * better choice. */ prev_intercept_idx = idx; @@ -396,30 +396,36 @@ * first enabled state that is deep enough. */ if (teo_state_ok(i, drv) && - !dev->states_usage[i].disable) + !dev->states_usage[i].disable) { idx = i; - else - idx = first_suitable_idx; - + break; + } + idx = first_suitable_idx; break; } if (dev->states_usage[i].disable) continue; - if (!teo_state_ok(i, drv)) { + if (teo_state_ok(i, drv)) { /* - * The current state is too shallow, but if an - * alternative candidate state has been found, - * it may still turn out to be a better choice. + * The current state is deep enough, but still + * there may be a better one. */ - if (first_suitable_idx != idx) - continue; - - break; + first_suitable_idx = i; + continue; } - first_suitable_idx = i; + /* + * The current state is too shallow, so if no suitable + * states other than the initial candidate have been + * found, give up (the remaining states to check are + * shallower still), but otherwise the first suitable + * state other than the initial candidate may turn out + * to be preferable. + */ + if (first_suitable_idx == idx) + break; } } if (!idx && prev_intercept_idx && From patchwork Fri Jan 10 12:55:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 13934538 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 6B2EE20A5E9; Fri, 10 Jan 2025 12:57:57 +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=1736513880; cv=none; b=qnh7CUSFws/Ju3CUyf7GXddK+0OpLl/D7ZeV6X30LnjzHseRhQ+XZ3ARkwmRabmd4/q/lyq0SuhIcfZAXVYLoG2SwcELVsz0YY8M3q/AN3tb6zWIyCB4XGhDDnKJKtFRUkISuqSclwRFeFzpk7VeofdO0AuvIjUOA9m9sHSvJbo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736513880; c=relaxed/simple; bh=JwT38iZan3te1sUrNeDmcKgV3zvQtH2PT7sDx6rv1bM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=C5iQMkcEY3VxdNF7cIVcI9kZS8mrznA36GIcfjSeaJpfemxh89rbR24pHaZHjNxWM7xKcLmqF+rOb9oTm1UL/ZSgBPBB+98/2Tnu5Nm1IxUmKWyGnv1lN1cIaKwgnf26C2H/GtypkK0A3XL3Cua1ejVsXnf/LMrNXTTAoeBkOE4= 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=pass (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=Cv2PqwJ/; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="Cv2PqwJ/" 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.2.1) id faff95d8c2ca581f; Fri, 10 Jan 2025 13:57:56 +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 D69BD8E05BD; Fri, 10 Jan 2025 13:57:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1736513876; bh=JwT38iZan3te1sUrNeDmcKgV3zvQtH2PT7sDx6rv1bM=; h=From:Subject:Date; b=Cv2PqwJ/sANhOJtTpO9Vk9qRQJPxJAwVeXr2Q5GMsXqGCS+Vq4ps5kRE7ScjP+mrB pkiwdNNHIFIMmOfwaSqBvI0DjBFuS52KaH8yLcT6/bfMdtkuyDiMCvxGamhYmzVhik kgP0BVq+rj04arc9I2THVdC9BrnN4AleX63FAFn+owtn6hIE7R8Qi8jcHqinW7lfJB 7gVQOzwDH3Z++Q5EpvwnGanXG1x6Bgk9z2AASDvd17Kbs9LrLYE6Ipj01biAfeBNBE sD0ipYmEypRyW7yJeiTQ0nbCThnpPsKDKWLwyKkcwmtlIj3JMrK1lvDrNjiihLMIZt W02UV//X6tsow== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Daniel Lezcano , Christian Loehle , Artem Bityutskiy Subject: [PATCH v1 3/4] cpuidle: teo: Reorder candidate state index checks Date: Fri, 10 Jan 2025 13:55:29 +0100 Message-ID: <8476650.T7Z3S40VBb@rjwysocki.net> In-Reply-To: <4953183.GXAFRqVoOG@rjwysocki.net> References: <4953183.GXAFRqVoOG@rjwysocki.net> Precedence: bulk X-Mailing-List: linux-pm@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: gggruggvucftvghtrhhoucdtuddrgeefuddrudegkedggeeiucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomheprhhjfiesrhhjfiihshhotghkihdrnhgvthdpnhgspghrtghpthhtohephedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheptghhrhhishhtihgrnhdrlhhovghhlhgvsegrrhhmrdgtohhmpdhrtghpthhtoheprghrthgvmhdrsghithihuhhtshhkihihsehlihh X-DCC--Metrics: v370.home.net.pl 1024; Body=5 Fuz1=5 Fuz2=5 From: Rafael J. Wysocki Since constraint_idx may be 0, the candidate state index may change to 0 after assinging constraint_idx to it, so first check if it is greater than constraint_idx (and update it if so) and then check it against 0. Signed-off-by: Rafael J. Wysocki --- drivers/cpuidle/governors/teo.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) --- a/drivers/cpuidle/governors/teo.c +++ b/drivers/cpuidle/governors/teo.c @@ -428,6 +428,14 @@ break; } } + + /* + * If there is a latency constraint, it may be necessary to select an + * idle state shallower than the current candidate one. + */ + if (idx > constraint_idx) + idx = constraint_idx; + if (!idx && prev_intercept_idx && !(drv->states[0].flags & CPUIDLE_FLAG_POLLING)) { /* @@ -440,13 +448,6 @@ } /* - * If there is a latency constraint, it may be necessary to select an - * idle state shallower than the current candidate one. - */ - if (idx > constraint_idx) - idx = constraint_idx; - - /* * Skip the timers check if state 0 is the current candidate one, * because an immediate non-timer wakeup is expected in that case. */ From patchwork Fri Jan 10 12:56:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 13934537 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 3237D20B7FA; Fri, 10 Jan 2025 12:57:56 +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=1736513879; cv=none; b=Zesk/4HiYFcaGmBblguBmGjMBW8iYPPl0PelzZyM7NNgx8IB4TvWDRRjo/v67cnTE3y/Lj4SO1Xx5cC8tQ9I0AuMn6lR5SfbYZmN2x+7UKllrN60EKOroZl/QZwrrsqezqKA8Ie3u6t4ZMnv5wVIJ+IvY7fMgmWlWYKWht2C/Oc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736513879; c=relaxed/simple; bh=CcDF7WwwV59H8UViLxsSQlOdaroZnGiK3JoHgMgnESI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=jyftYSa9LTZ+VtZhfTZ2bXHFm4TzVjXUrzK4lgRByidVqL9yEc/fLYvLYy+6ZMpCkdw9+x9RNCRTncrNaYnJRhKSiHR2v3v5nf85WS/MGcMlcAJAoe5gS1r7Xg822BeFBlVCzFkGYuZCiIZIN7Xwq8Nu6auG2Fj/V8bq8gMNUEI= 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=pass (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=ONkfwFYD; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="ONkfwFYD" 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.2.1) id 562bfbd173d43376; Fri, 10 Jan 2025 13:57:55 +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 8E78B8E05BD; Fri, 10 Jan 2025 13:57:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1736513875; bh=CcDF7WwwV59H8UViLxsSQlOdaroZnGiK3JoHgMgnESI=; h=From:Subject:Date; b=ONkfwFYDjL/2DBLoKbnOC/zcWv3naYS8hgsg3K36xYYI5s/e5A9YWeScYSeTwxdp1 Y/6tjdInJjv5n7elqTdGyxhTZjFVC/Z9AtTjYLU4xZ8wU+/g9gKfjX5G7pKlg7a7af AcirrnF0JbGBnPcaCigYvEmTu5dlL7H7Gzy00kvei44mbmU7HmuZwVRaEaYtdqHEqu u2o84VRGwCu4ex3cAYRpPpbOySTUGcTnM42nJ2vG+Wf8EN/IYslJJUwRVBNtAyA+RP Ztb6mADRrOLydzGTzB3osWtHWArLixyJBoEJ8hxvm2nGW321z9WKG0GB5/Pcw8nYgH +wm5v6g/fkkjw== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Daniel Lezcano , Christian Loehle , Artem Bityutskiy Subject: [PATCH v1 4/4] cpuidle: teo: Combine candidate state index checks against 0 Date: Fri, 10 Jan 2025 13:56:07 +0100 Message-ID: <2296767.iZASKD2KPV@rjwysocki.net> In-Reply-To: <4953183.GXAFRqVoOG@rjwysocki.net> References: <4953183.GXAFRqVoOG@rjwysocki.net> Precedence: bulk X-Mailing-List: linux-pm@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: gggruggvucftvghtrhhoucdtuddrgeefuddrudegkedggeeiucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomheprhhjfiesrhhjfiihshhotghkihdrnhgvthdpnhgspghrtghpthhtohephedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheptghhrhhishhtihgrnhdrlhhovghhlhgvsegrrhhmrdgtohhmpdhrtghpthhtoheprghrthgvmhdrsghithihuhhtshhkihihsehlihh X-DCC--Metrics: v370.home.net.pl 1024; Body=5 Fuz1=5 Fuz2=5 From: Rafael J. Wysocki There are two candidate state index checks against 0 in teo_select() that need not be separate, so combine them and update comments around them. No intentional functional impact. Signed-off-by: Rafael J. Wysocki --- drivers/cpuidle/governors/teo.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) --- a/drivers/cpuidle/governors/teo.c +++ b/drivers/cpuidle/governors/teo.c @@ -436,25 +436,25 @@ if (idx > constraint_idx) idx = constraint_idx; - if (!idx && prev_intercept_idx && - !(drv->states[0].flags & CPUIDLE_FLAG_POLLING)) { + + if (!idx) { /* - * We have to query the sleep length here otherwise we don't - * know after wakeup if our guess was correct. + * Skip the timers check if state 0 is the current candidate + * one because an immediate non-timer wakeup is expected then. */ - duration_ns = tick_nohz_get_sleep_length(&delta_tick); - cpu_data->sleep_length_ns = duration_ns; + if (prev_intercept_idx && + !(drv->states[0].flags & CPUIDLE_FLAG_POLLING)) { + /* + * Query the sleep length to be able to count the wakeup + * as a hit if it is caused by a timer. + */ + duration_ns = tick_nohz_get_sleep_length(&delta_tick); + cpu_data->sleep_length_ns = duration_ns; + } goto out_tick; } /* - * Skip the timers check if state 0 is the current candidate one, - * because an immediate non-timer wakeup is expected in that case. - */ - if (!idx) - goto out_tick; - - /* * If state 0 is a polling one, check if the target residency of * the current candidate state is low enough and skip the timers * check in that case too.