summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_synch.c
Commit message (Collapse)AuthorAgeFilesLines
...
* Commit a partial lazy thread switch mechanism for i386. it isn't as lazypeter2003-04-021-3/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* - Borrow the KSE single threading code for exec and exit. We use the checkjeff2003-04-011-1/+1
| | | | | | | | 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.
* Adjust code for userland preemptive. Userland can set a quantum indavidxu2003-03-191-1/+2
| | | | | | | | | | 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
* Replace calls to WITNESS_SLEEP() and witness_list() with equivalent callsjhb2003-03-041-1/+2
| | | | to WITNESS_WARN().
* When a process has been waiting on a condition variable or mutex theharti2003-02-271-0/+2
| | | | | | | | | | | | td_wmesg field in the thread structure points to the description string of the condition variable or mutex. If the condvar or the mutex had been initialized from a loadable module that was unloaded in the meantime, td_wmesg may now point to invalid memory. Retrieving the process table now may panic the kernel (or access junk). Setting the td_wmesg field to NULL after unblocking on the condvar/mutex prevents this panic. PR: kern/47408 Approved by: jake (mentor)
* Change the process flags P_KSES to be P_THREADED.julian2003-02-271-1/+1
| | | | This is just a cosmetic change but I've been meaning to do it for about a year.
* Move a bunch of flags from the KSE to the thread.julian2003-02-171-2/+1
| | | | | | | | 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@
* Print a backtrace in case we tsleep from inside of DDB.alfred2003-02-141-0/+1
|
* Add code to ddb to allow backtracing an arbitrary thread.julian2002-12-281-16/+1
| | | | | | | | | | | | | | | | | | | | | | | | (show thread {address}) Remove the IDLE kse state and replace it with a change in the way threads sahre KSEs. Every KSE now has a thread, which is considered its "owner" however a KSE may also be lent to other threads in the same group to allow completion of in-kernel work. n this case the owner remains the same and the KSE will revert to the owner when the other work has been completed. All creations of upcalls etc. is now done from kse_reassign() which in turn is called from mi_switch or thread_exit(). This means that special code can be removed from msleep() and cv_wait(). kse_release() does not leave a KSE with no thread any more but converts the existing thread into teh KSE's owner, and sets it up for doing an upcall. It is just inhibitted from being scheduled until there is some reason to do an upcall. Remove all trace of the kse_idle queue since it is no-longer needed. "Idle" KSEs are now on the loanable queue.
* Unbreak the KSE code. Keep track of zobie threads using the Per-CPU storagejulian2002-12-101-0/+8
| | | | | | | | during the context switch. Rearrange thread cleanups to avoid problems with Giant. Clean threads when freed or when recycled. Approved by: re (jhb)
* - Move FSCALE back to kern_sync. This is not scheduler specific.jeff2002-11-211-0/+15
| | | | | | | - Create a new callout for lbolt and move it out of schedcpu(). This is not scheduler specific either. Approved by: re
* Add an actual implementation of kse_thr_interrupt()davidxu2002-10-301-2/+12
|
* More work on the interaction between suspending and sleeping threads.julian2002-10-251-7/+10
| | | | | | Also clean up some code used with 'single-threading'. Reviewed by: davidxu
* - Create a new scheduler api that is defined in sys/sched.hjeff2002-10-121-415/+21
| | | | | | | | | | - Begin moving scheduler specific functionality into sched_4bsd.c - Replace direct manipulation of scheduler data with hooks provided by the new api. - Remove KSE specific state modifications and single runq assumptions from kern_switch.c Reviewed by: -arch
* - Move p_cpulimit to struct proc from struct plimit and protect it withjhb2002-10-091-8/+2
| | | | | | | | | | | | | | | sched_lock. This means that we no longer access p_limit in mi_switch() and the p_limit pointer can be protected by the proc lock. - Remove PRS_ZOMBIE check from CPU limit test in mi_switch(). PRS_ZOMBIE processes don't call mi_switch(), and even if they did there is no longer the danger of p_limit being NULL (which is what the original zombie check was added for). - When we bump the current processes soft CPU limit in ast(), just bump the private p_cpulimit instead of the shared rlimit. This fixes an XXX for some value of fix. There is still a (probably benign) bug in that this code doesn't check that the new soft limit exceeds the hard limit. Inspired by: bde (2)
* Round out the facilty for a 'bound' thread to loan out its KSEjulian2002-10-091-21/+11
| | | | | | | | | | | | | | | | | | | | | | | | in specific situations. The owner thread must be blocked, and the borrower can not proceed back to user space with the borrowed KSE. The borrower will return the KSE on the next context switch where teh owner wants it back. This removes a lot of possible race conditions and deadlocks. It is consceivable that the borrower should inherit the priority of the owner too. that's another discussion and would be simple to do. Also, as part of this, the "preallocatd spare thread" is attached to the thread doing a syscall rather than the KSE. This removes the need to lock the scheduler when we want to access it, as it's now "at hand". DDB now shows a lot mor info for threaded proceses though it may need some optimisation to squeeze it all back into 80 chars again. (possible JKH project) Upcalls are now "bound" threads, but "KSE Lending" now means that other completing syscalls can be completed using that KSE before the upcall finally makes it back to the UTS. (getting threads OUT OF THE KERNEL is one of the highest priorities in the KSE system.) The upcall when it happens will present all the completed syscalls to the KSE for selection.
* XXX Add a check for p->p_limit being NULL before dereferencing it. This isjmallett2002-10-031-1/+6
| | | | | | | | totally bogus but will hide the occurances of access of 0xbc(NULL) which people have run into lately. This is not a proper fix, just a bandaid, until the cause of this happening is tracked down and fixed. Reviewed by: rwatson
* Rename the mutex thread and process states to use a more generic 'LOCK'jhb2002-10-021-1/+1
| | | | | | | | | name instead. (e.g., SLOCK instead of SMTX, TD_ON_LOCK() instead of TD_ON_MUTEX()) Eventually a turnstile abstraction will be added that will be shared with mutexes and other types of locks. SLOCK/TDI_LOCK will be used internally by the turnstile code and will not be specific to mutexes. Making the change now ensures that turnstiles can be dropped in at a later date without affecting the ABI of userland applications.
* - Adjust comment noting that handling of CPU limit exhaustion is done injhb2002-10-011-2/+5
| | | | | | | | | | ast(). - Actually set KEF_ASTPENDING so ast() is called. I think this is buggy for a process with multiple KSE's in that PS_XCPU is not a KSE event, it's a process-wide event. IMO there really should probably be two ASTPENDING flags, one for per-process, and one for per-KSE. Submitted by: bde
* - Add a new per-process flag PS_XCPU to indicate that at least one threadjhb2002-09-301-28/+2
| | | | | | | | has exceeded its CPU time limit. - In mi_switch(), set PS_XCPU when the CPU time limit is exceeded. - Perform actual CPU time limit exceeded work in ast() when PS_XCPU is set. Requested by: many
* Implement basic KSE loaning. This stops a hread that is blocked in BOUND modejulian2002-09-291-0/+5
| | | | | | | | | from stopping another thread from completing a syscall, and this allows it to release its resources etc. Probably more related commits to follow (at least one I know of) Initial concept by: julian, dillon Submitted by: davidxu
* Completely redo thread states.julian2002-09-111-125/+63
| | | | Reviewed by: davidxu@freebsd.org
* Rejig the code to figure out estcpu and work out how long a KSEGRP has beenjulian2002-08-301-17/+27
| | | | | | | | | idle. What was there before was surprisingly ALMOST correct. Peter and I fried our brains on this for a couple of hours figuring out what this actually means in the context of multiple threads. Reviewed by: peter@freebsd.org
* updatepri() works on a ksegrp (where the scheduling parameters are), sopeter2002-08-281-17/+18
| | | | | | | directly give it the ksegrp instead of the thread. The only thing it used to use in the thread was the ksegrp. Reviewed by: julian
* Slight cleanup of some comments/whitespace.julian2002-08-011-10/+21
| | | | | | | | | | | | Make idle process state more consistant. Add an assert on thread state. Clean up idleproc/mi_switch() interaction. Use a local instead of referencing curthread 7 times in a row (I've been told curthread can be expensive on some architectures) Remove some commented out code. Add a little commented out code (completion coming soon) Reviewed by: jhb@freebsd.org
* In endtsleep() and cv_timedwait_end(), a thread marked TDF_TIMEOUT maytanimura2002-07-301-2/+11
| | | | | | | | | be swapped out. Do not put such the thread directly back to the run queue. Spotted by: David Xu <davidx@viasoft.com.cn> While I am here, s/PS_TIMEOUT/TDF_TIMEOUT/.
* - Optimize wakeup() and its friends; if a thread waken up is beingtanimura2002-07-301-6/+12
| | | | | | | | | | | | | | swapped in, we do not have to ask for the scheduler thread to do that. - Assert that a process is not swapped out in runq functions and swapout(). - Introduce thread_safetoswapout() for readability. - In swapout_procs(), perform a test that may block (check of a thread working on its vm map) first. This lets us call swapout() with the sched_lock held, providing a better atomicity.
* Create a new thread state to describe threads that would be ready to runjulian2002-07-291-3/+4
| | | | | | | | | | | except for the fact tha they are presently swapped out. Also add a process flag to indicate that the process has started the struggle to swap back in. This will be needed for the case where multiple threads start the swapin action top a collision. Also add code to stop a process fropm being swapped out if one of the threads in this process is actually off running on another CPU.. that might hurt... Submitted by: Seigo Tanimura <tanimura@r.dl.itc.u-tokyo.ac.jp>
* slight stylisations to take into account recent code changes.julian2002-07-241-7/+3
|
* Fix a reversed test.julian2002-07-171-7/+15
| | | | | | | | Fix some style nits. Fix a KASSERT message. Add/fix some comments. Submitted by: bde@freebsd.org
* Add a KASSERT() to assert that td_critnest is == 1 when mi_switch() isjhb2002-07-171-0/+2
| | | | called.
* Allow alphas to do crashdumps: Refuse to run anything in choosethread()gallatin2002-07-171-4/+4
| | | | | | | | | | after a panic which is not an interrupt thread, or the thread which caused the panic. Also, remove panicstr checks from msleep() and from cv_wait() in order to allow threads to go to sleep and yeild the cpu to the panicing thread, or to an interrupt thread which might be doing the crashdump. Reviewed by: jhb (and it was mostly his idea too)
* Thinking about it I came to the conclusion that the KSE states were incorrectlyjulian2002-07-141-13/+4
| | | | | | | | | | | | | | formulated. The correct states should be: IDLE: On the idle KSE list for that KSEG RUNQ: Linked onto the system run queue. THREAD: Attached to a thread and slaved to whatever state the thread is in. This means that most places where we were adjusting kse state can go away as it is just moving around because the thread is.. The only places we need to adjust the KSE state is in transition to and from the idle and run queues. Reviewed by: jhb@freebsd.org
* oops, state cannot be two different values at once..julian2002-07-141-1/+1
| | | | use || instead of &&
* Re-enable the idle page-zeroing code. Remove all IPIs from the idledillon2002-07-121-0/+7
| | | | | | | | | | | | | | | | | page-zeroing code as well as from the general page-zeroing code and use a lazy tlb page invalidation scheme based on a callback made at the end of mi_switch. A number of people came up with this idea at the same time so credit belongs to Peter, John, and Jake as well. Two-way SMP buildworld -j 5 tests (second run, after stabilization) 2282.76 real 2515.17 user 704.22 sys before peter's IPI commit 2266.69 real 2467.50 user 633.77 sys after peter's commit 2232.80 real 2468.99 user 615.89 sys after this commit Reviewed by: peter, jhb Approved by: peter
* make this repect ps_sigintr if there is a pre-existing signaljulian2002-07-061-1/+0
| | | | | | or suspension request. Submitted by: David Xu
* Fix at least one of the things wrong with signalsjulian2002-07-061-6/+9
| | | | | | ^Z should work a lot better now. Submitted by: peter@freebsd.org
* Try clean up some of the mess that resulted from layers and layersjulian2002-07-031-2/+1
| | | | | | of p4 merges from -current as things started getting different. Corroborated by: Similar patches just mailed by BDE.
* When going back to SLEEP state, make sure ourjulian2002-07-021-0/+1
| | | | State is correctly marked so.
* Part 1 of KSE-IIIjulian2002-06-291-80/+195
| | | | | | | | | | | | | 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..
* more caddr_t removal.alfred2002-06-291-4/+4
|
* I Noticed a defect in the way wakeup() scans the tailq. Tor noticed andillon2002-06-241-3/+8
| | | | | | | even worse defect in wakeup_one(). This patch cleans up both. Submitted by: tegge MFC after: 3 days
* - Catch up to new ktrace API.jhb2002-06-071-7/+5
| | | | - ktrace trace points in msleep() and cv_wait() no longer need Giant.
* CURSIG() is not a macro so rename it cursig().julian2002-05-291-6/+6
| | | | Obtained from: KSE tree
* Minor nit: get p pointer in msleep() from td->td_proc (wherejhb2002-05-231-1/+1
| | | | td == curthread) rather than from curproc.
* Remove __P.alfred2002-03-191-5/+5
|
* Fix a gcc-3.1+ warning.peter2002-03-191-0/+1
| | | | | | | | | | | warning: deprecated use of label at end of compound statement ie: you cannot do this anymore: switch(foo) { .... default: }
* Convert p->p_runtime and PCPU(switchtime) to bintime format.phk2002-02-221-17/+6
|
* In a threaded world, differnt priorirites become properties ofjulian2002-02-111-22/+26
| | | | | | different entities. Make it so. Reviewed by: jhb@freebsd.org (john baldwin)
* Change the preemption code for software interrupt thread schedules andjhb2002-01-051-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | mutex releases to not require flags for the cases when preemption is not allowed: The purpose of the MTX_NOSWITCH and SWI_NOSWITCH flags is to prevent switching to a higher priority thread on mutex releease and swi schedule, respectively when that switch is not safe. Now that the critical section API maintains a per-thread nesting count, the kernel can easily check whether or not it should switch without relying on flags from the programmer. This fixes a few bugs in that all current callers of swi_sched() used SWI_NOSWITCH, when in fact, only the ones called from fast interrupt handlers and the swi_sched of softclock needed this flag. Note that to ensure that swi_sched()'s in clock and fast interrupt handlers do not switch, these handlers have to be explicitly wrapped in critical_enter/exit pairs. Presently, just wrapping the handlers is sufficient, but in the future with the fully preemptive kernel, the interrupt must be EOI'd before critical_exit() is called. (critical_exit() can switch due to a deferred preemption in a fully preemptive kernel.) I've tested the changes to the interrupt code on i386 and alpha. I have not tested ia64, but the interrupt code is almost identical to the alpha code, so I expect it will work fine. PowerPC and ARM do not yet have interrupt code in the tree so they shouldn't be broken. Sparc64 is broken, but that's been ok'd by jake and tmm who will be fixing the interrupt code for sparc64 shortly. Reviewed by: peter Tested on: i386, alpha
OpenPOWER on IntegriCloud