Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp220651rdb; Thu, 21 Dec 2023 07:25:07 -0800 (PST) X-Google-Smtp-Source: AGHT+IGBx+OjHyHovS1kIcrIoo7YNj98jFc9UxUY5r3qFHAZrGBs2GEJ8Zpi4rOE1pkDA4VKYy6S X-Received: by 2002:a05:6870:478a:b0:204:1ed0:83ef with SMTP id c10-20020a056870478a00b002041ed083efmr1703145oaq.36.1703172307500; Thu, 21 Dec 2023 07:25:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703172307; cv=none; d=google.com; s=arc-20160816; b=OPdr7/yQNI+PzHJdXwy4utaUd/Io9vh2QXoQk2ql+vq/rDMYjAlopPqWO5Mf8T5yV9 XgJh25DRdE5RmULjOvYlLNkzjvmCcqJEyazD8Nnuqn7jK2sLkGSQwo/Wda7IqiO0cjy8 Gpkzp4ptF7uLfsPKdcIX+fZHckvwfYyeJjnckrnHQOYc4H/Hz3xn4fug7YkNCNc15IQF NRbcd+a9YuJvocVIcvSGif4fxQjUgJi9JKMJe0H2SXrvQVU+E0G8GkNRR+qv8ZZ21eo+ /vic6pIDRcPgbJF9WfoxEkQpGylEeC8TI6+eqkAIFQ9npmkGvo+wNBsvszhJ3nzz04gi BCbg== 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=v/J6RB2Lw/HQZsxNLlML+TfeS0CELCbuPUL4YNRnsW4=; fh=iADtN8DS7aRpM2ioXQmdV7EpooAyhly8rwPOp18JeP8=; b=EvxIpWuyueV/jvTB02p2HueIROkmF22R7eh84XcwVUN4uADNkXEW3IMTe183iRJl9T Tyl1/50mY+pwdrWsw9AvpPBsdN+OGTjBwr4M74w6INE+tOfmYa5jnyMdUXd5pVDSZyNk 34Gk88NKZWM24LGhnl/uhlUsV+1VvVYyyZfHYAdmtEzfLe321NvbGuSqAzb4SvOLPNGj wBxDXlRt3e2rd1O3pu05yOKyVFNCtDhDWnz4VPRkoKnDnYZWBucSEwVogGx6NCsQHd6M UbxHHdO0Zdr2NkkcuEG3znTRFjPJK2IVZbSBKJPd9Fg0lJ1Aazf20gVjHF+P7d/WkBt1 Y2/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EPo9OeCy; spf=pass (google.com: domain of linux-kernel+bounces-8647-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8647-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id y12-20020a67bd0c000000b004668701e9c5si329224vsq.737.2023.12.21.07.25.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 07:25:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-8647-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=@linaro.org header.s=google header.b=EPo9OeCy; spf=pass (google.com: domain of linux-kernel+bounces-8647-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-8647-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 4389B1C23B94 for ; Thu, 21 Dec 2023 15:24:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D2E6B53A1E; Thu, 21 Dec 2023 15:24:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="EPo9OeCy" X-Original-To: linux-kernel@vger.kernel.org Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (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 642C5539EA for ; Thu, 21 Dec 2023 15:24:14 +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-wr1-f52.google.com with SMTP id ffacd0b85a97d-3365f1326e4so809069f8f.1 for ; Thu, 21 Dec 2023 07:24:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1703172252; x=1703777052; 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=v/J6RB2Lw/HQZsxNLlML+TfeS0CELCbuPUL4YNRnsW4=; b=EPo9OeCyCT8iG7KPFfiRRNBD1nPqfCmFN8NlasJvxyBiLFqC5rn0OVtiIanRpnLJCc AHytF4qG/CuSOoWZSuWpdA1Alg+xBVngoYIJtIPEv4JKJ+HJ/1cogvellIBHsOCyIZnO xH3olKLQCKsAe32z9y1TpViCtIrRBK1y/SWEUT7JDzoOe8t5+f37sRgldkELnFFaBvHm TDCz+NGq0JzS1WcYJlwWknWqQZYSvLNqyz1rscmYI9c86T1/YGvKUpdxKEzh2pUUziQf RAVldsdiSzQOX5j7L1ATDLsP11+kQDzXGj6u/JQzmuGrJfFUAc2Hmd2R3SD2UrebMs8i 5KvA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703172252; x=1703777052; 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=v/J6RB2Lw/HQZsxNLlML+TfeS0CELCbuPUL4YNRnsW4=; b=Hk5QNmoZHnO8is5Q56c8KKwyEwD1LGYPY40sQFDrbEQtuN6F4lZfjGfltftAmEv2hm G46zVaKxryGTVEF8ZmbANA6EkbW+IFqnCfaCRkePe/uL8SdKO1d/fDN6EZIhM+Mvis4h om4N86VUMEbYikhoYzIaEXnWleSBETW3PA7efEOYTF+n97tTfoWrb8UDWZl2WvIEn+Uh 1aGf/0LsWbvB0N7Xijw48szagjSlPJ5sdPrG2H45ekkIrm2kri6S01Zklay9gI89idK2 bEaHSa/XidoZpC77TpWpcXZG7K31mDWbbYXR6iR8Y3uxxp3OKhbccUs9rtcKlJD58qjB ZCmw== X-Gm-Message-State: AOJu0YyWk38bXm58+b141KXufp3F4Od0HxEm2JLAhHs+1LKEyXbXpxAV PN/6dq+OVmlcUu6z68Bi/KfelQ== X-Received: by 2002:a05:600c:6012:b0:40c:32fe:e123 with SMTP id az18-20020a05600c601200b0040c32fee123mr827986wmb.167.1703172252551; Thu, 21 Dec 2023 07:24:12 -0800 (PST) Received: from vingu-book.. ([2a01:e0a:f:6020:2db4:9d2a:db65:42d6]) by smtp.gmail.com with ESMTPSA id t3-20020a05600c450300b0040c4acaa4bfsm11466974wmo.19.2023.12.21.07.24.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Dec 2023 07:24:11 -0800 (PST) From: Vincent Guittot To: 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, linux@armlinux.org.uk, corbet@lwn.net, 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 Cc: Vincent Guittot Subject: [PATCH v2 1/5] cpufreq: Add a cpufreq pressure feedback for the scheduler Date: Thu, 21 Dec 2023 16:24:03 +0100 Message-Id: <20231221152407.436177-2-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221152407.436177-1-vincent.guittot@linaro.org> References: <20231221152407.436177-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 | 34 ++++++++++++++++++++++++++++++++++ include/linux/cpufreq.h | 10 ++++++++++ 2 files changed, 44 insertions(+) diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c index 44db4f59c4cc..15bd41f9bb5e 100644 --- a/drivers/cpufreq/cpufreq.c +++ b/drivers/cpufreq/cpufreq.c @@ -2563,6 +2563,38 @@ 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); + pressure = max_capacity = arch_scale_cpu_capacity(cpu); + capped_freq = policy->max; + max_freq = arch_scale_freq_ref(cpu); + + /* + * Handle properly the boost frequencies, which should simply clean + * the thermal pressure value. + */ + if (max_freq <= capped_freq) + pressure -= max_capacity; + else + pressure -= 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 +2650,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