summaryrefslogtreecommitdiffstats
path: root/sys/kern
diff options
context:
space:
mode:
authorjeff <jeff@FreeBSD.org>2002-11-21 01:22:38 +0000
committerjeff <jeff@FreeBSD.org>2002-11-21 01:22:38 +0000
commit49bf96275f3964fb635238eb94eec3afbc449864 (patch)
treeffffe185be0dc78e5e3c311d7fcb3156b1524543 /sys/kern
parent8fd30b58c6c738e9fb184bb33bf58c140f0fac3a (diff)
downloadFreeBSD-src-49bf96275f3964fb635238eb94eec3afbc449864.zip
FreeBSD-src-49bf96275f3964fb635238eb94eec3afbc449864.tar.gz
- Implement a mechanism for allowing schedulers to place scheduler dependant
data in the scheduler independant structures (proc, ksegrp, kse, thread). - Implement unused stubs for this mechanism in sched_4bsd. Approved by: re Reviewed by: luigi, trb Tested on: x86, alpha
Diffstat (limited to 'sys/kern')
-rw-r--r--sys/kern/init_main.c6
-rw-r--r--sys/kern/kern_kse.c50
-rw-r--r--sys/kern/kern_proc.c12
-rw-r--r--sys/kern/kern_thread.c50
-rw-r--r--sys/kern/sched_4bsd.c25
5 files changed, 96 insertions, 47 deletions
diff --git a/sys/kern/init_main.c b/sys/kern/init_main.c
index 933c25c..4da2377 100644
--- a/sys/kern/init_main.c
+++ b/sys/kern/init_main.c
@@ -64,6 +64,7 @@
#include <sys/vnode.h>
#include <sys/sysent.h>
#include <sys/reboot.h>
+#include <sys/sched.h>
#include <sys/sx.h>
#include <sys/sysproto.h>
#include <sys/vmmeter.h>
@@ -316,6 +317,11 @@ proc0_init(void *dummy __unused)
ke = &kse0;
kg = &ksegrp0;
+ ke->ke_sched = kse0_sched;
+ kg->kg_sched = ksegrp0_sched;
+ p->p_sched = proc0_sched;
+ td->td_sched = thread0_sched;
+
/*
* Initialize magic number.
*/
diff --git a/sys/kern/kern_kse.c b/sys/kern/kern_kse.c
index 6a92914..45ac5c0 100644
--- a/sys/kern/kern_kse.c
+++ b/sys/kern/kern_kse.c
@@ -39,9 +39,10 @@
#include <sys/sysctl.h>
#include <sys/sysproto.h>
#include <sys/filedesc.h>
-#include <sys/tty.h>
+#include <sys/sched.h>
#include <sys/signalvar.h>
#include <sys/sx.h>
+#include <sys/tty.h>
#include <sys/user.h>
#include <sys/jail.h>
#include <sys/kse.h>
@@ -101,9 +102,6 @@ thread_ctor(void *mem, int size, void *arg)
{
struct thread *td;
- KASSERT((size == sizeof(struct thread)),
- ("size mismatch: %d != %d\n", size, (int)sizeof(struct thread)));
-
td = (struct thread *)mem;
td->td_state = TDS_INACTIVE;
td->td_flags |= TDF_UNBOUND;
@@ -117,9 +115,6 @@ thread_dtor(void *mem, int size, void *arg)
{
struct thread *td;
- KASSERT((size == sizeof(struct thread)),
- ("size mismatch: %d != %d\n", size, (int)sizeof(struct thread)));
-
td = (struct thread *)mem;
#ifdef INVARIANTS
@@ -152,14 +147,12 @@ thread_init(void *mem, int size)
{
struct thread *td;
- KASSERT((size == sizeof(struct thread)),
- ("size mismatch: %d != %d\n", size, (int)sizeof(struct thread)));
-
td = (struct thread *)mem;
mtx_lock(&Giant);
pmap_new_thread(td, 0);
mtx_unlock(&Giant);
cpu_thread_setup(td);
+ td->td_sched = (struct td_sched *)&td[1];
}
/*
@@ -170,12 +163,31 @@ thread_fini(void *mem, int size)
{
struct thread *td;
- KASSERT((size == sizeof(struct thread)),
- ("size mismatch: %d != %d\n", size, (int)sizeof(struct thread)));
-
td = (struct thread *)mem;
pmap_dispose_thread(td);
}
+/*
+ * Initialize type-stable parts of a kse (when newly created).
+ */
+static void
+kse_init(void *mem, int size)
+{
+ struct kse *ke;
+
+ ke = (struct kse *)mem;
+ ke->ke_sched = (struct ke_sched *)&ke[1];
+}
+/*
+ * Initialize type-stable parts of a ksegrp (when newly created).
+ */
+static void
+ksegrp_init(void *mem, int size)
+{
+ struct ksegrp *kg;
+
+ kg = (struct ksegrp *)mem;
+ kg->kg_sched = (struct kg_sched *)&kg[1];
+}
/*
* KSE is linked onto the idle queue.
@@ -609,7 +621,7 @@ threadinit(void)
{
#ifndef __ia64__
- thread_zone = uma_zcreate("THREAD", sizeof (struct thread),
+ thread_zone = uma_zcreate("THREAD", sched_sizeof_thread(),
thread_ctor, thread_dtor, thread_init, thread_fini,
UMA_ALIGN_CACHE, 0);
#else
@@ -620,16 +632,16 @@ threadinit(void)
* in the system startup while contigmalloc() still works. Once we
* have them, keep them. Sigh.
*/
- thread_zone = uma_zcreate("THREAD", sizeof (struct thread),
+ thread_zone = uma_zcreate("THREAD", sched_sizeof_thread(),
thread_ctor, thread_dtor, thread_init, thread_fini,
UMA_ALIGN_CACHE, UMA_ZONE_NOFREE);
uma_prealloc(thread_zone, 512); /* XXX arbitary */
#endif
- ksegrp_zone = uma_zcreate("KSEGRP", sizeof (struct ksegrp),
- NULL, NULL, NULL, NULL,
+ ksegrp_zone = uma_zcreate("KSEGRP", sched_sizeof_ksegrp(),
+ NULL, NULL, ksegrp_init, NULL,
UMA_ALIGN_CACHE, 0);
- kse_zone = uma_zcreate("KSE", sizeof (struct kse),
- NULL, NULL, NULL, NULL,
+ kse_zone = uma_zcreate("KSE", sched_sizeof_kse(),
+ NULL, NULL, kse_init, NULL,
UMA_ALIGN_CACHE, 0);
}
diff --git a/sys/kern/kern_proc.c b/sys/kern/kern_proc.c
index a016bba..cf9de34 100644
--- a/sys/kern/kern_proc.c
+++ b/sys/kern/kern_proc.c
@@ -45,6 +45,7 @@
#include <sys/mutex.h>
#include <sys/proc.h>
#include <sys/kse.h>
+#include <sys/sched.h>
#include <sys/smp.h>
#include <sys/sysctl.h>
#include <sys/filedesc.h>
@@ -123,7 +124,7 @@ procinit()
LIST_INIT(&zombproc);
pidhashtbl = hashinit(maxproc / 4, M_PROC, &pidhash);
pgrphashtbl = hashinit(maxproc / 4, M_PROC, &pgrphash);
- proc_zone = uma_zcreate("PROC", sizeof (struct proc),
+ proc_zone = uma_zcreate("PROC", sched_sizeof_proc(),
proc_ctor, proc_dtor, proc_init, proc_fini,
UMA_ALIGN_PTR, UMA_ZONE_NOFREE);
uihashinit();
@@ -137,8 +138,6 @@ proc_ctor(void *mem, int size, void *arg)
{
struct proc *p;
- KASSERT((size == sizeof(struct proc)),
- ("size mismatch: %d != %d\n", size, (int)sizeof(struct proc)));
p = (struct proc *)mem;
}
@@ -154,8 +153,6 @@ proc_dtor(void *mem, int size, void *arg)
struct kse *ke;
/* INVARIANTS checks go here */
- KASSERT((size == sizeof(struct proc)),
- ("size mismatch: %d != %d\n", size, (int)sizeof(struct proc)));
p = (struct proc *)mem;
KASSERT((p->p_numthreads == 1),
("bad number of threads in exiting process"));
@@ -194,9 +191,8 @@ proc_init(void *mem, int size)
struct ksegrp *kg;
struct kse *ke;
- KASSERT((size == sizeof(struct proc)),
- ("size mismatch: %d != %d\n", size, (int)sizeof(struct proc)));
p = (struct proc *)mem;
+ p->p_sched = (struct p_sched *)&p[1];
vm_proc_new(p);
td = thread_alloc();
ke = kse_alloc();
@@ -215,8 +211,6 @@ proc_fini(void *mem, int size)
struct ksegrp *kg;
struct kse *ke;
- KASSERT((size == sizeof(struct proc)),
- ("size mismatch: %d != %d\n", size, (int)sizeof(struct proc)));
p = (struct proc *)mem;
KASSERT((p->p_numthreads == 1),
("bad number of threads in freeing process"));
diff --git a/sys/kern/kern_thread.c b/sys/kern/kern_thread.c
index 6a92914..45ac5c0 100644
--- a/sys/kern/kern_thread.c
+++ b/sys/kern/kern_thread.c
@@ -39,9 +39,10 @@
#include <sys/sysctl.h>
#include <sys/sysproto.h>
#include <sys/filedesc.h>
-#include <sys/tty.h>
+#include <sys/sched.h>
#include <sys/signalvar.h>
#include <sys/sx.h>
+#include <sys/tty.h>
#include <sys/user.h>
#include <sys/jail.h>
#include <sys/kse.h>
@@ -101,9 +102,6 @@ thread_ctor(void *mem, int size, void *arg)
{
struct thread *td;
- KASSERT((size == sizeof(struct thread)),
- ("size mismatch: %d != %d\n", size, (int)sizeof(struct thread)));
-
td = (struct thread *)mem;
td->td_state = TDS_INACTIVE;
td->td_flags |= TDF_UNBOUND;
@@ -117,9 +115,6 @@ thread_dtor(void *mem, int size, void *arg)
{
struct thread *td;
- KASSERT((size == sizeof(struct thread)),
- ("size mismatch: %d != %d\n", size, (int)sizeof(struct thread)));
-
td = (struct thread *)mem;
#ifdef INVARIANTS
@@ -152,14 +147,12 @@ thread_init(void *mem, int size)
{
struct thread *td;
- KASSERT((size == sizeof(struct thread)),
- ("size mismatch: %d != %d\n", size, (int)sizeof(struct thread)));
-
td = (struct thread *)mem;
mtx_lock(&Giant);
pmap_new_thread(td, 0);
mtx_unlock(&Giant);
cpu_thread_setup(td);
+ td->td_sched = (struct td_sched *)&td[1];
}
/*
@@ -170,12 +163,31 @@ thread_fini(void *mem, int size)
{
struct thread *td;
- KASSERT((size == sizeof(struct thread)),
- ("size mismatch: %d != %d\n", size, (int)sizeof(struct thread)));
-
td = (struct thread *)mem;
pmap_dispose_thread(td);
}
+/*
+ * Initialize type-stable parts of a kse (when newly created).
+ */
+static void
+kse_init(void *mem, int size)
+{
+ struct kse *ke;
+
+ ke = (struct kse *)mem;
+ ke->ke_sched = (struct ke_sched *)&ke[1];
+}
+/*
+ * Initialize type-stable parts of a ksegrp (when newly created).
+ */
+static void
+ksegrp_init(void *mem, int size)
+{
+ struct ksegrp *kg;
+
+ kg = (struct ksegrp *)mem;
+ kg->kg_sched = (struct kg_sched *)&kg[1];
+}
/*
* KSE is linked onto the idle queue.
@@ -609,7 +621,7 @@ threadinit(void)
{
#ifndef __ia64__
- thread_zone = uma_zcreate("THREAD", sizeof (struct thread),
+ thread_zone = uma_zcreate("THREAD", sched_sizeof_thread(),
thread_ctor, thread_dtor, thread_init, thread_fini,
UMA_ALIGN_CACHE, 0);
#else
@@ -620,16 +632,16 @@ threadinit(void)
* in the system startup while contigmalloc() still works. Once we
* have them, keep them. Sigh.
*/
- thread_zone = uma_zcreate("THREAD", sizeof (struct thread),
+ thread_zone = uma_zcreate("THREAD", sched_sizeof_thread(),
thread_ctor, thread_dtor, thread_init, thread_fini,
UMA_ALIGN_CACHE, UMA_ZONE_NOFREE);
uma_prealloc(thread_zone, 512); /* XXX arbitary */
#endif
- ksegrp_zone = uma_zcreate("KSEGRP", sizeof (struct ksegrp),
- NULL, NULL, NULL, NULL,
+ ksegrp_zone = uma_zcreate("KSEGRP", sched_sizeof_ksegrp(),
+ NULL, NULL, ksegrp_init, NULL,
UMA_ALIGN_CACHE, 0);
- kse_zone = uma_zcreate("KSE", sizeof (struct kse),
- NULL, NULL, NULL, NULL,
+ kse_zone = uma_zcreate("KSE", sched_sizeof_kse(),
+ NULL, NULL, kse_init, NULL,
UMA_ALIGN_CACHE, 0);
}
diff --git a/sys/kern/sched_4bsd.c b/sys/kern/sched_4bsd.c
index c57262f..236a3c7 100644
--- a/sys/kern/sched_4bsd.c
+++ b/sys/kern/sched_4bsd.c
@@ -51,6 +51,10 @@
#include <sys/sysctl.h>
#include <sys/sx.h>
+struct ke_sched *kse0_sched = NULL;
+struct kg_sched *ksegrp0_sched = NULL;
+struct p_sched *proc0_sched = NULL;
+struct td_sched *thread0_sched = NULL;
static int sched_quantum; /* Roundrobin scheduling quantum in ticks. */
#define SCHED_QUANTUM (hz / 10); /* Default sched quantum */
@@ -618,3 +622,24 @@ sched_userret(struct thread *td)
mtx_unlock_spin(&sched_lock);
}
}
+
+int
+sched_sizeof_kse(void)
+{
+ return (sizeof(struct kse));
+}
+int
+sched_sizeof_ksegrp(void)
+{
+ return (sizeof(struct ksegrp));
+}
+int
+sched_sizeof_proc(void)
+{
+ return (sizeof(struct proc));
+}
+int
+sched_sizeof_thread(void)
+{
+ return (sizeof(struct thread));
+}
OpenPOWER on IntegriCloud