squeue_impl.h revision 8348:4137e18bfaf0
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21/*
22 * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23 * Use is subject to license terms.
24 */
25
26#ifndef	_SYS_SQUEUE_IMPL_H
27#define	_SYS_SQUEUE_IMPL_H
28
29#ifdef	__cplusplus
30extern "C" {
31#endif
32
33#include <sys/disp.h>
34#include <sys/types.h>
35#include <sys/squeue.h>
36#include <inet/ip.h>
37
38#define	SQ_NAMELEN 31
39
40/*
41 * SQUEUE_DEBUG: If defined as 1, special code is compiled in which records
42 *      additional information aiding debugging is recorded in squeue.
43 *
44 * SQUEUE_PROFILE: If defined as 1, special code is compiled in which collects
45 *      various squeue statistics and exports them as kstats.
46 *
47 * Ideally we would like both SQUEUE_DEBUG and SQUEUE_PROFILE to be always set,
48 * but it affects performance, so they are enabled on DEBUG kernels and disabled
49 * on non-DEBUG by default.
50 */
51#ifdef DEBUG
52#define	SQUEUE_DEBUG 1
53#define	SQUEUE_PROFILE 1
54#else
55#define	SQUEUE_DEBUG 0
56#define	SQUEUE_PROFILE 0
57#endif
58
59#define	SQUEUE_DEFAULT_PRIORITY	MAXCLSYSPRI
60
61typedef struct sqstat_s {
62	uint_t		sq_max_qlen;
63	uint_t		sq_npackets_worker;
64	uint_t		sq_npackets_intr;
65	uint_t		sq_npackets_other;
66	uint_t		sq_nqueued_intr;
67	uint_t		sq_nqueued_other;
68	uint_t		sq_ndrains_worker;
69	uint_t		sq_ndrains_intr;
70	uint_t		sq_ndrains_other;
71	hrtime_t	sq_time_worker;
72	hrtime_t	sq_time_intr;
73	hrtime_t	sq_time_other;
74} sqstat_t;
75
76typedef struct squeue_set_s {
77	squeue_t	*sqs_head;
78	squeue_t	*sqs_default;
79	processorid_t	sqs_cpuid;
80} squeue_set_t;
81
82typedef void (*sqproc_t)(void *, mblk_t *, void *);
83typedef void (*sq_enter_proc_t)(squeue_t *, mblk_t *, mblk_t *, uint32_t,
84		int, uint8_t);
85typedef void (*sq_drain_proc_t)(squeue_t *, uint_t, hrtime_t);
86
87extern void squeue_worker_wakeup(squeue_t *);
88extern int ip_squeue_flag;
89
90struct squeue_s {
91	sq_enter_proc_t	sq_enter;	/* sq_process function */
92	sq_drain_proc_t	sq_drain;	/* sq_drain function */
93	kmutex_t	sq_lock;	/* lock before using any member */
94	uint32_t	sq_state;	/* state flags and message count */
95	int		sq_count;	/* # of mblocks in squeue */
96	mblk_t		*sq_first;	/* first mblk chain or NULL */
97	mblk_t		*sq_last;	/* last mblk chain or NULL */
98	kthread_t	*sq_run;	/* Current thread processing sq */
99	ill_rx_ring_t	*sq_rx_ring;	/* The Rx ring tied to this sq */
100	ill_t		*sq_ill;	/* The ill this squeue is tied to */
101
102	clock_t		sq_curr_time;	/* Current tick (lbolt) */
103	kcondvar_t	sq_worker_cv;	/* cond var. worker thread blocks on */
104	kcondvar_t	sq_poll_cv;	/* cond variable poll_thr waits on */
105	kcondvar_t	sq_synch_cv;	/* cond var. synch thread waits on */
106	kcondvar_t	sq_ctrlop_done_cv; /* cond variable for ctrl ops */
107	clock_t		sq_wait;	/* lbolts to wait after a fill() */
108	timeout_id_t	sq_tid;		/* timer id of pending timeout() */
109	clock_t		sq_awaken;	/* time async thread was awakened */
110
111	processorid_t	sq_bind;	/* processor to bind to */
112	kthread_t	*sq_worker;	/* kernel thread id */
113	kthread_t	*sq_poll_thr;	/* polling thread */
114	uintptr_t	sq_private[SQPRIVATE_MAX];
115
116	squeue_t	*sq_next;	/* managed by squeue creator */
117	squeue_set_t	*sq_set;	/* managed by squeue creator */
118
119	pri_t		sq_priority;	/* squeue thread priority */
120
121	/* Keep the debug-only fields at the end of the structure */
122#ifdef DEBUG
123	int		sq_isintr;	/* serviced by interrupt */
124	mblk_t		*sq_curmp;
125	void		(*sq_curproc)();
126	conn_t		*sq_connp;
127	uchar_t		sq_tag;
128#endif
129};
130
131/*
132 * State flags.
133 * Note: The MDB IP module depends on the values of these flags.
134 */
135#define	SQS_PROC	0x00000001	/* being processed */
136#define	SQS_WORKER	0x00000002	/* worker thread */
137#define	SQS_ENTER	0x00000004	/* enter thread */
138#define	SQS_FAST	0x00000008	/* enter-fast thread */
139
140#define	SQS_USER	0x00000010	/* A non interrupt user */
141#define	SQS_BOUND	0x00000020	/* Worker thread is bound */
142#define	SQS_REENTER	0x00000040	/* Re entered thread */
143#define	SQS_TMO_PROG	0x00000080	/* Timeout is being set */
144
145#define	SQS_POLL_CAPAB	0x00000100	/* Squeue can control interrupts */
146#define	SQS_ILL_BOUND	0x00000200	/* Squeue bound to an ill */
147#define	SQS_GET_PKTS	0x00000400	/* Moving pkts from NIC in progress */
148#define	SQS_DEFAULT	0x00000800	/* The default squeue for the CPU */
149
150#define	SQS_POLLING	0x00001000	/* Squeue in polling mode */
151#define	SQS_INTR_BLANK	0x00002000	/* Interrupt blanking capability */
152#define	SQS_PROC_HELD	0x00004000	/* SQS_PROC is held by the caller */
153#define	SQS_FORCE_TIMER	0x00008000	/* Schedule worker due to B/W control */
154
155#define	SQS_POLL_CLEANUP	0x00010000
156#define	SQS_POLL_CLEANUP_DONE	0x00020000
157#define	SQS_POLL_QUIESCE	0x00040000
158#define	SQS_POLL_QUIESCE_DONE	0x00080000
159
160#define	SQS_POLL_RESTART	0x00100000
161#define	SQS_POLL_THR_QUIESCED	0x00200000
162#define	SQS_POLL_THR_RESTART	0x00400000
163#define	SQS_POLL_PROC		0x00800000 /* Poll thread processing the sq */
164
165#define	SQS_POLL_RESTART_DONE	0x01000000
166#define	SQS_POLL_THR_QUIESCE	0x02000000
167#define	SQS_PAUSE		0x04000000 /* The squeue has been paused */
168
169#define	SQS_WORKER_THR_CONTROL          \
170	(SQS_POLL_QUIESCE | SQS_POLL_RESTART | SQS_POLL_CLEANUP)
171
172#define	SQS_POLL_THR_CONTROL            \
173	(SQS_POLL_THR_QUIESCE | SQS_POLL_THR_RESTART)
174
175#ifdef	__cplusplus
176}
177#endif
178
179#endif	/* _SYS_SQUEUE_IMPL_H */
180