Module Name: src
Committed By: rmind
Date: Sun Jan 29 22:55:40 UTC 2012
Modified Files:
src/sys/kern: init_main.c kern_cpu.c kern_idle.c subr_pserialize.c
sys_sched.c
src/sys/sys: cpu.h cpu_data.h
Log Message:
- Add mi_cpu_init() and initialise cpu_lock and kcpuset_attached/running there.
- Add kcpuset_running which gets set in idle_loop().
- Use kcpuset_running in pserialize_perform().
To generate a diff of this commit:
cvs rdiff -u -r1.439 -r1.440 src/sys/kern/init_main.c
cvs rdiff -u -r1.54 -r1.55 src/sys/kern/kern_cpu.c
cvs rdiff -u -r1.24 -r1.25 src/sys/kern/kern_idle.c
cvs rdiff -u -r1.4 -r1.5 src/sys/kern/subr_pserialize.c
cvs rdiff -u -r1.38 -r1.39 src/sys/kern/sys_sched.c
cvs rdiff -u -r1.34 -r1.35 src/sys/sys/cpu.h
cvs rdiff -u -r1.33 -r1.34 src/sys/sys/cpu_data.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/kern/init_main.c
diff -u src/sys/kern/init_main.c:1.439 src/sys/kern/init_main.c:1.440
--- src/sys/kern/init_main.c:1.439 Tue Jan 24 20:03:36 2012
+++ src/sys/kern/init_main.c Sun Jan 29 22:55:40 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: init_main.c,v 1.439 2012/01/24 20:03:36 christos Exp $ */
+/* $NetBSD: init_main.c,v 1.440 2012/01/29 22:55:40 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.439 2012/01/24 20:03:36 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: init_main.c,v 1.440 2012/01/29 22:55:40 rmind Exp $");
#include "opt_ddb.h"
#include "opt_ipsec.h"
@@ -304,7 +304,7 @@ main(void)
kernel_lock_init();
once_init();
- mutex_init(&cpu_lock, MUTEX_DEFAULT, IPL_NONE);
+ mi_cpu_init();
kernconfig_lock_init();
kthread_sysinit();
Index: src/sys/kern/kern_cpu.c
diff -u src/sys/kern/kern_cpu.c:1.54 src/sys/kern/kern_cpu.c:1.55
--- src/sys/kern/kern_cpu.c:1.54 Tue Jan 17 10:47:27 2012
+++ src/sys/kern/kern_cpu.c Sun Jan 29 22:55:40 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_cpu.c,v 1.54 2012/01/17 10:47:27 cegger Exp $ */
+/* $NetBSD: kern_cpu.c,v 1.55 2012/01/29 22:55:40 rmind Exp $ */
/*-
* Copyright (c) 2007, 2008, 2009, 2010, 2012 The NetBSD Foundation, Inc.
@@ -56,7 +56,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_cpu.c,v 1.54 2012/01/17 10:47:27 cegger Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_cpu.c,v 1.55 2012/01/29 22:55:40 rmind Exp $");
#include "opt_cpu_ucode.h"
@@ -110,13 +110,31 @@ int ncpu __read_mostly;
int ncpuonline __read_mostly;
bool mp_online __read_mostly;
-kcpuset_t * kcpuset_attached __read_mostly;
+/* Note: set on mi_cpu_attach() and idle_loop(). */
+kcpuset_t * kcpuset_attached __read_mostly = NULL;
+kcpuset_t * kcpuset_running __read_mostly = NULL;
struct cpuqueue cpu_queue __cacheline_aligned
= CIRCLEQ_HEAD_INITIALIZER(cpu_queue);
static struct cpu_info **cpu_infos __read_mostly;
+/*
+ * mi_cpu_init: early initialisation of MI CPU related structures.
+ *
+ * Note: may not block and memory allocator is not yet available.
+ */
+void
+mi_cpu_init(void)
+{
+
+ mutex_init(&cpu_lock, MUTEX_DEFAULT, IPL_NONE);
+
+ kcpuset_create(&kcpuset_attached, true);
+ kcpuset_create(&kcpuset_running, true);
+ kcpuset_set(kcpuset_running, 0);
+}
+
int
mi_cpu_attach(struct cpu_info *ci)
{
@@ -125,6 +143,8 @@ mi_cpu_attach(struct cpu_info *ci)
KASSERT(maxcpus > 0);
ci->ci_index = ncpu;
+ kcpuset_set(kcpuset_attached, cpu_index(ci));
+
CIRCLEQ_INSERT_TAIL(&cpu_queue, ci, ci_data.cpu_qchain);
TAILQ_INIT(&ci->ci_data.cpu_ld_locks);
__cpu_simple_lock_init(&ci->ci_data.cpu_ld_lock);
@@ -136,10 +156,8 @@ mi_cpu_attach(struct cpu_info *ci)
if (__predict_false(cpu_infos == NULL)) {
cpu_infos =
kmem_zalloc(sizeof(cpu_infos[0]) * maxcpus, KM_SLEEP);
- kcpuset_create(&kcpuset_attached, true);
}
cpu_infos[cpu_index(ci)] = ci;
- kcpuset_set(kcpuset_attached, ci->ci_index);
sched_cpuattach(ci);
Index: src/sys/kern/kern_idle.c
diff -u src/sys/kern/kern_idle.c:1.24 src/sys/kern/kern_idle.c:1.25
--- src/sys/kern/kern_idle.c:1.24 Mon Jan 17 07:13:31 2011
+++ src/sys/kern/kern_idle.c Sun Jan 29 22:55:40 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: kern_idle.c,v 1.24 2011/01/17 07:13:31 uebayasi Exp $ */
+/* $NetBSD: kern_idle.c,v 1.25 2012/01/29 22:55:40 rmind Exp $ */
/*-
* Copyright (c)2002, 2006, 2007 YAMAMOTO Takashi,
@@ -28,7 +28,7 @@
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_idle.c,v 1.24 2011/01/17 07:13:31 uebayasi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_idle.c,v 1.25 2012/01/29 22:55:40 rmind Exp $");
#include <sys/param.h>
#include <sys/cpu.h>
@@ -49,6 +49,7 @@ idle_loop(void *dummy)
struct schedstate_percpu *spc;
struct lwp *l = curlwp;
+ kcpuset_atomic_set(kcpuset_running, cpu_index(ci));
ci->ci_data.cpu_onproc = l;
/* Update start time for this thread. */
Index: src/sys/kern/subr_pserialize.c
diff -u src/sys/kern/subr_pserialize.c:1.4 src/sys/kern/subr_pserialize.c:1.5
--- src/sys/kern/subr_pserialize.c:1.4 Sun Aug 7 21:38:32 2011
+++ src/sys/kern/subr_pserialize.c Sun Jan 29 22:55:40 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_pserialize.c,v 1.4 2011/08/07 21:38:32 rmind Exp $ */
+/* $NetBSD: subr_pserialize.c,v 1.5 2012/01/29 22:55:40 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.4 2011/08/07 21:38:32 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_pserialize.c,v 1.5 2012/01/29 22:55:40 rmind Exp $");
#include <sys/param.h>
@@ -156,7 +156,7 @@ pserialize_perform(pserialize_t psz)
* other processors.
*/
psz->psz_owner = curlwp;
- kcpuset_copy(psz->psz_target, kcpuset_attached);
+ kcpuset_copy(psz->psz_target, kcpuset_running);
kcpuset_zero(psz->psz_pass);
mutex_spin_enter(&psz_lock);
Index: src/sys/kern/sys_sched.c
diff -u src/sys/kern/sys_sched.c:1.38 src/sys/kern/sys_sched.c:1.39
--- src/sys/kern/sys_sched.c:1.38 Sun Aug 7 21:38:32 2011
+++ src/sys/kern/sys_sched.c Sun Jan 29 22:55:40 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: sys_sched.c,v 1.38 2011/08/07 21:38:32 rmind Exp $ */
+/* $NetBSD: sys_sched.c,v 1.39 2012/01/29 22:55:40 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.38 2011/08/07 21:38:32 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sys_sched.c,v 1.39 2012/01/29 22:55:40 rmind Exp $");
#include <sys/param.h>
@@ -353,8 +353,9 @@ sys__sched_setaffinity(struct lwp *l,
for (CPU_INFO_FOREACH(cii, ici)) {
struct schedstate_percpu *ispc;
- if (kcpuset_isset(kcset, cpu_index(ici)) == 0)
+ if (!kcpuset_isset(kcset, cpu_index(ici))) {
continue;
+ }
ispc = &ici->ci_schedstate;
/* Check that CPU is not in the processor-set */
Index: src/sys/sys/cpu.h
diff -u src/sys/sys/cpu.h:1.34 src/sys/sys/cpu.h:1.35
--- src/sys/sys/cpu.h:1.34 Fri Jan 13 16:05:16 2012
+++ src/sys/sys/cpu.h Sun Jan 29 22:55:40 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu.h,v 1.34 2012/01/13 16:05:16 cegger Exp $ */
+/* $NetBSD: cpu.h,v 1.35 2012/01/29 22:55:40 rmind Exp $ */
/*-
* Copyright (c) 2007 YAMAMOTO Takashi,
@@ -94,7 +94,8 @@ extern kmutex_t cpu_lock;
extern u_int maxcpus;
extern struct cpuqueue cpu_queue;
extern kcpuset_t *kcpuset_attached;
-
+extern kcpuset_t *kcpuset_running;
+
static inline u_int
cpu_index(struct cpu_info *ci)
{
Index: src/sys/sys/cpu_data.h
diff -u src/sys/sys/cpu_data.h:1.33 src/sys/sys/cpu_data.h:1.34
--- src/sys/sys/cpu_data.h:1.33 Thu Feb 17 18:32:29 2011
+++ src/sys/sys/cpu_data.h Sun Jan 29 22:55:40 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: cpu_data.h,v 1.33 2011/02/17 18:32:29 rmind Exp $ */
+/* $NetBSD: cpu_data.h,v 1.34 2012/01/29 22:55:40 rmind Exp $ */
/*-
* Copyright (c) 2004, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -125,6 +125,7 @@ struct cpu_data {
#define ci_core_id ci_data.cpu_core_id
#define ci_smt_id ci_data.cpu_smt_id
-int mi_cpu_attach(struct cpu_info *ci);
+void mi_cpu_init(void);
+int mi_cpu_attach(struct cpu_info *);
#endif /* _SYS_CPU_DATA_H_ */