summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_synch.c
Commit message (Collapse)AuthorAgeFilesLines
...
* Remove a stale and misleading comment.tjr2004-06-071-7/+0
|
* Fixed some common printf format errors. Don't assume that "struct foo *"bde2004-05-141-19/+14
| | | | | | | | is "void *" (it isn't) or that the default promotion of pid_t is int. Instead, assume that casting "struct foo *" to "void *" and printing the result with %p is useful, and that all pid_t's are representable as longs. Fixed some minor style bugs (mainly spelling errors in comments).
* Remove advertising clause from University of California Regent's license,imp2004-04-051-4/+0
| | | | | | per letter dated July 22, 1999. Approved by: core
* - Remove old sleep queues.jhb2004-03-121-13/+1
| | | | | - Remove sleepqueue argument from sleepq_set_timeout() since it is not used.
* Mark loadaverage callout as CALLOUT_MPSAFE.rwatson2004-03-081-1/+1
| | | | Reviewed by: jhb
* Correct handling of PDROP in msleep() to just skip the mtx_lock() ratherjhb2004-03-021-3/+1
| | | | | than clear the lock pointer so that sleepq_add() still gets the correct lock pointer and doesn't bogusly trip an assertion.
* Switch the sleep/wakeup and condition variable implementations to use thejhb2004-02-271-217/+81
| | | | | | | | | | | | | | | | | | | | | | | | | | | sleep queue interface: - Sleep queues attempt to merge some of the benefits of both sleep queues and condition variables. Having sleep qeueus in a hash table avoids having to allocate a queue head for each wait channel. Thus, struct cv has shrunk down to just a single char * pointer now. However, the hash table does not hold threads directly, but queue heads. This means that once you have located a queue in the hash bucket, you no longer have to walk the rest of the hash chain looking for threads. Instead, you have a list of all the threads sleeping on that wait channel. - Outside of the sleepq code and the sleep/cv code the kernel no longer differentiates between cv's and sleep/wakeup. For example, calls to abortsleep() and cv_abort() are replaced with a call to sleepq_abort(). Thus, the TDF_CVWAITQ flag is removed. Also, calls to unsleep() and cv_waitq_remove() have been replaced with calls to sleepq_remove(). - The sched_sleep() function no longer accepts a priority argument as sleep's no longer inherently bump the priority. Instead, this is soley a propery of msleep() which explicitly calls sched_prio() before blocking. - The TDF_ONSLEEPQ flag has been dropped as it was never used. The associated TDF_SET_ONSLEEPQ and TDF_CLR_ON_SLEEPQ macros have also been dropped and replaced with a single explicit clearing of td_wchan. TD_SET_ONSLEEPQ() would really have only made sense if it had taken the wait channel and message as arguments anyway. Now that that only happens in one place, a macro would be overkill.
* - Revert rev 1.240 we no longer need a kthread for loadav().jeff2004-02-011-31/+12
|
* - Use sched_load() rather than grabbing the sx lock and traversing the procjeff2004-02-011-20/+2
| | | | table to discover the load.
* Move the loadav() callout into its own kthread since it uses allproc_lockjhb2004-01-281-12/+31
| | | | | which is a sleepable lock and thus is not safe to acquire from a callout routine.
* - Use a unique string for the sched_setup SYSINIT and rename sched_setup tojeff2004-01-251-3/+3
| | | | synch_setup. The schedulers use the sched_setup function name.
* - Add a flags parameter to mi_switch. The value of flags may be SW_VOL orjeff2004-01-251-7/+10
| | | | | | | | | | SW_INVOL. Assert that one of these is set in mi_switch() and propery adjust the rusage statistics. This is to simplify the large number of users of this interface which were previously all required to adjust the proper counter prior to calling mi_switch(). This also facilitates more switch and locking optimizations. - Change all callers of mi_switch() to pass the appropriate paramter and remove direct references to the process statistics.
* Removed mostly-dead code for setting switchtime after the idle loopbde2003-10-291-8/+2
| | | | | | | | | | | | | | | | | | | | | | clobbers this variable. Long ago, when the idle loop wasn't in a process, it set switchtime.tv_sec to zero to indicate that the time needs to be read after the idle loop finishes. The special case for this isn't needed now that there is an idle process (for each CPU). The time is read in the normal way when the idle process is switched away from. The seconds component of the time is only zero for the first second after the uptime is set, and the mostly-dead code was only executed during this time. (This was slightly broken by using uptimes instead of times relative to the Epoch -- in the original version the seconds component of the time was only 0 for the first second after the Epoch.) In mi_switch(), moved the setting of switchticks to just after the first (and now only) setting of switchtime. This setting used to be delayed since a late setting was needed for the idle case and an early setting was not needed. Now the early setting is needed so that fork_exit() doesn't need to set either switchtime or switchticks. Removed now-completely-rotted comment attached to this. Most of the code described by the comment had already moved to sched_switch().
* - Collapse sched_switchin() and sched_switchout() into sched_switch(). Nowjeff2003-10-161-12/+1
| | | | | mi_switch() calls sched_switch() which calls cpu_switch(). This is actually one less function call than it had been.
* Add a pre-emption counter, td_generation, so that threads can noticebms2003-10-051-0/+2
| | | | | | | when they have been pre-empted by other threads. This is bumped from within mi_switch() every time a context switch takes place. Discussed with: pete
* - On my Pentium4-M laptop, invalpg takes ~1100 cycles if the page is found injeff2003-09-301-8/+0
| | | | | | | | | | the TLB and ~1600 if it is not. Therefore, it is more effecient to invalidate the TLB after operations that use CMAP rather than before. - So that the tlb is invalidated prior to switching off of a processor, we must change the switchin functions to switchout functions. - Remove td_switchout from the thread and move it to the x86 pcb. - Move the code that calls switchout into swtch.s. These changes make this optimization truely x86 specific.
* Change instances of callout_init that specify MPSAFE behaviour tosam2003-08-191-1/+1
| | | | | use CALLOUT_MPSAFE instead of "1" for the second parameter. This does not change the behaviour; it just makes the intent more clear.
* - Various style fixes in both code and comments.jhb2003-08-151-18/+16
| | | | | | | | | - Update some stale comments. - Sort a couple of includes. - Only set 'newcpu' in updatepri() if we use it. - No functional changes. Obtained from: bde (via an old diff I got a long time ago)
* Update powerpc to use the (old thread,new thread) calling conventiongrehan2003-08-141-6/+0
| | | | for cpu_throw() and cpu_switch().
* - Convert Alpha over to the new calling conventions for cpu_throw() andjhb2003-08-121-2/+2
| | | | | | | | cpu_switch() where both the old and new threads are passed in as arguments. Only powerpc uses the old conventions now. - Update comments in the Alpha swtch.s to reflect KSE changes. Tested by: obrien, marcel
* unifdef -DLAZY_SWITCH and start to tidy up the associated glue.peter2003-07-101-3/+0
|
* o Change kse_thr_interrupt to allow send a signal to a specified thread,davidxu2003-06-281-8/+10
| | | | | | | | | | | | | | | | | or unblock a thread in kernel, and allow UTS to specify whether syscall should be restarted. o Add ability for UTS to monitor signal comes in and removed from process, the flag PS_SIGEVENT is used to indicate the events. o Add a KMF_WAITSIGEVENT for KSE mailbox flag, UTS call kse_release with this flag set to wait for above signal event. o For SA based thread, kernel masks all signal in its signal mask, let UTS to use kse_thr_interrupt interrupt a thread, and install a signal frame in userland for the thread. o Add a tm_syncsig in thread mailbox, when a hardware trap occurs, it is used to deliver synchronous signal to userland, and upcall is schedule, so UTS can process the synchronous signal for the thread. Reviewed by: julian (mentor)
* Tidy up leftover lazy_switch instrumentation that is no longer needed.peter2003-06-271-7/+0
| | | | This cleans up some #ifdef hell.
* Rename P_THREADED to P_SA. P_SA means a process is using schedulerdavidxu2003-06-151-2/+2
| | | | activations.
* Use __FBSDID().obrien2003-06-111-1/+3
|
* Add a couple of XXX comments where the intent is not clear.phk2003-05-311-0/+2
| | | | Found by: FlexeLint
* Revamp of the syscall path, exception and context handling. Themarcel2003-05-161-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | prime objectives are: o Implement a syscall path based on the epc inststruction (see sys/ia64/ia64/syscall.s). o Revisit the places were we need to save and restore registers and define those contexts in terms of the register sets (see sys/ia64/include/_regset.h). Secundairy objectives: o Remove the requirement to use contigmalloc for kernel stacks. o Better handling of the high FP registers for SMP systems. o Switch to the new cpu_switch() and cpu_throw() semantics. o Add a good unwinder to reconstruct contexts for the rare cases we need to (see sys/contrib/ia64/libuwx) Many files are affected by this change. Functionally it boils down to: o The EPC syscall doesn't preserve registers it does not need to preserve and places the arguments differently on the stack. This affects libc and truss. o The address of the kernel page directory (kptdir) had to be unstaticized for use by the nested TLB fault handler. The name has been changed to ia64_kptdir to avoid conflicts. The renaming affects libkvm. o The trapframe only contains the special registers and the scratch registers. For syscalls using the EPC syscall path no scratch registers are saved. This affects all places where the trapframe is accessed. Most notably the unaligned access handler, the signal delivery code and the debugger. o Context switching only partly saves the special registers and the preserved registers. This affects cpu_switch() and triggered the move to the new semantics, which additionally affects cpu_throw(). o The high FP registers are either in the PCB or on some CPU. context switching for them is done lazily. This affects trap(). o The mcontext has room for all registers, but not all of them have to be defined in all cases. This mostly affects signal delivery code now. The *context syscalls are as of yet still unimplemented. Many details went into the removal of the requirement to use contigmalloc for kernel stacks. The details are mostly CPU specific and limited to exception_save() and exception_restore(). The few places where we create, destroy or switch stacks were mostly simplified by not having to construct physical addresses and additionally saving the virtual addresses for later use. Besides more efficient context saving and restoring, which of course yields a noticable speedup, this also fixes the dreaded SMP bootup problem as a side-effect. The details of which are still not fully understood. This change includes all the necessary backward compatibility code to have it handle older userland binaries that use the break instruction for syscalls. Support for break-based syscalls has been pessimized in favor of a clean implementation. Due to the overall better performance of the kernel, this will still be notived as an improvement if it's noticed at all. Approved by: re@ (jhb)
* - Merge struct procsig with struct sigacts.jhb2003-05-131-0/+4
| | | | | | | | | | | | | | | | | - Move struct sigacts out of the u-area and malloc() it using the M_SUBPROC malloc bucket. - Add a small sigacts_*() API for managing sigacts structures: sigacts_alloc(), sigacts_free(), sigacts_copy(), sigacts_share(), and sigacts_shared(). - Remove the p_sigignore, p_sigacts, and p_sigcatch macros. - Add a mutex to struct sigacts that protects all the members of the struct. - Add sigacts locking. - Remove Giant from nosys(), kill(), killpg(), and kern_sigaction() now that sigacts is locked. - Several in-kernel functions such as psignal(), tdsignal(), trapsignal(), and thread_stopped() are now MP safe. Reviewed by: arch@ Approved by: re (rwatson)
* Remove TD_ON_RUNQ() from a check to make sure Giant is not held whenjhb2003-05-051-3/+1
| | | | | calling mi_switch(). The kernel would panic on an earlier KASSERT() in mi_switch() if TD_ON_RUNQ() was true.
* Garbage collect unused TDF_INMSLEEP flag.jhb2003-05-011-1/+0
|
* AMD64 uses the new-style cpu_switch()/cpu_throw() calling conventions.peter2003-04-301-2/+2
|
* - Protect p_numthreads with the sched_lock.jhb2003-04-231-1/+2
| | | | | - Protect p_singlethread with both the sched_lock and the proc lock. - Protect p_suspcount with the proc lock.
* 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.
OpenPOWER on IntegriCloud