From patchwork Tue Mar 26 09:16:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 13603714 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B3497CD11DC for ; Tue, 26 Mar 2024 09:16:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=HBFQr6yQiTATmuxLLqhjxaMMYQRteokuoCfler4ZCcg=; b=QT7l/BkwtBFBaB v39UcJFuW3jPDFhlNmeq0sS6hYfjSJfUgneXRuo+CnJw2aGrEANLq3RQ61bkjkyD/Eb+CzsE1g4ja 6oZGkUiuKE+aCiOdNpZRgnrrVpKvDry212I36do2x0hFsOlu0yUQnh6waDTg/M19Hdc3ahbof1rYn bPz2FLNNzEdH0JMiN6pHg/j5p2nxnx40Xtw0bKrKFI94RYHiWzHq6BKxq/9R+/FSOX4/x6Vax+cAV qPjJoMPrEWx+l3N18YLyI/okl/kBgFOSU4cgmH0WeoNtINuOKzqQ7dM+24KhYY7q0vTbT9Qy6GVTr GL1y9nOASZdjCUBrQh7Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rp2v2-00000003lgy-1irT; Tue, 26 Mar 2024 09:16:32 +0000 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rp2uu-00000003lcH-2Npu for linux-arm-kernel@lists.infradead.org; Tue, 26 Mar 2024 09:16:26 +0000 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-4148c5de23fso6403985e9.1 for ; Tue, 26 Mar 2024 02:16:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1711444582; x=1712049382; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ncvV5tywoT0mg3neUWKgBj7OJB0wlJy/Q6vGL+2Nulc=; b=R5L9u/+Wy+bezyIqPFmqd0h6eV12pZJDYi0MvOKatE82vcyW8Lc/VUNZpXXx6kyC7D aeSeEza2Z+7F7vZnh2iiPlRIYZ98BGOwEJCIGEIkO4jS9gOHDLOnJiLlwcAppgDUHC4l 9MfNPhbvROI2hGtM2XNrD0Kk55EkWd9YEHOSeAf4axrtevCgb6L8w5COyYbNsl4A4AJ/ EALaQTQ+7eRURjI3Za20ZHrBaa4bVElGlRoo3IDXhIcxHyM2uRxtmdvC9DBmTG9lrKEK /h0h9cE/WOjmPjwvP0e7d0fSsfX/cWXUpxQgQa/tyIRFomiiPZBSXLF9D4xb296nLQJ+ ZQ2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711444582; x=1712049382; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ncvV5tywoT0mg3neUWKgBj7OJB0wlJy/Q6vGL+2Nulc=; b=c4gygiPb9+BfErrMgj8lVhTeuU9KbL5FeNZLryWbb2jFb+teq1WIY3RE/EW36mYV+j DwURFFSo16jJlq3cO8YgTwtTFO3PLZUc+1SUolYrmespuPz/bVuryPgYRSzoMQ4XiUS3 B8VgSyU7FKJ2gkGZdQXnXWJEyys8Wm3kFVrN6vCgax6q7NZ6/PZRqMAWLGAi2NFSNqiN OFt7XWgi9qL1qtMoRiVma2D9ZnzAjpnNZi71W2JA97AMS8r8BTTHTKABEpNqrHbsggl+ K5b27/cs8IarXhKEwJgCtXs2ypwlMWpAnuI3/c8Xh5fi63iaJOFSmBSLmdpgkOWa3+h0 897w== X-Forwarded-Encrypted: i=1; AJvYcCXHg2UpbS3K3Cr8bNGePmpQCPE5sDoqpvd+vuQPB17MLSEY9UwmCM+0ISAbR2fnAelqItmIOC9GfXs2AjhUq0co9gWD0TgCO5U6VrpPKAEiGAXo2Rs= X-Gm-Message-State: AOJu0YyVUt2FXT1xi/aCH38qnrV3zNZF7ESPmpAY+Rcq/aiNJYnzoOsG GAppgSWfjBr4gvaMhdC1G49+WBVB/i5PhXb3FhZpmxxhbw7WxWrJ0p5VI8bly+M= X-Google-Smtp-Source: AGHT+IHKsTV0/LeDcmgiX3ak5nNVWUf2SsQEWgiXqkLcxsRGl+qMU2ykVdAX8JRk7vEVobwjN1tF0g== X-Received: by 2002:a05:600c:4f04:b0:414:887e:6806 with SMTP id l4-20020a05600c4f0400b00414887e6806mr4263661wmq.10.1711444582050; Tue, 26 Mar 2024 02:16:22 -0700 (PDT) Received: from localhost.localdomain ([2a01:e0a:f:6020:e6b6:c92e:43ff:71d7]) by smtp.gmail.com with ESMTPSA id m15-20020adffe4f000000b0033e5c54d0d9sm11647606wrs.38.2024.03.26.02.16.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 02:16:21 -0700 (PDT) From: Vincent Guittot To: linux@armlinux.org.uk, catalin.marinas@arm.com, will@kernel.org, sudeep.holla@arm.com, rafael@kernel.org, viresh.kumar@linaro.org, agross@kernel.org, andersson@kernel.org, konrad.dybcio@linaro.org, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, dietmar.eggemann@arm.com, rostedt@goodmis.org, bsegall@google.com, mgorman@suse.de, bristot@redhat.com, vschneid@redhat.com, lukasz.luba@arm.com, rui.zhang@intel.com, mhiramat@kernel.org, daniel.lezcano@linaro.org, amit.kachhap@gmail.com, corbet@lwn.net, gregkh@linuxfoundation.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-trace-kernel@vger.kernel.org, linux-doc@vger.kernel.org Cc: Vincent Guittot , Qais Yousef Subject: [PATCH v6 1/5] cpufreq: Add a cpufreq pressure feedback for the scheduler Date: Tue, 26 Mar 2024 10:16:12 +0100 Message-Id: <20240326091616.3696851-2-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240326091616.3696851-1-vincent.guittot@linaro.org> References: <20240326091616.3696851-1-vincent.guittot@linaro.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240326_021624_958775_C1CA2910 X-CRM114-Status: GOOD ( 15.19 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Provide to the scheduler a feedback about the temporary max available capacity. Unlike arch_update_thermal_pressure, this doesn't need to be filtered as the pressure will happen for dozens ms or more. Signed-off-by: Vincent Guittot Acked-by: Rafael J. Wysocki Acked-by: Viresh Kumar Reviewed-by: Qais Yousef Reviewed-by: Lukasz Luba Tested-by: Lukasz Luba Reviewed-by: Dhruva Gole --- drivers/cpufreq/cpufreq.c | 36 ++++++++++++++++++++++++++++++++++++ include/linux/cpufreq.h | 10 ++++++++++ 2 files changed, 46 insertions(+) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 66e10a19d76a..1de8bd105934 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -2582,6 +2582,40 @@ int cpufreq_get_policy(struct cpufreq_policy *policy, unsigned int cpu) } EXPORT_SYMBOL(cpufreq_get_policy); +DEFINE_PER_CPU(unsigned long, cpufreq_pressure); + +/** + * cpufreq_update_pressure() - Update cpufreq pressure for CPUs + * @policy: cpufreq policy of the CPUs. + * + * Update the value of cpufreq pressure for all @cpus in the policy. + */ +static void cpufreq_update_pressure(struct cpufreq_policy *policy) +{ + unsigned long max_capacity, capped_freq, pressure; + u32 max_freq; + int cpu; + + cpu = cpumask_first(policy->related_cpus); + max_freq = arch_scale_freq_ref(cpu); + capped_freq = policy->max; + + /* + * Handle properly the boost frequencies, which should simply clean + * the cpufreq pressure value. + */ + if (max_freq <= capped_freq) { + pressure = 0; + } else { + max_capacity = arch_scale_cpu_capacity(cpu); + pressure = max_capacity - + mult_frac(max_capacity, capped_freq, max_freq); + } + + for_each_cpu(cpu, policy->related_cpus) + WRITE_ONCE(per_cpu(cpufreq_pressure, cpu), pressure); +} + /** * cpufreq_set_policy - Modify cpufreq policy parameters. * @policy: Policy object to modify. @@ -2637,6 +2671,8 @@ static int cpufreq_set_policy(struct cpufreq_policy *policy, policy->max = __resolve_freq(policy, policy->max, CPUFREQ_RELATION_H); trace_cpu_frequency_limits(policy); + cpufreq_update_pressure(policy); + policy->cached_target_freq = UINT_MAX; pr_debug("new min and max freqs are %u - %u kHz\n", diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h index 9956afb9acc2..20f7e98ee8af 100644 --- a/include/linux/cpufreq.h +++ b/include/linux/cpufreq.h @@ -241,6 +241,12 @@ struct kobject *get_governor_parent_kobj(struct cpufreq_policy *policy); void cpufreq_enable_fast_switch(struct cpufreq_policy *policy); void cpufreq_disable_fast_switch(struct cpufreq_policy *policy); bool has_target_index(void); + +DECLARE_PER_CPU(unsigned long, cpufreq_pressure); +static inline unsigned long cpufreq_get_pressure(int cpu) +{ + return READ_ONCE(per_cpu(cpufreq_pressure, cpu)); +} #else static inline unsigned int cpufreq_get(unsigned int cpu) { @@ -264,6 +270,10 @@ static inline bool cpufreq_supports_freq_invariance(void) } static inline void disable_cpufreq(void) { } static inline void cpufreq_update_limits(unsigned int cpu) { } +static inline unsigned long cpufreq_get_pressure(int cpu) +{ + return 0; +} #endif #ifdef CONFIG_CPU_FREQ_STAT