Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp4214348pxb; Tue, 10 Nov 2020 10:33:26 -0800 (PST) X-Google-Smtp-Source: ABdhPJw0TkdV90X/MDeuapJnQEc+1xxLnmn/xBBHJ80R2yxQWYe22goxsVOFZ0gRPTfVr95lCDn8 X-Received: by 2002:a50:ff06:: with SMTP id a6mr719215edu.295.1605033205969; Tue, 10 Nov 2020 10:33:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605033205; cv=none; d=google.com; s=arc-20160816; b=x8QAcsW9J8MsBKBVBXMGtPsdOGSDjBU2v/Luo1vBwhPSStILpcROerKt8T3ZJHeQV6 L+hychmts24EhuoYmHJIzrPsRRwJ/KGQaEu73H2QxUexDYvRdH3KjmkEwuafXb8honV/ cUzXvLN/awPNQ5z8CYkhmX2nPp4z1G8ZlreEnEUuFzUEx7UoYNlDs41bpp4AZFHvtv2h l5WD2SD0ku5cQ+/8iBg2SBYdFamXGkKF3q0x0J2PDgzfkEpuYsXkp+2FCw/pbd5zKmlf qAyJ1cPJEZT1oiLba+/42us3ZVMoFQ6gvttVe9GQqGMFkf1hzHlcN9/lyAbUs/tDOsJy 5mHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=0VnDz2H6D4pcru2r1FJy+lyxB0Zjb/oioBxbFMy+sIQ=; b=Wk4W/avENG6eOfrYJ45Dlb5T3Rl70b2gEyOzEL6Y+VeeznmBqw4n7z+O13wYvKqL1e Hl8ugbh6vzq4WQmdVIu1mWkPDqoBV2uaPXxmqCCS218DKsZJydRaxZwoFEQ/I0KPBjyZ +9utqKuBOII6W4oCLnNDBOkO2ZdcfpE4NM2I0SkUZZ+F3wjOUUWStu+b1rmyEgzFSbTV geDtDWu+cuEPLitqkX7OOef4CF9d29tS4LaNOmr2El9hCDW1CNTeyQE4BywrI6GsC9v2 280RbRP44lg1fsmXW19YlU/xp2eb6BYYlhxttsp3bWPGwZEUOJVYZtvc2Upglr2T6zgY rOKw== 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 u26si9548100ejc.609.2020.11.10.10.32.58; Tue, 10 Nov 2020 10:33:25 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731311AbgKJSbJ (ORCPT + 99 others); Tue, 10 Nov 2020 13:31:09 -0500 Received: from mx2.suse.de ([195.135.220.15]:34588 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730164AbgKJSbI (ORCPT ); Tue, 10 Nov 2020 13:31:08 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 8DCEAAC23; Tue, 10 Nov 2020 18:31:06 +0000 (UTC) From: Giovanni Gherdovich To: Borislav Petkov , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Len Brown , "Rafael J . Wysocki" Cc: Jon Grimm , Nathan Fontenot , Yazen Ghannam , Thomas Lendacky , Mel Gorman , Pu Wen , Viresh Kumar , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Doug Smythies , x86@kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, Nathan Fontenot , Giovanni Gherdovich Subject: [PATCH v2 1/3] x86, sched: Calculate frequency invariance for AMD systems Date: Tue, 10 Nov 2020 19:30:52 +0100 Message-Id: <20201110183054.15883-2-ggherdovich@suse.cz> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201110183054.15883-1-ggherdovich@suse.cz> References: <20201110183054.15883-1-ggherdovich@suse.cz> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Nathan Fontenot This is the first pass in creating the ability to calculate the frequency invariance on AMD systems. This approach uses the CPPC highest performance and nominal performance values that range from 0 - 255 instead of a high and base frquency. This is because we do not have the ability on AMD to get a highest frequency value. On AMD systems the highest performance and nominal performance vaues do correspond to the highest and base frequencies for the system so using them should produce an appropriate ratio but some tweaking is likely necessary. Due to CPPC being initialized later in boot than when the frequency invariant calculation is currently made, I had to create a callback from the CPPC init code to do the calculation after we have CPPC data. Signed-off-by: Nathan Fontenot [ ggherdovich@suse.cz: made safe under CPU hotplug ] Signed-off-by: Giovanni Gherdovich --- arch/x86/include/asm/topology.h | 8 ++++ arch/x86/kernel/smpboot.c | 81 +++++++++++++++++++++++++++++++-- drivers/acpi/cppc_acpi.c | 3 ++ 3 files changed, 87 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/topology.h b/arch/x86/include/asm/topology.h index f4234575f3fd..9799d4da282d 100644 --- a/arch/x86/include/asm/topology.h +++ b/arch/x86/include/asm/topology.h @@ -218,4 +218,12 @@ static inline void arch_set_max_freq_ratio(bool turbo_disabled) } #endif +#ifdef CONFIG_ACPI +void init_freq_invariance_cppc(void); +#else +static inline void init_freq_invariance_cppc(void) +{ +} +#endif + #endif /* _ASM_X86_TOPOLOGY_H */ diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index de776b2e6046..7077f44759b5 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -82,6 +82,10 @@ #include #include +#ifdef CONFIG_ACPI +#include +#endif + /* representing HT siblings of each logical CPU */ DEFINE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_sibling_map); EXPORT_PER_CPU_SYMBOL(cpu_sibling_map); @@ -148,7 +152,7 @@ static inline void smpboot_restore_warm_reset_vector(void) *((volatile u32 *)phys_to_virt(TRAMPOLINE_PHYS_LOW)) = 0; } -static void init_freq_invariance(bool secondary); +static void init_freq_invariance(bool secondary, bool cppc_ready); /* * Report back to the Boot Processor during boot time or to the caller processor @@ -186,7 +190,7 @@ static void smp_callin(void) */ set_cpu_sibling_map(raw_smp_processor_id()); - init_freq_invariance(true); + init_freq_invariance(true, false); /* * Get our bogomips. @@ -1340,7 +1344,7 @@ void __init native_smp_prepare_cpus(unsigned int max_cpus) set_sched_topology(x86_topology); set_cpu_sibling_map(0); - init_freq_invariance(false); + init_freq_invariance(false, false); smp_sanity_check(); switch (apic_intr_mode) { @@ -2027,6 +2031,46 @@ static bool intel_set_max_freq_ratio(void) return true; } +#ifdef CONFIG_ACPI +static bool amd_set_max_freq_ratio(void) +{ + struct cppc_perf_caps perf_caps; + u64 highest_perf, nominal_perf; + u64 perf_ratio; + int rc; + + rc = cppc_get_perf_caps(0, &perf_caps); + if (rc) { + pr_debug("Could not retrieve perf counters (%d)\n", rc); + 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) { + pr_debug("Non-zero highest/nominal perf values led to a 0 ratio\n"); + return false; + } + + arch_turbo_freq_ratio = perf_ratio; + arch_set_max_freq_ratio(false); + + return true; +} +#else +static bool amd_set_max_freq_ratio(void) +{ + return false; +} +#endif + static void init_counter_refs(void) { u64 aperf, mperf; @@ -2038,7 +2082,7 @@ static void init_counter_refs(void) this_cpu_write(arch_prev_mperf, mperf); } -static void init_freq_invariance(bool secondary) +static void init_freq_invariance(bool secondary, bool cppc_ready) { bool ret = false; @@ -2054,6 +2098,12 @@ static void init_freq_invariance(bool secondary) if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL) ret = intel_set_max_freq_ratio(); + else if (boot_cpu_data.x86_vendor == X86_VENDOR_AMD) { + if (!cppc_ready) { + return; + } + ret = amd_set_max_freq_ratio(); + } if (ret) { init_counter_refs(); @@ -2063,6 +2113,27 @@ static void init_freq_invariance(bool secondary) } } +#ifdef CONFIG_ACPI +static DEFINE_MUTEX(freq_invariance_lock); + +void init_freq_invariance_cppc(void) +{ + static bool freq_invariance_late; + + mutex_lock(&freq_invariance_lock); + + if (!freq_invariance_late) { + init_freq_invariance(false, true); + freq_invariance_late = true; + } + + mutex_unlock(&freq_invariance_lock); + + if (static_branch_likely(&arch_scale_freq_key)) + init_counter_refs(); +} +#endif + static void disable_freq_invariance_workfn(struct work_struct *work) { static_branch_disable(&arch_scale_freq_key); @@ -2112,7 +2183,7 @@ void arch_scale_freq_tick(void) schedule_work(&disable_freq_invariance_work); } #else -static inline void init_freq_invariance(bool secondary) +static inline void init_freq_invariance(bool secondary, bool cppc_ready) { } #endif /* CONFIG_X86_64 */ diff --git a/drivers/acpi/cppc_acpi.c b/drivers/acpi/cppc_acpi.c index 7a99b19bb893..368b13cb975d 100644 --- a/drivers/acpi/cppc_acpi.c +++ b/drivers/acpi/cppc_acpi.c @@ -39,6 +39,7 @@ #include #include #include +#include #include @@ -850,6 +851,8 @@ int acpi_cppc_processor_probe(struct acpi_processor *pr) goto out_free; } + init_freq_invariance_cppc(); + kfree(output.pointer); return 0; -- 2.26.2