From patchwork Tue Jan 16 10:08:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 188482 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:42cf:b0:101:a8e8:374 with SMTP id q15csp155725dye; Tue, 16 Jan 2024 02:08:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IGRN4z8MnSJvd+SHjMpsT2rXKq0bi0Aveo6NPfqojcR1NScfZryqyctSB7bJT/VIrg6Tjxx X-Received: by 2002:a05:6870:3c84:b0:206:c934:49db with SMTP id gl4-20020a0568703c8400b00206c93449dbmr5462912oab.99.1705399720392; Tue, 16 Jan 2024 02:08:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1705399720; cv=none; d=google.com; s=arc-20160816; b=csDMt5ksTl5Zk9UDZkEgBAZL6w2+igOOxetOgovhLcBmjHaEFlzo71Ns/+FOTwm4GS ks8NhfQZCbLQ7Rkd5Tu6r9tYcsxYvS2Sqa6//frNE2R/hBi5/cfqWOFnYRi1jfm2BqLg R2A0rgqOGChmNLYb59peQ+UCN5zubPspGuH1pft++G6O2B02z2fJ6ll4LYOgutR2HzUO KjFFpWDF2AQm8GWIwKfA7wl2FfwNkDMaQ1O7EWG5oCX9pGym1f1sVnK3YVqQTC53uhg9 ST8dolsQHXL/eFRFD6wQi3gNQ8fmuNuqn6ZDMFpq2juyPNar2zS3TO1He7PYngak1pPp Rolw== 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 header.s=2020e; spf=pass (google.com: domain of linux-kernel+bounces-27236-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27236-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=linutronix.de Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id u17-20020a656711000000b005cdb49a80adsi10818882pgf.144.2024.01.16.02.08.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 02:08:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-27236-ouuuleilei=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 header.s=2020e; spf=pass (google.com: domain of linux-kernel+bounces-27236-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-27236-ouuuleilei=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 422B02833A8 for ; Tue, 16 Jan 2024 10:08:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B780813AC4; Tue, 16 Jan 2024 10:08:29 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788241217131544551 X-GMAIL-MSGID: 1788241217131544551 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); } /**