Received: by 2002:a05:7412:8d09:b0:fa:4c10:6cad with SMTP id bj9csp349538rdb; Tue, 16 Jan 2024 02:08:33 -0800 (PST) X-Google-Smtp-Source: AGHT+IH9u5+cRsQZrX4WmifT3mmNdkmygyztzTZZ/Y7af+U43pt+A1/k19QrZeixRqOOHn+tLtkW X-Received: by 2002:a05:6a00:e88:b0:6d9:aa5e:3969 with SMTP id bo8-20020a056a000e8800b006d9aa5e3969mr8009470pfb.40.1705399713542; Tue, 16 Jan 2024 02:08:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705399713; cv=none; d=google.com; s=arc-20160816; b=w+2OyCtfhivSeOIAA8r+EyHlS80YUQPAWBMEhVi2NTHL0Hv+ycuHYyCwxt6SaT6fpg oTd10etMwHSkOFnYZuPBVUxbk8mlYMotJXQilPNjZ6LAeVXBjEe2f8hRTahRRQ98GZcv HE9sdSpD+WJjVO8EL/Mu0KfOA8PjdHU6MylXukwZEiyY4I1cENnY/2epfGtQIhqIiKW0 1Ts0mVOA94p8fFstY9R/V7NYSZ80qxXEkmQinMugpu8n5gJr7I6AC6eI8dOn4G+S+fu8 QbDMLhPcoNAonKej6g0Or9mD8WecixvdqQg1XWqf/OMPBYPaxJMdo8xVwUEqi8kujUNf dPSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:precedence:robot-unsubscribe:robot-id :message-id:mime-version:list-unsubscribe:list-subscribe:list-id :precedence:references:in-reply-to:cc:subject:to:reply-to:sender :from:dkim-signature:dkim-signature:date; bh=/Awifqxg6eOBMIPHwm/f2jqMJMZMe9tEsWAtoE0BA5w=; fh=aXjG/0fXTeE6UWbe5HURXmJFNvkHwoyqhnCuGNQ+tp0=; b=HWDHCrUS82a8xlVGczlpZA4nMqSZM0aLcscqWQ2xNKepbkc1lLNWPOSj+2K8FiJPG6 dZ2CXL/M95+4nEdmdyXYx94iSJIxTyPtGLh8eEgK9JHGuBgc5oHOJ0ZvYh7F4VPVtlYs CyyT6qdZ0yCZ95RXyxDT7Ob3pDSBQC5IxS5pHYzs/6fMl0Si9u2yJmyMU/RkFUL2PNP4 BMabt2SwMTIv0O9m+128bagNaGu9ZqsAuNm5WiYkpunPdjBns2l4LAi+sPJSDWYRbnS+ wL21HDH7ooz8Ly1ZZDYiFyIqcvP12ep74nD/8PMFoTmEW/XRHKBH+PfUjMgHlFSbS0Qc OBzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Iin3idrR; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel+bounces-27236-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27236-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id cd23-20020a056a02079700b005ce89d2b942si10799469pgb.868.2024.01.16.02.08.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 02:08:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-27236-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=Iin3idrR; dkim=neutral (no key) header.i=@linutronix.de; spf=pass (google.com: domain of linux-kernel+bounces-27236-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27236-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id A2115284F52 for ; Tue, 16 Jan 2024 10:08:32 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D83D2134C7; Tue, 16 Jan 2024 10:08:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="Iin3idrR"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="IP5KSt3E" Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (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 A26E6134A3; Tue, 16 Jan 2024 10:08:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Date: Tue, 16 Jan 2024 10:08:20 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1705399701; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/Awifqxg6eOBMIPHwm/f2jqMJMZMe9tEsWAtoE0BA5w=; b=Iin3idrR5MZ/nYHs+cYEsV+nEIlY6DHvv2qPF2ngONsM98z0snV5Y2/CfdNjbcpNLu480W qdntxcOkNVC5Yhx6bGrnqpSRO2E6arjUNGDhL2AfTnu30764nYzgnBEpWRLuQDNc/xWGzT mBMjciieIvAaxgrTgxajtDziN69N7D2DiOKWF3WqdN0ComW2ucwVuhgVvSEYFLnmfYC4+O q8NY/vbl3qBPeGZfBi9QZKqKSsc1weB0RrnQIfIvxy77GozjPoC9cNbUjYkJ/Pscd4k4JV jv/5AryD7oG8OCJqCLA7zHi3scL5x9ad0FbLldIX63omB9BJ8pP0qhmvXkqHWA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1705399701; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/Awifqxg6eOBMIPHwm/f2jqMJMZMe9tEsWAtoE0BA5w=; b=IP5KSt3ELERRE2YEvC1Ydl8wwWpVpWNiLC0dT6a1jo7G/ywSa/YSKcO5bWzk1jSmF4zA4o 4VzZtEmakW8noeDA== From: "tip-bot2 for Vincent Guittot" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: sched/urgent] sched/fair: Fix frequency selection for non-invariant case Cc: Linus Torvalds , Wyes Karny , Vincent Guittot , Ingo Molnar , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <20240114183600.135316-1-vincent.guittot@linaro.org> References: <20240114183600.135316-1-vincent.guittot@linaro.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <170539970061.398.16662091173685476681.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit The following commit has been merged into the sched/urgent branch of tip: Commit-ID: e37617c8e53a1f7fcba6d5e1041f4fd8a2425c27 Gitweb: https://git.kernel.org/tip/e37617c8e53a1f7fcba6d5e1041f4fd8a2425c27 Author: Vincent Guittot AuthorDate: Sun, 14 Jan 2024 19:36:00 +01:00 Committer: Ingo Molnar CommitterDate: Tue, 16 Jan 2024 10:41:25 +01:00 sched/fair: Fix frequency selection for non-invariant case Linus reported a ~50% performance regression on single-threaded workloads on his AMD Ryzen system, and bisected it to: 9c0b4bb7f630 ("sched/cpufreq: Rework schedutil governor performance estimation") When frequency invariance is not enabled, get_capacity_ref_freq(policy) is supposed to return the current frequency and the performance margin applied by map_util_perf(), enabling the utilization to go above the maximum compute capacity and to select a higher frequency than the current one. After the changes in 9c0b4bb7f630, the performance margin was applied earlier in the path to take into account utilization clampings and we couldn't get a utilization higher than the maximum compute capacity, and the CPU remained 'stuck' at lower frequencies. To fix this, we must use a frequency above the current frequency to get a chance to select a higher OPP when the current one becomes fully used. Apply the same margin and return a frequency 25% higher than the current one in order to switch to the next OPP before we fully use the CPU at the current one. [ mingo: Clarified the changelog. ] Fixes: 9c0b4bb7f630 ("sched/cpufreq: Rework schedutil governor performance estimation") Reported-by: Linus Torvalds Bisected-by: Linus Torvalds Reported-by: Wyes Karny Signed-off-by: Vincent Guittot Signed-off-by: Ingo Molnar Tested-by: Wyes Karny Link: https://lore.kernel.org/r/20240114183600.135316-1-vincent.guittot@linaro.org --- kernel/sched/cpufreq_schedutil.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index 95c3c09..eece624 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -133,7 +133,11 @@ unsigned long get_capacity_ref_freq(struct cpufreq_policy *policy) if (arch_scale_freq_invariant()) return policy->cpuinfo.max_freq; - return policy->cur; + /* + * Apply a 25% margin so that we select a higher frequency than + * the current one before the CPU is fully busy: + */ + return policy->cur + (policy->cur >> 2); } /**