lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Mon, 12 May 2008 05:56:27 -0600
From:	Matthew Wilcox <matthew@....cx>
To:	Alexander van Heukelum <heukelum@...tmail.fm>
Cc:	Alexander van Heukelum <heukelum@...lshack.com>,
	Andrew Morton <akpm@...ux-foundation.org>,
	Paul Jackson <pj@....com>, Ingo Molnar <mingo@...e.hu>,
	Thomas Gleixner <tglx@...utronix.de>,
	linux-arch <linux-arch@...r.kernel.org>,
	LKML <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH] Make for_each_cpu_mask a bit smaller

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."
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ