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/tcp_output.c
          +++ new/usr/src/uts/common/inet/tcp/tcp_output.c
↓ open down ↓ 1265 lines elided ↑ open up ↑
1266 1266          tcpha->tha_flags = (TH_ACK|TH_PUSH);
1267 1267  
1268 1268          sum = len + connp->conn_ht_ulp_len + connp->conn_sum;
1269 1269          sum = (sum >> 16) + (sum & 0xFFFF);
1270 1270          tcpha->tha_sum = htons(sum);
1271 1271  
1272 1272          tcpha->tha_seq = htonl(snxt);
1273 1273  
1274 1274          TCPS_BUMP_MIB(tcps, tcpOutDataSegs);
1275 1275          TCPS_UPDATE_MIB(tcps, tcpOutDataBytes, len);
1276      -        BUMP_LOCAL(tcp->tcp_obsegs);
     1276 +        TCPS_BUMP_MIB(tcps, tcpHCOutSegs);
     1277 +        tcp->tcp_cs.tcp_out_data_segs++;
     1278 +        tcp->tcp_cs.tcp_out_data_bytes += len;
1277 1279  
1278 1280          /* Update the latest receive window size in TCP header. */
1279 1281          tcpha->tha_win = htons(tcp->tcp_rwnd >> tcp->tcp_rcv_ws);
1280 1282  
1281 1283          tcp->tcp_last_sent_len = (ushort_t)len;
1282 1284  
1283 1285          plen = len + connp->conn_ht_iphc_len;
1284 1286  
1285 1287          ixa = connp->conn_ixa;
1286 1288          ixa->ixa_pktlen = plen;
↓ open down ↓ 666 lines elided ↑ open up ↑
1953 1955                                  tcp->tcp_last_sent_len = (ushort_t)len;
1954 1956                          while (mp1->b_cont) {
1955 1957                                  *xmit_tail = (*xmit_tail)->b_cont;
1956 1958                                  (*xmit_tail)->b_prev = local_time;
1957 1959                                  (*xmit_tail)->b_next =
1958 1960                                      (mblk_t *)(uintptr_t)(*snxt);
1959 1961                                  mp1 = mp1->b_cont;
1960 1962                          }
1961 1963                          *snxt += len;
1962 1964                          *tail_unsent = (*xmit_tail)->b_wptr - mp1->b_wptr;
1963      -                        BUMP_LOCAL(tcp->tcp_obsegs);
     1965 +                        TCPS_BUMP_MIB(tcps, tcpHCOutSegs);
1964 1966                          TCPS_BUMP_MIB(tcps, tcpOutDataSegs);
1965 1967                          TCPS_UPDATE_MIB(tcps, tcpOutDataBytes, len);
     1968 +                        tcp->tcp_cs.tcp_out_data_segs++;
     1969 +                        tcp->tcp_cs.tcp_out_data_bytes += len;
1966 1970                          tcp_send_data(tcp, mp);
1967 1971                          continue;
1968 1972                  }
1969 1973  
1970 1974                  *snxt += len;   /* Adjust later if we don't send all of len */
     1975 +                TCPS_BUMP_MIB(tcps, tcpHCOutSegs);
1971 1976                  TCPS_BUMP_MIB(tcps, tcpOutDataSegs);
1972 1977                  TCPS_UPDATE_MIB(tcps, tcpOutDataBytes, len);
     1978 +                tcp->tcp_cs.tcp_out_data_segs++;
     1979 +                tcp->tcp_cs.tcp_out_data_bytes += len;
1973 1980  
1974 1981                  if (*tail_unsent) {
1975 1982                          /* Are the bytes above us in flight? */
1976 1983                          rptr = (*xmit_tail)->b_wptr - *tail_unsent;
1977 1984                          if (rptr != (*xmit_tail)->b_rptr) {
1978 1985                                  *tail_unsent -= len;
1979 1986                                  if (len <= mss) /* LSO is unusable */
1980 1987                                          tcp->tcp_last_sent_len = (ushort_t)len;
1981 1988                                  len += total_hdr_len;
1982 1989                                  ixa->ixa_pktlen = len;
↓ open down ↓ 155 lines elided ↑ open up ↑
2138 2145                                  *tail_unsent = spill;
2139 2146                          } else {
2140 2147                                  /*
2141 2148                                   * We did not send everything we could in
2142 2149                                   * order to remain within the b_cont limit.
2143 2150                                   */
2144 2151                                  *usable -= spill;
2145 2152                                  *snxt += spill;
2146 2153                                  tcp->tcp_last_sent_len += spill;
2147 2154                                  TCPS_UPDATE_MIB(tcps, tcpOutDataBytes, spill);
     2155 +                                tcp->tcp_cs.tcp_out_data_bytes += spill;
2148 2156                                  /*
2149 2157                                   * Adjust the checksum
2150 2158                                   */
2151 2159                                  tcpha = (tcpha_t *)(rptr +
2152 2160                                      ixa->ixa_ip_hdr_length);
2153 2161                                  sum += spill;
2154 2162                                  sum = (sum >> 16) + (sum & 0xFFFF);
2155 2163                                  tcpha->tha_sum = htons(sum);
2156 2164                                  if (connp->conn_ipversion == IPV4_VERSION) {
2157 2165                                          sum = ntohs(
↓ open down ↓ 28 lines elided ↑ open up ↑
2186 2194                          DTRACE_PROBE2(tcp_send_lso, int, num_lso_seg,
2187 2195                              boolean_t, B_TRUE);
2188 2196  
2189 2197                          tcp_send_data(tcp, mp);
2190 2198  
2191 2199                          /*
2192 2200                           * Restore values of ixa_fragsize and ixa_extra_ident.
2193 2201                           */
2194 2202                          ixa->ixa_fragsize = ixa->ixa_pmtu;
2195 2203                          ixa->ixa_extra_ident = 0;
2196      -                        tcp->tcp_obsegs += num_lso_seg;
     2204 +                        TCPS_BUMP_MIB(tcps, tcpHCOutSegs);
2197 2205                          TCP_STAT(tcps, tcp_lso_times);
2198 2206                          TCP_STAT_UPDATE(tcps, tcp_lso_pkt_out, num_lso_seg);
2199 2207                  } else {
2200 2208                          /*
2201 2209                           * Make sure to clean up LSO information. Wherever a
2202 2210                           * new mp uses the prepended header room after dupb(),
2203 2211                           * lso_info_cleanup() should be called.
2204 2212                           */
2205 2213                          lso_info_cleanup(mp);
2206 2214                          tcp_send_data(tcp, mp);
2207      -                        BUMP_LOCAL(tcp->tcp_obsegs);
     2215 +                        TCPS_BUMP_MIB(tcps, tcpHCOutSegs);
2208 2216                  }
2209 2217          }
2210 2218  
2211 2219          return (0);
2212 2220  }
2213 2221  
2214 2222  /*
2215 2223   * Initiate closedown sequence on an active connection.  (May be called as
2216 2224   * writer.)  Return value zero for OK return, non-zero for error return.
2217 2225   */
↓ open down ↓ 195 lines elided ↑ open up ↑
2413 2421                  }
2414 2422  
2415 2423                  /* Update the latest receive window size in TCP header. */
2416 2424                  tcpha->tha_win = htons(tcp->tcp_rwnd >> tcp->tcp_rcv_ws);
2417 2425                  /* Track what we sent to the peer */
2418 2426                  tcp->tcp_tcpha->tha_win = tcpha->tha_win;
2419 2427                  tcp->tcp_rack = ack;
2420 2428                  tcp->tcp_rack_cnt = 0;
2421 2429                  TCPS_BUMP_MIB(tcps, tcpOutAck);
2422 2430          }
2423      -        BUMP_LOCAL(tcp->tcp_obsegs);
     2431 +        TCPS_BUMP_MIB(tcps, tcpHCOutSegs);
2424 2432          tcpha->tha_seq = htonl(seq);
2425 2433          tcpha->tha_ack = htonl(ack);
2426 2434          /*
2427 2435           * Include the adjustment for a source route if any.
2428 2436           */
2429 2437          sum = (sum >> 16) + (sum & 0xFFFF);
2430 2438          tcpha->tha_sum = htons(sum);
2431 2439          tcp_send_data(tcp, mp);
2432 2440  }
2433 2441  
↓ open down ↓ 953 lines elided ↑ open up ↑
3387 3395                  tcp_send_data(tcp, xmit_mp);
3388 3396  
3389 3397                  /*
3390 3398                   * Update the send timestamp to avoid false retransmission.
3391 3399                   */
3392 3400                  snxt_mp->b_prev = (mblk_t *)(intptr_t)gethrtime();
3393 3401  
3394 3402                  TCPS_BUMP_MIB(tcps, tcpRetransSegs);
3395 3403                  TCPS_UPDATE_MIB(tcps, tcpRetransBytes, seg_len);
3396 3404                  TCPS_BUMP_MIB(tcps, tcpOutSackRetransSegs);
     3405 +                tcp->tcp_cs.tcp_out_retrans_segs++;
     3406 +                tcp->tcp_cs.tcp_out_retrans_bytes += seg_len;
3397 3407                  /*
3398 3408                   * Update tcp_rexmit_max to extend this SACK recovery phase.
3399 3409                   * This happens when new data sent during fast recovery is
3400 3410                   * also lost.  If TCP retransmits those new data, it needs
3401 3411                   * to extend SACK recover phase to avoid starting another
3402 3412                   * fast retransmit/recovery unnecessarily.
3403 3413                   */
3404 3414                  if (SEQ_GT(tcp->tcp_sack_snxt, tcp->tcp_rexmit_max)) {
3405 3415                          tcp->tcp_rexmit_max = tcp->tcp_sack_snxt;
3406 3416                  }
↓ open down ↓ 50 lines elided ↑ open up ↑
3457 3467  
3458 3468                          snxt += cnt;
3459 3469                          win -= cnt;
3460 3470                          /*
3461 3471                           * Update the send timestamp to avoid false
3462 3472                           * retransmission.
3463 3473                           */
3464 3474                          old_snxt_mp->b_prev = (mblk_t *)(intptr_t)gethrtime();
3465 3475                          TCPS_BUMP_MIB(tcps, tcpRetransSegs);
3466 3476                          TCPS_UPDATE_MIB(tcps, tcpRetransBytes, cnt);
     3477 +                        tcp->tcp_cs.tcp_out_retrans_segs++;
     3478 +                        tcp->tcp_cs.tcp_out_retrans_bytes += cnt;
3467 3479  
3468 3480                          tcp->tcp_rexmit_nxt = snxt;
3469 3481                  }
3470 3482                  /*
3471 3483                   * If we have transmitted all we have at the time
3472 3484                   * we started the retranmission, we can leave
3473 3485                   * the rest of the job to tcp_wput_data().  But we
3474 3486                   * need to check the send window first.  If the
3475 3487                   * win is not 0, go on with tcp_wput_data().
3476 3488                   */
↓ open down ↓ 241 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX