summaryrefslogtreecommitdiffstats
path: root/sys/kern/kern_event.c
Commit message (Collapse)AuthorAgeFilesLines
* Defer freeing a kevent list until after dropping kqueue locks.jhb2010-03-301-4/+6
| | | | | | LOR: 185 Submitted by: Matthew Fleming @ Isilon MFC after: 1 week
* Do not leak process lock when current thread is not allowed to see target.kib2010-02-141-1/+3
| | | | | Bumped into by: ed MFC after: 3 days
* If a filter has already been added, actually return EEXIST when tryingbrooks2009-12-311-1/+2
| | | | | | at add it again. MFC after: 1 week
* The devices that supported EVFILT_NETDEV kqueue filters were removed inbrooks2009-12-311-1/+1
| | | | | | | | | | | | r195175. Remove all definitions, documentation, and usage. fifo_misc.c: Remove all kqueue tests as fifo_io.c performs all those that would have remained. Reviewed by: rwatson MFC after: 3 weeks X-MFC note: don't change vlan_link_state() function signature
* Postpone dropping fp till both kq_global and kqueue mutexes arekib2009-10-101-3/+3
| | | | | | | | | | unlocked. fdrop() closes file descriptor when reference count goes to zero. Close method for vnodes locks the vnode, resulting in "sleepable after non-sleepable". For pipes, pipe mutex is before kqueue lock, causing LOR. Reported and tested by: pho MFC after: 2 weeks
* Use correct sizeof() object for klist 'list'. Currently, struct klistdelphij2009-09-281-4/+4
| | | | | | | | | contained only SLIST_HEAD as its member, thus sizeof(struct klist) would equal to sizeof(struct klist *), so this change makes the code more correct in terms of semantics, but should be a no-op to compiler at this time. Reported by: MQ <antinvidia at gmail com>
* Change unsigned foo to u_foo as required by style(9).rdivacky2009-09-221-3/+3
| | | | | Requested by: bde Approved by: ed (mentor)
* Fix the style of the previous commit.rdivacky2009-09-171-1/+2
| | | | Approved by: ed (mentor, implicit)
* Make these argument/variable unsigned as the defines for them don't fitrdivacky2009-09-171-3/+3
| | | | | | | into signed 32bit integer. Approved by: ed (mentor, implicit) Approved by: sson
* Add EV_RECEIPT to kevents.sson2009-09-161-1/+1
| | | | | | | | EV_RECEIPT is useful to disambiguating error conditions when multiple events structures are passed to kevent(2). The error code is returned in the data field and EV_ERROR is set. Approved by: rwatson (co-mentor)
* Add the EV_DISPATCH flag to kevents.sson2009-09-161-2/+4
| | | | | | | | When the EV_DISPATCH flag is used the event source will be disabled immediately after the delivery of an event. This is similar to the EV_ONESHOT flag but it doesn't delete the event. Approved by: rwatson (co-mentor)
* Add EVFILT_USER to kevents.sson2009-09-161-0/+99
| | | | | | | | | Add user events support to kernel events which are not associated with any kernel mechanism but are triggered by user level code. This is useful for adding user level events to an event handler that may also be monitoring kernel events. Approved by: rwatson (co-mentor)
* Add optional touch event filter hooks to kevents.sson2009-09-161-37/+56
| | | | | | | | The touch event filter is called when a kernel event data is possibly updated. There are two hook points. First, during a kevent() system call. Second, when an event has been triggered. Approved by: rwatson (co-mentor)
* Use C99 initialization for struct filterops.rwatson2009-09-121-10/+25
| | | | | | Obtained from: Mac OS X Sponsored by: Apple Inc. MFC after: 3 weeks
* - Turn the third (islocked) argument of the knote call into flags parameter.stas2009-06-281-6/+18
| | | | | | | | | | | Introduce the new flag KNF_NOKQLOCK to allow event callers to be called without KQ_LOCK mtx held. - Modify VFS knote calls to always use KNF_NOKQLOCK flag. This is required for ZFS as its getattr implementation may sleep. Approved by: re (rwatson) Reviewed by: kib MFC after: 2 weeks
* Adapt vfs kqfilter to the shared vnode lock used by zfs write vop. Usekib2009-06-101-14/+29
| | | | | | | | | | | | | | | | | | | | | | | | | vnode interlock to protect the knote fields [1]. The locking assumes that shared vnode lock is held, thus we get exclusive access to knote either by exclusive vnode lock protection, or by shared vnode lock + vnode interlock. Do not use kl_locked() method to assert either lock ownership or the fact that curthread does not own the lock. For shared locks, ownership is not recorded, e.g. VOP_ISLOCKED can return LK_SHARED for the shared lock not owned by curthread, causing false positives in kqueue subsystem assertions about knlist lock. Remove kl_locked method from knlist lock vector, and add two separate assertion methods kl_assert_locked and kl_assert_unlocked, that are supposed to use proper asserts. Change knlist_init accordingly. Add convenience function knlist_init_mtx to reduce number of arguments for typical knlist initialization. Submitted by: jhb [1] Noted by: jhb [2] Reviewed by: jhb Tested by: rnoland
* Fix a number of style issues in the MALLOC / FREE commit. I've tried todes2008-10-231-3/+2
| | | | | be careful not to fix anything that was already broken; the NFSv4 code is particularly bad in this respect.
* Retire the MALLOC and FREE macros. They are an abomination unto style(9).des2008-10-231-6/+5
| | | | MFC after: 3 months
* The kqueue_register() function assumes that it is called from the top ofkib2008-07-071-15/+67
| | | | | | | | | | | | | | | | | | | | | | | | | | | the syscall code and acquires various event subsystem locks as needed. The handling of the NOTE_TRACK for EVFILT_PROC is currently done by calling the kqueue_register() from filt_proc() filter, causing recursive entrance of the kqueue code. This results in the LORs and recursive acquisition of the locks. Implement the variant of the knote() function designed to only handle the fork() event. It mostly copies the knote() body, but also handles the NOTE_TRACK, removing the handling from the filt_proc(), where it causes problems described above. The function is called from the fork1() instead of knote(). When encountering NOTE_TRACK knote, it marks the knote as influx and drops the knlist and kqueue lock. In this context call to kqueue_register is safe from the problems. An error from the kqueue_register() is reported to the observer as NOTE_TRACKERR fflag. PR: 108201 Reviewed by: jhb, Pramod Srinivasan <pramod juniper net> (previous version) Discussed with: jmg Tested by: pho MFC after: 2 weeks
* The r178914 I erronously put the setting of the KQ_FLUXWAIT flag beforekib2008-07-071-2/+1
| | | | | | | | | | KQ_FLUX_WAKEUP(). Since the later macro clears the KQ_FLUXWAIT, the kqueue_scan() thread may be not woken up. Move the setting of KQ_FLUXWAIT after wakeup to correct the issue. Reported and tested by: pho MFC after: 3 days
* Kqueue_scan() may sleep when encountered the influx knotes. On the otherkib2008-05-101-1/+10
| | | | | | | | | | | | hand, it may cause other threads to sleep since kqueue_scan() may mark some knotes as infux. This could lead to the deadlock. Before kqueue_scan() sleeps, wakeup the threads that are waiting for the influx knotes produced by this thread. Tested by: pho (previous version) Reviewed by: jmg MFC after: 2 weeks
* The kqueue_close() encountering the KN_INFLUX knotes on the kq beingkib2008-05-101-4/+11
| | | | | | | | | | closed is the legitimate situation. For instance, filedescriptor with registered events may be closed in parallel with closing the kqueue. Properly handle the case instead of asserting that this cannot happen. Reported and tested by: pho Reviewed by: jmg MFC after: 2 weeks
* - Convert two timeout users to the new callout_reset_curcpu() api.jeff2008-04-021-3/+3
| | | | Sponsored by: Nokia
* In keeping with style(9)'s recommendations on macros, use a ';'rwatson2008-03-161-1/+1
| | | | | | | | | after each SYSINIT() macro invocation. This makes a number of lightweight C parsers much happier with the FreeBSD kernel source, including cflow's prcc and lxr. MFC after: 1 month Discussed with: imp, rink
* Make ftruncate a 'struct file' operation rather than a vnode operation.jhb2008-01-071-0/+11
| | | | | | | | | | | | | | This makes it possible to support ftruncate() on non-vnode file types in the future. - 'struct fileops' grows a 'fo_truncate' method to handle an ftruncate() on a given file descriptor. - ftruncate() moves to kern/sys_generic.c and now just fetches a file object and invokes fo_truncate(). - The vnode-specific portions of ftruncate() move to vn_truncate() in vfs_vnops.c which implements fo_truncate() for vnode file types. - Non-vnode file types return EINVAL in their fo_truncate() method. Submitted by: rwatson
* Remove explicit locking of struct file.jeff2007-12-301-23/+11
| | | | | | | | | | | | | - Introduce a finit() which is used to initailize the fields of struct file in such a way that the ops vector is only valid after the data, type, and flags are valid. - Protect f_flag and f_count with atomic operations. - Remove the global list of all files and associated accounting. - Rewrite the unp garbage collection such that it no longer requires the global list of all files and instead uses a list of all unp sockets. - Mark sockets in the accept queue so we don't incorrectly gc them. Tested by: kris, pho
* Refactor select to reduce contention and hide internal implementationjeff2007-12-161-3/+6
| | | | | | | | | | | | | | | | | | | | | details from consumers. - Track individual selecters on a per-descriptor basis such that there are no longer collisions and after sleeping for events only those descriptors which triggered events must be rescaned. - Protect the selinfo (per descriptor) structure with a mtx pool mutex. mtx pool mutexes were chosen to preserve api compatibility with existing code which does nothing but bzero() to setup selinfo structures. - Use a per-thread wait channel rather than a global wait channel. - Hide select implementation details in a seltd structure which is opaque to the rest of the kernel. - Provide a 'selsocket' interface for those kernel consumers who wish to select on a socket when they have no fd so they no longer have to be aware of select implementation details. Tested by: kris Reviewed on: arch
* Revert previous commits which I committed by mistake.rodrigc2007-07-141-9/+0
| | | | | Approved by: re (implicit) Pointy hat to: me
* The last entry in the ext2_opts array must be NULL,rodrigc2007-07-141-0/+9
| | | | | | | otherwise the kernel with crash in vfs_filteropt() if an invalid mount option is passed to ext2fs. Approved by: re (kensmith)
* In kern_kevent(), unconditionally fdrop() fp once fget() has succeeded,rwatson2007-05-281-2/+1
| | | | | | | as we never have an opportunity to set it to NULL. Found with: Coverity Prevent(tm) CID: 2161
* Select a more appealing spelling for the word acquire.rwatson2007-05-271-10/+10
|
* Replace custom file descriptor array sleep lock constructed using a mutexrwatson2007-04-041-9/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | and flags with an sxlock. This leads to a significant and measurable performance improvement as a result of access to shared locking for frequent lookup operations, reduced general overhead, and reduced overhead in the event of contention. All of these are imported for threaded applications where simultaneous access to a shared file descriptor array occurs frequently. Kris has reported 2x-4x transaction rate improvements on 8-core MySQL benchmarks; smaller improvements can be expected for many workloads as a result of reduced overhead. - Generally eliminate the distinction between "fast" and regular acquisisition of the filedesc lock; the plan is that they will now all be fast. Change all locking instances to either shared or exclusive locks. - Correct a bug (pointed out by kib) in fdfree() where previously msleep() was called without the mutex held; sx_sleep() is now always called with the sxlock held exclusively. - Universally hold the struct file lock over changes to struct file, rather than the filedesc lock or no lock. Always update the f_ops field last. A further memory barrier is required here in the future (discussed with jhb). - Improve locking and reference management in linux_at(), which fails to properly acquire vnode references before using vnode pointers. Annotate improper use of vn_fullpath(), which will be replaced at a future date. In fcntl(), we conservatively acquire an exclusive lock, even though in some cases a shared lock may be sufficient, which should be revisited. The dropping of the filedesc lock in fdgrowtable() is no longer required as the sxlock can be held over the sleep operation; we should consider removing that (pointed out by attilio). Tested by: kris Discussed with: jhb, kris, attilio, jeff
* Remove 'MPSAFE' annotations from the comments above most system calls: allrwatson2007-03-041-6/+0
| | | | | | | | system calls now enter without Giant held, and then in some cases, acquire Giant explicitly. Remove a number of other MPSAFE annotations in the credential code and tweak one or two other adjacent comments.
* Save exit status of an exiting process in kn_data in the knote.jhb2006-11-201-0/+1
| | | | | Submitted by: Jared Yanovich ^phirerunner at comcast.net^ MFC after: 2 weeks
* remove unnecessary NULL check...jmg2006-09-251-2/+1
| | | | Coverity ID: 1545
* hide kqueue_register from public view, and replace it w/ kqfd_register...jmg2006-09-241-2/+30
| | | | this eliminates a possible race in aio registering a kevent..
* add KTRACE hooks into kevent... This will help people debug their kqueuejmg2006-09-241-2/+38
| | | | | | | | | | programs to find out exactly which events were registered and which were returned... This should be lower in kern_kevent, but that would require special munging due to locks and the functions used to copyin/copyout kevents... If someone wants to teach ktrace how to output pretty kevents, I have a kevent prety printer that can be used...
* Use fget() in kqueue_register() instead of doing all the work by hand.jhb2006-06-121-17/+3
|
* Don't forget to unlock kq lock in low memory situations.pjd2006-06-021-0/+1
| | | | OK'ed by: jmg
* Remove confusing done_noglobal label. The KQ_GLOBAL_UNLOCK() macro knowpjd2006-06-021-2/+1
| | | | | | how to handle both situations - when kq_global lock is and is not held. OK'ed by: jmg
* Use SLIST_FOREACH_SAFE() macro, because knote_drop() can free an elementpjd2006-06-021-2/+2
| | | | | | which can be then used to find next element in the list. OK'ed by: jmg
* Drop the kqueue global mutex as soon as we are finished with it ratherjhb2006-04-141-4/+2
| | | | | | | | | | | | | | | than keeping it locked until we exit the function to optimize the case where the lock would be dropped and later reacquired. The optimization was broken when kevent's were moved from UFS to VFS and the knote list lock for a vnode kevent became the lockmgr vnode lock. If one tried to use a kqueue that contained events for a kqueue fd followed by a vnode, then the kq global lock would end up being held when the vnode lock was acquired which could result in sleeping with a mutex held (and subsequent panics) if the vnode lock was contested. Reviewed by: jmg Tested by: ps (on 6.x) MFC after: 3 days
* spell unlock correctly, this is relatively minor as it's rare someone wouldjmg2006-04-071-1/+1
| | | | | | | | provide a lock method, and want the default unlock, but it is a bug... PR: 95356 Submitted by: Stephen Corteselli MFC after: 3 days
* mask out any action when copying the flags from the event to the knote..jmg2006-04-011-0/+2
| | | | | | Pointed out by: Václav Haisman Submitted by: Dan Nelson (slightly modifed patch) MFC after: 3 days
* hold the list lock over the f_event and KNOTE_ACTIVATE calls... This closesjmg2006-03-291-1/+1
| | | | | | | | | | a race where data could come in before we clear the INFLUX flag, and get skipped over by knote (and hence never be activated, though it should of been)... Found by: glebius & co. Reviewed by: glebius MFC after: 3 days
* Add in kqueue support to LIO event notification and fix how it handledambrisko2005-10-121-2/+6
| | | | | | | | | | | | | | | | | | notifications when LIO operations completed. These were the problems with LIO event complete notification: - Move all LIO/AIO event notification into one general function so we don't have bugs in different data paths. This unification got rid of several notification bugs one of which if kqueue was used a SIGILL could get sent to the process. - Change the LIO event accounting to count all AIO request that could have been split across the fast path and daemon mode. The prior accounting only kept track of AIO op's in that mode and not the entire list of operations. This could cause a bogus LIO event complete notification to occur when all of the fast path AIO op's completed and not the AIO op's that ended up queued for the daemon. Suggestions from: alc
* Fix race condition that caused activation of an event toups2005-09-151-2/+4
| | | | | | | be ignored immediately after it was deactivated. Found by: Yahoo! MFC after: 3 days
* Fix the recent panics/LORs/hangs created by my kqueue commit by:ssouhlal2005-07-011-28/+83
| | | | | | | | | | | | | | | | | - Introducing the possibility of using locks different than mutexes for the knlist locking. In order to do this, we add three arguments to knlist_init() to specify the functions to use to lock, unlock and check if the lock is owned. If these arguments are NULL, we assume mtx_lock, mtx_unlock and mtx_owned, respectively. - Using the vnode lock for the knlist locking, when doing kqueue operations on a vnode. This way, we don't have to lock the vnode while holding a mutex, in filt_vfsread. Reviewed by: jmg Approved by: re (scottl), scottl (mentor override) Pointyhat to: ssouhlal Will be happy: everyone
* Wrap copyin/copyout for kevent so the 32bit wrapper does not haveps2005-06-031-44/+51
| | | | | | | | | to malloc nchanges * sizeof(struct kevent) AND/OR nevents * sizeof(struct kevent) on every syscall. Glanced at by: peter, jmg Obtained from: Yahoo! MFC after: 2 weeks
* make stat return an zero'd struct, and be a FIFO again... This is onlyjmg2005-05-241-1/+10
| | | | | | | | | to fix libc_r since it requires stat to close fd's, and so commented in the code... PR: threads/75795 Reviewed by: ps MFC after: 1 week
OpenPOWER on IntegriCloud