Linux SPARSE checker discussions
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <uwe@kleine-koenig.org>
To: Linus Torvalds <torvalds@linux-foundation.org>,
	Luc Van Oostenryck <luc.vanoostenryck@gmail.com>,
	Alexei Starovoitov <ast@kernel.org>
Cc: Randy Dunlap <rdunlap@infradead.org>,
	Linux-Sparse <linux-sparse@vger.kernel.org>,
	Martin KaFai Lau <kafai@fb.com>,
	Arthur Fabre <afabre@cloudflare.com>
Subject: Re: sparse problem with Linux kernel v5.5
Date: Fri, 7 Feb 2020 07:34:57 +0100	[thread overview]
Message-ID: <b6d24fd2-e5b8-7010-86b5-c46f65536eef@kleine-koenig.org> (raw)
In-Reply-To: <CAHk-=whEFcgPW8oD=rGGyDiML_7AaCP0DGdW=WXjvF9zAv6Vrg@mail.gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 747 bytes --]

Hello,

On 2/7/20 12:47 AM, Linus Torvalds wrote:
> Instead, it could just calculate the nbuckets first, and then do the
> "log2()" on that:
> 
>         /* Use at least 2 buckets, select_bucket() is undefined
> behavior with 1 bucket */
>         nbuckets = max_t(u32, 2, roundup_pow_of_two(num_possible_cpus()));
>         smap->bucket_log = ilog2(buckets);


Isn't it kind of ineffective to first round to a power of two and then
take the ilog2 of it?

At a first glance I'd say that

	ilog2(roundup_pow_of_two(x)) == ilog(x - 1) + 1

for x > 1. (Maybe even for x == 1? Didn't care to check, I think it
doesn't matter for the case at hand.)

This RHS might be easier to optimize for the compiler?!

Best regards
Uwe


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  parent reply	other threads:[~2020-02-07  6:42 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-06  4:49 sparse problem with Linux kernel v5.5 Randy Dunlap
2020-02-06  4:58 ` Randy Dunlap
2020-02-06  7:18 ` Linus Torvalds
2020-02-06 11:46   ` Luc Van Oostenryck
2020-02-06 18:25     ` Randy Dunlap
2020-02-06 20:06       ` Luc Van Oostenryck
2020-02-06 23:47         ` Linus Torvalds
2020-02-07  0:34           ` Martin KaFai Lau
2020-02-07 10:35             ` Luc Van Oostenryck
2020-02-07  6:34           ` Uwe Kleine-König [this message]
2020-02-07  8:29             ` Martin KaFai Lau
2020-02-07 11:34               ` Uwe Kleine-König
2020-02-07 12:43                 ` Luc Van Oostenryck
2020-02-07 10:31           ` Luc Van Oostenryck

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=b6d24fd2-e5b8-7010-86b5-c46f65536eef@kleine-koenig.org \
    --to=uwe@kleine-koenig.org \
    --cc=afabre@cloudflare.com \
    --cc=ast@kernel.org \
    --cc=kafai@fb.com \
    --cc=linux-sparse@vger.kernel.org \
    --cc=luc.vanoostenryck@gmail.com \
    --cc=rdunlap@infradead.org \
    --cc=torvalds@linux-foundation.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox