Skip to content

Commit

Permalink
move retransmits back into tcp_stats_t
Browse files Browse the repository at this point in the history
  • Loading branch information
brycekahle committed Nov 5, 2024
1 parent 4314c5f commit 5917430
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pkg/network/ebpf/c/tracer/events.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ static __always_inline void cleanup_conn(void *ctx, conn_tuple_t *tup, struct so
conn.tup.pid = 0;
retrans = bpf_map_lookup_elem(&tcp_retransmits, &(conn.tup));
if (retrans) {
conn.tcp_retransmits = *retrans;
conn.tcp_stats.retransmits = *retrans;
bpf_map_delete_elem(&tcp_retransmits, &(conn.tup));
}
conn.tup.pid = tup->pid;
Expand Down
5 changes: 3 additions & 2 deletions pkg/network/ebpf/c/tracer/tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ typedef enum {
typedef struct {
__u32 rtt;
__u32 rtt_var;
__u32 retransmits;

// Bit mask containing all TCP state transitions tracked by our tracer
__u16 state_transitions;
Expand All @@ -74,9 +75,9 @@ typedef struct {
// Full data for a tcp connection
typedef struct {
conn_tuple_t tup;
conn_stats_ts_t conn_stats;
// move tcp_stats here to align conn_stats on a cacheline boundary
tcp_stats_t tcp_stats;
__u32 tcp_retransmits;
conn_stats_ts_t conn_stats;
} conn_t;

typedef struct {
Expand Down
8 changes: 4 additions & 4 deletions pkg/network/ebpf/kprobe_types_linux.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions pkg/network/tracer/connection/ebpf_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,10 @@ func (t *ebpfTracer) GetConnections(buffer *network.ConnectionBuffer, filter fun
}

if t.getTCPStats(tcp, key) {
updateTCPStats(conn, tcp, 0)
updateTCPStats(conn, tcp)
}
if retrans, ok := t.getTCPRetransmits(key, seen); ok {
updateTCPStats(conn, nil, retrans)
if retrans, ok := t.getTCPRetransmits(key, seen); ok && conn.Type == network.TCP {
conn.Monotonic.Retransmits = retrans
}

*buffer.Next() = *conn
Expand Down Expand Up @@ -791,13 +791,13 @@ func populateConnStats(stats *network.ConnectionStats, t *netebpf.ConnTuple, s *
}
}

func updateTCPStats(conn *network.ConnectionStats, tcpStats *netebpf.TCPStats, retransmits uint32) {
func updateTCPStats(conn *network.ConnectionStats, tcpStats *netebpf.TCPStats) {
if conn.Type != network.TCP {
return
}

conn.Monotonic.Retransmits = retransmits
if tcpStats != nil {
conn.Monotonic.Retransmits = tcpStats.Retransmits
conn.Monotonic.TCPEstablished = tcpStats.State_transitions >> netebpf.Established & 1
conn.Monotonic.TCPClosed = tcpStats.State_transitions >> netebpf.Close & 1
conn.RTT = tcpStats.Rtt
Expand Down
4 changes: 2 additions & 2 deletions pkg/network/tracer/connection/perf_batching.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (p *perfBatchManager) ExtractBatchInto(buffer *network.ConnectionBuffer, b
for rc := p.extractor.NextConnection(b); rc != nil; rc = p.extractor.NextConnection(b) {
conn := buffer.Next()
populateConnStats(conn, &rc.Tup, &rc.Conn_stats, p.ch)
updateTCPStats(conn, &rc.Tcp_stats, rc.Tcp_retransmits)
updateTCPStats(conn, &rc.Tcp_stats)
}
}

Expand All @@ -80,7 +80,7 @@ func (p *perfBatchManager) GetPendingConns(buffer *network.ConnectionBuffer) {
for rc := p.extractor.NextConnection(b); rc != nil; rc = p.extractor.NextConnection(b) {
c := buffer.Next()
populateConnStats(c, &rc.Tup, &rc.Conn_stats, p.ch)
updateTCPStats(c, &rc.Tcp_stats, rc.Tcp_retransmits)
updateTCPStats(c, &rc.Tcp_stats)
}
}
p.extractor.CleanupExpiredState(time.Now())
Expand Down
2 changes: 1 addition & 1 deletion pkg/network/tracer/connection/tcp_close_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (c *tcpCloseConsumer) extractConn(data []byte) {
ct := (*netebpf.Conn)(unsafe.Pointer(&data[0]))
conn := c.buffer.Next()
populateConnStats(conn, &ct.Tup, &ct.Conn_stats, c.ch)
updateTCPStats(conn, &ct.Tcp_stats, ct.Tcp_retransmits)
updateTCPStats(conn, &ct.Tcp_stats)
}

func (c *tcpCloseConsumer) Start(callback func(*network.ConnectionStats)) {
Expand Down

0 comments on commit 5917430

Please sign in to comment.