1
0
mirror of https://github.com/facebookincubator/mvfst.git synced 2026-01-06 03:41:10 +03:00

Remove UNLIKELY and LIKELY calls from mvfst

Summary:
All instancesi of LIKELY and UNLIKELY probably should be removed. We will
add them back in if we see pathologies in performance profiles.

Reviewed By: mjoras

Differential Revision: D19163441

fbshipit-source-id: c4c2494d18ecfd28f00af1e68ecaf1e85c1a2e10
This commit is contained in:
Anton Frolov
2020-01-06 17:42:41 -08:00
committed by Facebook Github Bot
parent b771ea5f57
commit 1482011db5
11 changed files with 73 additions and 88 deletions

View File

@@ -1428,7 +1428,7 @@ void QuicTransportBase::handlePingCallback() {
}
void QuicTransportBase::processCallbacksAfterNetworkData() {
if (UNLIKELY(closeState_ != CloseState::OPEN)) {
if (closeState_ != CloseState::OPEN) {
return;
}
// TODO move all of this callback processing to individual functions.
@@ -1980,9 +1980,7 @@ folly::Expected<folly::Unit, LocalErrorCode> QuicTransportBase::resetStream(
}
void QuicTransportBase::checkForClosedStream() {
// TODO: This UNLIKELY here could be premature. This isn't *that* unlikely,
// as we call this function in closeImpl (via cancelAllAppCallbacks).
if (UNLIKELY(closeState_ == CloseState::CLOSED)) {
if (closeState_ == CloseState::CLOSED) {
return;
}
auto itr = conn_->streamManager->closedStreams().begin();

View File

@@ -18,7 +18,7 @@ quic::PacketNum nextAckedPacketGap(quic::PacketNum packetNum, uint64_t gap) {
// Gap cannot overflow because of the definition of quic integer encoding, so
// we can just add to gap.
uint64_t adjustedGap = gap + 2;
if (UNLIKELY(packetNum < adjustedGap)) {
if (packetNum < adjustedGap) {
throw quic::QuicTransportException(
"Bad gap",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
@@ -31,7 +31,7 @@ quic::PacketNum nextAckedPacketLen(
quic::PacketNum packetNum,
uint64_t ackBlockLen) {
// Going to allow 0 as a valid value.
if (UNLIKELY(packetNum < ackBlockLen)) {
if (packetNum < ackBlockLen) {
throw quic::QuicTransportException(
"Bad block len",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
@@ -81,7 +81,7 @@ ReadAckFrame decodeAckFrame(
const CodecParameters& params) {
ReadAckFrame frame;
auto largestAckedInt = decodeQuicInteger(cursor);
if (UNLIKELY(!largestAckedInt)) {
if (!largestAckedInt) {
throw QuicTransportException(
"Bad largest acked",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
@@ -89,21 +89,21 @@ ReadAckFrame decodeAckFrame(
}
auto largestAcked = folly::to<PacketNum>(largestAckedInt->first);
auto ackDelay = decodeQuicInteger(cursor);
if (UNLIKELY(!ackDelay)) {
if (!ackDelay) {
throw QuicTransportException(
"Bad ack delay",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
quic::FrameType::ACK);
}
auto additionalAckBlocks = decodeQuicInteger(cursor);
if (UNLIKELY(!additionalAckBlocks)) {
if (!additionalAckBlocks) {
throw QuicTransportException(
"Bad ack block count",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
quic::FrameType::ACK);
}
auto firstAckBlockLen = decodeQuicInteger(cursor);
if (UNLIKELY(!firstAckBlockLen)) {
if (!firstAckBlockLen) {
throw QuicTransportException(
"Bad first block",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
@@ -122,17 +122,16 @@ ReadAckFrame decodeAckFrame(
uint8_t leftShift = (sizeof(ackDelay->first) * 8 - ackDelayExponentToUse);
DCHECK_LT(leftShift, sizeof(delayOverflowMask) * 8);
delayOverflowMask = delayOverflowMask << leftShift;
if (UNLIKELY((ackDelay->first & delayOverflowMask) != 0)) {
if ((ackDelay->first & delayOverflowMask) != 0) {
throw QuicTransportException(
"Decoded ack delay overflows",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
quic::FrameType::ACK);
}
uint64_t adjustedAckDelay = ackDelay->first << ackDelayExponentToUse;
if (UNLIKELY(
adjustedAckDelay >
static_cast<uint64_t>(
std::numeric_limits<std::chrono::microseconds::rep>::max()))) {
if (adjustedAckDelay >
static_cast<uint64_t>(
std::numeric_limits<std::chrono::microseconds::rep>::max())) {
throw QuicTransportException(
"Bad ack delay",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
@@ -146,14 +145,14 @@ ReadAckFrame decodeAckFrame(
for (uint64_t numBlocks = 0; numBlocks < additionalAckBlocks->first;
++numBlocks) {
auto currentGap = decodeQuicInteger(cursor);
if (UNLIKELY(!currentGap)) {
if (!currentGap) {
throw QuicTransportException(
"Bad gap",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
quic::FrameType::ACK);
}
auto blockLen = decodeQuicInteger(cursor);
if (UNLIKELY(!blockLen)) {
if (!blockLen) {
throw QuicTransportException(
"Bad block len",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
@@ -177,21 +176,21 @@ ReadAckFrame decodeAckFrameWithECN(
auto readAckFrame = decodeAckFrame(cursor, header, params);
// TODO we simply ignore ECN blocks in ACK-ECN frames for now.
auto ect_0 = decodeQuicInteger(cursor);
if (UNLIKELY(!ect_0)) {
if (!ect_0) {
throw QuicTransportException(
"Bad ECT(0) value",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
quic::FrameType::ACK_ECN);
}
auto ect_1 = decodeQuicInteger(cursor);
if (UNLIKELY(!ect_1)) {
if (!ect_1) {
throw QuicTransportException(
"Bad ECT(1) value",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
quic::FrameType::ACK_ECN);
}
auto ect_ce = decodeQuicInteger(cursor);
if (UNLIKELY(!ect_ce)) {
if (!ect_ce) {
throw QuicTransportException(
"Bad ECT-CE value",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
@@ -204,7 +203,7 @@ RstStreamFrame decodeRstStreamFrame(
folly::io::Cursor& cursor,
const CodecParameters& params) {
auto streamId = decodeQuicInteger(cursor);
if (UNLIKELY(!streamId)) {
if (!streamId) {
throw QuicTransportException(
"Bad streamId",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
@@ -226,7 +225,7 @@ RstStreamFrame decodeRstStreamFrame(
}
}
auto offset = decodeQuicInteger(cursor);
if (UNLIKELY(!offset)) {
if (!offset) {
throw QuicTransportException(
"Bad offset",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
@@ -240,7 +239,7 @@ StopSendingFrame decodeStopSendingFrame(
folly::io::Cursor& cursor,
const CodecParameters& params) {
auto streamId = decodeQuicInteger(cursor);
if (UNLIKELY(!streamId)) {
if (!streamId) {
throw QuicTransportException(
"Bad streamId",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
@@ -369,7 +368,7 @@ ReadStreamFrame decodeStreamFrame(
MaxDataFrame decodeMaxDataFrame(folly::io::Cursor& cursor) {
auto maximumData = decodeQuicInteger(cursor);
if (UNLIKELY(!maximumData)) {
if (!maximumData) {
throw QuicTransportException(
"Bad Max Data",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
@@ -380,14 +379,14 @@ MaxDataFrame decodeMaxDataFrame(folly::io::Cursor& cursor) {
MaxStreamDataFrame decodeMaxStreamDataFrame(folly::io::Cursor& cursor) {
auto streamId = decodeQuicInteger(cursor);
if (UNLIKELY(!streamId)) {
if (!streamId) {
throw QuicTransportException(
"Invalid streamId",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
quic::FrameType::MAX_STREAM_DATA);
}
auto offset = decodeQuicInteger(cursor);
if (UNLIKELY(!offset)) {
if (!offset) {
throw QuicTransportException(
"Invalid offset",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
@@ -399,7 +398,7 @@ MaxStreamDataFrame decodeMaxStreamDataFrame(folly::io::Cursor& cursor) {
MaxStreamsFrame decodeBiDiMaxStreamsFrame(folly::io::Cursor& cursor) {
auto streamCount = decodeQuicInteger(cursor);
if (UNLIKELY(!streamCount)) {
if (!streamCount) {
throw QuicTransportException(
"Invalid Bi-directional streamId",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
@@ -410,7 +409,7 @@ MaxStreamsFrame decodeBiDiMaxStreamsFrame(folly::io::Cursor& cursor) {
MaxStreamsFrame decodeUniMaxStreamsFrame(folly::io::Cursor& cursor) {
auto streamCount = decodeQuicInteger(cursor);
if (UNLIKELY(!streamCount)) {
if (!streamCount) {
throw QuicTransportException(
"Invalid Uni-directional streamId",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
@@ -421,7 +420,7 @@ MaxStreamsFrame decodeUniMaxStreamsFrame(folly::io::Cursor& cursor) {
DataBlockedFrame decodeDataBlockedFrame(folly::io::Cursor& cursor) {
auto dataLimit = decodeQuicInteger(cursor);
if (UNLIKELY(!dataLimit)) {
if (!dataLimit) {
throw QuicTransportException(
"Bad offset",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
@@ -432,14 +431,14 @@ DataBlockedFrame decodeDataBlockedFrame(folly::io::Cursor& cursor) {
StreamDataBlockedFrame decodeStreamDataBlockedFrame(folly::io::Cursor& cursor) {
auto streamId = decodeQuicInteger(cursor);
if (UNLIKELY(!streamId)) {
if (!streamId) {
throw QuicTransportException(
"Bad streamId",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
quic::FrameType::STREAM_DATA_BLOCKED);
}
auto dataLimit = decodeQuicInteger(cursor);
if (UNLIKELY(!dataLimit)) {
if (!dataLimit) {
throw QuicTransportException(
"Bad offset",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
@@ -451,7 +450,7 @@ StreamDataBlockedFrame decodeStreamDataBlockedFrame(folly::io::Cursor& cursor) {
StreamsBlockedFrame decodeBiDiStreamsBlockedFrame(folly::io::Cursor& cursor) {
auto streamId = decodeQuicInteger(cursor);
if (UNLIKELY(!streamId)) {
if (!streamId) {
throw QuicTransportException(
"Bad Bi-Directional streamId",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
@@ -463,7 +462,7 @@ StreamsBlockedFrame decodeBiDiStreamsBlockedFrame(folly::io::Cursor& cursor) {
StreamsBlockedFrame decodeUniStreamsBlockedFrame(folly::io::Cursor& cursor) {
auto streamId = decodeQuicInteger(cursor);
if (UNLIKELY(!streamId)) {
if (!streamId) {
throw QuicTransportException(
"Bad Uni-direcitonal streamId",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
@@ -475,14 +474,14 @@ StreamsBlockedFrame decodeUniStreamsBlockedFrame(folly::io::Cursor& cursor) {
NewConnectionIdFrame decodeNewConnectionIdFrame(folly::io::Cursor& cursor) {
auto sequenceNumber = decodeQuicInteger(cursor);
if (UNLIKELY(!sequenceNumber)) {
if (!sequenceNumber) {
throw QuicTransportException(
"Bad sequence",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
quic::FrameType::NEW_CONNECTION_ID);
}
auto retirePriorTo = decodeQuicInteger(cursor);
if (UNLIKELY(!retirePriorTo)) {
if (!retirePriorTo) {
throw QuicTransportException(
"Bad retire prior to",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
@@ -495,7 +494,7 @@ NewConnectionIdFrame decodeNewConnectionIdFrame(folly::io::Cursor& cursor) {
quic::FrameType::NEW_CONNECTION_ID);
}
auto connIdLen = cursor.readBE<uint8_t>();
if (UNLIKELY(cursor.totalLength() < connIdLen)) {
if (cursor.totalLength() < connIdLen) {
throw QuicTransportException(
"Bad connid",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
@@ -521,7 +520,7 @@ RetireConnectionIdFrame decodeRetireConnectionIdFrame(
folly::io::Cursor& cursor) {
// TODO we parse this frame, but return NoopFrame. Add proper support for it!
auto sequenceNum = decodeQuicInteger(cursor);
if (UNLIKELY(!sequenceNum)) {
if (!sequenceNum) {
throw QuicTransportException(
// TODO change the error code
"Bad sequence num",
@@ -577,7 +576,7 @@ ConnectionCloseFrame decodeConnectionCloseFrame(
}
}
auto frameTypeField = decodeQuicInteger(cursor);
if (UNLIKELY(!frameTypeField || frameTypeField->second != sizeof(uint8_t))) {
if (!frameTypeField || frameTypeField->second != sizeof(uint8_t)) {
throw QuicTransportException(
"Bad connection close triggering frame type value",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
@@ -585,9 +584,8 @@ ConnectionCloseFrame decodeConnectionCloseFrame(
}
FrameType triggeringFrameType = static_cast<FrameType>(frameTypeField->first);
auto reasonPhraseLength = decodeQuicInteger(cursor);
if (UNLIKELY(
!reasonPhraseLength ||
reasonPhraseLength->first > kMaxReasonPhraseLength)) {
if (!reasonPhraseLength ||
reasonPhraseLength->first > kMaxReasonPhraseLength) {
throw QuicTransportException(
"Bad reason phrase length",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
@@ -619,9 +617,8 @@ ConnectionCloseFrame decodeApplicationClose(
}
auto reasonPhraseLength = decodeQuicInteger(cursor);
if (UNLIKELY(
!reasonPhraseLength ||
reasonPhraseLength->first > kMaxReasonPhraseLength)) {
if (!reasonPhraseLength ||
reasonPhraseLength->first > kMaxReasonPhraseLength) {
throw QuicTransportException(
"Bad reason phrase length",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
@@ -636,21 +633,21 @@ ConnectionCloseFrame decodeApplicationClose(
MinStreamDataFrame decodeMinStreamDataFrame(folly::io::Cursor& cursor) {
auto streamId = decodeQuicInteger(cursor);
if (UNLIKELY(!streamId)) {
if (!streamId) {
throw QuicTransportException(
"Invalid streamId",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
quic::FrameType::MIN_STREAM_DATA);
}
auto maximumData = decodeQuicInteger(cursor);
if (UNLIKELY(!maximumData)) {
if (!maximumData) {
throw QuicTransportException(
"Invalid maximumData",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
quic::FrameType::MIN_STREAM_DATA);
}
auto minimumStreamOffset = decodeQuicInteger(cursor);
if (UNLIKELY(!minimumStreamOffset)) {
if (!minimumStreamOffset) {
throw QuicTransportException(
"Invalid minimumStreamOffset",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
@@ -664,14 +661,14 @@ MinStreamDataFrame decodeMinStreamDataFrame(folly::io::Cursor& cursor) {
ExpiredStreamDataFrame decodeExpiredStreamDataFrame(folly::io::Cursor& cursor) {
auto streamId = decodeQuicInteger(cursor);
if (UNLIKELY(!streamId)) {
if (!streamId) {
throw QuicTransportException(
"Invalid streamId",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
quic::FrameType::EXPIRED_STREAM_DATA);
}
auto minimumStreamOffset = decodeQuicInteger(cursor);
if (UNLIKELY(!minimumStreamOffset)) {
if (!minimumStreamOffset) {
throw QuicTransportException(
"Invalid minimumStreamOffset",
quic::TransportErrorCode::FRAME_ENCODING_ERROR,
@@ -693,7 +690,7 @@ QuicFrame parseFrame(
}
auto initialByte = decodeQuicInteger(cursor);
// TODO add an new api to determine whether the frametype is encoded minimally
if (UNLIKELY(!initialByte)) {
if (!initialByte) {
throw QuicTransportException(
"Invalid frame-type field", TransportErrorCode::FRAME_ENCODING_ERROR);
}
@@ -1025,7 +1022,7 @@ folly::Expected<ParsedLongHeader, TransportErrorCode> parseLongHeaderVariants(
Buf token;
if (type == LongHeader::Types::Initial) {
auto tokenLen = decodeQuicInteger(cursor);
if (UNLIKELY(!tokenLen)) {
if (!tokenLen) {
VLOG(5) << "Token len not found in Long header";
return folly::makeUnexpected(TransportErrorCode::FRAME_ENCODING_ERROR);
}
@@ -1042,7 +1039,7 @@ folly::Expected<ParsedLongHeader, TransportErrorCode> parseLongHeaderVariants(
}
}
auto pktLen = decodeQuicInteger(cursor);
if (UNLIKELY(!pktLen)) {
if (!pktLen) {
VLOG(5) << "Packet len not found in Long header";
return folly::makeUnexpected(TransportErrorCode::FRAME_ENCODING_ERROR);
}

View File

@@ -50,7 +50,7 @@ Buf BufQueue::splitAtMost(size_t len) {
}
chainLength_ -= (len - remaining);
DCHECK_EQ(chainLength_, chain_ ? chain_->computeChainDataLength() : 0);
if (UNLIKELY(result == nullptr)) {
if (result == nullptr) {
return folly::IOBuf::create(0);
}
return result;

View File

@@ -80,7 +80,7 @@ void IntervalSet<T, Unit, Container>::withdraw(
template <typename T, T Unit, template <typename... I> class Container>
void IntervalSet<T, Unit, Container>::insert(const T& startIt, const T& endIt) {
if (UNLIKELY(startIt > endIt)) {
if (startIt > endIt) {
throw std::invalid_argument("Trying to insert invalid interval");
}
insert(Interval<T, Unit>(startIt, endIt));

View File

@@ -28,10 +28,10 @@ struct Interval {
return Unit;
}
Interval(const T& s, const T& e) : start(s), end(e) {
if (UNLIKELY(start > end)) {
if (start > end) {
throw std::invalid_argument("Trying to construct invalid interval");
}
if (UNLIKELY(end > std::numeric_limits<T>::max() - unitValue())) {
if (end > std::numeric_limits<T>::max() - unitValue()) {
throw std::invalid_argument("Interval bound too large");
}
}

View File

@@ -29,7 +29,7 @@ PacingRate calculatePacingRate(
template <class T1, class T2>
void addAndCheckOverflow(T1& value, const T2& toAdd) {
if (UNLIKELY(std::numeric_limits<T1>::max() - toAdd < value)) {
if (std::numeric_limits<T1>::max() - toAdd < value) {
// TODO: the error code is CWND_OVERFLOW but this function can totally be
// used for inflight bytes.
throw quic::QuicInternalException(
@@ -40,7 +40,7 @@ void addAndCheckOverflow(T1& value, const T2& toAdd) {
template <class T1, class T2>
void subtractAndCheckUnderflow(T1& value, const T2& toSub) {
if (UNLIKELY(value < toSub)) {
if (value < toSub) {
// TODO: wrong error code
throw quic::QuicInternalException(
"Underflow bytes in flight", quic::LocalErrorCode::CWND_OVERFLOW);

View File

@@ -240,9 +240,8 @@ void Cubic::updateTimeToOrigin() noexcept {
*/
// 2500 = kTimeScalingFactor * 1000
auto bytesToOrigin = *steadyState_.lastMaxCwndBytes - cwndBytes_;
if (UNLIKELY(
bytesToOrigin * 1000 * 1000 / conn_.udpSendPacketLen * 2500 >
std::numeric_limits<double>::max())) {
if (bytesToOrigin * 1000 * 1000 / conn_.udpSendPacketLen * 2500 >
std::numeric_limits<double>::max()) {
LOG(WARNING) << "Quic Cubic: timeToOrigin calculation overflow";
steadyState_.timeToOrigin = std::numeric_limits<double>::max();
} else {
@@ -262,9 +261,8 @@ int64_t Cubic::calculateCubicCwndDelta(TimePoint ackTime) noexcept {
ackTime - *steadyState_.lastReductionTime);
int64_t delta = 0;
double timeElapsedCount = static_cast<double>(timeElapsed.count());
if (UNLIKELY(
std::pow((timeElapsedCount - steadyState_.timeToOrigin), 3) >
std::numeric_limits<double>::max())) {
if (std::pow((timeElapsedCount - steadyState_.timeToOrigin), 3) >
std::numeric_limits<double>::max()) {
// (timeElapsed - timeToOrigin) ^ 3 will overflow/underflow, cut delta
// to numeric_limit
LOG(WARNING) << "Quic Cubic: (t-K) ^ 3 overflows";
@@ -303,17 +301,13 @@ uint64_t Cubic::calculateCubicCwnd(int64_t delta) noexcept {
// TODO: chromium has a limit on targetCwnd to be no larger than half of acked
// packet size. Linux also has a limit the cwnd increase to 1 MSS per 2 ACKs.
if (delta > 0 &&
UNLIKELY(
std::numeric_limits<uint64_t>::max() -
*steadyState_.lastMaxCwndBytes <
folly::to<uint64_t>(delta))) {
(std::numeric_limits<uint64_t>::max() - *steadyState_.lastMaxCwndBytes <
folly::to<uint64_t>(delta))) {
LOG(WARNING) << "Quic Cubic: overflow cwnd cut at uint64_t max";
return conn_.transportSettings.maxCwndInMss * conn_.udpSendPacketLen;
} else if (
delta < 0 &&
UNLIKELY(
folly::to<uint64_t>(std::abs(delta)) >
*steadyState_.lastMaxCwndBytes)) {
(folly::to<uint64_t>(std::abs(delta)) > *steadyState_.lastMaxCwndBytes)) {
LOG(WARNING) << "Quic Cubic: underflow cwnd cut at minCwndBytes_ " << conn_;
return conn_.transportSettings.minCwndInMss * conn_.udpSendPacketLen;
} else {
@@ -488,9 +482,8 @@ void Cubic::onPacketAckedInHystart(const AckEvent& ack) {
// TODO: Should we not increase cwnd if inflight is less than half of cwnd?
// Note that we take bytes out of inflightBytes_ before invoke the state
// machine. So the inflightBytes_ here is already reduced.
if (UNLIKELY(
std::numeric_limits<decltype(cwndBytes_)>::max() - cwndBytes_ <
ack.ackedBytes)) {
if (std::numeric_limits<decltype(cwndBytes_)>::max() - cwndBytes_ <
ack.ackedBytes) {
throw QuicInternalException(
"Cubic Hystart: cwnd overflow", LocalErrorCode::CWND_OVERFLOW);
}
@@ -575,9 +568,8 @@ void Cubic::onPacketAckedInHystart(const AckEvent& ack) {
}
if (!hystartState_.lastSampledRtt.hasValue() ||
UNLIKELY(
*hystartState_.lastSampledRtt >=
std::chrono::microseconds::max() - kDelayIncreaseLowerBound)) {
(*hystartState_.lastSampledRtt >=
std::chrono::microseconds::max() - kDelayIncreaseLowerBound)) {
return;
}
auto eta = std::min(
@@ -587,9 +579,8 @@ void Cubic::onPacketAckedInHystart(const AckEvent& ack) {
std::chrono::microseconds(
hystartState_.lastSampledRtt.value().count() >> 4)));
// lastSampledRtt + eta may overflow:
if (UNLIKELY(
*hystartState_.lastSampledRtt >
std::chrono::microseconds::max() - eta)) {
if (*hystartState_.lastSampledRtt >
std::chrono::microseconds::max() - eta) {
// No way currSampledRtt can top this either, return
// TODO: so our rtt is within 8us (kDelayIncreaseUpperBound) of the
// microseconds::max(), should we just shut down the connection?
@@ -677,7 +668,7 @@ void Cubic::onPacketAckedInSteady(const AckEvent& ack) {
}
uint64_t newCwnd = calculateCubicCwnd(calculateCubicCwndDelta(ack.ackTime));
if (UNLIKELY(newCwnd < cwndBytes_)) {
if (newCwnd < cwndBytes_) {
VLOG(10) << "Cubic steady state calculates a smaller cwnd than last round"
<< ", new cnwd = " << newCwnd << ", current cwnd = " << cwndBytes_;
} else {

View File

@@ -46,7 +46,7 @@ folly::Optional<uint64_t> calculateNewWindowUpdate(
template <typename T>
inline void incrementWithOverFlowCheck(T& num, T diff) {
if (UNLIKELY(num > std::numeric_limits<T>::max() - diff)) {
if (num > std::numeric_limits<T>::max() - diff) {
throw QuicInternalException(
"flow control state overflow", LocalErrorCode::INTERNAL_ERROR);
}

View File

@@ -183,7 +183,7 @@ void QuicServerTransport::writeData() {
return;
}
if (UNLIKELY(!conn_->initialWriteCipher)) {
if (!conn_->initialWriteCipher) {
// This would be possible if we read a packet from the network which
// could not be parsed later.
return;

View File

@@ -427,14 +427,14 @@ void QuicServerWorker::dispatchPacketData(
<< *transport;
}
}
if (LIKELY(!dropPacket)) {
if (!dropPacket) {
DCHECK(transport->getEventBase()->isInEventBaseThread());
transport->onNetworkData(client, std::move(networkData));
return;
}
ServerConnectionIdParams connIdParam =
connIdAlgo_->parseConnectionId(routingData.destinationConnId);
if (UNLIKELY(connIdParam.hostId != hostId_)) {
if (connIdParam.hostId != hostId_) {
VLOG(3) << "Dropping packet routed to wrong host, CID="
<< routingData.destinationConnId.hex()
<< ", workerId=" << (uint32_t)workerId_

View File

@@ -238,9 +238,8 @@ struct CongestionController {
persistentCongestion(false) {}
void addLostPacket(const OutstandingPacket& packet) {
if (UNLIKELY(
std::numeric_limits<uint64_t>::max() - lostBytes <
packet.encodedSize)) {
if (std::numeric_limits<uint64_t>::max() - lostBytes <
packet.encodedSize) {
throw QuicInternalException(
"LossEvent: lostBytes overflow",
LocalErrorCode::LOST_BYTES_OVERFLOW);