Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp367003ybh; Wed, 22 Jul 2020 02:40:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZrDqYjE0DKUe2ARwI0rt/uDlqladuotGRQAt2tCeByOCONaUr2ndYc+4HhknbYzy2t4// X-Received: by 2002:a17:906:4341:: with SMTP id z1mr28552816ejm.392.1595410831012; Wed, 22 Jul 2020 02:40:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595410831; cv=none; d=google.com; s=arc-20160816; b=Wk7vtU1qgXId9TNpvCQl7yxRZWTBpwRfMDTDIfAEiyBATfjYGw4SDC/SlmD54hFSnZ npWQFaj0JzYOIOGrebqOfDmUg8Ueu84+nlyxQ097m/jt03W/9JRRpidWzbbmzU/H6GSW YFCMCGBFZrXTDMC6zTgYYqWtgf9BlLHQFU+08OJjKo7NDSjc6AHBmq5PpSOQm9st9ehI WRSIrqp49LkRAE2Nt5LsCfDXTj3KAX71/G++GWf7KivQ3hFSRZSALkx83J/7yjoV5h/W BhtL+7KX/U37pkZ8lh6Ib+OrWV96jxPfaxMTtZyaRGytx+er4bbSwmImxZB0AaUOEsHe sXoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=wvTbVH8D68scx3YjKma2bffksW6gYydObhw2bB+cTDc=; b=YEpD924y3wSObB3pH3QyRdXUxYCHGaX3X/kGx9DKCLrMW3xVT9UGACHf1ExD3IHXje iHkjNn8eWdZZ5dKYcPDiHoTLBoR5bumLZ4m4oISjYhoXv6rMQXQKShZPkcQZRxyIsEFe yiW8XQQ0YH3iW4otm/2+x2dVjKvIHLYXSc/p0hq+vK0iREuXp/bijwro76FAeaAZ0b11 ZNkYG9J4A8Cpc/kFja1WRQwI9nQZ/EcuBtmc4RWpH8BVKvl5cdE+xI0vddgRc41XU8ct 5j9aTIy9CqV8tRoGMlvEzQcHbpms6WVAHNtmHKjmc8uwRPNyIOMKoUKkxXekdihGQLlp fGOg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y19si13908027ejw.454.2020.07.22.02.40.08; Wed, 22 Jul 2020 02:40:30 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731717AbgGVJiw (ORCPT + 99 others); Wed, 22 Jul 2020 05:38:52 -0400 Received: from foss.arm.com ([217.140.110.172]:53094 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726147AbgGVJiv (ORCPT ); Wed, 22 Jul 2020 05:38:51 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D45E0101E; Wed, 22 Jul 2020 02:38:50 -0700 (PDT) Received: from e108754-lin.cambridge.arm.com (unknown [10.1.198.53]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 1A1B73F66F; Wed, 22 Jul 2020 02:38:48 -0700 (PDT) From: Ionela Voinescu To: rjw@rjwysocki.net, viresh.kumar@linaro.org, dietmar.eggemann@arm.com, catalin.marinas@arm.com, sudeep.holla@arm.com, will@kernel.org, linux@armlinux.org.uk Cc: mingo@redhat.com, peterz@infradead.org, linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, ionela.voinescu@arm.com, Valentin Schneider Subject: [PATCH v2 6/7] arch_topology,arm,arm64: define arch_scale_freq_invariant() Date: Wed, 22 Jul 2020 10:37:31 +0100 Message-Id: <20200722093732.14297-7-ionela.voinescu@arm.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200722093732.14297-1-ionela.voinescu@arm.com> References: <20200722093732.14297-1-ionela.voinescu@arm.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Valentin Schneider arch_scale_freq_invariant() is used by schedutil to determine whether the scheduler's load-tracking signals are frequency invariant. Its definition is overridable, though by default it is hardcoded to 'true' if arch_scale_freq_capacity() is defined ('false' otherwise). This behaviour is not overridden on arm, arm64 and other users of the generic arch topology driver, which is somewhat precarious: arch_scale_freq_capacity() will always be defined, yet not all cpufreq drivers are guaranteed to drive the frequency invariance scale factor setting. In other words, the load-tracking signals may very well *not* be frequency invariant. Now that cpufreq can be queried on whether the current driver is driving the Frequency Invariance (FI) scale setting, the current situation can be improved. This combines the query of whether cpufreq supports the setting of the frequency scale factor, with whether all online CPUs are counter-based FI enabled. While cpufreq FI enablement applies at system level, for all CPUs, counter-based FI support could also be used for only a subset of CPUs to set the invariance scale factor. Therefore, if cpufreq-based FI support is present, we consider the system to be invariant. If missing, we require all online CPUs to be counter-based FI enabled in order for the full system to be considered invariant. If the system ends up not being invariant, a new condition is needed in the counter initialization code that disables all scale factor setting based on counters. Precedence of counters over cpufreq use is not important here. The invariant status is only given to the system if all CPUs have at least one method of setting the frequency scale factor. Signed-off-by: Valentin Schneider Signed-off-by: Ionela Voinescu Cc: Catalin Marinas Cc: Will Deacon Cc: Sudeep Holla --- arch/arm/include/asm/topology.h | 1 + arch/arm64/include/asm/topology.h | 1 + arch/arm64/kernel/topology.c | 7 +++++++ drivers/base/arch_topology.c | 6 ++++++ include/linux/arch_topology.h | 2 ++ 5 files changed, 17 insertions(+) diff --git a/arch/arm/include/asm/topology.h b/arch/arm/include/asm/topology.h index 435aba289fc5..d59458e97c6d 100644 --- a/arch/arm/include/asm/topology.h +++ b/arch/arm/include/asm/topology.h @@ -9,6 +9,7 @@ /* Replace task scheduler's default frequency-invariant accounting */ #define arch_scale_freq_capacity topology_get_freq_scale +#define arch_scale_freq_invariant topology_scale_freq_invariant /* Replace task scheduler's default cpu-invariant accounting */ #define arch_scale_cpu_capacity topology_get_cpu_scale diff --git a/arch/arm64/include/asm/topology.h b/arch/arm64/include/asm/topology.h index 0cc835ddfcd1..b67081c0dcfb 100644 --- a/arch/arm64/include/asm/topology.h +++ b/arch/arm64/include/asm/topology.h @@ -27,6 +27,7 @@ void topology_scale_freq_tick(void); /* Replace task scheduler's default frequency-invariant accounting */ #define arch_scale_freq_capacity topology_get_freq_scale +#define arch_scale_freq_invariant topology_scale_freq_invariant /* Replace task scheduler's default cpu-invariant accounting */ #define arch_scale_cpu_capacity topology_get_cpu_scale diff --git a/arch/arm64/kernel/topology.c b/arch/arm64/kernel/topology.c index 9a9f2b8dedf5..4064d39bb66d 100644 --- a/arch/arm64/kernel/topology.c +++ b/arch/arm64/kernel/topology.c @@ -246,6 +246,13 @@ static int __init init_amu_fie(void) static_branch_enable(&amu_fie_key); } + /* + * If the system is not fully invariant after AMU init, disable + * partial use of counters for frequency invariance. + */ + if (!topology_scale_freq_invariant()) + static_branch_disable(&amu_fie_key); + free_valid_mask: free_cpumask_var(valid_cpus); diff --git a/drivers/base/arch_topology.c b/drivers/base/arch_topology.c index 3ad59e38f3f3..30b67bb820c5 100644 --- a/drivers/base/arch_topology.c +++ b/drivers/base/arch_topology.c @@ -21,6 +21,12 @@ #include #include +bool topology_scale_freq_invariant(void) +{ + return cpufreq_sets_freq_scale() || + arch_freq_counters_available(cpu_online_mask); +} + __weak bool arch_freq_counters_available(const struct cpumask *cpus) { return false; diff --git a/include/linux/arch_topology.h b/include/linux/arch_topology.h index 4be0315700cb..5bc55cfc9399 100644 --- a/include/linux/arch_topology.h +++ b/include/linux/arch_topology.h @@ -30,6 +30,8 @@ static inline unsigned long topology_get_freq_scale(int cpu) return per_cpu(freq_scale, cpu); } +bool topology_scale_freq_invariant(void); + bool arch_freq_counters_available(const struct cpumask *cpus); DECLARE_PER_CPU(unsigned long, thermal_pressure); -- 2.17.1