xref: /illumos-gate/usr/src/uts/common/sys/poll_impl.h (revision f23ed011)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
27a5eb7107SBryan Cantrill /*
2887bfe94cSPatrick Mooney  * Copyright 2017 Joyent, Inc.
292c76d751SPatrick Mooney  * Copyright 2022 Oxide Computer Company
30a5eb7107SBryan Cantrill  */
31a5eb7107SBryan Cantrill 
327c478bd9Sstevel@tonic-gate #ifndef _SYS_POLL_IMPL_H
337c478bd9Sstevel@tonic-gate #define	_SYS_POLL_IMPL_H
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate /*
367c478bd9Sstevel@tonic-gate  * Caching Poll Subsystem:
377c478bd9Sstevel@tonic-gate  *
387c478bd9Sstevel@tonic-gate  * Each kernel thread (1), if engaged in poll system call, has a reference to
397c478bd9Sstevel@tonic-gate  * a pollstate_t (2), which contains relevant flags and locks.  The pollstate_t
40f3bb54f3SPatrick Mooney  * contains a pointer to a pollcache_t (3), which caches the state of previous
417c478bd9Sstevel@tonic-gate  * calls to poll.  A bitmap (4) is stored inside the poll cache, where each
427c478bd9Sstevel@tonic-gate  * bit represents a file descriptor.  The bits are set if the corresponding
437c478bd9Sstevel@tonic-gate  * device has a polled event pending.  Only fds with their bit set will be
447c478bd9Sstevel@tonic-gate  * examined on the next poll invocation.  The pollstate_t also contains a list
457c478bd9Sstevel@tonic-gate  * of fd sets (5), which are represented by the pollcacheset_t type.  These
467c478bd9Sstevel@tonic-gate  * structures keep track of the pollfd_t arrays (6) passed in from userland.
477c478bd9Sstevel@tonic-gate  * Each polled file descriptor has a corresponding polldat_t which can be
487c478bd9Sstevel@tonic-gate  * chained onto a device's pollhead, and these are kept in a hash table (7)
49f3bb54f3SPatrick Mooney  * inside the pollcache_t.  The hash table allows efficient conversion of a
507c478bd9Sstevel@tonic-gate  * given fd to its corresponding polldat_t.
517c478bd9Sstevel@tonic-gate  *
527c478bd9Sstevel@tonic-gate  * (1)              (2)
537c478bd9Sstevel@tonic-gate  * +-----------+    +-------------+
547c478bd9Sstevel@tonic-gate  * | kthread_t |--->| pollstate_t |-->+-------------+  (6)
557c478bd9Sstevel@tonic-gate  * +-----------+    +-------------+(5)| pcacheset_t |->[_][_][_][_] pollfd_t
567c478bd9Sstevel@tonic-gate  *                          |         +-------------+
577c478bd9Sstevel@tonic-gate  *                          |         | pcacheset_t |->[_][_][_][_] pollfd_t
587c478bd9Sstevel@tonic-gate  * (1a)                     |         +-------------+
597c478bd9Sstevel@tonic-gate  * +---------------+	    |
607c478bd9Sstevel@tonic-gate  * | /dev/poll tbl |	    |
617c478bd9Sstevel@tonic-gate  * +-v-------------+	    |
627c478bd9Sstevel@tonic-gate  *   |			    |
637c478bd9Sstevel@tonic-gate  *   +------------------+   |
647c478bd9Sstevel@tonic-gate  * (7)              (3) V   v
657c478bd9Sstevel@tonic-gate  * polldat hash     +-------------+    (4) bitmap representing fd space
667c478bd9Sstevel@tonic-gate  * [_][_][_][_]<----|             |--->000010010010001010101010101010110
677c478bd9Sstevel@tonic-gate  *  |  |  |  |      | pollcache_t |
687c478bd9Sstevel@tonic-gate  *  .  v  .  .      |             |
697c478bd9Sstevel@tonic-gate  *    [polldat_t]   +-------------+
707c478bd9Sstevel@tonic-gate  *     |
717c478bd9Sstevel@tonic-gate  *    [polldat_t]
727c478bd9Sstevel@tonic-gate  *     |
737c478bd9Sstevel@tonic-gate  *     v
747c478bd9Sstevel@tonic-gate  *     NULL
757c478bd9Sstevel@tonic-gate  *
767c478bd9Sstevel@tonic-gate  *
777c478bd9Sstevel@tonic-gate  * Both poll system call and /dev/poll use the pollcache_t structure
787c478bd9Sstevel@tonic-gate  * definition and the routines managing the structure. But poll(2) and
797c478bd9Sstevel@tonic-gate  * /dev/poll have their own copy of the structures. The /dev/poll driver
80f3bb54f3SPatrick Mooney  * table (1a) contains an array of pointers, each pointing at a pollcache_t
817c478bd9Sstevel@tonic-gate  * struct (3). A device minor number is used as an device table index.
827c478bd9Sstevel@tonic-gate  *
837c478bd9Sstevel@tonic-gate  */
847c478bd9Sstevel@tonic-gate #include <sys/poll.h>
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_KMEMUSER)
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate #include <sys/thread.h>
897c478bd9Sstevel@tonic-gate #include <sys/file.h>
90f3bb54f3SPatrick Mooney #include <sys/port_kernel.h>
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
937c478bd9Sstevel@tonic-gate extern "C" {
947c478bd9Sstevel@tonic-gate #endif
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate /*
97f3bb54f3SPatrick Mooney  * Typedefs
98f3bb54f3SPatrick Mooney  */
99f3bb54f3SPatrick Mooney struct pollcache;
100f3bb54f3SPatrick Mooney struct pollstate;
101f3bb54f3SPatrick Mooney struct pcachelink;
102f3bb54f3SPatrick Mooney struct polldat;
103f3bb54f3SPatrick Mooney 
104f3bb54f3SPatrick Mooney typedef struct pollcache pollcache_t;
105f3bb54f3SPatrick Mooney typedef struct pollstate pollstate_t;
106f3bb54f3SPatrick Mooney typedef struct pcachelink pcachelink_t;
107f3bb54f3SPatrick Mooney typedef struct polldat polldat_t;
108f3bb54f3SPatrick Mooney 
109f3bb54f3SPatrick Mooney /*
1107c478bd9Sstevel@tonic-gate  * description of pollcacheset structure
1117c478bd9Sstevel@tonic-gate  */
1127c478bd9Sstevel@tonic-gate typedef struct pollcacheset {
1137c478bd9Sstevel@tonic-gate 	uintptr_t	pcs_usradr;	/* usr pollfd array address */
1147c478bd9Sstevel@tonic-gate 	pollfd_t	*pcs_pollfd;	/* cached poll lists */
1157c478bd9Sstevel@tonic-gate 	size_t		pcs_nfds;	/* number of poll fd in cached list */
1167c478bd9Sstevel@tonic-gate 	ulong_t		pcs_count;	/* for LU replacement policy */
1177c478bd9Sstevel@tonic-gate } pollcacheset_t;
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate #define	POLLFDSETS	2
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate /*
122f3bb54f3SPatrick Mooney  * Maximum depth for recusive poll operations.
123f3bb54f3SPatrick Mooney  */
124f3bb54f3SPatrick Mooney #define	POLLMAXDEPTH	5
125f3bb54f3SPatrick Mooney 
126f3bb54f3SPatrick Mooney /*
1277c478bd9Sstevel@tonic-gate  * State information kept by each polling thread
1287c478bd9Sstevel@tonic-gate  */
129f3bb54f3SPatrick Mooney struct pollstate {
1307c478bd9Sstevel@tonic-gate 	pollfd_t	*ps_pollfd;	/* hold the current poll list */
1317c478bd9Sstevel@tonic-gate 	size_t		ps_nfds;	/* size of ps_pollfd */
1327c478bd9Sstevel@tonic-gate 	kmutex_t	ps_lock;	/* mutex for sleep/wakeup */
133f3bb54f3SPatrick Mooney 	pollcache_t	*ps_pcache;	/* cached poll fd set */
1347c478bd9Sstevel@tonic-gate 	pollcacheset_t	*ps_pcacheset;	/* cached poll lists */
1357c478bd9Sstevel@tonic-gate 	int		ps_nsets;	/* no. of cached poll sets */
1367c478bd9Sstevel@tonic-gate 	pollfd_t	*ps_dpbuf;	/* return pollfd buf used by devpoll */
1377c478bd9Sstevel@tonic-gate 	size_t		ps_dpbufsize;	/* size of ps_dpbuf */
138f3bb54f3SPatrick Mooney 	int		ps_depth;	/* epoll recursion depth */
139f3bb54f3SPatrick Mooney 	pollcache_t	*ps_pc_stack[POLLMAXDEPTH]; /* epoll recursion state */
140f3bb54f3SPatrick Mooney 	pollcache_t	*ps_contend_pc;		/* pollcache waited on */
141f3bb54f3SPatrick Mooney 	pollstate_t	*ps_contend_nextp;	/* next in contender list */
142f3bb54f3SPatrick Mooney 	pollstate_t	**ps_contend_pnextp;	/* pointer-to-previous-next */
143f3bb54f3SPatrick Mooney 	int		ps_flags;	/* state flags */
144f3bb54f3SPatrick Mooney };
145f3bb54f3SPatrick Mooney 
146f3bb54f3SPatrick Mooney /* pollstate flags */
147f3bb54f3SPatrick Mooney #define	POLLSTATE_STALEMATE	0x1
148f3bb54f3SPatrick Mooney #define	POLLSTATE_ULFAIL	0x2
149f3bb54f3SPatrick Mooney 
150f3bb54f3SPatrick Mooney /* pollstate_enter results */
151f3bb54f3SPatrick Mooney #define	PSE_SUCCESS		0
152f3bb54f3SPatrick Mooney #define	PSE_FAIL_DEPTH		1
153f3bb54f3SPatrick Mooney #define	PSE_FAIL_LOOP		2
154f3bb54f3SPatrick Mooney #define	PSE_FAIL_DEADLOCK	3
155f3bb54f3SPatrick Mooney #define	PSE_FAIL_POLLSTATE	4
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate /*
1587c478bd9Sstevel@tonic-gate  * poll cache size defines
1597c478bd9Sstevel@tonic-gate  */
1607c478bd9Sstevel@tonic-gate #define	POLLCHUNKSHIFT		8	/* hash table increment size is 256 */
1617c478bd9Sstevel@tonic-gate #define	POLLHASHCHUNKSZ		(1 << POLLCHUNKSHIFT)
1627c478bd9Sstevel@tonic-gate #define	POLLHASHINC		2	/* poll hash table growth factor */
1637c478bd9Sstevel@tonic-gate #define	POLLHASHTHRESHOLD	2	/* poll hash list length threshold */
1647c478bd9Sstevel@tonic-gate #define	POLLHASH(x, y)	((y) % (x))	/* poll hash function */
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate /*
1677c478bd9Sstevel@tonic-gate  * poll.c assumes the POLLMAPCHUNK is power of 2
1687c478bd9Sstevel@tonic-gate  */
1697c478bd9Sstevel@tonic-gate #define	POLLMAPCHUNK	2048	/* bitmap inc -- each for 2K of polled fd's */
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate /*
1727c478bd9Sstevel@tonic-gate  * used to refrence from watched fd back to the fd position in cached
1737c478bd9Sstevel@tonic-gate  * poll list for quick revents update.
1747c478bd9Sstevel@tonic-gate  */
1757c478bd9Sstevel@tonic-gate typedef struct xref {
1767c478bd9Sstevel@tonic-gate 	ssize_t	xf_position;    /* xref fd position in poll fd list */
1777c478bd9Sstevel@tonic-gate 	short	xf_refcnt;	/* ref cnt of same fd in poll list */
1787c478bd9Sstevel@tonic-gate } xref_t;
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate #define	POLLPOSINVAL	(-1L)	/* xf_position is invalid */
1817c478bd9Sstevel@tonic-gate #define	POLLPOSTRANS	(-2L)	/* xf_position is transient state */
1827c478bd9Sstevel@tonic-gate 
183f3bb54f3SPatrick Mooney 
184f3bb54f3SPatrick Mooney typedef enum pclstate {
185f3bb54f3SPatrick Mooney 	PCL_INIT = 0,	/* just allocated/zeroed, prior */
186f3bb54f3SPatrick Mooney 	PCL_VALID,	/* linked with both parent and child pollcaches */
187f3bb54f3SPatrick Mooney 	PCL_STALE,	/* still linked but marked stale, pending refresh */
188f3bb54f3SPatrick Mooney 	PCL_INVALID,	/* dissociated from one pollcache, awaiting cleanup */
189f3bb54f3SPatrick Mooney 	PCL_FREE	/* only meant to indicate use-after-free */
190f3bb54f3SPatrick Mooney } pclstate_t;
191f3bb54f3SPatrick Mooney 
192f3bb54f3SPatrick Mooney /*
193f3bb54f3SPatrick Mooney  * The pcachelink struct creates an association between parent and child
194f3bb54f3SPatrick Mooney  * pollcaches in a recursive /dev/poll operation.  Fields are protected by
195f3bb54f3SPatrick Mooney  * pcl_lock although manipulation of pcl_child_next or pcl_parent_next also
196f3bb54f3SPatrick Mooney  * requires holding pc_lock in the respective pcl_parent_pc or pcl_child_pc
197f3bb54f3SPatrick Mooney  * pollcache.
198f3bb54f3SPatrick Mooney  */
199f3bb54f3SPatrick Mooney struct pcachelink {
200f3bb54f3SPatrick Mooney 	kmutex_t	pcl_lock;		/* protects contents */
201f3bb54f3SPatrick Mooney 	pclstate_t	pcl_state;		/* status of link entry */
202f3bb54f3SPatrick Mooney 	int		pcl_refcnt;		/* ref cnt of linked pcaches */
203f3bb54f3SPatrick Mooney 	pollcache_t	*pcl_child_pc;		/* child pollcache */
204f3bb54f3SPatrick Mooney 	pollcache_t	*pcl_parent_pc;		/* parent pollcache */
205f3bb54f3SPatrick Mooney 	pcachelink_t	*pcl_child_next;	/* next in child list */
206f3bb54f3SPatrick Mooney 	pcachelink_t	*pcl_parent_next;	/* next in parents list */
207f3bb54f3SPatrick Mooney };
208f3bb54f3SPatrick Mooney 
209f3bb54f3SPatrick Mooney 
2107c478bd9Sstevel@tonic-gate /*
2117c478bd9Sstevel@tonic-gate  * polldat is an entry for a cached poll fd. A polldat struct can be in
2127c478bd9Sstevel@tonic-gate  * poll cache table as well as on pollhead ph_list, which is used by
2137c478bd9Sstevel@tonic-gate  * pollwakeup to wake up a sleeping poller. There should be one polldat
2147c478bd9Sstevel@tonic-gate  * per polled fd hanging off pollstate struct.
2157c478bd9Sstevel@tonic-gate  */
216f3bb54f3SPatrick Mooney struct polldat {
2177c478bd9Sstevel@tonic-gate 	int		pd_fd;		/* cached poll fd */
2187c478bd9Sstevel@tonic-gate 	int		pd_events;	/* union of all polled events */
2197c478bd9Sstevel@tonic-gate 	file_t		*pd_fp;		/* used to detect fd reuse */
2207c478bd9Sstevel@tonic-gate 	pollhead_t	*pd_php;	/* used to undo poll registration */
2217c478bd9Sstevel@tonic-gate 	kthread_t	*pd_thread;	/* used for waking up a sleep thrd */
222f3bb54f3SPatrick Mooney 	pollcache_t	*pd_pcache;	/* a ptr to the pollcache of this fd */
223f3bb54f3SPatrick Mooney 	polldat_t	*pd_next;	/* next on pollhead's ph_list */
224f3bb54f3SPatrick Mooney 	polldat_t	*pd_hashnext;	/* next on pollhead's ph_list */
2257c478bd9Sstevel@tonic-gate 	int		pd_count;	/* total count from all ref'ed sets */
2267c478bd9Sstevel@tonic-gate 	int		pd_nsets;	/* num of xref sets, used by poll(2) */
2277c478bd9Sstevel@tonic-gate 	xref_t		*pd_ref;	/* ptr to xref info, 1 for each set */
228f3bb54f3SPatrick Mooney 	port_kevent_t	*pd_portev;	/* associated port event struct */
229086d9687SPatrick Mooney 	uf_entry_gen_t	pd_gen;		/* fd generation at cache time */
230a5eb7107SBryan Cantrill 	uint64_t	pd_epolldata;	/* epoll data, if any */
231f3bb54f3SPatrick Mooney };
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate /*
2347c478bd9Sstevel@tonic-gate  * One cache for each thread that polls. Points to a bitmap (used by pollwakeup)
2357c478bd9Sstevel@tonic-gate  * and a hash table of polldats.
236*f23ed011SPatrick Mooney  *
237*f23ed011SPatrick Mooney  * Because of the handling required in pollrelock(), portfs abuses the notion of
238*f23ed011SPatrick Mooney  * an active pollcache (t_pollcache), providing its own struct port_fdcache_t.
239*f23ed011SPatrick Mooney  * It has matching pc_lock and pc_flag members at the correct offsets, but none
240*f23ed011SPatrick Mooney  * of its other fields can be accessed (through t_pollcache) safetly.
2417c478bd9Sstevel@tonic-gate  */
242f3bb54f3SPatrick Mooney struct pollcache {
2437c478bd9Sstevel@tonic-gate 	kmutex_t	pc_lock;	/* lock to protect pollcache */
2447c478bd9Sstevel@tonic-gate 	ulong_t		*pc_bitmap;	/* point to poll fd bitmap */
2457c478bd9Sstevel@tonic-gate 	polldat_t	**pc_hash;	/* points to a hash table of ptrs */
2467c478bd9Sstevel@tonic-gate 	int		pc_mapend;	/* the largest fd encountered so far */
2477c478bd9Sstevel@tonic-gate 	int		pc_mapsize;	/* the size of current map */
2487c478bd9Sstevel@tonic-gate 	int		pc_hashsize;	/* the size of current hash table */
2497c478bd9Sstevel@tonic-gate 	int		pc_fdcount;	/* track how many fd's are hashed */
2507c478bd9Sstevel@tonic-gate 	int		pc_flag;	/* see pc_flag define below */
2517c478bd9Sstevel@tonic-gate 	int		pc_busy;	/* can only exit when its 0 */
2527c478bd9Sstevel@tonic-gate 	kmutex_t	pc_no_exit;	/* protects pc_busy*, can't be nested */
2537c478bd9Sstevel@tonic-gate 	kcondvar_t	pc_busy_cv;	/* cv to wait on if ps_busy != 0 */
2547c478bd9Sstevel@tonic-gate 	kcondvar_t	pc_cv;		/* cv to wait on if needed */
2557c478bd9Sstevel@tonic-gate 	pid_t		pc_pid;		/* for check acc rights, devpoll only */
2567c478bd9Sstevel@tonic-gate 	int		pc_mapstart;	/* where search start, devpoll only */
257f3bb54f3SPatrick Mooney 	pcachelink_t	*pc_parents;	/* linked list of epoll parents */
258f3bb54f3SPatrick Mooney 	pcachelink_t	*pc_children;	/* linked list of epoll children */
259f3bb54f3SPatrick Mooney };
2607c478bd9Sstevel@tonic-gate 
2617c478bd9Sstevel@tonic-gate /* pc_flag */
262a5eb7107SBryan Cantrill #define	PC_POLLWAKE	0x02	/* pollwakeup() occurred */
26387bfe94cSPatrick Mooney #define	PC_EPOLL	0x04	/* pollcache is epoll-enabled */
264*f23ed011SPatrick Mooney /*
265*f23ed011SPatrick Mooney  * PC_PORTFS is not a flag for "real" pollcaches, but rather an indicator for
266*f23ed011SPatrick Mooney  * when portfs sets t_pollcache to a port_fdcache_t pointer.  If, while
267*f23ed011SPatrick Mooney  * debugging a system, one sees PC_PORTFS in pc_flag, they will know to
268*f23ed011SPatrick Mooney  * disregard the other fields, as it is not a pollcache.
269*f23ed011SPatrick Mooney  */
270*f23ed011SPatrick Mooney #define	PC_PORTFS	0x08
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate #if defined(_KERNEL)
2737c478bd9Sstevel@tonic-gate /*
2747c478bd9Sstevel@tonic-gate  * Internal routines.
2757c478bd9Sstevel@tonic-gate  */
2767c478bd9Sstevel@tonic-gate extern void pollnotify(pollcache_t *, int);
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate /*
2797c478bd9Sstevel@tonic-gate  * public poll head interfaces (see poll.h):
2807c478bd9Sstevel@tonic-gate  *
2817c478bd9Sstevel@tonic-gate  *  pollhead_clean      clean up all polldats on a pollhead list
2827c478bd9Sstevel@tonic-gate  */
2837c478bd9Sstevel@tonic-gate extern void pollhead_clean(pollhead_t *);
2847c478bd9Sstevel@tonic-gate 
2857c478bd9Sstevel@tonic-gate /*
2867c478bd9Sstevel@tonic-gate  * private poll head interfaces:
2877c478bd9Sstevel@tonic-gate  *
2882c76d751SPatrick Mooney  *  polldat_associate		adds a polldat to a pollhead list
2892c76d751SPatrick Mooney  *  polldat_disassociate	remove polldat from its assoc'd pollhead list
2907c478bd9Sstevel@tonic-gate  */
2912c76d751SPatrick Mooney extern void polldat_associate(polldat_t *, pollhead_t *);
2922c76d751SPatrick Mooney extern void polldat_disassociate(polldat_t *);
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate /*
2957c478bd9Sstevel@tonic-gate  * poll state interfaces:
2967c478bd9Sstevel@tonic-gate  *
297f3bb54f3SPatrick Mooney  *  pollstate_create	initializes per-thread pollstate
2987c478bd9Sstevel@tonic-gate  *  pollstate_destroy	cleans up per-thread pollstate
299f3bb54f3SPatrick Mooney  *  pollstate_enter	safely lock pollcache for pollstate
300f3bb54f3SPatrick Mooney  *  pollstate_exit	unlock pollcache from pollstate
3017c478bd9Sstevel@tonic-gate  */
3027c478bd9Sstevel@tonic-gate extern pollstate_t *pollstate_create(void);
3037c478bd9Sstevel@tonic-gate extern void pollstate_destroy(pollstate_t *);
304f3bb54f3SPatrick Mooney extern int pollstate_enter(pollcache_t *);
305f3bb54f3SPatrick Mooney extern void pollstate_exit(pollcache_t *);
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate /*
3087c478bd9Sstevel@tonic-gate  * public pcache interfaces:
3097c478bd9Sstevel@tonic-gate  *
3107c478bd9Sstevel@tonic-gate  *  pcache_alloc	allocate a poll cache skeleton
3117c478bd9Sstevel@tonic-gate  *  pcache_create       creates all poll cache supporting data struct
3127c478bd9Sstevel@tonic-gate  *  pcache_insert	cache a poll fd, calls pcache_insert_fd
3137c478bd9Sstevel@tonic-gate  *  pcache_lookup       given an fd list, returns a cookie
3147c478bd9Sstevel@tonic-gate  *  pcache_poll         polls the cache for fd's having events on them
3157c478bd9Sstevel@tonic-gate  *  pcache_clean        clean up all the pollhead and fpollinfo reference
3167c478bd9Sstevel@tonic-gate  *  pcache_destroy      destroys the pcache
3177c478bd9Sstevel@tonic-gate  */
3187c478bd9Sstevel@tonic-gate extern pollcache_t *pcache_alloc();
3197c478bd9Sstevel@tonic-gate extern void pcache_create(pollcache_t *, nfds_t);
3207c478bd9Sstevel@tonic-gate extern int pcache_insert(pollstate_t *, file_t *, pollfd_t *, int *, ssize_t,
3217c478bd9Sstevel@tonic-gate     int);
3227c478bd9Sstevel@tonic-gate extern int pcache_poll(pollfd_t *, pollstate_t *, nfds_t, int *, int);
3237c478bd9Sstevel@tonic-gate extern void pcache_clean(pollcache_t *);
3247c478bd9Sstevel@tonic-gate extern void pcache_destroy(pollcache_t *);
3257c478bd9Sstevel@tonic-gate 
3267c478bd9Sstevel@tonic-gate /*
3277c478bd9Sstevel@tonic-gate  * private pcache interfaces:
3287c478bd9Sstevel@tonic-gate  *
3297c478bd9Sstevel@tonic-gate  *  pcache_lookup_fd	lookup an fd, returns a polldat
3307c478bd9Sstevel@tonic-gate  *  pcache_alloc_fd	allocates and returns a polldat
3317c478bd9Sstevel@tonic-gate  *  pcache_insert_fd	insert an fd into pcache (called by pcache_insert)
3327c478bd9Sstevel@tonic-gate  *  pcache_delete_fd	insert an fd into pcache (called by pcacheset_delete_fd)
3337c478bd9Sstevel@tonic-gate  *  pcache_grow_hashtbl	grows the pollcache hash table and rehash
3347c478bd9Sstevel@tonic-gate  *  pcache_grow_map	grows the pollcache bitmap
3357c478bd9Sstevel@tonic-gate  *  pcache_update_xref	update cross ref (from polldat back to cacheset) info
3367c478bd9Sstevel@tonic-gate  *  pcache_clean_entry	cleanup an entry in pcache and more...
337f3bb54f3SPatrick Mooney  *  pcache_wake_parents	wake linked parent pollcaches
3387c478bd9Sstevel@tonic-gate  */
3397c478bd9Sstevel@tonic-gate extern polldat_t *pcache_lookup_fd(pollcache_t *, int);
3407c478bd9Sstevel@tonic-gate extern polldat_t *pcache_alloc_fd(int);
3417c478bd9Sstevel@tonic-gate extern void pcache_insert_fd(pollcache_t *, polldat_t *, nfds_t);
3427c478bd9Sstevel@tonic-gate extern int pcache_delete_fd(pollstate_t *, int, size_t, int, uint_t);
3437c478bd9Sstevel@tonic-gate extern void pcache_grow_hashtbl(pollcache_t *, nfds_t);
3447c478bd9Sstevel@tonic-gate extern void pcache_grow_map(pollcache_t *, int);
3457c478bd9Sstevel@tonic-gate extern void pcache_update_xref(pollcache_t *, int, ssize_t, int);
3467c478bd9Sstevel@tonic-gate extern void pcache_clean_entry(pollstate_t *, int);
347f3bb54f3SPatrick Mooney extern void pcache_wake_parents(pollcache_t *);
3487c478bd9Sstevel@tonic-gate 
3497c478bd9Sstevel@tonic-gate /*
3507c478bd9Sstevel@tonic-gate  * pcacheset interfaces:
3517c478bd9Sstevel@tonic-gate  *
3527c478bd9Sstevel@tonic-gate  * pcacheset_create     creates new pcachesets (easier for dynamic pcachesets)
3537c478bd9Sstevel@tonic-gate  * pcacheset_destroy    destroys a pcacheset
3547c478bd9Sstevel@tonic-gate  * pcacheset_cache_list caches and polls a new poll list
3557c478bd9Sstevel@tonic-gate  * pcacheset_remove_list removes (usually a partial) cached poll list
3567c478bd9Sstevel@tonic-gate  * pcacheset_resolve    resolves extant pcacheset and fd list
3577c478bd9Sstevel@tonic-gate  * pcacheset_cmp        compares a pcacheset with an fd list
3587c478bd9Sstevel@tonic-gate  * pcacheset_invalidate invalidate entries in pcachesets
3597c478bd9Sstevel@tonic-gate  * pcacheset_reset_count resets the usage counter of pcachesets
3607c478bd9Sstevel@tonic-gate  * pcacheset_replace	selects a poll cacheset for replacement
3617c478bd9Sstevel@tonic-gate  */
3627c478bd9Sstevel@tonic-gate extern pollcacheset_t *pcacheset_create(int);
3637c478bd9Sstevel@tonic-gate extern void pcacheset_destroy(pollcacheset_t *, int);
3647c478bd9Sstevel@tonic-gate extern int pcacheset_cache_list(pollstate_t *, pollfd_t *, int *, int);
3657c478bd9Sstevel@tonic-gate extern void pcacheset_remove_list(pollstate_t *, pollfd_t *, int, int, int,
3667c478bd9Sstevel@tonic-gate     int);
3677c478bd9Sstevel@tonic-gate extern int pcacheset_resolve(pollstate_t *, nfds_t, int *, int);
3687c478bd9Sstevel@tonic-gate extern int pcacheset_cmp(pollfd_t *, pollfd_t *, pollfd_t *, int);
3697c478bd9Sstevel@tonic-gate extern void pcacheset_invalidate(pollstate_t *, polldat_t *);
3707c478bd9Sstevel@tonic-gate extern void pcacheset_reset_count(pollstate_t *, int);
3717c478bd9Sstevel@tonic-gate extern int pcacheset_replace(pollstate_t *);
3727c478bd9Sstevel@tonic-gate 
3737c478bd9Sstevel@tonic-gate #endif /* defined(_KERNEL) */
3747c478bd9Sstevel@tonic-gate 
3757c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
3767c478bd9Sstevel@tonic-gate }
3777c478bd9Sstevel@tonic-gate #endif
3787c478bd9Sstevel@tonic-gate 
3797c478bd9Sstevel@tonic-gate #endif /* defined(_KERNEL) || defined(_KMEMUSER) */
3807c478bd9Sstevel@tonic-gate 
3817c478bd9Sstevel@tonic-gate #endif	/* _SYS_POLL_IMPL_H */
382