Received: by 2002:a05:7412:e794:b0:fa:551:50a7 with SMTP id o20csp444753rdd; Tue, 9 Jan 2024 08:47:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IEhxQSLUz2WtPVk2q0LnkU5EYZNF1H9IMhfDl/wGvhP9NJCXCDRQ3ndj1EDzI5121jNfjWV X-Received: by 2002:a05:6358:7254:b0:174:febd:51f3 with SMTP id i20-20020a056358725400b00174febd51f3mr6510690rwa.47.1704818860935; Tue, 09 Jan 2024 08:47:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704818860; cv=none; d=google.com; s=arc-20160816; b=0Dq5Kh4ml5uwmdUyFtHYM5aE/pCKVjgK5bNvhpK454X2042NCR4YE2Bey/20N4qLE9 LHkhqxMuGLTgUZOpaGAlcAwEoPuMEPqQqD3SviAMNyqy/zQJbiZVtGxw6/OtU7ciEV/m zseJGmF9c05HvBUSjzOY5rk6w/rUV4sL6y6VFL3L3OjyJQsngnddVPWxt56J0bKcClX9 q67oTmA+nChV4B12YqI91q2P/q3xTLEDY4QWSFmfTOmsGx7qR5FCX6F3cz1L4rXhIBvW ew0E/ErZkmGrK1ZjSKKrxut0kh+Fcnih8YJJFKMkRmzB92tFkoC8epMZmPZCMfw//Zkc kTPA== ARC-Message-Signature: i=1; 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:dkim-signature; bh=1VSqPsC352z1+DaREu/L/y/EnPhhSVHlvyMYIWruXUU=; fh=ckb4uIHbQxCINhPspZAm7nYFj+6K7jiYA7oZvU68Qj8=; b=naCMUGKZs0scwwqnYX+tqo8uBRqTgmxv+btC5srP2TxuPh9o9dUvNoXhobntA+2RvE RgnmQJdzZPw4XFZBnhjv2JYvLVvwQVIVUFzKtqTJamWA7BZCys7etojo55MMXxgjW61b qB1vbsoU7yKzq7VfsgtaLcEYsoJhbe3HWo163DmBQOJZOVU7pt12jeQUCrrOeTPDhinH ugUrGxsL6s6FS0JtSFJNGkd+bVGkdGzOBWslIJm3cE9yYeELP0jIVyQM2ObXt2f9/hYa mH3GWBqdmoyL9Hb7dmSNY+C/o8g+Sr53dJ9uYo2GY79lEgIf8Fi6OtoeByw9FypWpNYO s1RQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jTVVLDGi; spf=pass (google.com: domain of linux-kernel+bounces-21125-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21125-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id w186-20020a6362c3000000b005cdfc01dcc9si1692002pgb.245.2024.01.09.08.47.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 08:47:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-21125-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jTVVLDGi; spf=pass (google.com: domain of linux-kernel+bounces-21125-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-21125-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 9B5A9288D5D for ; Tue, 9 Jan 2024 16:47:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E42333AC1B; Tue, 9 Jan 2024 16:47:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="jTVVLDGi" Received: from mail-wm1-f46.google.com (mail-wm1-f46.google.com [209.85.128.46]) (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 5F3843A8C8 for ; Tue, 9 Jan 2024 16:47:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-wm1-f46.google.com with SMTP id 5b1f17b1804b1-40d5a41143fso35182955e9.3 for ; Tue, 09 Jan 2024 08:47:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704818820; x=1705423620; darn=vger.kernel.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=1VSqPsC352z1+DaREu/L/y/EnPhhSVHlvyMYIWruXUU=; b=jTVVLDGiE7WNcrkOERK2EEUMaKyg23ystLP3DjBT/yke9332eivvROsbDW5aZ55wK9 NfbjgFTPKu2lUX3A8Hs4cwDPggo16wcqxp4MINnLsTuWHsqhjS03inWExzQfwF137NYW 4p9quVeKD5CgmJ5LD7fjvOow6FJ626B4Ft0sCsFVmi0VNt2Po3uEvK++8gt/6dKX9g7t V2OooJbDOL+UJY8MSTqFmXYTbKqTzjdBJ6//gDnte6iZdGlsFbo29pKFGjV+rQGPrEex Z+HDwzVziw00LwoQ9MpLntwOAbl+vMgzcH3yVr6/2SowUY/Cat7xpsdbnpgH1pJYBtv7 bC0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704818820; x=1705423620; 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=1VSqPsC352z1+DaREu/L/y/EnPhhSVHlvyMYIWruXUU=; b=JRdOO7ju/WIzr6aC4XmtNd+lnIZ7m3dNbE7VZriMAsnn3Mt0sCbwX7JmhwWZTews16 Ay80Gspw/73TE5lI/CILepj8jZwjKrEkpI9DQCYacWJTaEtWL5tQvGdlj//lKp7bCWeU QQtg8wYQ9D87ATLwbLa3QXjJs40Vn1dreL6D+dB1LQ/rmOEPbODKeBOF88oKEHfyt7fM 6b+REBb5NBK3ya5Bo4aC0iay70jlMYGOj0TrFHIDspd9gXtS6BSC9t7p1FJxCZukp2ip xpV+STrgoNPZIVHtqPpyHGWHubufUUbLMaMacX7kH/5titpLcyTAsm/eV6Gh5/lwhBZO pZyg== X-Gm-Message-State: AOJu0Yz4doQt5KfvepvCyrySvceQ7Y6EDM7nYgH2xUxH2Psey6MM1dov I8n7axn5Fx9VU3FKTU1YlDDQaGZYvJwlzg== X-Received: by 2002:a7b:c043:0:b0:40d:38ba:544e with SMTP id u3-20020a7bc043000000b0040d38ba544emr3404193wmc.60.1704818820623; Tue, 09 Jan 2024 08:47:00 -0800 (PST) Received: from vingu-book.. ([2a01:e0a:f:6020:378:51f6:d46e:8457]) by smtp.gmail.com with ESMTPSA id r4-20020adff104000000b00336a0c083easm2847845wro.53.2024.01.09.08.46.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jan 2024 08:46:59 -0800 (PST) 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: qyousef@layalina.io, Vincent Guittot Subject: [PATCH v4 1/5] cpufreq: Add a cpufreq pressure feedback for the scheduler Date: Tue, 9 Jan 2024 17:46:51 +0100 Message-Id: <20240109164655.626085-2-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240109164655.626085-1-vincent.guittot@linaro.org> References: <20240109164655.626085-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 Content-Transfer-Encoding: 8bit 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 --- 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 44db4f59c4cc..f4eee3d107f1 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -2563,6 +2563,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. @@ -2618,6 +2652,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 afda5f24d3dd..b1d97edd3253 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 per_cpu(cpufreq_pressure, cpu); +} #else static inline unsigned int cpufreq_get(unsigned int cpu) { @@ -263,6 +269,10 @@ static inline bool cpufreq_supports_freq_invariance(void) return false; } static inline void disable_cpufreq(void) { } +static inline unsigned long cpufreq_get_pressure(int cpu) +{ + return 0; +} #endif #ifdef CONFIG_CPU_FREQ_STAT -- 2.34.1