summaryrefslogtreecommitdiff
path: root/sys/kern/subr_eventhandler.c
Commit message (Collapse)AuthorAgeFilesLines
* Use __FBSDID().David E. O'Brien2003-06-111-2/+3
| | | | Notes: svn path=/head/; revision=116182
* Rework the eventhandler locking for hopefully the last time. The schemeJohn Baldwin2003-03-111-41/+108
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | used popped into my head during my morning commute a few weeks ago, but it is also very similar (though a bit simpler) to a patch that mini@ developed a while ago. Basically, each eventhandler list has a mutex and a run count. During an eventhandler invocation, the mutex is held while we traverse the list but is dropped while we execute actual handlers. Also, a runcount counter is incremented at the start of an invocation and decremented at the end of an invocation. Adding to the list is not a big deal since the reference of a thread currently executing the handlers remains valid across an add operation. Whether or not new handlers are executed by threads currently executing the handlers for a given list is indeterminate however. The harder case is when a handler is removed from the list. If the runcount is zero, the handler is simply removed from the list directly. If the runcount is not zero, then another thread is currently executing the handlers of this list, so the priority of this handler is set to a magic value (currently -1) to mark it as dead. Dead handlers are not executed during an invocation. If the runcount is zero after it is decremented at the end of an invocation, then a new eventhandler_prune_list() function is called to remove dead handlers from the list. Additional minor notes: - All the common parts of EVENTHANDLER_INVOKE() and EVENTHANDLER_FAST_INVOKE() have been merged into a common _EVENTHANDLER_INVOKE() macro to reduce duplication and ease maintenance. - KTR logging for eventhandlers is now available via the KTR_EVH mask. - The global eventhander_mutex is no longer recursive. Tested by: scottl (SMP i386) Notes: svn path=/head/; revision=112111
* Wrap a line longer than 80 characters.Maxime Henrion2002-07-191-2/+2
| | | | Notes: svn path=/head/; revision=100370
* Change callers of mtx_init() to pass in an appropriate lock type name. InJohn Baldwin2002-04-041-1/+1
| | | | | | | | | | most cases NULL is passed, but in some cases such as network driver locks (which use the MTX_NETWORK_LOCK macro) and UMA zone locks, a name is used. Tested on: i386, alpha, sparc64 Notes: svn path=/head/; revision=93818
* Avoid a lock order reversal by dropping the eventhandler_mutex earlier.Alfred Perlstein2002-04-041-2/+1
| | | | | | | | | | | We get enough protection from the lock on the individual lists that we aquire later. Noticed/Tested by: Steven G. Kargl <kargl@troutmask.apl.washington.edu> Submitted by: Jonathan Mini <mini@haikugeek.com> Notes: svn path=/head/; revision=93743
* Use sx locks rather than lockmgr locks for eventhandlers.Alfred Perlstein2002-04-021-5/+6
| | | | | | | Submitted by: Jonathan Mini <mini@haikugeek.com> Notes: svn path=/head/; revision=93615
* KSE Milestone 2Julian Elischer2001-09-121-4/+4
| | | | | | | | | | | | | | | | | 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 Notes: svn path=/head/; revision=83366
* Don't try to find an eventhandler list if the list of lists hasn'tJake Burkholder2001-07-311-0/+3
| | | | | | | been initialized yet. Notes: svn path=/head/; revision=80703
* Undo part of the tangle of having sys/lock.h and sys/mutex.h included inMark Murray2001-05-011-0/+1
| | | | | | | | | | | | | | other "system" header files. Also help the deprecation of lockmgr.h by making it a sub-include of sys/lock.h and removing sys/lockmgr.h form kernel .c files. Sort sys/*.h includes where possible in affected files. OK'ed by: bde (with reservations) Notes: svn path=/head/; revision=76166
* Catch up to header include changes:John Baldwin2001-03-281-0/+1
| | | | | | | | - <sys/mutex.h> now requires <sys/systm.h> - <sys/mutex.h> and <sys/sx.h> now require <sys/lock.h> Notes: svn path=/head/; revision=74914
* Change and clean the mutex lock interface.Bosko Milekic2001-02-091-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Implement MTX_RECURSE flag for mtx_init().Bosko Milekic2001-01-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | All calls to mtx_init() for mutexes that recurse must now include the MTX_RECURSE bit in the flag argument variable. This change is in preparation for an upcoming (further) mutex API cleanup. The witness code will call panic() if a lock is found to recurse but the MTX_RECURSE bit was not set during the lock's initialization. The old MTX_RECURSE "state" bit (in mtx_lock) has been renamed to MTX_RECURSED, which is more appropriate given its meaning. The following locks have been made "recursive," thus far: eventhandler, Giant, callout, sched_lock, possibly some others declared in the architecture-specific code, all of the network card driver locks in pci/, as well as some other locks in dev/ stuff that I've found to be recursive. Reviewed by: jhb Notes: svn path=/head/; revision=71228
* - Convert the per-eventhandler list mutex to a lockmgr lock so that it canJohn Baldwin2000-12-121-11/+20
| | | | | | | | | | | | | | | be safely held across an eventhandler function call. - Fix an instance of the head of an eventhandler list being read without the lock being held. - Break down and use a SYSINIT at the new SI_SUB_EVENTHANDLER to initialize the eventhandler global mutex and the eventhandler list of lists rather than using a non-MP safe initialization during the first call to eventhandler_register(). - Add in a KASSERT() to eventhandler_register() to ensure that we don't try to register an eventhandler before things have been initialized. Notes: svn path=/head/; revision=69893
* Staticize some malloc M_ instances.Poul-Henning Kamp2000-12-081-1/+1
| | | | Notes: svn path=/head/; revision=69774
* - Make the eventhandler_mutex mutex a private variable inJohn Baldwin2000-10-251-0/+1
| | | | | | | | | subr_eventhandler.c - Move the extra #include's in sys/eventhandler.h to be protected by the #ifndef SYS_EVENTHANDLER/#endif Notes: svn path=/head/; revision=67535
* Make the EVENTHANDLER mechanism MP-safe. Events can now be invokedMike Smith2000-09-221-3/+21
| | | | | | | without holding the Giant lock. Notes: svn path=/head/; revision=66205
* 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
* Commit the remaining part of PR14914:Poul-Henning Kamp1999-11-161-1/+1
| | | | | | | | | | | | | | Alot of the code in sys/kern directly accesses the *Q_HEAD and *Q_ENTRY structures for list operations. This patch makes all list operations in sys/kern use the queue(3) macros, rather than directly accessing the *Q_{HEAD,ENTRY} structures. Reviewed by: phk Submitted by: Jake Burkholder <jake@checker.org> PR: 14914 Notes: svn path=/head/; revision=53225
* $Id$ -> $FreeBSD$Peter Wemm1999-08-281-1/+1
| | | | Notes: svn path=/head/; revision=50477
* Implement a new generic mechanism for attaching handler functions toMike Smith1999-08-211-0/+140
events, in order to pave the way for removing a number of the ad-hoc implementations currently in use. Retire the at_shutdown family of functions and replace them with new event handler lists. Rework kern_shutdown.c to take greater advantage of the use of event handlers. Reviewed by: green Notes: svn path=/head/; revision=50107