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 30 extern "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 61 typedef 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 76 typedef struct squeue_set_s { 77 squeue_t *sqs_head; 78 squeue_t *sqs_default; 79 processorid_t sqs_cpuid; 80 } squeue_set_t; 81 82 typedef void (*sqproc_t)(void *, mblk_t *, void *); 83 typedef void (*sq_enter_proc_t)(squeue_t *, mblk_t *, mblk_t *, uint32_t, 84 int, uint8_t); 85 typedef void (*sq_drain_proc_t)(squeue_t *, uint_t, hrtime_t); 86 87 extern void squeue_worker_wakeup(squeue_t *); 88 extern int ip_squeue_flag; 89 90 struct 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_ctrlop_done_cv; /* cond variable for ctrl ops */ 106 clock_t sq_wait; /* lbolts to wait after a fill() */ 107 timeout_id_t sq_tid; /* timer id of pending timeout() */ 108 clock_t sq_awaken; /* time async thread was awakened */ 109 110 processorid_t sq_bind; /* processor to bind to */ 111 kthread_t *sq_worker; /* kernel thread id */ 112 kthread_t *sq_poll_thr; /* polling thread */ 113 uintptr_t sq_private[SQPRIVATE_MAX]; 114 115 squeue_t *sq_next; /* managed by squeue creator */ 116 squeue_set_t *sq_set; /* managed by squeue creator */ 117 118 pri_t sq_priority; /* squeue thread priority */ 119 120 /* Keep the debug-only fields at the end of the structure */ 121 #ifdef DEBUG 122 int sq_isintr; /* serviced by interrupt */ 123 mblk_t *sq_curmp; 124 void (*sq_curproc)(); 125 conn_t *sq_connp; 126 uchar_t sq_tag; 127 #endif 128 }; 129 130 /* 131 * State flags. 132 * Note: The MDB IP module depends on the values of these flags. 133 */ 134 #define SQS_PROC 0x00000001 /* being processed */ 135 #define SQS_WORKER 0x00000002 /* worker thread */ 136 #define SQS_ENTER 0x00000004 /* enter thread */ 137 #define SQS_FAST 0x00000008 /* enter-fast thread */ 138 139 #define SQS_USER 0x00000010 /* A non interrupt user */ 140 #define SQS_BOUND 0x00000020 /* Worker thread is bound */ 141 #define SQS_REENTER 0x00000040 /* Re entered thread */ 142 #define SQS_TMO_PROG 0x00000080 /* Timeout is being set */ 143 144 #define SQS_POLL_CAPAB 0x00000100 /* Squeue can control interrupts */ 145 #define SQS_ILL_BOUND 0x00000200 /* Squeue bound to an ill */ 146 #define SQS_GET_PKTS 0x00000400 /* Moving pkts from NIC in progress */ 147 #define SQS_DEFAULT 0x00000800 /* The default squeue for the CPU */ 148 149 #define SQS_POLLING 0x00001000 /* Squeue in polling mode */ 150 #define SQS_INTR_BLANK 0x00002000 /* Interrupt blanking capability */ 151 #define SQS_PROC_HELD 0x00004000 /* SQS_PROC is held by the caller */ 152 #define SQS_FORCE_TIMER 0x00008000 /* Schedule worker due to B/W control */ 153 154 #define SQS_POLL_CLEANUP 0x00010000 155 #define SQS_POLL_CLEANUP_DONE 0x00020000 156 #define SQS_POLL_QUIESCE 0x00040000 157 #define SQS_POLL_QUIESCE_DONE 0x00080000 158 159 #define SQS_POLL_RESTART 0x00100000 160 #define SQS_POLL_THR_QUIESCED 0x00200000 161 #define SQS_POLL_THR_RESTART 0x00400000 162 #define SQS_POLL_PROC 0x00800000 /* Poll thread processing the sq */ 163 164 #define SQS_POLL_RESTART_DONE 0x01000000 165 #define SQS_POLL_THR_QUIESCE 0x02000000 166 167 #define SQS_WORKER_THR_CONTROL \ 168 (SQS_POLL_QUIESCE | SQS_POLL_RESTART | SQS_POLL_CLEANUP) 169 170 #define SQS_POLL_THR_CONTROL \ 171 (SQS_POLL_THR_QUIESCE | SQS_POLL_THR_RESTART) 172 173 #ifdef __cplusplus 174 } 175 #endif 176 177 #endif /* _SYS_SQUEUE_IMPL_H */ 178