Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp539431lqm; Wed, 1 May 2024 08:16:04 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUOuUnCeZopfcc0fEZWnBCZF2fiZYDVqqfLb7iw51aBe2MeQWim9jRE9Is8Kahwq8YFMH5A4hF3p5iBt+KKPVKvvX5jtiOMAcsW6wzdrg== X-Google-Smtp-Source: AGHT+IH4Diky2/B3GHrqXC6tDTCHiz0Qhol0cU/ejbj1T4/nzNMRqlvJ1F6Rj49kD7caFJ2/3qqw X-Received: by 2002:a05:6214:d66:b0:696:4086:5e1 with SMTP id 6-20020a0562140d6600b00696408605e1mr4761613qvs.2.1714576564091; Wed, 01 May 2024 08:16:04 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714576564; cv=pass; d=google.com; s=arc-20160816; b=YIGADl91EdIWnSF6uHO0jWggDsS6Nnvve4ufVdA8YuRYyAuLvQWg/ZB6kG4773hYt1 3EBefe0hFRnqDCBdeRXPing0wLU8VgTYSugB8eqgF3l1jd96Hqtp0Vj60ki3XR3dWcM2 6d30o/cW0DtPL11PgbRzvXM2yiwBT1SrKLazeIwjMTTQLorCZBbEA5lzMBEVrUKGmLDF +6BFFP3eeEPlPARtTN37RcwWHmpJSCTtob42SoQfkXHvvpejScw3XIOKP5JcRnc4cNpk +nNy8sl0CrY1Bcfi15mq4HMqQ+T8C8iLhK0NQHxC+O8lHpx8Se45tcd23PYgOqpO12bC TLvA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:sender:dkim-signature; bh=egMQjv+C2ACOSGJGwERMU3JJelRVUGx5f2uXYjvIRCI=; fh=CyfQ59gAqHCqEVu3/Kpmpz3eSpqY4OKqy3rni0n0vzM=; b=HZlJuqHrutCXeUaDahrUEDBqhczlmTOxK8xawhuIIPprnz4MCTVzpWnaYWVThpB5Xp gU8hK3uaviATumf+fGIj0CSce2owM8kNHdk9MhVaBHF/9CqTCpfbJ54qCNh89Yk9TUje hKDuybEt8PyL4wED+DHfKrm3r6TpFVkmQWxTAvsvXIIuMFAbuM5elyliBAVpF+AkU4vD NbDas7j3Fl2YfToL7sPT2hMNCjNrsx8M30hdezeeqgxq9Q8IcyqbJkDeoegM+oks+Ydw tAubNDOzzNYKYfMoFi4NMDST28U0EmxBcq5SSY7azgFABhR14F/9wAmxTaoQmU1fnk7n m8bA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ZOtBdF4X; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-165429-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-165429-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id gf2-20020a056214250200b0069b80bdb5a1si31846592qvb.305.2024.05.01.08.16.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 08:16:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-165429-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=ZOtBdF4X; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-165429-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-165429-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id BD8761C21A0A for ; Wed, 1 May 2024 15:16:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DD35B131742; Wed, 1 May 2024 15:13:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZOtBdF4X" Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7A7D21311B6; Wed, 1 May 2024 15:13:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714576421; cv=none; b=iPyJPb027Rx6MrczFzEkzC2Gp+1FIjW3Tx1akHwyOL6pIklkJUziHfUwcAYJz6RxZsY92DIFdin105MFW4iSGyz1V7HjQXPH5dqISCejpDksbia2zWqTXjP60Njql1j4Lf/UyedKjcUXHpjX2SrhI6R3kxojgV4vNOnqGTsKGBQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714576421; c=relaxed/simple; bh=UVJBlg1E80HF88FwUythpmvNcunKH0Z9gizWAA9cYKA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=PmYzTtJP+LHlW9vMt65OD7/MLVn9eiLetuUFtRl+R7ce+CSe1LAXgVOD8lNfybZu0LIMpOXMPlFA2ajihwQJXM8h83dgqO59iCc1/RHc7HsO1TPDffwZKhkqyrrBwnq4etfIvZsVbnbL1p1sRWu5+Xo1BH5tymDLXBBhZLNxC4A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ZOtBdF4X; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1ec85c2f469so6589045ad.1; Wed, 01 May 2024 08:13:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714576420; x=1715181220; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:from:to:cc:subject:date :message-id:reply-to; bh=egMQjv+C2ACOSGJGwERMU3JJelRVUGx5f2uXYjvIRCI=; b=ZOtBdF4XXQ73z83mBxzUUTmCUU0784h6KULV9SSgUiXDr20pR8dREuPlEajFF2IoeK rXHsSSmKSjjvVixiafTfjEstTOJEYlpkzhLQ7DDpm5jWBWZDhF1WI2EcwgfcjnhjlsMz hwPV9P5gRPgrX8JbSmcj5S4ICOHfK/t6eh+qJzndBPtGzlt/G0scsHf3G+eKasJ+OEvx WSBwfRo05uMVD5PWL5LLG/7GAbcTS+YNG8mvrChbljGmNbQIfEr8l1w2lr3yFAAod/Ye IPK35NmEDsFl9b2xIMN4Z4RsSFc9/wmnup55fVLR8RTUBEJ18Ch2K7cmW8p4oBd8/53u rH9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714576420; x=1715181220; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:sender:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=egMQjv+C2ACOSGJGwERMU3JJelRVUGx5f2uXYjvIRCI=; b=CB6yiz7bpAm76WZUWxBxL/9IGMq4EKfg6wVSwIGsizrIyt7KrpFtub2ZbVdH10/8WD VvXfWavMSBGsvRLLkxnb2MCteW3po22qfpnQNWTNDGYOo4SqKCVtBokjUAiRsJpIXERj G1nFaDpJBOJ/KbedMpuJEystK5KYnl6NBhiw+lOM97NX/1phazsN8Xni7hBkmd9jjSMX RJ9Ssfh7cMZvQX6k6Ft9ytKISPBmjnuGv5EnvEGHQ3QEqq4XCvQXJmsWdZUC8b1MOD3H Nm/MI24/tiT5OtRKs4eP4qdhavhHIP84kA9iWi6gSIEFVJNcv4vJ/dKmNETpV0GdYam4 8S1w== X-Forwarded-Encrypted: i=1; AJvYcCW6MV36rgizZVYakvMi3QoTJ5eGa3Blw5rSyCbYhUX1PMv36PXwJuIWlvR9bk2ctsX6Hm/6pBYo7/4A9C/7G3ieSbrM X-Gm-Message-State: AOJu0Yy/UcdhXP+xFUOUDvnbdi1+3QwCX/q+126KgsH9XPOxuHtb7Z0o SJEHRytINwhVcCMPATjprY/+LH4NS4SuJZj4DrmN7K2hQePF1qjj X-Received: by 2002:a17:902:eacc:b0:1eb:d72e:8296 with SMTP id p12-20020a170902eacc00b001ebd72e8296mr3719278pld.10.1714576419525; Wed, 01 May 2024 08:13:39 -0700 (PDT) Received: from localhost (dhcp-141-239-159-203.hawaiiantel.net. [141.239.159.203]) by smtp.gmail.com with ESMTPSA id w3-20020a170902a70300b001e83a718d87sm24349755plq.19.2024.05.01.08.13.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 08:13:39 -0700 (PDT) Sender: Tejun Heo From: Tejun Heo To: torvalds@linux-foundation.org, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, martin.lau@kernel.org, joshdon@google.com, brho@google.com, pjt@google.com, derkling@google.com, haoluo@google.com, dvernet@meta.com, dschatzberg@meta.com, dskarlat@cs.cmu.edu, riel@surriel.com, changwoo@igalia.com, himadrics@inria.fr, memxor@gmail.com, andrea.righi@canonical.com, joel@joelfernandes.org Cc: linux-kernel@vger.kernel.org, bpf@vger.kernel.org, kernel-team@meta.com, Tejun Heo , "Rafael J . Wysocki" Subject: [PATCH 11/39] cpufreq_schedutil: Refactor sugov_cpu_is_busy() Date: Wed, 1 May 2024 05:09:46 -1000 Message-ID: <20240501151312.635565-12-tj@kernel.org> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240501151312.635565-1-tj@kernel.org> References: <20240501151312.635565-1-tj@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit sugov_cpu_is_busy() is used to avoid decreasing performance level while the CPU is busy and called by sugov_update_single_freq() and sugov_update_single_perf(). Both callers repeat the same pattern to first test for uclamp and then the business. Let's refactor so that the tests aren't repeated. The new helper is named sugov_hold_freq() and tests both the uclamp exception and CPU business. No functional changes. This will make adding more exception conditions easier. Signed-off-by: Tejun Heo Reviewed-by: David Vernet Cc: Rafael J. Wysocki --- kernel/sched/cpufreq_schedutil.c | 38 +++++++++++++++----------------- 1 file changed, 18 insertions(+), 20 deletions(-) diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c index eece6244f9d2..972b7dd65af2 100644 --- a/kernel/sched/cpufreq_schedutil.c +++ b/kernel/sched/cpufreq_schedutil.c @@ -325,16 +325,27 @@ static unsigned long sugov_iowait_apply(struct sugov_cpu *sg_cpu, u64 time, } #ifdef CONFIG_NO_HZ_COMMON -static bool sugov_cpu_is_busy(struct sugov_cpu *sg_cpu) +static bool sugov_hold_freq(struct sugov_cpu *sg_cpu) { - unsigned long idle_calls = tick_nohz_get_idle_calls_cpu(sg_cpu->cpu); - bool ret = idle_calls == sg_cpu->saved_idle_calls; + unsigned long idle_calls; + bool ret; + + /* if capped by uclamp_max, always update to be in compliance */ + if (uclamp_rq_is_capped(cpu_rq(sg_cpu->cpu))) + return false; + + /* + * Maintain the frequency if the CPU has not been idle recently, as + * reduction is likely to be premature. + */ + idle_calls = tick_nohz_get_idle_calls_cpu(sg_cpu->cpu); + ret = idle_calls == sg_cpu->saved_idle_calls; sg_cpu->saved_idle_calls = idle_calls; return ret; } #else -static inline bool sugov_cpu_is_busy(struct sugov_cpu *sg_cpu) { return false; } +static inline bool sugov_hold_freq(struct sugov_cpu *sg_cpu) { return false; } #endif /* CONFIG_NO_HZ_COMMON */ /* @@ -382,14 +393,8 @@ static void sugov_update_single_freq(struct update_util_data *hook, u64 time, return; next_f = get_next_freq(sg_policy, sg_cpu->util, max_cap); - /* - * Do not reduce the frequency if the CPU has not been idle - * recently, as the reduction is likely to be premature then. - * - * Except when the rq is capped by uclamp_max. - */ - if (!uclamp_rq_is_capped(cpu_rq(sg_cpu->cpu)) && - sugov_cpu_is_busy(sg_cpu) && next_f < sg_policy->next_freq && + + if (sugov_hold_freq(sg_cpu) && next_f < sg_policy->next_freq && !sg_policy->need_freq_update) { next_f = sg_policy->next_freq; @@ -436,14 +441,7 @@ static void sugov_update_single_perf(struct update_util_data *hook, u64 time, if (!sugov_update_single_common(sg_cpu, time, max_cap, flags)) return; - /* - * Do not reduce the target performance level if the CPU has not been - * idle recently, as the reduction is likely to be premature then. - * - * Except when the rq is capped by uclamp_max. - */ - if (!uclamp_rq_is_capped(cpu_rq(sg_cpu->cpu)) && - sugov_cpu_is_busy(sg_cpu) && sg_cpu->util < prev_util) + if (sugov_hold_freq(sg_cpu) && sg_cpu->util < prev_util) sg_cpu->util = prev_util; cpufreq_driver_adjust_perf(sg_cpu->cpu, sg_cpu->bw_min, -- 2.44.0