Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3796521pxf; Mon, 29 Mar 2021 11:39:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJymzWOwlp4gghw7MmnQS6EuJ5UyCAFEFeNlxL7diLa/bmu4qS6NJ3tSNwCntENy66m34/Dj X-Received: by 2002:a17:906:d8c6:: with SMTP id re6mr28867199ejb.311.1617043151681; Mon, 29 Mar 2021 11:39:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617043151; cv=none; d=google.com; s=arc-20160816; b=ipLfdr9Xk3PAjtylLw9JmAba7VflNxyAI85qNylGSEwJvC31su1oCPdwGxrB/SXge+ N1hU6s1zA9Ryk0BsYrpAhoGT+QhCDL8zddjjtNKQG3IqUjc5HY+zQoWJCpAW0mfM2E6z w1RUIlAChda7M+q/DvdTvwcavc6FmvslyaJsxZHiOUFrCR6jPt9eFEHpy6HYjUS0EopQ 4p23zejqkQqn0ILHyHosjoFTt7DazzOYGugQ6Kq2RyC4oyQHX/ziigu/6hzF6nQAS53B ILfb2ZUMzaYQnv8ucSAHdFumB4mLQ4FSBXo05lKN32HwiK9ENPbklAxP7y5rRBAMtxcr Ysog== 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=OetCiSb2S2AfUVhmyDSsDP3wVhaSKCDEN0iH+qWuuzU=; b=XjNtYfNjpKwdLhETTKD2KZjf58xjUO1xbq1jUZdrVScMUh/j6GfAMZ82BMD/qO1SOg jxbehvzzZw3XU/RuP69ac/QH7jtshXFKt9fGjQPo45bgnjSrJQeijGvGFVqU+XZuX2J2 PIjovMZ+b27oULZbLcpuFGNpEhu6iSCjDxJfzX/+KVb9pnnwqtQAslZlgKku5+X0O4uQ 3iUf3V8i5diDQaP+eEd8+J0Q4pm636S12CoRh68wJC78YsGjJJ0O1brRQPTMHAw5kXJ0 jEObeBVD3yhONnnae3YKYljXaKX9vGhIBHOlsYdvn+5PLxb61cz6u+o2xChFePJ4pY2Q NXJQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id s19si13240335ejd.449.2021.03.29.11.38.49; Mon, 29 Mar 2021 11:39:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231560AbhC2Sho (ORCPT + 99 others); Mon, 29 Mar 2021 14:37:44 -0400 Received: from cloudserver094114.home.pl ([79.96.170.134]:48772 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231358AbhC2Shh (ORCPT ); Mon, 29 Mar 2021 14:37:37 -0400 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 2.0.3) id 43deede600701cc8; Mon, 29 Mar 2021 20:37:35 +0200 Received: from kreacher.localnet (89-64-81-131.dynamic.chello.pl [89.64.81.131]) (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 5454F669165; Mon, 29 Mar 2021 20:37:34 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , Frederic Weisbecker , Peter Zijlstra , Thomas Gleixner , "Zhou Ti (x2019cwm)" Subject: [PATCH v1 3/5] cpuidle: teo: Adjust handling of very short idle times Date: Mon, 29 Mar 2021 20:19:03 +0200 Message-ID: <7219614.EvYhyI6sBW@kreacher> In-Reply-To: <2764850.e9J7NaK4W3@kreacher> References: <2764850.e9J7NaK4W3@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgeduledrudehkedguddvkecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdejlefghfeiudektdelkeekvddugfeghffggeejgfeukeejleevgffgvdeluddtnecukfhppeekledrieegrdekuddrudefudenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeekledrieegrdekuddrudefuddphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehfrhgvuggvrhhitgeskhgvrhhnvghlrdhorhhgpdhrtghpthhtohepphgvthgvrhiisehinhhfrhgruggvrggurdhorhhgpdhrtghpthhtohepthhglhigsehlihhnuhhtrhhonhhigidruggvpdhrtghp thhtohepgidvtddulegtfihmsehsthhfgidrtggr X-DCC--Metrics: v370.home.net.pl 1024; Body=6 Fuz1=6 Fuz2=6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Rafael J. Wysocki" If the time till the next timer event is shorter than the target residency of the first idle state (state 0), the TEO governor does not update its metrics for any idle states, but arguably it should record a "hit" for idle state 0 in that case, so modify it to do that. Accordingly, also make it record an "early hit" for idle state 0 if the measured idle duration is less than its target residency, which allows one branch more to be dropped from teo_update(). Signed-off-by: Rafael J. Wysocki --- drivers/cpuidle/governors/teo.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) Index: linux-pm/drivers/cpuidle/governors/teo.c =================================================================== --- linux-pm.orig/drivers/cpuidle/governors/teo.c +++ linux-pm/drivers/cpuidle/governors/teo.c @@ -117,7 +117,8 @@ static DEFINE_PER_CPU(struct teo_cpu, te static void teo_update(struct cpuidle_driver *drv, struct cpuidle_device *dev) { struct teo_cpu *cpu_data = per_cpu_ptr(&teo_cpus, dev->cpu); - int i, idx_hit = -1, idx_timer = -1; + int i, idx_hit = 0, idx_timer = 0; + unsigned int hits, misses; u64 measured_ns; if (cpu_data->time_span_ns >= cpu_data->sleep_length_ns) { @@ -174,25 +175,22 @@ static void teo_update(struct cpuidle_dr * also increase the "early hits" metric for the state that actually * matches the measured idle duration. */ - if (idx_timer >= 0) { - unsigned int hits = cpu_data->states[idx_timer].hits; - unsigned int misses = cpu_data->states[idx_timer].misses; - - hits -= hits >> DECAY_SHIFT; - misses -= misses >> DECAY_SHIFT; - - if (idx_timer > idx_hit) { - misses += PULSE; - if (idx_hit >= 0) - cpu_data->states[idx_hit].early_hits += PULSE; - } else { - hits += PULSE; - } + hits = cpu_data->states[idx_timer].hits; + hits -= hits >> DECAY_SHIFT; + + misses = cpu_data->states[idx_timer].misses; + misses -= misses >> DECAY_SHIFT; - cpu_data->states[idx_timer].misses = misses; - cpu_data->states[idx_timer].hits = hits; + if (idx_timer == idx_hit) { + hits += PULSE; + } else { + misses += PULSE; + cpu_data->states[idx_hit].early_hits += PULSE; } + cpu_data->states[idx_timer].misses = misses; + cpu_data->states[idx_timer].hits = hits; + /* * Save idle duration values corresponding to non-timer wakeups for * pattern detection.