From patchwork Fri Jul 28 10:00:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 127510 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:918b:0:b0:3e4:2afc:c1 with SMTP id s11csp333320vqg; Fri, 28 Jul 2023 03:25:23 -0700 (PDT) X-Google-Smtp-Source: APBJJlEESdlGjQmRUapE7IOc9GnQHB8LTkkk9Oo/mMl/2qp9koL1kKEfEgoTasQCvzuGxHrpb9Oq X-Received: by 2002:a17:90a:a60b:b0:268:7be6:29a5 with SMTP id c11-20020a17090aa60b00b002687be629a5mr1078855pjq.9.1690539923112; Fri, 28 Jul 2023 03:25:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690539923; cv=none; d=google.com; s=arc-20160816; b=LunLeDkQ6Ffezg6cNBL/y2EDJqVQAPZKdS5P0uleEIJcsDyFIRx8AmEitS1mxNYB+T kbm3cUapltzCQPmjS8fO+ExLXlXK5keVSOJTGvZ0y10ohflQ5HOaC3QcczkmDeJFLzJz 1WKOKQI5IStVvDe56u6TgAc6bZrPJH7n3mGSWd8J91iDWOA/dF4xDJuxpWcI8yfbRzy2 C/36ugpuHzOjA5vIW6ZdBC/d0u1ckdG5nxSO7hmAKDWTNOX90u4FmRx4SWGOze4Qdc31 fRt7vYTRYwU5eiQXyLk8BlOZp2mP2EXXgUxBxxgdjX8k4/XO8cE4SXZo2k5BfWmE1+sy nA6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=TW3trZaYh1/5PAH+FUrKgla5fJVPScKo/LRPhACT22s=; fh=vcb1WTwJPUMTZX6OxkyO+5cKBEoTRHpgQZ5gmsle4eE=; b=p5bFlzCXrzB5g12Klmmmt6Yx8MbecyIhrqcZrx1H55vXgzVaQ4A/n6REvcsgZkA1nE gulTXe0Z0Ot69RUbzTXlMlp53KSgXTZKy21iHD5fNhpRm7b+Niy26GWRk1x92utiRqcZ unoglMCWgzxBw/bgFNXr85zMb6zUn7otVpsVPQcLQbLr58xOcaECPrXc+O7DVXPauOP2 K4RqtOUVIK4I2ylRUjiGY7mV8SccUJT8srUwK0g+pCK+YLR2+3xa61GjCZvflbReuEN5 yvnHuZTAxAbE2rIL+P5ZiZcrIduM7ZjmPg1dP9jcjMil0Gnz2BRSLIbidbRhStyj1q6g cHvQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n6-20020a17090a2bc600b0025eee012ca4si4463374pje.30.2023.07.28.03.25.10; Fri, 28 Jul 2023 03:25:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231266AbjG1KCz (ORCPT + 99 others); Fri, 28 Jul 2023 06:02:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235349AbjG1KC3 (ORCPT ); Fri, 28 Jul 2023 06:02:29 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2AE0149CA; Fri, 28 Jul 2023 03:01:59 -0700 (PDT) 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.2.0) id da2d6a680178221d; Fri, 28 Jul 2023 12:01:57 +0200 Authentication-Results: v370.home.net.pl; spf=softfail (domain owner discourages use of this host) smtp.mailfrom=rjwysocki.net (client-ip=195.136.19.94; helo=[195.136.19.94]; envelope-from=rjw@rjwysocki.net; receiver=) 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 v370.home.net.pl (Postfix) with ESMTPSA id 0B801661E3D; Fri, 28 Jul 2023 12:01:57 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Peter Zijlstra , Anna-Maria Behnsen , Frederic Weisbecker , Kajetan Puchalski Subject: [PATCH v2 2/3] cpuidle: teo: Avoid stopping the tick unnecessarily when bailing out Date: Fri, 28 Jul 2023 12:00:46 +0200 Message-ID: <3254124.aeNJFYEL58@kreacher> In-Reply-To: <5707588.DvuYhMxLoT@kreacher> References: <5707588.DvuYhMxLoT@kreacher> 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: gggruggvucftvghtrhhoucdtuddrgedviedrieeigddvtdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeeipdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepphgvthgvrhiisehinhhfrhgruggvrggurdhorhhgpdhrtghpthhtoheprghnnhgrqdhmrghrihgrsehlihhnuhhtrhhonhhigidruggvpdhrtghpthhtohepfhhrvggu vghrihgtsehkvghrnhgvlhdrohhrghdprhgtphhtthhopehkrghjvghtrghnrdhpuhgthhgrlhhskhhisegrrhhmrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=6 Fuz1=6 Fuz2=6 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772659590750802721 X-GMAIL-MSGID: 1772659590750802721 From: Rafael J. Wysocki When teo_select() is going to return early in some special cases, make it avoid stopping the tick if the idle state to be returned is shallow. Signed-off-by: Rafael J. Wysocki --- drivers/cpuidle/governors/teo.c | 50 +++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 18 deletions(-) Index: linux-pm/drivers/cpuidle/governors/teo.c =================================================================== --- linux-pm.orig/drivers/cpuidle/governors/teo.c +++ linux-pm/drivers/cpuidle/governors/teo.c @@ -462,9 +462,9 @@ static int teo_select(struct cpuidle_dri /* Avoid unnecessary overhead. */ if (idx < 0) { idx = 0; /* No states enabled, must use 0. */ - goto end; + goto bail_out; } else if (idx == idx0) { - goto end; + goto bail_out; } /* @@ -547,8 +547,10 @@ static int teo_select(struct cpuidle_dri * 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) + if (idx > constraint_idx) { idx = constraint_idx; + goto bail_out; + } /* * If the CPU is being utilized over the threshold, choose a shallower @@ -569,23 +571,35 @@ static int teo_select(struct cpuidle_dri end: /* - * Don't stop the tick if the selected state is a polling one or if the - * expected idle duration is shorter than the tick period length. + * Allow the tick to be stopped unless the selected state is a polling + * one or the expected idle duration is shorter than the tick period + * length. */ - if (((drv->states[idx].flags & CPUIDLE_FLAG_POLLING) || - duration_ns < TICK_NSEC) && !tick_nohz_tick_stopped()) { - *stop_tick = false; + if ((!(drv->states[idx].flags & CPUIDLE_FLAG_POLLING) && + duration_ns >= TICK_NSEC) || tick_nohz_tick_stopped()) + return idx; - /* - * The tick is not going to be stopped, so if the target - * residency of the state to be returned is not within the time - * till the closest timer including the tick, try to correct - * that. - */ - if (idx > idx0 && - drv->states[idx].target_residency_ns > delta_tick) - idx = teo_find_shallower_state(drv, dev, idx, delta_tick, false); - } +retain_tick: + *stop_tick = false; + + /* + * The tick is not going to be stopped, so if the target residency of + * the state to be returned is not within the time till the closest + * timer including the tick, try to correct that. + */ + if (idx > idx0 && + drv->states[idx].target_residency_ns > delta_tick) + idx = teo_find_shallower_state(drv, dev, idx, delta_tick, false); + + return idx; + +bail_out: + /* + * Do not allow the tick to be stopped if the selected state is shallow + * enough. + */ + if (drv->states[idx].target_residency_ns < TICK_NSEC) + goto retain_tick; return idx; }