Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Add kcpuset(9) - a reworked dynamic CPU set implementation f...
details: https://anonhg.NetBSD.org/src/rev/698ff1078a8d
branches: trunk
changeset: 768062:698ff1078a8d
user: rmind <rmind%NetBSD.org@localhost>
date: Sun Aug 07 13:33:01 2011 +0000
description:
Add kcpuset(9) - a reworked dynamic CPU set implementation for kernel.
Suitable for use during the early boot. MD and other implementations
should be replaced with this interface.
Discussed on: tech-kern@
diffstat:
common/lib/libc/sys/cpuset.c | 164 +-----------------
distrib/sets/lists/comp/mi | 3 +-
sys/conf/files | 3 +-
sys/kern/init_main.c | 6 +-
sys/kern/kern_cpu.c | 12 +-
sys/kern/kern_runq.c | 6 +-
sys/kern/subr_kcpuset.c | 386 +++++++++++++++++++++++++++++++++++++++++++
sys/kern/subr_pserialize.c | 15 +-
sys/kern/sys_pset.c | 6 +-
sys/kern/sys_sched.c | 70 ++++---
sys/sys/Makefile | 4 +-
sys/sys/cpu.h | 3 +-
sys/sys/kcpuset.h | 63 +++++++
sys/sys/lwp.h | 3 +-
sys/sys/sched.h | 21 +--
15 files changed, 532 insertions(+), 233 deletions(-)
diffs (truncated from 1143 to 300 lines):
diff -r 792798abe727 -r 698ff1078a8d common/lib/libc/sys/cpuset.c
--- a/common/lib/libc/sys/cpuset.c Sun Aug 07 13:00:35 2011 +0000
+++ b/common/lib/libc/sys/cpuset.c Sun Aug 07 13:33:01 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cpuset.c,v 1.16 2010/09/21 02:03:29 rmind Exp $ */
+/* $NetBSD: cpuset.c,v 1.17 2011/08/07 13:33:02 rmind Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
@@ -32,7 +32,7 @@
#ifndef _STANDALONE
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: cpuset.c,v 1.16 2010/09/21 02:03:29 rmind Exp $");
+__RCSID("$NetBSD: cpuset.c,v 1.17 2011/08/07 13:33:02 rmind Exp $");
#endif /* LIBC_SCCS and not lint */
#include <sys/param.h>
@@ -64,24 +64,11 @@
uint32_t bits[0];
};
-#ifdef _KERNEL
-struct _kcpuset {
- unsigned int nused;
- struct _kcpuset *next;
- uint32_t bits[0];
-};
-#define KCPUSET_SIZE(n) (sizeof( \
- struct { \
- unsigned int nused; \
- struct _kcpuset *next; \
- uint32_t bits[0]; \
- }) + sizeof(uint32_t) * (n))
-#endif
+#ifndef _KERNEL
static size_t cpuset_size = 0;
static size_t cpuset_nentries = 0;
-#ifndef _KERNEL
size_t
/*ARGSUSED*/
_cpuset_size(const cpuset_t *c)
@@ -161,150 +148,5 @@
free(c);
}
-#else
-
-kcpuset_t *
-kcpuset_create(void)
-{
- kcpuset_t *c;
-
- if (cpuset_size == 0) {
- cpuset_nentries = CPUSET_NENTRIES(MAXCPUS);
- cpuset_size = KCPUSET_SIZE(cpuset_nentries);
- }
- c = kmem_zalloc(cpuset_size, KM_SLEEP);
- c->next = NULL;
- c->nused = 1;
- return c;
-}
-
-void
-kcpuset_destroy(kcpuset_t *c)
-{
- kcpuset_t *nc;
-
- while (c) {
- KASSERT(c->nused == 0);
- nc = c->next;
- kmem_free(c, cpuset_size);
- c = nc;
- }
-}
-
-void
-kcpuset_copy(kcpuset_t *d, const kcpuset_t *s)
-{
-
- KASSERT(d->nused == 1);
- memcpy(d->bits, s->bits, cpuset_nentries * sizeof(s->bits[0]));
-}
-
-void
-kcpuset_use(kcpuset_t *c)
-{
-
- atomic_inc_uint(&c->nused);
-}
-
-void
-kcpuset_unuse(kcpuset_t *c, kcpuset_t **lst)
-{
-
- if (atomic_dec_uint_nv(&c->nused) != 0)
- return;
- KASSERT(c->nused == 0);
- KASSERT(c->next == NULL);
- if (lst == NULL) {
- kcpuset_destroy(c);
- return;
- }
- c->next = *lst;
- *lst = c;
-}
-
-int
-kcpuset_copyin(const cpuset_t *u, kcpuset_t *k, size_t len)
-{
-
- KASSERT(k->nused > 0);
- KASSERT(k->next == NULL);
- if (len != CPUSET_SIZE(cpuset_nentries))
- return EINVAL;
- return copyin(u->bits, k->bits, cpuset_nentries * sizeof(k->bits[0]));
-}
-
-int
-kcpuset_copyout(const kcpuset_t *k, cpuset_t *u, size_t len)
-{
-
- KASSERT(k->nused > 0);
- KASSERT(k->next == NULL);
- if (len != CPUSET_SIZE(cpuset_nentries))
- return EINVAL;
- return copyout(k->bits, u->bits, cpuset_nentries * sizeof(u->bits[0]));
-}
-
-void
-kcpuset_zero(kcpuset_t *c)
-{
-
- KASSERT(c->nused > 0);
- KASSERT(c->next == NULL);
- memset(c->bits, 0, cpuset_nentries * sizeof(c->bits[0]));
-}
-
-void
-kcpuset_fill(kcpuset_t *c)
-{
-
- KASSERT(c->nused > 0);
- KASSERT(c->next == NULL);
- memset(c->bits, ~0, cpuset_nentries * sizeof(c->bits[0]));
-}
-
-void
-kcpuset_set(cpuid_t i, kcpuset_t *c)
-{
- const unsigned long j = i >> CPUSET_SHIFT;
-
- KASSERT(c->next == NULL);
- KASSERT(j < cpuset_nentries);
- c->bits[j] |= 1 << (i & CPUSET_MASK);
-}
-
-int
-kcpuset_isset(cpuid_t i, const kcpuset_t *c)
-{
- const unsigned long j = i >> CPUSET_SHIFT;
-
- KASSERT(c != NULL);
- KASSERT(c->nused > 0);
- KASSERT(c->next == NULL);
- KASSERT(j < cpuset_nentries);
- return ((1 << (i & CPUSET_MASK)) & c->bits[j]) != 0;
-}
-
-bool
-kcpuset_iszero(const kcpuset_t *c)
-{
- unsigned long j;
-
- for (j = 0; j < cpuset_nentries; j++)
- if (c->bits[j] != 0)
- return false;
- return true;
-}
-
-bool
-kcpuset_match(const kcpuset_t *c1, const kcpuset_t *c2)
-{
- unsigned long j;
-
- for (j = 0; j < cpuset_nentries; j++)
- if ((c1->bits[j] & c2->bits[j]) != c2->bits[j])
- return false;
- return true;
-}
-
#endif
#endif
diff -r 792798abe727 -r 698ff1078a8d distrib/sets/lists/comp/mi
--- a/distrib/sets/lists/comp/mi Sun Aug 07 13:00:35 2011 +0000
+++ b/distrib/sets/lists/comp/mi Sun Aug 07 13:33:01 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1657 2011/08/06 17:17:39 jruoho Exp $
+# $NetBSD: mi,v 1.1658 2011/08/07 13:33:02 rmind Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -2385,6 +2385,7 @@
./usr/include/sys/ipc.h comp-c-include
./usr/include/sys/joystick.h comp-c-include
./usr/include/sys/kcore.h comp-c-include
+./usr/include/sys/kcpuset.h comp-c-include
./usr/include/sys/kernel.h comp-obsolete obsolete
./usr/include/sys/keylock.h comp-obsolete obsolete
./usr/include/sys/kgdb.h comp-c-include
diff -r 792798abe727 -r 698ff1078a8d sys/conf/files
--- a/sys/conf/files Sun Aug 07 13:00:35 2011 +0000
+++ b/sys/conf/files Sun Aug 07 13:33:01 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files,v 1.1022 2011/07/30 17:01:04 christos Exp $
+# $NetBSD: files,v 1.1023 2011/08/07 13:33:01 rmind Exp $
# @(#)files.newconf 7.5 (Berkeley) 5/10/93
version 20100430
@@ -1530,6 +1530,7 @@
file kern/subr_hash.c
file kern/subr_humanize.c
file kern/subr_iostat.c
+file kern/subr_kcpuset.c
file kern/subr_kmem.c
file kern/subr_kobj.c
file kern/subr_kobj_vfs.c
diff -r 792798abe727 -r 698ff1078a8d sys/kern/init_main.c
--- a/sys/kern/init_main.c Sun Aug 07 13:00:35 2011 +0000
+++ b/sys/kern/init_main.c Sun Aug 07 13:33:01 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: init_main.c,v 1.434 2011/07/30 17:01:04 christos Exp $ */
+/* $NetBSD: init_main.c,v 1.435 2011/08/07 13:33:01 rmind Exp $ */
/*-
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -97,7 +97,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.434 2011/07/30 17:01:04 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.435 2011/08/07 13:33:01 rmind Exp $");
#include "opt_ddb.h"
#include "opt_ipsec.h"
@@ -167,6 +167,7 @@
#include <sys/event.h>
#include <sys/lockf.h>
#include <sys/once.h>
+#include <sys/kcpuset.h>
#include <sys/ksyms.h>
#include <sys/uidinfo.h>
#include <sys/kprintf.h>
@@ -310,6 +311,7 @@
evcnt_init();
uvm_init();
+ kcpuset_sysinit();
prop_kern_init();
diff -r 792798abe727 -r 698ff1078a8d sys/kern/kern_cpu.c
--- a/sys/kern/kern_cpu.c Sun Aug 07 13:00:35 2011 +0000
+++ b/sys/kern/kern_cpu.c Sun Aug 07 13:33:01 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_cpu.c,v 1.47 2011/06/29 06:22:21 matt Exp $ */
+/* $NetBSD: kern_cpu.c,v 1.48 2011/08/07 13:33:01 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.47 2011/06/29 06:22:21 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_cpu.c,v 1.48 2011/08/07 13:33:01 rmind Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -107,6 +107,9 @@
int ncpu __read_mostly;
int ncpuonline __read_mostly;
bool mp_online __read_mostly;
+
+kcpuset_t * kcpuset_attached __read_mostly;
+
struct cpuqueue cpu_queue __cacheline_aligned
= CIRCLEQ_HEAD_INITIALIZER(cpu_queue);
@@ -131,8 +134,11 @@
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);
}
cpu_infos[cpu_index(ci)] = ci;
+ kcpuset_set(kcpuset_attached, ci->ci_index);
Home |
Main Index |
Thread Index |
Old Index