Received: by 2002:ac0:950c:0:0:0:0:0 with SMTP id f12csp2798044imc; Wed, 13 Mar 2019 01:21:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqxjF1g4HPFyz5hU8qJdN/wYTtMPNrvZ/EgcYhMVPNPIbRaQBSBeKA1aitQPegh9eQYJyueA X-Received: by 2002:a65:6108:: with SMTP id z8mr23372246pgu.188.1552465278756; Wed, 13 Mar 2019 01:21:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1552465278; cv=none; d=google.com; s=arc-20160816; b=DT7cC7drvBPFzGmcufLv3Twt679ZMqa+ONAtp6VD3OjM+RMSHShQ26uPODstut1j0k 5oqpcMrPZ+vqfKKyqewJzJ6JBy7ORWgPhtB5MCoHewg8t5ZeueiiNNdLARQesYoHL7hm 80EIQUhdKvIuY4V5q7zBYpMs99XxSj9Fv7qF/0mjqXNmhNYKSMQZbY1R6w1bOz6RweO9 jWhPUzWPqDRVRpA8oYOvcpRsOw7qu7gWoAu1Iza7J1ZqT/+Sk3l0/uIZiZTLYYHyMdwc 3dsssvizwADChPHLPQYjTBvBJTF9Kr5KT3B0wxrHu/0N2H38MW2UJZ8sP9oI7X8EgGuZ 2vCg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=ENirkpHLaDHbwhuX8Tw5Q/hr/4fSZUenQgyhRnch7CE=; b=LtI0j+yhSXKw+BmpXWG5FHUdkC1UNKOX+yAmuFlMig48MYcSktyAlogAUKfIyEcrUz 8IqrmJ5dSYcm23ZK5zuZ3wjrmUI/yByK1wdaoITbKz8rZuc+L6gf+O60HcjDZrh3pZck EO7KDSC0HarvW53pnj+0DP+slDiBnic2PKMr9klk/ow+Zc44GizAmKlk7ncuhsNxUWyc tsuv3RkU0DhbcmPb23iBUJ25SJC1fX9LTO+PWei1YaM6fGRcW2x1KCx13Zv9MbAQx27Y fO9bWmaydHgDQjKgQ29dPWOBmiw9rlSbAB5Uo/CYEnNPPu2FH7EflvoqtTpfzE1sENJv QRzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=GBZEQLDS; 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 n18si9441689pgb.91.2019.03.13.01.21.02; Wed, 13 Mar 2019 01:21:18 -0700 (PDT) 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; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b=GBZEQLDS; 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 S1726891AbfCMIUU (ORCPT + 99 others); Wed, 13 Mar 2019 04:20:20 -0400 Received: from merlin.infradead.org ([205.233.59.134]:44254 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725820AbfCMIUU (ORCPT ); Wed, 13 Mar 2019 04:20:20 -0400 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:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=ENirkpHLaDHbwhuX8Tw5Q/hr/4fSZUenQgyhRnch7CE=; b=GBZEQLDSEzGSelcl5Njcsq1ui Zm82Jqjv+Ed1Ly6BUGXO2vXVpfJQnfaZHj7eIMlIcVdH0MlRNtCO+v25PHWIpBc4R2GxztvurVoYJ o2ORMJq3mvP1PjNOWBJsQyreZ2IvN8Wu/84zBSTc36QozkLsnU7RhvTJgr+5GL7AiO146M/bDe/+K gcIDg2BJn1Qnm37MoG2LaZZOeZpIIv0nhrjRu/ymHYHu96fqB8nqUqDptdgzjCXttDWYsfra3C3uC rFwSDASrdC/V5/nhYefyAgAWW7of9CV49RAqktC5IjE60xUI1DDlnwU9ik9fZx2TDPAy0pa/LAXsb k+sHMqfHA==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=hirez.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1h3z7K-0006uA-LP; Wed, 13 Mar 2019 08:20:02 +0000 Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 390E42011D47D; Wed, 13 Mar 2019 09:19:58 +0100 (CET) Date: Wed, 13 Mar 2019 09:19:58 +0100 From: Peter Zijlstra To: Patrick Bellasi Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, linux-api@vger.kernel.org, Ingo Molnar , Tejun Heo , "Rafael J . Wysocki" , Vincent Guittot , Viresh Kumar , Paul Turner , Quentin Perret , Dietmar Eggemann , Morten Rasmussen , Juri Lelli , Todd Kjos , Joel Fernandes , Steve Muckle , Suren Baghdasaryan Subject: Re: [PATCH v7 01/15] sched/core: uclamp: Add CPU's clamp buckets refcounting Message-ID: <20190313081958.GA5996@hirez.programming.kicks-ass.net> References: <20190208100554.32196-1-patrick.bellasi@arm.com> <20190208100554.32196-2-patrick.bellasi@arm.com> <20190312152059.GA5922@hirez.programming.kicks-ass.net> <20190312155043.vj3fiutnsovjti2x@e110439-lin> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190312155043.vj3fiutnsovjti2x@e110439-lin> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 12, 2019 at 03:50:43PM +0000, Patrick Bellasi wrote: > On 12-Mar 16:20, Peter Zijlstra wrote: > > On Fri, Feb 08, 2019 at 10:05:40AM +0000, Patrick Bellasi wrote: > > > +/* Integer ceil-rounded range for each bucket */ ^^^^^^^^^^^^^^^^^^^^^^^^^^^ > > > +#define UCLAMP_BUCKET_DELTA ((SCHED_CAPACITY_SCALE / UCLAMP_BUCKETS) + 1) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ simply do not match. > > Uhm, should that not me ((x+y-1)/y), aka. DIV_ROUND_UP(x,y) ? > > Well, there is certainly some rounding to be done... > > > The above would give 4 for 9/3, which is clearly buggered. > > .. still the math above should work fine within the boundaries we > define for UCLAMP_BUCKET_DELTA (5..20 groups) and considering that > SCHED_CAPACITY_SCALE will never be smaller then 1024. That's a very poor reason to write utter nonsense :-) > The above is designed to shrink the topmost bucket wrt all the others > but it will never be smaller than ~30%. 30% sounds like a lot, esp. for this range. > Here are the start values computed for each bucket using the math > above and the computed shrinking percentage for the topmost bucket: If you use a regular rounding, the error is _much_ smaller: $ for ((x=5;x<21;x++)) ; do let d=(1024+x/2)/x; let s=(x-1)*d; let e=1024-s; let p=100*(d-e)/d; echo $x $d $s $e $p%; done 5 205 820 204 0% 6 171 855 169 1% 7 146 876 148 -1% 8 128 896 128 0% 9 114 912 112 1% 10 102 918 106 -3% 11 93 930 94 -1% 12 85 935 89 -4% 13 79 948 76 3% 14 73 949 75 -2% 15 68 952 72 -5% 16 64 960 64 0% 17 60 960 64 -6% 18 57 969 55 3% 19 54 972 52 3% 20 51 969 55 -7% Funnily enough, we have a helper for that too: DIV_ROUND_CLOSEST(). Now, if we go further, the error will obviously increase because we run out of precision, but even there, regular rounding will be better than either floor or ceil.