summaryrefslogtreecommitdiffstats
path: root/sys/sys/event.h (follow)
Commit message (Collapse)AuthorAgeFilesLines
* kqueue: Revise filterops interfacevisa2021-02-241-11/+69
| | | | | | | | | | | | | | | | | Extend kqueue's filterops interface with new callbacks so that it becomes easier to use with fine-grained locking. The new interface delegates the serialization of kn_event access to event sources. Now kqueue uses filterops callbacks to read or write kn_event. This hides event sources' locking patterns from kqueue, and allows clean implementation of atomic read-and-clear for EV_CLEAR, for instance. There are so many existing filterops instances that converting all of them in one go is tricky. This patch adds a wrapper mechanism that kqueue uses when the new callbacks are missing. The new filterops interface has been influenced by XNU's kqueue. OK mpi@ semarie@
* kqueue: Revise fd close notificationvisa2021-01-171-1/+3
| | | | | | | | | | | | | | | | | | Deliver file descriptor close notification for __EV_POLL knotes through struct kevent that kqueue_scan() returns. This replaces the previous way of returning EBADF from kqueue_scan(), making it easier to determine what exactly has changed. When a file descriptor is closed, its __EV_POLL knotes are turned into one-shot events and queued for delivery. These knotes are "unregistered" as they are reachable only through the queue of active events. This reduces interference with the normal workings of kqueue. However, more care is needed to avoid leaking knotes. In addition, the unregistering removes a limit on the number of issued knotes. To prevent accumulation of pending fd close notifications, kqpoll_init() flushes the active queue at the start of a kqpoll scan. OK mpi@
* Refactor klist insertion and removalvisa2020-12-251-1/+3
| | | | | | | | | | | | Rename klist_{insert,remove}() to klist_{insert,remove}_locked(). These functions assume that the caller has locked the klist. The current state of locking remains intact because the kernel lock is still used with all klists. Add new functions klist_insert() and klist_remove() that lock the klist internally. This allows some code simplification. OK mpi@
* Introduce klistopsvisa2020-12-201-1/+17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch extends struct klist with a callback descriptor and an argument. The main purpose of this is to let the kqueue subsystem assert when a klist should be locked, and operate the klist lock in klist_invalidate(). Access to a knote list of a kqueue-monitored object has to be serialized somehow. Because the object often has a lock for protecting its state, and because the object often acquires this lock at the latest in its f_event callback function, it makes sense to use this lock also for the knote lists. The existing uses of NOTE_SUBMIT already show a pattern that is likely to become more prevalent. There could be an embedded lock in klist. However, such a lock would be redundant in many cases. The code cannot rely on a single lock type (mutex, rwlock, something else) because the needs of monitored objects vary. In addition, an embedded lock would introduce new lock order constraints. Note that the patch does not rule out use of dedicated klist locks. The patch introduces a way to associate lock operations with a klist. The caller can provide a custom implementation, or use a ready-made interface with a mutex or rwlock. For compatibility with old code, the new code falls back to using the kernel lock if no specific klist initialization has been done. The existing code already relies on implicit initialization of klist. Sadly, this change increases the size of struct klist. dlg@ thinks this is not fatal, though. OK mpi@
* Make knote_{activate,remove}() internal to kern_event.c.visa2020-12-181-3/+1
| | | | OK mpi@
* Add kernel-only per-thread kqueue & helpers to initialize and free it.mpi2020-12-091-1/+4
| | | | | | This will soon be used by select(2) and poll(2). ok anton@, visa@
* Refactor kqueue_scan() so it can be used by other syscalls.mpi2020-12-071-2/+2
| | | | | | | Stop iterating in the function and instead copy the returned events to userland after every call. ok visa@
* Change kqueue_scan() to keep track of collected events in the given context.mpi2020-11-251-1/+4
| | | | | | | | | | | | | | It is now possible to call the function multiple times to collect events. For that, the end marker has to be preserved between calls because otherwise the scan might collect an event more than once. If a collected event gets reactivated during scanning, it will be added at the tail of the queue, out of reach because of the end marker. This is required to implement select(2) and poll(2) on top of kqueue_scan(). Done & originally committed by visa@ in r1.143, in snap for more than 2 weeks. ok visa@, anton@
* Refactor kqueue_scan() to use a context: a "kqueue_scan_state struct".mpi2020-10-111-1/+12
| | | | | | | | | | The struct keeps track of the end point of an event queue scan by persisting the end marker. This will be needed when kqueue_scan() is called repeatedly to complete a scan in a piecewise fashion. Extracted from a previous diff from visa@. ok visa@, anton@
* Allow userland to use EVFILT_EXCEPT.mpi2020-08-231-2/+2
| | | | ok mvs@, visa@
* Extend kqueue interface with EVFILT_EXCEPT filter.mpi2020-06-221-1/+8
| | | | | | | | | | This filter, already implemented in macOS and Dragonfly BSD, returns exceptional conditions like the reception of out-of-band data. The functionnality is similar to poll(2)'s POLLPRI & POLLRDBAND and it can be used by the kqfilter-based poll & select implementation. ok millert@ on a previous version, ok visa@
* Implement a simple kqfilter for deadfs matching its poll handler.mpi2020-06-151-1/+2
| | | | ok visa@, millert@
* Set __EV_HUP when the conditions matching poll(2)'s POLLUP are found.mpi2020-06-151-2/+5
| | | | | | This is only done in poll-compatibility mode, when __EV_POLL is set. ok visa@, millert@
* Revert addition of double underbars for filter-specific flag.mpi2020-06-121-2/+2
| | | | Port breakages reported by naddy@
* Rename poll-compatibility flag to better reflect what it is.mpi2020-06-111-3/+3
| | | | | | While here prefix kernel-only EV flags with two underbars. Suggested by kettenis@, ok visa@
* Use a new EV_OLDAPI flag to match the behavior of poll(2) and select(2).mpi2020-06-081-1/+2
| | | | | | | | | Adapt FS kqfilters to always return true when the flag is set and bypass the polling mechanism of the NFS thread. While here implement a write filter for NFS. ok visa@
* Revert "Add kqueue_scan_state struct"visa2020-05-251-12/+1
| | | | sthen@ has reported that the patch might be causing hangs with X.
* Add kqueue_scan_state structvisa2020-05-171-1/+12
| | | | | | | | | | | | The struct keeps track of the end point of an event queue scan by persisting the end marker. This will be needed when kqueue_scan() is called repeatedly to complete a scan in a piecewise fashion. The end marker has to be preserved between calls because otherwise the scan might collect an event more than once. If a collected event gets reactivated during scanning, it will be added at the tail of the queue, out of reach because of the end marker. OK mpi@
* Use a double-underscore prefix for local variables declared in macrosguenther2020-05-101-5/+5
| | | | | | | that have arguments. Document this requirement/recommendation in style(9) prompted by mpi@ ok deraadt@
* Abstract the head of knote lists. This allows extending the lists,visa2020-04-071-3/+10
| | | | | | for example, with locking assertions. OK mpi@, anton@
* Prevent shadowing of local variable by the EV_SET() macro.mpi2020-04-041-9/+9
| | | | | | | | Use two underbars to start the locally defined variable, as suggested by guenther@. The other option to avoid namespace conflict would be to start the identifier with an underbar and a capital. ok beck@, guenther@
* Replace field f_isfd with field f_flags in struct filterops to allowvisa2020-02-201-2/+4
| | | | | | adding more filter properties without cluttering the struct. OK mpi@, anton@
* Use C99 designated initializers with struct filterops. In addition,visa2019-12-311-1/+3
| | | | | | make the structs const so that the data are put in .rodata. OK mpi@, deraadt@, anton@, bluhm@
* Allow sleeping inside kqueue event filters.visa2019-12-121-1/+5
| | | | | | | | | | | | | | | | | | | | In kqueue_scan(), threads have to get an exclusive access to a knote before processing by calling knote_acquire(). This prevents the knote from being destroyed while it is still in use. knote_acquire() also blocks other threads from processing the knote. Once knote processing has finished, the thread has to call knote_release(). The kqueue subsystem is still serialized by the kernel lock. If an event filter sleeps, the kernel lock is released and another thread might enter kqueue_scan(). kqueue_scan() uses start and end markers to keep track of the scan's progress and it has to be aware of other threads' markers. This patch is a revised version of mpi@'s work derived from DragonFly BSD. kqueue_check() has been adapted from NetBSD. Tested by anton@, sashan@ OK mpi@, anton@, sashan@
* introduce a filter called EVFILT_DEVICE that can be used to notifyrobert2018-01-131-2/+6
| | | | | | | listeners of device state changes. currently only supports NOTE_CHANGE that will be used by drm(4) ok kettenis@
* Expand u_short and u_int to unsigned short and unsigned intmillert2017-12-211-4/+4
| | | | | | respectively to avoid compilation errors when one of the POSIX or X/OPEN version macros is defined. Also sync the field descriptions with kqueue.2. OK deraadt@
* Revert support for multiple threads to enter kqueue_scan() in parallel.mpi2017-12-181-5/+1
| | | | | | It is not clear if this change is responsible for the lockups experienced by dhill@ and jcs@ but since we're no longer grabbing the socket lock in kqueue(2) filters there's no need for this change.
* Make it possible for multiple threads to enter kqueue_scan() in parallel.mpi2017-11-041-12/+14
| | | | | | | | | | | | | | | | | This is a requirement to use a sleeping lock inside kqueue filters. It is now possible, but not recommended, to sleep inside ``f_event''. Threads iterating over the list of pending events are now recognizing and skipping other threads' markers. knote_acquire() and knote_release() must be used to "own" a knote to make sure no other thread is sleeping with a reference on it. Acquire and marker logic taken from DragonFly but the KERNEL_LOCK() is still serializing the execution of the kqueue code. This also enable the NET_LOCK() in socket filters. Tested by abieber@ & juanfra@, run by naddy@ in a bulk, ok visa@, bluhm@
* Assert that the corresponding socket is locked when manipulating socketmpi2017-06-261-1/+8
| | | | | | | | | | | | | | | | buffers. This is one step towards unlocking TCP input path. Note that all the functions asserting for the socket lock are not necessarilly MP-safe. All the fields of 'struct socket' aren't protected. Introduce a new kernel-only kqueue hint, NOTE_SUBMIT, to be able to tell when a filter needs to lock the underlying data structures. Logic and name taken from NetBSD. Tested by Hrvoje Popovski. ok claudio@, bluhm@, mikeb@
* Add support for EV_RECEIPT and EV_DISPATCH flagsmikeb2017-05-311-1/+3
| | | | | From FreeBSD via Jan Schreiber <jes at posteo ! de>, thanks! OK tedu, bluhm
* make a copy of the first EV_SET argument to prevent multiple evaluation.tedu2017-05-311-3/+5
| | | | | matches freebsd, fixes lldb. from Kamil Rytarowski at NetBSD. while here, make the same change to KNOTE. ok deraadt
* move knhash size to event.h, use it for hashfree. from Mathieu -tedu2016-09-241-1/+3
| | | | ok guenther
* modern interfaces should use modern speelings, so spell quad_t as int64_t.tedu2016-08-131-3/+3
|
* struct knote's kn_sdata needs to be the same type as struct kevent's dataguenther2015-10-061-2/+2
| | | | ok deraadt@
* knote_processexit() needs the thread to pass down to FRELE(), so pass itguenther2014-05-151-2/+2
| | | | | | | the exiting thread instead of assuming that that's ps_mainproc. Also, panic no matter which thread of init takes it down. ok tedu@
* Switch time_t, ino_t, clock_t, and struct kevent's ident and dataguenther2013-08-131-3/+3
| | | | | | | | | | | | | | | | | | | | members to 64bit types. Assign new syscall numbers for (almost all) the syscalls that involve the affected types, including anything with time_t, timeval, itimerval, timespec, rusage, dirent, stat, or kevent arguments. Add a d_off member to struct dirent and replace getdirentries() with getdents(), thus immensely simplifying and accelerating telldir/seekdir. Build perl with -DBIG_TIME. Bump the major on every single base library: the compat bits included here are only good enough to make the transition; the T32 compat option will be burned as soon as we've reached the new world are are happy with the snapshots for all architectures. DANGER: ABI incompatibility. Updating to this kernel requires extra work or you won't be able to login: install a snapshot instead. Much assistance in fixing userland issues from deraadt@ and tedu@ and build assistance from todd@ and otto@
* When a ucom(4) is removed, it frees the tty with ttyfree(). However ifnicm2013-04-241-1/+2
| | | | | | | | | | | anyone is waiting with kqueue their knotes may still have a reference to the tty and later try to use it in the filt_tty* functions. To avoid this, walk the knotes in ttyfree(), remove them from the tty's list and invalidate them by setting kn_hook to NODEV. The filter functions can then check for this and safely ignore the knotes. ok tedu matthieu
* Missed a comment in the proc->process changeguenther2012-06-081-3/+3
|
* EVFILT_SIGNAL and EVFILT_PROC events need to track the process they'reguenther2012-06-061-2/+2
| | | | | | attached to and not just the thread, which can go away. Problem observed by jsg@; ok jsg@ matthew@
* Fix knote handling for exiting processes: when triggering a NOTE_EXITguenther2010-08-021-1/+2
| | | | | | | | | knote, remove it from the process's klist; after handling those, remove and drop any remaining knotes from the process's klist. Ban attaching knotes to processes that have started exiting or attaching them via the pid of a thread other than the main thread. ok tedu@, deraadt@
* Add a dummy kqueue filter similar to seltrue and use it for anythingnicm2010-07-281-1/+2
| | | | | | | | using seltrue for poll. Based on code from NetBSD. Also remove a stray duplicate lpt entry from loongson, from deraadt. ok tedu deraadt
* wrap use of KNOTE macro arguments in () to prevent potential strangedlg2008-11-051-2/+2
| | | | | | expansion. requested by otto@
* wrap an if statement in a macro up with do { } while (0) so it is safe todlg2008-11-051-2/+5
| | | | | | use in other if/else blocks. "yeah" deraadt@
* add a new kevent filter type for timers. this allows processes to createtedu2007-05-301-2/+3
| | | | | | a series of oneshot or periodic timers. capped to a global limit. from freebsd via brad. ok art pedro
* Change sys/select.h -> sys/selinfo.h in comment.millert2005-12-191-2/+2
|
* klist_invalidate to help clean up when the backend disappears, tested by mpf@tedu2004-01-121-1/+2
|
* add NOTE_EOF (return on EOF) and NOTE_TRUNCATE (vnode was truncated)tedu2003-12-171-1/+3
| | | | | to kqueue from marius@monkey tested by brad@
* void *, not caddr_t. missed in last commit. thanks Marco Peereboomtedu2003-07-221-2/+2
|
* filter event that simulates seltrue(). From NetBSDnate2003-06-271-1/+2
|
* filterops doesn't need to change, so we can make it constnate2003-05-221-2/+2
| | | | ok deraadt@