Commit Graph

127 Commits

Author SHA1 Message Date
David Xu
c6523b663f Fix compiling problem, p_tracee is in my local repository for
threaded process debugging, not ready for this time.
2003-05-01 12:16:06 +00:00
David Xu
1ecc645634 Drop Giant lock before suspended, pick up it after resumed.
thread_suspend_check() is used in exit1() which still needs
Giant lock.
2003-05-01 07:29:25 +00:00
Peter Wemm
cb1f265c60 AMD64 uses the new-style cpu_switch()/cpu_throw() calling conventions. 2003-04-30 21:45:03 +00:00
David Xu
5c29a450ae Increase some default values. 2003-04-30 01:18:29 +00:00
David Xu
5073e68fa3 unlock sched_lock at right time. 2003-04-27 04:32:40 +00:00
Daniel Eischen
1328e1c4be Add an argument to get_mcontext() which specified whether the
syscall return values should be cleared.  The system calls
getcontext() and swapcontext() want to return 0 on success
but these contexts can be switched to at a later time so
the return values need to be cleared in the saved register
sets.  Other callers of get_mcontext() would normally want
the context without clearing the return values.

Remove the i386-specific context saving from the KSE code.
get_mcontext() is not i386-specific any more.

Fix a bad pointer in the alpha get_mcontext() code.  The
context was being bcopy()'d from &td->tf_frame, but tf_frame
is itself a pointer, so the thread was being copied instead.
Spotted by jake.

Glanced at by:  jake
Reviewed by:    bde (months ago)
2003-04-25 01:50:30 +00:00
John Baldwin
112afcb232 - Protect p_numthreads with the sched_lock.
- Protect p_singlethread with both the sched_lock and the proc lock.
- Protect p_suspcount with the proc lock.
2003-04-23 18:46:51 +00:00
John Baldwin
a6f37ac9d6 - Mark the kse_purge_group() and kse_purge() definitions static to match
their prototypes.
- Remove sched_lock locking from kse_purge() as all callers already lock
  the sched_lock before calling it.
- Hold the proc lock slightly longer to protect P_SHOULDSTOP().
2003-04-22 19:47:55 +00:00
David Xu
11b20c685b Fix lock order reversal problem. 2003-04-21 14:42:04 +00:00
David Xu
1ecb38a365 Introduce two flags to control upcall behaviour:
o KMF_NOUPCALL
	Ask kse_release to not return to userland upcall entry, but instead
	direct returns to userland by using current thread's stack and return
	address on stack. This flags is intended to be used by UTS in critical
	region to wait another UTS thread to leave critical region, by using
	kse_release with this flag to avoid spinnng and burning CPU. Also this
	flags can be used by UTS to poll completed context when there is nothing
	to do in userland and needn't restart from its entry like normal upcall.

o KMF_NOCOMPLETED
	Ask kernel to not bring completed thread contexts back to userland when
	doing upcall, this flags is intend to be used with above flag when an
	upcall thread is in critical region and can not process completed contexts
	at that time.

Tested by: deischen
2003-04-21 07:27:59 +00:00
David Xu
95bee4c365 Test next upcall time correctly. 2003-04-19 06:16:04 +00:00
David Xu
588257e810 Use correct thread pointer. 2003-04-19 04:39:10 +00:00
John Baldwin
889a6b5845 Use the proc lock to protect p_singlethread and a P_WEXIT test. This
fixes a couple of potential KSE panics on non-i386 arch's that weren't
holding the proc lock when calling thread_exit().
2003-04-18 20:20:00 +00:00
Julian Elischer
d3a0bd78a8 Add a thread_unlink() and use it.
It could also be used twice in kern_thr.c but that's owned by jeff
so I'l let him change it when he's next there.
2003-04-18 00:16:13 +00:00
John Baldwin
94df4b8584 Protect td_sigmask with the proc lock. 2003-04-17 22:21:57 +00:00
Julian Elischer
060563ec50 Move the _oncpu entry from the KSE to the thread.
The entry in the KSE still exists but it's purpose will change a bit
when we add the ability to lock a KSE to a cpu.
2003-04-10 17:35:44 +00:00
David Xu
36f7b36f8a Inherit blocked thread's context for upcall thread. 2003-04-08 07:45:56 +00:00
Peter Wemm
cc66ebe2a9 Commit a partial lazy thread switch mechanism for i386. it isn't as lazy
as it could be and can do with some more cleanup.  Currently its under
options LAZY_SWITCH.  What this does is avoid %cr3 reloads for short
context switches that do not involve another user process.  ie: we can
take an interrupt, switch to a kthread and return to the user without
explicitly flushing the tlb.  However, this isn't as exciting as it could
be, the interrupt overhead is still high and too much blocks on Giant
still.  There are some debug sysctls, for stats and for an on/off switch.

The main problem with doing this has been "what if the process that you're
running on exits while we're borrowing its address space?" - in this case
we use an IPI to give it a kick when we're about to reclaim the pmap.

Its not compiled in unless you add the LAZY_SWITCH option.  I want to fix a
few more things and get some more feedback before turning it on by default.

This is NOT a replacement for Bosko's lazy interrupt stuff.  This was more
meant for the kthread case, while his was for interrupts.  Mine helps a
little for interrupts, but his helps a lot more.

The stats are enabled with options SWTCH_OPTIM_STATS - this has been a
pseudo-option for years, I just added a bunch of stuff to it.

One non-trivial change was to select a new thread before calling
cpu_switch() in the first place.  This allows us to catch the silly
case of doing a cpu_switch() to the current process.  This happens
uncomfortably often.  This simplifies a bit of the asm code in cpu_switch
(no longer have to call choosethread() in the middle).  This has been
implemented on i386 and (thanks to jake) sparc64.  The others will come
soon.  This is actually seperate to the lazy switch stuff.

Glanced at by:  jake, jhb
2003-04-02 23:53:30 +00:00
Jeff Roberson
2c10d16a4b - Borrow the KSE single threading code for exec and exit. We use the check
if (p->p_numthreads > 1) and not a flag because action is only necessary
   if there are other threads.  The rest of the system has no need to
   identify thr threaded processes.
 - In kern_thread.c use thr_exit1() instead of thread_exit() if P_THREADED
   is not set.
2003-04-01 01:26:20 +00:00
Jeff Roberson
4093529dee - Move p->p_sigmask to td->td_sigmask. Signal masks will be per thread with
a follow on commit to kern_sig.c
 - signotify() now operates on a thread since unmasked pending signals are
   stored in the thread.
 - PS_NEEDSIGCHK moves to TDF_NEEDSIGCHK.
2003-03-31 22:49:17 +00:00
John Baldwin
16088e4a88 Check for the PS_NEEDSIGCHK flag in the right flags field. 2003-03-28 18:08:57 +00:00
David Xu
6ce75196ce Adjust code for userland preemptive. Userland can set a quantum in
kse_mailbox to schedule an upcall, this is useful for userland timeout
routine, for example pthread_cond_timedwait().

Also extract upcall scheduling code from kse_reassign and create
a new function called thread_switchout to include these code.

Reviewed by: julain
2003-03-19 05:49:38 +00:00
David Xu
9a4b78c9da Export current time when returning from never blocked syscall. 2003-03-14 03:52:16 +00:00
David Xu
661db6da35 Lock proc lock before changing p_flag. 2003-03-11 03:16:02 +00:00
David Xu
21e0492ab1 Fix signal delivering bug for threaded process. 2003-03-11 02:59:50 +00:00
David Xu
e574e444e0 Fix threaded process job control bug. SMP tested.
Reviewed by: julian
2003-03-11 00:07:53 +00:00
David Xu
b4508d7d3f Lock sched_lock before modifying td_flags. 2003-03-08 04:09:04 +00:00
David Xu
9948c47f0e Check kse group limit before linking new ksegrp. 2003-02-28 15:57:33 +00:00
David Xu
3b3df40fc4 Release sched_lock before calling upcall_free. 2003-02-27 05:42:01 +00:00
Julian Elischer
ac2e415327 Change the process flags P_KSES to be P_THREADED.
This is just a cosmetic change but I've been meaning to do it for about a year.
2003-02-27 02:05:19 +00:00
David Xu
5614648e5e Add a missing '!'. 2003-02-26 01:56:14 +00:00
David Xu
4b4866ed42 Add a simple facility to allow round roubin in userland.
Reviewed by:	julain
2003-02-26 00:58:23 +00:00
David Xu
d4b570f053 Remove a bogus comment. 2003-02-25 05:17:18 +00:00
David Xu
0fccb684d1 Remove a XXXKSE. kg_completed now needs proc lock. 2003-02-24 01:28:10 +00:00
David Xu
f5878f69df Backout last surplus commit. That day just wasn't my day. 2003-02-24 00:49:55 +00:00
David Xu
34ada4b3bb If UTS kernel is calling kse_wakeup for itself, do nothing. 2003-02-21 07:11:38 +00:00
David Xu
ab7d94f7eb Forgot to set KU_DOUPCALL in kse_wakeup. 2003-02-20 08:22:04 +00:00
David Xu
eb117d5cb0 Add a timeout parameter to kse_release. 2003-02-20 08:18:15 +00:00
David Xu
a87891ee9e Move thread limits testing code up a bit. This let UPCALLING thread
takes possible accumulated contexts away.
2003-02-20 01:11:17 +00:00
David Xu
fc8cdd87d2 Count non-threaded group. 2003-02-19 13:40:24 +00:00
David Xu
30621e142d M_WAITOK and remove an useless comment. 2003-02-19 09:59:12 +00:00
Warner Losh
a163d034fa Back out M_* changes, per decision of the TRB.
Approved by: trb
2003-02-19 05:47:46 +00:00
David Xu
0252d20369 Optimize the case when max threads number was hit. 2003-02-19 04:01:55 +00:00
David Xu
88aba94cdc Further fix PS_NEEDSIGCHK 2003-02-17 14:54:57 +00:00
David Xu
02bbffaf3c Move code for detecting PS_NEEDSIGCHK into thread_schedule_upcall,
I think it is a better place to handle it.
2003-02-17 14:41:22 +00:00
Jeff Roberson
58a3c27384 - Add a new function, thread_signal_add(), that is called from postsig to
add a signal to a mailbox's pending set.
 - Add a new function, thread_signal_upcall(), this causes the current thread
   to upcall so that we can deliver pending signals.

Reviewed by:	mini
2003-02-17 09:58:11 +00:00
Julian Elischer
4a338afd7a Move a bunch of flags from the KSE to the thread.
I was in two minds as to where to put them in the first case..
I should have listenned to the other mind.

Submitted by:	 parts by davidxu@
Reviewed by:	jeff@ mini@
2003-02-17 09:55:10 +00:00
Jeff Roberson
5215b1872f - Split the struct kse into struct upcall and struct kse. struct kse will
soon be visible only to schedulers.  This greatly simplifies much the
   KSE code.

Submitted by:	davidxu
2003-02-17 05:14:26 +00:00
Julian Elischer
6f8132a867 Reversion of commit by Davidxu plus fixes since applied.
I'm not convinced there is anything major wrong with the patch but
them's the rules..

I am using my "David's mentor" hat to revert this as he's
offline for a while.
2003-02-01 12:17:09 +00:00
Julian Elischer
ff92b12dce Only add one tick per tick to the thread stats, instead of some random number. 2003-01-31 22:14:46 +00:00