summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_mutex.c
Commit message (Collapse)AuthorAgeFilesLines
* Disable the kernacc() check in mtx_validate() until such time that kernaccphk2002-10-251-0/+5
| | | | | | | | | does not require Giant. This means that we may miss panics on a class of mutex programming bugs, but only if running with a Chernobyl setting of debug-flags. Spotted by: Pete Carah <pete@ns.altadena.net>
* Whitespace cleanup.des2002-10-231-10/+9
|
* Change the `mutex_prof' structure to use three variables containedrobert2002-10-221-18/+14
| | | | | | in an anonymous structure as counters, instead of an array with preprocessor-defined names for indices. Remove the associated XXX- comment.
* Reduce the overhead of the mutex statistics gathering code, try to producedes2002-10-211-19/+28
| | | | shorter lines in the report, and clean up some minor style issues.
* - Create a new scheduler api that is defined in sys/sched.hjeff2002-10-121-4/+2
| | | | | | | | | | - 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
* Rename the mutex thread and process states to use a more generic 'LOCK'jhb2002-10-021-13/+13
| | | | | | | | | 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.
* uh, commit all of the patchjulian2002-09-291-0/+1
|
* commit the version I actually tested..julian2002-09-291-2/+4
| | | | Submitted by: davidxu
* Implement basic KSE loaning. This stops a hread that is blocked in BOUND modejulian2002-09-291-1/+2
| | | | | | | | | 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-7/+6
| | | | Reviewed by: davidxu@freebsd.org
* Add some KASSERT()'s to ensure that we don't perform spin mutex ops onjhb2002-09-031-4/+16
| | | | | | sleep mutexes and vice versa. WITNESS normally should catch this but not everyone uses WITNESS so this is a fallback to catch nasty but easy to do bugs.
* Add a new KTR type KTR_CONTENTION, and use it in the mutex code toiedowse2002-08-261-0/+20
| | | | | | | | log the start and end of periods during which mtx_lock() is waiting to acquire a sleep mutex. The log message includes the file and line of both the waiter and the holder. Reviewed by: jhb, jake
* Disable optimization of spinlocks on UP kernels w/o debugging for nowjhb2002-07-271-2/+2
| | | | | | | | since it breaks mtx_owned() on spin mutexes when used outside of mtx_assert(). Unfortunately we currently use it in the i386 MD code and in the sio(4) driver. Reported by: bde
* Add mtx_ prefixes to the fields used for mutex profiling, and fix a bugdes2002-07-031-11/+12
| | | | | | | where the profiling code would report the release point instead of the acquisition point. Requested by: bde
* Part 1 of KSE-IIIjulian2002-06-291-15/+16
| | | | | | | | | | | | | 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..
* Replace thread_runnable() with thread_running() as the latter is morejhb2002-06-041-6/+5
| | | | | | accurate. Suggested by: julian
* Optimize the adaptive mutex spin a bit. Use a simple while loop withjhb2002-06-041-1/+4
| | | | | | | | | simple reads (and on IA32, a "pause" instruction for each interation of the loop) to spin until either the mutex owner field changes, or the lock owner stops executing. Suggested by: tanimura Tested on: i386
* Add a private thread_runnable() macro to make the code more readable andjhb2002-06-041-3/+5
| | | | make the KSE diff easier to maintain.
* Make the counters uintmax_ts, and use %ju rather than %llu.des2002-05-231-2/+3
|
* Rename pause() to ia32_pause() so it doesn't conflict with the pause()jhb2002-05-221-5/+5
| | | | | function defined in <unistd.h>. I didn't #ifdef _KERNEL it because the mutex implementation in libpthread will probably need this.
* Rename cpu_pause() to pause(). Originally I was going to make this anjhb2002-05-221-5/+5
| | | | | | | | | MI API with empty cpu_pause() functions on other arch's, but this functionality is definitely unique to IA-32, so I decided to leave it as i386-only and wrap it in #ifdef's. I should have dropped the cpu_ prefix when I made that decision. Requested by: bde
* Add appropriate IA32 "pause" instructions to improve performanec onjhb2002-05-211-1/+17
| | | | | | Pentium 4's and newer IA32 processors. The "pause" instruction has been verified by Intel to be a NOP on all currently existing IA32 processors prior to the Pentium 4.
* Fix an old cut 'n' paste bug inherited from BSD/OS: don't increment 'i'jhb2002-05-211-1/+1
| | | | twice once we are in the long wait stage of spinning on a spin mutex.
* Whitespace fixup, properly indent the body of an else clause.jhb2002-05-211-2/+2
|
* Add code to make default mutexes adaptive if the ADAPTIVE_MUTEXES kerneljhb2002-05-211-0/+26
| | | | | | | | | | | | | | | | | | | | | | option is used (not on by default). - In the case of trying to lock a mutex, if the MTX_CONTESTED flag is set, then we can safely read the thread pointer from the mtx_lock member while holding sched_lock. We then examine the thread to see if it is currently executing on another CPU. If it is, then we keep looping instead of blocking. - In the case of trying to unlock a mutex, it is now possible for a mutex to have MTX_CONTESTED set in mtx_lock but to not have any threads actually blocked on it, so we need to handle that case. In that case, we just release the lock as if MTX_CONTESTED was not set and return. - We do not adaptively spin on Giant as Giant is held for long times and it slows SMP systems down to a crawl (it was taking several minutes, like 5-10 or so for my test alpha and sparc64 SMP boxes to boot up when they adaptively spinned on Giant). - We only compile in the code to do this for SMP kernels, it doesn't make sense for UP kernels. Tested on: i386, alpha, sparc64
* Optimize spin mutexes for UP kernels without debugging to just enter andjhb2002-05-211-0/+8
| | | | | exit critical sections. We only contest on a spin mutex on an SMP kernel running on an SMP machine.
* Change mtx_init() to now take an extra argument. The third argument isjhb2002-04-041-8/+11
| | | | | | the generic lock type for use with witness. If this argument is NULL then the lock name is used as the lock type. Add a macro for a lock type name for network driver locks.
* Revert to open hashing. It makes the code simpler, and works farily welldes2002-04-021-16/+10
| | | | | | | even when the number of records approaches the size of the hash table. Besides, the previous implementation (using linear probing) was broken :) Also, use the newly introduced MTX_SYSINIT.
* - Move the MI mutexes sched_lock and Giant from being declared in thejhb2002-04-021-0/+27
| | | | | | | | | | various machdep.c's to being declared in kern_mutex.c. - Add a new function mutex_init() used to perform early initialization needed for mutexes such as setting up thread0's contested lock list and initializing MI mutexes. Change the various MD startup routines to call this function instead of duplicating all the code themselves. Tested on: alpha, i386
* Spelling police.jhb2002-04-021-1/+1
|
* - Add MTX_SYSINIT and SX_SYSINIT as macro glue for allowing sx and mtxarr2002-04-021-0/+11
| | | | | | | | | | locks to be able to setup a SYSINIT call. This helps in places where a lock is needed to protect some data, but the data is not truly associated with a subsystem that can properly initialize it's lock. The macros use the mtx_sysinit() and sx_sysinit() functions, respectively, as the handler argument to SYSINIT(). Reviewed by: alfred, jhb, smp@
* Instead of get_cyclecount(9), use nanotime(9) to record acquisition anddes2002-04-021-19/+28
| | | | | | | release times. Measurements are made and stored in nanoseconds but presented in microseconds, which should be sufficient for the locks for which we actually want this (those that are held long and / or often). Also, rename some variables and structure members to unit-agnostic names.
* Mutex profiling code, conditional on the MUTEX_PROFILING option. Adds thedes2002-04-021-2/+159
| | | | | | | | | | | | | | | | | | | | | | | following sysctl variables: debug.mutex.prof.enable enable / disable profiling debug.mutex.prof.acquisitions number of mutex acquisitions recorded debug.mutex.prof.records number of acquisition points recorded debug.mutex.prof.maxrecords max number of acquisition points debug.mutex.prof.rejected number of rejections (due to full table) debug.mutex.prof.hashsize hash size debug.mutex.prof.collisions number of hash collisions debug.mutex.prof.stats profiling statistics The code records four numbers for each acquisition point (identified by source file name and line number): longest time held, total time held, number of non-recursive acquisitions, average time held. The measurements are in clock cycles (as returned by get_cyclecount(9)); this may cause measurements on some SMP systems to be unreliable. This can probably be worked around by replacing get_cyclecount(9) by some incarnation of nanotime(9). This work was derived from initial patches by eivind.
* Add a new mtx_init option "MTX_DUPOK" which allows duplicate acquires of locksjeff2002-03-271-1/+3
| | | | | | | | | | | with this flag. Remove the dup_list and dup_ok code from subr_witness. Now we just check for the flag instead of doing string compares. Also, switch the process lock, process group lock, and uma per cpu locks over to this interface. The original mechanism did not work well for uma because per cpu lock names are unique to each zone. Approved by: jhb
* Remove __P.alfred2002-03-191-1/+1
|
* Tidy up some unused variablespeter2002-02-201-5/+0
|
* Add kern_giant_ucred to instrument Giant around ucred related operationsdillon2002-02-181-0/+2
| | | | such a getgid(), setgid(), etc...
* In a threaded world, differnt priorirites become properties ofjulian2002-02-111-15/+13
| | | | | | different entities. Make it so. Reviewed by: jhb@freebsd.org (john baldwin)
* Use the mtx_owner() macro in one spot in _mtx_lock_sleep() to make thejhb2002-02-091-1/+1
| | | | code easier to read.
* Bump the limits for determining if we've held a spinlock too long as theyjhb2002-01-151-2/+2
| | | | | | | seem to be too short for the 500 Mhz DS20 I'm testing on. The rather arbitrary numbers are rather bogus anyways. We should probably have variables for these limits that are calibrated in the MD startup code somehow.
* Change the preemption code for software interrupt thread schedules andjhb2002-01-051-11/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Modify the critical section API as follows:jhb2001-12-181-5/+3
| | | | | | | | | | | | | | | | | | | - The MD functions critical_enter/exit are renamed to start with a cpu_ prefix. - MI wrapper functions critical_enter/exit maintain a per-thread nesting count and a per-thread critical section saved state set when entering a critical section while at nesting level 0 and restored when exiting to nesting level 0. This moves the saved state out of spin mutexes so that interlocking spin mutexes works properly. - Most low-level MD code that used critical_enter/exit now use cpu_critical_enter/exit. MI code such as device drivers and spin mutexes use the MI wrappers. Note that since the MI wrappers store the state in the current thread, they do not have any return values or arguments. - mtx_intr_enable() is replaced with a constant CRITICAL_FORK which is assigned to curthread->td_savecrit during fork_exit(). Tested on: i386, alpha
* Remove definition of witness and comment stating that this file implementsjhb2001-11-151-22/+1
| | | | witness. Witness moved off to subr_witness.c a while ago.
* Add mtx_lock_giant() and mtx_unlock_giant() wrappers for sysctl managementdillon2001-10-261-0/+42
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | of Giant during the Giant unwinding phase, and start work on instrumenting Giant for the file and proc mutexes. These wrappers allow developers to turn on and off Giant around various subsystems. DEVELOPERS SHOULD NEVER TURN OFF GIANT AROUND A SUBSYSTEM JUST BECAUSE THE SYSCTL EXISTS! General developers should only considering turning on Giant for a subsystem whos default is off (to help track down bugs). Only developers working on particular subsystems who know what they are doing should consider turning off Giant. These wrappers will greatly improve our ability to unwind Giant and test the kernel on a (mostly) subsystem by subsystem basis. They allow Giant unwinding developers (GUDs) to emplace appropriate subsystem and structural mutexes in the main tree and then request that the larger community test the work by turning off Giant around the subsystem(s), without the larger community having to mess around with patches. These wrappers also allow GUDs to boot into a (more likely to be) working system in the midst of their unwinding work and to test that work under more controlled circumstances. There is a master sysctl, kern.giant.all, which defaults to 0 (off). If turned on it overrides *ALL* other kern.giant sysctls and forces Giant to be turned on for all wrapped subsystems. If turned off then Giant around individual subsystems are controlled by various other kern.giant.XXX sysctls. Code which overlaps multiple subsystems must have all related subsystem Giant sysctls turned off in order to run without Giant.
* The mtx_init() and sx_init() functions bzero'd locks before handing themjhb2001-10-201-1/+3
| | | | | | off to witness_init() making the check for double intializating a lock by testing the LO_INITIALIZED flag moot. Workaround this by checking the LO_INITIALIZED flag ourself before we bzero the lock structure.
* Remove superflous parens after de-macroizing.jhb2001-09-261-2/+2
|
* Since we no longer inline any debugging code in the mutex operations, movejhb2001-09-221-4/+24
| | | | | | | | all the debugging code into the function versions of the mutex operations in kern_mutex.c. This reduced the __mtx_* macros to simply wrappers of the _{get,rel}_lock_* macros, so the __mtx_* macros were also abolished in favor of just calling the _{get,rel}_lock_* macros. The tangled hairy mass of macros calling macros is at least a bit more sane now.
* Fix a bug in propagate priority: the kse group pointer wasn't beingjhb2001-09-191-0/+1
| | | | | updated in the loop so the new thread always seemd to have the same priority as the original thread and no actual priorities were changed.
* KSE Milestone 2julian2001-09-121-95/+103
| | | | | | | | | | | | | | Note ALL MODULES MUST BE RECOMPILED make the kernel aware that there are smaller units of scheduling than the process. (but only allow one thread per process at this time). This is functionally equivalent to teh previousl -current except that there is a thread associated with each process. Sorry john! (your next MFC will be a doosie!) Reviewed by: peter@freebsd.org, dillon@freebsd.org X-MFC after: ha ha ha ha
* Force a commit on kern_mutex.c to explain reason for last commit but whilebmilekic2001-08-241-0/+5
| | | | | | | | | | | | I'm at it also add a comment in mtx_validate() explaining the purpose of the last change. Basically, this fixes booting kernels compiled with MUTEX_DEBUG. What used to happen is before we setidt from init386() [still using BTX idt], we called mtx_init() on several mutex locks, notably Giant and some others. This is a problem for MUTEX_DEBUG because it enables mtx_validate() which calls kernacc(), some of which in turn requires Giant. Fix by calling kernacc() from mtx_validate() only if (!cold).
OpenPOWER on IntegriCloud