From patchwork Mon Jan 8 13:48:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 13513507 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 22A24C47079 for ; Mon, 8 Jan 2024 13:49:27 +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=vvDXJLBsKwu5Gcr4+/pOo6uEffd9eEdNgq052JcZop4=; b=R3wGdRX1o2jywH 1SDJ8gc5hxAOZrmd3oHG/qBQvjgqHRktvPv+C1Vxq47Yh+qDIJvrKPRJV431b8kQ302HTQR5IXPCx GAoAGdxnsGCpJjVBYYKCFXOBgB9Cu+3jJQERQ3Q8rXHCeGRhUhEKUF76206yK0CDjIceMBQ1TMNE5 zC7MshFLH8sRECUPogzW5rsupQIO3zGCWrRYpaGkVS8yaEsdflD+m2VVTnhzfOhuzuRPOV2eB5L18 5GlumcgemNyUmtf+DoJ/ZN1PJAzc0dY2w4AqsSUNZ6XWkmRK+mtd6mfbxcEZ1eV4Ox5O8DInBA0Gz xmqbvAnFQHFWfI3BgkrQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rMpzs-005Fra-0l; Mon, 08 Jan 2024 13:48:56 +0000 Received: from mail-wm1-x334.google.com ([2a00:1450:4864:20::334]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rMpzm-005Fqa-2k for linux-arm-kernel@lists.infradead.org; Mon, 08 Jan 2024 13:48:54 +0000 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40d8902da73so16970445e9.2 for ; Mon, 08 Jan 2024 05:48:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1704721728; x=1705326528; 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=7fvnZibSbFntNDnoL7efsSjElZrSEtJFyvVsz8uF35o=; b=dZVHsmAPt7teMdftIyMBfOdETu0JHodIGFkOZjZ152KBqfA0Hq4keUItS9E3jAc/6g Nex7QLmO0QRRyynfAzgKbRYSZU636QYF9Gr9p1B9omunoTgjXAcSMZDAl+nWFL6zbYN7 jOmVlVfpf7+GyUbCIL4MQjxrRY5+eu62rzwT4GsjEaBwTf/SOiwGMYq+Hc+Wi0ZRIWW3 cA8YYvY5hHyoBbzmJhJvRjwJngt9fOUCqFt2lct5lzqmxVHXHJOyckJEqLKVFWSwYUlB /XAyt1SWuvEjCv4557LEDmmTd/glj8GsIjfbML/CojKgX43ZSN47T7T+NRvI8aoE7s8K z1jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704721728; x=1705326528; 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=7fvnZibSbFntNDnoL7efsSjElZrSEtJFyvVsz8uF35o=; b=iTu3PFYjLXbwvOu3Wgwg1DtVFRkVQPRMxphPoEH/O2aca5nyW8c6uLkAMQwJH4XSBr LxcgdvFqVG23VhHoyX1y3o53t61ZXuKxyDLo5UT1Zs9Ob/OXqSWt1T/SYOeOk3Xbwflh pYfoJPMEvYVKn4ljUDApE6mXJgFnFrbQOnZZBEoJjDX2bV3dzAcikwb2iK/+6jCOK1+z Iz1ILABhcVzSKqlewMIrK79sJkBb3+kkaPb71GUxY+DkJemwHFfLO7l1/zuzidDFLvUo /OHrnT1/8xMnRs8IzmUt2W0q2dQP6a/FGD98UzbXsH//tpyHjvL+AoEWeuRI/1E6XPrb uaJg== X-Gm-Message-State: AOJu0YzxrIYHY/zQAJDc2lc/3Gsl5DlSGcBjEOQcqeX1ON5a0yZj2AAu A0bX/9J0M5XH46/efWMpHrBTSD31VWpoPQ== X-Google-Smtp-Source: AGHT+IFGcSS+/XjdVmoQS1tnDqiwMY73Ok/eEi3N9RLgn7yJV1nW0BMvbA+cNjcsMS1gHNXDUwdhvA== X-Received: by 2002:a05:600c:458d:b0:40d:5b7b:8f18 with SMTP id r13-20020a05600c458d00b0040d5b7b8f18mr2053627wmo.81.1704721728303; Mon, 08 Jan 2024 05:48:48 -0800 (PST) Received: from vingu-book.. ([2a01:e0a:f:6020:53aa:59bc:34ea:bb2c]) by smtp.gmail.com with ESMTPSA id n34-20020a05600c3ba200b0040d5b984668sm11165003wms.9.2024.01.08.05.48.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 05:48:47 -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 v3 1/5] cpufreq: Add a cpufreq pressure feedback for the scheduler Date: Mon, 8 Jan 2024 14:48:39 +0100 Message-Id: <20240108134843.429769-2-vincent.guittot@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240108134843.429769-1-vincent.guittot@linaro.org> References: <20240108134843.429769-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-20240108_054850_941559_477531F7 X-CRM114-Status: GOOD ( 14.97 ) 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 --- 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..fa2e2ea26f7f 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; + + /* + * Handle properly the boost frequencies, which should simply clean + * the thermal pressure value. + */ + if (max_freq <= capped_freq) { + pressure = 0; + } else { + cpu = cpumask_first(policy->related_cpus); + max_capacity = arch_scale_cpu_capacity(cpu); + capped_freq = policy->max; + max_freq = arch_scale_freq_ref(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