1999-08-19 00:06:53 +00:00
|
|
|
/*
|
2001-02-12 00:20:08 +00:00
|
|
|
* Copyright (c) 2001 Jake Burkholder <jake@FreeBSD.org>
|
|
|
|
* All rights reserved.
|
1999-08-19 00:06:53 +00:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
/***
|
|
|
|
|
|
|
|
Here is the logic..
|
|
|
|
|
|
|
|
If there are N processors, then there are at most N KSEs (kernel
|
|
|
|
schedulable entities) working to process threads that belong to a
|
|
|
|
KSEGOUP (kg). If there are X of these KSEs actually running at the
|
|
|
|
moment in question, then there are at most M (N-X) of these KSEs on
|
|
|
|
the run queue, as running KSEs are not on the queue.
|
|
|
|
|
|
|
|
Runnable threads are queued off the KSEGROUP in priority order.
|
|
|
|
If there are M or more threads runnable, the top M threads
|
|
|
|
(by priority) are 'preassigned' to the M KSEs not running. The KSEs take
|
|
|
|
their priority from those threads and are put on the run queue.
|
|
|
|
|
|
|
|
The last thread that had a priority high enough to have a KSE associated
|
|
|
|
with it, AND IS ON THE RUN QUEUE is pointed to by
|
|
|
|
kg->kg_last_assigned. If no threads queued off the KSEGROUP have KSEs
|
|
|
|
assigned as all the available KSEs are activly running, or because there
|
|
|
|
are no threads queued, that pointer is NULL.
|
|
|
|
|
|
|
|
When a KSE is removed from the run queue to become runnable, we know
|
|
|
|
it was associated with the highest priority thread in the queue (at the head
|
|
|
|
of the queue). If it is also the last assigned we know M was 1 and must
|
|
|
|
now be 0. Since the thread is no longer queued that pointer must be
|
|
|
|
removed from it. Since we know there were no more KSEs available,
|
|
|
|
(M was 1 and is now 0) and since we are not FREEING our KSE
|
|
|
|
but using it, we know there are STILL no more KSEs available, we can prove
|
|
|
|
that the next thread in the ksegrp list will not have a KSE to assign to
|
|
|
|
it, so we can show that the pointer must be made 'invalid' (NULL).
|
|
|
|
|
|
|
|
The pointer exists so that when a new thread is made runnable, it can
|
|
|
|
have its priority compared with the last assigned thread to see if
|
|
|
|
it should 'steal' its KSE or not.. i.e. is it 'earlier'
|
|
|
|
on the list than that thread or later.. If it's earlier, then the KSE is
|
|
|
|
removed from the last assigned (which is now not assigned a KSE)
|
|
|
|
and reassigned to the new thread, which is placed earlier in the list.
|
|
|
|
The pointer is then backed up to the previous thread (which may or may not
|
|
|
|
be the new thread).
|
|
|
|
|
|
|
|
When a thread sleeps or is removed, the KSE becomes available and if there
|
|
|
|
are queued threads that are not assigned KSEs, the highest priority one of
|
|
|
|
them is assigned the KSE, which is then placed back on the run queue at
|
|
|
|
the approipriate place, and the kg->kg_last_assigned pointer is adjusted down
|
|
|
|
to point to it.
|
|
|
|
|
|
|
|
The following diagram shows 2 KSEs and 3 threads from a single process.
|
|
|
|
|
|
|
|
RUNQ: --->KSE---KSE--... (KSEs queued at priorities from threads)
|
|
|
|
\ \____
|
|
|
|
\ \
|
|
|
|
KSEGROUP---thread--thread--thread (queued in priority order)
|
|
|
|
\ /
|
|
|
|
\_______________/
|
|
|
|
(last_assigned)
|
|
|
|
|
|
|
|
The result of this scheme is that the M available KSEs are always
|
|
|
|
queued at the priorities they have inherrited from the M highest priority
|
|
|
|
threads for that KSEGROUP. If this situation changes, the KSEs are
|
|
|
|
reassigned to keep this true.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
1999-08-19 00:06:53 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
2000-09-07 01:33:02 +00:00
|
|
|
#include <sys/ktr.h>
|
2001-03-28 09:17:56 +00:00
|
|
|
#include <sys/lock.h>
|
2000-10-20 07:58:15 +00:00
|
|
|
#include <sys/mutex.h>
|
1999-08-19 00:06:53 +00:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/queue.h>
|
2002-10-12 05:32:24 +00:00
|
|
|
#include <sys/sched.h>
|
2002-04-01 23:51:23 +00:00
|
|
|
#include <machine/critical.h>
|
1999-08-19 00:06:53 +00:00
|
|
|
|
2002-05-25 01:12:23 +00:00
|
|
|
CTASSERT((RQB_BPW * RQB_LEN) == RQ_NQS);
|
|
|
|
|
2002-10-09 02:33:36 +00:00
|
|
|
void panc(char *string1, char *string2);
|
|
|
|
|
|
|
|
#if 0
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
static void runq_readjust(struct runq *rq, struct kse *ke);
|
2002-10-09 02:33:36 +00:00
|
|
|
#endif
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
/************************************************************************
|
|
|
|
* Functions that manipulate runnability from a thread perspective. *
|
|
|
|
************************************************************************/
|
1999-08-19 00:06:53 +00:00
|
|
|
/*
|
2003-02-01 12:17:09 +00:00
|
|
|
* Select the KSE that will be run next. From that find the thread, and x
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
* remove it from the KSEGRP's run queue. If there is thread clustering,
|
|
|
|
* this will be what does it.
|
1999-08-19 00:06:53 +00:00
|
|
|
*/
|
2001-09-12 08:38:13 +00:00
|
|
|
struct thread *
|
|
|
|
choosethread(void)
|
1999-08-19 00:06:53 +00:00
|
|
|
{
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
struct kse *ke;
|
|
|
|
struct thread *td;
|
|
|
|
struct ksegrp *kg;
|
|
|
|
|
2002-07-17 02:23:44 +00:00
|
|
|
retry:
|
2002-10-12 05:32:24 +00:00
|
|
|
if ((ke = sched_choose())) {
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
td = ke->ke_thread;
|
|
|
|
KASSERT((td->td_kse == ke), ("kse/thread mismatch"));
|
|
|
|
kg = ke->ke_ksegrp;
|
2003-02-01 12:17:09 +00:00
|
|
|
if (TD_IS_UNBOUND(td)) {
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
TAILQ_REMOVE(&kg->kg_runq, td, td_runq);
|
2002-09-23 05:27:30 +00:00
|
|
|
if (kg->kg_last_assigned == td) {
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
kg->kg_last_assigned = TAILQ_PREV(td,
|
|
|
|
threadqueue, td_runq);
|
2002-09-23 05:27:30 +00:00
|
|
|
}
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
}
|
|
|
|
kg->kg_runnable--;
|
|
|
|
CTR2(KTR_RUNQ, "choosethread: td=%p pri=%d",
|
|
|
|
td, td->td_priority);
|
|
|
|
} else {
|
2002-07-12 20:16:46 +00:00
|
|
|
/* Simulate runq_choose() having returned the idle thread */
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
td = PCPU_GET(idlethread);
|
2002-08-30 00:25:49 +00:00
|
|
|
ke = td->td_kse;
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
CTR1(KTR_RUNQ, "choosethread: td=%p (idle)", td);
|
|
|
|
}
|
2002-08-30 00:25:49 +00:00
|
|
|
ke->ke_flags |= KEF_DIDRUN;
|
2002-12-28 01:23:07 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Only allow non system threads to run in panic
|
|
|
|
* if they are the one we are tracing. (I think.. [JRE])
|
|
|
|
*/
|
2002-07-17 02:23:44 +00:00
|
|
|
if (panicstr && ((td->td_proc->p_flag & P_SYSTEM) == 0 &&
|
|
|
|
(td->td_flags & TDF_INPANIC) == 0))
|
|
|
|
goto retry;
|
2002-12-28 01:23:07 +00:00
|
|
|
|
2002-09-11 08:13:56 +00:00
|
|
|
TD_SET_RUNNING(td);
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
return (td);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-02-01 12:17:09 +00:00
|
|
|
* Given a KSE (now surplus or at least loanable), either assign a new
|
|
|
|
* runable thread to it (and put it in the run queue) or put it in
|
|
|
|
* the ksegrp's idle KSE list.
|
2002-12-28 01:23:07 +00:00
|
|
|
* Or maybe give it back to its owner if it's been loaned.
|
|
|
|
* Assumes that the original thread is either not runnable or
|
|
|
|
* already on the run queue
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
kse_reassign(struct kse *ke)
|
|
|
|
{
|
|
|
|
struct ksegrp *kg;
|
|
|
|
struct thread *td;
|
2003-02-01 12:17:09 +00:00
|
|
|
struct thread *owner;
|
2002-10-09 02:33:36 +00:00
|
|
|
struct thread *original;
|
2003-02-01 12:17:09 +00:00
|
|
|
int loaned;
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
|
2003-02-01 12:17:09 +00:00
|
|
|
KASSERT((ke->ke_owner), ("reassigning KSE with no owner"));
|
|
|
|
KASSERT((ke->ke_thread && TD_IS_INHIBITED(ke->ke_thread)),
|
|
|
|
("reassigning KSE with no or runnable thread"));
|
2002-09-23 05:27:30 +00:00
|
|
|
mtx_assert(&sched_lock, MA_OWNED);
|
Move UPCALL related data structure out of kse, introduce a new
data structure called kse_upcall to manage UPCALL. All KSE binding
and loaning code are gone.
A thread owns an upcall can collect all completed syscall contexts in
its ksegrp, turn itself into UPCALL mode, and takes those contexts back
to userland. Any thread without upcall structure has to export their
contexts and exit at user boundary.
Any thread running in user mode owns an upcall structure, when it enters
kernel, if the kse mailbox's current thread pointer is not NULL, then
when the thread is blocked in kernel, a new UPCALL thread is created and
the upcall structure is transfered to the new UPCALL thread. if the kse
mailbox's current thread pointer is NULL, then when a thread is blocked
in kernel, no UPCALL thread will be created.
Each upcall always has an owner thread. Userland can remove an upcall by
calling kse_exit, when all upcalls in ksegrp are removed, the group is
atomatically shutdown. An upcall owner thread also exits when process is
in exiting state. when an owner thread exits, the upcall it owns is also
removed.
KSE is a pure scheduler entity. it represents a virtual cpu. when a thread
is running, it always has a KSE associated with it. scheduler is free to
assign a KSE to thread according thread priority, if thread priority is changed,
KSE can be moved from one thread to another.
When a ksegrp is created, there is always N KSEs created in the group. the
N is the number of physical cpu in the current system. This makes it is
possible that even an userland UTS is single CPU safe, threads in kernel still
can execute on different cpu in parallel. Userland calls kse_create to add more
upcall structures into ksegrp to increase concurrent in userland itself, kernel
is not restricted by number of upcalls userland provides.
The code hasn't been tested under SMP by author due to lack of hardware.
Reviewed by: julian
2003-01-26 11:41:35 +00:00
|
|
|
kg = ke->ke_ksegrp;
|
2003-02-01 12:17:09 +00:00
|
|
|
owner = ke->ke_owner;
|
|
|
|
loaned = TD_LENDER(owner);
|
|
|
|
original = ke->ke_thread;
|
|
|
|
|
|
|
|
if (TD_CAN_UNBIND(original) && (original->td_standin)) {
|
|
|
|
KASSERT((owner == original),
|
|
|
|
("Early thread borrowing?"));
|
2002-12-28 01:23:07 +00:00
|
|
|
/*
|
2003-02-01 12:17:09 +00:00
|
|
|
* The outgoing thread is "threaded" and has never
|
|
|
|
* scheduled an upcall.
|
|
|
|
* decide whether this is a short or long term event
|
|
|
|
* and thus whether or not to schedule an upcall.
|
|
|
|
* if it is a short term event, just suspend it in
|
2002-12-28 01:23:07 +00:00
|
|
|
* a way that takes its KSE with it.
|
|
|
|
* Select the events for which we want to schedule upcalls.
|
|
|
|
* For now it's just sleep.
|
2003-02-01 12:17:09 +00:00
|
|
|
* Other threads that still have not fired an upcall
|
|
|
|
* are held to their KSE using the temorary Binding.
|
2002-12-28 01:23:07 +00:00
|
|
|
*/
|
2003-02-01 12:17:09 +00:00
|
|
|
if (TD_ON_SLEEPQ(original)) {
|
|
|
|
/*
|
|
|
|
* An bound thread that can still unbind itself
|
|
|
|
* has been scheduled out.
|
|
|
|
* If it is sleeping, then we need to schedule an
|
|
|
|
* upcall.
|
|
|
|
* XXXKSE eventually almost any inhibition could do.
|
2002-12-28 01:23:07 +00:00
|
|
|
*/
|
|
|
|
original->td_flags &= ~TDF_CAN_UNBIND;
|
2003-02-01 12:17:09 +00:00
|
|
|
original->td_flags |= TDF_UNBOUND;
|
|
|
|
thread_schedule_upcall(original, ke);
|
|
|
|
owner = ke->ke_owner;
|
|
|
|
loaned = 1;
|
2002-12-28 01:23:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-02-01 12:17:09 +00:00
|
|
|
/*
|
|
|
|
* If the current thread was borrowing, then make things consistent
|
|
|
|
* by giving it back to the owner for the moment. The original thread
|
|
|
|
* must be unbound and have already used its chance for
|
|
|
|
* firing off an upcall. Threads that have not yet made an upcall
|
|
|
|
* can not borrow KSEs.
|
|
|
|
*/
|
|
|
|
if (loaned) {
|
|
|
|
TD_CLR_LOAN(owner);
|
|
|
|
ke->ke_thread = owner;
|
|
|
|
original->td_kse = NULL; /* give it amnesia */
|
|
|
|
/*
|
|
|
|
* Upcalling threads have lower priority than all
|
|
|
|
* in-kernel threads, However threads that have loaned out
|
|
|
|
* their KSE and are NOT upcalling have the priority that
|
|
|
|
* they have. In other words, only look for other work if
|
|
|
|
* the owner is not runnable, OR is upcalling.
|
|
|
|
*/
|
|
|
|
if (TD_CAN_RUN(owner) &&
|
|
|
|
((owner->td_flags & TDF_UPCALLING) == 0)) {
|
|
|
|
setrunnable(owner);
|
|
|
|
CTR2(KTR_RUNQ, "kse_reassign: ke%p -> td%p (give back)",
|
|
|
|
ke, owner);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
/*
|
2003-02-01 12:17:09 +00:00
|
|
|
* Either the owner is not runnable, or is an upcall.
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
* Find the first unassigned thread
|
2003-02-01 12:17:09 +00:00
|
|
|
* If there is a 'last assigned' then see what's next.
|
|
|
|
* otherwise look at what is first.
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
*/
|
2003-02-01 12:17:09 +00:00
|
|
|
if ((td = kg->kg_last_assigned)) {
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
td = TAILQ_NEXT(td, td_runq);
|
2003-02-01 12:17:09 +00:00
|
|
|
} else {
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
td = TAILQ_FIRST(&kg->kg_runq);
|
2003-02-01 12:17:09 +00:00
|
|
|
}
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
|
|
|
|
/*
|
2003-02-01 12:17:09 +00:00
|
|
|
* If we found one assign it the kse, otherwise idle the kse.
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
*/
|
|
|
|
if (td) {
|
2003-02-01 12:17:09 +00:00
|
|
|
/*
|
|
|
|
* Assign the new thread to the KSE.
|
|
|
|
* and make the KSE runnable again,
|
|
|
|
*/
|
|
|
|
if (TD_IS_BOUND(owner)) {
|
|
|
|
/*
|
|
|
|
* If there is a reason to keep the previous
|
|
|
|
* owner, do so.
|
|
|
|
*/
|
|
|
|
TD_SET_LOAN(owner);
|
|
|
|
} else {
|
|
|
|
/* otherwise, cut it free */
|
|
|
|
ke->ke_owner = td;
|
|
|
|
owner->td_kse = NULL;
|
|
|
|
}
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
kg->kg_last_assigned = td;
|
|
|
|
td->td_kse = ke;
|
|
|
|
ke->ke_thread = td;
|
2002-10-12 05:32:24 +00:00
|
|
|
sched_add(ke);
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
CTR2(KTR_RUNQ, "kse_reassign: ke%p -> td%p", ke, td);
|
2002-10-09 02:33:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-02-01 12:17:09 +00:00
|
|
|
/*
|
|
|
|
* Now handle any waiting upcall.
|
|
|
|
* Since we didn't make them runnable before.
|
|
|
|
*/
|
|
|
|
if (TD_CAN_RUN(owner)) {
|
|
|
|
setrunnable(owner);
|
|
|
|
CTR2(KTR_RUNQ, "kse_reassign: ke%p -> td%p (give back)",
|
|
|
|
ke, owner);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* It is possible that this is the last thread in the group
|
|
|
|
* because the KSE is being shut down or the process
|
|
|
|
* is exiting.
|
|
|
|
*/
|
|
|
|
if (TD_IS_EXITING(owner) || (ke->ke_flags & KEF_EXIT)) {
|
|
|
|
ke->ke_thread = NULL;
|
|
|
|
owner->td_kse = NULL;
|
|
|
|
kse_unlink(ke);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* At this stage all we know is that the owner
|
|
|
|
* is the same as the 'active' thread in the KSE
|
|
|
|
* and that it is
|
|
|
|
* Presently NOT loaned out.
|
|
|
|
* Put it on the loanable queue. Make it fifo
|
|
|
|
* so that long term sleepers donate their KSE's first.
|
|
|
|
*/
|
|
|
|
KASSERT((TD_IS_BOUND(owner)), ("kse_reassign: UNBOUND lender"));
|
|
|
|
ke->ke_state = KES_THREAD;
|
|
|
|
ke->ke_flags |= KEF_ONLOANQ;
|
|
|
|
TAILQ_INSERT_TAIL(&kg->kg_lq, ke, ke_kgrlist);
|
|
|
|
kg->kg_loan_kses++;
|
|
|
|
CTR1(KTR_RUNQ, "kse_reassign: ke%p on loan queue", ke);
|
2002-12-28 01:23:07 +00:00
|
|
|
return;
|
2001-02-12 00:20:08 +00:00
|
|
|
}
|
1999-08-19 00:06:53 +00:00
|
|
|
|
2002-10-14 20:34:31 +00:00
|
|
|
#if 0
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
/*
|
|
|
|
* Remove a thread from its KSEGRP's run queue.
|
|
|
|
* This in turn may remove it from a KSE if it was already assigned
|
|
|
|
* to one, possibly causing a new thread to be assigned to the KSE
|
2003-02-01 12:17:09 +00:00
|
|
|
* and the KSE getting a new priority (unless it's a BOUND thread/KSE pair).
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
*/
|
2002-10-14 20:34:31 +00:00
|
|
|
static void
|
2001-09-12 08:38:13 +00:00
|
|
|
remrunqueue(struct thread *td)
|
2001-02-12 00:20:08 +00:00
|
|
|
{
|
2002-10-09 02:33:36 +00:00
|
|
|
struct thread *td2, *td3;
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
struct ksegrp *kg;
|
|
|
|
struct kse *ke;
|
|
|
|
|
|
|
|
mtx_assert(&sched_lock, MA_OWNED);
|
2003-02-01 12:17:09 +00:00
|
|
|
KASSERT ((TD_ON_RUNQ(td)), ("remrunqueue: Bad state on run queue"));
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
kg = td->td_ksegrp;
|
|
|
|
ke = td->td_kse;
|
2003-02-01 12:17:09 +00:00
|
|
|
/*
|
|
|
|
* If it's a bound thread/KSE pair, take the shortcut. All non-KSE
|
|
|
|
* threads are BOUND.
|
|
|
|
*/
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
CTR1(KTR_RUNQ, "remrunqueue: td%p", td);
|
|
|
|
kg->kg_runnable--;
|
2002-09-11 08:13:56 +00:00
|
|
|
TD_SET_CAN_RUN(td);
|
2003-02-01 12:17:09 +00:00
|
|
|
if (TD_IS_BOUND(td)) {
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
/* Bring its kse with it, leave the thread attached */
|
2002-10-12 05:32:24 +00:00
|
|
|
sched_rem(ke);
|
2002-07-14 03:43:33 +00:00
|
|
|
ke->ke_state = KES_THREAD;
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
return;
|
|
|
|
}
|
2002-10-09 02:33:36 +00:00
|
|
|
td3 = TAILQ_PREV(td, threadqueue, td_runq);
|
|
|
|
TAILQ_REMOVE(&kg->kg_runq, td, td_runq);
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
if (ke) {
|
|
|
|
/*
|
|
|
|
* This thread has been assigned to a KSE.
|
|
|
|
* We need to dissociate it and try assign the
|
|
|
|
* KSE to the next available thread. Then, we should
|
|
|
|
* see if we need to move the KSE in the run queues.
|
|
|
|
*/
|
2002-12-28 01:23:07 +00:00
|
|
|
sched_rem(ke);
|
|
|
|
ke->ke_state = KES_THREAD;
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
td2 = kg->kg_last_assigned;
|
2003-02-01 12:17:09 +00:00
|
|
|
KASSERT((td2 != NULL), ("last assigned has wrong value "));
|
2002-10-09 02:33:36 +00:00
|
|
|
if (td2 == td)
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
kg->kg_last_assigned = td3;
|
2002-10-09 02:33:36 +00:00
|
|
|
kse_reassign(ke);
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
}
|
1999-08-19 00:06:53 +00:00
|
|
|
}
|
2002-10-14 20:34:31 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Change the priority of a thread that is on the run queue.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
adjustrunqueue( struct thread *td, int newpri)
|
|
|
|
{
|
|
|
|
struct ksegrp *kg;
|
|
|
|
struct kse *ke;
|
|
|
|
|
|
|
|
mtx_assert(&sched_lock, MA_OWNED);
|
2003-02-01 12:17:09 +00:00
|
|
|
KASSERT ((TD_ON_RUNQ(td)), ("adjustrunqueue: Bad state on run queue"));
|
Move UPCALL related data structure out of kse, introduce a new
data structure called kse_upcall to manage UPCALL. All KSE binding
and loaning code are gone.
A thread owns an upcall can collect all completed syscall contexts in
its ksegrp, turn itself into UPCALL mode, and takes those contexts back
to userland. Any thread without upcall structure has to export their
contexts and exit at user boundary.
Any thread running in user mode owns an upcall structure, when it enters
kernel, if the kse mailbox's current thread pointer is not NULL, then
when the thread is blocked in kernel, a new UPCALL thread is created and
the upcall structure is transfered to the new UPCALL thread. if the kse
mailbox's current thread pointer is NULL, then when a thread is blocked
in kernel, no UPCALL thread will be created.
Each upcall always has an owner thread. Userland can remove an upcall by
calling kse_exit, when all upcalls in ksegrp are removed, the group is
atomatically shutdown. An upcall owner thread also exits when process is
in exiting state. when an owner thread exits, the upcall it owns is also
removed.
KSE is a pure scheduler entity. it represents a virtual cpu. when a thread
is running, it always has a KSE associated with it. scheduler is free to
assign a KSE to thread according thread priority, if thread priority is changed,
KSE can be moved from one thread to another.
When a ksegrp is created, there is always N KSEs created in the group. the
N is the number of physical cpu in the current system. This makes it is
possible that even an userland UTS is single CPU safe, threads in kernel still
can execute on different cpu in parallel. Userland calls kse_create to add more
upcall structures into ksegrp to increase concurrent in userland itself, kernel
is not restricted by number of upcalls userland provides.
The code hasn't been tested under SMP by author due to lack of hardware.
Reviewed by: julian
2003-01-26 11:41:35 +00:00
|
|
|
/*
|
2003-02-01 12:17:09 +00:00
|
|
|
* If it's a bound thread/KSE pair, take the shortcut. All non-KSE
|
|
|
|
* threads are BOUND.
|
Move UPCALL related data structure out of kse, introduce a new
data structure called kse_upcall to manage UPCALL. All KSE binding
and loaning code are gone.
A thread owns an upcall can collect all completed syscall contexts in
its ksegrp, turn itself into UPCALL mode, and takes those contexts back
to userland. Any thread without upcall structure has to export their
contexts and exit at user boundary.
Any thread running in user mode owns an upcall structure, when it enters
kernel, if the kse mailbox's current thread pointer is not NULL, then
when the thread is blocked in kernel, a new UPCALL thread is created and
the upcall structure is transfered to the new UPCALL thread. if the kse
mailbox's current thread pointer is NULL, then when a thread is blocked
in kernel, no UPCALL thread will be created.
Each upcall always has an owner thread. Userland can remove an upcall by
calling kse_exit, when all upcalls in ksegrp are removed, the group is
atomatically shutdown. An upcall owner thread also exits when process is
in exiting state. when an owner thread exits, the upcall it owns is also
removed.
KSE is a pure scheduler entity. it represents a virtual cpu. when a thread
is running, it always has a KSE associated with it. scheduler is free to
assign a KSE to thread according thread priority, if thread priority is changed,
KSE can be moved from one thread to another.
When a ksegrp is created, there is always N KSEs created in the group. the
N is the number of physical cpu in the current system. This makes it is
possible that even an userland UTS is single CPU safe, threads in kernel still
can execute on different cpu in parallel. Userland calls kse_create to add more
upcall structures into ksegrp to increase concurrent in userland itself, kernel
is not restricted by number of upcalls userland provides.
The code hasn't been tested under SMP by author due to lack of hardware.
Reviewed by: julian
2003-01-26 11:41:35 +00:00
|
|
|
*/
|
2003-02-01 12:17:09 +00:00
|
|
|
ke = td->td_kse;
|
|
|
|
CTR1(KTR_RUNQ, "adjustrunqueue: td%p", td);
|
|
|
|
if (TD_IS_BOUND(td)) {
|
2002-10-14 20:34:31 +00:00
|
|
|
/* We only care about the kse in the run queue. */
|
2002-10-14 20:43:02 +00:00
|
|
|
td->td_priority = newpri;
|
2002-10-14 20:34:31 +00:00
|
|
|
if (ke->ke_rqindex != (newpri / RQ_PPQ)) {
|
|
|
|
sched_rem(ke);
|
|
|
|
sched_add(ke);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2003-02-01 12:17:09 +00:00
|
|
|
/*
|
|
|
|
* An unbound thread. This is not optimised yet.
|
|
|
|
*/
|
2002-10-14 20:34:31 +00:00
|
|
|
kg = td->td_ksegrp;
|
|
|
|
kg->kg_runnable--;
|
|
|
|
TD_SET_CAN_RUN(td);
|
|
|
|
if (ke) {
|
|
|
|
if (kg->kg_last_assigned == td) {
|
|
|
|
kg->kg_last_assigned =
|
|
|
|
TAILQ_PREV(td, threadqueue, td_runq);
|
|
|
|
}
|
|
|
|
sched_rem(ke);
|
|
|
|
}
|
|
|
|
TAILQ_REMOVE(&kg->kg_runq, td, td_runq);
|
|
|
|
td->td_priority = newpri;
|
|
|
|
setrunqueue(td);
|
|
|
|
}
|
1999-08-19 00:06:53 +00:00
|
|
|
|
|
|
|
void
|
2001-09-12 08:38:13 +00:00
|
|
|
setrunqueue(struct thread *td)
|
1999-08-19 00:06:53 +00:00
|
|
|
{
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
struct kse *ke;
|
|
|
|
struct ksegrp *kg;
|
|
|
|
struct thread *td2;
|
|
|
|
struct thread *tda;
|
|
|
|
|
|
|
|
CTR1(KTR_RUNQ, "setrunqueue: td%p", td);
|
|
|
|
mtx_assert(&sched_lock, MA_OWNED);
|
2002-09-11 08:13:56 +00:00
|
|
|
KASSERT((TD_CAN_RUN(td) || TD_IS_RUNNING(td)),
|
|
|
|
("setrunqueue: bad thread state"));
|
|
|
|
TD_SET_RUNQ(td);
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
kg = td->td_ksegrp;
|
|
|
|
kg->kg_runnable++;
|
2002-10-09 02:33:36 +00:00
|
|
|
if ((td->td_proc->p_flag & P_KSES) == 0) {
|
|
|
|
/*
|
|
|
|
* Common path optimisation: Only one of everything
|
|
|
|
* and the KSE is always already attached.
|
|
|
|
* Totally ignore the ksegrp run queue.
|
|
|
|
*/
|
2002-10-12 05:32:24 +00:00
|
|
|
sched_add(td->td_kse);
|
2002-10-09 02:33:36 +00:00
|
|
|
return;
|
|
|
|
}
|
2003-02-01 12:17:09 +00:00
|
|
|
/*
|
|
|
|
* If the process is threaded but the thread is bound then
|
|
|
|
* there is still a little extra to do re. KSE loaning.
|
|
|
|
*/
|
|
|
|
if (TD_IS_BOUND(td)) {
|
|
|
|
KASSERT((td->td_kse != NULL),
|
|
|
|
("queueing BAD thread to run queue"));
|
|
|
|
ke = td->td_kse;
|
|
|
|
KASSERT((ke->ke_owner == ke->ke_thread),
|
|
|
|
("setrunqueue: Hey KSE loaned out"));
|
|
|
|
if (ke->ke_flags & KEF_ONLOANQ) {
|
|
|
|
ke->ke_flags &= ~KEF_ONLOANQ;
|
|
|
|
TAILQ_REMOVE(&kg->kg_lq, ke, ke_kgrlist);
|
|
|
|
kg->kg_loan_kses--;
|
|
|
|
}
|
|
|
|
sched_add(td->td_kse);
|
|
|
|
return;
|
|
|
|
}
|
2002-10-09 02:33:36 +00:00
|
|
|
|
2003-02-01 12:17:09 +00:00
|
|
|
/*
|
|
|
|
* Ok, so we are threading with this thread.
|
|
|
|
* We don't have a KSE, see if we can get one..
|
|
|
|
*/
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
tda = kg->kg_last_assigned;
|
|
|
|
if ((ke = td->td_kse) == NULL) {
|
2003-02-01 12:17:09 +00:00
|
|
|
/*
|
|
|
|
* We will need a KSE, see if there is one..
|
|
|
|
* First look for a free one, before getting desperate.
|
|
|
|
* If we can't get one, our priority is not high enough..
|
|
|
|
* that's ok..
|
|
|
|
*/
|
|
|
|
if (kg->kg_loan_kses) {
|
2002-10-09 02:33:36 +00:00
|
|
|
/*
|
2003-02-01 12:17:09 +00:00
|
|
|
* Failing that see if we can borrow one.
|
2002-10-09 02:33:36 +00:00
|
|
|
*/
|
2003-02-01 12:17:09 +00:00
|
|
|
ke = TAILQ_FIRST(&kg->kg_lq);
|
|
|
|
TAILQ_REMOVE(&kg->kg_lq, ke, ke_kgrlist);
|
|
|
|
ke->ke_flags &= ~KEF_ONLOANQ;
|
2002-09-29 23:04:34 +00:00
|
|
|
ke->ke_state = KES_THREAD;
|
2003-02-01 12:17:09 +00:00
|
|
|
TD_SET_LOAN(ke->ke_owner);
|
|
|
|
ke->ke_thread = NULL;
|
|
|
|
kg->kg_loan_kses--;
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
} else if (tda && (tda->td_priority > td->td_priority)) {
|
|
|
|
/*
|
|
|
|
* None free, but there is one we can commandeer.
|
|
|
|
*/
|
|
|
|
ke = tda->td_kse;
|
|
|
|
tda->td_kse = NULL;
|
|
|
|
ke->ke_thread = NULL;
|
|
|
|
tda = kg->kg_last_assigned =
|
|
|
|
TAILQ_PREV(tda, threadqueue, td_runq);
|
2002-10-12 05:32:24 +00:00
|
|
|
sched_rem(ke);
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
}
|
|
|
|
} else {
|
2002-07-14 03:43:33 +00:00
|
|
|
/*
|
|
|
|
* Temporarily disassociate so it looks like the other cases.
|
2003-02-01 12:17:09 +00:00
|
|
|
* If the owner wasn't lending before, then it is now..
|
2002-07-14 03:43:33 +00:00
|
|
|
*/
|
2003-02-01 12:17:09 +00:00
|
|
|
if (!TD_LENDER(ke->ke_owner)) {
|
|
|
|
TD_SET_LOAN(ke->ke_owner);
|
|
|
|
}
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
ke->ke_thread = NULL;
|
|
|
|
td->td_kse = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add the thread to the ksegrp's run queue at
|
|
|
|
* the appropriate place.
|
|
|
|
*/
|
|
|
|
TAILQ_FOREACH(td2, &kg->kg_runq, td_runq) {
|
|
|
|
if (td2->td_priority > td->td_priority) {
|
|
|
|
TAILQ_INSERT_BEFORE(td2, td, td_runq);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (td2 == NULL) {
|
|
|
|
/* We ran off the end of the TAILQ or it was empty. */
|
|
|
|
TAILQ_INSERT_TAIL(&kg->kg_runq, td, td_runq);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If we have a ke to use, then put it on the run queue and
|
|
|
|
* If needed, readjust the last_assigned pointer.
|
|
|
|
*/
|
|
|
|
if (ke) {
|
|
|
|
if (tda == NULL) {
|
|
|
|
/*
|
|
|
|
* No pre-existing last assigned so whoever is first
|
2002-07-14 03:43:33 +00:00
|
|
|
* gets the KSE we brought in.. (maybe us)
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
*/
|
|
|
|
td2 = TAILQ_FIRST(&kg->kg_runq);
|
|
|
|
KASSERT((td2->td_kse == NULL),
|
|
|
|
("unexpected ke present"));
|
|
|
|
td2->td_kse = ke;
|
|
|
|
ke->ke_thread = td2;
|
|
|
|
kg->kg_last_assigned = td2;
|
|
|
|
} else if (tda->td_priority > td->td_priority) {
|
|
|
|
/*
|
|
|
|
* It's ours, grab it, but last_assigned is past us
|
|
|
|
* so don't change it.
|
|
|
|
*/
|
|
|
|
td->td_kse = ke;
|
|
|
|
ke->ke_thread = td;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* We are past last_assigned, so
|
|
|
|
* put the new kse on whatever is next,
|
|
|
|
* which may or may not be us.
|
|
|
|
*/
|
|
|
|
td2 = TAILQ_NEXT(tda, td_runq);
|
|
|
|
kg->kg_last_assigned = td2;
|
|
|
|
td2->td_kse = ke;
|
|
|
|
ke->ke_thread = td2;
|
|
|
|
}
|
2002-10-12 05:32:24 +00:00
|
|
|
sched_add(ke);
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
}
|
2001-02-12 00:20:08 +00:00
|
|
|
}
|
1999-08-19 00:06:53 +00:00
|
|
|
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
/************************************************************************
|
|
|
|
* Critical section marker functions *
|
|
|
|
************************************************************************/
|
2001-12-18 00:27:18 +00:00
|
|
|
/* Critical sections that prevent preemption. */
|
|
|
|
void
|
|
|
|
critical_enter(void)
|
|
|
|
{
|
|
|
|
struct thread *td;
|
|
|
|
|
|
|
|
td = curthread;
|
|
|
|
if (td->td_critnest == 0)
|
2002-03-27 05:39:23 +00:00
|
|
|
cpu_critical_enter();
|
2001-12-18 00:27:18 +00:00
|
|
|
td->td_critnest++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
critical_exit(void)
|
|
|
|
{
|
|
|
|
struct thread *td;
|
|
|
|
|
|
|
|
td = curthread;
|
|
|
|
if (td->td_critnest == 1) {
|
|
|
|
td->td_critnest = 0;
|
2002-03-27 05:39:23 +00:00
|
|
|
cpu_critical_exit();
|
|
|
|
} else {
|
2001-12-18 00:27:18 +00:00
|
|
|
td->td_critnest--;
|
2002-03-27 05:39:23 +00:00
|
|
|
}
|
2001-12-18 00:27:18 +00:00
|
|
|
}
|
|
|
|
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
* SYSTEM RUN QUEUE manipulations and tests *
|
|
|
|
************************************************************************/
|
|
|
|
/*
|
|
|
|
* Initialize a run structure.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
runq_init(struct runq *rq)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
bzero(rq, sizeof *rq);
|
|
|
|
for (i = 0; i < RQ_NQS; i++)
|
|
|
|
TAILQ_INIT(&rq->rq_queues[i]);
|
|
|
|
}
|
|
|
|
|
2001-02-12 00:20:08 +00:00
|
|
|
/*
|
|
|
|
* Clear the status bit of the queue corresponding to priority level pri,
|
|
|
|
* indicating that it is empty.
|
|
|
|
*/
|
|
|
|
static __inline void
|
|
|
|
runq_clrbit(struct runq *rq, int pri)
|
|
|
|
{
|
|
|
|
struct rqbits *rqb;
|
2000-09-07 01:33:02 +00:00
|
|
|
|
2001-02-12 00:20:08 +00:00
|
|
|
rqb = &rq->rq_status;
|
|
|
|
CTR4(KTR_RUNQ, "runq_clrbit: bits=%#x %#x bit=%#x word=%d",
|
|
|
|
rqb->rqb_bits[RQB_WORD(pri)],
|
|
|
|
rqb->rqb_bits[RQB_WORD(pri)] & ~RQB_BIT(pri),
|
|
|
|
RQB_BIT(pri), RQB_WORD(pri));
|
|
|
|
rqb->rqb_bits[RQB_WORD(pri)] &= ~RQB_BIT(pri);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Find the index of the first non-empty run queue. This is done by
|
|
|
|
* scanning the status bits, a set bit indicates a non-empty queue.
|
|
|
|
*/
|
|
|
|
static __inline int
|
|
|
|
runq_findbit(struct runq *rq)
|
|
|
|
{
|
|
|
|
struct rqbits *rqb;
|
|
|
|
int pri;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
rqb = &rq->rq_status;
|
|
|
|
for (i = 0; i < RQB_LEN; i++)
|
|
|
|
if (rqb->rqb_bits[i]) {
|
2002-06-20 06:21:20 +00:00
|
|
|
pri = RQB_FFS(rqb->rqb_bits[i]) + (i << RQB_L2BPW);
|
2001-02-12 00:20:08 +00:00
|
|
|
CTR3(KTR_RUNQ, "runq_findbit: bits=%#x i=%d pri=%d",
|
|
|
|
rqb->rqb_bits[i], i, pri);
|
|
|
|
return (pri);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the status bit of the queue corresponding to priority level pri,
|
|
|
|
* indicating that it is non-empty.
|
|
|
|
*/
|
|
|
|
static __inline void
|
|
|
|
runq_setbit(struct runq *rq, int pri)
|
|
|
|
{
|
|
|
|
struct rqbits *rqb;
|
|
|
|
|
|
|
|
rqb = &rq->rq_status;
|
|
|
|
CTR4(KTR_RUNQ, "runq_setbit: bits=%#x %#x bit=%#x word=%d",
|
|
|
|
rqb->rqb_bits[RQB_WORD(pri)],
|
|
|
|
rqb->rqb_bits[RQB_WORD(pri)] | RQB_BIT(pri),
|
|
|
|
RQB_BIT(pri), RQB_WORD(pri));
|
|
|
|
rqb->rqb_bits[RQB_WORD(pri)] |= RQB_BIT(pri);
|
1999-08-19 00:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
* Add the KSE to the queue specified by its priority, and set the
|
2001-02-12 00:20:08 +00:00
|
|
|
* corresponding status bit.
|
1999-08-19 00:06:53 +00:00
|
|
|
*/
|
|
|
|
void
|
2001-09-12 08:38:13 +00:00
|
|
|
runq_add(struct runq *rq, struct kse *ke)
|
1999-08-19 00:06:53 +00:00
|
|
|
{
|
2001-02-12 00:20:08 +00:00
|
|
|
struct rqhead *rqh;
|
|
|
|
int pri;
|
1999-08-19 00:06:53 +00:00
|
|
|
|
2002-02-11 20:37:54 +00:00
|
|
|
pri = ke->ke_thread->td_priority / RQ_PPQ;
|
2001-09-12 08:38:13 +00:00
|
|
|
ke->ke_rqindex = pri;
|
2001-02-12 00:20:08 +00:00
|
|
|
runq_setbit(rq, pri);
|
|
|
|
rqh = &rq->rq_queues[pri];
|
|
|
|
CTR4(KTR_RUNQ, "runq_add: p=%p pri=%d %d rqh=%p",
|
2002-02-11 20:37:54 +00:00
|
|
|
ke->ke_proc, ke->ke_thread->td_priority, pri, rqh);
|
2001-09-12 08:38:13 +00:00
|
|
|
TAILQ_INSERT_TAIL(rqh, ke, ke_procq);
|
1999-08-19 00:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2001-02-12 00:20:08 +00:00
|
|
|
* Return true if there are runnable processes of any priority on the run
|
|
|
|
* queue, false otherwise. Has no side effects, does not modify the run
|
|
|
|
* queue structure.
|
1999-08-19 00:06:53 +00:00
|
|
|
*/
|
2001-02-12 00:20:08 +00:00
|
|
|
int
|
|
|
|
runq_check(struct runq *rq)
|
1999-08-19 00:06:53 +00:00
|
|
|
{
|
2001-02-12 00:20:08 +00:00
|
|
|
struct rqbits *rqb;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
rqb = &rq->rq_status;
|
|
|
|
for (i = 0; i < RQB_LEN; i++)
|
|
|
|
if (rqb->rqb_bits[i]) {
|
|
|
|
CTR2(KTR_RUNQ, "runq_check: bits=%#x i=%d",
|
|
|
|
rqb->rqb_bits[i], i);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
CTR0(KTR_RUNQ, "runq_check: empty");
|
|
|
|
|
|
|
|
return (0);
|
1999-08-19 00:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-10-12 05:32:24 +00:00
|
|
|
* Find the highest priority process on the run queue.
|
1999-08-19 00:06:53 +00:00
|
|
|
*/
|
2001-09-12 08:38:13 +00:00
|
|
|
struct kse *
|
2001-02-12 00:20:08 +00:00
|
|
|
runq_choose(struct runq *rq)
|
1999-08-19 00:06:53 +00:00
|
|
|
{
|
2001-02-12 00:20:08 +00:00
|
|
|
struct rqhead *rqh;
|
2001-09-12 08:38:13 +00:00
|
|
|
struct kse *ke;
|
2001-02-12 00:20:08 +00:00
|
|
|
int pri;
|
1999-08-19 00:06:53 +00:00
|
|
|
|
2000-09-07 01:33:02 +00:00
|
|
|
mtx_assert(&sched_lock, MA_OWNED);
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
while ((pri = runq_findbit(rq)) != -1) {
|
2001-02-12 00:20:08 +00:00
|
|
|
rqh = &rq->rq_queues[pri];
|
2001-09-12 08:38:13 +00:00
|
|
|
ke = TAILQ_FIRST(rqh);
|
|
|
|
KASSERT(ke != NULL, ("runq_choose: no proc on busy queue"));
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
CTR3(KTR_RUNQ,
|
|
|
|
"runq_choose: pri=%d kse=%p rqh=%p", pri, ke, rqh);
|
2001-09-12 08:38:13 +00:00
|
|
|
return (ke);
|
2001-02-12 00:20:08 +00:00
|
|
|
}
|
|
|
|
CTR1(KTR_RUNQ, "runq_choose: idleproc pri=%d", pri);
|
|
|
|
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
return (NULL);
|
2001-02-12 00:20:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
* Remove the KSE from the queue specified by its priority, and clear the
|
2001-02-12 00:20:08 +00:00
|
|
|
* corresponding status bit if the queue becomes empty.
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
* Caller must set ke->ke_state afterwards.
|
2001-02-12 00:20:08 +00:00
|
|
|
*/
|
|
|
|
void
|
2001-09-12 08:38:13 +00:00
|
|
|
runq_remove(struct runq *rq, struct kse *ke)
|
2001-02-12 00:20:08 +00:00
|
|
|
{
|
|
|
|
struct rqhead *rqh;
|
|
|
|
int pri;
|
|
|
|
|
2002-07-30 06:54:05 +00:00
|
|
|
KASSERT(ke->ke_proc->p_sflag & PS_INMEM,
|
|
|
|
("runq_remove: process swapped out"));
|
2001-09-12 08:38:13 +00:00
|
|
|
pri = ke->ke_rqindex;
|
2001-02-12 00:20:08 +00:00
|
|
|
rqh = &rq->rq_queues[pri];
|
|
|
|
CTR4(KTR_RUNQ, "runq_remove: p=%p pri=%d %d rqh=%p",
|
2002-02-11 20:37:54 +00:00
|
|
|
ke, ke->ke_thread->td_priority, pri, rqh);
|
2001-09-12 08:38:13 +00:00
|
|
|
KASSERT(ke != NULL, ("runq_remove: no proc on busy queue"));
|
|
|
|
TAILQ_REMOVE(rqh, ke, ke_procq);
|
2001-02-12 00:20:08 +00:00
|
|
|
if (TAILQ_EMPTY(rqh)) {
|
|
|
|
CTR0(KTR_RUNQ, "runq_remove: empty");
|
|
|
|
runq_clrbit(rq, pri);
|
1999-08-19 00:06:53 +00:00
|
|
|
}
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
}
|
|
|
|
|
2002-07-11 22:47:58 +00:00
|
|
|
#if 0
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
void
|
2002-10-09 02:33:36 +00:00
|
|
|
panc(char *string1, char *string2)
|
|
|
|
{
|
|
|
|
printf("%s", string1);
|
|
|
|
Debugger(string2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
thread_sanity_check(struct thread *td, char *string)
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
{
|
|
|
|
struct proc *p;
|
|
|
|
struct ksegrp *kg;
|
|
|
|
struct kse *ke;
|
2002-10-09 02:33:36 +00:00
|
|
|
struct thread *td2 = NULL;
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
unsigned int prevpri;
|
2002-10-09 02:33:36 +00:00
|
|
|
int saw_lastassigned = 0;
|
|
|
|
int unassigned = 0;
|
|
|
|
int assigned = 0;
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
|
|
|
|
p = td->td_proc;
|
|
|
|
kg = td->td_ksegrp;
|
|
|
|
ke = td->td_kse;
|
|
|
|
|
|
|
|
|
|
|
|
if (ke) {
|
2002-09-15 23:52:25 +00:00
|
|
|
if (p != ke->ke_proc) {
|
2002-10-09 02:33:36 +00:00
|
|
|
panc(string, "wrong proc");
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
}
|
|
|
|
if (ke->ke_thread != td) {
|
2002-10-09 02:33:36 +00:00
|
|
|
panc(string, "wrong thread");
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((p->p_flag & P_KSES) == 0) {
|
|
|
|
if (ke == NULL) {
|
2002-10-09 02:33:36 +00:00
|
|
|
panc(string, "non KSE thread lost kse");
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
prevpri = 0;
|
|
|
|
saw_lastassigned = 0;
|
|
|
|
unassigned = 0;
|
|
|
|
assigned = 0;
|
|
|
|
TAILQ_FOREACH(td2, &kg->kg_runq, td_runq) {
|
|
|
|
if (td2->td_priority < prevpri) {
|
2002-10-09 02:33:36 +00:00
|
|
|
panc(string, "thread runqueue unosorted");
|
|
|
|
}
|
|
|
|
if ((td2->td_state == TDS_RUNQ) &&
|
|
|
|
td2->td_kse &&
|
|
|
|
(td2->td_kse->ke_state != KES_ONRUNQ)) {
|
|
|
|
panc(string, "KSE wrong state");
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
}
|
|
|
|
prevpri = td2->td_priority;
|
|
|
|
if (td2->td_kse) {
|
|
|
|
assigned++;
|
|
|
|
if (unassigned) {
|
2002-10-09 02:33:36 +00:00
|
|
|
panc(string, "unassigned before assigned");
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
}
|
|
|
|
if (kg->kg_last_assigned == NULL) {
|
2002-10-09 02:33:36 +00:00
|
|
|
panc(string, "lastassigned corrupt");
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
}
|
|
|
|
if (saw_lastassigned) {
|
2002-10-09 02:33:36 +00:00
|
|
|
panc(string, "last assigned not last");
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
}
|
|
|
|
if (td2->td_kse->ke_thread != td2) {
|
2002-10-09 02:33:36 +00:00
|
|
|
panc(string, "mismatched kse/thread");
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
unassigned++;
|
|
|
|
}
|
|
|
|
if (td2 == kg->kg_last_assigned) {
|
|
|
|
saw_lastassigned = 1;
|
|
|
|
if (td2->td_kse == NULL) {
|
2002-10-09 02:33:36 +00:00
|
|
|
panc(string, "last assigned not assigned");
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (kg->kg_last_assigned && (saw_lastassigned == 0)) {
|
2002-10-09 02:33:36 +00:00
|
|
|
panc(string, "where on earth does lastassigned point?");
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
}
|
|
|
|
FOREACH_THREAD_IN_GROUP(kg, td2) {
|
|
|
|
if (((td2->td_flags & TDF_UNBOUND) == 0) &&
|
2002-09-11 08:13:56 +00:00
|
|
|
(TD_ON_RUNQ(td2))) {
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
assigned++;
|
|
|
|
if (td2->td_kse == NULL) {
|
2002-10-09 02:33:36 +00:00
|
|
|
panc(string, "BOUND thread with no KSE");
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#if 0
|
|
|
|
if ((unassigned + assigned) != kg->kg_runnable) {
|
2002-10-09 02:33:36 +00:00
|
|
|
panc(string, "wrong number in runnable");
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2002-10-09 02:33:36 +00:00
|
|
|
if (assigned == 12345) {
|
|
|
|
printf("%p %p %p %p %p %d, %d",
|
|
|
|
td, td2, ke, kg, p, assigned, saw_lastassigned);
|
|
|
|
}
|
1999-08-19 00:06:53 +00:00
|
|
|
}
|
2002-07-11 22:47:58 +00:00
|
|
|
#endif
|
Part 1 of KSE-III
The ability to schedule multiple threads per process
(one one cpu) by making ALL system calls optionally asynchronous.
to come: ia64 and power-pc patches, patches for gdb, test program (in tools)
Reviewed by: Almost everyone who counts
(at various times, peter, jhb, matt, alfred, mini, bernd,
and a cast of thousands)
NOTE: this is still Beta code, and contains lots of debugging stuff.
expect slight instability in signals..
2002-06-29 17:26:22 +00:00
|
|
|
|