xref: /titanic_51/usr/src/uts/common/sys/squeue_impl.h (revision bd670b35a010421b6e1a5536c34453a827007c81)
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
5e824d57fSjohnlev  * Common Development and Distribution License (the "License").
6e824d57fSjohnlev  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*bd670b35SErik Nordmark  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef	_SYS_SQUEUE_IMPL_H
277c478bd9Sstevel@tonic-gate #define	_SYS_SQUEUE_IMPL_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
307c478bd9Sstevel@tonic-gate extern "C" {
317c478bd9Sstevel@tonic-gate #endif
327c478bd9Sstevel@tonic-gate 
33da14cebeSEric Cheng #include <sys/disp.h>
34da14cebeSEric Cheng #include <sys/types.h>
357c478bd9Sstevel@tonic-gate #include <sys/squeue.h>
36da14cebeSEric Cheng #include <inet/ip.h>
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #define	SQ_NAMELEN 31
397c478bd9Sstevel@tonic-gate 
40e824d57fSjohnlev /*
41e824d57fSjohnlev  * SQUEUE_DEBUG: If defined as 1, special code is compiled in which records
42e824d57fSjohnlev  *      additional information aiding debugging is recorded in squeue.
43e824d57fSjohnlev  *
44e824d57fSjohnlev  * SQUEUE_PROFILE: If defined as 1, special code is compiled in which collects
45e824d57fSjohnlev  *      various squeue statistics and exports them as kstats.
46e824d57fSjohnlev  *
47e824d57fSjohnlev  * Ideally we would like both SQUEUE_DEBUG and SQUEUE_PROFILE to be always set,
48e824d57fSjohnlev  * but it affects performance, so they are enabled on DEBUG kernels and disabled
49e824d57fSjohnlev  * on non-DEBUG by default.
50e824d57fSjohnlev  */
51e824d57fSjohnlev #ifdef DEBUG
52e824d57fSjohnlev #define	SQUEUE_DEBUG 1
53e824d57fSjohnlev #define	SQUEUE_PROFILE 1
54e824d57fSjohnlev #else
55e824d57fSjohnlev #define	SQUEUE_DEBUG 0
56e824d57fSjohnlev #define	SQUEUE_PROFILE 0
57e824d57fSjohnlev #endif
58e824d57fSjohnlev 
59da14cebeSEric Cheng #define	SQUEUE_DEFAULT_PRIORITY	MAXCLSYSPRI
60da14cebeSEric Cheng 
617c478bd9Sstevel@tonic-gate typedef struct sqstat_s {
627c478bd9Sstevel@tonic-gate 	uint_t		sq_max_qlen;
637c478bd9Sstevel@tonic-gate 	uint_t		sq_npackets_worker;
647c478bd9Sstevel@tonic-gate 	uint_t		sq_npackets_intr;
657c478bd9Sstevel@tonic-gate 	uint_t		sq_npackets_other;
667c478bd9Sstevel@tonic-gate 	uint_t		sq_nqueued_intr;
677c478bd9Sstevel@tonic-gate 	uint_t		sq_nqueued_other;
687c478bd9Sstevel@tonic-gate 	uint_t		sq_ndrains_worker;
697c478bd9Sstevel@tonic-gate 	uint_t		sq_ndrains_intr;
707c478bd9Sstevel@tonic-gate 	uint_t		sq_ndrains_other;
717c478bd9Sstevel@tonic-gate 	hrtime_t	sq_time_worker;
727c478bd9Sstevel@tonic-gate 	hrtime_t	sq_time_intr;
737c478bd9Sstevel@tonic-gate 	hrtime_t	sq_time_other;
747c478bd9Sstevel@tonic-gate } sqstat_t;
757c478bd9Sstevel@tonic-gate 
76da14cebeSEric Cheng typedef struct squeue_set_s {
77da14cebeSEric Cheng 	squeue_t	*sqs_head;
78da14cebeSEric Cheng 	squeue_t	*sqs_default;
79da14cebeSEric Cheng 	processorid_t	sqs_cpuid;
80da14cebeSEric Cheng } squeue_set_t;
81da14cebeSEric Cheng 
82*bd670b35SErik Nordmark typedef void (*sqproc_t)(void *, mblk_t *, void *, struct ip_recv_attr_s *);
83da14cebeSEric Cheng typedef void (*sq_enter_proc_t)(squeue_t *, mblk_t *, mblk_t *, uint32_t,
84*bd670b35SErik Nordmark 	    struct ip_recv_attr_s *, int, uint8_t);
85da14cebeSEric Cheng typedef void (*sq_drain_proc_t)(squeue_t *, uint_t, hrtime_t);
86da14cebeSEric Cheng 
87da14cebeSEric Cheng extern void squeue_worker_wakeup(squeue_t *);
88da14cebeSEric Cheng extern int ip_squeue_flag;
89da14cebeSEric Cheng 
907c478bd9Sstevel@tonic-gate struct squeue_s {
91da14cebeSEric Cheng 	sq_enter_proc_t	sq_enter;	/* sq_process function */
92da14cebeSEric Cheng 	sq_drain_proc_t	sq_drain;	/* sq_drain function */
937c478bd9Sstevel@tonic-gate 	kmutex_t	sq_lock;	/* lock before using any member */
947c478bd9Sstevel@tonic-gate 	uint32_t	sq_state;	/* state flags and message count */
957c478bd9Sstevel@tonic-gate 	int		sq_count;	/* # of mblocks in squeue */
967c478bd9Sstevel@tonic-gate 	mblk_t		*sq_first;	/* first mblk chain or NULL */
977c478bd9Sstevel@tonic-gate 	mblk_t		*sq_last;	/* last mblk chain or NULL */
987c478bd9Sstevel@tonic-gate 	kthread_t	*sq_run;	/* Current thread processing sq */
99da14cebeSEric Cheng 	ill_rx_ring_t	*sq_rx_ring;	/* The Rx ring tied to this sq */
100da14cebeSEric Cheng 	ill_t		*sq_ill;	/* The ill this squeue is tied to */
101da14cebeSEric Cheng 
102da14cebeSEric Cheng 	clock_t		sq_curr_time;	/* Current tick (lbolt) */
103da14cebeSEric Cheng 	kcondvar_t	sq_worker_cv;	/* cond var. worker thread blocks on */
104da14cebeSEric Cheng 	kcondvar_t	sq_poll_cv;	/* cond variable poll_thr waits on */
1050f1702c5SYu Xiangning 	kcondvar_t	sq_synch_cv;	/* cond var. synch thread waits on */
106da14cebeSEric Cheng 	kcondvar_t	sq_ctrlop_done_cv; /* cond variable for ctrl ops */
107da14cebeSEric Cheng 	clock_t		sq_wait;	/* lbolts to wait after a fill() */
108da14cebeSEric Cheng 	timeout_id_t	sq_tid;		/* timer id of pending timeout() */
109da14cebeSEric Cheng 	clock_t		sq_awaken;	/* time async thread was awakened */
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate 	processorid_t	sq_bind;	/* processor to bind to */
1127c478bd9Sstevel@tonic-gate 	kthread_t	*sq_worker;	/* kernel thread id */
113da14cebeSEric Cheng 	kthread_t	*sq_poll_thr;	/* polling thread */
114da14cebeSEric Cheng 	uintptr_t	sq_private[SQPRIVATE_MAX];
1157c478bd9Sstevel@tonic-gate 
116da14cebeSEric Cheng 	squeue_t	*sq_next;	/* managed by squeue creator */
117da14cebeSEric Cheng 	squeue_set_t	*sq_set;	/* managed by squeue creator */
118da14cebeSEric Cheng 
119da14cebeSEric Cheng 	pri_t		sq_priority;	/* squeue thread priority */
120da14cebeSEric Cheng 
121da14cebeSEric Cheng 	/* Keep the debug-only fields at the end of the structure */
122da14cebeSEric Cheng #ifdef DEBUG
1237c478bd9Sstevel@tonic-gate 	int		sq_isintr;	/* serviced by interrupt */
1247c478bd9Sstevel@tonic-gate 	mblk_t		*sq_curmp;
1257c478bd9Sstevel@tonic-gate 	void		(*sq_curproc)();
1267c478bd9Sstevel@tonic-gate 	conn_t		*sq_connp;
1277c478bd9Sstevel@tonic-gate 	uchar_t		sq_tag;
1287c478bd9Sstevel@tonic-gate #endif
1297c478bd9Sstevel@tonic-gate };
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate /*
1327c478bd9Sstevel@tonic-gate  * State flags.
1337c478bd9Sstevel@tonic-gate  * Note: The MDB IP module depends on the values of these flags.
1347c478bd9Sstevel@tonic-gate  */
135da14cebeSEric Cheng #define	SQS_PROC	0x00000001	/* being processed */
136da14cebeSEric Cheng #define	SQS_WORKER	0x00000002	/* worker thread */
137da14cebeSEric Cheng #define	SQS_ENTER	0x00000004	/* enter thread */
138da14cebeSEric Cheng #define	SQS_FAST	0x00000008	/* enter-fast thread */
139da14cebeSEric Cheng 
140da14cebeSEric Cheng #define	SQS_USER	0x00000010	/* A non interrupt user */
141da14cebeSEric Cheng #define	SQS_BOUND	0x00000020	/* Worker thread is bound */
142da14cebeSEric Cheng #define	SQS_REENTER	0x00000040	/* Re entered thread */
143da14cebeSEric Cheng #define	SQS_TMO_PROG	0x00000080	/* Timeout is being set */
144da14cebeSEric Cheng 
145da14cebeSEric Cheng #define	SQS_POLL_CAPAB	0x00000100	/* Squeue can control interrupts */
146da14cebeSEric Cheng #define	SQS_ILL_BOUND	0x00000200	/* Squeue bound to an ill */
147da14cebeSEric Cheng #define	SQS_GET_PKTS	0x00000400	/* Moving pkts from NIC in progress */
148da14cebeSEric Cheng #define	SQS_DEFAULT	0x00000800	/* The default squeue for the CPU */
149da14cebeSEric Cheng 
150da14cebeSEric Cheng #define	SQS_POLLING	0x00001000	/* Squeue in polling mode */
151da14cebeSEric Cheng #define	SQS_INTR_BLANK	0x00002000	/* Interrupt blanking capability */
152da14cebeSEric Cheng #define	SQS_PROC_HELD	0x00004000	/* SQS_PROC is held by the caller */
153da14cebeSEric Cheng #define	SQS_FORCE_TIMER	0x00008000	/* Schedule worker due to B/W control */
154da14cebeSEric Cheng 
155da14cebeSEric Cheng #define	SQS_POLL_CLEANUP	0x00010000
156da14cebeSEric Cheng #define	SQS_POLL_CLEANUP_DONE	0x00020000
157da14cebeSEric Cheng #define	SQS_POLL_QUIESCE	0x00040000
158da14cebeSEric Cheng #define	SQS_POLL_QUIESCE_DONE	0x00080000
159da14cebeSEric Cheng 
160da14cebeSEric Cheng #define	SQS_POLL_RESTART	0x00100000
161da14cebeSEric Cheng #define	SQS_POLL_THR_QUIESCED	0x00200000
162da14cebeSEric Cheng #define	SQS_POLL_THR_RESTART	0x00400000
163da14cebeSEric Cheng #define	SQS_POLL_PROC		0x00800000 /* Poll thread processing the sq */
164da14cebeSEric Cheng 
165da14cebeSEric Cheng #define	SQS_POLL_RESTART_DONE	0x01000000
166da14cebeSEric Cheng #define	SQS_POLL_THR_QUIESCE	0x02000000
1670f1702c5SYu Xiangning #define	SQS_PAUSE		0x04000000 /* The squeue has been paused */
168da14cebeSEric Cheng 
169da14cebeSEric Cheng #define	SQS_WORKER_THR_CONTROL          \
170da14cebeSEric Cheng 	(SQS_POLL_QUIESCE | SQS_POLL_RESTART | SQS_POLL_CLEANUP)
171da14cebeSEric Cheng 
172da14cebeSEric Cheng #define	SQS_POLL_THR_CONTROL            \
173da14cebeSEric Cheng 	(SQS_POLL_THR_QUIESCE | SQS_POLL_THR_RESTART)
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1767c478bd9Sstevel@tonic-gate }
1777c478bd9Sstevel@tonic-gate #endif
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate #endif	/* _SYS_SQUEUE_IMPL_H */
180