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 2009 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 * Copyright 2017 Joyent, Inc. 25 */ 26 27 #ifndef _SYS_SQUEUE_IMPL_H 28 #define _SYS_SQUEUE_IMPL_H 29 30 #ifdef __cplusplus 31 extern "C" { 32 #endif 33 34 #include <sys/disp.h> 35 #include <sys/types.h> 36 #include <sys/squeue.h> 37 #include <inet/ip.h> 38 39 #define SQ_NAMELEN 31 40 41 /* 42 * SQUEUE_DEBUG: If defined as 1, special code is compiled in which records 43 * additional information aiding debugging is recorded in squeue. 44 * 45 * SQUEUE_PROFILE: If defined as 1, special code is compiled in which collects 46 * various squeue statistics and exports them as kstats. 47 * 48 * Ideally we would like both SQUEUE_DEBUG and SQUEUE_PROFILE to be always set, 49 * but it affects performance, so they are enabled on DEBUG kernels and disabled 50 * on non-DEBUG by default. 51 */ 52 #ifdef DEBUG 53 #define SQUEUE_DEBUG 1 54 #define SQUEUE_PROFILE 1 55 #else 56 #define SQUEUE_DEBUG 0 57 #define SQUEUE_PROFILE 0 58 #endif 59 60 #define SQUEUE_DEFAULT_PRIORITY MAXCLSYSPRI 61 62 typedef struct sqstat_s { 63 uint_t sq_max_qlen; 64 uint_t sq_npackets_worker; 65 uint_t sq_npackets_intr; 66 uint_t sq_npackets_other; 67 uint_t sq_nqueued_intr; 68 uint_t sq_nqueued_other; 69 uint_t sq_ndrains_worker; 70 uint_t sq_ndrains_intr; 71 uint_t sq_ndrains_other; 72 hrtime_t sq_time_worker; 73 hrtime_t sq_time_intr; 74 hrtime_t sq_time_other; 75 } sqstat_t; 76 77 typedef struct squeue_set_s { 78 squeue_t *sqs_head; 79 squeue_t *sqs_default; 80 processorid_t sqs_cpuid; 81 } squeue_set_t; 82 83 typedef void (*sqproc_t)(void *, mblk_t *, void *, struct ip_recv_attr_s *); 84 typedef void (*sq_enter_proc_t)(squeue_t *, mblk_t *, mblk_t *, uint32_t, 85 struct ip_recv_attr_s *, int, uint8_t); 86 typedef void (*sq_drain_proc_t)(squeue_t *, uint_t, hrtime_t); 87 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 hrtime_t sq_awoken; /* time of worker wake req */ 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 108 processorid_t sq_bind; /* processor to bind to */ 109 kthread_t *sq_worker; /* kernel thread id */ 110 kthread_t *sq_poll_thr; /* polling thread */ 111 uintptr_t sq_private[SQPRIVATE_MAX]; 112 113 squeue_t *sq_next; /* managed by squeue creator */ 114 squeue_set_t *sq_set; /* managed by squeue creator */ 115 116 pri_t sq_priority; /* squeue thread priority */ 117 118 /* Keep the debug-only fields at the end of the structure */ 119 #ifdef DEBUG 120 int sq_isintr; /* serviced by interrupt */ 121 mblk_t *sq_curmp; 122 void (*sq_curproc)(); 123 conn_t *sq_connp; 124 uchar_t sq_tag; 125 #endif 126 }; 127 128 /* 129 * State flags. 130 * Note: The MDB IP module depends on the values of these flags. 131 */ 132 #define SQS_PROC 0x00000001 /* being processed */ 133 #define SQS_WORKER 0x00000002 /* worker thread */ 134 #define SQS_ENTER 0x00000004 /* enter thread */ 135 #define SQS_FAST 0x00000008 /* enter-fast thread */ 136 137 #define SQS_USER 0x00000010 /* A non interrupt user */ 138 #define SQS_BOUND 0x00000020 /* Worker thread is bound */ 139 #define SQS_REENTER 0x00000040 /* Re entered thread */ 140 141 #define SQS_POLL_CAPAB 0x00000100 /* Squeue can control interrupts */ 142 #define SQS_ILL_BOUND 0x00000200 /* Squeue bound to an ill */ 143 #define SQS_GET_PKTS 0x00000400 /* Moving pkts from NIC in progress */ 144 #define SQS_DEFAULT 0x00000800 /* The default squeue for the CPU */ 145 146 #define SQS_POLLING 0x00001000 /* Squeue in polling mode */ 147 #define SQS_INTR_BLANK 0x00002000 /* Interrupt blanking capability */ 148 #define SQS_PROC_HELD 0x00004000 /* SQS_PROC is held by the caller */ 149 #define SQS_FORCE_TIMER 0x00008000 /* Schedule worker due to B/W control */ 150 151 #define SQS_POLL_CLEANUP 0x00010000 152 #define SQS_POLL_CLEANUP_DONE 0x00020000 153 #define SQS_POLL_QUIESCE 0x00040000 154 #define SQS_POLL_QUIESCE_DONE 0x00080000 155 156 #define SQS_POLL_RESTART 0x00100000 157 #define SQS_POLL_THR_QUIESCED 0x00200000 158 #define SQS_POLL_THR_RESTART 0x00400000 159 #define SQS_POLL_PROC 0x00800000 /* Poll thread processing the sq */ 160 161 #define SQS_POLL_RESTART_DONE 0x01000000 162 #define SQS_POLL_THR_QUIESCE 0x02000000 163 #define SQS_PAUSE 0x04000000 /* The squeue has been paused */ 164 165 #define SQS_WORKER_THR_CONTROL \ 166 (SQS_POLL_QUIESCE | SQS_POLL_RESTART | SQS_POLL_CLEANUP) 167 168 #define SQS_POLL_THR_CONTROL \ 169 (SQS_POLL_THR_QUIESCE | SQS_POLL_THR_RESTART) 170 171 #ifdef __cplusplus 172 } 173 #endif 174 175 #endif /* _SYS_SQUEUE_IMPL_H */ 176