Index: kern/kern_ktr.c =================================================================== --- kern/kern_ktr.c (revision 250255) +++ kern/kern_ktr.c (revision 250256) @@ -104,7 +104,7 @@ int ktr_entries = KTR_BOOT_ENTRIES; int ktr_version = KTR_VERSION; struct ktr_entry ktr_buf_init[KTR_BOOT_ENTRIES]; struct ktr_entry *ktr_buf = ktr_buf_init; -cpuset_t ktr_cpumask = CPUSET_T_INITIALIZER(KTR_CPUMASK); +cpuset_t ktr_cpumask = BITSET_T_INITIALIZER(KTR_CPUMASK); static char ktr_cpumask_str[CPUSETBUFSIZ]; TUNABLE_INT("debug.ktr.mask", &ktr_mask); Index: kern/kern_cpuset.c =================================================================== --- kern/kern_cpuset.c (revision 250255) +++ kern/kern_cpuset.c (revision 250256) @@ -630,7 +630,7 @@ cpusetobj_ffs(const cpuset_t *set) for (i = 0; i < _NCPUWORDS; i++) { if (set->__bits[i] != 0) { cbit = ffsl(set->__bits[i]); - cbit += i * _NCPUBITS; + cbit += i * _BITSET_BITS; break; } } Index: sys/cpuset.h =================================================================== --- sys/cpuset.h (revision 250255) +++ sys/cpuset.h (revision 250256) @@ -34,125 +34,30 @@ #include +#include + #define CPUSETBUFSIZ ((2 + sizeof(long) * 2) * _NCPUWORDS) -/* - * Macros addressing word and bit within it, tuned to make compiler - * optimize cases when CPU_SETSIZE fits into single machine word. - */ -#define __cpuset_mask(n) \ - ((long)1 << ((_NCPUWORDS == 1) ? (__size_t)(n) : ((n) % _NCPUBITS))) -#define __cpuset_word(n) ((_NCPUWORDS == 1) ? 0 : ((n) / _NCPUBITS)) +#define CPU_CLR(n, p) BIT_CLR(CPU_SETSIZE, n, p) +#define CPU_COPY(f, t) BIT_COPY(CPU_SETSIZE, f, t) +#define CPU_ISSET(n, p) BIT_ISSET(CPU_SETSIZE, n, p) +#define CPU_SET(n, p) BIT_SET(CPU_SETSIZE, n, p) +#define CPU_ZERO(p) BIT_ZERO(CPU_SETSIZE, p) +#define CPU_FILL(p) BIT_FILL(CPU_SETSIZE, p) +#define CPU_SETOF(n, p) BIT_SETOF(CPU_SETSIZE, n, p) +#define CPU_EMPTY(p) BIT_EMPTY(CPU_SETSIZE, p) +#define CPU_ISFULLSET(p) BIT_ISFULLSET(CPU_SETSIZE, p) +#define CPU_SUBSET(p, c) BIT_SUBSET(CPU_SETSIZE, p, c) +#define CPU_OVERLAP(p, c) BIT_OVERLAP(CPU_SETSIZE, p, c) +#define CPU_CMP(p, c) BIT_CMP(CPU_SETSIZE, p, c) +#define CPU_OR(d, s) BIT_OR(CPU_SETSIZE, d, s) +#define CPU_AND(d, s) BIT_AND(CPU_SETSIZE, d, s) +#define CPU_NAND(d, s) BIT_NAND(CPU_SETSIZE, d, s) +#define CPU_CLR_ATOMIC(n, p) BIT_CLR_ATOMIC(CPU_SETSIZE, n, p) +#define CPU_SET_ATOMIC(n, p) BIT_SET_ATOMIC(CPU_SETSIZE, n, p) +#define CPU_OR_ATOMIC(d, s) BIT_OR_ATOMIC(CPU_SETSIZE, d, s) +#define CPU_COPY_STORE_REL(f, t) BIT_COPY_STORE_REL(CPU_SETSIZE, f, t) -#define CPU_CLR(n, p) ((p)->__bits[__cpuset_word(n)] &= ~__cpuset_mask(n)) -#define CPU_COPY(f, t) (void)(*(t) = *(f)) -#define CPU_ISSET(n, p) (((p)->__bits[__cpuset_word(n)] & __cpuset_mask(n)) != 0) -#define CPU_SET(n, p) ((p)->__bits[__cpuset_word(n)] |= __cpuset_mask(n)) -#define CPU_ZERO(p) do { \ - __size_t __i; \ - for (__i = 0; __i < _NCPUWORDS; __i++) \ - (p)->__bits[__i] = 0; \ -} while (0) - -#define CPU_FILL(p) do { \ - __size_t __i; \ - for (__i = 0; __i < _NCPUWORDS; __i++) \ - (p)->__bits[__i] = -1; \ -} while (0) - -#define CPU_SETOF(n, p) do { \ - CPU_ZERO(p); \ - ((p)->__bits[__cpuset_word(n)] = __cpuset_mask(n)); \ -} while (0) - -/* Is p empty. */ -#define CPU_EMPTY(p) __extension__ ({ \ - __size_t __i; \ - for (__i = 0; __i < _NCPUWORDS; __i++) \ - if ((p)->__bits[__i]) \ - break; \ - __i == _NCPUWORDS; \ -}) - -/* Is p full set. */ -#define CPU_ISFULLSET(p) __extension__ ({ \ - __size_t __i; \ - for (__i = 0; __i < _NCPUWORDS; __i++) \ - if ((p)->__bits[__i] != (long)-1) \ - break; \ - __i == _NCPUWORDS; \ -}) - -/* Is c a subset of p. */ -#define CPU_SUBSET(p, c) __extension__ ({ \ - __size_t __i; \ - for (__i = 0; __i < _NCPUWORDS; __i++) \ - if (((c)->__bits[__i] & \ - (p)->__bits[__i]) != \ - (c)->__bits[__i]) \ - break; \ - __i == _NCPUWORDS; \ -}) - -/* Are there any common bits between b & c? */ -#define CPU_OVERLAP(p, c) __extension__ ({ \ - __size_t __i; \ - for (__i = 0; __i < _NCPUWORDS; __i++) \ - if (((c)->__bits[__i] & \ - (p)->__bits[__i]) != 0) \ - break; \ - __i != _NCPUWORDS; \ -}) - -/* Compare two sets, returns 0 if equal 1 otherwise. */ -#define CPU_CMP(p, c) __extension__ ({ \ - __size_t __i; \ - for (__i = 0; __i < _NCPUWORDS; __i++) \ - if (((c)->__bits[__i] != \ - (p)->__bits[__i])) \ - break; \ - __i != _NCPUWORDS; \ -}) - -#define CPU_OR(d, s) do { \ - __size_t __i; \ - for (__i = 0; __i < _NCPUWORDS; __i++) \ - (d)->__bits[__i] |= (s)->__bits[__i]; \ -} while (0) - -#define CPU_AND(d, s) do { \ - __size_t __i; \ - for (__i = 0; __i < _NCPUWORDS; __i++) \ - (d)->__bits[__i] &= (s)->__bits[__i]; \ -} while (0) - -#define CPU_NAND(d, s) do { \ - __size_t __i; \ - for (__i = 0; __i < _NCPUWORDS; __i++) \ - (d)->__bits[__i] &= ~(s)->__bits[__i]; \ -} while (0) - -#define CPU_CLR_ATOMIC(n, p) \ - atomic_clear_long(&(p)->__bits[__cpuset_word(n)], __cpuset_mask(n)) - -#define CPU_SET_ATOMIC(n, p) \ - atomic_set_long(&(p)->__bits[__cpuset_word(n)], __cpuset_mask(n)) - -/* Convenience functions catering special cases. */ -#define CPU_OR_ATOMIC(d, s) do { \ - __size_t __i; \ - for (__i = 0; __i < _NCPUWORDS; __i++) \ - atomic_set_long(&(d)->__bits[__i], \ - (s)->__bits[__i]); \ -} while (0) - -#define CPU_COPY_STORE_REL(f, t) do { \ - __size_t __i; \ - for (__i = 0; __i < _NCPUWORDS; __i++) \ - atomic_store_rel_long(&(t)->__bits[__i], \ - (f)->__bits[__i]); \ -} while (0) - /* * Valid cpulevel_t values. */ Index: sys/_bitset.h =================================================================== --- sys/_bitset.h (revision 0) +++ sys/_bitset.h (revision 250256) @@ -0,0 +1,61 @@ +/*- + * Copyright (c) 2008, Jeffrey Roberson + * All rights reserved. + * + * Copyright (c) 2008 Nokia Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS__BITSET_H_ +#define _SYS__BITSET_H_ + +/* + * Macros addressing word and bit within it, tuned to make compiler + * optimize cases when SETSIZE fits into single machine word. + */ +#define _BITSET_BITS (sizeof(long) * NBBY) + +#define __bitset_words(_s) (howmany(_s, _BITSET_BITS)) + +#define __bitset_mask(_s, n) \ + (1L << ((__bitset_words((_s)) == 1) ? \ + (__size_t)(n) : ((n) % _BITSET_BITS))) + +#define __bitset_word(_s, n) \ + ((__bitset_words((_s)) == 1) ? 0 : ((n) / _BITSET_BITS)) + +#define BITSET_DEFINE(t, _s) \ +struct t { \ + long __bits[__bitset_words((_s))]; \ +}; + +#define BITSET_T_INITIALIZER(x) \ + { .__bits = { x } } + +#define BITSET_FSET(n) \ + [ 0 ... ((n) - 1) ] = (-1L) + +#endif /* !_SYS__BITSET_H_ */ Property changes on: sys/_bitset.h ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H Added: svn:eol-style ## -0,0 +1 ## +native Index: sys/_cpuset.h =================================================================== --- sys/_cpuset.h (revision 250255) +++ sys/_cpuset.h (revision 250256) @@ -32,6 +32,8 @@ #ifndef _SYS__CPUSET_H_ #define _SYS__CPUSET_H_ +#include + #ifdef _KERNEL #define CPU_SETSIZE MAXCPU #endif @@ -42,17 +44,11 @@ #define CPU_SETSIZE CPU_MAXSIZE #endif -#define _NCPUBITS (sizeof(long) * NBBY) /* bits per mask */ -#define _NCPUWORDS howmany(CPU_SETSIZE, _NCPUBITS) +#define _NCPUWORDS __bitset_words(CPU_SETSIZE) -typedef struct _cpuset { - long __bits[howmany(CPU_SETSIZE, _NCPUBITS)]; -} cpuset_t; +BITSET_DEFINE(_cpuset, CPU_SETSIZE); +typedef struct _cpuset cpuset_t; -#define CPUSET_FSET \ - [ 0 ... (_NCPUWORDS - 1) ] = (-1L) +#define CPUSET_FSET BITSET_FSET(_NCPUWORDS) -#define CPUSET_T_INITIALIZER(x) \ - { .__bits = { x } } - #endif /* !_SYS__CPUSET_H_ */ Index: sys/bitset.h =================================================================== --- sys/bitset.h (revision 0) +++ sys/bitset.h (revision 250256) @@ -0,0 +1,153 @@ +/*- + * Copyright (c) 2008, Jeffrey Roberson + * All rights reserved. + * + * Copyright (c) 2008 Nokia Corporation + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * $FreeBSD$ + */ + +#ifndef _SYS_BITSET_H_ +#define _SYS_BITSET_H_ + +#define BIT_CLR(_s, n, p) \ + ((p)->__bits[__bitset_word(_s, n)] &= ~__bitset_mask((_s), (n))) + +#define BIT_COPY(_s, f, t) (void)(*(t) = *(f)) + +#define BIT_ISSET(_s, n, p) \ + ((((p)->__bits[__bitset_word(_s, n)] & __bitset_mask((_s), (n))) != 0)) + +#define BIT_SET(_s, n, p) \ + ((p)->__bits[__bitset_word(_s, n)] |= __bitset_mask((_s), (n))) + +#define BIT_ZERO(_s, p) do { \ + __size_t __i; \ + for (__i = 0; __i < __bitset_words((_s)); __i++) \ + (p)->__bits[__i] = 0L; \ +} while (0) + +#define BIT_FILL(_s, p) do { \ + __size_t __i; \ + for (__i = 0; __i < __bitset_words((_s)); __i++) \ + (p)->__bits[__i] = -1L; \ +} while (0) + +#define BIT_SETOF(_s, n, p) do { \ + BIT_ZERO(_s, p); \ + (p)->__bits[__bitset_word(_s, n)] = __bitset_mask((_s), (n)); \ +} while (0) + +/* Is p empty. */ +#define BIT_EMPTY(_s, p) __extension__ ({ \ + __size_t __i; \ + for (__i = 0; __i < __bitset_words((_s)); __i++) \ + if ((p)->__bits[__i]) \ + break; \ + __i == __bitset_words((_s)); \ +}) + +/* Is p full set. */ +#define BIT_ISFULLSET(_s, p) __extension__ ({ \ + __size_t __i; \ + for (__i = 0; __i < __bitset_words((_s)); __i++) \ + if ((p)->__bits[__i] != (long)-1) \ + break; \ + __i == __bitset_words((_s)); \ +}) + +/* Is c a subset of p. */ +#define BIT_SUBSET(_s, p, c) __extension__ ({ \ + __size_t __i; \ + for (__i = 0; __i < __bitset_words((_s)); __i++) \ + if (((c)->__bits[__i] & \ + (p)->__bits[__i]) != \ + (c)->__bits[__i]) \ + break; \ + __i == __bitset_words((_s)); \ +}) + +/* Are there any common bits between b & c? */ +#define BIT_OVERLAP(_s, p, c) __extension__ ({ \ + __size_t __i; \ + for (__i = 0; __i < __bitset_words((_s)); __i++) \ + if (((c)->__bits[__i] & \ + (p)->__bits[__i]) != 0) \ + break; \ + __i != __bitset_words((_s)); \ +}) + +/* Compare two sets, returns 0 if equal 1 otherwise. */ +#define BIT_CMP(_s, p, c) __extension__ ({ \ + __size_t __i; \ + for (__i = 0; __i < __bitset_words((_s)); __i++) \ + if (((c)->__bits[__i] != \ + (p)->__bits[__i])) \ + break; \ + __i != __bitset_words((_s)); \ +}) + +#define BIT_OR(_s, d, s) do { \ + __size_t __i; \ + for (__i = 0; __i < __bitset_words((_s)); __i++) \ + (d)->__bits[__i] |= (s)->__bits[__i]; \ +} while (0) + +#define BIT_AND(_s, d, s) do { \ + __size_t __i; \ + for (__i = 0; __i < __bitset_words((_s)); __i++) \ + (d)->__bits[__i] &= (s)->__bits[__i]; \ +} while (0) + +#define BIT_NAND(_s, d, s) do { \ + __size_t __i; \ + for (__i = 0; __i < __bitset_words((_s)); __i++) \ + (d)->__bits[__i] &= ~(s)->__bits[__i]; \ +} while (0) + +#define BIT_CLR_ATOMIC(_s, n, p) \ + atomic_clear_long(&(p)->__bits[__bitset_word(_s, n)], \ + __bitset_mask((_s), n)) + +#define BIT_SET_ATOMIC(_s, n, p) \ + atomic_set_long(&(p)->__bits[__bitset_word(_s, n)], \ + __bitset_mask((_s), n)) + +/* Convenience functions catering special cases. */ +#define BIT_OR_ATOMIC(_s, d, s) do { \ + __size_t __i; \ + for (__i = 0; __i < __bitset_words((_s)); __i++) \ + atomic_set_long(&(d)->__bits[__i], \ + (s)->__bits[__i]); \ +} while (0) + +#define BIT_COPY_STORE_REL(_s, f, t) do { \ + __size_t __i; \ + for (__i = 0; __i < __bitset_words((_s)); __i++) \ + atomic_store_rel_long(&(t)->__bits[__i], \ + (f)->__bits[__i]); \ +} while (0) + +#endif /* !_SYS_BITSET_H_ */ Property changes on: sys/bitset.h ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native Added: svn:mime-type ## -0,0 +1 ## +text/plain Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H Index: sparc64/sparc64/swtch.S =================================================================== --- sparc64/sparc64/swtch.S (revision 250255) +++ sparc64/sparc64/swtch.S (revision 250256) @@ -172,7 +172,7 @@ ENTRY(cpu_switch) * Mark the pmap of the last non-kernel vmspace to run as no longer * active on this CPU. */ - mov _NCPUBITS, %l5 + mov _BITSET_BITS, %l5 mov %g0, %y udiv %l3, %l5, %l6 srl %l6, 0, %l4 @@ -241,7 +241,7 @@ ENTRY(cpu_switch) /* * Mark the pmap as active on this CPU. */ - mov _NCPUBITS, %l5 + mov _BITSET_BITS, %l5 mov %g0, %y udiv %l3, %l5, %l6 srl %l6, 0, %l4 Index: sparc64/sparc64/intr_machdep.c =================================================================== --- sparc64/sparc64/intr_machdep.c (revision 250255) +++ sparc64/sparc64/intr_machdep.c (revision 250256) @@ -456,7 +456,7 @@ intr_describe(int vec, void *ih, const char *descr * allocate CPUs round-robin. */ -static cpuset_t intr_cpus = CPUSET_T_INITIALIZER(0x1); +static cpuset_t intr_cpus = BITSET_T_INITIALIZER(0x1); static int current_cpu; static void Index: sparc64/sparc64/mp_exception.S =================================================================== --- sparc64/sparc64/mp_exception.S (revision 250255) +++ sparc64/sparc64/mp_exception.S (revision 250256) @@ -41,7 +41,7 @@ __FBSDID("$FreeBSD$"); #define IPI_DONE(r1, r2, r3, r4, r5, r6) \ rd %y, r6 ; \ lduw [PCPU(CPUID)], r2 ; \ - mov _NCPUBITS, r3 ; \ + mov _BITSET_BITS, r3 ; \ mov %g0, %y ; \ udiv r2, r3, r4 ; \ srl r4, 0, r5 ; \ Index: sparc64/sparc64/genassym.c =================================================================== --- sparc64/sparc64/genassym.c (revision 250255) +++ sparc64/sparc64/genassym.c (revision 250256) @@ -58,7 +58,7 @@ ASSYM(PCPU_PAGES, PCPU_PAGES); ASSYM(TAR_VPN_SHIFT, TAR_VPN_SHIFT); -ASSYM(_NCPUBITS, _NCPUBITS); +ASSYM(_BITSET_BITS, _BITSET_BITS); ASSYM(TLB_DEMAP_ALL, TLB_DEMAP_ALL); ASSYM(TLB_DEMAP_CONTEXT, TLB_DEMAP_CONTEXT); Index: sparc64/include/ktr.h =================================================================== --- sparc64/include/ktr.h (revision 250255) +++ sparc64/include/ktr.h (revision 250256) @@ -81,7 +81,7 @@ l2: add r2, 1, r3 ; \ brz r1, l3 ## f ; \ nop ; \ lduw [PCPU(CPUID)], r2 ; \ - mov _NCPUBITS, r3 ; \ + mov _BITSET_BITS, r3 ; \ mov %g0, %y ; \ udiv r2, r3, r2 ; \ srl r2, 0, r2 ; \ @@ -89,7 +89,7 @@ l2: add r2, 1, r3 ; \ SET(ktr_cpumask, r3, r1) ; \ ldx [r1 + r2], r1 ; \ lduw [PCPU(CPUID)], r2 ; \ - mov _NCPUBITS, r3 ; \ + mov _BITSET_BITS, r3 ; \ mov %g0, %y ; \ udiv r2, r3, r2 ; \ srl r2, 0, r2 ; \ Index: x86/x86/intr_machdep.c =================================================================== --- x86/x86/intr_machdep.c (revision 250255) +++ x86/x86/intr_machdep.c (revision 250256) @@ -452,7 +452,7 @@ DB_SHOW_COMMAND(irqs, db_show_irqs) * allocate CPUs round-robin. */ -static cpuset_t intr_cpus = CPUSET_T_INITIALIZER(0x1); +static cpuset_t intr_cpus = BITSET_T_INITIALIZER(0x1); static int current_cpu; /*