Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp725298pxb; Tue, 2 Feb 2021 16:48:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJwD3ImNwrAIdZ+ah6hYAmMdx7hK4Rn9MilTrzR5bRKQx1Z5y5SDLILfUjtbL5oPnOuTqUmk X-Received: by 2002:a05:6402:b85:: with SMTP id cf5mr641078edb.368.1612313306616; Tue, 02 Feb 2021 16:48:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612313306; cv=none; d=google.com; s=arc-20160816; b=f6q9/iAYi5a0WWIu+okzR/aXsA0+Hh6C6Lg8UHq4qNdDcymty21tCi1cyKtiEfdFFl Sb3zuv1M0xvLwoM9gNYhem5OzIVIh7uJGH5zN7Dpfdu56K3P1Ixko4Gc3oXEDD7BoYiu x0le1Q/ryHaWZg+RX+fs6c84WdW97KRS4JZkv8WzH2B9KRtRm4HCy36erV3HRth4c+0q SG0FVewJmXmPGlRvVfDrN1v1zcID7xsh4CJ4u6CZGZdC6HG2oMU4jUjXacbyqKqhqm2P uEU5RULJ3bvzEw11LBNnMf/nMCBdV8eGCnuiLSRZ9/KQOT3uYsEJnD8SwCGUDEZsRpZz 38Rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version; bh=PL823AeoOnocWqbQIyVntk39u9KZJqQxqiL1WnA09Sg=; b=kRjoIaIiYAV3J5UlkQkxE6GjP8HKfzGSA/ljDFS5q6kAHLJc4WBfK5DgmEsCjHeIOL /iV2RcrINBPz7PboNpEhxgUrEIvYpEjmrNfxwvNjkuDJIvOdcdG/5bSUXInRZ0JZb0UU oSDhxb41OLtUBhfgHKlhwJRg+rFDTQCBMldRBgkidpwy/IfeEXX2w2G1uhaRVBVflYGr jcUIJZQ1qAApc53/PYZJCsJmfvkB9QFCBPJxAm8LYXdnTFJcuyZUv4pOl8o6PmJ4N+gK c59eLLN6GiRliktfmTYrhOU2YWZIshxihSjemhkVgM8+YuOQhCwq5uCWDybpdktt9jNc 5XGw== 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k17si304445ejg.72.2021.02.02.16.48.02; Tue, 02 Feb 2021 16:48:26 -0800 (PST) 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239518AbhBBTaN (ORCPT + 99 others); Tue, 2 Feb 2021 14:30:13 -0500 Received: from mail-oi1-f179.google.com ([209.85.167.179]:38687 "EHLO mail-oi1-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239702AbhBBT1J (ORCPT ); Tue, 2 Feb 2021 14:27:09 -0500 Received: by mail-oi1-f179.google.com with SMTP id h6so24015199oie.5; Tue, 02 Feb 2021 11:26:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=PL823AeoOnocWqbQIyVntk39u9KZJqQxqiL1WnA09Sg=; b=QAcIWKCaEmMVCuLUqeV/dcFlxAshI6uttm0bKMUpf9B0ruSi3HFE8dmfCLqzo2xr2C X5SlQvPiorTVGMVSlDmyXSTXsWD2PT+6N3apbZu44w5v4cGBFLhHhF0R75tD6xuSWcYn iSoXx++JJy8rIELObkqtBcKuuFcEcfNrtyEv4VEm50nxcC1nPAWucQZCTVpkfv2iuGyJ cw6dFTvna5qvA/7ZCaDHXg8s9IfMHfu/KJr3xZPmp87DY/h1M5hkBQMJixET+xCGmgkp 0gAY+ciewXpToYqTTI/Mo8hlR3cqefx7FYKzoVsRwWemI69Uhy/4ogiaiwELB45dC+rY ZHOQ== X-Gm-Message-State: AOAM530BnhddBR44tKMjXfV8I5Pecf6Wf3RE8/XOCjNS/73yhwMlLHlt jemlfuMn1F+ppAZ/LsmN72Ah5kZCGsEVQ6TNHfXiaZR8 X-Received: by 2002:aca:fc84:: with SMTP id a126mr3912900oii.71.1612293988009; Tue, 02 Feb 2021 11:26:28 -0800 (PST) MIME-Version: 1.0 References: <20210122204038.3238-1-ggherdovich@suse.cz> <20210122204038.3238-2-ggherdovich@suse.cz> In-Reply-To: From: "Rafael J. Wysocki" Date: Tue, 2 Feb 2021 20:26:16 +0100 Message-ID: Subject: Re: [PATCH v2 1/1] x86,sched: On AMD EPYC set freq_max = max_boost in schedutil invariant formula To: Giovanni Gherdovich Cc: Borislav Petkov , Ingo Molnar , Peter Zijlstra , "Rafael J . Wysocki" , Viresh Kumar , Jon Grimm , Nathan Fontenot , Yazen Ghannam , Thomas Lendacky , Suthikulpanit Suravee , Mel Gorman , Pu Wen , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Michael Larabel , "the arch/x86 maintainers" , Linux PM , Linux Kernel Mailing List , ACPI Devel Maling List Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Feb 2, 2021 at 7:59 PM Rafael J. Wysocki wrote: > > On Fri, Jan 22, 2021 at 9:47 PM Giovanni Gherdovich wrote: > > > > [cut] > > > > > Fixes: 41ea667227ba ("x86, sched: Calculate frequency invariance for AMD systems") > > Fixes: 976df7e5730e ("x86, sched: Use midpoint of max_boost and max_P for frequency invariance on AMD EPYC") > > Reported-by: Michael Larabel > > Signed-off-by: Giovanni Gherdovich > > --- > > drivers/cpufreq/acpi-cpufreq.c | 64 +++++++++++++++++++++++++++++++- > > drivers/cpufreq/cpufreq.c | 3 ++ > > include/linux/cpufreq.h | 5 +++ > > kernel/sched/cpufreq_schedutil.c | 8 +++- > > 4 files changed, 76 insertions(+), 4 deletions(-) > > > > diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c > > index 1e4fbb002a31..2378bc1bf2c4 100644 > > --- a/drivers/cpufreq/acpi-cpufreq.c > > +++ b/drivers/cpufreq/acpi-cpufreq.c > > @@ -27,6 +27,10 @@ > > > > #include > > > > +#ifdef CONFIG_ACPI_CPPC_LIB > > Why is the #ifdef needed here? > > > +#include > > +#endif > > + > > #include > > #include > > #include > > @@ -628,11 +632,57 @@ static int acpi_cpufreq_blacklist(struct cpuinfo_x86 *c) > > } > > #endif > > > > +#ifdef CONFIG_ACPI_CPPC_LIB > > +static bool amd_max_boost(unsigned int max_freq, > > + unsigned int *max_boost) > > +{ > > + struct cppc_perf_caps perf_caps; > > + u64 highest_perf, nominal_perf, perf_ratio; > > + int ret; > > + > > + ret = cppc_get_perf_caps(0, &perf_caps); > > + if (ret) { > > + pr_debug("Could not retrieve perf counters (%d)\n", ret); > > + return false; > > + } > > + > > + highest_perf = perf_caps.highest_perf; > > + nominal_perf = perf_caps.nominal_perf; > > + > > + if (!highest_perf || !nominal_perf) { > > + pr_debug("Could not retrieve highest or nominal performance\n"); > > + return false; > > + } > > + > > + perf_ratio = div_u64(highest_perf * SCHED_CAPACITY_SCALE, nominal_perf); > > + if (perf_ratio <= SCHED_CAPACITY_SCALE) { > > + pr_debug("Either perf_ratio is 0, or nominal >= highest performance\n"); > > + return false; > > + } > > + > > + *max_boost = max_freq * perf_ratio >> SCHED_CAPACITY_SHIFT; > > + if (!*max_boost) { > > + pr_debug("max_boost seems to be zero\n"); > > + return false; > > + } > > + > > + return true; > > +} > > +#else > > +static bool amd_max_boost(unsigned int max_freq, > > + unsigned int *max_boost) > > +{ > > + return false; > > +} > > +#endif > > + > > static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy) > > { > > unsigned int i; > > unsigned int valid_states = 0; > > unsigned int cpu = policy->cpu; > > + unsigned int freq, max_freq = 0; > > + unsigned int max_boost; > > struct acpi_cpufreq_data *data; > > unsigned int result = 0; > > struct cpuinfo_x86 *c = &cpu_data(policy->cpu); > > @@ -779,15 +829,25 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy) > > freq_table[valid_states-1].frequency / 1000) > > continue; > > > > + freq = perf->states[i].core_frequency * 1000; > > freq_table[valid_states].driver_data = i; > > - freq_table[valid_states].frequency = > > - perf->states[i].core_frequency * 1000; > > + freq_table[valid_states].frequency = freq; > > + > > + if (freq > max_freq) > > + max_freq = freq; > > + > > valid_states++; > > } > > freq_table[valid_states].frequency = CPUFREQ_TABLE_END; > > policy->freq_table = freq_table; > > perf->state = 0; > > > > + if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD && > > + amd_max_boost(max_freq, &max_boost)) { > > + policy->cpuinfo.max_boost = max_boost; > > Why not to set max_freq to max_boost instead? I mean, would setting the frequency in the last table entry to max_boost work? Alternatively, one more (artificial) entry with the frequency equal to max_boost could be added. > This value is set once at the init time anyway and schedutil would use > max_boost instead of max_freq anyway. > > Also notice that the static branch is global and the max_boost value > for different CPUs may be different, at least in theory. > > > + static_branch_enable(&cpufreq_amd_max_boost); > > + } > > + > > switch (perf->control_register.space_id) { > > case ACPI_ADR_SPACE_SYSTEM_IO: > > /* > > diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c > > index d0a3525ce27f..b96677f6b57e 100644 > > --- a/drivers/cpufreq/cpufreq.c > > +++ b/drivers/cpufreq/cpufreq.c > > @@ -2721,6 +2721,9 @@ int cpufreq_boost_enabled(void) > > } > > EXPORT_SYMBOL_GPL(cpufreq_boost_enabled); > > > > +DEFINE_STATIC_KEY_FALSE(cpufreq_amd_max_boost); > > +EXPORT_SYMBOL_GPL(cpufreq_amd_max_boost); > > + > > /********************************************************************* > > * REGISTER / UNREGISTER CPUFREQ DRIVER * > > *********************************************************************/ > > diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h > > index 9c8b7437b6cd..341cac76d254 100644 > > --- a/include/linux/cpufreq.h > > +++ b/include/linux/cpufreq.h > > @@ -40,9 +40,14 @@ enum cpufreq_table_sorting { > > CPUFREQ_TABLE_SORTED_DESCENDING > > }; > > > > +DECLARE_STATIC_KEY_FALSE(cpufreq_amd_max_boost); > > + > > +#define cpufreq_driver_has_max_boost() static_branch_unlikely(&cpufreq_amd_max_boost) > > + > > struct cpufreq_cpuinfo { > > unsigned int max_freq; > > unsigned int min_freq; > > + unsigned int max_boost; > > > > /* in 10^(-9) s = nanoseconds */ > > unsigned int transition_latency; > > diff --git a/kernel/sched/cpufreq_schedutil.c b/kernel/sched/cpufreq_schedutil.c > > index 6931f0cdeb80..541f3db3f576 100644 > > --- a/kernel/sched/cpufreq_schedutil.c > > +++ b/kernel/sched/cpufreq_schedutil.c > > @@ -159,8 +159,12 @@ static unsigned int get_next_freq(struct sugov_policy *sg_policy, > > unsigned long util, unsigned long max) > > { > > struct cpufreq_policy *policy = sg_policy->policy; > > - unsigned int freq = arch_scale_freq_invariant() ? > > - policy->cpuinfo.max_freq : policy->cur; > > + unsigned int freq, max_freq; > > + > > + max_freq = cpufreq_driver_has_max_boost() ? > > + policy->cpuinfo.max_boost : policy->cpuinfo.max_freq; > > + > > + freq = arch_scale_freq_invariant() ? max_freq : policy->cur; > > > > freq = map_util_freq(util, freq, max); > > > > -- > > 2.26.2 > >