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 /* 22bd670b35SErik Nordmark * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 24*233fee3fSPatrick Mooney * Copyright 2017 Joyent, Inc. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #ifndef _SYS_SQUEUE_IMPL_H 287c478bd9Sstevel@tonic-gate #define _SYS_SQUEUE_IMPL_H 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #ifdef __cplusplus 317c478bd9Sstevel@tonic-gate extern "C" { 327c478bd9Sstevel@tonic-gate #endif 337c478bd9Sstevel@tonic-gate 34da14cebeSEric Cheng #include <sys/disp.h> 35da14cebeSEric Cheng #include <sys/types.h> 367c478bd9Sstevel@tonic-gate #include <sys/squeue.h> 37da14cebeSEric Cheng #include <inet/ip.h> 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate #define SQ_NAMELEN 31 407c478bd9Sstevel@tonic-gate 41e824d57fSjohnlev /* 42e824d57fSjohnlev * SQUEUE_DEBUG: If defined as 1, special code is compiled in which records 43e824d57fSjohnlev * additional information aiding debugging is recorded in squeue. 44e824d57fSjohnlev * 45e824d57fSjohnlev * SQUEUE_PROFILE: If defined as 1, special code is compiled in which collects 46e824d57fSjohnlev * various squeue statistics and exports them as kstats. 47e824d57fSjohnlev * 48e824d57fSjohnlev * Ideally we would like both SQUEUE_DEBUG and SQUEUE_PROFILE to be always set, 49e824d57fSjohnlev * but it affects performance, so they are enabled on DEBUG kernels and disabled 50e824d57fSjohnlev * on non-DEBUG by default. 51e824d57fSjohnlev */ 52e824d57fSjohnlev #ifdef DEBUG 53e824d57fSjohnlev #define SQUEUE_DEBUG 1 54e824d57fSjohnlev #define SQUEUE_PROFILE 1 55e824d57fSjohnlev #else 56e824d57fSjohnlev #define SQUEUE_DEBUG 0 57e824d57fSjohnlev #define SQUEUE_PROFILE 0 58e824d57fSjohnlev #endif 59e824d57fSjohnlev 60da14cebeSEric Cheng #define SQUEUE_DEFAULT_PRIORITY MAXCLSYSPRI 61da14cebeSEric Cheng 627c478bd9Sstevel@tonic-gate typedef struct sqstat_s { 637c478bd9Sstevel@tonic-gate uint_t sq_max_qlen; 647c478bd9Sstevel@tonic-gate uint_t sq_npackets_worker; 657c478bd9Sstevel@tonic-gate uint_t sq_npackets_intr; 667c478bd9Sstevel@tonic-gate uint_t sq_npackets_other; 677c478bd9Sstevel@tonic-gate uint_t sq_nqueued_intr; 687c478bd9Sstevel@tonic-gate uint_t sq_nqueued_other; 697c478bd9Sstevel@tonic-gate uint_t sq_ndrains_worker; 707c478bd9Sstevel@tonic-gate uint_t sq_ndrains_intr; 717c478bd9Sstevel@tonic-gate uint_t sq_ndrains_other; 727c478bd9Sstevel@tonic-gate hrtime_t sq_time_worker; 737c478bd9Sstevel@tonic-gate hrtime_t sq_time_intr; 747c478bd9Sstevel@tonic-gate hrtime_t sq_time_other; 757c478bd9Sstevel@tonic-gate } sqstat_t; 767c478bd9Sstevel@tonic-gate 77da14cebeSEric Cheng typedef struct squeue_set_s { 78da14cebeSEric Cheng squeue_t *sqs_head; 79da14cebeSEric Cheng squeue_t *sqs_default; 80da14cebeSEric Cheng processorid_t sqs_cpuid; 81da14cebeSEric Cheng } squeue_set_t; 82da14cebeSEric Cheng 83bd670b35SErik Nordmark typedef void (*sqproc_t)(void *, mblk_t *, void *, struct ip_recv_attr_s *); 84da14cebeSEric Cheng typedef void (*sq_enter_proc_t)(squeue_t *, mblk_t *, mblk_t *, uint32_t, 85bd670b35SErik Nordmark struct ip_recv_attr_s *, int, uint8_t); 86da14cebeSEric Cheng typedef void (*sq_drain_proc_t)(squeue_t *, uint_t, hrtime_t); 87da14cebeSEric Cheng 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 102*233fee3fSPatrick Mooney hrtime_t sq_awoken; /* time of worker wake req */ 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 */ 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate processorid_t sq_bind; /* processor to bind to */ 1097c478bd9Sstevel@tonic-gate kthread_t *sq_worker; /* kernel thread id */ 110da14cebeSEric Cheng kthread_t *sq_poll_thr; /* polling thread */ 111da14cebeSEric Cheng uintptr_t sq_private[SQPRIVATE_MAX]; 1127c478bd9Sstevel@tonic-gate 113da14cebeSEric Cheng squeue_t *sq_next; /* managed by squeue creator */ 114da14cebeSEric Cheng squeue_set_t *sq_set; /* managed by squeue creator */ 115da14cebeSEric Cheng 116da14cebeSEric Cheng pri_t sq_priority; /* squeue thread priority */ 117da14cebeSEric Cheng 118da14cebeSEric Cheng /* Keep the debug-only fields at the end of the structure */ 119da14cebeSEric Cheng #ifdef DEBUG 1207c478bd9Sstevel@tonic-gate int sq_isintr; /* serviced by interrupt */ 1217c478bd9Sstevel@tonic-gate mblk_t *sq_curmp; 1227c478bd9Sstevel@tonic-gate void (*sq_curproc)(); 1237c478bd9Sstevel@tonic-gate conn_t *sq_connp; 1247c478bd9Sstevel@tonic-gate uchar_t sq_tag; 1257c478bd9Sstevel@tonic-gate #endif 1267c478bd9Sstevel@tonic-gate }; 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate /* 1297c478bd9Sstevel@tonic-gate * State flags. 1307c478bd9Sstevel@tonic-gate * Note: The MDB IP module depends on the values of these flags. 1317c478bd9Sstevel@tonic-gate */ 132da14cebeSEric Cheng #define SQS_PROC 0x00000001 /* being processed */ 133da14cebeSEric Cheng #define SQS_WORKER 0x00000002 /* worker thread */ 134da14cebeSEric Cheng #define SQS_ENTER 0x00000004 /* enter thread */ 135da14cebeSEric Cheng #define SQS_FAST 0x00000008 /* enter-fast thread */ 136da14cebeSEric Cheng 137da14cebeSEric Cheng #define SQS_USER 0x00000010 /* A non interrupt user */ 138da14cebeSEric Cheng #define SQS_BOUND 0x00000020 /* Worker thread is bound */ 139da14cebeSEric Cheng #define SQS_REENTER 0x00000040 /* Re entered thread */ 140da14cebeSEric Cheng 141da14cebeSEric Cheng #define SQS_POLL_CAPAB 0x00000100 /* Squeue can control interrupts */ 142da14cebeSEric Cheng #define SQS_ILL_BOUND 0x00000200 /* Squeue bound to an ill */ 143da14cebeSEric Cheng #define SQS_GET_PKTS 0x00000400 /* Moving pkts from NIC in progress */ 144da14cebeSEric Cheng #define SQS_DEFAULT 0x00000800 /* The default squeue for the CPU */ 145da14cebeSEric Cheng 146da14cebeSEric Cheng #define SQS_POLLING 0x00001000 /* Squeue in polling mode */ 147da14cebeSEric Cheng #define SQS_INTR_BLANK 0x00002000 /* Interrupt blanking capability */ 148da14cebeSEric Cheng #define SQS_PROC_HELD 0x00004000 /* SQS_PROC is held by the caller */ 149da14cebeSEric Cheng #define SQS_FORCE_TIMER 0x00008000 /* Schedule worker due to B/W control */ 150da14cebeSEric Cheng 151da14cebeSEric Cheng #define SQS_POLL_CLEANUP 0x00010000 152da14cebeSEric Cheng #define SQS_POLL_CLEANUP_DONE 0x00020000 153da14cebeSEric Cheng #define SQS_POLL_QUIESCE 0x00040000 154da14cebeSEric Cheng #define SQS_POLL_QUIESCE_DONE 0x00080000 155da14cebeSEric Cheng 156da14cebeSEric Cheng #define SQS_POLL_RESTART 0x00100000 157da14cebeSEric Cheng #define SQS_POLL_THR_QUIESCED 0x00200000 158da14cebeSEric Cheng #define SQS_POLL_THR_RESTART 0x00400000 159da14cebeSEric Cheng #define SQS_POLL_PROC 0x00800000 /* Poll thread processing the sq */ 160da14cebeSEric Cheng 161da14cebeSEric Cheng #define SQS_POLL_RESTART_DONE 0x01000000 162da14cebeSEric Cheng #define SQS_POLL_THR_QUIESCE 0x02000000 1630f1702c5SYu Xiangning #define SQS_PAUSE 0x04000000 /* The squeue has been paused */ 164da14cebeSEric Cheng 165da14cebeSEric Cheng #define SQS_WORKER_THR_CONTROL \ 166da14cebeSEric Cheng (SQS_POLL_QUIESCE | SQS_POLL_RESTART | SQS_POLL_CLEANUP) 167da14cebeSEric Cheng 168da14cebeSEric Cheng #define SQS_POLL_THR_CONTROL \ 169da14cebeSEric Cheng (SQS_POLL_THR_QUIESCE | SQS_POLL_THR_RESTART) 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1727c478bd9Sstevel@tonic-gate } 1737c478bd9Sstevel@tonic-gate #endif 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate #endif /* _SYS_SQUEUE_IMPL_H */ 176