Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp1771912ybz; Sat, 2 May 2020 07:28:19 -0700 (PDT) X-Google-Smtp-Source: APiQypKgkg+uHKKzMjfcSSyGWhb/5vxC3zpIzFrcu7NcuSvG25DEkdJQ4SWhN+CqU6qK96nTyQnb X-Received: by 2002:a05:6402:d0a:: with SMTP id eb10mr7530802edb.60.1588429699234; Sat, 02 May 2020 07:28:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588429699; cv=none; d=google.com; s=arc-20160816; b=zZU70jVUhy1LBIgKHFFz82XnM4VTm8PAUz/Yj9W6QJvAniIDmquP+VJDV7zMskwA0M biGr3EoeMxHWAxJfxsfEYjGNSq0OeCeI4Z4IcxWwW62zLeECP+09Fjmv9QY5R7Ap7TGg z1zgNgnLzBQr83s+vadKVMXUEiZR+49HUNdpUKrphrsHSH7iWvEc3iDumaIj80e8r01n sKgr0IJyXUL8lRBOduNMSYwF3ZOxnUbKltVsqQBE1R8WgbP7vJydBoZeiUMcXjlGlNNr gRFt2X+GVqfHOkAo2HYi0fy6UG9vG51K9HcOYwZeOAmTOIGPLplLIbfwDJdzq0WpOES2 9S/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id; bh=TN4hl6JQNRo/SBPJ1zUwEZHiMMoUFZ9g8SU3slRhuhk=; b=xdxkKerZR6yawCtIqMDrIzZPhrQ97xkLa+FchpDA/2eSMgpG2h5eGy5faWcZtg9g+x PyVdt+cTGn+9+NxxNMdAQOnSYJ9HMYjpNtjTe54S8bixO53lpFSFq6tC5yDCPI/eay4p re0rPP7D0FGWKn+ZtcjFZeoLNhUtzcIxvXa+mF8vZGNUsufZ3DiEDOsTMUHVm+xwiRxw Ms0isPV3W/PSlx8hjEGasPwK+55LfxM+9+cwoBDoT3CyuI9TjVC1n+mBeF9cyrHejQQD fivDcMYmXsvh2fj5YXqS0KWUtptxqX7M4Jf4hJ7FSn7nDp9v3wSGznZpmC1we/cPAeTj 2D6Q== 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 x5si3659562edr.583.2020.05.02.07.27.56; Sat, 02 May 2020 07:28:19 -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 S1728105AbgEBO02 (ORCPT + 99 others); Sat, 2 May 2020 10:26:28 -0400 Received: from mx2.suse.de ([195.135.220.15]:34224 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728020AbgEBO02 (ORCPT ); Sat, 2 May 2020 10:26:28 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id D010BB019; Sat, 2 May 2020 14:26:26 +0000 (UTC) Message-ID: <1588429584.8505.31.camel@suse.cz> Subject: Re: [PATCH 2/2] x86, sched: Bail out of frequency invariance if turbo frequency is unknown From: Giovanni Gherdovich To: Peter Zijlstra Cc: Srinivas Pandruvada , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Len Brown , "Rafael J . Wysocki" , x86@kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Neri , Linus Torvalds Date: Sat, 02 May 2020 16:26:24 +0200 In-Reply-To: <20200501130427.GD3762@hirez.programming.kicks-ass.net> References: <20200428132450.24901-1-ggherdovich@suse.cz> <20200428132450.24901-3-ggherdovich@suse.cz> <20200501130427.GD3762@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.26.6 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2020-05-01 at 15:04 +0200, Peter Zijlstra wrote: > On Tue, Apr 28, 2020 at 03:24:50PM +0200, Giovanni Gherdovich wrote: > > There may be CPUs that support turbo boost but don't declare any turbo > > ratio, i.e. their MSR_TURBO_RATIO_LIMIT is all zeroes. In that condition > > scale-invariant calculations can't be performed. > > > > Signed-off-by: Giovanni Gherdovich > > Suggested-by: Ricardo Neri > > Fixes: 1567c3e3467c ("x86, sched: Add support for frequency invariance") > > --- > > arch/x86/kernel/smpboot.c | 6 ++++-- > > 1 file changed, 4 insertions(+), 2 deletions(-) > > > > diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c > > index 4718f29a3065..ab2a0df7d1fb 100644 > > --- a/arch/x86/kernel/smpboot.c > > +++ b/arch/x86/kernel/smpboot.c > > @@ -1991,9 +1991,11 @@ static bool intel_set_max_freq_ratio(void) > > /* > > * Some hypervisors advertise X86_FEATURE_APERFMPERF > > * but then fill all MSR's with zeroes. > > + * Some CPUs have turbo boost but don't declare any turbo ratio > > + * in MSR_TURBO_RATIO_LIMIT. > > */ > > - if (!base_freq) { > > - pr_debug("Couldn't determine cpu base frequency, necessary for scale-invariant accounting.\n"); > > + if (!base_freq || !turbo_freq) { > > + pr_debug("Couldn't determine cpu base or turbo frequency, necessary for scale-invariant accounting.\n"); > > return false; > > } > > I've added the below, imagine base_freq > turbo_freq * > SCHED_CAPACITY_SCALE. Right, I didn't consider that case. It doesn't hurt to be defensive. I understand you've already edited the patches in your tree, so I am not resending, just confirming my Signed-off-by: Giovanni Gherdovich > > --- a/arch/x86/kernel/smpboot.c > +++ b/arch/x86/kernel/smpboot.c > @@ -1975,6 +1975,7 @@ static bool core_set_max_freq_ratio(u64 > static bool intel_set_max_freq_ratio(void) > { > u64 base_freq, turbo_freq; > + u64 turbo_ratio; > > if (slv_set_max_freq_ratio(&base_freq, &turbo_freq)) > goto out; > @@ -2008,9 +2009,15 @@ static bool intel_set_max_freq_ratio(voi > return false; > } > > - arch_turbo_freq_ratio = div_u64(turbo_freq * SCHED_CAPACITY_SCALE, > - base_freq); > + turbo_ratio = div_u64(turbo_freq * SCHED_CAPACITY_SCALE, base_freq); > + if (!turbo_ratio) { > + pr_debug("Non-zero turbo and base frequencies led to a 0 ratio.\n"); > + return false; > + } > + > + arch_turbo_freq_ratio = turbo_ratio; > arch_set_max_freq_ratio(turbo_disabled()); > + > return true; > } >