summaryrefslogtreecommitdiff
path: root/samples/bpf/hbm_out_kern.c
diff options
context:
space:
mode:
authorbrakmo <brakmo@fb.com>2019-05-29 02:59:39 +0300
committerAlexei Starovoitov <ast@kernel.org>2019-06-01 02:41:29 +0300
commitffd81558d56c611b1e93f856c77f42046a2deab5 (patch)
treef3c30120e3d5afdf625d155ea139b9851a2b2104 /samples/bpf/hbm_out_kern.c
parent956fe2190820df3a6ee530204e059da508159319 (diff)
downloadlinux-ffd81558d56c611b1e93f856c77f42046a2deab5.tar.xz
bpf: Add cn support to hbm_out_kern.c
Update hbm_out_kern.c to support returning cn notifications. Also updates relevant files to allow disabling cn notifications. Signed-off-by: Lawrence Brakmo <brakmo@fb.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Diffstat (limited to 'samples/bpf/hbm_out_kern.c')
-rw-r--r--samples/bpf/hbm_out_kern.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/samples/bpf/hbm_out_kern.c b/samples/bpf/hbm_out_kern.c
index f806863d0b79..fa3ea92e1564 100644
--- a/samples/bpf/hbm_out_kern.c
+++ b/samples/bpf/hbm_out_kern.c
@@ -119,13 +119,16 @@ int _hbm_out_cg(struct __sk_buff *skb)
// Set flags (drop, congestion, cwr)
// Dropping => we are congested, so ignore congestion flag
if (credit < -DROP_THRESH ||
- (len > LARGE_PKT_THRESH &&
- credit < -LARGE_PKT_DROP_THRESH)) {
- // Very congested, set drop flag
+ (len > LARGE_PKT_THRESH && credit < -LARGE_PKT_DROP_THRESH)) {
+ // Very congested, set drop packet
drop_flag = true;
+ if (pkti.ecn)
+ congestion_flag = true;
+ else if (pkti.is_tcp)
+ cwr_flag = true;
} else if (credit < 0) {
// Congested, set congestion flag
- if (pkti.ecn) {
+ if (pkti.ecn || pkti.is_tcp) {
if (credit < -MARK_THRESH)
congestion_flag = true;
else
@@ -137,7 +140,15 @@ int _hbm_out_cg(struct __sk_buff *skb)
if (congestion_flag) {
if (!bpf_skb_ecn_set_ce(skb)) {
- if (len > LARGE_PKT_THRESH) {
+ if (pkti.is_tcp) {
+ unsigned int rand = bpf_get_prandom_u32();
+
+ if (-credit >= MARK_THRESH +
+ (rand % MARK_REGION_SIZE)) {
+ // Do congestion control
+ cwr_flag = true;
+ }
+ } else if (len > LARGE_PKT_THRESH) {
// Problem if too many small packets?
drop_flag = true;
}
@@ -146,12 +157,17 @@ int _hbm_out_cg(struct __sk_buff *skb)
if (drop_flag)
rv = DROP_PKT;
+ if (qsp != NULL)
+ if (qsp->no_cn)
+ cwr_flag = false;
hbm_update_stats(qsp, len, curtime, congestion_flag, drop_flag);
if (rv == DROP_PKT)
__sync_add_and_fetch(&(qdp->credit), len);
+ if (cwr_flag)
+ rv |= 2;
return rv;
}
char _license[] SEC("license") = "GPL";