From nobody Fri Jan 14 18:10:26 2022 X-Original-To: dev-commits-src-branches@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 578BF1942B0D; Fri, 14 Jan 2022 18:10:28 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Jb8VC462Kz4pGg; Fri, 14 Jan 2022 18:10:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642183827; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=/piWN2X4Vvvszwahth/yr2wDFpyhSspkMHSHWTKG0MY=; b=aUsd6tbJm5jn0fdLE6clUSCT80hWWWQygz8lWBzpV9CRG28HAvehqq6g6U1eW+x8XCOKQQ vBIQwVMqTfB0qvKeMbUB+sy+Bcd/lai/yf9aU4ZIF/KPMk+PzEvrcBuAUP8o4lLrfv9RQg bcFJpxGO5dJ9I+bUw1rEO1a0MKoPMjfaF78SACBpE8957FENYCr/Kr6aprpk1SPkW+dQ8Y UzqaJolZgnLtJVnFSBXGdULUs432B2gHf8/2vM4nED6ludt/G4PkVlhG5QB9ZbKFuxH2sv q5gwE6qZElaBqGWj6A/U+td0pnVZgWbEep8vlnLG6RacRYsnyW4rRTWa63DrTA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 11C5518575; Fri, 14 Jan 2022 18:10:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 20EIAQBw095485; Fri, 14 Jan 2022 18:10:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 20EIAQVA095484; Fri, 14 Jan 2022 18:10:26 GMT (envelope-from git) Date: Fri, 14 Jan 2022 18:10:26 GMT Message-Id: <202201141810.20EIAQVA095484@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 379bfb2aa9e9 - stable/13 - sys/bitset.h: reduce visibility of BIT_* macros List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 379bfb2aa9e940d1ddb6ed3fd113a543c0db3572 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1642183827; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=/piWN2X4Vvvszwahth/yr2wDFpyhSspkMHSHWTKG0MY=; b=w+nTNo5yDMzFz3nmV4hCQfdSVHGnnEo58BiGNi/FqIqxVFzCJ7N4LuZXwwhX42YNZ2ImJJ 7yvqrO5ws9KBlX1ye5dSRf+ivZl1At6sKO/jiOFhz2d9Ki1BJ96PPYPN8spzzwL9LESi34 PaLaNVK6sds267yM/jC40gt+QlHwcJB/K7aOqckQldbcHA6H5msmTctQAhj4ERIohTdAFU bseXwJDHY6/Vlpa8EEJump88WXOlrg33QLvwDOnYFt4/N/TUxxvrhDqj4B6G3/vsXab5z7 lwB7/tN5iITwdn3FJMpNYKuBCDRfNtyA1EoQPqKfo+YEoY+hllz3A+r/oNsNCA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1642183827; a=rsa-sha256; cv=none; b=mzkrbyy8nxLxoEKRm3ItaDgtbR4OmzVabSPz/HrSJmmvE+fJWK6JbMOuQWm4ygzE2rijUT c4MXmzTEmiGgus2t1ujld0PgC+WhiG3xW2Y6WtI8wj2iuiQkRKZVpl4JkMVFOxiPVEzFwG oOaZCplI/PsK1yb6h6UKl0CoqKGvOifm+lq4Zlq3SKbgksnRLShQZUw7vdaK5uX+IqitA5 hCEcPV3n8lockWhGOMEpnjqk3D6n++1rtdbYlnTa1D9NoALGsPOIwKeeMkMr3fSYdmO3Wy j7TUPJqu+qmb3IdVs9K4Vdn6V+Wh1CaIHzTAET2v7n5TOcmQX1ndGg1/74SxyA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=379bfb2aa9e940d1ddb6ed3fd113a543c0db3572 commit 379bfb2aa9e940d1ddb6ed3fd113a543c0db3572 Author: Stefan Eßer AuthorDate: 2021-12-05 21:27:33 +0000 Commit: Konstantin Belousov CommitDate: 2022-01-14 16:17:30 +0000 sys/bitset.h: reduce visibility of BIT_* macros (cherry picked from commit 5e04571cf3cf4024be926976a6abf19626df30be) --- include/sched.h | 4 -- lib/libmemstat/memstat_uma.c | 2 + sbin/pfctl/pfctl_altq.c | 1 + sbin/pfctl/pfctl_parser.h | 2 +- share/man/man9/bitset.9 | 25 +++++++++ sys/sys/_bitset.h | 13 +++-- sys/sys/_cpuset.h | 2 +- sys/sys/_domainset.h | 2 +- sys/sys/bitset.h | 130 +++++++++++++++++++++++++++++-------------- sys/sys/cpuset.h | 58 +++++++++---------- sys/sys/domainset.h | 52 ++++++++--------- tests/sys/sys/bitset_test.c | 2 + usr.bin/cpuset/cpuset.c | 2 + 13 files changed, 186 insertions(+), 109 deletions(-) diff --git a/include/sched.h b/include/sched.h index 02b0d5e51e94..e03f076febb1 100644 --- a/include/sched.h +++ b/include/sched.h @@ -33,20 +33,16 @@ #include #include #if __BSD_VISIBLE -#ifdef _WITH_CPU_SET_T #include struct _cpuset; typedef struct _cpuset cpu_set_t; -#endif /* _WITH_CPU_SET_T */ #endif /* __BSD_VISIBLE */ __BEGIN_DECLS #if __BSD_VISIBLE -#ifdef _WITH_CPU_SET_T int sched_getaffinity(pid_t pid, size_t cpusetsz, cpuset_t *cpuset); int sched_setaffinity(pid_t pid, size_t cpusetsz, const cpuset_t *cpuset); int sched_getcpu(void); -#endif /* _WITH_CPU_SET_T */ #endif /* __BSD_VISIBLE */ __END_DECLS diff --git a/lib/libmemstat/memstat_uma.c b/lib/libmemstat/memstat_uma.c index b416cbc63297..980a674ab76e 100644 --- a/lib/libmemstat/memstat_uma.c +++ b/lib/libmemstat/memstat_uma.c @@ -28,6 +28,8 @@ * $FreeBSD$ */ +#define _WANT_FREEBSD_BITSET + #include #include #include diff --git a/sbin/pfctl/pfctl_altq.c b/sbin/pfctl/pfctl_altq.c index 8067b0598361..7b709040f162 100644 --- a/sbin/pfctl/pfctl_altq.c +++ b/sbin/pfctl/pfctl_altq.c @@ -22,6 +22,7 @@ __FBSDID("$FreeBSD$"); #define PFIOC_USE_LATEST +#define _WANT_FREEBSD_BITSET #include #include diff --git a/sbin/pfctl/pfctl_parser.h b/sbin/pfctl/pfctl_parser.h index 4e144b97567b..0cd19a560f8d 100644 --- a/sbin/pfctl/pfctl_parser.h +++ b/sbin/pfctl/pfctl_parser.h @@ -184,7 +184,7 @@ struct node_queue_opt { }; #define QPRI_BITSET_SIZE 256 -BITSET_DEFINE(qpri_bitset, QPRI_BITSET_SIZE); +__BITSET_DEFINE(qpri_bitset, QPRI_BITSET_SIZE); LIST_HEAD(gen_sc, segment); struct pfctl_altq { diff --git a/share/man/man9/bitset.9 b/share/man/man9/bitset.9 index 1a5ec05b01c6..e6ce3d9b4f58 100644 --- a/share/man/man9/bitset.9 +++ b/share/man/man9/bitset.9 @@ -164,6 +164,7 @@ .Fo BIT_COPY_STORE_REL .Fa "const SETSIZE" "struct STRUCTNAME *from" "struct STRUCTNAME *to" .Fc +.Fd #define _WANT_FREEBSD_BITSET .Sh DESCRIPTION The .Nm @@ -179,6 +180,16 @@ One example use of is .In sys/cpuset.h . .Pp +These macros are meant to be used in the kernel and are visible if +.Dv _KERNEL is defined when +.In sys/_bitset.h +or +.In sys/bitset.h +are included in a program. +Userland programs must define +.Dv _WANT_FREEBSD_BITSET +before including these files to make the macros visible. +.Pp The .Fn BITSET_DEFINE macro defines a bitset struct @@ -584,3 +595,17 @@ Unlike every other reference to individual set members, which are zero-indexed, and .Fn BIT_FLS return a one-indexed result (or zero if the set is empty). +.Pp +In order to use the macros defined in +.In sys/bitset.h +and +.In sys/_bitset.h +in userland programs, +.Dv _WANT_FREEBSD_BITSET +has to be defined before including the header files. +This requirements exists to prevent a name space pollution due to macros defined in +.Nm +in programs that include +.In sys/cpuset.h +or +.In sched.h . diff --git a/sys/sys/_bitset.h b/sys/sys/_bitset.h index e54f04cbeee7..1c167daf3f09 100644 --- a/sys/sys/_bitset.h +++ b/sys/sys/_bitset.h @@ -44,8 +44,8 @@ #define __bitset_words(_s) (__howmany(_s, _BITSET_BITS)) -#define BITSET_DEFINE(t, _s) \ -struct t { \ +#define __BITSET_DEFINE(_t, _s) \ +struct _t { \ long __bits[__bitset_words((_s))]; \ } @@ -55,12 +55,17 @@ struct t { \ * Sadly we cannot declare a bitset struct with '__bits[]', because it's * the only member of the struct and the compiler complains. */ -#define BITSET_DEFINE_VAR(t) BITSET_DEFINE(t, 1) +#define __BITSET_DEFINE_VAR(_t) __BITSET_DEFINE(_t, 1) /* * Define a default type that can be used while manually specifying size * to every call. */ -BITSET_DEFINE(bitset, 1); +__BITSET_DEFINE(bitset, 1); + +#if defined(_KERNEL) || defined(_WANT_FREEBSD_BITSET) +#define BITSET_DEFINE(_t, _s) __BITSET_DEFINE(_t, _s) +#define BITSET_DEFINE_VAR(_t) __BITSET_DEFINE_VAR(_t) +#endif #endif /* !_SYS__BITSET_H_ */ diff --git a/sys/sys/_cpuset.h b/sys/sys/_cpuset.h index cb3c0f9d586e..9033acb9ba14 100644 --- a/sys/sys/_cpuset.h +++ b/sys/sys/_cpuset.h @@ -46,7 +46,7 @@ #define CPU_SETSIZE CPU_MAXSIZE #endif -BITSET_DEFINE(_cpuset, CPU_SETSIZE); +__BITSET_DEFINE(_cpuset, CPU_SETSIZE); typedef struct _cpuset cpuset_t; #endif /* !_SYS__CPUSET_H_ */ diff --git a/sys/sys/_domainset.h b/sys/sys/_domainset.h index 5685d532a9e3..443c68fd331b 100644 --- a/sys/sys/_domainset.h +++ b/sys/sys/_domainset.h @@ -43,7 +43,7 @@ #define DOMAINSET_SETSIZE DOMAINSET_MAXSIZE #endif -BITSET_DEFINE(_domainset, DOMAINSET_SETSIZE); +__BITSET_DEFINE(_domainset, DOMAINSET_SETSIZE); typedef struct _domainset domainset_t; /* diff --git a/sys/sys/bitset.h b/sys/sys/bitset.h index 1c154d5601ab..91a5e6e37db3 100644 --- a/sys/sys/bitset.h +++ b/sys/sys/bitset.h @@ -48,36 +48,36 @@ (__constexpr_cond(__bitset_words((_s)) == 1) ? \ 0 : ((n) / _BITSET_BITS)) -#define BIT_CLR(_s, n, p) \ +#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_COPY(_s, f, t) (void)(*(t) = *(f)) -#define BIT_ISSET(_s, n, p) \ +#define __BIT_ISSET(_s, n, p) \ ((((p)->__bits[__bitset_word(_s, n)] & __bitset_mask((_s), (n))) != 0)) -#define BIT_SET(_s, n, p) \ +#define __BIT_SET(_s, n, p) \ ((p)->__bits[__bitset_word(_s, n)] |= __bitset_mask((_s), (n))) -#define BIT_ZERO(_s, p) do { \ +#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 { \ +#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); \ +#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__ ({ \ +#define __BIT_EMPTY(_s, p) __extension__ ({ \ __size_t __i; \ for (__i = 0; __i < __bitset_words((_s)); __i++) \ if ((p)->__bits[__i]) \ @@ -86,7 +86,7 @@ }) /* Is p full set. */ -#define BIT_ISFULLSET(_s, p) __extension__ ({ \ +#define __BIT_ISFULLSET(_s, p) __extension__ ({ \ __size_t __i; \ for (__i = 0; __i < __bitset_words((_s)); __i++) \ if ((p)->__bits[__i] != (long)-1) \ @@ -95,7 +95,7 @@ }) /* Is c a subset of p. */ -#define BIT_SUBSET(_s, p, c) __extension__ ({ \ +#define __BIT_SUBSET(_s, p, c) __extension__ ({ \ __size_t __i; \ for (__i = 0; __i < __bitset_words((_s)); __i++) \ if (((c)->__bits[__i] & \ @@ -106,7 +106,7 @@ }) /* Are there any common bits between b & c? */ -#define BIT_OVERLAP(_s, p, c) __extension__ ({ \ +#define __BIT_OVERLAP(_s, p, c) __extension__ ({ \ __size_t __i; \ for (__i = 0; __i < __bitset_words((_s)); __i++) \ if (((c)->__bits[__i] & \ @@ -116,7 +116,7 @@ }) /* Compare two sets, returns 0 if equal 1 otherwise. */ -#define BIT_CMP(_s, p, c) __extension__ ({ \ +#define __BIT_CMP(_s, p, c) __extension__ ({ \ __size_t __i; \ for (__i = 0; __i < __bitset_words((_s)); __i++) \ if (((c)->__bits[__i] != \ @@ -125,49 +125,49 @@ __i != __bitset_words((_s)); \ }) -#define BIT_OR(_s, d, s) do { \ +#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_OR2(_s, d, s1, s2) do { \ +#define __BIT_OR2(_s, d, s1, s2) do { \ __size_t __i; \ for (__i = 0; __i < __bitset_words((_s)); __i++) \ (d)->__bits[__i] = (s1)->__bits[__i] | (s2)->__bits[__i];\ } while (0) -#define BIT_AND(_s, d, s) do { \ +#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_AND2(_s, d, s1, s2) do { \ +#define __BIT_AND2(_s, d, s1, s2) do { \ __size_t __i; \ for (__i = 0; __i < __bitset_words((_s)); __i++) \ (d)->__bits[__i] = (s1)->__bits[__i] & (s2)->__bits[__i];\ } while (0) -#define BIT_ANDNOT(_s, d, s) do { \ +#define __BIT_ANDNOT(_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_ANDNOT2(_s, d, s1, s2) do { \ +#define __BIT_ANDNOT2(_s, d, s1, s2) do { \ __size_t __i; \ for (__i = 0; __i < __bitset_words((_s)); __i++) \ (d)->__bits[__i] = (s1)->__bits[__i] & ~(s2)->__bits[__i];\ } while (0) -#define BIT_XOR(_s, d, s) do { \ +#define __BIT_XOR(_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_XOR2(_s, d, s1, s2) do { \ +#define __BIT_XOR2(_s, d, s1, s2) do { \ __size_t __i; \ for (__i = 0; __i < __bitset_words((_s)); __i++) \ (d)->__bits[__i] = (s1)->__bits[__i] ^ (s2)->__bits[__i];\ @@ -179,42 +179,42 @@ * or a bit index. */ -#define BIT_CLR_ATOMIC(_s, n, p) \ +#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) \ +#define __BIT_SET_ATOMIC(_s, n, p) \ atomic_set_long(&(p)->__bits[__bitset_word(_s, n)], \ __bitset_mask((_s), n)) -#define BIT_SET_ATOMIC_ACQ(_s, n, p) \ +#define __BIT_SET_ATOMIC_ACQ(_s, n, p) \ atomic_set_acq_long(&(p)->__bits[__bitset_word(_s, n)], \ __bitset_mask((_s), n)) -#define BIT_TEST_CLR_ATOMIC(_s, n, p) \ +#define __BIT_TEST_CLR_ATOMIC(_s, n, p) \ (atomic_testandclear_long( \ &(p)->__bits[__bitset_word((_s), (n))], (n)) != 0) -#define BIT_TEST_SET_ATOMIC(_s, n, p) \ +#define __BIT_TEST_SET_ATOMIC(_s, n, p) \ (atomic_testandset_long( \ &(p)->__bits[__bitset_word((_s), (n))], (n)) != 0) /* Convenience functions catering special cases. */ -#define BIT_AND_ATOMIC(_s, d, s) do { \ +#define __BIT_AND_ATOMIC(_s, d, s) do { \ __size_t __i; \ for (__i = 0; __i < __bitset_words((_s)); __i++) \ atomic_clear_long(&(d)->__bits[__i], \ ~(s)->__bits[__i]); \ } while (0) -#define BIT_OR_ATOMIC(_s, d, s) do { \ +#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 { \ +#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], \ @@ -222,10 +222,10 @@ } while (0) /* - * Note that `start` and the returned value from BIT_FFS_AT are + * Note that `start` and the returned value from __BIT_FFS_AT are * 1-based bit indices. */ -#define BIT_FFS_AT(_s, p, start) __extension__ ({ \ +#define __BIT_FFS_AT(_s, p, start) __extension__ ({ \ __size_t __i; \ long __bit, __mask; \ \ @@ -244,9 +244,9 @@ __bit; \ }) -#define BIT_FFS(_s, p) BIT_FFS_AT((_s), (p), 0) +#define __BIT_FFS(_s, p) __BIT_FFS_AT((_s), (p), 0) -#define BIT_FLS(_s, p) __extension__ ({ \ +#define __BIT_FLS(_s, p) __extension__ ({ \ __size_t __i; \ long __bit; \ \ @@ -261,7 +261,7 @@ __bit; \ }) -#define BIT_COUNT(_s, p) __extension__ ({ \ +#define __BIT_COUNT(_s, p) __extension__ ({ \ __size_t __i; \ long __count; \ \ @@ -271,7 +271,7 @@ __count; \ }) -#define _BIT_FOREACH_ADVANCE(_s, i, p, op) __extension__ ({ \ +#define __BIT_FOREACH_ADVANCE(_s, i, p, op) __extension__ ({ \ int __found; \ for (;;) { \ if (__bits != 0) { \ @@ -293,24 +293,68 @@ /* * Non-destructively loop over all set or clear bits in the set. */ -#define _BIT_FOREACH(_s, i, p, op) \ +#define __BIT_FOREACH(_s, i, p, op) \ for (long __i = -1, __bits = 0; \ - _BIT_FOREACH_ADVANCE(_s, i, p, op); ) + __BIT_FOREACH_ADVANCE(_s, i, p, op); ) -#define BIT_FOREACH_ISSET(_s, i, p) _BIT_FOREACH(_s, i, p, ) -#define BIT_FOREACH_ISCLR(_s, i, p) _BIT_FOREACH(_s, i, p, ~) +#define __BIT_FOREACH_ISSET(_s, i, p) __BIT_FOREACH(_s, i, p, ) +#define __BIT_FOREACH_ISCLR(_s, i, p) __BIT_FOREACH(_s, i, p, ~) -#define BITSET_T_INITIALIZER(x) \ +#define __BITSET_T_INITIALIZER(x) \ { .__bits = { x } } -#define BITSET_FSET(n) \ +#define __BITSET_FSET(n) \ [ 0 ... ((n) - 1) ] = (-1L) -#define BITSET_SIZE(_s) (__bitset_words((_s)) * sizeof(long)) +#define __BITSET_SIZE(_s) (__bitset_words((_s)) * sizeof(long)) /* * Dynamically allocate a bitset. */ -#define BITSET_ALLOC(_s, mt, mf) malloc(BITSET_SIZE((_s)), mt, (mf)) +#define __BITSET_ALLOC(_s, mt, mf) malloc(__BITSET_SIZE((_s)), mt, (mf)) + +#if defined(_KERNEL) || defined(_WANT_FREEBSD_BITSET) +#define BIT_AND(_s, d, s) __BIT_AND(_s, d, s) +#define BIT_AND2(_s, d, s1, s2) __BIT_AND2(_s, d, s1, s2) +#define BIT_ANDNOT(_s, d, s) __BIT_ANDNOT(_s, d, s) +#define BIT_ANDNOT2(_s, d, s1, s2) __BIT_ANDNOT2(_s, d, s1, s2) +#define BIT_AND_ATOMIC(_s, d, s) __BIT_AND_ATOMIC(_s, d, s) +#define BIT_CLR(_s, n, p) __BIT_CLR(_s, n, p) +#define BIT_CLR_ATOMIC(_s, n, p) __BIT_CLR_ATOMIC(_s, n, p) +#define BIT_CMP(_s, p, c) __BIT_CMP(_s, p, c) +#define BIT_COPY(_s, f, t) __BIT_COPY(_s, f, t) +#define BIT_COPY_STORE_REL(_s, f, t) __BIT_COPY_STORE_REL(_s, f, t) +#define BIT_COUNT(_s, p) __BIT_COUNT(_s, p) +#define BIT_EMPTY(_s, p) __BIT_EMPTY(_s, p) +#define BIT_FFS(_s, p) __BIT_FFS(_s, p) +#define BIT_FFS_AT(_s, p, start) __BIT_FFS_AT(_s, p, start) +#define BIT_FILL(_s, p) __BIT_FILL(_s, p) +#define BIT_FLS(_s, p) __BIT_FLS(_s, p) +#define BIT_FOREACH(_s, i, p, op) __BIT_FOREACH(_s, i, p, op) +#define BIT_FOREACH_ADVANCE(_s, i, p, op) __BIT_FOREACH_ADVANCE(_s, i, p, op) +#define BIT_FOREACH_ISCLR(_s, i, p) __BIT_FOREACH_ISCLR(_s, i, p) +#define BIT_FOREACH_ISSET(_s, i, p) __BIT_FOREACH_ISSET(_s, i, p) +#define BIT_ISFULLSET(_s, p) __BIT_ISFULLSET(_s, p) +#define BIT_ISSET(_s, n, p) __BIT_ISSET(_s, n, p) +#define BIT_OR(_s, d, s) __BIT_OR(_s, d, s) +#define BIT_OR2(_s, d, s1, s2) __BIT_OR2(_s, d, s1, s2) +#define BIT_OR_ATOMIC(_s, d, s) __BIT_OR_ATOMIC(_s, d, s) +#define BIT_OVERLAP(_s, p, c) __BIT_OVERLAP(_s, p, c) +#define BIT_SET(_s, n, p) __BIT_SET(_s, n, p) +#define BIT_SETOF(_s, n, p) __BIT_SETOF(_s, n, p) +#define BIT_SET_ATOMIC(_s, n, p) __BIT_SET_ATOMIC(_s, n, p) +#define BIT_SET_ATOMIC_ACQ(_s, n, p) __BIT_SET_ATOMIC_ACQ(_s, n, p) +#define BIT_SUBSET(_s, p, c) __BIT_SUBSET(_s, p, c) +#define BIT_TEST_CLR_ATOMIC(_s, n, p) __BIT_TEST_CLR_ATOMIC(_s, n, p) +#define BIT_TEST_SET_ATOMIC(_s, n, p) __BIT_TEST_SET_ATOMIC(_s, n, p) +#define BIT_XOR(_s, d, s) __BIT_XOR(_s, d, s) +#define BIT_XOR2(_s, d, s1, s2) __BIT_XOR2(_s, d, s1, s2) +#define BIT_ZERO(_s, p) __BIT_ZERO(_s, p) + +#define BITSET_ALLOC(_s, mt, mf) __BITSET_ALLOC(_s, mt, mf) +#define BITSET_FSET(n) __BITSET_FSET(n) +#define BITSET_SIZE(_s) __BITSET_SIZE(_s) +#define BITSET_T_INITIALIZER(x) __BITSET_T_INITIALIZER(x) +#endif #endif /* !_SYS_BITSET_H_ */ diff --git a/sys/sys/cpuset.h b/sys/sys/cpuset.h index 602f73fbe5e4..71317670c593 100644 --- a/sys/sys/cpuset.h +++ b/sys/sys/cpuset.h @@ -43,35 +43,35 @@ #define CPUSETBUFSIZ ((2 + sizeof(long) * 2) * _NCPUWORDS) -#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_EQUAL(p, c) (BIT_CMP(CPU_SETSIZE, p, c) == 0) -#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_ANDNOT(d, s) BIT_ANDNOT(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_SET_ATOMIC_ACQ(n, p) BIT_SET_ATOMIC_ACQ(CPU_SETSIZE, n, p) -#define CPU_AND_ATOMIC(n, p) BIT_AND_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_FFS(p) BIT_FFS(CPU_SETSIZE, p) -#define CPU_FLS(p) BIT_FLS(CPU_SETSIZE, p) -#define CPU_FOREACH_ISSET(i, p) BIT_FOREACH_ISSET(CPU_SETSIZE, i, p) -#define CPU_FOREACH_ISCLR(i, p) BIT_FOREACH_ISCLR(CPU_SETSIZE, i, p) -#define CPU_COUNT(p) ((int)BIT_COUNT(CPU_SETSIZE, p)) -#define CPUSET_FSET BITSET_FSET(_NCPUWORDS) -#define CPUSET_T_INITIALIZER BITSET_T_INITIALIZER +#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_EQUAL(p, c) (__BIT_CMP(CPU_SETSIZE, p, c) == 0) +#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_ANDNOT(d, s) __BIT_ANDNOT(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_SET_ATOMIC_ACQ(n, p) __BIT_SET_ATOMIC_ACQ(CPU_SETSIZE, n, p) +#define CPU_AND_ATOMIC(n, p) __BIT_AND_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_FFS(p) __BIT_FFS(CPU_SETSIZE, p) +#define CPU_FLS(p) __BIT_FLS(CPU_SETSIZE, p) +#define CPU_FOREACH_ISSET(i, p) __BIT_FOREACH_ISSET(CPU_SETSIZE, i, p) +#define CPU_FOREACH_ISCLR(i, p) __BIT_FOREACH_ISCLR(CPU_SETSIZE, i, p) +#define CPU_COUNT(p) ((int)__BIT_COUNT(CPU_SETSIZE, p)) +#define CPUSET_FSET __BITSET_FSET(_NCPUWORDS) +#define CPUSET_T_INITIALIZER(x) __BITSET_T_INITIALIZER(x) /* * Valid cpulevel_t values. diff --git a/sys/sys/domainset.h b/sys/sys/domainset.h index 2113196d8d26..51b5011fcb4e 100644 --- a/sys/sys/domainset.h +++ b/sys/sys/domainset.h @@ -43,34 +43,34 @@ sizeof("::") + sizeof(__XSTRING(DOMAINSET_POLICY_MAX)) + \ sizeof(__XSTRING(MAXMEMDOM))) -#define DOMAINSET_CLR(n, p) BIT_CLR(DOMAINSET_SETSIZE, n, p) -#define DOMAINSET_COPY(f, t) BIT_COPY(DOMAINSET_SETSIZE, f, t) -#define DOMAINSET_ISSET(n, p) BIT_ISSET(DOMAINSET_SETSIZE, n, p) -#define DOMAINSET_SET(n, p) BIT_SET(DOMAINSET_SETSIZE, n, p) -#define DOMAINSET_ZERO(p) BIT_ZERO(DOMAINSET_SETSIZE, p) -#define DOMAINSET_FILL(p) BIT_FILL(DOMAINSET_SETSIZE, p) -#define DOMAINSET_SETOF(n, p) BIT_SETOF(DOMAINSET_SETSIZE, n, p) -#define DOMAINSET_EMPTY(p) BIT_EMPTY(DOMAINSET_SETSIZE, p) -#define DOMAINSET_ISFULLSET(p) BIT_ISFULLSET(DOMAINSET_SETSIZE, p) -#define DOMAINSET_SUBSET(p, c) BIT_SUBSET(DOMAINSET_SETSIZE, p, c) -#define DOMAINSET_OVERLAP(p, c) BIT_OVERLAP(DOMAINSET_SETSIZE, p, c) -#define DOMAINSET_CMP(p, c) BIT_CMP(DOMAINSET_SETSIZE, p, c) -#define DOMAINSET_OR(d, s) BIT_OR(DOMAINSET_SETSIZE, d, s) -#define DOMAINSET_AND(d, s) BIT_AND(DOMAINSET_SETSIZE, d, s) -#define DOMAINSET_ANDNOT(d, s) BIT_ANDNOT(DOMAINSET_SETSIZE, d, s) -#define DOMAINSET_CLR_ATOMIC(n, p) BIT_CLR_ATOMIC(DOMAINSET_SETSIZE, n, p) -#define DOMAINSET_SET_ATOMIC(n, p) BIT_SET_ATOMIC(DOMAINSET_SETSIZE, n, p) +#define DOMAINSET_CLR(n, p) __BIT_CLR(DOMAINSET_SETSIZE, n, p) +#define DOMAINSET_COPY(f, t) __BIT_COPY(DOMAINSET_SETSIZE, f, t) +#define DOMAINSET_ISSET(n, p) __BIT_ISSET(DOMAINSET_SETSIZE, n, p) +#define DOMAINSET_SET(n, p) __BIT_SET(DOMAINSET_SETSIZE, n, p) +#define DOMAINSET_ZERO(p) __BIT_ZERO(DOMAINSET_SETSIZE, p) +#define DOMAINSET_FILL(p) __BIT_FILL(DOMAINSET_SETSIZE, p) +#define DOMAINSET_SETOF(n, p) __BIT_SETOF(DOMAINSET_SETSIZE, n, p) +#define DOMAINSET_EMPTY(p) __BIT_EMPTY(DOMAINSET_SETSIZE, p) +#define DOMAINSET_ISFULLSET(p) __BIT_ISFULLSET(DOMAINSET_SETSIZE, p) +#define DOMAINSET_SUBSET(p, c) __BIT_SUBSET(DOMAINSET_SETSIZE, p, c) +#define DOMAINSET_OVERLAP(p, c) __BIT_OVERLAP(DOMAINSET_SETSIZE, p, c) +#define DOMAINSET_CMP(p, c) __BIT_CMP(DOMAINSET_SETSIZE, p, c) +#define DOMAINSET_OR(d, s) __BIT_OR(DOMAINSET_SETSIZE, d, s) +#define DOMAINSET_AND(d, s) __BIT_AND(DOMAINSET_SETSIZE, d, s) +#define DOMAINSET_ANDNOT(d, s) __BIT_ANDNOT(DOMAINSET_SETSIZE, d, s) +#define DOMAINSET_CLR_ATOMIC(n, p) __BIT_CLR_ATOMIC(DOMAINSET_SETSIZE, n, p) +#define DOMAINSET_SET_ATOMIC(n, p) __BIT_SET_ATOMIC(DOMAINSET_SETSIZE, n, p) #define DOMAINSET_SET_ATOMIC_ACQ(n, p) \ - BIT_SET_ATOMIC_ACQ(DOMAINSET_SETSIZE, n, p) -#define DOMAINSET_AND_ATOMIC(n, p) BIT_AND_ATOMIC(DOMAINSET_SETSIZE, n, p) -#define DOMAINSET_OR_ATOMIC(d, s) BIT_OR_ATOMIC(DOMAINSET_SETSIZE, d, s) + __BIT_SET_ATOMIC_ACQ(DOMAINSET_SETSIZE, n, p) +#define DOMAINSET_AND_ATOMIC(n, p) __BIT_AND_ATOMIC(DOMAINSET_SETSIZE, n, p) +#define DOMAINSET_OR_ATOMIC(d, s) __BIT_OR_ATOMIC(DOMAINSET_SETSIZE, d, s) #define DOMAINSET_COPY_STORE_REL(f, t) \ - BIT_COPY_STORE_REL(DOMAINSET_SETSIZE, f, t) -#define DOMAINSET_FFS(p) BIT_FFS(DOMAINSET_SETSIZE, p) -#define DOMAINSET_FLS(p) BIT_FLS(DOMAINSET_SETSIZE, p) -#define DOMAINSET_COUNT(p) ((int)BIT_COUNT(DOMAINSET_SETSIZE, p)) -#define DOMAINSET_FSET BITSET_FSET(_NDOMAINSETWORDS) -#define DOMAINSET_T_INITIALIZER BITSET_T_INITIALIZER + __BIT_COPY_STORE_REL(DOMAINSET_SETSIZE, f, t) +#define DOMAINSET_FFS(p) __BIT_FFS(DOMAINSET_SETSIZE, p) +#define DOMAINSET_FLS(p) __BIT_FLS(DOMAINSET_SETSIZE, p) +#define DOMAINSET_COUNT(p) ((int)__BIT_COUNT(DOMAINSET_SETSIZE, p)) +#define DOMAINSET_FSET __BITSET_FSET(_NDOMAINSETWORDS) +#define DOMAINSET_T_INITIALIZER(x) __BITSET_T_INITIALIZER(x) #define DOMAINSET_POLICY_INVALID 0 #define DOMAINSET_POLICY_ROUNDROBIN 1 diff --git a/tests/sys/sys/bitset_test.c b/tests/sys/sys/bitset_test.c index 781b523dae97..d193d2e3014c 100644 --- a/tests/sys/sys/bitset_test.c +++ b/tests/sys/sys/bitset_test.c @@ -7,6 +7,8 @@ * the FreeBSD Foundation. */ +#define _WANT_FREEBSD_BITSET + #include #include #include diff --git a/usr.bin/cpuset/cpuset.c b/usr.bin/cpuset/cpuset.c index e039030415bb..79c6c2b6ca79 100644 --- a/usr.bin/cpuset/cpuset.c +++ b/usr.bin/cpuset/cpuset.c @@ -32,6 +32,8 @@ #include __FBSDID("$FreeBSD$"); +#define _WANT_FREEBSD_BITSET + #include #include #include