summaryrefslogtreecommitdiffstatshomepage
path: root/samples
diff options
context:
space:
mode:
authorbrakmo <brakmo@fb.com>2019-05-28 15:59:40 -0800
committerAlexei Starovoitov <ast@kernel.org>2019-05-31 15:41:29 -0800
commitd58c6f7212f4eda59ca94cbfbaa785dde7675456 (patch)
tree84c6e60b4f3ca303da138d79f55747c6222213eb /samples
parentffd81558d56c611b1e93f856c77f42046a2deab5 (diff)
downloadlinux-stable-d58c6f7212f4eda59ca94cbfbaa785dde7675456.tar.gz
linux-stable-d58c6f7212f4eda59ca94cbfbaa785dde7675456.tar.bz2
linux-stable-d58c6f7212f4eda59ca94cbfbaa785dde7675456.tar.xz
linux-stable-d58c6f7212f4eda59ca94cbfbaa785dde7675456.zip
bpf: Add more stats to HBM
Adds more stats to HBM, including average cwnd and rtt of all TCP flows, percents of packets that are ecn ce marked and distribution of return values. Signed-off-by: Lawrence Brakmo <brakmo@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'samples')
-rw-r--r--samples/bpf/hbm.c33
-rw-r--r--samples/bpf/hbm.h6
-rw-r--r--samples/bpf/hbm_kern.h66
-rw-r--r--samples/bpf/hbm_out_kern.c22
4 files changed, 117 insertions, 10 deletions
diff --git a/samples/bpf/hbm.c b/samples/bpf/hbm.c
index c5629bae67ab..480b7ad6a1f2 100644
--- a/samples/bpf/hbm.c
+++ b/samples/bpf/hbm.c
@@ -316,6 +316,14 @@ static int run_bpf_prog(char *prog, int cg_id)
316 double percent_pkts, percent_bytes; 316 double percent_pkts, percent_bytes;
317 char fname[100]; 317 char fname[100];
318 FILE *fout; 318 FILE *fout;
319 int k;
320 static const char *returnValNames[] = {
321 "DROP_PKT",
322 "ALLOW_PKT",
323 "DROP_PKT_CWR",
324 "ALLOW_PKT_CWR"
325 };
326#define RET_VAL_COUNT 4
319 327
320// Future support of ingress 328// Future support of ingress
321// if (!outFlag) 329// if (!outFlag)
@@ -350,6 +358,31 @@ static int run_bpf_prog(char *prog, int cg_id)
350 (qstats.bytes_total + 1); 358 (qstats.bytes_total + 1);
351 fprintf(fout, "pkts_dropped_percent:%6.2f\n", percent_pkts); 359 fprintf(fout, "pkts_dropped_percent:%6.2f\n", percent_pkts);
352 fprintf(fout, "bytes_dropped_percent:%6.2f\n", percent_bytes); 360 fprintf(fout, "bytes_dropped_percent:%6.2f\n", percent_bytes);
361
362 // ECN CE markings
363 percent_pkts = (qstats.pkts_ecn_ce * 100.0) /
364 (qstats.pkts_total + 1);
365 fprintf(fout, "pkts_ecn_ce:%6.2f (%d)\n", percent_pkts,
366 (int)qstats.pkts_ecn_ce);
367
368 // Average cwnd
369 fprintf(fout, "avg cwnd:%d\n",
370 (int)(qstats.sum_cwnd / (qstats.sum_cwnd_cnt + 1)));
371 // Average rtt
372 fprintf(fout, "avg rtt:%d\n",
373 (int)(qstats.sum_rtt / (qstats.pkts_total + 1)));
374 // Average credit
375 fprintf(fout, "avg credit:%d\n",
376 (int)(qstats.sum_credit /
377 (1500 * ((int)qstats.pkts_total) + 1)));
378
379 // Return values stats
380 for (k = 0; k < RET_VAL_COUNT; k++) {
381 percent_pkts = (qstats.returnValCount[k] * 100.0) /
382 (qstats.pkts_total + 1);
383 fprintf(fout, "%s:%6.2f (%d)\n", returnValNames[k],
384 percent_pkts, (int)qstats.returnValCount[k]);
385 }
353 fclose(fout); 386 fclose(fout);
354 } 387 }
355 388
diff --git a/samples/bpf/hbm.h b/samples/bpf/hbm.h
index c08247cec2a7..f0963ed6a562 100644
--- a/samples/bpf/hbm.h
+++ b/samples/bpf/hbm.h
@@ -29,4 +29,10 @@ struct hbm_queue_stats {
29 unsigned long long bytes_total; 29 unsigned long long bytes_total;
30 unsigned long long firstPacketTime; 30 unsigned long long firstPacketTime;
31 unsigned long long lastPacketTime; 31 unsigned long long lastPacketTime;
32 unsigned long long pkts_ecn_ce;
33 unsigned long long returnValCount[4];
34 unsigned long long sum_cwnd;
35 unsigned long long sum_rtt;
36 unsigned long long sum_cwnd_cnt;
37 long long sum_credit;
32}; 38};
diff --git a/samples/bpf/hbm_kern.h b/samples/bpf/hbm_kern.h
index 41384be233b9..be19cf1d5cd5 100644
--- a/samples/bpf/hbm_kern.h
+++ b/samples/bpf/hbm_kern.h
@@ -65,17 +65,43 @@ struct bpf_map_def SEC("maps") queue_stats = {
65BPF_ANNOTATE_KV_PAIR(queue_stats, int, struct hbm_queue_stats); 65BPF_ANNOTATE_KV_PAIR(queue_stats, int, struct hbm_queue_stats);
66 66
67struct hbm_pkt_info { 67struct hbm_pkt_info {
68 int cwnd;
69 int rtt;
68 bool is_ip; 70 bool is_ip;
69 bool is_tcp; 71 bool is_tcp;
70 short ecn; 72 short ecn;
71}; 73};
72 74
75static int get_tcp_info(struct __sk_buff *skb, struct hbm_pkt_info *pkti)
76{
77 struct bpf_sock *sk;
78 struct bpf_tcp_sock *tp;
79
80 sk = skb->sk;
81 if (sk) {
82 sk = bpf_sk_fullsock(sk);
83 if (sk) {
84 if (sk->protocol == IPPROTO_TCP) {
85 tp = bpf_tcp_sock(sk);
86 if (tp) {
87 pkti->cwnd = tp->snd_cwnd;
88 pkti->rtt = tp->srtt_us >> 3;
89 return 0;
90 }
91 }
92 }
93 }
94 return 1;
95}
96
73static __always_inline void hbm_get_pkt_info(struct __sk_buff *skb, 97static __always_inline void hbm_get_pkt_info(struct __sk_buff *skb,
74 struct hbm_pkt_info *pkti) 98 struct hbm_pkt_info *pkti)
75{ 99{
76 struct iphdr iph; 100 struct iphdr iph;
77 struct ipv6hdr *ip6h; 101 struct ipv6hdr *ip6h;
78 102
103 pkti->cwnd = 0;
104 pkti->rtt = 0;
79 bpf_skb_load_bytes(skb, 0, &iph, 12); 105 bpf_skb_load_bytes(skb, 0, &iph, 12);
80 if (iph.version == 6) { 106 if (iph.version == 6) {
81 ip6h = (struct ipv6hdr *)&iph; 107 ip6h = (struct ipv6hdr *)&iph;
@@ -91,6 +117,8 @@ static __always_inline void hbm_get_pkt_info(struct __sk_buff *skb,
91 pkti->is_tcp = false; 117 pkti->is_tcp = false;
92 pkti->ecn = 0; 118 pkti->ecn = 0;
93 } 119 }
120 if (pkti->is_tcp)
121 get_tcp_info(skb, pkti);
94} 122}
95 123
96static __always_inline void hbm_init_vqueue(struct hbm_vqueue *qdp, int rate) 124static __always_inline void hbm_init_vqueue(struct hbm_vqueue *qdp, int rate)
@@ -105,8 +133,14 @@ static __always_inline void hbm_update_stats(struct hbm_queue_stats *qsp,
105 int len, 133 int len,
106 unsigned long long curtime, 134 unsigned long long curtime,
107 bool congestion_flag, 135 bool congestion_flag,
108 bool drop_flag) 136 bool drop_flag,
137 bool cwr_flag,
138 bool ecn_ce_flag,
139 struct hbm_pkt_info *pkti,
140 int credit)
109{ 141{
142 int rv = ALLOW_PKT;
143
110 if (qsp != NULL) { 144 if (qsp != NULL) {
111 // Following is needed for work conserving 145 // Following is needed for work conserving
112 __sync_add_and_fetch(&(qsp->bytes_total), len); 146 __sync_add_and_fetch(&(qsp->bytes_total), len);
@@ -116,7 +150,7 @@ static __always_inline void hbm_update_stats(struct hbm_queue_stats *qsp,
116 qsp->firstPacketTime = curtime; 150 qsp->firstPacketTime = curtime;
117 qsp->lastPacketTime = curtime; 151 qsp->lastPacketTime = curtime;
118 __sync_add_and_fetch(&(qsp->pkts_total), 1); 152 __sync_add_and_fetch(&(qsp->pkts_total), 1);
119 if (congestion_flag || drop_flag) { 153 if (congestion_flag) {
120 __sync_add_and_fetch(&(qsp->pkts_marked), 1); 154 __sync_add_and_fetch(&(qsp->pkts_marked), 1);
121 __sync_add_and_fetch(&(qsp->bytes_marked), len); 155 __sync_add_and_fetch(&(qsp->bytes_marked), len);
122 } 156 }
@@ -125,6 +159,34 @@ static __always_inline void hbm_update_stats(struct hbm_queue_stats *qsp,
125 __sync_add_and_fetch(&(qsp->bytes_dropped), 159 __sync_add_and_fetch(&(qsp->bytes_dropped),
126 len); 160 len);
127 } 161 }
162 if (ecn_ce_flag)
163 __sync_add_and_fetch(&(qsp->pkts_ecn_ce), 1);
164 if (pkti->cwnd) {
165 __sync_add_and_fetch(&(qsp->sum_cwnd),
166 pkti->cwnd);
167 __sync_add_and_fetch(&(qsp->sum_cwnd_cnt), 1);
168 }
169 if (pkti->rtt)
170 __sync_add_and_fetch(&(qsp->sum_rtt),
171 pkti->rtt);
172 __sync_add_and_fetch(&(qsp->sum_credit), credit);
173
174 if (drop_flag)
175 rv = DROP_PKT;
176 if (cwr_flag)
177 rv |= 2;
178 if (rv == DROP_PKT)
179 __sync_add_and_fetch(&(qsp->returnValCount[0]),
180 1);
181 else if (rv == ALLOW_PKT)
182 __sync_add_and_fetch(&(qsp->returnValCount[1]),
183 1);
184 else if (rv == 2)
185 __sync_add_and_fetch(&(qsp->returnValCount[2]),
186 1);
187 else if (rv == 3)
188 __sync_add_and_fetch(&(qsp->returnValCount[3]),
189 1);
128 } 190 }
129 } 191 }
130} 192}
diff --git a/samples/bpf/hbm_out_kern.c b/samples/bpf/hbm_out_kern.c
index fa3ea92e1564..829934bd43cb 100644
--- a/samples/bpf/hbm_out_kern.c
+++ b/samples/bpf/hbm_out_kern.c
@@ -62,11 +62,12 @@ int _hbm_out_cg(struct __sk_buff *skb)
62 unsigned int queue_index = 0; 62 unsigned int queue_index = 0;
63 unsigned long long curtime; 63 unsigned long long curtime;
64 int credit; 64 int credit;
65 signed long long delta = 0, zero = 0; 65 signed long long delta = 0, new_credit;
66 int max_credit = MAX_CREDIT; 66 int max_credit = MAX_CREDIT;
67 bool congestion_flag = false; 67 bool congestion_flag = false;
68 bool drop_flag = false; 68 bool drop_flag = false;
69 bool cwr_flag = false; 69 bool cwr_flag = false;
70 bool ecn_ce_flag = false;
70 struct hbm_vqueue *qdp; 71 struct hbm_vqueue *qdp;
71 struct hbm_queue_stats *qsp = NULL; 72 struct hbm_queue_stats *qsp = NULL;
72 int rv = ALLOW_PKT; 73 int rv = ALLOW_PKT;
@@ -99,9 +100,11 @@ int _hbm_out_cg(struct __sk_buff *skb)
99 */ 100 */
100 if (delta > 0) { 101 if (delta > 0) {
101 qdp->lasttime = curtime; 102 qdp->lasttime = curtime;
102 credit += CREDIT_PER_NS(delta, qdp->rate); 103 new_credit = credit + CREDIT_PER_NS(delta, qdp->rate);
103 if (credit > MAX_CREDIT) 104 if (new_credit > MAX_CREDIT)
104 credit = MAX_CREDIT; 105 credit = MAX_CREDIT;
106 else
107 credit = new_credit;
105 } 108 }
106 credit -= len; 109 credit -= len;
107 qdp->credit = credit; 110 qdp->credit = credit;
@@ -139,7 +142,9 @@ int _hbm_out_cg(struct __sk_buff *skb)
139 } 142 }
140 143
141 if (congestion_flag) { 144 if (congestion_flag) {
142 if (!bpf_skb_ecn_set_ce(skb)) { 145 if (bpf_skb_ecn_set_ce(skb)) {
146 ecn_ce_flag = true;
147 } else {
143 if (pkti.is_tcp) { 148 if (pkti.is_tcp) {
144 unsigned int rand = bpf_get_prandom_u32(); 149 unsigned int rand = bpf_get_prandom_u32();
145 150
@@ -155,16 +160,17 @@ int _hbm_out_cg(struct __sk_buff *skb)
155 } 160 }
156 } 161 }
157 162
158 if (drop_flag)
159 rv = DROP_PKT;
160 if (qsp != NULL) 163 if (qsp != NULL)
161 if (qsp->no_cn) 164 if (qsp->no_cn)
162 cwr_flag = false; 165 cwr_flag = false;
163 166
164 hbm_update_stats(qsp, len, curtime, congestion_flag, drop_flag); 167 hbm_update_stats(qsp, len, curtime, congestion_flag, drop_flag,
168 cwr_flag, ecn_ce_flag, &pkti, credit);
165 169
166 if (rv == DROP_PKT) 170 if (drop_flag) {
167 __sync_add_and_fetch(&(qdp->credit), len); 171 __sync_add_and_fetch(&(qdp->credit), len);
172 rv = DROP_PKT;
173 }
168 174
169 if (cwr_flag) 175 if (cwr_flag)
170 rv |= 2; 176 rv |= 2;