Skip to content

Commit

Permalink
Some Cubic Clean Up (microsoft#2305)
Browse files Browse the repository at this point in the history
  • Loading branch information
nibanks authored Jan 20, 2022
1 parent be03dc6 commit bf8a783
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
41 changes: 22 additions & 19 deletions src/core/cubic.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ CubicCongestionControlOnDataAcknowledged(
{
QUIC_CONGESTION_CONTROL_CUBIC* Cubic = &Cc->Cubic;

uint64_t TimeNow = US_TO_MS(AckEvent->TimeNow);
const uint64_t TimeNowUs = AckEvent->TimeNow;
QUIC_CONNECTION* Connection = QuicCongestionControlGetConnection(Cc);
BOOLEAN PreviousCanSendState = CubicCongestionControlCanSend(Cc);

Expand All @@ -384,7 +384,7 @@ CubicCongestionControlOnDataAcknowledged(
Connection);
Cubic->IsInRecovery = FALSE;
Cubic->IsInPersistentCongestion = FALSE;
Cubic->TimeOfCongAvoidStart = CxPlatTimeMs64();
Cubic->TimeOfCongAvoidStart = CxPlatTimeUs64();
}
goto Exit;
} else if (AckEvent->NumRetransmittableBytes == 0) {
Expand All @@ -398,12 +398,13 @@ CubicCongestionControlOnDataAcknowledged(
//

//
// TODO: CongestionWindow should only be allowed to grow up to SlowStartThreshold
// here, and then any spare bytes should be handled in the Congestion Avoidance path.
// TODO: CongestionWindow should only be allowed to grow up to
// SlowStartThreshold here, and then any spare bytes should be handled
// in the Congestion Avoidance path.
//
Cubic->CongestionWindow += AckEvent->NumRetransmittableBytes;
if (Cubic->CongestionWindow >= Cubic->SlowStartThreshold) {
Cubic->TimeOfCongAvoidStart = CxPlatTimeMs64();
Cubic->TimeOfCongAvoidStart = TimeNowUs;
}

} else {
Expand All @@ -422,21 +423,18 @@ CubicCongestionControlOnDataAcknowledged(
// growth during the gap.
//
if (Cubic->TimeOfLastAckValid) {
uint64_t TimeSinceLastAck = CxPlatTimeDiff64(Cubic->TimeOfLastAck, TimeNow);
if (TimeSinceLastAck > Cubic->SendIdleTimeoutMs &&
TimeSinceLastAck > US_TO_MS(Connection->Paths[0].SmoothedRtt + 4 * Connection->Paths[0].RttVariance)) {
const uint64_t TimeSinceLastAck = CxPlatTimeDiff64(Cubic->TimeOfLastAck, TimeNowUs);
if (TimeSinceLastAck > MS_TO_US((uint64_t)Cubic->SendIdleTimeoutMs) &&
TimeSinceLastAck > (Connection->Paths[0].SmoothedRtt + 4 * Connection->Paths[0].RttVariance)) {
Cubic->TimeOfCongAvoidStart += TimeSinceLastAck;
if (CxPlatTimeAtOrBefore64(TimeNow, Cubic->TimeOfCongAvoidStart)) {
Cubic->TimeOfCongAvoidStart = TimeNow;
if (CxPlatTimeAtOrBefore64(TimeNowUs, Cubic->TimeOfCongAvoidStart)) {
Cubic->TimeOfCongAvoidStart = TimeNowUs;
}
}
}

uint64_t TimeInCongAvoid =
CxPlatTimeDiff64(Cubic->TimeOfCongAvoidStart, CxPlatTimeMs64());
if (TimeInCongAvoid > UINT32_MAX) {
TimeInCongAvoid = UINT32_MAX;
}
const uint64_t TimeInCongAvoidUs =
CxPlatTimeDiff64(Cubic->TimeOfCongAvoidStart, TimeNowUs);

//
// Compute the cubic window:
Expand All @@ -455,9 +453,14 @@ CubicCongestionControlOnDataAcknowledged(
//

int64_t DeltaT =
(int64_t)TimeInCongAvoid -
(int64_t)Cubic->KCubic +
(int64_t)US_TO_MS(AckEvent->SmoothedRtt);
US_TO_MS(
(int64_t)TimeInCongAvoidUs -
(int64_t)MS_TO_US(Cubic->KCubic) +
(int64_t)AckEvent->SmoothedRtt
);
if (DeltaT > 2500000) {
DeltaT = 2500000;
}

int64_t CubicWindow =
((((DeltaT * DeltaT) >> 10) * DeltaT *
Expand Down Expand Up @@ -528,7 +531,7 @@ CubicCongestionControlOnDataAcknowledged(

Exit:

Cubic->TimeOfLastAck = TimeNow;
Cubic->TimeOfLastAck = TimeNowUs;
Cubic->TimeOfLastAckValid = TRUE;
return CubicCongestionControlUpdateBlockedState(Cc, PreviousCanSendState);
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/cubic.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ typedef struct QUIC_CONGESTION_CONTROL_CUBIC {
//
uint8_t Exemptions;

uint64_t TimeOfLastAck; // millisec
uint64_t TimeOfCongAvoidStart; // millisec
uint64_t TimeOfLastAck; // microseconds
uint64_t TimeOfCongAvoidStart; // microseconds
uint32_t KCubic; // millisec
uint32_t PrevKCubic; // millisec
uint32_t WindowMax; // bytes
Expand Down

0 comments on commit bf8a783

Please sign in to comment.