Skip to content

Commit

Permalink
Importing all files for v0.4.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
b-pujari committed Feb 3, 2023
1 parent 3efc3b0 commit 8ae8cc6
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 43 deletions.
13 changes: 13 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@

# Changes to TCP-INT in version 0.4.0-alpha

## New features

* Link speed
* Available bandwidth

## Optimizations

* New Version option to display currently running tcp-int version
* Removed link utilzation feature

# Changes to TCP-INT in version 0.3.0-alpha

## New features
Expand Down
1 change: 1 addition & 0 deletions code/include/tcp_int_common.bpf.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct tcp_int_state {
tcp_int_id idecr; /* ID to be echoed back (network order) */
__u32 qdepth; /* Queue depth in data path */
tcp_int_latecr hoplatecr; /* Sum of hop latencies on data path */
__u8 linkspeedecr; /* Link speed to be echoed back */
};

/* Attaches INT state to socket */
Expand Down
44 changes: 31 additions & 13 deletions code/include/tcp_int_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
#define TCP_INT_BYTES_IN_KBYTE 1024
#define TCP_INT_HIST_MAX_SLOTS 256
#define TCP_INT_MAX_PERID_HISTS (TCP_INT_TTL_INIT + 1)
#define TCP_INT_MAX_UTIL_PERCENT 100
#define TCP_INT_MAX_UTIL_SCALED 0x7f
#define TCP_INT_MIN_QDEPTH_SCALED 0x80
#define TCP_INT_MAX_CGROUP_PATH_LEN 128
#define TCP_INT_SKBLEN_BITSHIFT 8
Expand Down Expand Up @@ -52,7 +50,7 @@
* N.B. Because IdEcr is 4 bits (and 0 indicates uninitialized), it cannot be
* used for paths longer than 15 hops.
*/
#define tcp_int_id_to_idecr(x) (TCP_INT_TTL_INIT - (x) + 1)
#define tcp_int_id_to_idecr(x) (TCP_INT_TTL_INIT - (x))

struct tcp_int_event {
__u64 ts_us;
Expand All @@ -79,17 +77,18 @@ struct tcp_int_event {
tcp_int_id hid;
__u32 hoplat;
__u32 return_hoplat;
__u32 total_retrans;
__u32 segs_out;
__u64 bytes_acked;
__u32 total_retrans;
__u8 link_speed;
} __attribute__((packed));
;

enum tcp_int_hist_type {
TCP_INT_HIST_TYPE_SRTT = 0,
TCP_INT_HIST_TYPE_CWND,
TCP_INT_HIST_TYPE_HID,
TCP_INT_HIST_TYPE_UTIL,
TCP_INT_HIST_TYPE_AVAILBW,
TCP_INT_HIST_TYPE_QDEPTH,
TCP_INT_HIST_TYPE_HLAT,
TCP_INT_HIST_TYPE_RXSKBLEN,
Expand Down Expand Up @@ -125,24 +124,43 @@ static inline bool tcp_int_ival_is_qdepth(tcp_int_val ival)
return (ival >= TCP_INT_MIN_QDEPTH_SCALED);
}

static inline __u32 tcp_int_ival_to_util_scaled(tcp_int_val ival)
static inline __u32 tcp_int_ival_to_qdepth_scaled(tcp_int_val ival)
{
return tcp_int_ival_is_qdepth(ival) ? TCP_INT_MAX_UTIL_SCALED : ival;
return tcp_int_ival_is_qdepth(ival) ? (ival & TCP_INT_MIN_AVAILBW_SCALED)
: 0;
}

static inline __u32 tcp_int_ival_to_qdepth_scaled(tcp_int_val ival)
static inline __u32 tcp_int_ival_to_qdepth(tcp_int_val ival)
{
return tcp_int_ival_is_qdepth(ival) ? (ival & TCP_INT_MAX_UTIL_SCALED) : 0;
return tcp_int_ival_to_qdepth_scaled(ival) << TCP_INT_QDEPTH_BITSHIFT;
}

static inline __u32 tcp_int_ival_to_util(tcp_int_val ival)
static inline __u32 tcp_int_ival_to_avail_bw(tcp_int_val ival)
{
return tcp_int_ival_is_qdepth(ival) ? 100 : (ival << TCP_INT_UTIL_BITSHIFT);
return tcp_int_ival_is_qdepth(ival) ? 0
: (TCP_INT_MIN_AVAILBW_SCALED - ival);
}

static inline __u32 tcp_int_ival_to_qdepth(tcp_int_val ival)
static inline __u32 tcp_int_unmap_link_speed(__u8 mapped_link_speed)
{
return tcp_int_ival_to_qdepth_scaled(ival) << TCP_INT_QDEPTH_BITSHIFT;
switch (mapped_link_speed) {
case 1:
return 10;
case 2:
return 25;
case 3:
return 40;
case 4:
return 50;
case 5:
return 100;
case 6:
return 200;
case 7:
return 400;
default:
return 0;
}
}

#endif /* __TCP_INT_COMMON_H */
2 changes: 1 addition & 1 deletion code/include/tcp_int_opt.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ typedef __u16 tcp_int_latecr;
#define TCP_INT_UTIL_BITSHIFT 3
#define TCP_INT_QDEPTH_BITSHIFT 13
#define TCP_INT_HLAT_BITSHIFT 8
#define TCP_INT_MAX_UTIL_SCALED 0x7f
#define TCP_INT_MIN_AVAILBW_SCALED 0x7f
#define TCP_INT_MIN_QDEPTH_SCALED 0x80
#define TCP_INT_TTL_INIT 64
#define TCP_INT_MAX_SKBLEN 65536
Expand Down
12 changes: 10 additions & 2 deletions code/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,22 @@ BPF_OBJS = $(@:.skel.h=.bpf.o)
PREFIX ?= /usr/local
INSTALLPATH = $(PREFIX)/lib/bpf/tcp-int
LIBS = -lbpf

GIT_COMPILE_TIME := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
GIT_VERSION := "$(shell git describe --abbrev=12 --tags)"
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
CC := gcc
CFLAGS :=-DTCP_INT_NUM_CPUS=$(shell nproc --all)

CFLAGS += -DTCP_INT_NUM_CPUS=$(shell nproc --all)

export VERSION_FLAGS=-DGIT_VERSION="\"$(GIT_VERSION)\"" -DGIT_COMPILE_TIME="\"$(GIT_COMPILE_TIME)\"" -DGIT_BRANCH="\"$(GIT_BRANCH)\""

.PHONY: clean

all: $(USER_TARGETS)

$(USER_TARGETS): %: %.c $(wildcard ../include/*.h) $(SKELETON_HEADERS)
$(CC) -Wall $(CFLAGS) $(LDFLAGS) -I../include -I. -o $@ $< $(LIBS)
$(CC) -Wall $(CFLAGS) $(VERSION_FLAGS) $(LDFLAGS) -I../include -I. -o $@ $< $(LIBS)

$(SKELETON_HEADERS): %.skel.h: %.bpf.c $(wildcard ../include/*.h)
$(eval $@_BPF_OBJ := $(@:.skel.h=.bpf.o))
Expand Down
7 changes: 5 additions & 2 deletions code/src/bpf/tcp_int.bpf.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ static inline void tcp_int_add_tcpopt(struct bpf_sock_ops *skops,
iopt.intvalecr = istate->intvalecr;
iopt.idecr = istate->idecr;
iopt.hoplatecr = istate->hoplatecr;
iopt.linkspeedecr = istate->linkspeedecr;

#if TCP_INT_ENABLE_DYNAMIC_TAGGING
if (skops->packets_out < 1)
Expand Down Expand Up @@ -159,8 +160,8 @@ static void tcp_int_update_hists(struct bpf_sock_ops *skops,
val = skops->snd_cwnd;
linear = false;
break;
case TCP_INT_HIST_TYPE_UTIL:
val = tcp_int_ival_to_util_scaled(iopt->intvalecr);
case TCP_INT_HIST_TYPE_AVAILBW:
val = tcp_int_ival_to_avail_bw(iopt->intvalecr);
linear = true;
break;
case TCP_INT_HIST_TYPE_QDEPTH:
Expand Down Expand Up @@ -212,6 +213,7 @@ static void tcp_int_send_event(struct bpf_sock_ops *skops,
event.segs_out = skops->segs_out;
event.bytes_acked = skops->bytes_acked;
event.total_retrans = skops->total_retrans;
event.link_speed = iopt->linkspeedecr;
bpf_perf_event_output(skops, &map_tcp_int_events, BPF_F_CURRENT_CPU, &event,
sizeof(event));
}
Expand Down Expand Up @@ -269,6 +271,7 @@ static inline void tcp_int_process_tcpopt(struct bpf_sock_ops *skops,
istate->idecr = tcp_int_id_to_idecr(iopt.id);
istate->hoplatecr =
tcp_int_hoplat_to_hoplatecr(be24tohl(iopt.hoplat.u24));
istate->linkspeedecr = iopt.linkspeed;
istate->pending_ecr = true;
}

Expand Down
53 changes: 30 additions & 23 deletions code/src/tools/tcp_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ static const char *tcp_int_doc =
"start histograming (INT-related histograms)\n"
" tcp_int hist-int-perid # Enables tcp-int and "
"start histograming (INT-related histograms per hop ID)\n"
" tcp_int hist-[rtt,cwnd,qdepth,util,hoplat,\n"
" hid,rxskblen,txskblen] # Enables tcp-int and "
" tcp_int hist-[rtt,cwnd,qdepth,util,availbw,\n"
" hoplat,hid,rxskblen,txskblen] # Enables tcp-int and "
"start histograming (selected histogram)\n"
" tcp_int ecr-enable # Enables echo replies "
"(default = enabled)\n"
Expand All @@ -55,6 +55,8 @@ static const char *tcp_int_doc =
"BPF programs\n"
" tcp_int unload -d # Unloads all tcp_int "
"BPF programs with debug enabled\n"
" tcp_int version # Prints compile time, "
"version and current branch name"
" tcp_int help # Prints help "
"message\n";

Expand Down Expand Up @@ -468,6 +470,13 @@ static int tcp_int_unload(void)
return err;
}

static void tcp_int_version(void)
{
printf("Compile time: %s\n", GIT_COMPILE_TIME);
printf("Version: %s\n", GIT_VERSION);
printf("Branch: %s\n", GIT_BRANCH);
}

static int tcp_int_load(const char *cg_path)
{
struct tcp_int_bpf *tcp_int_obj;
Expand Down Expand Up @@ -583,14 +592,14 @@ static void tcp_int_handle_event(void *ctx, int cpu, void *data, __u32 data_sz)

inet_ntop(e->family, &e->saddr, saddr, sizeof(saddr));
inet_ntop(e->family, &e->daddr, daddr, sizeof(daddr));
printf("%11.6f, %15s:%5d, %15s:%5d, %8d, %8d, %6d, %8lld, %7u, %12u, %9f, "
"%3d, %11d, %21lld\n",
printf("%11.6f, %15s:%5d, %15s:%5d, %8d, %8d, %6d, %8lld, %14d, %8u, %9f, "
"%3d, %11d, %21lld, %10d\n",
(e->ts_us - start_ts) / 1000000.0, saddr, e->sport, daddr, e->dport,
(e->srtt_us >> 3), (e->snd_cwnd * e->mss), e->total_retrans,
tcp_int_get_tp(e), tcp_int_ival_to_util(e->intval),
tcp_int_get_tp(e), (tcp_int_ival_to_avail_bw(e->intval) * 1000),
tcp_int_ival_to_qdepth(e->intval),
tcp_int_hoplatecr_to_ns(e->hoplat) / 1000.0, e->hid, e->segs_out,
e->bytes_acked);
e->bytes_acked, tcp_int_unmap_link_speed(e->link_speed));
}

static void tcp_int_handle_lost_events(void *ctx, int cpu, __u64 lost_cnt)
Expand Down Expand Up @@ -672,8 +681,6 @@ static void tcp_int_print_hist(struct tcp_int_hist *hist,
enum tcp_int_hist_type type)
{
float pstep;
float step;
float cnt;

printf("\n");
switch (type) {
Expand All @@ -683,11 +690,9 @@ static void tcp_int_print_hist(struct tcp_int_hist *hist,
case TCP_INT_HIST_TYPE_CWND:
print_log2_hist(hist->slots, TCP_INT_HIST_MAX_SLOTS, -1, "CWND [pkts]");
break;
case TCP_INT_HIST_TYPE_UTIL:
cnt = (TCP_INT_MAX_UTIL_PERCENT >> TCP_INT_UTIL_BITSHIFT) + 1;
step = TCP_INT_MAX_UTIL_PERCENT / cnt;
print_linear_hist(hist->slots, TCP_INT_HIST_MAX_SLOTS, 0, step, 0,
cnt - 1, "BW UTIL. [\%]", false);
case TCP_INT_HIST_TYPE_AVAILBW:
print_linear_hist(hist->slots, TCP_INT_HIST_MAX_SLOTS, 0, 1, 0, -1,
"AVAIL BW[Gbps]", false);
break;
case TCP_INT_HIST_TYPE_QDEPTH:
print_log2_hist(hist->slots, TCP_INT_HIST_MAX_SLOTS, -1, "QDEPTH [KB]");
Expand Down Expand Up @@ -737,10 +742,10 @@ static int tcp_int_print_hists_perid(enum tcp_int_hist_type type_min,
break;
}
if (j == type_min) {
printf("\n\n-- SWITCH HOP %02d "
printf("\n\n-- SWITCH HOP %2d "
"-------------------------------------------------------"
"------",
(1 + TCP_INT_TTL_INIT - i));
i);
}
tcp_int_print_hist(&hists.hist[i], j);
}
Expand Down Expand Up @@ -809,11 +814,11 @@ static int tcp_int_trace(void)

printf("Tracing TCP-INT... Hit Ctrl-C to end.\n");

printf("%11s, %15s:%5s, %15s:%5s, %8s, %8s, %6s, %8s, %7s, %12s, %9s, %3s, "
"%11s, %21s\n\n",
printf("%11s, %15s:%5s, %15s:%5s, %8s, %8s, %6s, %8s, %14s, %8s, %9s, %3s, "
"%11s, %21s, %8s\n\n",
"TIME(s)", "SIP", "SPORT", "DIP", "DPORT", "SRTT(US)", "CWND(B)",
"LOST", "TP(MB/s)", "UTIL(\%)", "QDEPTH(B)", "HLAT(us)", "HID",
"SOUT", "BA");
"LOST", "TP(MB/s)", "AVAILBW(Mb/s)", "QDEPTH(B)", "HLAT(us)", "HID",
"SOUT", "BA", "LINKSPEED(Gb/s)");

while (!tcp_int_exiting) {
err = perf_buffer__poll(pb, TCP_INT_PERF_POLL_TIMEOUT_MS);
Expand Down Expand Up @@ -926,14 +931,14 @@ int main(int argc, char **argv)
rv = tcp_int_hist(TCP_INT_HIST_TYPE_HID, TCP_INT_HIST_TYPE_QDEPTH,
false);
} else if (!strcmp(argv[1], "hist-int-perid")) {
rv = tcp_int_hist(TCP_INT_HIST_TYPE_UTIL, TCP_INT_HIST_TYPE_QDEPTH,
rv = tcp_int_hist(TCP_INT_HIST_TYPE_AVAILBW, TCP_INT_HIST_TYPE_QDEPTH,
true);
} else if (!strcmp(argv[1], "hist-qdepth")) {
rv = tcp_int_hist(TCP_INT_HIST_TYPE_QDEPTH, TCP_INT_HIST_TYPE_QDEPTH,
false);
} else if (!strcmp(argv[1], "hist-util")) {
rv =
tcp_int_hist(TCP_INT_HIST_TYPE_UTIL, TCP_INT_HIST_TYPE_UTIL, false);
} else if (!strcmp(argv[1], "hist-availbw")) {
rv = tcp_int_hist(TCP_INT_HIST_TYPE_AVAILBW, TCP_INT_HIST_TYPE_AVAILBW,
false);
} else if (!strcmp(argv[1], "hist-hoplat")) {
rv =
tcp_int_hist(TCP_INT_HIST_TYPE_HLAT, TCP_INT_HIST_TYPE_HLAT, false);
Expand All @@ -953,6 +958,8 @@ int main(int argc, char **argv)
rv = tcp_int_events_enable(true);
} else if (!strcmp(argv[1], "events-disable")) {
rv = tcp_int_events_enable(false);
} else if (!strcmp(argv[1], "version")) {
tcp_int_version();
} else {
show_help();
}
Expand Down
2 changes: 2 additions & 0 deletions code/tcp-int-exporter/src/models/proto/exporter.proto
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ message TcpIntMsg {
uint64 bytes_acked = 24; //number of bytes acked
uint32 total_retrans = 25; //total lost packets(cumulative)
optional uint32 hop_id = 26;
uint32 available_bandwidth = 27; //units: MB/s
uint32 link_speed = 28; //units: Gb/s
}

message TcpIntMsgs {
Expand Down
11 changes: 10 additions & 1 deletion code/tcp-int-exporter/src/tcp_int_exporter/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
# Copyright 2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

GIT_VERSION := $(shell git describe --abbrev=12 --tags)
GIT_COMPILE_TIME := $(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)

GOLDFLAGS += -X main.version=$(GIT_VERSION)
GOLDFLAGS += -X main.compileTime=$(GIT_COMPILE_TIME)
GOLDFLAGS += -X main.gitBranch=$(GIT_BRANCH)
GOFLAGS = -ldflags "$(GOLDFLAGS)"

USER_TARGETS = tcp_int_exporter

PREFIX ?= /usr/local
Expand All @@ -13,7 +22,7 @@ clean:
rm -f $(USER_TARGETS)

build:
go build -o tcp_int_exporter
go build -o tcp_int_exporter $(GOFLAGS)

install: $(USER_TARGETS)
install -d $(INSTALLPATH)
Expand Down
7 changes: 7 additions & 0 deletions code/tcp-int-exporter/src/tcp_int_exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ var (
timeout time.Duration
useTls bool
caCert string
version string
compileTime string
gitBranch string
)

func main() {
Expand All @@ -43,6 +46,10 @@ func main() {
flag.StringVar(&caCert, "ca-cert", "/ets/ssl/certs/tcp_int_ca_cert.pem", "Certificate of the CA that signed the collector's cert")
flag.Parse()

log.Printf("Compile Time: %s\n", compileTime)
log.Printf("Version: %s\n", version)
log.Printf("Git Branch: %s\n", gitBranch)

if useTls && !secure.IsValidCert(caCert) {
log.Fatalf("CA certificate '%s' does not appear to be a valid PEM certificate file", caCert)
}
Expand Down
Loading

0 comments on commit 8ae8cc6

Please sign in to comment.