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*8275SEric Cheng * Copyright 2008 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 33*8275SEric Cheng #include <sys/disp.h> 34*8275SEric Cheng #include <sys/types.h> 350Sstevel@tonic-gate #include <sys/squeue.h> 36*8275SEric 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 59*8275SEric Cheng #define SQUEUE_DEFAULT_PRIORITY MAXCLSYSPRI 60*8275SEric 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 76*8275SEric Cheng typedef struct squeue_set_s { 77*8275SEric Cheng squeue_t *sqs_head; 78*8275SEric Cheng squeue_t *sqs_default; 79*8275SEric Cheng processorid_t sqs_cpuid; 80*8275SEric Cheng } squeue_set_t; 81*8275SEric Cheng 82*8275SEric Cheng typedef void (*sqproc_t)(void *, mblk_t *, void *); 83*8275SEric Cheng typedef void (*sq_enter_proc_t)(squeue_t *, mblk_t *, mblk_t *, uint32_t, 84*8275SEric Cheng int, uint8_t); 85*8275SEric Cheng typedef void (*sq_drain_proc_t)(squeue_t *, uint_t, hrtime_t); 86*8275SEric Cheng 87*8275SEric Cheng extern void squeue_worker_wakeup(squeue_t *); 88*8275SEric Cheng extern int ip_squeue_flag; 89*8275SEric Cheng 900Sstevel@tonic-gate struct squeue_s { 91*8275SEric Cheng sq_enter_proc_t sq_enter; /* sq_process function */ 92*8275SEric 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 */ 98*8275SEric Cheng kthread_t *sq_run; /* Current thread processing sq */ 99*8275SEric Cheng ill_rx_ring_t *sq_rx_ring; /* The Rx ring tied to this sq */ 100*8275SEric Cheng ill_t *sq_ill; /* The ill this squeue is tied to */ 101*8275SEric Cheng 102*8275SEric Cheng clock_t sq_curr_time; /* Current tick (lbolt) */ 103*8275SEric Cheng kcondvar_t sq_worker_cv; /* cond var. worker thread blocks on */ 104*8275SEric Cheng kcondvar_t sq_poll_cv; /* cond variable poll_thr waits on */ 105*8275SEric Cheng kcondvar_t sq_ctrlop_done_cv; /* cond variable for ctrl ops */ 106*8275SEric Cheng clock_t sq_wait; /* lbolts to wait after a fill() */ 107*8275SEric Cheng timeout_id_t sq_tid; /* timer id of pending timeout() */ 1080Sstevel@tonic-gate clock_t sq_awaken; /* time async thread was awakened */ 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate processorid_t sq_bind; /* processor to bind to */ 111*8275SEric Cheng kthread_t *sq_worker; /* kernel thread id */ 112*8275SEric Cheng kthread_t *sq_poll_thr; /* polling thread */ 1130Sstevel@tonic-gate uintptr_t sq_private[SQPRIVATE_MAX]; 114*8275SEric Cheng 115*8275SEric Cheng squeue_t *sq_next; /* managed by squeue creator */ 116*8275SEric Cheng squeue_set_t *sq_set; /* managed by squeue creator */ 1170Sstevel@tonic-gate 118*8275SEric Cheng pri_t sq_priority; /* squeue thread priority */ 119*8275SEric Cheng 120*8275SEric Cheng /* Keep the debug-only fields at the end of the structure */ 121*8275SEric Cheng #ifdef DEBUG 1220Sstevel@tonic-gate int sq_isintr; /* serviced by interrupt */ 1230Sstevel@tonic-gate mblk_t *sq_curmp; 1240Sstevel@tonic-gate void (*sq_curproc)(); 1250Sstevel@tonic-gate conn_t *sq_connp; 1260Sstevel@tonic-gate uchar_t sq_tag; 1270Sstevel@tonic-gate #endif 1280Sstevel@tonic-gate }; 1290Sstevel@tonic-gate 1300Sstevel@tonic-gate /* 1310Sstevel@tonic-gate * State flags. 1320Sstevel@tonic-gate * Note: The MDB IP module depends on the values of these flags. 1330Sstevel@tonic-gate */ 134*8275SEric Cheng #define SQS_PROC 0x00000001 /* being processed */ 135*8275SEric Cheng #define SQS_WORKER 0x00000002 /* worker thread */ 136*8275SEric Cheng #define SQS_ENTER 0x00000004 /* enter thread */ 137*8275SEric Cheng #define SQS_FAST 0x00000008 /* enter-fast thread */ 138*8275SEric Cheng 139*8275SEric Cheng #define SQS_USER 0x00000010 /* A non interrupt user */ 140*8275SEric Cheng #define SQS_BOUND 0x00000020 /* Worker thread is bound */ 141*8275SEric Cheng #define SQS_REENTER 0x00000040 /* Re entered thread */ 142*8275SEric Cheng #define SQS_TMO_PROG 0x00000080 /* Timeout is being set */ 143*8275SEric Cheng 144*8275SEric Cheng #define SQS_POLL_CAPAB 0x00000100 /* Squeue can control interrupts */ 145*8275SEric Cheng #define SQS_ILL_BOUND 0x00000200 /* Squeue bound to an ill */ 146*8275SEric Cheng #define SQS_GET_PKTS 0x00000400 /* Moving pkts from NIC in progress */ 147*8275SEric Cheng #define SQS_DEFAULT 0x00000800 /* The default squeue for the CPU */ 148*8275SEric Cheng 149*8275SEric Cheng #define SQS_POLLING 0x00001000 /* Squeue in polling mode */ 150*8275SEric Cheng #define SQS_INTR_BLANK 0x00002000 /* Interrupt blanking capability */ 151*8275SEric Cheng #define SQS_PROC_HELD 0x00004000 /* SQS_PROC is held by the caller */ 152*8275SEric Cheng #define SQS_FORCE_TIMER 0x00008000 /* Schedule worker due to B/W control */ 153*8275SEric Cheng 154*8275SEric Cheng #define SQS_POLL_CLEANUP 0x00010000 155*8275SEric Cheng #define SQS_POLL_CLEANUP_DONE 0x00020000 156*8275SEric Cheng #define SQS_POLL_QUIESCE 0x00040000 157*8275SEric Cheng #define SQS_POLL_QUIESCE_DONE 0x00080000 158*8275SEric Cheng 159*8275SEric Cheng #define SQS_POLL_RESTART 0x00100000 160*8275SEric Cheng #define SQS_POLL_THR_QUIESCED 0x00200000 161*8275SEric Cheng #define SQS_POLL_THR_RESTART 0x00400000 162*8275SEric Cheng #define SQS_POLL_PROC 0x00800000 /* Poll thread processing the sq */ 163*8275SEric Cheng 164*8275SEric Cheng #define SQS_POLL_RESTART_DONE 0x01000000 165*8275SEric Cheng #define SQS_POLL_THR_QUIESCE 0x02000000 166*8275SEric Cheng 167*8275SEric Cheng #define SQS_WORKER_THR_CONTROL \ 168*8275SEric Cheng (SQS_POLL_QUIESCE | SQS_POLL_RESTART | SQS_POLL_CLEANUP) 169*8275SEric Cheng 170*8275SEric Cheng #define SQS_POLL_THR_CONTROL \ 171*8275SEric Cheng (SQS_POLL_THR_QUIESCE | SQS_POLL_THR_RESTART) 1720Sstevel@tonic-gate 1730Sstevel@tonic-gate #ifdef __cplusplus 1740Sstevel@tonic-gate } 1750Sstevel@tonic-gate #endif 1760Sstevel@tonic-gate 1770Sstevel@tonic-gate #endif /* _SYS_SQUEUE_IMPL_H */ 178