From patchwork Thu Dec 21 15:24:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vincent Guittot X-Patchwork-Id: 13502269 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 37DD5C35274 for ; Thu, 21 Dec 2023 15:24:43 +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=jsJBBits47BvhWPXT09RHjfH/fMMe7TLKpZKHPPsFDc=; b=xxuBO0IKiyRDZ9 2w8k32HFED3f01pyEijGHqF/gl+X/8N2hdrRgPGiU6WCPkX07ZG+LYj9H0NcGd1LD5Wg6kaQ1Cse/ BWIeHDFOA3RO2+1C3QcJPz6tX92y7zRkNZAwMYit92C41W9X039GTfQo+9sv6W80SbtYSBgwhL8Fg h6D9N71zlTLgfrMAxxPcZU6am+trKutULZdkNIMBMs49N7T1kY66OFNEe08Ae778NyYyc11S4A0/x MwY926GCpjzbEv+/OaucqWK+VX71kj3YYEihfZJglvLkRbJSJJHSM+mhk8KmfvUrXen/CWKvtRfMG 72xKf3k9Bphd0V6X75bQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rGKuI-003Jy1-0C; Thu, 21 Dec 2023 15:24:18 +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 1rGKuE-003Ju8-2L for linux-arm-kernel@lists.infradead.org; Thu, 21 Dec 2023 15:24:16 +0000 Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-40d3ae326f6so9310455e9.3 for ; Thu, 21 Dec 2023 07:24:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1703172252; x=1703777052; 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=v/J6RB2Lw/HQZsxNLlML+TfeS0CELCbuPUL4YNRnsW4=; b=gILUfOf65+kYrqdQZIcFIAMuhf71NrlofM2yZLWTBOZixfq00kE+SQWhsYsHhYkbwY wPjMidGqpmcPjtp28gPYQYEDiRVhfxN5oXXkQPyNzcqE6VkwBMHB3SBNlshMElF+h1UY JPjKX7IHDe5KH+/v9P20uZbEhDtcC6UK1BebkVDaZLBcZ8WyVprnSD89nXjcORQ1wwWv WZH05iR/2H58ERTv9n/UlM81yo4/Z0lXBGNLeWXjTjfQsq9iIZ7RQ32LrOBzuWeF67jb HNnjWHccsQmSb9p6F2134VyRffyZyiUW7dSPmpM0l72CkJ8bKj3qIpwLg0K49dtLuAzh tFMQ== 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=DMItl/uJCid27DZTQZj8vbhsUNm5x9e8WbAoJ2rOXkYJWo0vy46ekRLa+eON1bj3lh M2/H+MsZPZjs2ULSUbDQd+2fZ8XaXYz404kp5FYz1Xuz6yD9uiAXUqaG4tqwo5ddmTKZ rDQxZD6hNTXEE6nSpN+uIo4rdmB3PPEQEBwNFQirOIdvhx0NqOgmILC/hOujyGh5krVx 0g9ioPUpWtCflFCfeqzNqnfyfqJLhZCn/BbtJ/LC8mZIpedOcqujh4B2ET682YVTWLWN gJwWev2PWY6EROPsX8sf4MaVhZGc80dPszogTS0oWgv4XcbRuGDj+h3ANayLxD9Oj68v WIBQ== X-Gm-Message-State: AOJu0YxQjl7oIADgc4Oun0tBTNhE0szrmdwrrlJZ/+a5Gxoj5C9qQelv nkcPXkevo6Q03UPt5fYOhM2CYg== X-Google-Smtp-Source: AGHT+IGfndV/3k6rdSSpdIesuC+ma43H3wDHyNoKIqhnNKmVdHkXbh2v619WcJ8xmuQj7PY/A9xp4g== 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> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231221_072414_763368_CF566014 X-CRM114-Status: GOOD ( 14.37 ) 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 --- 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