From: Matthew Wilcox <matthew@wil.cx>
To: Alexander van Heukelum <heukelum@fastmail.fm>
Cc: Alexander van Heukelum <heukelum@mailshack.com>,
Andrew Morton <akpm@linux-foundation.org>,
Paul Jackson <pj@sgi.com>, Ingo Molnar <mingo@elte.hu>,
Thomas Gleixner <tglx@linutronix.de>,
linux-arch <linux-arch@vger.kernel.org>,
LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] Make for_each_cpu_mask a bit smaller
Date: Mon, 12 May 2008 05:56:27 -0600 [thread overview]
Message-ID: <20080512115626.GE19219@parisc-linux.org> (raw)
In-Reply-To: <1210590294.13136.1252653345@webmail.messagingengine.com>
On Mon, May 12, 2008 at 01:04:54PM +0200, Alexander van Heukelum wrote:
> > #define for_each_cpu_mask(cpu, mask) \
> > for ((cpu) = -1; \
> > (cpu) < NR_CPUS; \
> > (cpu) = find_next_cpu_mask((cpu), &(mask)))
> >
> > int find_next_cpu_mask(int n, const cpumask_t *srcp)
> > {
> > return find_next_bit(srcp->bits, NR_CPUS, ++n);
> > }
> >
> > That actually behaves the way I'd expect a function called
> > 'find_next_cpu_mask' to work. It also abuses the 'for' condtion
> > less and might take a little less text space.
>
> But it does not work.
You're right, of course. Either of these should work:
#define for_each_cpu_mask(cpu, mask) \
for ((cpu) = find_next_cpu_mask(-1, &(mask)); \
(cpu) < NR_CPUS; \
(cpu) = find_next_cpu_mask((cpu), &(mask)))
#define for_each_cpu_mask(cpu, mask) \
for ((cpu) = -1; \
(cpu) = find_next_cpu_mask((cpu), &(mask)), (cpu) < NR_CPUS; \
)
int find_next_cpu_mask(int n, const cpumask_t *srcp)
{
return find_next_bit(srcp->bits, NR_CPUS, ++n);
}
> I think of find_next_cpu_mask(cpu, mask) as: "find next
> cpu-index in mask, starting at index cpu". And similar
> with find_next_bit.
If you're determined to stick to your original formulation, renaming it
to find_valid_cpu_mask() would work better.
> As for the text-space argument, I think you might be right.
> Just not on i386/x86_64 where initialising a register to -1
> can be done in three bytes, initialising to 0 in two bytes
> and an increment in one byte :-).
While the initialisation may take one extra byte, the increment is
done in the function, and so takes at least one byte out of the loop.
Of course on other instruction sets, that's probably 4 bytes out of the
loop and they can initialise to -1 as cheaply as init to 0, so it's a
win on non-x86 and neutral on x86.
--
Intel are signing my paycheques ... these opinions are still mine
"Bill, look, we understand that you're interested in selling us this
operating system, but compare it to ours. We can't possibly take such
a retrograde step."
prev parent reply other threads:[~2008-05-12 11:56 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-05-11 13:50 [PATCH] Make for_each_cpu_mask a bit smaller Alexander van Heukelum
2008-05-11 13:50 ` Alexander van Heukelum
2008-05-11 13:57 ` Paul Jackson
2008-05-11 14:14 ` Paul Jackson
2008-05-11 16:06 ` [RFC/PATCH] Make for_each_node_mask out-of-line Alexander van Heukelum
2008-05-11 21:01 ` Paul Jackson
2008-05-12 12:04 ` Alexander van Heukelum
2008-05-12 16:45 ` Mike Travis
2008-05-12 19:00 ` [PATCHv2] Make for_each_cpu_mask a bit smaller Alexander van Heukelum
2008-05-12 21:45 ` Andreas Schwab
2008-05-13 9:28 ` [PATCHv3] " Alexander van Heukelum
2008-05-13 12:02 ` Ingo Molnar
2008-05-11 15:24 ` [PATCH] " Matthew Wilcox
2008-05-11 16:19 ` Alexander van Heukelum
2008-05-11 16:19 ` Alexander van Heukelum
2008-05-11 22:01 ` Matthew Wilcox
2008-05-12 11:04 ` Alexander van Heukelum
2008-05-12 11:04 ` Alexander van Heukelum
2008-05-12 11:56 ` Matthew Wilcox [this message]
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=20080512115626.GE19219@parisc-linux.org \
--to=matthew@wil.cx \
--cc=akpm@linux-foundation.org \
--cc=heukelum@fastmail.fm \
--cc=heukelum@mailshack.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=pj@sgi.com \
--cc=tglx@linutronix.de \
/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