From: David Howells <dhowells@redhat.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: akpm@linux-foundation.org, benh@kernel.crashing.org,
linux-kernel@vger.kernel.org, hpa@zytor.com,
johannes@sipsolutions.net
Subject: Re: [PATCH] Fix get_order()
Date: Wed, 07 Mar 2007 11:43:06 +0000 [thread overview]
Message-ID: <8543.1173267786@redhat.com> (raw)
In-Reply-To: <Pine.LNX.4.64.0703061913080.5963@woody.linux-foundation.org>
Linus Torvalds <torvalds@linux-foundation.org> wrote:
> > +#define ilog2_up(n) ((n) == 1 ? 0 : ilog2((n) - 1) + 1)
>
> This is wrong. It uses "n" twice, which makes it unsafe as a macro.
Damn. I missed that.
> Or it could use a "__builtin_constant_p()" (which gcc defines to not have
> side effects) to allow the multiple use for constant data.
I should have, yes.
> Or we could require that "ilog2(0)" returns -1, and then we could just say
>
> #define ilog2_up(n) (ilog2((n)-1)+1)
I'd rather not do that as the inline assembly variants then have to special
case ilog2(0) rather than just having an undefined result.
> The whole "get_order()" macro also has some serious lack of parenthesis.
> In general, commit 39d61db0edb34d60b83c5e0d62d0e906578cc707 just was
> pretty damn bad!
Unfortunately, I can't disagree.
> I'm becoming a bit disgruntled about this whole thing, I have to admit.
> I'm just not sure the bugs here are worth it. Especially considering that
> __get_order() has apparently never even tested these things to begin with,
It was tested... I've just re-examined my test program and I've realised I've
only tested power-of-2 parameters. Sigh.
> since nobody but FRV has ever #defined the ARCH_HAS_ILOG2_U?? macros.
Well, that should be CONFIG_ARCH_HAS_ILOG2_U?? macros, and powerpc defines
those too.
> - buggy
True, for N being a non-power-of-two, unfortunately; and also where evaluating
N has side-effects.
> - untested
Not true, just that my userspace test program isn't sufficiently exhaustive.
> - has untrue comments
Unfortunately so.
> - makes no real sense
Not true.
Various archs (including i386, x86_64, powerpc and frv) have instructions that
can be used to calculate integer log2(N). The fallback position is to use a
loop:
size = (size - 1) >> (PAGE_SHIFT - 1);
order = -1;
do {
size >>= 1;
order++;
} while (size);
> and I'm inclined to just revert 39d61db0 instead of adding more and more
> breakage to it, since it's simply not going to help with the fundamental
> problems!
Probably a good idea. I'll work on it some more and improve my test program
(which is actually quite simple to do).
David
next prev parent reply other threads:[~2007-03-07 11:43 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-03-06 17:39 [PATCH] Fix get_order() David Howells
2007-03-06 17:58 ` H. Peter Anvin
2007-03-06 18:21 ` David Howells
2007-03-06 18:41 ` Linus Torvalds
2007-03-06 18:51 ` David Howells
2007-03-07 3:28 ` Linus Torvalds
2007-03-07 11:43 ` David Howells [this message]
2007-03-07 16:02 ` ALIGN via ilog2 without gccisms (Re: [PATCH] Fix get_order()) Oleg Verych
2007-03-07 16:38 ` Linus Torvalds
2007-03-07 17:24 ` Oleg Verych
2007-03-07 18:05 ` Linus Torvalds
2007-03-09 23:13 ` ALIGN " Oleg Verych
2007-03-09 23:15 ` Linus Torvalds
2007-03-10 0:31 ` Oleg Verych
2007-03-10 8:01 ` ALIGN Oleg Verych
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=8543.1173267786@redhat.com \
--to=dhowells@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=benh@kernel.crashing.org \
--cc=hpa@zytor.com \
--cc=johannes@sipsolutions.net \
--cc=linux-kernel@vger.kernel.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