Print this page
11547 Want connstat(1M) command to display per-connection TCP statistics
Portions contributed by: Cody Peter Mello <cody.mello@joyent.com>
Portions contributed by: Ahmed G <ahmedg@delphix.com>
Reviewed by: Jason King <jason.king@joyent.com>
Reviewed by: Robert Mustacchi <rm@joyent.com>
Reviewed by: Dan McDonald <danmcd@joyent.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/inet/tcp_stats.h
+++ new/usr/src/uts/common/inet/tcp_stats.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
24 + * Copyright (c) 2015 by Delphix. All rights reserved.
24 25 */
25 26
26 27 #ifndef _INET_TCP_STATS_H
27 28 #define _INET_TCP_STATS_H
28 29
29 30 /*
30 31 * TCP private kernel statistics declarations.
31 32 */
32 33
33 34 #ifdef __cplusplus
34 35 extern "C" {
35 36 #endif
36 37
37 38 #ifdef _KERNEL
38 39
39 40 /*
40 41 * TCP Statistics.
41 42 *
42 43 * How TCP statistics work.
43 44 *
44 45 * There are two types of statistics invoked by two macros.
45 46 *
46 47 * TCP_STAT(name) does non-atomic increment of a named stat counter. It is
47 48 * supposed to be used in non MT-hot paths of the code.
48 49 *
49 50 * TCP_DBGSTAT(name) does atomic increment of a named stat counter. It is
50 51 * supposed to be used for DEBUG purposes and may be used on a hot path.
51 52 * These counters are only available in a debugged kernel. They are grouped
52 53 * under the TCP_DEBUG_COUNTER C pre-processor condition.
53 54 *
54 55 * Both TCP_STAT and TCP_DBGSTAT counters are available using kstat
55 56 * (use "kstat tcp" to get them).
56 57 *
57 58 * How to add new counters.
58 59 *
59 60 * 1) Add a field in the tcp_stat structure describing your counter.
60 61 * 2) Add a line in the template in tcp_kstat2_init() with the name
61 62 * of the counter.
62 63 * 3) Update tcp_clr_stats() and tcp_cp_stats() with the new counters.
63 64 * IMPORTANT!! - make sure that all the above functions are in sync !!
64 65 * 4) Use either TCP_STAT or TCP_DBGSTAT with the name.
65 66 *
66 67 * Please avoid using private counters which are not kstat-exported.
67 68 *
68 69 * Implementation note.
69 70 *
70 71 * Both the MIB2 and tcp_stat_t counters are kept per CPU in the array
71 72 * tcps_sc in tcp_stack_t. Each array element is a pointer to a
72 73 * tcp_stats_cpu_t struct. Once allocated, the tcp_stats_cpu_t struct is
73 74 * not freed until the tcp_stack_t is going away. So there is no need to
74 75 * acquire a lock before accessing the stats counters.
75 76 */
76 77
77 78 #ifndef TCP_DEBUG_COUNTER
78 79 #ifdef DEBUG
79 80 #define TCP_DEBUG_COUNTER 1
80 81 #else
81 82 #define TCP_DEBUG_COUNTER 0
82 83 #endif
83 84 #endif
84 85
85 86 /* Kstats */
86 87 typedef struct tcp_stat {
87 88 kstat_named_t tcp_time_wait_syn_success;
88 89 kstat_named_t tcp_clean_death_nondetached;
89 90 kstat_named_t tcp_eager_blowoff_q;
90 91 kstat_named_t tcp_eager_blowoff_q0;
91 92 kstat_named_t tcp_no_listener;
92 93 kstat_named_t tcp_listendrop;
93 94 kstat_named_t tcp_listendropq0;
94 95 kstat_named_t tcp_wsrv_called;
95 96 kstat_named_t tcp_flwctl_on;
96 97 kstat_named_t tcp_timer_fire_early;
97 98 kstat_named_t tcp_timer_fire_miss;
98 99 kstat_named_t tcp_zcopy_on;
99 100 kstat_named_t tcp_zcopy_off;
100 101 kstat_named_t tcp_zcopy_backoff;
101 102 kstat_named_t tcp_fusion_flowctl;
102 103 kstat_named_t tcp_fusion_backenabled;
103 104 kstat_named_t tcp_fusion_urg;
104 105 kstat_named_t tcp_fusion_putnext;
105 106 kstat_named_t tcp_fusion_unfusable;
106 107 kstat_named_t tcp_fusion_aborted;
107 108 kstat_named_t tcp_fusion_unqualified;
108 109 kstat_named_t tcp_fusion_rrw_busy;
109 110 kstat_named_t tcp_fusion_rrw_msgcnt;
110 111 kstat_named_t tcp_fusion_rrw_plugged;
111 112 kstat_named_t tcp_in_ack_unsent_drop;
112 113 kstat_named_t tcp_sock_fallback;
113 114 kstat_named_t tcp_lso_enabled;
114 115 kstat_named_t tcp_lso_disabled;
115 116 kstat_named_t tcp_lso_times;
116 117 kstat_named_t tcp_lso_pkt_out;
117 118 kstat_named_t tcp_listen_cnt_drop;
118 119 kstat_named_t tcp_listen_mem_drop;
119 120 kstat_named_t tcp_zwin_mem_drop;
120 121 kstat_named_t tcp_zwin_ack_syn;
121 122 kstat_named_t tcp_rst_unsent;
122 123 kstat_named_t tcp_reclaim_cnt;
123 124 kstat_named_t tcp_reass_timeout;
124 125 #ifdef TCP_DEBUG_COUNTER
125 126 kstat_named_t tcp_time_wait;
126 127 kstat_named_t tcp_rput_time_wait;
127 128 kstat_named_t tcp_detach_time_wait;
128 129 kstat_named_t tcp_timeout_calls;
129 130 kstat_named_t tcp_timeout_cached_alloc;
130 131 kstat_named_t tcp_timeout_cancel_reqs;
131 132 kstat_named_t tcp_timeout_canceled;
132 133 kstat_named_t tcp_timermp_freed;
133 134 kstat_named_t tcp_push_timer_cnt;
134 135 kstat_named_t tcp_ack_timer_cnt;
135 136 #endif
136 137 } tcp_stat_t;
137 138
138 139 /*
139 140 * This struct contains only the counter part of tcp_stat_t. It is used
140 141 * in tcp_stats_cpu_t instead of tcp_stat_t to save memory space.
141 142 */
142 143 typedef struct tcp_stat_counter_s {
143 144 uint64_t tcp_time_wait_syn_success;
144 145 uint64_t tcp_clean_death_nondetached;
145 146 uint64_t tcp_eager_blowoff_q;
146 147 uint64_t tcp_eager_blowoff_q0;
147 148 uint64_t tcp_no_listener;
148 149 uint64_t tcp_listendrop;
149 150 uint64_t tcp_listendropq0;
150 151 uint64_t tcp_wsrv_called;
151 152 uint64_t tcp_flwctl_on;
152 153 uint64_t tcp_timer_fire_early;
153 154 uint64_t tcp_timer_fire_miss;
154 155 uint64_t tcp_zcopy_on;
155 156 uint64_t tcp_zcopy_off;
156 157 uint64_t tcp_zcopy_backoff;
157 158 uint64_t tcp_fusion_flowctl;
158 159 uint64_t tcp_fusion_backenabled;
159 160 uint64_t tcp_fusion_urg;
160 161 uint64_t tcp_fusion_putnext;
161 162 uint64_t tcp_fusion_unfusable;
162 163 uint64_t tcp_fusion_aborted;
163 164 uint64_t tcp_fusion_unqualified;
164 165 uint64_t tcp_fusion_rrw_busy;
165 166 uint64_t tcp_fusion_rrw_msgcnt;
166 167 uint64_t tcp_fusion_rrw_plugged;
167 168 uint64_t tcp_in_ack_unsent_drop;
168 169 uint64_t tcp_sock_fallback;
169 170 uint64_t tcp_lso_enabled;
170 171 uint64_t tcp_lso_disabled;
171 172 uint64_t tcp_lso_times;
172 173 uint64_t tcp_lso_pkt_out;
173 174 uint64_t tcp_listen_cnt_drop;
174 175 uint64_t tcp_listen_mem_drop;
175 176 uint64_t tcp_zwin_mem_drop;
176 177 uint64_t tcp_zwin_ack_syn;
177 178 uint64_t tcp_rst_unsent;
178 179 uint64_t tcp_reclaim_cnt;
179 180 uint64_t tcp_reass_timeout;
180 181 #ifdef TCP_DEBUG_COUNTER
181 182 uint64_t tcp_time_wait;
182 183 uint64_t tcp_rput_time_wait;
183 184 uint64_t tcp_detach_time_wait;
184 185 uint64_t tcp_timeout_calls;
185 186 uint64_t tcp_timeout_cached_alloc;
186 187 uint64_t tcp_timeout_cancel_reqs;
187 188 uint64_t tcp_timeout_canceled;
188 189 uint64_t tcp_timermp_freed;
189 190 uint64_t tcp_push_timer_cnt;
190 191 uint64_t tcp_ack_timer_cnt;
191 192 #endif
192 193 } tcp_stat_counter_t;
193 194
194 195 typedef struct tcp_g_stat {
195 196 kstat_named_t tcp_timermp_alloced;
196 197 kstat_named_t tcp_timermp_allocfail;
197 198 kstat_named_t tcp_timermp_allocdblfail;
↓ open down ↓ |
164 lines elided |
↑ open up ↑ |
198 199 kstat_named_t tcp_freelist_cleanup;
199 200 } tcp_g_stat_t;
200 201
201 202 /* Per CPU stats: TCP MIB2, TCP kstat and connection counter. */
202 203 typedef struct {
203 204 int64_t tcp_sc_conn_cnt;
204 205 mib2_tcp_t tcp_sc_mib;
205 206 tcp_stat_counter_t tcp_sc_stats;
206 207 } tcp_stats_cpu_t;
207 208
209 +/*
210 + * Per-connection statistics. Some of these are also kept globally in the
211 + * per-cpu tcp_sc_mib entry (see tcp_stats_cpu_t above). We need not maintain
212 + * per-cpu versions of these stats since a connection is typically processed
213 + * on the same CPU.
214 + */
215 +typedef struct tcp_conn_stats {
216 + uint64_t tcp_in_data_inorder_bytes;
217 + uint64_t tcp_in_data_inorder_segs;
218 + uint64_t tcp_in_data_unorder_bytes;
219 + uint64_t tcp_in_data_unorder_segs;
220 + uint64_t tcp_in_zwnd_probes;
221 +
222 + uint64_t tcp_out_data_bytes;
223 + uint64_t tcp_out_data_segs;
224 + uint64_t tcp_out_retrans_bytes;
225 + uint64_t tcp_out_retrans_segs;
226 + uint64_t tcp_out_zwnd_probes;
227 +} tcp_conn_stats_t;
228 +
208 229 #define TCPS_BUMP_MIB(tcps, x) \
209 230 BUMP_MIB(&(tcps)->tcps_sc[CPU->cpu_seqid]->tcp_sc_mib, x)
210 231
211 232 #define TCPS_UPDATE_MIB(tcps, x, y) \
212 233 UPDATE_MIB(&(tcps)->tcps_sc[CPU->cpu_seqid]->tcp_sc_mib, x, y)
213 234
214 235 #if TCP_DEBUG_COUNTER
215 236 #define TCP_DBGSTAT(tcps, x) \
216 237 atomic_inc_64( \
217 238 &((tcps)->tcps_sc[CPU->cpu_seqid]->tcp_sc_stats.x))
218 239 #define TCP_G_DBGSTAT(x) \
219 240 atomic_inc_64(&(tcp_g_statistics.x.value.ui64))
220 241 #else
221 242 #define TCP_DBGSTAT(tcps, x)
222 243 #define TCP_G_DBGSTAT(x)
223 244 #endif
224 245
225 246 #define TCP_G_STAT(x) (tcp_g_statistics.x.value.ui64++)
226 247
227 248 #define TCP_STAT(tcps, x) \
228 249 ((tcps)->tcps_sc[CPU->cpu_seqid]->tcp_sc_stats.x++)
229 250 #define TCP_STAT_UPDATE(tcps, x, n) \
230 251 ((tcps)->tcps_sc[CPU->cpu_seqid]->tcp_sc_stats.x += (n))
231 252 #define TCP_STAT_SET(tcps, x, n) \
232 253 ((tcps)->tcps_sc[CPU->cpu_seqid]->tcp_sc_stats.x = (n))
233 254
234 255 /* Global TCP stats for all IP stacks. */
235 256 extern tcp_g_stat_t tcp_g_statistics;
236 257 extern kstat_t *tcp_g_kstat;
237 258
238 259 extern void *tcp_g_kstat_init(tcp_g_stat_t *);
239 260 extern void tcp_g_kstat_fini(kstat_t *);
240 261 extern void *tcp_kstat_init(netstackid_t);
241 262 extern void tcp_kstat_fini(netstackid_t, kstat_t *);
242 263 extern void *tcp_kstat2_init(netstackid_t);
243 264 extern void tcp_kstat2_fini(netstackid_t, kstat_t *);
244 265
245 266 #endif /* _KERNEL */
246 267
247 268 #ifdef __cplusplus
248 269 }
249 270 #endif
250 271
251 272 #endif /* _INET_TCP_STATS_H */
↓ open down ↓ |
34 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX