xref: /onnv-gate/usr/src/uts/common/sys/squeue_impl.h (revision 11042:2d6e217af1b4)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
52722Sjohnlev  * Common Development and Distribution License (the "License").
62722Sjohnlev  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*11042SErik.Nordmark@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef	_SYS_SQUEUE_IMPL_H
270Sstevel@tonic-gate #define	_SYS_SQUEUE_IMPL_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #ifdef	__cplusplus
300Sstevel@tonic-gate extern "C" {
310Sstevel@tonic-gate #endif
320Sstevel@tonic-gate 
338275SEric Cheng #include <sys/disp.h>
348275SEric Cheng #include <sys/types.h>
350Sstevel@tonic-gate #include <sys/squeue.h>
368275SEric Cheng #include <inet/ip.h>
370Sstevel@tonic-gate 
380Sstevel@tonic-gate #define	SQ_NAMELEN 31
390Sstevel@tonic-gate 
402722Sjohnlev /*
412722Sjohnlev  * SQUEUE_DEBUG: If defined as 1, special code is compiled in which records
422722Sjohnlev  *      additional information aiding debugging is recorded in squeue.
432722Sjohnlev  *
442722Sjohnlev  * SQUEUE_PROFILE: If defined as 1, special code is compiled in which collects
452722Sjohnlev  *      various squeue statistics and exports them as kstats.
462722Sjohnlev  *
472722Sjohnlev  * Ideally we would like both SQUEUE_DEBUG and SQUEUE_PROFILE to be always set,
482722Sjohnlev  * but it affects performance, so they are enabled on DEBUG kernels and disabled
492722Sjohnlev  * on non-DEBUG by default.
502722Sjohnlev  */
512722Sjohnlev #ifdef DEBUG
522722Sjohnlev #define	SQUEUE_DEBUG 1
532722Sjohnlev #define	SQUEUE_PROFILE 1
542722Sjohnlev #else
552722Sjohnlev #define	SQUEUE_DEBUG 0
562722Sjohnlev #define	SQUEUE_PROFILE 0
572722Sjohnlev #endif
582722Sjohnlev 
598275SEric Cheng #define	SQUEUE_DEFAULT_PRIORITY	MAXCLSYSPRI
608275SEric Cheng 
610Sstevel@tonic-gate typedef struct sqstat_s {
620Sstevel@tonic-gate 	uint_t		sq_max_qlen;
630Sstevel@tonic-gate 	uint_t		sq_npackets_worker;
640Sstevel@tonic-gate 	uint_t		sq_npackets_intr;
650Sstevel@tonic-gate 	uint_t		sq_npackets_other;
660Sstevel@tonic-gate 	uint_t		sq_nqueued_intr;
670Sstevel@tonic-gate 	uint_t		sq_nqueued_other;
680Sstevel@tonic-gate 	uint_t		sq_ndrains_worker;
690Sstevel@tonic-gate 	uint_t		sq_ndrains_intr;
700Sstevel@tonic-gate 	uint_t		sq_ndrains_other;
710Sstevel@tonic-gate 	hrtime_t	sq_time_worker;
720Sstevel@tonic-gate 	hrtime_t	sq_time_intr;
730Sstevel@tonic-gate 	hrtime_t	sq_time_other;
740Sstevel@tonic-gate } sqstat_t;
750Sstevel@tonic-gate 
768275SEric Cheng typedef struct squeue_set_s {
778275SEric Cheng 	squeue_t	*sqs_head;
788275SEric Cheng 	squeue_t	*sqs_default;
798275SEric Cheng 	processorid_t	sqs_cpuid;
808275SEric Cheng } squeue_set_t;
818275SEric Cheng 
82*11042SErik.Nordmark@Sun.COM typedef void (*sqproc_t)(void *, mblk_t *, void *, struct ip_recv_attr_s *);
838275SEric Cheng typedef void (*sq_enter_proc_t)(squeue_t *, mblk_t *, mblk_t *, uint32_t,
84*11042SErik.Nordmark@Sun.COM 	    struct ip_recv_attr_s *, int, uint8_t);
858275SEric Cheng typedef void (*sq_drain_proc_t)(squeue_t *, uint_t, hrtime_t);
868275SEric Cheng 
878275SEric Cheng extern void squeue_worker_wakeup(squeue_t *);
888275SEric Cheng extern int ip_squeue_flag;
898275SEric Cheng 
900Sstevel@tonic-gate struct squeue_s {
918275SEric Cheng 	sq_enter_proc_t	sq_enter;	/* sq_process function */
928275SEric Cheng 	sq_drain_proc_t	sq_drain;	/* sq_drain function */
930Sstevel@tonic-gate 	kmutex_t	sq_lock;	/* lock before using any member */
940Sstevel@tonic-gate 	uint32_t	sq_state;	/* state flags and message count */
950Sstevel@tonic-gate 	int		sq_count;	/* # of mblocks in squeue */
960Sstevel@tonic-gate 	mblk_t		*sq_first;	/* first mblk chain or NULL */
970Sstevel@tonic-gate 	mblk_t		*sq_last;	/* last mblk chain or NULL */
988275SEric Cheng 	kthread_t	*sq_run;	/* Current thread processing sq */
998275SEric Cheng 	ill_rx_ring_t	*sq_rx_ring;	/* The Rx ring tied to this sq */
1008275SEric Cheng 	ill_t		*sq_ill;	/* The ill this squeue is tied to */
1018275SEric Cheng 
1028275SEric Cheng 	clock_t		sq_curr_time;	/* Current tick (lbolt) */
1038275SEric Cheng 	kcondvar_t	sq_worker_cv;	/* cond var. worker thread blocks on */
1048275SEric Cheng 	kcondvar_t	sq_poll_cv;	/* cond variable poll_thr waits on */
1058348SEric.Yu@Sun.COM 	kcondvar_t	sq_synch_cv;	/* cond var. synch thread waits on */
1068275SEric Cheng 	kcondvar_t	sq_ctrlop_done_cv; /* cond variable for ctrl ops */
1078275SEric Cheng 	clock_t		sq_wait;	/* lbolts to wait after a fill() */
1088275SEric Cheng 	timeout_id_t	sq_tid;		/* timer id of pending timeout() */
1090Sstevel@tonic-gate 	clock_t		sq_awaken;	/* time async thread was awakened */
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate 	processorid_t	sq_bind;	/* processor to bind to */
1128275SEric Cheng 	kthread_t	*sq_worker;	/* kernel thread id */
1138275SEric Cheng 	kthread_t	*sq_poll_thr;	/* polling thread */
1140Sstevel@tonic-gate 	uintptr_t	sq_private[SQPRIVATE_MAX];
1158275SEric Cheng 
1168275SEric Cheng 	squeue_t	*sq_next;	/* managed by squeue creator */
1178275SEric Cheng 	squeue_set_t	*sq_set;	/* managed by squeue creator */
1180Sstevel@tonic-gate 
1198275SEric Cheng 	pri_t		sq_priority;	/* squeue thread priority */
1208275SEric Cheng 
1218275SEric Cheng 	/* Keep the debug-only fields at the end of the structure */
1228275SEric Cheng #ifdef DEBUG
1230Sstevel@tonic-gate 	int		sq_isintr;	/* serviced by interrupt */
1240Sstevel@tonic-gate 	mblk_t		*sq_curmp;
1250Sstevel@tonic-gate 	void		(*sq_curproc)();
1260Sstevel@tonic-gate 	conn_t		*sq_connp;
1270Sstevel@tonic-gate 	uchar_t		sq_tag;
1280Sstevel@tonic-gate #endif
1290Sstevel@tonic-gate };
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate /*
1320Sstevel@tonic-gate  * State flags.
1330Sstevel@tonic-gate  * Note: The MDB IP module depends on the values of these flags.
1340Sstevel@tonic-gate  */
1358275SEric Cheng #define	SQS_PROC	0x00000001	/* being processed */
1368275SEric Cheng #define	SQS_WORKER	0x00000002	/* worker thread */
1378275SEric Cheng #define	SQS_ENTER	0x00000004	/* enter thread */
1388275SEric Cheng #define	SQS_FAST	0x00000008	/* enter-fast thread */
1398275SEric Cheng 
1408275SEric Cheng #define	SQS_USER	0x00000010	/* A non interrupt user */
1418275SEric Cheng #define	SQS_BOUND	0x00000020	/* Worker thread is bound */
1428275SEric Cheng #define	SQS_REENTER	0x00000040	/* Re entered thread */
1438275SEric Cheng #define	SQS_TMO_PROG	0x00000080	/* Timeout is being set */
1448275SEric Cheng 
1458275SEric Cheng #define	SQS_POLL_CAPAB	0x00000100	/* Squeue can control interrupts */
1468275SEric Cheng #define	SQS_ILL_BOUND	0x00000200	/* Squeue bound to an ill */
1478275SEric Cheng #define	SQS_GET_PKTS	0x00000400	/* Moving pkts from NIC in progress */
1488275SEric Cheng #define	SQS_DEFAULT	0x00000800	/* The default squeue for the CPU */
1498275SEric Cheng 
1508275SEric Cheng #define	SQS_POLLING	0x00001000	/* Squeue in polling mode */
1518275SEric Cheng #define	SQS_INTR_BLANK	0x00002000	/* Interrupt blanking capability */
1528275SEric Cheng #define	SQS_PROC_HELD	0x00004000	/* SQS_PROC is held by the caller */
1538275SEric Cheng #define	SQS_FORCE_TIMER	0x00008000	/* Schedule worker due to B/W control */
1548275SEric Cheng 
1558275SEric Cheng #define	SQS_POLL_CLEANUP	0x00010000
1568275SEric Cheng #define	SQS_POLL_CLEANUP_DONE	0x00020000
1578275SEric Cheng #define	SQS_POLL_QUIESCE	0x00040000
1588275SEric Cheng #define	SQS_POLL_QUIESCE_DONE	0x00080000
1598275SEric Cheng 
1608275SEric Cheng #define	SQS_POLL_RESTART	0x00100000
1618275SEric Cheng #define	SQS_POLL_THR_QUIESCED	0x00200000
1628275SEric Cheng #define	SQS_POLL_THR_RESTART	0x00400000
1638275SEric Cheng #define	SQS_POLL_PROC		0x00800000 /* Poll thread processing the sq */
1648275SEric Cheng 
1658275SEric Cheng #define	SQS_POLL_RESTART_DONE	0x01000000
1668275SEric Cheng #define	SQS_POLL_THR_QUIESCE	0x02000000
1678348SEric.Yu@Sun.COM #define	SQS_PAUSE		0x04000000 /* The squeue has been paused */
1688275SEric Cheng 
1698275SEric Cheng #define	SQS_WORKER_THR_CONTROL          \
1708275SEric Cheng 	(SQS_POLL_QUIESCE | SQS_POLL_RESTART | SQS_POLL_CLEANUP)
1718275SEric Cheng 
1728275SEric Cheng #define	SQS_POLL_THR_CONTROL            \
1738275SEric Cheng 	(SQS_POLL_THR_QUIESCE | SQS_POLL_THR_RESTART)
1740Sstevel@tonic-gate 
1750Sstevel@tonic-gate #ifdef	__cplusplus
1760Sstevel@tonic-gate }
1770Sstevel@tonic-gate #endif
1780Sstevel@tonic-gate 
1790Sstevel@tonic-gate #endif	/* _SYS_SQUEUE_IMPL_H */
180