Re: [patch] Re: Bug 619 - sched_best_cpu does not pick best cpu (2/2)

Gabriel Paubert (paubert@iram.es)
Tue, 6 May 2003 13:06:44 +0200


On Mon, May 05, 2003 at 06:28:34PM -0700, Matthew Dobson wrote:
> This patch is in regard to bugme.osdl.org bug 619, link here:
>
> http://bugme.osdl.org/show_bug.cgi?id=619
>
> This is the second of two patches to fix this bug. This patch fills in
> include/linux/topology.h (created in the last patch) with a couple
> #defines. The patch also creates a generic_hweight64() in
> include/linux/bitops.h, which we've been lacking for a while. It then
> uses these new macros in sched.c to ensure that if a node has no CPUs,
> it is not used in scheduling decisions.
>
> [mcd@arrakis src]$ diffstat ~/patches/node_online.patch
> include/linux/bitops.h | 27 +++++++++++++++++++++++++++
> include/linux/topology.h | 7 +++++++
> kernel/sched.c | 2 +-
> 3 files changed, 35 insertions(+), 1 deletion(-)
>
> Cheers!
>
> -Matt

> diff -Nur --exclude-from=/home/mcd/.dontdiff linux-2.5.69-add_linux_topo/include/linux/bitops.h linux-2.5.69-node_online_fix/include/linux/bitops.h
> --- linux-2.5.69-add_linux_topo/include/linux/bitops.h Sun May 4 16:53:42 2003
> +++ linux-2.5.69-node_online_fix/include/linux/bitops.h Mon May 5 18:00:00 2003
> @@ -107,6 +107,33 @@
> return (res & 0x0F) + ((res >> 4) & 0x0F);
> }
>
> +#if (BITS_PER_LONG == 64)
> +
> +static inline unsigned int generic_hweight64(unsigned int w)
> +{
> + unsigned int res = (w & 0x5555555555555555) + ((w >> 1) & 0x5555555555555555);

Ignoring the fact that the types are wrong for 64 bit values, you can save
one masking (in all generic_hweight functions in fact) by using the
following expression for the first line:

uxx res = w - ((w>>1) & 0x55...55);

where xx is 8, 16, 32, or 64 and the right number of 5s.
That's an old trick but I can't remember the reference nor
where I found the reference to it, sorry.

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