summaryrefslogtreecommitdiff
path: root/sys/kern/kern_synch.c
Commit message (Collapse)AuthorAgeFilesLines
...
* Add in assertions to ensure that we always call msleep or mawait withJohn Baldwin2001-05-231-0/+4
| | | | | | | | | | either a timeout or a held mutex to detect unprotected infinite sleeps that can easily lead to deadlock. Submitted by: alfred Notes: svn path=/head/; revision=77059
* Remove KASSERT test for sleeping on mv_mtx, instead let WITNESS catchAlfred Perlstein2001-05-221-2/+0
| | | | | | | | | it. Requested by: jhb Notes: svn path=/head/; revision=76950
* remove my private assertions from tsleep.Alfred Perlstein2001-05-191-7/+2
| | | | | | | add one assertion to ensure we don't sleep while holding vm. Notes: svn path=/head/; revision=76830
* Introduce a global lock for the vm subsystem (vm_mtx).Alfred Perlstein2001-05-191-0/+7
| | | | | | | | | | | | | | | | | | | | | | vm_mtx does not recurse and is required for most low level vm operations. faults can not be taken without holding Giant. Memory subsystems can now call the base page allocators safely. Almost all atomic ops were removed as they are covered under the vm mutex. Alpha and ia64 now need to catch up to i386's trap handlers. FFS and NFS have been tested, other filesystems will need minor changes (grabbing the vm lock when twiddling page properties). Reviewed (partially) by: jake, jhb Notes: svn path=/head/; revision=76827
* - Remove unneeded include of sys/ipl.h.John Baldwin2001-05-151-1/+2
| | | | | | | | - Lock the process before calling killproc() to kill it for exceeding the maximum CPU limit. Notes: svn path=/head/; revision=76647
* Overhaul of the SMP code. Several portions of the SMP kernel support haveJohn Baldwin2001-04-271-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | been made machine independent and various other adjustments have been made to support Alpha SMP. - It splits the per-process portions of hardclock() and statclock() off into hardclock_process() and statclock_process() respectively. hardclock() and statclock() call the *_process() functions for the current process so that UP systems will run as before. For SMP systems, it is simply necessary to ensure that all other processors execute the *_process() functions when the main clock functions are triggered on one CPU by an interrupt. For the alpha 4100, clock interrupts are delievered in a staggered broadcast fashion, so we simply call hardclock/statclock on the boot CPU and call the *_process() functions on the secondaries. For x86, we call statclock and hardclock as usual and then call forward_hardclock/statclock in the MD code to send an IPI to cause the AP's to execute forwared_hardclock/statclock which then call the *_process() functions. - forward_signal() and forward_roundrobin() have been reworked to be MI and to involve less hackery. Now the cpu doing the forward sets any flags, etc. and sends a very simple IPI_AST to the other cpu(s). AST IPIs now just basically return so that they can execute ast() and don't bother with setting the astpending or needresched flags themselves. This also removes the loop in forward_signal() as sched_lock closes the race condition that the loop worked around. - need_resched(), resched_wanted() and clear_resched() have been changed to take a process to act on rather than assuming curproc so that they can be used to implement forward_roundrobin() as described above. - Various other SMP variables have been moved to a MI subr_smp.c and a new header sys/smp.h declares MI SMP variables and API's. The IPI API's from machine/ipl.h have moved to machine/smp.h which is included by sys/smp.h. - The globaldata_register() and globaldata_find() functions as well as the SLIST of globaldata structures has become MI and moved into subr_smp.c. Also, the globaldata list is only available if SMP support is compiled in. Reviewed by: jake, peter Looked over by: eivind Notes: svn path=/head/; revision=76078
* Convert the allproc and proctree locks from lockmgr locks to sx locks.John Baldwin2001-03-281-6/+7
| | | | Notes: svn path=/head/; revision=74927
* Rework the witness code to work with sx locks as well as mutexes.John Baldwin2001-03-281-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Introduce lock classes and lock objects. Each lock class specifies a name and set of flags (or properties) shared by all locks of a given type. Currently there are three lock classes: spin mutexes, sleep mutexes, and sx locks. A lock object specifies properties of an additional lock along with a lock name and all of the extra stuff needed to make witness work with a given lock. This abstract lock stuff is defined in sys/lock.h. The lockmgr constants, types, and prototypes have been moved to sys/lockmgr.h. For temporary backwards compatability, sys/lock.h includes sys/lockmgr.h. - Replace proc->p_spinlocks with a per-CPU list, PCPU(spinlocks), of spin locks held. By making this per-cpu, we do not have to jump through magic hoops to deal with sched_lock changing ownership during context switches. - Replace proc->p_heldmtx, formerly a list of held sleep mutexes, with proc->p_sleeplocks, which is a list of held sleep locks including sleep mutexes and sx locks. - Add helper macros for logging lock events via the KTR_LOCK KTR logging level so that the log messages are consistent. - Add some new flags that can be passed to mtx_init(): - MTX_NOWITNESS - specifies that this lock should be ignored by witness. This is used for the mutex that blocks a sx lock for example. - MTX_QUIET - this is not new, but you can pass this to mtx_init() now and no events will be logged for this lock, so that one doesn't have to change all the individual mtx_lock/unlock() operations. - All lock objects maintain an initialized flag. Use this flag to export a mtx_initialized() macro that can be safely called from drivers. Also, we on longer walk the all_mtx list if MUTEX_DEBUG is defined as witness performs the corresponding checks using the initialized flag. - The lock order reversal messages have been improved to output slightly more accurate file and line numbers. Notes: svn path=/head/; revision=74912
* - Proc locking.John Baldwin2001-03-071-25/+7
| | | | | | | - Remove unneeded spl()'s. Notes: svn path=/head/; revision=73915
* Add a mtx_assert() in maybe_resched() just to be sure it's always calledJohn Baldwin2001-02-221-0/+1
| | | | | | | with sched_lock held. Notes: svn path=/head/; revision=72886
* - Use the new NOCPU constant.John Baldwin2001-02-221-2/+2
| | | | | | | | | - Fix a warning. Noticed by: bde (2) Notes: svn path=/head/; revision=72828
* - Don't call clear_resched() in userret(), instead, clear the resched flagJohn Baldwin2001-02-201-0/+8
| | | | | | | | | | | | | | | in mi_switch() just before calling cpu_switch() so that the first switch after a resched request will satisfy the request. - While I'm at it, move a few things into mi_switch() and out of cpu_switch(), specifically set the p_oncpu and p_lastcpu members of proc in mi_switch(), and handle the sched_lock state change across a context switch in mi_switch(). - Since cpu_switch() no longer handles the sched_lock state change, we have to setup an initial state for sched_lock in fork_exit() before we release it. Notes: svn path=/head/; revision=72746
* Implement a unified run queue and adjust priority levels accordingly.Jake Burkholder2001-02-121-58/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - All processes go into the same array of queues, with different scheduling classes using different portions of the array. This allows user processes to have their priorities propogated up into interrupt thread range if need be. - I chose 64 run queues as an arbitrary number that is greater than 32. We used to have 4 separate arrays of 32 queues each, so this may not be optimal. The new run queue code was written with this in mind; changing the number of run queues only requires changing constants in runq.h and adjusting the priority levels. - The new run queue code takes the run queue as a parameter. This is intended to be used to create per-cpu run queues. Implement wrappers for compatibility with the old interface which pass in the global run queue structure. - Group the priority level, user priority, native priority (before propogation) and the scheduling class into a struct priority. - Change any hard coded priority levels that I found to use symbolic constants (TTIPRI and TTOPRI). - Remove the curpriority global variable and use that of curproc. This was used to detect when a process' priority had lowered and it should yield. We now effectively yield on every interrupt. - Activate propogate_priority(). It should now have the desired effect without needing to also propogate the scheduling class. - Temporarily comment out the call to vm_page_zero_idle() in the idle loop. It interfered with propogate_priority() because the idle process needed to do a non-blocking acquire of Giant and then other processes would try to propogate their priority onto it. The idle process should not do anything except idle. vm_page_zero_idle() will return in the form of an idle priority kernel thread which is woken up at apprioriate times by the vm system. - Update struct kinfo_proc to the new priority interface. Deliberately change its size by adjusting the spare fields. It remained the same size, but the layout has changed, so userland processes that use it would parse the data incorrectly. The size constraint should really be changed to an arbitrary version number. Also add a debug.sizeof sysctl node for struct kinfo_proc. Notes: svn path=/head/; revision=72376
* Acquire sched_lock around need_resched() in roundrobin() to satisfyJake Burkholder2001-02-101-8/+4
| | | | | | | | assertions that it is held. Since roundrobin() is a timeout there's no possible way that it could be called with sched_lock held. Notes: svn path=/head/; revision=72330
* Change and clean the mutex lock interface.Bosko Milekic2001-02-091-42/+42
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | mtx_enter(lock, type) becomes: mtx_lock(lock) for sleep locks (MTX_DEF-initialized locks) mtx_lock_spin(lock) for spin locks (MTX_SPIN-initialized) similarily, for releasing a lock, we now have: mtx_unlock(lock) for MTX_DEF and mtx_unlock_spin(lock) for MTX_SPIN. We change the caller interface for the two different types of locks because the semantics are entirely different for each case, and this makes it explicitly clear and, at the same time, it rids us of the extra `type' argument. The enter->lock and exit->unlock change has been made with the idea that we're "locking data" and not "entering locked code" in mind. Further, remove all additional "flags" previously passed to the lock acquire/release routines with the exception of two: MTX_QUIET and MTX_NOSWITCH The functionality of these flags is preserved and they can be passed to the lock/unlock routines by calling the corresponding wrappers: mtx_{lock, unlock}_flags(lock, flag(s)) and mtx_{lock, unlock}_spin_flags(lock, flag(s)) for MTX_DEF and MTX_SPIN locks, respectively. Re-inline some lock acq/rel code; in the sleep lock case, we only inline the _obtain_lock()s in order to ensure that the inlined code fits into a cache line. In the spin lock case, we inline recursion and actually only perform a function call if we need to spin. This change has been made with the idea that we generally tend to avoid spin locks and that also the spin locks that we do have and are heavily used (i.e. sched_lock) do recurse, and therefore in an effort to reduce function call overhead for some architectures (such as alpha), we inline recursion for this case. Create a new malloc type for the witness code and retire from using the M_DEV type. The new type is called M_WITNESS and is only declared if WITNESS is enabled. Begin cleaning up some machdep/mutex.h code - specifically updated the "optimized" inlined code in alpha/mutex.h and wrote MTX_LOCK_SPIN and MTX_UNLOCK_SPIN asm macros for the i386/mutex.h as we presently need those. Finally, caught up to the interface changes in all sys code. Contributors: jake, jhb, jasone (in no particular order) Notes: svn path=/head/; revision=72200
* Zap last remaining references to (and a use use of) of simple_locks.Peter Wemm2001-01-311-4/+0
| | | | Notes: svn path=/head/; revision=71858
* - Catch up to proc flag changes.John Baldwin2001-01-241-25/+29
| | | | | | | | | - Add in some locking ops that might fix SIGXCPU, but don't enable them yet. - Assert that sched_lock is not recursed when mi_switch() is called. Notes: svn path=/head/; revision=71564
* Do not do the commenting out the way that saves bytes and looks cleanerMatt Jacob2001-01-231-1/+4
| | | | | | | to you. Do it the way Vox Populi wants it. Notes: svn path=/head/; revision=71436
* Move (now) unused variable declaration inside the block (now commented out).Matt Jacob2001-01-221-2/+1
| | | | Notes: svn path=/head/; revision=71391
* Temporarily disable the printf() for micruptime() going backwards, theJohn Baldwin2001-01-201-0/+5
| | | | | | | | | | SIGXCPU signal, and killing of processes that exceed their allowed run time until they can play nice with sched_lock. Right now they are just potentital panics waiting to happen. The printf() has bitten several people. Notes: svn path=/head/; revision=71288
* Implement condition variables.Jason Evans2001-01-161-6/+8
| | | | Notes: svn path=/head/; revision=71088
* Use PCPU_GET, PCPU_PTR and PCPU_SET to access all per-cpu variablesJake Burkholder2001-01-101-11/+12
| | | | | | | other then curproc. Notes: svn path=/head/; revision=70861
* - Change the allproc_lock to use a macro, ALLPROC_LOCK(how), insteadJake Burkholder2000-12-131-2/+2
| | | | | | | | | | | of explicit calls to lockmgr. Also provides macros for the flags pased to specify shared, exclusive or release which map to the lockmgr flags. This is so that the use of lockmgr can be easily replaced with optimized reader-writer locks. - Add some locking that I missed the first time. Notes: svn path=/head/; revision=69947
* Add in #include of <sys/lock.h> since it was axed from <sys/proc.h>.John Baldwin2000-12-061-0/+1
| | | | | | | | Noticed by: Wesley Morgan <morganw@chemikals.org> Pointy hat to: me Notes: svn path=/head/; revision=69645
* Remove thr_sleep and thr_wakeup. Remove fields p_nthread and p_wakeupJake Burkholder2000-12-021-0/+25
| | | | | | | | | | | | | from struct proc, which are now unused (p_nthread already was). Remove process flag P_KTHREADP which was untested and only set in vfs_aio.c (it should use kthread_create). Move the yield system call to kern_synch.c as kern_threads.c has been removed completely. moral support from: alfred, jhb Notes: svn path=/head/; revision=69512
* Use an mp-safe callout for endtsleep.Jake Burkholder2000-12-011-0/+2
| | | | Notes: svn path=/head/; revision=69437
* Fix up priority propagation:John Baldwin2000-11-301-1/+0
| | | | | | | | | | - Use a better test for determining when a process is running. - Convert some checks to assertions. - Remove unnecessary tests. - Save the priority before acquiring a mutex rather than in msleep(9). Notes: svn path=/head/; revision=69376
* Don't drop Giant and the passed in mutex incorrectly in theJohn Baldwin2000-11-291-10/+12
| | | | | | | | cold || panicstr case. Do drop the passed in mutex in that case if PDROP is specified. Notes: svn path=/head/; revision=69360
* Use callout_reset instead of timeout(9). Most callouts are staticallyJake Burkholder2000-11-271-8/+13
| | | | | | | | | allocated, 2 have been added to struct proc for setitimer and sleep. Reviewed by: jhb, jlemon Notes: svn path=/head/; revision=69286
* Protect the following with a lockmgr lock:Jake Burkholder2000-11-221-0/+2
| | | | | | | | | | | | | | | allproc zombproc pidhashtbl proc.p_list proc.p_hash nextpid Reviewed by: jhb Obtained from: BSD/OS and netbsd Notes: svn path=/head/; revision=69022
* - Split the run queue and sleep queue linkage, so that a processJake Burkholder2000-11-171-9/+9
| | | | | | | | | | | | may block on a mutex while on the sleep queue without corrupting it. - Move dropping of Giant to after the acquire of sched_lock. Tested by: John Hay <jhay@icomtek.csir.co.za> jhb Notes: svn path=/head/; revision=68862
* Don't release and acquire Giant in mi_switch(). Instead, release andJohn Baldwin2000-11-161-16/+5
| | | | | | | | | | | acquire Giant as needed in functions that call mi_switch(). The releases need to be done outside of the sched_lock to avoid potential deadlocks from trying to acquire Giant while interrupts are disabled. Submitted by: witness Notes: svn path=/head/; revision=68808
* Argh, add in a missing release of the sched_lock.John Baldwin2000-11-161-0/+1
| | | | Notes: svn path=/head/; revision=68805
* CURSIG() calls functions that acquire sleep mutexes, so it is not a goodJohn Baldwin2000-11-161-3/+12
| | | | | | | | | | | idea to be holding the sched_lock while we are calling it. As such, release sched_lock before calling CURSIG() in msleep() and mawait() and reacquire it after CURSIG() returns. Submitted by: witness Notes: svn path=/head/; revision=68804
* - Rename await() to mawait(). mawait() is to await() as msleep() is toJohn Baldwin2000-11-151-14/+27
| | | | | | | | | | | | tsleep(). Namely, mawait() takes an extra argument which is a mutex to drop when going to sleep. Just as with msleep(), if the priority argument includes the PDROP flag, then the mutex will be dropped and will not be reacquired when the process wakes up. - Add in a backwards compatible macro await() that passes in NULL as the mutex argument to mawait(). Notes: svn path=/head/; revision=68794
* - Replace a KASSERT() that knew too much about mutex internals with aJohn Baldwin2000-11-151-2/+1
| | | | | | | | mtx_assert() that ensures the mutex we release during msleep() is both not recursed and owned by the current process. Notes: svn path=/head/; revision=68793
* - Convert references from tsleep() -> msleep()John Baldwin2000-11-151-9/+9
| | | | | | | - Fix a buglet in a comment above await() Notes: svn path=/head/; revision=68792
* - GC some #if 0'd code regarding the non-existant safepri variable.John Baldwin2000-10-201-17/+6
| | | | | | | | - Don't dink with the witness state of Giant unless we actually own it during mi_switch(). Notes: svn path=/head/; revision=67362
* - Change fast interrupts on x86 to push a full interrupt frame and toJohn Baldwin2000-10-061-6/+8
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | return through doreti to handle ast's. This is necessary for the clock interrupts to work properly. - Change the clock interrupts on the x86 to be fast instead of threaded. This is needed because both hardclock() and statclock() need to run in the context of the current process, not in a separate thread context. - Kill the prevproc hack as it is no longer needed. - We really need Giant when we call psignal(), but we don't want to block during the clock interrupt. Instead, use two p_flag's in the proc struct to mark the current process as having a pending SIGVTALRM or a SIGPROF and let them be delivered during ast() when hardclock() has finished running. - Remove CLKF_BASEPRI, which was #ifdef'd out on the x86 anyways. It was broken on the x86 if it was turned on since cpl is gone. It's only use was to bogusly run softclock() directly during hardclock() rather than scheduling an SWI. - Remove the COM_LOCK simplelock and replace it with a clock_lock spin mutex. Since the spin mutex already handles disabling/restoring interrupts appropriately, this also lets us axe all the *_intr() fu. - Back out the hacks in the APIC_IO x86 cpu_initclocks() code to use temporary fast interrupts for the APIC trial. - Add two new process flags P_ALRMPEND and P_PROFPEND to mark the pending signals in hardclock() that are to be delivered in ast(). Submitted by: jakeb (making statclock safe in a fast interrupt) Submitted by: cp (concept of delaying signals until ast()) Notes: svn path=/head/; revision=66716
* Add a KASSERT() to catch instances where the mutex that we pass in toJohn Baldwin2000-09-241-0/+2
| | | | | | | | | msleep() are recursed. Suggested by: cp Notes: svn path=/head/; revision=66314
* Remove the mtx_t, witness_t, and witness_blessed_t types. Instead, justJohn Baldwin2000-09-141-1/+1
| | | | | | | | | use struct mtx, struct witness, and struct witness_blessed. Requested by: bde Notes: svn path=/head/; revision=65856
* Rename tsleep to msleep and add a mutex argument, which isJake Burkholder2000-09-111-4/+19
| | | | | | | | | | | | | | | | | | | released before sleeping and re-acquired before msleep returns. A compatibility cpp macro has been provided for tsleep to avoid changing all occurences of it in the kernel. Remove an assertion that the Giant mutex be held before calling tsleep or asleep. This is intended to serve the same purpose as condition variables, but does not preclude their addition in the future. Approved by: jasone Obtained from: BSD/OS Notes: svn path=/head/; revision=65708
* Fix printf warnings in CTRx calls.Doug Rabson2000-09-101-18/+18
| | | | Notes: svn path=/head/; revision=65682
* Major update to the way synchronization is done in the kernel. HighlightsJason Evans2000-09-071-14/+101
| | | | | | | | | | | | | | | | | | include: * Mutual exclusion is used instead of spl*(). See mutex(9). (Note: The alpha port is still in transition and currently uses both.) * Per-CPU idle processes. * Interrupts are run in their own separate kernel threads and can be preempted (i386 only). Partially contributed by: BSDi (BSD/OS) Submissions by (at least): cp, dfr, dillon, grog, jake, jhb, sheldonh Notes: svn path=/head/; revision=65557
* Previous commit changing SYSCTL_HANDLER_ARGS violated KNF.Poul-Henning Kamp2000-07-041-1/+1
| | | | | | | Pointed out by: bde Notes: svn path=/head/; revision=62573
* Style police catches up with rev 1.26 of src/sys/sys/sysctl.h:Poul-Henning Kamp2000-07-031-1/+1
| | | | | | | | | | | Sanitize SYSCTL_HANDLER_ARGS so that simplistic tools can grog our sources: -sysctl_vm_zone SYSCTL_HANDLER_ARGS +sysctl_vm_zone (SYSCTL_HANDLER_ARGS) Notes: svn path=/head/; revision=62454
* Back out the previous change to the queue(3) interface.Jake Burkholder2000-05-261-1/+1
| | | | | | | | | It was not discussed and should probably not happen. Requested by: msmith and others Notes: svn path=/head/; revision=60938
* Change the way that the queue(3) structures are declared; don't assume thatJake Burkholder2000-05-231-1/+1
| | | | | | | | | | | the type argument to *_HEAD and *_ENTRY is a struct. Suggested by: phk Reviewed by: phk Approved by: mdodd Notes: svn path=/head/; revision=60833
* Correct a couple of typos.Greg Lehey2000-05-071-2/+2
| | | | Notes: svn path=/head/; revision=60120
* Change the scheduler to actually respect the PUSER barrier. It's beenBrian Feldman2000-04-301-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | wrong for many years that negative niceness would lower the priority of a process below PUSER, and once below PUSER, there were conditionals in the code that are required to test for whether a process was in the kernel which would break. The breakage could (and did) cause lock-ups, basically nothing else but the least nice program being able to run in some conditions. The algorithm which adjusts the priority now subtracts PRIO_MIN to do things properly, and the ESTCPULIM() algorithm was updated to use PRIO_TOTAL (PRIO_MAX - PRIO_MIN) to calculate the estcpu. NICE_WEIGHT is now 1 to accomodate the full range of priorities better (a -20 process with full CPU time has the priority of a +0 process with no CPU time). There are now 20 queues (exactly; 80 priorities) for use in user processes' scheduling, and PUSER has been lowered to 48 to accomplish this. This means, to the user, that things will be scheduled more correctly (noticeable), there is no lock-up anymore WRT a niced -20 process never releasing the CPU time for other processes. In this fair system, tsleep()ed < PUSER processes now will get the proper higher priority than priority >= PUSER user processes. The detective work of this was done by me, along with part of the solution. Luoqi Chen has provided most of the solution, and really helped me understand what was happening better, to boot :) Submitted by: luoqi Concept reviewed by: bde Notes: svn path=/head/; revision=59792