Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue: 1897191 Implement extra TCP statistics #870

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,20 @@ if test ${revision:-0} -ne 0 ; then
CXXFLAGS="-DVMA_SVN_REVISION=$revision $CXXFLAGS"
fi

# Extra TCP statistics
#
AC_ARG_ENABLE([extra-stats],
AC_HELP_STRING([--enable-extra-stats],
[Enable extra TCP statistics (default=no)]))
AC_MSG_CHECKING(
[for extra TCP statistics support])
if test "x$enable_extra_stats" = xyes; then
AC_DEFINE_UNQUOTED([DEFINED_EXTRA_STATS], [1], [Define to 1 to provide extra TCP statistics])
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([no])
fi

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please consider moving to config\m4\opt.m4.
Look to implementation of otional log configure option at https://github.com/Mellanox/libvma/blob/master/config/m4/opt.m4
I would like to suggest --enable-opt-stats with following values:

    no | none)
        ;;
    medium)
        ;;
    high)
        ;;
    *)

Probably it can be done w/o none at this pull request

# OFED configuration.
#
AC_MSG_CHECKING([for OFED path])
Expand Down
56 changes: 46 additions & 10 deletions src/stats/stats_printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void print_full_stats(socket_stats_t* p_si_stats, mc_grp_info_t* p_mc_grp_info,

if (!filename) return;

bool b_any_activiy = false;
bool b_any_activity = false;
char post_fix[3] = "";

if (user_params.print_details_mode == e_deltas)
Expand Down Expand Up @@ -143,44 +143,44 @@ void print_full_stats(socket_stats_t* p_si_stats, mc_grp_info_t* p_mc_grp_info,
if (p_si_stats->counters.n_tx_sent_byte_count || p_si_stats->counters.n_tx_sent_pkt_count || p_si_stats->counters.n_tx_drops || p_si_stats->counters.n_tx_errors)
{
fprintf(filename, "Tx Offload: %u / %u / %u / %u [kilobytes/packets/drops/errors]%s\n", p_si_stats->counters.n_tx_sent_byte_count/BYTES_TRAFFIC_UNIT,p_si_stats->counters.n_tx_sent_pkt_count, p_si_stats->counters.n_tx_drops, p_si_stats->counters.n_tx_errors, post_fix);
b_any_activiy = true;
b_any_activity = true;
}
if (p_si_stats->counters.n_tx_os_bytes || p_si_stats->counters.n_tx_os_packets || p_si_stats->counters.n_tx_os_eagain || p_si_stats->counters.n_tx_os_errors)
{
fprintf(filename, "Tx OS info: %u / %u / %u / %u [kilobytes/packets/eagains/errors]%s\n", p_si_stats->counters.n_tx_os_bytes/BYTES_TRAFFIC_UNIT, p_si_stats->counters.n_tx_os_packets, p_si_stats->counters.n_tx_os_eagain, p_si_stats->counters.n_tx_os_errors, post_fix);
b_any_activiy = true;
b_any_activity = true;
}
if (p_si_stats->counters.n_tx_dummy) {
fprintf(filename, "Tx Dummy messages : %d\n", p_si_stats->counters.n_tx_dummy);
b_any_activiy = true;
b_any_activity = true;
}
if (p_si_stats->counters.n_rx_bytes || p_si_stats->counters.n_rx_packets || p_si_stats->counters.n_rx_eagain || p_si_stats->counters.n_rx_errors)
{
fprintf(filename, "Rx Offload: %u / %u / %u / %u [kilobytes/packets/eagains/errors]%s\n", p_si_stats->counters.n_rx_bytes/BYTES_TRAFFIC_UNIT, p_si_stats->counters.n_rx_packets, p_si_stats->counters.n_rx_eagain, p_si_stats->counters.n_rx_errors, post_fix);
b_any_activiy = true;
b_any_activity = true;
}
if (p_si_stats->counters.n_rx_os_bytes || p_si_stats->counters.n_rx_os_packets || p_si_stats->counters.n_rx_os_eagain || p_si_stats->counters.n_rx_os_errors)
{
fprintf(filename, "Rx OS info: %u / %u / %u / %u [kilobytes/packets/eagains/errors]%s\n", p_si_stats->counters.n_rx_os_bytes/BYTES_TRAFFIC_UNIT, p_si_stats->counters.n_rx_os_packets, p_si_stats->counters.n_rx_os_eagain, p_si_stats->counters.n_rx_os_errors, post_fix);
b_any_activiy = true;
b_any_activity = true;
}
if (p_si_stats->counters.n_rx_packets || p_si_stats->n_rx_ready_pkt_count)
{
fprintf(filename, "Rx byte: cur %u / max %u / dropped%s %u / limit %u\n", p_si_stats->n_rx_ready_byte_count, p_si_stats->counters.n_rx_ready_byte_max, post_fix,p_si_stats->counters.n_rx_ready_byte_drop, p_si_stats->n_rx_ready_byte_limit);
fprintf(filename, "Rx pkt : cur %u / max %u / dropped%s %u\n", p_si_stats->n_rx_ready_pkt_count, p_si_stats->counters.n_rx_ready_pkt_max, post_fix,p_si_stats->counters.n_rx_ready_pkt_drop);
b_any_activiy = true;
b_any_activity = true;
}
if (p_si_stats->n_rx_zcopy_pkt_count)
{
fprintf(filename, "Rx zero copy buffers: cur %u\n", p_si_stats->n_rx_zcopy_pkt_count);
b_any_activiy = true;
b_any_activity = true;
}
if (p_si_stats->counters.n_rx_poll_miss || p_si_stats->counters.n_rx_poll_hit)
{
double rx_poll_hit = (double)p_si_stats->counters.n_rx_poll_hit;
double rx_poll_hit_percentage = (rx_poll_hit / (rx_poll_hit + (double)p_si_stats->counters.n_rx_poll_miss)) * 100;
fprintf(filename, "Rx poll: %u / %u (%2.2f%%) [miss/hit]\n", p_si_stats->counters.n_rx_poll_miss, p_si_stats->counters.n_rx_poll_hit, rx_poll_hit_percentage);
b_any_activiy = true;
b_any_activity = true;
}

if (p_si_stats->counters.n_rx_migrations || p_si_stats->counters.n_tx_migrations)
Expand All @@ -193,9 +193,45 @@ void print_full_stats(socket_stats_t* p_si_stats, mc_grp_info_t* p_mc_grp_info,
fprintf(filename, "Retransmissions: %u\n", p_si_stats->counters.n_tx_retransmits);
}

if (b_any_activiy == false) {
if (b_any_activity == false) {
fprintf(filename, "Rx and Tx where not active\n");
}

#ifdef DEFINED_EXTRA_STATS
if (p_si_stats->socket_type == SOCK_STREAM && b_any_activity) {
fprintf(filename, "TCP --------------------------------\n");
fprintf(filename, "TCP n_rto: %u\n", p_si_stats->tcp_stats.n_rto);
fprintf(filename, "TCP n_rtx_fast: %u\n", p_si_stats->tcp_stats.n_rtx_fast);
fprintf(filename, "TCP n_rtx_rto: %u\n", p_si_stats->tcp_stats.n_rtx_rto);
fprintf(filename, "TCP n_rtx_ss: %u\n", p_si_stats->tcp_stats.n_rtx_ss);
fprintf(filename, "TCP n_rtx_spurious: %u\n", p_si_stats->tcp_stats.n_rtx_spurious);
fprintf(filename, "TCP n_recovered_fast: %u\n", p_si_stats->tcp_stats.n_recovered_fast);
fprintf(filename, "TCP n_dupacks: %u\n", p_si_stats->tcp_stats.n_dupacks);
fprintf(filename, "TCP n_ofo: %u\n", p_si_stats->tcp_stats.n_ofo);
fprintf(filename, "TCP n_underruns: %u\n", p_si_stats->tcp_stats.n_underruns);
fprintf(filename, "TCP n_blocked_cwnd: %u\n", p_si_stats->tcp_stats.n_blocked_cwnd);
fprintf(filename, "TCP n_blocked_rwnd: %u\n", p_si_stats->tcp_stats.n_blocked_rwnd);
fprintf(filename, "TCP n_blocked_sndbuf: %u\n", p_si_stats->tcp_stats.n_blocked_sndbuf);
fprintf(filename, "TCP n_updates_rtt: %u\n", p_si_stats->tcp_stats.n_updates_rtt);
fprintf(filename, "TCP n_rst: %u\n", p_si_stats->tcp_stats.n_rst);
fprintf(filename, "TCP --------------------------------\n");
fprintf(filename, "TCP n_rx_ignored: %u\n", p_si_stats->tcp_stats.n_rx_ignored);
fprintf(filename, "TCP n_dropped: %u\n", p_si_stats->tcp_stats.n_dropped);
fprintf(filename, "TCP n_memerr_pbuf: %u\n", p_si_stats->tcp_stats.n_memerr_pbuf);
fprintf(filename, "TCP n_memerr_seg: %u\n", p_si_stats->tcp_stats.n_memerr_seg);
fprintf(filename, "TCP --------------------------------\n");
fprintf(filename, "TCP n_mss: %u\n", p_si_stats->tcp_stats.n_mss);
fprintf(filename, "TCP n_rto_timer(ms): %u\n", p_si_stats->tcp_stats.n_rto_timer);
fprintf(filename, "TCP n_snd_wnd: %u\n", p_si_stats->tcp_stats.n_snd_wnd);
fprintf(filename, "TCP n_cwnd: %u\n", p_si_stats->tcp_stats.n_cwnd);
fprintf(filename, "TCP n_ssthresh: %u\n", p_si_stats->tcp_stats.n_ssthresh);
fprintf(filename, "TCP n_snd_nxt: %u\n", p_si_stats->tcp_stats.n_snd_nxt);
fprintf(filename, "TCP n_lastack: %u\n", p_si_stats->tcp_stats.n_lastack);
fprintf(filename, "TCP n_unsent_q: %u\n", p_si_stats->tcp_stats.n_unsent_q);
fprintf(filename, "TCP n_unacked_q: %u\n", p_si_stats->tcp_stats.n_unacked_q);
fprintf(filename, "TCP n_ooseq_q: %u\n", p_si_stats->tcp_stats.n_ooseq_q);
}
#endif /* DEFINED_EXTRA_STATS */
}

// Print statistics headers for all sockets - used in case view mode is e_netstat_like
Expand Down
92 changes: 68 additions & 24 deletions src/stats/stats_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,41 +174,85 @@ void usage(const char *argv0)
void update_delta_stat(socket_stats_t* p_curr_stat, socket_stats_t* p_prev_stat)
{
int delay = INTERVAL;
p_prev_stat->counters.n_tx_sent_byte_count = (p_curr_stat->counters.n_tx_sent_byte_count - p_prev_stat->counters.n_tx_sent_byte_count) / delay;
p_prev_stat->counters.n_tx_sent_pkt_count = (p_curr_stat->counters.n_tx_sent_pkt_count - p_prev_stat->counters.n_tx_sent_pkt_count) / delay;
p_prev_stat->counters.n_tx_drops = (p_curr_stat->counters.n_tx_drops - p_prev_stat->counters.n_tx_drops) / delay;
p_prev_stat->counters.n_tx_errors = (p_curr_stat->counters.n_tx_errors - p_prev_stat->counters.n_tx_errors) / delay;
p_prev_stat->counters.n_tx_dummy = (p_curr_stat->counters.n_tx_dummy - p_prev_stat->counters.n_tx_dummy) / delay;
p_prev_stat->counters.n_tx_os_bytes = (p_curr_stat->counters.n_tx_os_bytes - p_prev_stat->counters.n_tx_os_bytes) / delay;
p_prev_stat->counters.n_tx_os_packets = (p_curr_stat->counters.n_tx_os_packets - p_prev_stat->counters.n_tx_os_packets) / delay;
p_prev_stat->counters.n_tx_os_eagain = (p_curr_stat->counters.n_tx_os_eagain - p_prev_stat->counters.n_tx_os_eagain) / delay;
p_prev_stat->counters.n_tx_os_errors = (p_curr_stat->counters.n_tx_os_errors - p_prev_stat->counters.n_tx_os_errors) / delay;
p_prev_stat->counters.n_rx_bytes = (p_curr_stat->counters.n_rx_bytes - p_prev_stat->counters.n_rx_bytes) / delay;
p_prev_stat->counters.n_rx_packets = (p_curr_stat->counters.n_rx_packets - p_prev_stat->counters.n_rx_packets) / delay;
p_prev_stat->counters.n_rx_eagain = (p_curr_stat->counters.n_rx_eagain - p_prev_stat->counters.n_rx_eagain) / delay;
p_prev_stat->counters.n_rx_errors = (p_curr_stat->counters.n_rx_errors - p_prev_stat->counters.n_rx_errors) / delay;
p_prev_stat->counters.n_rx_os_bytes = (p_curr_stat->counters.n_rx_os_bytes - p_prev_stat->counters.n_rx_os_bytes) / delay;
p_prev_stat->counters.n_rx_os_packets = (p_curr_stat->counters.n_rx_os_packets - p_prev_stat->counters.n_rx_os_packets) / delay;
p_prev_stat->counters.n_rx_os_eagain = (p_curr_stat->counters.n_rx_os_eagain - p_prev_stat->counters.n_rx_os_eagain) / delay;
p_prev_stat->counters.n_rx_os_errors = (p_curr_stat->counters.n_rx_os_errors - p_prev_stat->counters.n_rx_os_errors) / delay;
p_prev_stat->counters.n_rx_poll_miss = (p_curr_stat->counters.n_rx_poll_miss - p_prev_stat->counters.n_rx_poll_miss) / delay;
p_prev_stat->counters.n_rx_poll_hit = (p_curr_stat->counters.n_rx_poll_hit - p_prev_stat->counters.n_rx_poll_hit) / delay;

#define STAT_DELTA(field) p_prev_stat->field = (p_curr_stat->field - p_prev_stat->field) / delay
#define STAT_COUNTERS_DELTA(field) STAT_DELTA(counters.field)
#define STAT_TCP_DELTA(field) STAT_DELTA(tcp_stats.field)

STAT_COUNTERS_DELTA(n_tx_sent_byte_count);
STAT_COUNTERS_DELTA(n_tx_sent_pkt_count);
STAT_COUNTERS_DELTA(n_tx_drops);
STAT_COUNTERS_DELTA(n_tx_errors);
STAT_COUNTERS_DELTA(n_tx_dummy);
STAT_COUNTERS_DELTA(n_tx_os_bytes);
STAT_COUNTERS_DELTA(n_tx_os_packets);
STAT_COUNTERS_DELTA(n_tx_os_eagain);
STAT_COUNTERS_DELTA(n_tx_os_errors);
STAT_COUNTERS_DELTA(n_rx_bytes);
STAT_COUNTERS_DELTA(n_rx_packets);
STAT_COUNTERS_DELTA(n_rx_eagain);
STAT_COUNTERS_DELTA(n_rx_errors);
STAT_COUNTERS_DELTA(n_rx_os_bytes);
STAT_COUNTERS_DELTA(n_rx_os_packets);
STAT_COUNTERS_DELTA(n_rx_os_eagain);
STAT_COUNTERS_DELTA(n_rx_os_errors);
STAT_COUNTERS_DELTA(n_rx_poll_miss);
STAT_COUNTERS_DELTA(n_rx_poll_hit);
p_prev_stat->n_rx_ready_byte_count = p_curr_stat->n_rx_ready_byte_count;
p_prev_stat->n_tx_ready_byte_count = p_curr_stat->n_tx_ready_byte_count;
p_prev_stat->n_rx_ready_byte_limit = p_curr_stat->n_rx_ready_byte_limit;
p_prev_stat->counters.n_rx_ready_byte_max = p_curr_stat->counters.n_rx_ready_byte_max;
p_prev_stat->counters.n_rx_ready_byte_drop = (p_curr_stat->counters.n_rx_ready_byte_drop - p_prev_stat->counters.n_rx_ready_byte_drop) / delay;
p_prev_stat->counters.n_rx_ready_pkt_drop = (p_curr_stat->counters.n_rx_ready_pkt_drop - p_prev_stat->counters.n_rx_ready_pkt_drop) / delay;
STAT_COUNTERS_DELTA(n_rx_ready_byte_drop);
STAT_COUNTERS_DELTA(n_rx_ready_pkt_drop);
p_prev_stat->n_rx_ready_pkt_count = p_curr_stat->n_rx_ready_pkt_count;
p_prev_stat->counters.n_rx_ready_pkt_max = p_curr_stat->counters.n_rx_ready_pkt_max;
p_prev_stat->n_rx_zcopy_pkt_count = p_curr_stat->n_rx_zcopy_pkt_count;

p_prev_stat->threadid_last_rx = p_curr_stat->threadid_last_rx;
p_prev_stat->threadid_last_tx = p_curr_stat->threadid_last_tx;

p_prev_stat->counters.n_rx_migrations = (p_curr_stat->counters.n_rx_migrations - p_prev_stat->counters.n_rx_migrations) / delay;
p_prev_stat->counters.n_tx_migrations = (p_curr_stat->counters.n_tx_migrations - p_prev_stat->counters.n_tx_migrations) / delay;
p_prev_stat->counters.n_tx_retransmits = (p_curr_stat->counters.n_tx_retransmits - p_prev_stat->counters.n_tx_retransmits) / delay;
STAT_COUNTERS_DELTA(n_rx_migrations);
STAT_COUNTERS_DELTA(n_tx_migrations);
STAT_COUNTERS_DELTA(n_tx_retransmits);

#ifdef DEFINED_EXTRA_STATS
if (p_curr_stat->socket_type == SOCK_STREAM) {
STAT_TCP_DELTA(n_rto);
STAT_TCP_DELTA(n_rtx_fast);
STAT_TCP_DELTA(n_rtx_rto);
STAT_TCP_DELTA(n_rtx_ss);
STAT_TCP_DELTA(n_rtx_spurious);
STAT_TCP_DELTA(n_recovered_fast);
STAT_TCP_DELTA(n_dupacks);
STAT_TCP_DELTA(n_ofo);
STAT_TCP_DELTA(n_underruns);
STAT_TCP_DELTA(n_blocked_cwnd);
STAT_TCP_DELTA(n_blocked_rwnd);
STAT_TCP_DELTA(n_blocked_sndbuf);
STAT_TCP_DELTA(n_updates_rtt);
STAT_TCP_DELTA(n_rst);

STAT_TCP_DELTA(n_rx_ignored);
STAT_TCP_DELTA(n_dropped);
STAT_TCP_DELTA(n_memerr_pbuf);
STAT_TCP_DELTA(n_memerr_seg);

p_prev_stat->tcp_stats.n_mss = p_curr_stat->tcp_stats.n_mss;
p_prev_stat->tcp_stats.n_rto_timer = p_curr_stat->tcp_stats.n_rto_timer;
p_prev_stat->tcp_stats.n_snd_wnd = p_curr_stat->tcp_stats.n_snd_wnd;
p_prev_stat->tcp_stats.n_cwnd = p_curr_stat->tcp_stats.n_cwnd;
p_prev_stat->tcp_stats.n_ssthresh = p_curr_stat->tcp_stats.n_ssthresh;
p_prev_stat->tcp_stats.n_snd_nxt = p_curr_stat->tcp_stats.n_snd_nxt;
p_prev_stat->tcp_stats.n_lastack = p_curr_stat->tcp_stats.n_lastack;
p_prev_stat->tcp_stats.n_unsent_q = p_curr_stat->tcp_stats.n_unsent_q;
p_prev_stat->tcp_stats.n_unacked_q = p_curr_stat->tcp_stats.n_unacked_q;
p_prev_stat->tcp_stats.n_ooseq_q = p_curr_stat->tcp_stats.n_ooseq_q;
}
#endif /* DEFINED_EXTRA_STATS */

#undef STAT_TCP_DELTA
#undef STAT_COUNTERS_DELTA
#undef STAT_DELTA
}

void update_delta_iomux_stat(iomux_func_stats_t* p_curr_stats, iomux_func_stats_t* p_prev_stats)
Expand Down
45 changes: 45 additions & 0 deletions src/vma/lwip/stats.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,51 @@ void stats_display_proto(struct stats_proto *proto, char *name);
#define stats_display_proto(proto, name)
#endif /* LWIP_STATS_DISPLAY */

#ifdef DEFINED_EXTRA_STATS

struct socket_tcp_stats {
u32_t n_rto; /* number of RTO */
u32_t n_rtx_fast; /* fast retransmits */
u32_t n_rtx_rto; /* retransmits caused by RTO */
u32_t n_rtx_ss; /* retransmits in slow start phase */
u32_t n_rtx_spurious; /* number of segments removed from unsent queue */
u32_t n_recovered_fast; /* recovered after fast retransmit without RTO */
u32_t n_dupacks; /* duplicate ACKs */
u32_t n_ofo; /* out of order segments */
u32_t n_underruns; /* underruns (no segments to send) */
u32_t n_blocked_cwnd; /* sending blocked by cwnd */
u32_t n_blocked_rwnd; /* sending blocked by rwnd */
u32_t n_blocked_sndbuf; /* sending blocked by snd_buf */
u32_t n_updates_rtt; /* RTT measurements */
u32_t n_rst; /* RST segments */

u32_t n_rx_ignored; /* ignored incoming segments */
u32_t n_dropped; /* dropped segments due to an error */
u32_t n_memerr_pbuf; /* pbuf allocation errors */
u32_t n_memerr_seg; /* segment allocation errors */

u32_t n_mss;
u32_t n_rto_timer;
u32_t n_snd_wnd;
u32_t n_cwnd;
u32_t n_ssthresh;
u32_t n_snd_nxt;
u32_t n_lastack;
u32_t n_unsent_q;
u32_t n_unacked_q;
u32_t n_ooseq_q;
};

typedef struct socket_tcp_stats socket_tcp_stats_t;

#define EXTRA_STATS_INC(x) ++x
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please consider (++x)


#else /* DEFINED_EXTRA_STATS */
#define EXTRA_STATS_INC(x) do {} while (0)
#endif /* DEFINED_EXTRA_STATS */

#define PCB_STATS_INC(x) EXTRA_STATS_INC(pcb->p_stats->x)

#ifdef __cplusplus
}
#endif
Expand Down
45 changes: 44 additions & 1 deletion src/vma/lwip/tcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,44 @@ const u8_t tcp_persist_backoff[7] = { 3, 6, 12, 24, 48, 96, 120 };
/** Only used for temporary storage. */
struct tcp_pcb *tcp_tmp_pcb;

#ifdef DEFINED_EXTRA_STATS
void register_tcp_stats_instance(struct tcp_pcb *pcb, socket_tcp_stats_t *stats)
{
pcb->p_stats = stats;
}

static void copy_tcp_metrics(struct tcp_pcb *pcb)
{
struct tcp_seg *seg;
socket_tcp_stats_t *stats = pcb->p_stats;
u32_t n;

if (stats == NULL)
return;

stats->n_mss = pcb->mss;
stats->n_rto_timer = pcb->rto * slow_tmr_interval;
stats->n_snd_wnd = pcb->snd_wnd;
stats->n_cwnd = pcb->cwnd;
stats->n_ssthresh = pcb->ssthresh;
stats->n_snd_nxt = pcb->snd_nxt;
stats->n_lastack = pcb->lastack;

for (seg = pcb->unsent, n = 0; seg != NULL; seg = seg->next, ++n);
stats->n_unsent_q = n;
for (seg = pcb->unacked, n = 0; seg != NULL; seg = seg->next, ++n);
stats->n_unacked_q = n;
for (seg = pcb->ooseq, n = 0; seg != NULL; seg = seg->next, ++n);
stats->n_ooseq_q = n;
}
#else /* DEFINED_EXTRA_STATS */
static void copy_tcp_metrics(struct tcp_pcb *pcb)
{
/* Do nothing if extra statistics is off. */
(void)pcb;
}
#endif /* DEFINED_EXTRA_STATS */

/**
*
* @param v value to set
Expand All @@ -132,6 +170,8 @@ tcp_tmr(struct tcp_pcb* pcb)
tcp_tmr() is called. */
tcp_slowtmr(pcb);
}

copy_tcp_metrics(pcb);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider

#ifdef DEFINED_EXTRA_STATS
#endif /* DEFINED_EXTRA_STATS */

as is done in other places

}

/**
Expand Down Expand Up @@ -1087,7 +1127,10 @@ tcp_tx_pbuf_alloc(struct tcp_pcb * pcb, u16_t length, pbuf_type type)

// pbuf_alloc is not valid, we should allocate a new pbuf.
p = external_tcp_tx_pbuf_alloc(pcb);
if (!p) return NULL;
if (!p) {
PCB_STATS_INC(n_memerr_pbuf);
return NULL;
}

p->next = NULL;
p->type = type;
Expand Down
10 changes: 10 additions & 0 deletions src/vma/lwip/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

#include "vma/lwip/pbuf.h"
#include "vma/lwip/ip.h"
#include "vma/lwip/stats.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -298,6 +299,10 @@ struct tcp_pcb {
#define TF_NAGLEMEMERR ((u16_t)0x0080U) /* nagle enabled, memerr, try to output to prevent delayed ACK to happen */
#define TF_WND_SCALE ((u16_t)0x0100U) /* Window Scale option enabled */

#ifdef DEFINED_EXTRA_STATS
socket_tcp_stats_t *p_stats;
#endif /* DEFINED_EXTRA_STATS */

/* the rest of the fields are in host byte order
as we have to do some math with them */
/* receiver variables */
Expand Down Expand Up @@ -483,6 +488,11 @@ err_t lwip_tcp_event(void *arg, struct tcp_pcb *pcb,
/*Initialization of tcp_pcb structure*/
void tcp_pcb_init (struct tcp_pcb* pcb, u8_t prio);

#ifdef DEFINED_EXTRA_STATS
/* Set pointer to extra TCP stats instance */
void register_tcp_stats_instance(struct tcp_pcb *pcb, socket_tcp_stats_t *stats);
#endif /* DEFINED_EXTRA_STATS */
Copy link
Collaborator

@igor-ivanov igor-ivanov Apr 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

register_ notation is for global function mostly related vma_lwip() initialization.
I would suggest to name as tcp_stats()


void tcp_arg (struct tcp_pcb *pcb, void *arg);
void tcp_ip_output (struct tcp_pcb *pcb, ip_output_fn ip_output);
void tcp_accept (struct tcp_pcb *pcb, tcp_accept_fn accept);
Expand Down
Loading