Some constification.

Add kcpuset_clone, kcpuset_insersection, kcpuset_remove,
kcpuset_ffs, kcpuset_ffs_intersecting,
kcpuset_atomicly_merge, kcpuset_atomicly_intersect, kcpuset_atomicly_remove
This commit is contained in:
matt 2013-07-17 22:36:26 +00:00
parent 495e7e8d6b
commit 6e660710b6
3 changed files with 211 additions and 26 deletions

View File

@ -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 "kcpuset_t * kcp" "cpuid_t cpu"
.Fn kcpuset_isotherset "const kcpuset_t * kcp" "cpuid_t cpu"
.Ft bool
.Fn kcpuset_iszero "kcpuset_t *kcp"
.Fn kcpuset_iszero "const kcpuset_t *kcp"
.Ft bool
.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 @@ set pointed by
.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 @@ Compares the sets
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 @@ from the
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

View File

@ -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 @@ typedef struct kcpuset_impl {
#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
@ -217,6 +218,13 @@ kcpuset_create(kcpuset_t **retkcp, bool zero)
*retkcp = kcpuset_create_raw(zero);
}
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)
{
@ -333,7 +341,7 @@ kcpuset_fill(kcpuset_t *kcp)
}
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 @@ kcpuset_clear(kcpuset_t *kcp, cpuid_t i)
{
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 @@ kcpuset_isotherset(kcpuset_t *kcp, cpuid_t i)
}
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 @@ kcpuset_match(const kcpuset_t *kcp1, const kcpuset_t *kcp2)
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;
}
cpuid_t
kcpuset_ffs_intersecting(const kcpuset_t *kcp1, const kcpuset_t *kcp2)
{
for (size_t j = 0; j < kc_nfields; j++) {
uint32_t bits = kcp1->bits[j] & kcp2->bits[j];
if (bits)
return 32 * j + ffs(bits);
}
return 0;
}
void
kcpuset_merge(kcpuset_t *kcp1, kcpuset_t *kcp2)
kcpuset_merge(kcpuset_t *kcp1, const kcpuset_t *kcp2)
{
for (size_t j = 0; j < kc_nfields; j++) {
@ -420,7 +462,7 @@ kcpuset_merge(kcpuset_t *kcp1, kcpuset_t *kcp2)
}
void
kcpuset_intersect(kcpuset_t *kcp1, kcpuset_t *kcp2)
kcpuset_intersect(kcpuset_t *kcp1, const kcpuset_t *kcp2)
{
for (size_t j = 0; j < kc_nfields; j++) {
@ -428,6 +470,15 @@ kcpuset_intersect(kcpuset_t *kcp1, kcpuset_t *kcp2)
}
}
void
kcpuset_remove(kcpuset_t *kcp1, const kcpuset_t *kcp2)
{
for (size_t j = 0; j < kc_nfields; j++) {
kcp1->bits[j] &= ~kcp2->bits[j];
}
}
int
kcpuset_countset(kcpuset_t *kcp)
{
@ -460,3 +511,33 @@ kcpuset_atomic_clear(kcpuset_t *kcp, cpuid_t i)
KASSERT(j < kc_nfields);
atomic_and_32(&kcp->bits[j], ~(1 << (i & KC_MASK)));
}
void
kcpuset_atomicly_intersect(kcpuset_t *kcp1, const kcpuset_t *kcp2)
{
for (size_t j = 0; j < kc_nfields; j++) {
if (kcp2->bits[j])
atomic_and_32(&kcp1->bits[j], kcp2->bits[j]);
}
}
void
kcpuset_atomicly_merge(kcpuset_t *kcp1, const kcpuset_t *kcp2)
{
for (size_t j = 0; j < kc_nfields; j++) {
if (kcp2->bits[j])
atomic_or_32(&kcp1->bits[j], kcp2->bits[j]);
}
}
void
kcpuset_atomicly_remove(kcpuset_t *kcp1, const kcpuset_t *kcp2)
{
for (size_t j = 0; j < kc_nfields; j++) {
if (kcp2->bits[j])
atomic_and_32(&kcp1->bits[j], ~kcp2->bits[j]);
}
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: kcpuset.h,v 1.8 2012/09/16 22:09:33 rmind Exp $ */
/* $NetBSD: kcpuset.h,v 1.9 2013/07/17 22:36:26 matt Exp $ */
/*-
* Copyright (c) 2008, 2011 The NetBSD Foundation, Inc.
@ -42,8 +42,9 @@ typedef struct kcpuset kcpuset_t;
void kcpuset_sysinit(void);
void kcpuset_create(kcpuset_t **, bool);
void kcpuset_clone(kcpuset_t **, const kcpuset_t *);
void kcpuset_destroy(kcpuset_t *);
void kcpuset_copy(kcpuset_t *, kcpuset_t *);
void kcpuset_copy(kcpuset_t *, const kcpuset_t *);
void kcpuset_use(kcpuset_t *);
void kcpuset_unuse(kcpuset_t *, kcpuset_t **);
@ -56,17 +57,27 @@ void kcpuset_fill(kcpuset_t *);
void kcpuset_set(kcpuset_t *, cpuid_t);
void kcpuset_clear(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_isset(const kcpuset_t *, cpuid_t);
bool kcpuset_isotherset(const kcpuset_t *, cpuid_t);
bool kcpuset_iszero(const kcpuset_t *);
bool kcpuset_intersecting_p(const kcpuset_t *, const kcpuset_t *);
bool kcpuset_match(const kcpuset_t *, const kcpuset_t *);
void kcpuset_merge(kcpuset_t *, kcpuset_t *);
void kcpuset_intersect(kcpuset_t *, kcpuset_t *);
void kcpuset_intersect(kcpuset_t *, const kcpuset_t *);
void kcpuset_merge(kcpuset_t *, const kcpuset_t *);
void kcpuset_remove(kcpuset_t *, const kcpuset_t *);
int kcpuset_countset(kcpuset_t *);
cpuid_t kcpuset_ffs(const kcpuset_t *);
cpuid_t kcpuset_ffs_intersecting(const kcpuset_t *, const kcpuset_t *);
void kcpuset_atomic_set(kcpuset_t *, cpuid_t);
void kcpuset_atomic_clear(kcpuset_t *, cpuid_t);
void kcpuset_atomicly_zero(kcpuset_t *);
void kcpuset_atomicly_intersect(kcpuset_t *, const kcpuset_t *);
void kcpuset_atomicly_merge(kcpuset_t *, const kcpuset_t *);
void kcpuset_atomicly_remove(kcpuset_t *, const kcpuset_t *);
void kcpuset_export_u32(const kcpuset_t *, uint32_t *, size_t);
#endif