Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp7218512imm; Tue, 24 Jul 2018 10:18:51 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdIsq2OmyIhl9OyBbY2c2fzo08YABI6CvXdwbLjDG+lxhK0cHMAc8TxbWPlAK1CFvrP7ZfQ X-Received: by 2002:a17:902:292b:: with SMTP id g40-v6mr17979578plb.273.1532452731180; Tue, 24 Jul 2018 10:18:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532452731; cv=none; d=google.com; s=arc-20160816; b=PNQyFla0ChA2EU3+Cx9HE0k5obUDA2gLMU2su3CiF1o0hQe0egNNrUE2Xdp2xz2S6r 4rBS2qG1OJVAiXedcr5g9w0ZNXeSsIUviOx7aueP+IO/mL8smQXgrAEAHiwsc63eTKkL dNnanausK2jsRsk5ZNKcuL72L4Et61WwCpYNAUrkz2sbwoXDEBw56TaDB2nCiDOKTSdc 9yn7SVKjkmJgvI6zTFIue+mxSIK06OKWoTG/sjAuV9ycQvTId7xNttCbwzCB3DgfDvqT o7WY/VucT1bWDmJfhs3x83prxt53ZHRSlxa2GP/F9P8rLhkWEttXr72M3lyYIxh+SBWx cg0w== 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:arc-authentication-results; bh=wAz/hf7nV1aQsUYlwvCJVrwSzeXgd3Dk7i7z5l/edM4=; b=W2+pZXJuNSbhn5hcMfIm+pVQ0r9l+83n3iTJIt2Q5V7R+ZmNwEnvhxvLlXQaEHlYpT vUZERcCGzhyi8cpWsh5cE8f9t+15pjhqqyplt5szJdVjLanF7yfHb5PAK+Kecc1KFeH0 6C8YQMsPQDe3rGrrogTZSNDmP8CdixSiJlfJBGdCX9z8AYYysv+4Fy/GyMrnjhwPwKc8 oX94YlLFKtDu3F8FmANV/DJ91qUxMYZIGpi+kRGYyxZ6+xRoMLfiuvgLKqEI/1C5pqR9 nZYmhCA8AC8v+IxYhaNyN91AcCUgHefgg/XVa68aSG/WnCOP9LNKxp7fQXn8nGcWs3Iv SLRA== 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 s184-v6si11709936pgb.161.2018.07.24.10.18.35; Tue, 24 Jul 2018 10:18:51 -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; 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 S2388471AbeGXSZN (ORCPT + 99 others); Tue, 24 Jul 2018 14:25:13 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:55524 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388413AbeGXSZN (ORCPT ); Tue, 24 Jul 2018 14:25:13 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A33B080D; Tue, 24 Jul 2018 10:17:44 -0700 (PDT) Received: from e110439-lin (e110439-lin.emea.arm.com [10.4.12.126]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 015653F575; Tue, 24 Jul 2018 10:17:41 -0700 (PDT) Date: Tue, 24 Jul 2018 18:17:39 +0100 From: Patrick Bellasi To: Suren Baghdasaryan Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org, Ingo Molnar , Peter Zijlstra , Tejun Heo , "Rafael J . Wysocki" , Viresh Kumar , Vincent Guittot , Paul Turner , Dietmar Eggemann , Morten Rasmussen , Juri Lelli , Todd Kjos , Joel Fernandes , Steve Muckle Subject: Re: [PATCH v2 12/12] sched/core: uclamp: use percentage clamp values Message-ID: <20180724171739.GC3162@e110439-lin> References: <20180716082906.6061-1-patrick.bellasi@arm.com> <20180716082906.6061-13-patrick.bellasi@arm.com> <20180724164303.GB3162@e110439-lin> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 24-Jul 10:11, Suren Baghdasaryan wrote: > On Tue, Jul 24, 2018 at 9:43 AM, Patrick Bellasi > wrote: > > On 21-Jul 21:04, Suren Baghdasaryan wrote: > >> On Mon, Jul 16, 2018 at 1:29 AM, Patrick Bellasi > >> wrote: > > > > [...] > > > >> > +static inline unsigned int scale_from_percent(unsigned int pct) > >> > +{ > >> > + WARN_ON(pct > 100); > >> > + > >> > + return ((SCHED_FIXEDPOINT_SCALE * pct) / 100); > >> > +} > >> > + > >> > +static inline unsigned int scale_to_percent(unsigned int value) > >> > +{ > >> > + unsigned int rounding = 0; > >> > + > >> > + WARN_ON(value > SCHED_FIXEDPOINT_SCALE); > >> > + > >> > + /* Compensate rounding errors for: 0, 256, 512, 768, 1024 */ > >> > + if (likely((value & 0xFF) && ~(value & 0x700))) > >> > + rounding = 1; > >> > >> Hmm. I don't think ~(value & 0x700) will ever yield FALSE... What am I missing? > > > > So, 0x700 is the topmost 3 bits sets (111 0000 0000) which different > > configuration corresponds to: > > > > 001 0000 0000 => 256 > > 010 0000 0000 => 512 > > 011 0000 0000 => 768 > > 100 0000 0000 => 1024 > > > > Thus, if 0x700 matches then we have one of these values in input and > > for these cases we have to add a unit to the percentage value. > > > > For the case (value == 0) we translate it into 0% thanks to the check > > on (value & 0xFF) to ensure rounding = 0. > > > > I think just (value & 0xFF) is enough to get you the right behavior. > ~(value & 0x700) is not needed, it's effectively a NoOp which always > yields TRUE. For any *value* (value & 0x700) == 0x...00 and ~(value & > 0x700) == 0x...FF == TRUE. And you are actually right! ;) > > Here is a small python snippet I've used to check the conversion of > > all the possible percentage values: > > > > ---8<--- > > values = range(0, 101) > > for pct in xrange(0, 101): > > util = int((1024 * pct) / 100) > > rounding = 1 > > if not ((util & 0xFF) and ~(util & 0x700)): ... it works also by patching the line above! > > print "Fixing util_to_perc({:3d} => {:4d})".format(pct, util) > > rounding = 0 > > pct2 = (rounding + ((100 * util) / 1024)) > > if pct2 in values: > > values.remove(pct2) > > if pct != pct2: > > print "Convertion failed for: {:3d} => {:4d} => {:3d}".format(pct, util, pct2) > > if values: > > print "ERROR: not all percentage values converted" > > ---8<--- Good catch, thanks! -- #include Patrick Bellasi