gfe-relnote: For QUIC BBRv2 flows, cut inflight_hi gradually when there is high loss from PROBE_UP. Protected by --gfe2_reloadable_flag_quic_bbr2_cut_inflight_hi_gradually.

I'm using CODE_COUNT instead of FLAG_COUNT, in order to observe the effect outside of canary GFEs.

PiperOrigin-RevId: 286277020
Change-Id: I55a321981bbccfc47e57426ce765a35320f708ef
diff --git a/quic/core/congestion_control/bbr2_misc.cc b/quic/core/congestion_control/bbr2_misc.cc
index 8b8e663..419238c 100644
--- a/quic/core/congestion_control/bbr2_misc.cc
+++ b/quic/core/congestion_control/bbr2_misc.cc
@@ -11,12 +11,6 @@
 
 namespace quic {
 
-namespace {
-// Sensitivity in response to losses. 0 means no loss response.
-// 0.3 is also used by TCP bbr and cubic.
-const float kBeta = 0.3;
-}  // namespace
-
 RoundTripCounter::RoundTripCounter() : round_trip_count_(0) {}
 
 void RoundTripCounter::OnPacketSent(QuicPacketNumber packet_number) {
@@ -212,12 +206,13 @@
       inflight_lo_ = congestion_event.prior_cwnd;
     }
 
-    bandwidth_lo_ = std::max(bandwidth_latest_, bandwidth_lo_ * (1.0 - kBeta));
+    bandwidth_lo_ =
+        std::max(bandwidth_latest_, bandwidth_lo_ * (1.0 - Params().beta));
     QUIC_DVLOG(3) << "bandwidth_lo_ updated to " << bandwidth_lo_
                   << ", bandwidth_latest_ is " << bandwidth_latest_;
 
-    inflight_lo_ =
-        std::max<QuicByteCount>(inflight_latest_, inflight_lo_ * (1.0 - kBeta));
+    inflight_lo_ = std::max<QuicByteCount>(
+        inflight_latest_, inflight_lo_ * (1.0 - Params().beta));
   }
 }
 
diff --git a/quic/core/congestion_control/bbr2_misc.h b/quic/core/congestion_control/bbr2_misc.h
index 760f4c9..0c5a1eb 100644
--- a/quic/core/congestion_control/bbr2_misc.h
+++ b/quic/core/congestion_control/bbr2_misc.h
@@ -151,6 +151,10 @@
   // Estimate startup/bw probing has gone too far if loss rate exceeds this.
   float loss_threshold = GetQuicFlag(FLAGS_quic_bbr2_default_loss_threshold);
 
+  // A common factor for multiplicative decreases. Used for adjusting
+  // bandwidth_lo, inflight_lo and inflight_hi upon losses.
+  float beta = 0.3;
+
   Limits<QuicByteCount> cwnd_limits;
 };
 
diff --git a/quic/core/congestion_control/bbr2_probe_bw.cc b/quic/core/congestion_control/bbr2_probe_bw.cc
index 6d5000b..ec9235b 100644
--- a/quic/core/congestion_control/bbr2_probe_bw.cc
+++ b/quic/core/congestion_control/bbr2_probe_bw.cc
@@ -9,6 +9,7 @@
 #include "net/third_party/quiche/src/quic/core/quic_bandwidth.h"
 #include "net/third_party/quiche/src/quic/core/quic_time.h"
 #include "net/third_party/quiche/src/quic/core/quic_types.h"
+#include "net/third_party/quiche/src/quic/platform/api/quic_flags.h"
 
 namespace quic {
 
@@ -160,7 +161,20 @@
 
       if (!send_state.is_app_limited) {
         QuicByteCount inflight_at_send = BytesInFlight(send_state);
-        model_->set_inflight_hi(inflight_at_send);
+        if (GetQuicReloadableFlag(quic_bbr2_cut_inflight_hi_gradually)) {
+          QuicByteCount inflight_target =
+              sender_->GetTargetBytesInflight() * (1.0 - Params().beta);
+          if (inflight_at_send >= inflight_target) {
+            // The new code does not change behavior.
+            QUIC_CODE_COUNT(quic_bbr2_cut_inflight_hi_gradually_noop);
+          } else {
+            // The new code actually cuts inflight_hi slower than before.
+            QUIC_CODE_COUNT(quic_bbr2_cut_inflight_hi_gradually_in_effect);
+          }
+          model_->set_inflight_hi(std::max(inflight_at_send, inflight_target));
+        } else {
+          model_->set_inflight_hi(inflight_at_send);
+        }
       }
 
       QUIC_DVLOG(3) << sender_ << " " << cycle_.phase