[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20180724164303.GB3162@e110439-lin>
Date: Tue, 24 Jul 2018 17:43:03 +0100
From: Patrick Bellasi <patrick.bellasi@....com>
To: Suren Baghdasaryan <surenb@...gle.com>
Cc: linux-kernel@...r.kernel.org, linux-pm@...r.kernel.org,
Ingo Molnar <mingo@...hat.com>,
Peter Zijlstra <peterz@...radead.org>,
Tejun Heo <tj@...nel.org>,
"Rafael J . Wysocki" <rafael.j.wysocki@...el.com>,
Viresh Kumar <viresh.kumar@...aro.org>,
Vincent Guittot <vincent.guittot@...aro.org>,
Paul Turner <pjt@...gle.com>,
Dietmar Eggemann <dietmar.eggemann@....com>,
Morten Rasmussen <morten.rasmussen@....com>,
Juri Lelli <juri.lelli@...hat.com>,
Todd Kjos <tkjos@...gle.com>,
Joel Fernandes <joelaf@...gle.com>,
Steve Muckle <smuckle@...gle.com>
Subject: Re: [PATCH v2 12/12] sched/core: uclamp: use percentage clamp values
On 21-Jul 21:04, Suren Baghdasaryan wrote:
> On Mon, Jul 16, 2018 at 1:29 AM, Patrick Bellasi
> <patrick.bellasi@....com> 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.
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)):
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<---
--
#include <best/regards.h>
Patrick Bellasi
Powered by blists - more mailing lists