Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Some constification.
details: https://anonhg.NetBSD.org/src/rev/a0df5fbaf31f
branches: trunk
changeset: 788668:a0df5fbaf31f
user: matt <matt%NetBSD.org@localhost>
date: Wed Jul 17 22:36:26 2013 +0000
description:
Some constification.
Add kcpuset_clone, kcpuset_insersection, kcpuset_remove,
kcpuset_ffs, kcpuset_ffs_intersecting,
kcpuset_atomicly_merge, kcpuset_atomicly_intersect, kcpuset_atomicly_remove
diffstat:
share/man/man9/kcpuset.9 | 109 +++++++++++++++++++++++++++++++++++++++++++---
sys/kern/subr_kcpuset.c | 103 +++++++++++++++++++++++++++++++++++++++----
sys/sys/kcpuset.h | 25 +++++++---
3 files changed, 211 insertions(+), 26 deletions(-)
diffs (truncated from 431 to 300 lines):
diff -r 0b3af9bc4f7c -r a0df5fbaf31f share/man/man9/kcpuset.9
--- a/share/man/man9/kcpuset.9 Wed Jul 17 21:58:14 2013 +0000
+++ b/share/man/man9/kcpuset.9 Wed Jul 17 22:36:26 2013 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: kcpuset.9,v 1.5 2013/01/27 15:21:38 pgoyette Exp $ */
+.\" $NetBSD: kcpuset.9,v 1.6 2013/07/17 22:36:26 matt Exp $ */
.\"
.\" Copyright (c) 2011 Jukka Ruohonen <jruohonen.iki.fi>
.\" All rights reserved.
@@ -32,6 +32,7 @@
.Nm kcpuset ,
.Nm kcpuset_create ,
.Nm kcpuset_destroy ,
+.Nm kcpuset_clone ,
.Nm kcpuset_copy ,
.Nm kcpuset_use ,
.Nm kcpuset_unuse ,
@@ -45,10 +46,17 @@
.Nm kcpuset_isotherset ,
.Nm kcpuset_iszero ,
.Nm kcpuset_match ,
+.Nm kcpuset_intersect ,
.Nm kcpuset_merge ,
+.Nm kcpuset_remove ,
+.Nm kcpuset_ffs ,
+.Nm kcpuset_ffs_intersecting ,
.Nm kcpuset_countset ,
.Nm kcpuset_atomic_set ,
-.Nm kcpuset_atomic_clear
+.Nm kcpuset_atomic_clear ,
+.Nm kcpuset_atomicly_intersect ,
+.Nm kcpuset_atomicly_merge ,
+.Nm kcpuset_atomicly_remove ,
.Nm kcpuset_export_32
.Nd dynamic kernel CPU sets
.Sh SYNOPSIS
@@ -58,7 +66,9 @@
.Ft void
.Fn kcpuset_destroy "kcpuset_t *kcp"
.Ft void
-.Fn kcpuset_copy "kcpuset_t *dkcp" "kcpuset_t *skcp"
+.Fn kcpuset_clone "kcpuset_t **retkcp" "const kcpuset_t *skcp"
+.Ft void
+.Fn kcpuset_copy "kcpuset_t *dkcp" "const kcpuset_t *skcp"
.Ft void
.Fn kcpuset_use "kcpuset_t *kcp"
.Ft void
@@ -76,22 +86,38 @@
.Ft void
.Fn kcpuset_clear "kcpuset_t *kcp" "cpuid_t cpu"
.Ft bool
-.Fn kcpuset_isset "kcpuset_t * kcp" "cpuid_t cpu"
+.Fn kcpuset_isset "const kcpuset_t * kcp" "cpuid_t cpu"
+.Ft bool
+.Fn kcpuset_isotherset "const kcpuset_t * kcp" "cpuid_t cpu"
.Ft bool
-.Fn kcpuset_isotherset "kcpuset_t * kcp" "cpuid_t cpu"
+.Fn kcpuset_iszero "const kcpuset_t *kcp"
.Ft bool
-.Fn kcpuset_iszero "kcpuset_t *kcp"
+.Fn kcpuset_intersecting_p "const kcpuset_t *kcp1" "const kcpuset_t *kcp2"
.Ft bool
.Fn kcpuset_match "const kcpuset_t *kcp1" "const kcpuset_t *kcp2"
.Ft void
-.Fn kcpuset_merge "kcpuset_t *kcp1" "kcpuset_t *kcp2"
+.Fn kcpuset_intersect "kcpuset_t *kcp1" "const kcpuset_t *kcp2"
+.Ft void
+.Fn kcpuset_merge "kcpuset_t *kcp1" "const kcpuset_t *kcp2"
+.Ft void
+.Fn kcpuset_remove "kcpuset_t *kcp1" "const kcpuset_t *kcp2"
+.Ft cpuid_t
+.Fn kcpuset_ffs "const kcpuset_t *kcp"
+.Ft cpuid_t
+.Fn kcpuset_ffs_intersecting "const kcpuset_t *kcp1" "const kcpuset_t *kcp2"
.Ft int
-.Fn kcpuset_countset "kcpuset_t *kcp1"
+.Fn kcpuset_countset "const kcpuset_t *kcp"
.Ft void
.Fn kcpuset_atomic_set "kcpuset_t *kcp" "cpuid_t cpu"
.Ft void
.Fn kcpuset_atomic_clear "kcpuset_t *kcp" "cpuid_t cpu"
.Ft void
+.Fn kcpuset_atomicly_intersect "kcpuset_t *kcp1" "const kcpuset_t *kcp2"
+.Ft void
+.Fn kcpuset_atomicly_merge "kcpuset_t *kcp1" "const kcpuset_t *kcp2"
+.Ft void
+.Fn kcpuset_atomicly_remove "kcpuset_t *kcp1" "const kcpuset_t *kcp2"
+.Ft void
.Fn kcpuset_export_u32 "const kcpuset_t *kcp" "uint32_t *bitfield" "size_t len"
.Sh DESCRIPTION
The machine-independent
@@ -127,6 +153,18 @@
.Fa skcp
to
.Fa dkcp .
+.It Fn kcpuset_clone "retkcp" "skcp"
+Creates a dynamic
+.Tn CPU
+set and stores the result to
+.Fa retkcp
+and copies the
+.Tn CPU
+set pointed by
+.Fa skcp
+to the new
+.Tn CPU
+set.
.It Fn kcpuset_use "kcp"
Marks
.Fa kcp
@@ -210,11 +248,42 @@
and
.Fa kcp2 ,
returning true if these are identical.
+.It Fn kcpuset_intersect "kcp1" "kcp2"
+Removes any
+.Tn CPU
+not set in
+.Fa kcp2
+from the set
+.Fa kcp1 .
.It Fn kcpuset_merge "kcp1" "kcp2"
Merges the set
.Fa kcp2
to the set
.Fa kcp1 .
+.It Fn kcpuset_remove "kcp1" "kcp2"
+Removes any
+.Tn CPU
+present in
+.Fa kcp2
+from the set
+.Fa kcp1 .
+.It Fn kcpuset_ffs "kcp"
+Returns the lowest numbered
+.Ft cpu
+present in
+.Fa kcp
+plus 1. If
+.Fa kcp
+is empty, a value of 0 is returned .
+.Fa kcp
+.It Fn kcpuset_ffs_intersecting "kcp1" "kcp2"
+Returns the lowest numbered
+.Ft cpu
+present in the intersection of
+.Fa kcp1
+and
+.Fa kcp2
+plus 1. If the intersection is empty, a value of 0 is returned .
.It Fn kcpuset_countset "kcp"
Counts how many CPUs are in the set
.Fa kcp .
@@ -234,6 +303,30 @@
set
.Fa kcp
atomically.
+.It Fn kcpuset_atomicly_intersect "kcp1" "kcp2"
+The
+.Fn kcpuset_atomicly_intersect
+function operates as
+.Fn kcpuset_intersect ,
+but the operation is performed using atomic operations; see
+.Xr atomic_ops 3
+for more details.
+.It Fn kcpuset_atomicly_merge "kcp1" "kcp2"
+The
+.Fn kcpuset_atomicly_merge
+function operates as
+.Fn kcpuset_merge ,
+but the operation is performed using atomic operations; see
+.Xr atomic_ops 3
+for more details.
+.It Fn kcpuset_atomicly_remove "kcp1" "kcp2"
+The
+.Fn kcpuset_atomicly_remove
+function operates as
+.Fn kcpuset_remove ,
+but the operation is performed using atomic operations; see
+.Xr atomic_ops 3
+for more details.
.It Fn kcpuset_export_u32 "kcp" "bitfield" "len"
Exports the CPU set
.Fa kcp
diff -r 0b3af9bc4f7c -r a0df5fbaf31f sys/kern/subr_kcpuset.c
--- a/sys/kern/subr_kcpuset.c Wed Jul 17 21:58:14 2013 +0000
+++ b/sys/kern/subr_kcpuset.c Wed Jul 17 22:36:26 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_kcpuset.c,v 1.8 2012/09/16 22:09:33 rmind Exp $ */
+/* $NetBSD: subr_kcpuset.c,v 1.9 2013/07/17 22:36:26 matt 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.8 2012/09/16 22:09:33 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_kcpuset.c,v 1.9 2013/07/17 22:36:26 matt Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -72,6 +72,7 @@
#define KC_BITS_OFF (offsetof(struct kcpuset_impl, kc_field))
#define KC_GETSTRUCT(b) ((kcpuset_impl_t *)((char *)(b) - KC_BITS_OFF))
+#define KC_GETCSTRUCT(b) ((const kcpuset_impl_t *)((const char *)(b) - KC_BITS_OFF))
/* Sizes of a single bitset. */
#define KC_SHIFT 5
@@ -218,6 +219,13 @@
}
void
+kcpuset_clone(kcpuset_t **retkcp, const kcpuset_t *kcp)
+{
+ kcpuset_create(retkcp, false);
+ memcpy(*retkcp, kcp, kc_bitsize);
+}
+
+void
kcpuset_destroy(kcpuset_t *kcp)
{
kcpuset_impl_t *kc;
@@ -333,7 +341,7 @@
}
void
-kcpuset_copy(kcpuset_t *dkcp, kcpuset_t *skcp)
+kcpuset_copy(kcpuset_t *dkcp, const kcpuset_t *skcp)
{
KASSERT(!kc_initialised || KC_GETSTRUCT(dkcp)->kc_refcnt > 0);
@@ -357,27 +365,27 @@
{
const size_t j = i >> KC_SHIFT;
- KASSERT(!kc_initialised || KC_GETSTRUCT(kcp)->kc_next == NULL);
+ KASSERT(!kc_initialised || KC_GETCSTRUCT(kcp)->kc_next == NULL);
KASSERT(j < kc_nfields);
kcp->bits[j] &= ~(1 << (i & KC_MASK));
}
bool
-kcpuset_isset(kcpuset_t *kcp, cpuid_t i)
+kcpuset_isset(const kcpuset_t *kcp, cpuid_t i)
{
const size_t j = i >> KC_SHIFT;
KASSERT(kcp != NULL);
- KASSERT(!kc_initialised || KC_GETSTRUCT(kcp)->kc_refcnt > 0);
- KASSERT(!kc_initialised || KC_GETSTRUCT(kcp)->kc_next == NULL);
+ KASSERT(!kc_initialised || KC_GETCSTRUCT(kcp)->kc_refcnt > 0);
+ KASSERT(!kc_initialised || KC_GETCSTRUCT(kcp)->kc_next == NULL);
KASSERT(j < kc_nfields);
return ((1 << (i & KC_MASK)) & kcp->bits[j]) != 0;
}
bool
-kcpuset_isotherset(kcpuset_t *kcp, cpuid_t i)
+kcpuset_isotherset(const kcpuset_t *kcp, cpuid_t i)
{
const size_t j2 = i >> KC_SHIFT;
const uint32_t mask = ~(1 << (i & KC_MASK));
@@ -392,7 +400,7 @@
}
bool
-kcpuset_iszero(kcpuset_t *kcp)
+kcpuset_iszero(const kcpuset_t *kcp)
{
for (size_t j = 0; j < kc_nfields; j++) {
@@ -410,8 +418,42 @@
return memcmp(kcp1, kcp2, kc_bitsize) == 0;
}
+bool
+kcpuset_intersecting_p(const kcpuset_t *kcp1, const kcpuset_t *kcp2)
+{
+
+ for (size_t j = 0; j < kc_nfields; j++) {
+ if (kcp1->bits[j] & kcp2->bits[j])
+ return true;
+ }
+ return false;
+}
+
+cpuid_t
+kcpuset_ffs(const kcpuset_t *kcp)
+{
+
+ for (size_t j = 0; j < kc_nfields; j++) {
+ if (kcp->bits[j])
+ return 32 * j + ffs(kcp->bits[j]);
+ }
+ return 0;
+}
Home |
Main Index |
Thread Index |
Old Index