Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys - Add an argument to kcpuset_create() for zeroing.
details: https://anonhg.NetBSD.org/src/rev/c70c18645a67
branches: trunk
changeset: 768085:c70c18645a67
user: rmind <rmind%NetBSD.org@localhost>
date: Sun Aug 07 21:38:32 2011 +0000
description:
- Add an argument to kcpuset_create() for zeroing.
- Add kcpuset_atomic_set(), kcpuset_atomic_clear() and kcpuset_merge().
diffstat:
sys/kern/kern_cpu.c | 7 ++---
sys/kern/subr_kcpuset.c | 53 +++++++++++++++++++++++++++++++++++++--------
sys/kern/subr_pserialize.c | 8 +++---
sys/kern/sys_sched.c | 6 ++--
sys/sys/kcpuset.h | 8 +++++-
5 files changed, 59 insertions(+), 23 deletions(-)
diffs (232 lines):
diff -r 584f4c01b3a8 -r c70c18645a67 sys/kern/kern_cpu.c
--- a/sys/kern/kern_cpu.c Sun Aug 07 21:13:05 2011 +0000
+++ b/sys/kern/kern_cpu.c Sun Aug 07 21:38:32 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_cpu.c,v 1.49 2011/08/07 21:13:05 rmind Exp $ */
+/* $NetBSD: kern_cpu.c,v 1.50 2011/08/07 21:38:32 rmind Exp $ */
/*-
* Copyright (c) 2007, 2008, 2009, 2010 The NetBSD Foundation, Inc.
@@ -56,7 +56,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_cpu.c,v 1.49 2011/08/07 21:13:05 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_cpu.c,v 1.50 2011/08/07 21:38:32 rmind Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -134,8 +134,7 @@
if (__predict_false(cpu_infos == NULL)) {
cpu_infos =
kmem_zalloc(sizeof(cpu_infos[0]) * maxcpus, KM_SLEEP);
- kcpuset_create(&kcpuset_attached);
- kcpuset_zero(kcpuset_attached);
+ kcpuset_create(&kcpuset_attached, true);
}
cpu_infos[cpu_index(ci)] = ci;
kcpuset_set(kcpuset_attached, ci->ci_index);
diff -r 584f4c01b3a8 -r c70c18645a67 sys/kern/subr_kcpuset.c
--- a/sys/kern/subr_kcpuset.c Sun Aug 07 21:13:05 2011 +0000
+++ b/sys/kern/subr_kcpuset.c Sun Aug 07 21:38:32 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_kcpuset.c,v 1.2 2011/08/07 21:13:05 rmind Exp $ */
+/* $NetBSD: subr_kcpuset.c,v 1.3 2011/08/07 21:38:32 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.2 2011/08/07 21:13:05 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_kcpuset.c,v 1.3 2011/08/07 21:38:32 rmind Exp $");
#include <sys/param.h>
#include <sys/types.h>
@@ -98,7 +98,7 @@
static pool_cache_t kc_cache __read_mostly;
-static kcpuset_t * kcpuset_create_raw(void);
+static kcpuset_t * kcpuset_create_raw(bool);
/*
* kcpuset_sysinit: initialize the subsystem, transfer early boot cases
@@ -119,8 +119,7 @@
/* First, pre-allocate kcpuset entries. */
for (i = 0; i < kc_last_idx; i++) {
- kcp = kcpuset_create_raw();
- kcpuset_zero(kcp);
+ kcp = kcpuset_create_raw(true);
kc_dynamic[i] = kcp;
}
@@ -188,7 +187,7 @@
*/
static kcpuset_t *
-kcpuset_create_raw(void)
+kcpuset_create_raw(bool zero)
{
kcpuset_impl_t *kc;
@@ -196,13 +195,17 @@
kc->kc_refcnt = 1;
kc->kc_next = NULL;
+ if (zero) {
+ memset(&kc->kc_field, 0, kc_bitsize);
+ }
+
/* Note: return pointer to the actual field of bits. */
KASSERT((uint8_t *)kc + KC_BITS_OFF == (uint8_t *)&kc->kc_field);
return &kc->kc_field;
}
void
-kcpuset_create(kcpuset_t **retkcp)
+kcpuset_create(kcpuset_t **retkcp, bool zero)
{
if (__predict_false(!kc_initialised)) {
@@ -210,7 +213,7 @@
*retkcp = kcpuset_early_ptr(retkcp);
return;
}
- *retkcp = kcpuset_create_raw();
+ *retkcp = kcpuset_create_raw(zero);
}
void
@@ -237,8 +240,7 @@
kcpuset_copy(kcpuset_t *dkcp, kcpuset_t *skcp)
{
- KASSERT(kc_initialised);
- KASSERT(KC_GETSTRUCT(dkcp)->kc_refcnt == 1);
+ KASSERT(!kc_initialised || KC_GETSTRUCT(dkcp)->kc_refcnt == 1);
memcpy(dkcp, skcp, kc_bitsize);
}
@@ -383,3 +385,34 @@
return memcmp(kcp1, kcp2, kc_bitsize) == 0;
}
+
+void
+kcpuset_merge(kcpuset_t *kcp1, kcpuset_t *kcp2)
+{
+
+ for (size_t j = 0; j < kc_nfields; j++) {
+ kcp1->bits[j] |= kcp2->bits[j];
+ }
+}
+
+/*
+ * Routines to set/clear the flags atomically.
+ */
+
+void
+kcpuset_atomic_set(kcpuset_t *kcp, cpuid_t i)
+{
+ const size_t j = i >> KC_SHIFT;
+
+ KASSERT(j < kc_nfields);
+ atomic_or_32(&kcp->bits[j], 1 << (i & KC_MASK));
+}
+
+void
+kcpuset_atomic_clear(kcpuset_t *kcp, cpuid_t i)
+{
+ const size_t j = i >> KC_SHIFT;
+
+ KASSERT(j < kc_nfields);
+ atomic_and_32(&kcp->bits[j], ~(1 << (i & KC_MASK)));
+}
diff -r 584f4c01b3a8 -r c70c18645a67 sys/kern/subr_pserialize.c
--- a/sys/kern/subr_pserialize.c Sun Aug 07 21:13:05 2011 +0000
+++ b/sys/kern/subr_pserialize.c Sun Aug 07 21:38:32 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_pserialize.c,v 1.3 2011/08/07 13:33:01 rmind Exp $ */
+/* $NetBSD: subr_pserialize.c,v 1.4 2011/08/07 21:38:32 rmind Exp $ */
/*-
* Copyright (c) 2010, 2011 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_pserialize.c,v 1.3 2011/08/07 13:33:01 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_pserialize.c,v 1.4 2011/08/07 21:38:32 rmind Exp $");
#include <sys/param.h>
@@ -103,8 +103,8 @@
psz = kmem_zalloc(sizeof(struct pserialize), KM_SLEEP);
cv_init(&psz->psz_notifier, "psrlz");
- kcpuset_create(&psz->psz_target);
- kcpuset_create(&psz->psz_pass);
+ kcpuset_create(&psz->psz_target, true);
+ kcpuset_create(&psz->psz_pass, true);
psz->psz_owner = NULL;
return psz;
diff -r 584f4c01b3a8 -r c70c18645a67 sys/kern/sys_sched.c
--- a/sys/kern/sys_sched.c Sun Aug 07 21:13:05 2011 +0000
+++ b/sys/kern/sys_sched.c Sun Aug 07 21:38:32 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sys_sched.c,v 1.37 2011/08/07 21:13:05 rmind Exp $ */
+/* $NetBSD: sys_sched.c,v 1.38 2011/08/07 21:38:32 rmind Exp $ */
/*
* Copyright (c) 2008, 2011 Mindaugas Rasiukevicius <rmind at NetBSD org>
@@ -42,7 +42,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sys_sched.c,v 1.37 2011/08/07 21:13:05 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_sched.c,v 1.38 2011/08/07 21:38:32 rmind Exp $");
#include <sys/param.h>
@@ -301,7 +301,7 @@
kcpuset_t *kset;
int error;
- kcpuset_create(&kset);
+ kcpuset_create(&kset, false);
error = kcpuset_copyin(sset, kset, size);
if (error) {
kcpuset_unuse(kset, NULL);
diff -r 584f4c01b3a8 -r c70c18645a67 sys/sys/kcpuset.h
--- a/sys/sys/kcpuset.h Sun Aug 07 21:13:05 2011 +0000
+++ b/sys/sys/kcpuset.h Sun Aug 07 21:38:32 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kcpuset.h,v 1.1 2011/08/07 13:33:02 rmind Exp $ */
+/* $NetBSD: kcpuset.h,v 1.2 2011/08/07 21:38:32 rmind Exp $ */
/*-
* Copyright (c) 2008, 2011 The NetBSD Foundation, Inc.
@@ -39,7 +39,7 @@
void kcpuset_sysinit(void);
-void kcpuset_create(kcpuset_t **);
+void kcpuset_create(kcpuset_t **, bool);
void kcpuset_destroy(kcpuset_t *);
void kcpuset_copy(kcpuset_t *, kcpuset_t *);
@@ -57,6 +57,10 @@
int kcpuset_isset(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 *);
+
+void kcpuset_atomic_set(kcpuset_t *, cpuid_t);
+void kcpuset_atomic_clear(kcpuset_t *, cpuid_t);
#endif
Home |
Main Index |
Thread Index |
Old Index