Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys - Add kcpuset_isotherset() and kcpuset_countset().



details:   https://anonhg.NetBSD.org/src/rev/bcf318d14bd8
branches:  trunk
changeset: 773250:bcf318d14bd8
user:      rmind <rmind%NetBSD.org@localhost>
date:      Sun Jan 29 19:08:26 2012 +0000

description:
- Add kcpuset_isotherset() and kcpuset_countset().
- Fix KC_NFIELDS_EARLY.  Make kcpuset_isset() return bool.

diffstat:

 sys/kern/subr_kcpuset.c |  58 ++++++++++++++++++++++++++++++++++++------------
 sys/sys/kcpuset.h       |   6 +++-
 2 files changed, 47 insertions(+), 17 deletions(-)

diffs (156 lines):

diff -r e586010f3896 -r bcf318d14bd8 sys/kern/subr_kcpuset.c
--- a/sys/kern/subr_kcpuset.c   Sun Jan 29 18:55:12 2012 +0000
+++ b/sys/kern/subr_kcpuset.c   Sun Jan 29 19:08:26 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_kcpuset.c,v 1.3 2011/08/07 21:38:32 rmind Exp $   */
+/*     $NetBSD: subr_kcpuset.c,v 1.4 2012/01/29 19:08:26 rmind Exp $   */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_kcpuset.c,v 1.3 2011/08/07 21:38:32 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_kcpuset.c,v 1.4 2012/01/29 19:08:26 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -87,7 +87,7 @@
 static bool                    kc_initialised = false;
 
 #define        KC_BITSIZE_EARLY        sizeof(kc_bits_early[0])
-#define        KC_NFIELDS_EARLY        (KC_BITSIZE_EARLY >> KC_SHIFT)
+#define        KC_NFIELDS_EARLY        1
 
 /*
  * The size of whole bitset fields and amount of fields.
@@ -113,6 +113,7 @@
        /* Set a kcpuset_t sizes. */
        kc_nfields = (KC_MAXCPUS >> KC_SHIFT);
        kc_bitsize = sizeof(uint32_t) * kc_nfields;
+       KASSERT(kc_nfields != 0 && kc_bitsize != 0);
 
        kc_cache = pool_cache_init(sizeof(kcpuset_impl_t) + kc_bitsize,
            coherency_unit, 0, 0, "kcpuset", NULL, IPL_NONE, NULL, NULL, NULL);
@@ -232,19 +233,11 @@
 }
 
 /*
- * Routines to copy or reference/unreference the CPU set.
+ * Routines to reference/unreference the CPU set.
  * Note: early boot case is not supported by these routines.
  */
 
 void
-kcpuset_copy(kcpuset_t *dkcp, kcpuset_t *skcp)
-{
-
-       KASSERT(!kc_initialised || KC_GETSTRUCT(dkcp)->kc_refcnt == 1);
-       memcpy(dkcp, skcp, kc_bitsize);
-}
-
-void
 kcpuset_use(kcpuset_t *kcp)
 {
        kcpuset_impl_t *kc = KC_GETSTRUCT(kcp);
@@ -311,9 +304,9 @@
 }
 
 /*
- * Routines to change bit field - zero, fill, set, unset, etc.
+ * Routines to change bit field - zero, fill, copy, set, unset, etc.
  */
- 
+
 void
 kcpuset_zero(kcpuset_t *kcp)
 {
@@ -333,6 +326,15 @@
 }
 
 void
+kcpuset_copy(kcpuset_t *dkcp, kcpuset_t *skcp)
+{
+
+       KASSERT(!kc_initialised || KC_GETSTRUCT(dkcp)->kc_refcnt > 0);
+       KASSERT(!kc_initialised || KC_GETSTRUCT(dkcp)->kc_next == NULL);
+       memcpy(dkcp, skcp, kc_bitsize);
+}
+
+void
 kcpuset_set(kcpuset_t *kcp, cpuid_t i)
 {
        const size_t j = i >> KC_SHIFT;
@@ -354,7 +356,7 @@
        kcp->bits[j] &= ~(1 << (i & KC_MASK));
 }
 
-int
+bool
 kcpuset_isset(kcpuset_t *kcp, cpuid_t i)
 {
        const size_t j = i >> KC_SHIFT;
@@ -368,6 +370,21 @@
 }
 
 bool
+kcpuset_isotherset(kcpuset_t *kcp, cpuid_t i)
+{
+       const size_t j2 = i >> KC_SHIFT;
+       const uint32_t mask = ~(1 << (i & KC_MASK));
+
+       for (size_t j = 0; j < kc_nfields; j++) {
+               const uint32_t bits = kcp->bits[j];
+               if (bits && (j != j2 || (bits & mask) != 0)) {
+                       return true;
+               }
+       }
+       return false;
+}
+
+bool
 kcpuset_iszero(kcpuset_t *kcp)
 {
 
@@ -395,6 +412,17 @@
        }
 }
 
+int
+kcpuset_countset(kcpuset_t *kcp)
+{
+       int count = 0;
+
+       for (size_t j = 0; j < kc_nfields; j++) {
+               count += popcount32(kcp->bits[j]);
+       }
+       return count;
+}
+
 /*
  * Routines to set/clear the flags atomically.
  */
diff -r e586010f3896 -r bcf318d14bd8 sys/sys/kcpuset.h
--- a/sys/sys/kcpuset.h Sun Jan 29 18:55:12 2012 +0000
+++ b/sys/sys/kcpuset.h Sun Jan 29 19:08:26 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kcpuset.h,v 1.3 2011/08/08 17:53:29 matt Exp $ */
+/*     $NetBSD: kcpuset.h,v 1.4 2012/01/29 19:08:26 rmind Exp $        */
 
 /*-
  * Copyright (c) 2008, 2011 The NetBSD Foundation, Inc.
@@ -56,10 +56,12 @@
 void           kcpuset_set(kcpuset_t *, cpuid_t);
 void           kcpuset_clear(kcpuset_t *, cpuid_t);
 
-int            kcpuset_isset(kcpuset_t *, cpuid_t);
+bool           kcpuset_isset(kcpuset_t *, cpuid_t);
+bool           kcpuset_isotherset(kcpuset_t *, cpuid_t);
 bool           kcpuset_iszero(kcpuset_t *);
 bool           kcpuset_match(const kcpuset_t *, const kcpuset_t *);
 void           kcpuset_merge(kcpuset_t *, kcpuset_t *);
+int            kcpuset_countset(kcpuset_t *);
 
 void           kcpuset_atomic_set(kcpuset_t *, cpuid_t);
 void           kcpuset_atomic_clear(kcpuset_t *, cpuid_t);



Home | Main Index | Thread Index | Old Index