xref: /titanic_52/usr/src/uts/common/sys/poll_impl.h (revision f3bb54f387fc03cf651e19bbee54cc88ee51bb29)
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 /*
28*f3bb54f3SPatrick Mooney  * Copyright 2015, Joyent, Inc.
29a5eb7107SBryan Cantrill  */
30a5eb7107SBryan Cantrill 
317c478bd9Sstevel@tonic-gate #ifndef _SYS_POLL_IMPL_H
327c478bd9Sstevel@tonic-gate #define	_SYS_POLL_IMPL_H
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate /*
357c478bd9Sstevel@tonic-gate  * Caching Poll Subsystem:
367c478bd9Sstevel@tonic-gate  *
377c478bd9Sstevel@tonic-gate  * Each kernel thread (1), if engaged in poll system call, has a reference to
387c478bd9Sstevel@tonic-gate  * a pollstate_t (2), which contains relevant flags and locks.  The pollstate_t
39*f3bb54f3SPatrick Mooney  * contains a pointer to a pollcache_t (3), which caches the state of previous
407c478bd9Sstevel@tonic-gate  * calls to poll.  A bitmap (4) is stored inside the poll cache, where each
417c478bd9Sstevel@tonic-gate  * bit represents a file descriptor.  The bits are set if the corresponding
427c478bd9Sstevel@tonic-gate  * device has a polled event pending.  Only fds with their bit set will be
437c478bd9Sstevel@tonic-gate  * examined on the next poll invocation.  The pollstate_t also contains a list
447c478bd9Sstevel@tonic-gate  * of fd sets (5), which are represented by the pollcacheset_t type.  These
457c478bd9Sstevel@tonic-gate  * structures keep track of the pollfd_t arrays (6) passed in from userland.
467c478bd9Sstevel@tonic-gate  * Each polled file descriptor has a corresponding polldat_t which can be
477c478bd9Sstevel@tonic-gate  * chained onto a device's pollhead, and these are kept in a hash table (7)
48*f3bb54f3SPatrick Mooney  * inside the pollcache_t.  The hash table allows efficient conversion of a
497c478bd9Sstevel@tonic-gate  * given fd to its corresponding polldat_t.
507c478bd9Sstevel@tonic-gate  *
517c478bd9Sstevel@tonic-gate  * (1)              (2)
527c478bd9Sstevel@tonic-gate  * +-----------+    +-------------+
537c478bd9Sstevel@tonic-gate  * | kthread_t |--->| pollstate_t |-->+-------------+  (6)
547c478bd9Sstevel@tonic-gate  * +-----------+    +-------------+(5)| pcacheset_t |->[_][_][_][_] pollfd_t
557c478bd9Sstevel@tonic-gate  *                          |         +-------------+
567c478bd9Sstevel@tonic-gate  *                          |         | pcacheset_t |->[_][_][_][_] pollfd_t
577c478bd9Sstevel@tonic-gate  * (1a)                     |         +-------------+
587c478bd9Sstevel@tonic-gate  * +---------------+	    |
597c478bd9Sstevel@tonic-gate  * | /dev/poll tbl |	    |
607c478bd9Sstevel@tonic-gate  * +-v-------------+	    |
617c478bd9Sstevel@tonic-gate  *   |			    |
627c478bd9Sstevel@tonic-gate  *   +------------------+   |
637c478bd9Sstevel@tonic-gate  * (7)              (3) V   v
647c478bd9Sstevel@tonic-gate  * polldat hash     +-------------+    (4) bitmap representing fd space
657c478bd9Sstevel@tonic-gate  * [_][_][_][_]<----|             |--->000010010010001010101010101010110
667c478bd9Sstevel@tonic-gate  *  |  |  |  |      | pollcache_t |
677c478bd9Sstevel@tonic-gate  *  .  v  .  .      |             |
687c478bd9Sstevel@tonic-gate  *    [polldat_t]   +-------------+
697c478bd9Sstevel@tonic-gate  *     |
707c478bd9Sstevel@tonic-gate  *    [polldat_t]
717c478bd9Sstevel@tonic-gate  *     |
727c478bd9Sstevel@tonic-gate  *     v
737c478bd9Sstevel@tonic-gate  *     NULL
747c478bd9Sstevel@tonic-gate  *
757c478bd9Sstevel@tonic-gate  *
767c478bd9Sstevel@tonic-gate  * Both poll system call and /dev/poll use the pollcache_t structure
777c478bd9Sstevel@tonic-gate  * definition and the routines managing the structure. But poll(2) and
787c478bd9Sstevel@tonic-gate  * /dev/poll have their own copy of the structures. The /dev/poll driver
79*f3bb54f3SPatrick Mooney  * table (1a) contains an array of pointers, each pointing at a pollcache_t
807c478bd9Sstevel@tonic-gate  * struct (3). A device minor number is used as an device table index.
817c478bd9Sstevel@tonic-gate  *
827c478bd9Sstevel@tonic-gate  */
837c478bd9Sstevel@tonic-gate #include <sys/poll.h>
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate #if defined(_KERNEL) || defined(_KMEMUSER)
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate #include <sys/thread.h>
887c478bd9Sstevel@tonic-gate #include <sys/file.h>
89*f3bb54f3SPatrick Mooney #include <sys/port_kernel.h>
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
927c478bd9Sstevel@tonic-gate extern "C" {
937c478bd9Sstevel@tonic-gate #endif
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate /*
96*f3bb54f3SPatrick Mooney  * Typedefs
97*f3bb54f3SPatrick Mooney  */
98*f3bb54f3SPatrick Mooney struct pollcache;
99*f3bb54f3SPatrick Mooney struct pollstate;
100*f3bb54f3SPatrick Mooney struct pcachelink;
101*f3bb54f3SPatrick Mooney struct polldat;
102*f3bb54f3SPatrick Mooney 
103*f3bb54f3SPatrick Mooney typedef struct pollcache pollcache_t;
104*f3bb54f3SPatrick Mooney typedef struct pollstate pollstate_t;
105*f3bb54f3SPatrick Mooney typedef struct pcachelink pcachelink_t;
106*f3bb54f3SPatrick Mooney typedef struct polldat polldat_t;
107*f3bb54f3SPatrick Mooney 
108*f3bb54f3SPatrick Mooney /*
1097c478bd9Sstevel@tonic-gate  * description of pollcacheset structure
1107c478bd9Sstevel@tonic-gate  */
1117c478bd9Sstevel@tonic-gate typedef struct pollcacheset {
1127c478bd9Sstevel@tonic-gate 	uintptr_t	pcs_usradr;	/* usr pollfd array address */
1137c478bd9Sstevel@tonic-gate 	pollfd_t	*pcs_pollfd;	/* cached poll lists */
1147c478bd9Sstevel@tonic-gate 	size_t		pcs_nfds;	/* number of poll fd in cached list */
1157c478bd9Sstevel@tonic-gate 	ulong_t		pcs_count;	/* for LU replacement policy */
1167c478bd9Sstevel@tonic-gate } pollcacheset_t;
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate #define	POLLFDSETS	2
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate /*
121*f3bb54f3SPatrick Mooney  * Maximum depth for recusive poll operations.
122*f3bb54f3SPatrick Mooney  */
123*f3bb54f3SPatrick Mooney #define	POLLMAXDEPTH	5
124*f3bb54f3SPatrick Mooney 
125*f3bb54f3SPatrick Mooney /*
1267c478bd9Sstevel@tonic-gate  * State information kept by each polling thread
1277c478bd9Sstevel@tonic-gate  */
128*f3bb54f3SPatrick Mooney struct pollstate {
1297c478bd9Sstevel@tonic-gate 	pollfd_t	*ps_pollfd;	/* hold the current poll list */
1307c478bd9Sstevel@tonic-gate 	size_t		ps_nfds;	/* size of ps_pollfd */
1317c478bd9Sstevel@tonic-gate 	kmutex_t	ps_lock;	/* mutex for sleep/wakeup */
132*f3bb54f3SPatrick Mooney 	pollcache_t	*ps_pcache;	/* cached poll fd set */
1337c478bd9Sstevel@tonic-gate 	pollcacheset_t	*ps_pcacheset;	/* cached poll lists */
1347c478bd9Sstevel@tonic-gate 	int		ps_nsets;	/* no. of cached poll sets */
1357c478bd9Sstevel@tonic-gate 	pollfd_t	*ps_dpbuf;	/* return pollfd buf used by devpoll */
1367c478bd9Sstevel@tonic-gate 	size_t		ps_dpbufsize;	/* size of ps_dpbuf */
137*f3bb54f3SPatrick Mooney 	int		ps_depth;	/* epoll recursion depth */
138*f3bb54f3SPatrick Mooney 	pollcache_t	*ps_pc_stack[POLLMAXDEPTH]; /* epoll recursion state */
139*f3bb54f3SPatrick Mooney 	pollcache_t	*ps_contend_pc;		/* pollcache waited on */
140*f3bb54f3SPatrick Mooney 	pollstate_t	*ps_contend_nextp;	/* next in contender list */
141*f3bb54f3SPatrick Mooney 	pollstate_t	**ps_contend_pnextp;	/* pointer-to-previous-next */
142*f3bb54f3SPatrick Mooney 	int		ps_flags;	/* state flags */
143*f3bb54f3SPatrick Mooney };
144*f3bb54f3SPatrick Mooney 
145*f3bb54f3SPatrick Mooney /* pollstate flags */
146*f3bb54f3SPatrick Mooney #define	POLLSTATE_STALEMATE	0x1
147*f3bb54f3SPatrick Mooney #define	POLLSTATE_ULFAIL	0x2
148*f3bb54f3SPatrick Mooney 
149*f3bb54f3SPatrick Mooney /* pollstate_enter results */
150*f3bb54f3SPatrick Mooney #define	PSE_SUCCESS		0
151*f3bb54f3SPatrick Mooney #define	PSE_FAIL_DEPTH		1
152*f3bb54f3SPatrick Mooney #define	PSE_FAIL_LOOP		2
153*f3bb54f3SPatrick Mooney #define	PSE_FAIL_DEADLOCK	3
154*f3bb54f3SPatrick Mooney #define	PSE_FAIL_POLLSTATE	4
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate /*
1577c478bd9Sstevel@tonic-gate  * poll cache size defines
1587c478bd9Sstevel@tonic-gate  */
1597c478bd9Sstevel@tonic-gate #define	POLLCHUNKSHIFT		8	/* hash table increment size is 256 */
1607c478bd9Sstevel@tonic-gate #define	POLLHASHCHUNKSZ		(1 << POLLCHUNKSHIFT)
1617c478bd9Sstevel@tonic-gate #define	POLLHASHINC		2	/* poll hash table growth factor */
1627c478bd9Sstevel@tonic-gate #define	POLLHASHTHRESHOLD	2	/* poll hash list length threshold */
1637c478bd9Sstevel@tonic-gate #define	POLLHASH(x, y)	((y) % (x))	/* poll hash function */
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate /*
1667c478bd9Sstevel@tonic-gate  * poll.c assumes the POLLMAPCHUNK is power of 2
1677c478bd9Sstevel@tonic-gate  */
1687c478bd9Sstevel@tonic-gate #define	POLLMAPCHUNK	2048	/* bitmap inc -- each for 2K of polled fd's */
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate /*
1717c478bd9Sstevel@tonic-gate  * used to refrence from watched fd back to the fd position in cached
1727c478bd9Sstevel@tonic-gate  * poll list for quick revents update.
1737c478bd9Sstevel@tonic-gate  */
1747c478bd9Sstevel@tonic-gate typedef struct xref {
1757c478bd9Sstevel@tonic-gate 	ssize_t	xf_position;    /* xref fd position in poll fd list */
1767c478bd9Sstevel@tonic-gate 	short	xf_refcnt;	/* ref cnt of same fd in poll list */
1777c478bd9Sstevel@tonic-gate } xref_t;
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate #define	POLLPOSINVAL	(-1L)	/* xf_position is invalid */
1807c478bd9Sstevel@tonic-gate #define	POLLPOSTRANS	(-2L)	/* xf_position is transient state */
1817c478bd9Sstevel@tonic-gate 
182*f3bb54f3SPatrick Mooney 
183*f3bb54f3SPatrick Mooney typedef enum pclstate {
184*f3bb54f3SPatrick Mooney 	PCL_INIT = 0,	/* just allocated/zeroed, prior */
185*f3bb54f3SPatrick Mooney 	PCL_VALID,	/* linked with both parent and child pollcaches */
186*f3bb54f3SPatrick Mooney 	PCL_STALE,	/* still linked but marked stale, pending refresh */
187*f3bb54f3SPatrick Mooney 	PCL_INVALID,	/* dissociated from one pollcache, awaiting cleanup */
188*f3bb54f3SPatrick Mooney 	PCL_FREE	/* only meant to indicate use-after-free */
189*f3bb54f3SPatrick Mooney } pclstate_t;
190*f3bb54f3SPatrick Mooney 
191*f3bb54f3SPatrick Mooney /*
192*f3bb54f3SPatrick Mooney  * The pcachelink struct creates an association between parent and child
193*f3bb54f3SPatrick Mooney  * pollcaches in a recursive /dev/poll operation.  Fields are protected by
194*f3bb54f3SPatrick Mooney  * pcl_lock although manipulation of pcl_child_next or pcl_parent_next also
195*f3bb54f3SPatrick Mooney  * requires holding pc_lock in the respective pcl_parent_pc or pcl_child_pc
196*f3bb54f3SPatrick Mooney  * pollcache.
197*f3bb54f3SPatrick Mooney  */
198*f3bb54f3SPatrick Mooney struct pcachelink {
199*f3bb54f3SPatrick Mooney 	kmutex_t	pcl_lock;		/* protects contents */
200*f3bb54f3SPatrick Mooney 	pclstate_t	pcl_state;		/* status of link entry */
201*f3bb54f3SPatrick Mooney 	int		pcl_refcnt;		/* ref cnt of linked pcaches */
202*f3bb54f3SPatrick Mooney 	pollcache_t	*pcl_child_pc;		/* child pollcache */
203*f3bb54f3SPatrick Mooney 	pollcache_t	*pcl_parent_pc;		/* parent pollcache */
204*f3bb54f3SPatrick Mooney 	pcachelink_t	*pcl_child_next;	/* next in child list */
205*f3bb54f3SPatrick Mooney 	pcachelink_t	*pcl_parent_next;	/* next in parents list */
206*f3bb54f3SPatrick Mooney };
207*f3bb54f3SPatrick Mooney 
208*f3bb54f3SPatrick Mooney 
2097c478bd9Sstevel@tonic-gate /*
2107c478bd9Sstevel@tonic-gate  * polldat is an entry for a cached poll fd. A polldat struct can be in
2117c478bd9Sstevel@tonic-gate  * poll cache table as well as on pollhead ph_list, which is used by
2127c478bd9Sstevel@tonic-gate  * pollwakeup to wake up a sleeping poller. There should be one polldat
2137c478bd9Sstevel@tonic-gate  * per polled fd hanging off pollstate struct.
2147c478bd9Sstevel@tonic-gate  */
215*f3bb54f3SPatrick Mooney struct polldat {
2167c478bd9Sstevel@tonic-gate 	int		pd_fd;		/* cached poll fd */
2177c478bd9Sstevel@tonic-gate 	int		pd_events;	/* union of all polled events */
2187c478bd9Sstevel@tonic-gate 	file_t		*pd_fp;		/* used to detect fd reuse */
2197c478bd9Sstevel@tonic-gate 	pollhead_t	*pd_php;	/* used to undo poll registration */
2207c478bd9Sstevel@tonic-gate 	kthread_t	*pd_thread;	/* used for waking up a sleep thrd */
221*f3bb54f3SPatrick Mooney 	pollcache_t	*pd_pcache;	/* a ptr to the pollcache of this fd */
222*f3bb54f3SPatrick Mooney 	polldat_t	*pd_next;	/* next on pollhead's ph_list */
223*f3bb54f3SPatrick Mooney 	polldat_t	*pd_hashnext;	/* next on pollhead's ph_list */
2247c478bd9Sstevel@tonic-gate 	int		pd_count;	/* total count from all ref'ed sets */
2257c478bd9Sstevel@tonic-gate 	int		pd_nsets;	/* num of xref sets, used by poll(2) */
2267c478bd9Sstevel@tonic-gate 	xref_t		*pd_ref;	/* ptr to xref info, 1 for each set */
227*f3bb54f3SPatrick Mooney 	port_kevent_t	*pd_portev;	/* associated port event struct */
228a5eb7107SBryan Cantrill 	uint64_t	pd_epolldata;	/* epoll data, if any */
229*f3bb54f3SPatrick Mooney };
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate /*
2327c478bd9Sstevel@tonic-gate  * One cache for each thread that polls. Points to a bitmap (used by pollwakeup)
2337c478bd9Sstevel@tonic-gate  * and a hash table of polldats.
2347c478bd9Sstevel@tonic-gate  * The offset of pc_lock field must be kept in sync with the pc_lock offset
2357c478bd9Sstevel@tonic-gate  * of port_fdcache_t, both structs implement pc_lock with offset 0 (see also
2367c478bd9Sstevel@tonic-gate  * pollrelock()).
2377c478bd9Sstevel@tonic-gate  */
238*f3bb54f3SPatrick Mooney struct pollcache {
2397c478bd9Sstevel@tonic-gate 	kmutex_t	pc_lock;	/* lock to protect pollcache */
2407c478bd9Sstevel@tonic-gate 	ulong_t		*pc_bitmap;	/* point to poll fd bitmap */
2417c478bd9Sstevel@tonic-gate 	polldat_t	**pc_hash;	/* points to a hash table of ptrs */
2427c478bd9Sstevel@tonic-gate 	int		pc_mapend;	/* the largest fd encountered so far */
2437c478bd9Sstevel@tonic-gate 	int		pc_mapsize;	/* the size of current map */
2447c478bd9Sstevel@tonic-gate 	int		pc_hashsize;	/* the size of current hash table */
2457c478bd9Sstevel@tonic-gate 	int		pc_fdcount;	/* track how many fd's are hashed */
2467c478bd9Sstevel@tonic-gate 	int		pc_flag;	/* see pc_flag define below */
2477c478bd9Sstevel@tonic-gate 	int		pc_busy;	/* can only exit when its 0 */
2487c478bd9Sstevel@tonic-gate 	kmutex_t	pc_no_exit;	/* protects pc_busy*, can't be nested */
2497c478bd9Sstevel@tonic-gate 	kcondvar_t	pc_busy_cv;	/* cv to wait on if ps_busy != 0 */
2507c478bd9Sstevel@tonic-gate 	kcondvar_t	pc_cv;		/* cv to wait on if needed */
2517c478bd9Sstevel@tonic-gate 	pid_t		pc_pid;		/* for check acc rights, devpoll only */
2527c478bd9Sstevel@tonic-gate 	int		pc_mapstart;	/* where search start, devpoll only */
253*f3bb54f3SPatrick Mooney 	pcachelink_t	*pc_parents;	/* linked list of epoll parents */
254*f3bb54f3SPatrick Mooney 	pcachelink_t	*pc_children;	/* linked list of epoll children */
255*f3bb54f3SPatrick Mooney };
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate /* pc_flag */
258a5eb7107SBryan Cantrill #define	PC_POLLWAKE	0x02	/* pollwakeup() occurred */
2597c478bd9Sstevel@tonic-gate 
2607c478bd9Sstevel@tonic-gate #if defined(_KERNEL)
2617c478bd9Sstevel@tonic-gate /*
2627c478bd9Sstevel@tonic-gate  * Internal routines.
2637c478bd9Sstevel@tonic-gate  */
2647c478bd9Sstevel@tonic-gate extern void pollnotify(pollcache_t *, int);
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate /*
2677c478bd9Sstevel@tonic-gate  * public poll head interfaces (see poll.h):
2687c478bd9Sstevel@tonic-gate  *
2697c478bd9Sstevel@tonic-gate  *  pollhead_clean      clean up all polldats on a pollhead list
2707c478bd9Sstevel@tonic-gate  */
2717c478bd9Sstevel@tonic-gate extern void pollhead_clean(pollhead_t *);
2727c478bd9Sstevel@tonic-gate 
2737c478bd9Sstevel@tonic-gate /*
2747c478bd9Sstevel@tonic-gate  * private poll head interfaces:
2757c478bd9Sstevel@tonic-gate  *
2767c478bd9Sstevel@tonic-gate  *  pollhead_insert     adds a polldat to a pollhead list
2777c478bd9Sstevel@tonic-gate  *  pollhead_delete     removes a polldat from a pollhead list
2787c478bd9Sstevel@tonic-gate  */
2797c478bd9Sstevel@tonic-gate extern void pollhead_insert(pollhead_t *, polldat_t *);
2807c478bd9Sstevel@tonic-gate extern void pollhead_delete(pollhead_t *, polldat_t *);
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate /*
2837c478bd9Sstevel@tonic-gate  * poll state interfaces:
2847c478bd9Sstevel@tonic-gate  *
285*f3bb54f3SPatrick Mooney  *  pollstate_create	initializes per-thread pollstate
2867c478bd9Sstevel@tonic-gate  *  pollstate_destroy	cleans up per-thread pollstate
287*f3bb54f3SPatrick Mooney  *  pollstate_enter	safely lock pollcache for pollstate
288*f3bb54f3SPatrick Mooney  *  pollstate_exit	unlock pollcache from pollstate
2897c478bd9Sstevel@tonic-gate  */
2907c478bd9Sstevel@tonic-gate extern pollstate_t *pollstate_create(void);
2917c478bd9Sstevel@tonic-gate extern void pollstate_destroy(pollstate_t *);
292*f3bb54f3SPatrick Mooney extern int pollstate_enter(pollcache_t *);
293*f3bb54f3SPatrick Mooney extern void pollstate_exit(pollcache_t *);
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate /*
2967c478bd9Sstevel@tonic-gate  * public pcache interfaces:
2977c478bd9Sstevel@tonic-gate  *
2987c478bd9Sstevel@tonic-gate  *  pcache_alloc	allocate a poll cache skeleton
2997c478bd9Sstevel@tonic-gate  *  pcache_create       creates all poll cache supporting data struct
3007c478bd9Sstevel@tonic-gate  *  pcache_insert	cache a poll fd, calls pcache_insert_fd
3017c478bd9Sstevel@tonic-gate  *  pcache_lookup       given an fd list, returns a cookie
3027c478bd9Sstevel@tonic-gate  *  pcache_poll         polls the cache for fd's having events on them
3037c478bd9Sstevel@tonic-gate  *  pcache_clean        clean up all the pollhead and fpollinfo reference
3047c478bd9Sstevel@tonic-gate  *  pcache_destroy      destroys the pcache
3057c478bd9Sstevel@tonic-gate  */
3067c478bd9Sstevel@tonic-gate extern pollcache_t *pcache_alloc();
3077c478bd9Sstevel@tonic-gate extern void pcache_create(pollcache_t *, nfds_t);
3087c478bd9Sstevel@tonic-gate extern int pcache_insert(pollstate_t *, file_t *, pollfd_t *, int *, ssize_t,
3097c478bd9Sstevel@tonic-gate     int);
3107c478bd9Sstevel@tonic-gate extern int pcache_poll(pollfd_t *, pollstate_t *, nfds_t, int *, int);
3117c478bd9Sstevel@tonic-gate extern void pcache_clean(pollcache_t *);
3127c478bd9Sstevel@tonic-gate extern void pcache_destroy(pollcache_t *);
3137c478bd9Sstevel@tonic-gate 
3147c478bd9Sstevel@tonic-gate /*
3157c478bd9Sstevel@tonic-gate  * private pcache interfaces:
3167c478bd9Sstevel@tonic-gate  *
3177c478bd9Sstevel@tonic-gate  *  pcache_lookup_fd	lookup an fd, returns a polldat
3187c478bd9Sstevel@tonic-gate  *  pcache_alloc_fd	allocates and returns a polldat
3197c478bd9Sstevel@tonic-gate  *  pcache_insert_fd	insert an fd into pcache (called by pcache_insert)
3207c478bd9Sstevel@tonic-gate  *  pcache_delete_fd	insert an fd into pcache (called by pcacheset_delete_fd)
3217c478bd9Sstevel@tonic-gate  *  pcache_grow_hashtbl	grows the pollcache hash table and rehash
3227c478bd9Sstevel@tonic-gate  *  pcache_grow_map	grows the pollcache bitmap
3237c478bd9Sstevel@tonic-gate  *  pcache_update_xref	update cross ref (from polldat back to cacheset) info
3247c478bd9Sstevel@tonic-gate  *  pcache_clean_entry	cleanup an entry in pcache and more...
325*f3bb54f3SPatrick Mooney  *  pcache_wake_parents	wake linked parent pollcaches
3267c478bd9Sstevel@tonic-gate  */
3277c478bd9Sstevel@tonic-gate extern polldat_t *pcache_lookup_fd(pollcache_t *, int);
3287c478bd9Sstevel@tonic-gate extern polldat_t *pcache_alloc_fd(int);
3297c478bd9Sstevel@tonic-gate extern void pcache_insert_fd(pollcache_t *, polldat_t *, nfds_t);
3307c478bd9Sstevel@tonic-gate extern int pcache_delete_fd(pollstate_t *, int, size_t, int, uint_t);
3317c478bd9Sstevel@tonic-gate extern void pcache_grow_hashtbl(pollcache_t *, nfds_t);
3327c478bd9Sstevel@tonic-gate extern void pcache_grow_map(pollcache_t *, int);
3337c478bd9Sstevel@tonic-gate extern void pcache_update_xref(pollcache_t *, int, ssize_t, int);
3347c478bd9Sstevel@tonic-gate extern void pcache_clean_entry(pollstate_t *, int);
335*f3bb54f3SPatrick Mooney extern void pcache_wake_parents(pollcache_t *);
3367c478bd9Sstevel@tonic-gate 
3377c478bd9Sstevel@tonic-gate /*
3387c478bd9Sstevel@tonic-gate  * pcacheset interfaces:
3397c478bd9Sstevel@tonic-gate  *
3407c478bd9Sstevel@tonic-gate  * pcacheset_create     creates new pcachesets (easier for dynamic pcachesets)
3417c478bd9Sstevel@tonic-gate  * pcacheset_destroy    destroys a pcacheset
3427c478bd9Sstevel@tonic-gate  * pcacheset_cache_list caches and polls a new poll list
3437c478bd9Sstevel@tonic-gate  * pcacheset_remove_list removes (usually a partial) cached poll list
3447c478bd9Sstevel@tonic-gate  * pcacheset_resolve    resolves extant pcacheset and fd list
3457c478bd9Sstevel@tonic-gate  * pcacheset_cmp        compares a pcacheset with an fd list
3467c478bd9Sstevel@tonic-gate  * pcacheset_invalidate invalidate entries in pcachesets
3477c478bd9Sstevel@tonic-gate  * pcacheset_reset_count resets the usage counter of pcachesets
3487c478bd9Sstevel@tonic-gate  * pcacheset_replace	selects a poll cacheset for replacement
3497c478bd9Sstevel@tonic-gate  */
3507c478bd9Sstevel@tonic-gate extern pollcacheset_t *pcacheset_create(int);
3517c478bd9Sstevel@tonic-gate extern void pcacheset_destroy(pollcacheset_t *, int);
3527c478bd9Sstevel@tonic-gate extern int pcacheset_cache_list(pollstate_t *, pollfd_t *, int *, int);
3537c478bd9Sstevel@tonic-gate extern void pcacheset_remove_list(pollstate_t *, pollfd_t *, int, int, int,
3547c478bd9Sstevel@tonic-gate     int);
3557c478bd9Sstevel@tonic-gate extern int pcacheset_resolve(pollstate_t *, nfds_t, int *, int);
3567c478bd9Sstevel@tonic-gate extern int pcacheset_cmp(pollfd_t *, pollfd_t *, pollfd_t *, int);
3577c478bd9Sstevel@tonic-gate extern void pcacheset_invalidate(pollstate_t *, polldat_t *);
3587c478bd9Sstevel@tonic-gate extern void pcacheset_reset_count(pollstate_t *, int);
3597c478bd9Sstevel@tonic-gate extern int pcacheset_replace(pollstate_t *);
3607c478bd9Sstevel@tonic-gate 
3617c478bd9Sstevel@tonic-gate #endif /* defined(_KERNEL) */
3627c478bd9Sstevel@tonic-gate 
3637c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
3647c478bd9Sstevel@tonic-gate }
3657c478bd9Sstevel@tonic-gate #endif
3667c478bd9Sstevel@tonic-gate 
3677c478bd9Sstevel@tonic-gate #endif /* defined(_KERNEL) || defined(_KMEMUSER) */
3687c478bd9Sstevel@tonic-gate 
3697c478bd9Sstevel@tonic-gate #endif	/* _SYS_POLL_IMPL_H */
370