From: Patrick Bellasi <patrick.bellasi@arm.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: linux-kernel@vger.kernel.org, linux-pm@vger.kernel.org,
linux-api@vger.kernel.org, cgroups@vger.kernel.org,
Ingo Molnar <mingo@redhat.com>, Tejun Heo <tj@kernel.org>,
"Rafael J . Wysocki" <rafael.j.wysocki@intel.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Viresh Kumar <viresh.kumar@linaro.org>,
Paul Turner <pjt@google.com>, Michal Koutny <mkoutny@suse.com>,
Quentin Perret <quentin.perret@arm.com>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Morten Rasmussen <morten.rasmussen@arm.com>,
Juri Lelli <juri.lelli@redhat.com>, Todd Kjos <tkjos@google.com>,
Joel Fernandes <joelaf@google.com>,
Steve Muckle <smuckle@google.com>,
Suren Baghdasaryan <surenb@google.com>,
Alessio Balsini <balsini@android.com>
Subject: Re: [PATCH v14 1/6] sched/core: uclamp: Extend CPU's cgroup controller
Date: Mon, 02 Sep 2019 07:38:53 +0100 [thread overview]
Message-ID: <87zhjnnqz2.fsf@arm.com> (raw)
In-Reply-To: <20190830094505.GA2369@hirez.programming.kicks-ass.net>
On Fri, Aug 30, 2019 at 09:45:05 +0000, Peter Zijlstra wrote...
> On Thu, Aug 22, 2019 at 02:28:06PM +0100, Patrick Bellasi wrote:
>> +#define _POW10(exp) ((unsigned int)1e##exp)
>> +#define POW10(exp) _POW10(exp)
>
> What is this magic? You're forcing a float literal into an integer.
> Surely that deserves a comment!
Yes, I'm introducing the two constants:
UCLAMP_PERCENT_SHIFT,
UCLAMP_PERCENT_SCALE
similar to what we have for CAPACITY. Moreover, I need both 100*100 (for
the scale) and 100 further down in the code for the:
percent = div_u64_rem(percent, POW10(UCLAMP_PERCENT_SHIFT), &rem);
used in cpu_uclamp_print().
That's why adding a compile time support to compute a 10^N is useful.
C provides the "1eN" literal, I just convert it to integer and to do
that at compile time I need a two level macros.
What if I add this comment just above the macro definitions:
/*
* Integer 10^N with a given N exponent by casting to integer the literal "1eN"
* C expression. Since there is no way to convert a macro argument (N) into a
* character constant, use two levels of macros.
*/
is this clear enough?
>
>> +struct uclamp_request {
>> +#define UCLAMP_PERCENT_SHIFT 2
>> +#define UCLAMP_PERCENT_SCALE (100 * POW10(UCLAMP_PERCENT_SHIFT))
>> + s64 percent;
>> + u64 util;
>> + int ret;
>> +};
>> +
>> +static inline struct uclamp_request
>> +capacity_from_percent(char *buf)
>> +{
>> + struct uclamp_request req = {
>> + .percent = UCLAMP_PERCENT_SCALE,
>> + .util = SCHED_CAPACITY_SCALE,
>> + .ret = 0,
>> + };
>> +
>> + buf = strim(buf);
>> + if (strncmp("max", buf, 4)) {
>
> That is either a bug, and you meant to write: strncmp(buf, "max", 3),
> or it is not, and then you could've written: strcmp(buf, "max")
I don't think it's a bug.
The usage of 4 is intentional, to force a '\0' check while using
strncmp(). Otherwise, strncmp(buf, "max", 3) would accept also strings
starting by "max", which we don't want.
> But as written it doesn't make sense.
The code is safe but I agree that strcmp() does just the same and it
does not generate confusion. That's actually a pretty good example
on how it's not always better to use strncmp() instead of strcmp().
Cheers,
Patrick
next prev parent reply other threads:[~2019-09-02 6:38 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-22 13:28 [PATCH v14 0/6] Add utilization clamping support (CGroups API) Patrick Bellasi
2019-08-22 13:28 ` Patrick Bellasi
2019-08-22 13:28 ` [PATCH v14 1/6] sched/core: uclamp: Extend CPU's cgroup controller Patrick Bellasi
2019-08-30 9:45 ` Peter Zijlstra
2019-09-02 6:38 ` Patrick Bellasi [this message]
2019-09-02 7:47 ` Peter Zijlstra
2019-09-02 23:02 ` Suren Baghdasaryan
2019-09-03 8:52 ` Michal Koutný
2019-09-03 14:21 ` Joel Fernandes
2019-09-03 14:21 ` Joel Fernandes
2019-09-03 14:21 ` Joel Fernandes
2019-09-03 8:31 ` [tip: sched/core] sched/uclamp: " tip-bot2 for Patrick Bellasi
2019-08-22 13:28 ` [PATCH v14 2/6] sched/core: uclamp: Propagate parent clamps Patrick Bellasi
2019-09-03 8:31 ` [tip: sched/core] sched/uclamp: " tip-bot2 for Patrick Bellasi
2019-08-22 13:28 ` [PATCH v14 3/6] sched/core: uclamp: Propagate system defaults to root group Patrick Bellasi
2019-09-03 8:31 ` [tip: sched/core] sched/uclamp: Propagate system defaults to the " tip-bot2 for Patrick Bellasi
2019-08-22 13:28 ` [PATCH v14 4/6] sched/core: uclamp: Use TG's clamps to restrict TASK's clamps Patrick Bellasi
2019-09-03 8:31 ` [tip: sched/core] sched/uclamp: " tip-bot2 for Patrick Bellasi
2019-08-22 13:28 ` [PATCH v14 5/6] sched/core: uclamp: Update CPU's refcount on TG's clamp changes Patrick Bellasi
2019-08-30 9:48 ` Peter Zijlstra
2019-09-02 6:44 ` Patrick Bellasi
2019-09-02 7:38 ` Peter Zijlstra
2019-09-03 8:31 ` [tip: sched/core] sched/uclamp: " tip-bot2 for Patrick Bellasi
2019-08-22 13:28 ` [PATCH v14 6/6] sched/core: uclamp: always use enum uclamp_id for clamp_id values Patrick Bellasi
2019-09-03 8:31 ` [tip: sched/core] sched/uclamp: Always use 'enum uclamp_id' " tip-bot2 for Patrick Bellasi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87zhjnnqz2.fsf@arm.com \
--to=patrick.bellasi@arm.com \
--cc=balsini@android.com \
--cc=cgroups@vger.kernel.org \
--cc=dietmar.eggemann@arm.com \
--cc=joelaf@google.com \
--cc=juri.lelli@redhat.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=mkoutny@suse.com \
--cc=morten.rasmussen@arm.com \
--cc=peterz@infradead.org \
--cc=pjt@google.com \
--cc=quentin.perret@arm.com \
--cc=rafael.j.wysocki@intel.com \
--cc=smuckle@google.com \
--cc=surenb@google.com \
--cc=tj@kernel.org \
--cc=tkjos@google.com \
--cc=vincent.guittot@linaro.org \
--cc=viresh.kumar@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.