Skip to content

Commit

Permalink
add histogram statistics for the queue size
Browse files Browse the repository at this point in the history
  • Loading branch information
jsmoon committed Mar 14, 2022
1 parent e48d282 commit 07facce
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/44bsd/tcp_input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ int CTcpReass::pre_tcp_reass(CPerProfileCtx * pctx,
if (m_blocks.empty()) {
/* first one - just add it to the list */
m_blocks.insert(std::pair<CTcpSeqKey,CTcpReassBlock>(cur_seq, cur));
m_max_used = std::max(m_max_used, get_active_blocks());
return 0;
}

Expand Down Expand Up @@ -286,7 +287,7 @@ int CTcpReass::pre_tcp_reass(CPerProfileCtx * pctx,

ti->ti_len = it->second.m_len;

if (m_max_size && m_blocks.size() > m_max_size) {
if (m_max_size && get_active_blocks() > m_max_size) {
/* drop last segment */
auto last = std::prev(m_blocks.end(), 1);
if (it == last) {
Expand All @@ -298,6 +299,7 @@ int CTcpReass::pre_tcp_reass(CPerProfileCtx * pctx,
m_blocks.erase(last);
}

m_max_used = std::max(m_max_used, get_active_blocks());
return 0;
}

Expand Down
4 changes: 4 additions & 0 deletions src/44bsd/tcp_subr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ void CTcpStats::Dump(FILE *fd){
MYC(tcps_badsyn);
MYC(tcps_reasalloc);
MYC(tcps_reasfree);
MYC(tcps_reas_hist_4);
MYC(tcps_reas_hist_16);
MYC(tcps_reas_hist_100);
MYC(tcps_reas_hist_other);
MYC(tcps_nombuf);
MYC(tcps_notunnel);

Expand Down
26 changes: 23 additions & 3 deletions src/44bsd/tcp_var.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ struct tcpstat_int_t: public tcpstat {

uint64_t tcps_reasalloc; /* allocate tcp reasembly object */
uint64_t tcps_reasfree; /* free tcp reasembly object */
uint64_t tcps_reas_hist_4; /* count of max queue <= 4 */
uint64_t tcps_reas_hist_16; /* count of max queue <= 16 */
uint64_t tcps_reas_hist_100; /* count of max queue <= 100 */
uint64_t tcps_reas_hist_other; /* count of max queue > 100 */

uint64_t tcps_nombuf; /* no mbuf for tcp - drop the packets */
uint64_t tcps_notunnel; /* no GTP Tunnel for tcp - drop the packets */
};
Expand Down Expand Up @@ -1283,7 +1288,7 @@ typedef std::vector<CTcpReassBlock> vec_tcp_reas_t;
class CTcpReass {

public:
CTcpReass(int size): m_max_size(size) {}
CTcpReass(uint16_t size): m_max_size(size), m_max_used(0) {}

int pre_tcp_reass(CPerProfileCtx * pctx,
struct CTcpCb *tp,
Expand Down Expand Up @@ -1315,8 +1320,12 @@ class CTcpReass {
struct rte_mbuf *m) { return tcp_reass(DEFAULT_PROFILE_CTX(ctx), tp, ti, m); }
#endif

inline uint8_t get_active_blocks(void){
return m_blocks.size();
inline uint16_t get_active_blocks(void){
return (uint16_t)m_blocks.size();
}

inline uint16_t get_max_blocks(void) {
return m_max_used;
}

void Dump(FILE *fd);
Expand All @@ -1326,6 +1335,7 @@ class CTcpReass {
private:
std::map<CTcpSeqKey,CTcpReassBlock> m_blocks;
uint16_t m_max_size;
uint16_t m_max_used;
};


Expand Down Expand Up @@ -1384,6 +1394,16 @@ inline void tcp_reass_alloc(CPerProfileCtx * pctx,
inline void tcp_reass_free(CPerProfileCtx * pctx,
struct CTcpCb *tp){
INC_STAT(pctx, tp->m_flow->m_tg_id, tcps_reasfree);
uint16_t max_blocks = tp->m_tpc_reass->get_max_blocks();
if (max_blocks <= 4) {
INC_STAT(pctx, tp->m_flow->m_tg_id, tcps_reas_hist_4);
} else if (max_blocks <= 16) {
INC_STAT(pctx, tp->m_flow->m_tg_id, tcps_reas_hist_16);
} else if (max_blocks <= 100) {
INC_STAT(pctx, tp->m_flow->m_tg_id, tcps_reas_hist_100);
} else {
INC_STAT(pctx, tp->m_flow->m_tg_id, tcps_reas_hist_other);
}
delete tp->m_tpc_reass;
tp->m_tpc_reass=(CTcpReass *)0;
}
Expand Down
4 changes: 4 additions & 0 deletions src/stt_cp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,10 @@ void CSTTCpPerTGIDPerDir::create_clm_counters(){

TCP_S_ADD_CNT_E(tcps_reasalloc,"allocate tcp reasembly ctx");
TCP_S_ADD_CNT_E(tcps_reasfree,"free tcp reasembly ctx");
TCP_S_ADD_CNT_E(tcps_reas_hist_4,"count of max queue <= 4");
TCP_S_ADD_CNT_E(tcps_reas_hist_16,"count of max queue <= 16");
TCP_S_ADD_CNT_E(tcps_reas_hist_100,"count of max queue <= 100");
TCP_S_ADD_CNT_E(tcps_reas_hist_other,"count of max queue > 100");
TCP_S_ADD_CNT_E(tcps_nombuf,"no mbuf for tcp - drop the packets");

/* TREX_FBSD: SACK counters */
Expand Down

0 comments on commit 07facce

Please sign in to comment.