Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp3194545lqp; Tue, 26 Mar 2024 02:17:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWSs7Z7gqhM6mrW4JLXKNQdbrg8scmpsxcgZk1ByKEpO/iCSZ74akDx3vgZ32g6tsBr4uJr7xFU7vb07FM/rEPn2U4EvsE+MKmX364bVQ== X-Google-Smtp-Source: AGHT+IFifjzezAxfgFyiVBkKwa5X+0kWB0IUX+c2nKSY+QjFNih3rgyuXw+v00qk/211uop6NJKs X-Received: by 2002:a17:906:278c:b0:a46:f564:ff80 with SMTP id j12-20020a170906278c00b00a46f564ff80mr5347374ejc.68.1711444626613; Tue, 26 Mar 2024 02:17:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711444626; cv=pass; d=google.com; s=arc-20160816; b=eQf+Xv7ZT5j7131dpKOEbRswP0hh1fiDoUbswrHHwd/fhj+12C3EU3WEs1I2d8jRB5 +zFi8DZwgSvl5vW0LtBMYU+h/8cIHopHbBNrVSBTC/+qcBKdZ9bYD05+dOoRBgM9PDF9 J2UTRSuM5s0IWIO+7iqkqlQWAW/X5X1HeLKN6k8zQCr5T6e6iLgRNSUgvkDr1Y8zHagN RxDCAbWzaC+cCg44SGGgPPGCO0nXjtkCPj86le25XoqP1oosU0OpEXfU89ExN7n7da5Z u7nKjAFsKtN9+lraXkyxIzt8qIG2ANxk9ZdUCKfh31/2rGt6xEOYr2rSPkhD3XejwXbO 8xiA== ARC-Message-Signature: i=2; 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=ncvV5tywoT0mg3neUWKgBj7OJB0wlJy/Q6vGL+2Nulc=; fh=kZZDhuIb7fjX2rWGoUzh/FDyjMoSb52XKFpomEU25/0=; b=b4gUMI5RwezjyaBSoQOBQ0TtVbkWkivekfuWIDIHj0S2npQ5K9ffZMAMw0j050gfuT iaoE/wlq3UkMTu64FzkvTPo0uow5fchhgRIk1Pkop+PgcKP3AZRK2HcjR9pwpvDK97cw GHfDRxTNxyPaweyUuHl1uYB+qm6YvXK4HA0duhdFOMzFe1NzmSrJlTrYrz7hyM80aRn/ +NXVtpDN5zRhYSaqe2TSt9rh/Rc5Qka/MCDho+fgvBhut8IBzVZJ+rYd5ZAof32FojSD 5WmkVzYdawFUw9ZX5lgH32aCCPuILlwrfSPupztggc+/W8tgt1yI+pSoxyknL0b+egMt yBmQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="gn/Uzx1A"; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-118626-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-118626-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id ch7-20020a170906c2c700b00a46bb8aed85si3299441ejb.168.2024.03.26.02.17.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Mar 2024 02:17:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-118626-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="gn/Uzx1A"; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-118626-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-118626-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 am.mirrors.kernel.org (Postfix) with ESMTPS id 6E6001F2EF72 for ; Tue, 26 Mar 2024 09:17:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8F7915C611; Tue, 26 Mar 2024 09:16:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="gn/Uzx1A" Received: from mail-wm1-f51.google.com (mail-wm1-f51.google.com [209.85.128.51]) (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 A3532524BA for ; Tue, 26 Mar 2024 09:16:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711444586; cv=none; b=a3t78HabxLydgMHnPjq5kzMiFaMzoUDCdrmsa08Po4DhSbkuHS9gwrpqdfsUTJOJfVAj1JFTOlCk2JJ9RmKCf7b6jJS14NkeE0T8gJtyU2sGIRN8AG+RgPsqLM4bQqnIGkadnDh/5TiBsMh1VfE/8BOBYgofELUvKzrsiHX+aAU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711444586; c=relaxed/simple; bh=i0D1IBTob5kwT5WOYydIpPSm6Qn958At0dw1K+wykiA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Mv6JnnT4w2AJYY6Rxf3H8DwusBD/3xyoc0ldzMIpQ7vF5nkgsRCVuID7QInreOpqwpECZspHopzI/vIzsg+R9M//JV6FnoaYhYFLFN5f5NIzRNX/uKd3AQxS1P6CD4U6H7SjOLoah3qRS1T18O8zSM9tfWIAGt196eR8WZUAFEY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=gn/Uzx1A; arc=none smtp.client-ip=209.85.128.51 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-f51.google.com with SMTP id 5b1f17b1804b1-4148e14799eso3068325e9.0 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=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=ncvV5tywoT0mg3neUWKgBj7OJB0wlJy/Q6vGL+2Nulc=; b=gn/Uzx1A5rgMPv6Q6DO7Y60IVaP9G3O6xu+nTm+tnQ+hZH7H4TIx3owHMAHzg4Xf75 CTNn9GF6zOWkCYN5tCLHVxrlg9fCupduA7tmx227j+JhDv1UfbKTtuOvBj8/JB90oN5N Y1MBklc60qwxAaJ1Pu61a4fZX+x0hIuKwjH6dlZ+zRrCffMIUfl5FIeYpOAb6ScXN+xa mo6+WYiYVn0YAHlYhBAQwTnIh8lmAdJSUIo7DfunoD7NY14RotT/lI8WESpTgONBNF0d PA3spoITe3q0t5WNhYcoBhXwlfNRnRfWHhFNUSZm9BlePQe2k+BPtlCY8n5Ds+r4Edv2 8E1Q== 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=lXkhaEHsK2WY0AsQNVfnOlPP9IrCbVebkQTzN4YCMQmQ/4c7fFHldHzajxFV3wCf3R WUGcx6TG7lI/1Hr5KDxjjQgQLrEs9yVS7JVx+rxgIqEOKbws3D23fw9+jHATmhhyEmZL AnjJRYAjr9RXvaxyPeXAcR4F0/PG0A+blLNBayx5F4uSa5WTNO+F7ZiwU4y8m+g/9QPD YB6J0Lsw+NCrHyot5PsTA4zHilj6qU8YgdaOCnl619ddsKl+HyRgFvlbwNJUWDkdsvA7 IdCIxVlX5BCGP/nEIJkFcvTWtMgpUDIhuhc6o4t1YHonfiCZsBmAwbyVtrhjAI6nCp20 x6nw== X-Forwarded-Encrypted: i=1; AJvYcCW9qV241mO8ns04Smb0GmBk5qrHgvXrwC9ilcClFRN8z8ysFtASfvChuTX+/VUSZJcSU0PVMLQRObFtLMQmU8abCq0jJi8DbngqaQR1 X-Gm-Message-State: AOJu0YyVqWf66iwueeiuXB2cr2wbpMjWK3AiKwaJQvDGn4lHsqaMjL/c gUVDtlTBFD2d8FZcRSEq7XWdVYTA1aMZInVxIoGwUlxOUT9PFdWzsId68F3+B0E= 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> 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 Acked-by: Rafael J. Wysocki Acked-by: Viresh Kumar Reviewed-by: Qais Yousef Reviewed-by: Lukasz Luba Tested-by: Lukasz Luba --- 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 -- 2.34.1