Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp2022408ybc; Wed, 13 Nov 2019 07:52:43 -0800 (PST) X-Google-Smtp-Source: APXvYqwc4NTiNKAy+oOfCkYckzrQcgz8S3j6IUrXGxIKVfC+WnWpYGx/G+F0y4pTwKbRGSrq9wlz X-Received: by 2002:a17:906:4913:: with SMTP id b19mr3346019ejq.61.1573660363070; Wed, 13 Nov 2019 07:52:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573660363; cv=none; d=google.com; s=arc-20160816; b=Lqfa6fdX7Nt3CAha8tCN+dzjRlA08FUs9Tr2vsketCfp02yalC+1ByZ/8aXYE9hYda CvHW8ockCMlv56jkrUYOcY0wNVUPRsaC1zgJMz6A4R5SPWYwhNt8Rc86nOVsRRyz+Wo6 iGGc9Fq+P9evraVLAZmtwH1USPLb09Jth7Tlxs4XROmkMfKMeeWLVZPDM/Fe2XV4YjLZ hEGi4sYokNXnwmt1ud/VEW1UxXZ+QudZ4XE5AP+PfQtiMhxC7mzPjf4gnEjRDuI2HR1q IN4N8HFcvd7Mt2CPYmFrTLPXlFts/bFwnNguhiWGdDYzyP1x+gzANY67yfo+gsWyV4zm mvXQ== 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=hgJkOzFRSpx9WJgaRo3G9xinXZd4d5GNW9jahtJ0bzM=; b=yRfN8/lMVDAsgnwPT57OddGr1LtmjYzQTuKh5ITy5CyR2mo0NTLaERvOKMKZeZPTZt VV565zFfbn41nGINNuk6Ssrm3Fwcnwej8k/F3WpKcaORMyZPICycdTK37nw/QHppCkBy VxLoQnc+IXoM/EmhTnZdyoP3svs51pjr9sCPNKBozpnyMpAwHbn62tBBzo/bBAnmEohg b4GQ3KhDPEH34y6VWhc5f7I8RTgErtIHXKb7nM8sz16Ufacjz+mWFyUGQPTAFvycHHOT NVw/DcXuhOSMyc6LDTSQj/iBKgbw/Tjo+CYP9NPR9z7jVgdISdKYvaPxtxynA4acLA2C jE8A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id jx9si1340618ejb.32.2019.11.13.07.52.19; Wed, 13 Nov 2019 07:52:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727239AbfKMMlW (ORCPT + 99 others); Wed, 13 Nov 2019 07:41:22 -0500 Received: from mx2.suse.de ([195.135.220.15]:39278 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727097AbfKMMlV (ORCPT ); Wed, 13 Nov 2019 07:41:21 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 2CDD3B555; Wed, 13 Nov 2019 12:41:19 +0000 (UTC) From: Giovanni Gherdovich To: Srinivas Pandruvada , Thomas Gleixner , Ingo Molnar , Peter Zijlstra , Borislav Petkov , Len Brown , "Rafael J . Wysocki" Cc: x86@kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Mel Gorman , Matt Fleming , Viresh Kumar , Juri Lelli , Paul Turner , Vincent Guittot , Quentin Perret , Dietmar Eggemann , Doug Smythies , Giovanni Gherdovich Subject: [PATCH v4 4/6] x86,sched: Add support for frequency invariance on ATOM_GOLDMONT* Date: Wed, 13 Nov 2019 13:46:52 +0100 Message-Id: <20191113124654.18122-5-ggherdovich@suse.cz> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20191113124654.18122-1-ggherdovich@suse.cz> References: <20191113124654.18122-1-ggherdovich@suse.cz> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The scheduler needs the ratio freq_curr/freq_max for frequency-invariant accounting. On GOLDMONT (aka Apollo Lake), GOLDMONT_D (aka Denverton) and GOLDMONT_PLUS CPUs (aka Gemini Lake) set freq_max to the highest frequency reported by the CPU. The encoding of turbo ratios for GOLDMONT* is identical to the one for SKYLAKE_X, but we treat the Atom case apart because we want to set freq_max to a higher value, thus the ratio freq_curr/freq_max to be lower, leading to more conservative frequency selections (favoring power efficiency). Signed-off-by: Giovanni Gherdovich --- arch/x86/kernel/smpboot.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c index 0e79dcc03ae4..4d192abf337d 100644 --- a/arch/x86/kernel/smpboot.c +++ b/arch/x86/kernel/smpboot.c @@ -1795,6 +1795,10 @@ void native_play_dead(void) * which would ignore the entire turbo range (a conspicuous part, making * freq_curr/freq_max always maxed out). * + * An exception to the heuristic above is the Atom uarch, where we choose the + * highest turbo level for freq_max since Atom's are generally oriented towards + * power efficiency. + * * Setting freq_max to anything less than the 1C turbo ratio makes the ratio * freq_curr / freq_max to eventually grow >1, in which case we clip it to 1. */ @@ -1841,6 +1845,27 @@ static const struct x86_cpu_id has_glm_turbo_ratio_limits[] = { {} }; +static bool glm_set_cpu_max_freq(u64 *ratio, u64 *turbo_ratio) +{ + int err; + + if (!x86_match_cpu(has_glm_turbo_ratio_limits)) + return false; + + err = rdmsrl_safe(MSR_PLATFORM_INFO, ratio); + if (err) + return false; + + err = rdmsrl_safe(MSR_TURBO_RATIO_LIMIT, turbo_ratio); + if (err) + return false; + + *ratio = (*ratio >> 8) & 0xFF; /* max P state ratio */ + *turbo_ratio = *turbo_ratio & 0xFF; /* highest turbo ratio */ + + return true; +} + static int get_knl_turbo_ratio(u64 *turbo_ratio) { u64 msr; @@ -1962,7 +1987,6 @@ static void intel_set_cpu_max_freq(void) /* * TODO: add support for: * - * - Atom Goldmont * - Atom Silvermont * * which all now get by default arch_max_freq = SCHED_CAPACITY_SCALE @@ -1970,10 +1994,12 @@ static void intel_set_cpu_max_freq(void) u64 ratio = 1, turbo_ratio = 1; - if (turbo_disabled() || - x86_match_cpu(has_glm_turbo_ratio_limits)) + if (turbo_disabled()) return; + if (glm_set_cpu_max_freq(&ratio, &turbo_ratio)) + goto set_value; + if (knl_set_cpu_max_freq(&ratio, &turbo_ratio)) goto set_value; -- 2.16.4