Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp648569ybz; Fri, 1 May 2020 06:09:30 -0700 (PDT) X-Google-Smtp-Source: APiQypJupU6XEDdf7p8zobbek8yjTaa9YDpxV+SQB3aAd3F/s/hGB+qPF/EaXVkX3SqwCI5TeYFG X-Received: by 2002:a17:906:315a:: with SMTP id e26mr3062403eje.53.1588338570628; Fri, 01 May 2020 06:09:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588338570; cv=none; d=google.com; s=arc-20160816; b=HoF2PEuSwiBP6AoYlOyM/Km2PesN3+WVTMHsyj7F01KCcGBlZNN0BP659mO80sJam+ UFWXYLp1gOBp/zBuRyy9udhwmMU4kL07zdiGAR1WqRqiScFWjO1m44CLkYuO53FNdT8B mSR1FEOtZBN+Uxh4IB1YlQfoNUBol8aGfJXLXFhZqA7N6VRJTEqri8Zd8z1KveiNEUAh riQ1UfsJF7F3ZdwmoRjDDnPStnIuFL2KEg0wRJCCjm4/DRtbxCJbRX5BQ7TBqEBJr1aw M2ZvGh243adZ4qLNW1B03b0CjIoUbqG6up0FZ8lCSlX0vgnlbXEMKJOmrQ058RsJv0uI Q1tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=xMXWVTc7R+JhjJn+KS3GnD4/0ygZbQWbKw26aELhegA=; b=Th4B/qbil92XVAaVQPu57C9Ofos6hLZ4wNDZ4t/5teiy63TEcMruyDmmW+CPY6eHZW OHa2vCdXpjsQ7Z6Wn6W0A/ddAbKTovUDfiqmq+ZIS6KyasBXRNWRsZNTyZlM59CnXYXg hB7nmeGxgpoJsNHO8MYKQq0n6u0cpkKkRy6rXUCibFb8hrp8He9c12hYoVCDeSN3rS37 /10Q1YXIhPWddB8mKSP3RnV7xPBF9eePtq2dF9bE8Ehr2ZHhntG4HaL3wFO0YChrPqAk tFHiAxLTSLalMjUr9cAA7djHRXrC99KwexB87xB3M/ruB+zYnUhwdsphQjn/tAqlRLTs rHLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=mwwUk7GE; 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 x21si1942092edv.235.2020.05.01.06.09.06; Fri, 01 May 2020 06:09: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; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=mwwUk7GE; 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 S1728800AbgEANE7 (ORCPT + 99 others); Fri, 1 May 2020 09:04:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1728586AbgEANE7 (ORCPT ); Fri, 1 May 2020 09:04:59 -0400 Received: from merlin.infradead.org (unknown [IPv6:2001:8b0:10b:1231::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2E548C061A0C; Fri, 1 May 2020 06:04:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=xMXWVTc7R+JhjJn+KS3GnD4/0ygZbQWbKw26aELhegA=; b=mwwUk7GEE0TAQBUF24oh02jytD A/0jaT8TH802Az+IjxVBaIJACdmBGYq1cpDWwDS/KIUn74i+TSzJQAulkfC53sOKU39ZUqByGQnLM vZOQXNgzoFaWGWAHIcCrPvXVYx1zxk4l9QEKY4sYcbv9xRtkF7RgKIzB9GdzWCmj3lNp25btDyYiC JdkcxKHIA5PSHfJT9o/Cqt7YXx3axn/K5QG+MsNoSNAs7CacKtP2cVXMGyrIfg1YThAglejnc+STn iUZPuR6yxkuXNlQnECo5YCKYSF/1+6pf0vzNvJJLImpNHoyyjYawgb8jkN5ZageFpIx2cj4pWcdxH 4V+yWoTw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jUVLB-000510-PD; Fri, 01 May 2020 13:04:29 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id E35BE300F28; Fri, 1 May 2020 15:04:27 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id CA54529A7943E; Fri, 1 May 2020 15:04:27 +0200 (CEST) Date: Fri, 1 May 2020 15:04:27 +0200 From: Peter Zijlstra To: Giovanni Gherdovich 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 Subject: Re: [PATCH 2/2] x86, sched: Bail out of frequency invariance if turbo frequency is unknown Message-ID: <20200501130427.GD3762@hirez.programming.kicks-ass.net> References: <20200428132450.24901-1-ggherdovich@suse.cz> <20200428132450.24901-3-ggherdovich@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200428132450.24901-3-ggherdovich@suse.cz> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. --- 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; }