Skip to content

Commit

Permalink
Switch uses of min and max to CXPLAT_MIN and CXPLAT_MAX (microsoft#1706)
Browse files Browse the repository at this point in the history
* Switch uses of min and max to CXPLAT_MIN and CXPLAT_MAX

* Don't change comments
ThadHouse authored Jun 11, 2021
1 parent 78a8ddb commit 128759d
Showing 17 changed files with 27 additions and 27 deletions.
8 changes: 4 additions & 4 deletions src/core/congestion_control.c
Original file line number Diff line number Diff line change
@@ -261,7 +261,7 @@ QuicCongestionControlOnCongestionEvent(

Cc->SlowStartThreshold =
Cc->CongestionWindow =
max(
CXPLAT_MAX(
(uint32_t)Connection->Paths[0].Mtu * QUIC_PERSISTENT_CONGESTION_WINDOW_PACKETS,
Cc->CongestionWindow * TEN_TIMES_BETA_CUBIC / 10);
}
@@ -458,13 +458,13 @@ QuicCongestionControlOnDataAcknowledged(

int64_t AimdWindow =
Cc->WindowMax * TEN_TIMES_BETA_CUBIC / 10 +
TimeInCongAvoid * Connection->Paths[0].Mtu / (2 * max(1, US_TO_MS(SmoothedRtt)));
TimeInCongAvoid * Connection->Paths[0].Mtu / (2 * CXPLAT_MAX(1, US_TO_MS(SmoothedRtt)));

//
// Use the cubic or AIMD window, whichever is larger.
//
if (AimdWindow > CubicWindow) {
Cc->CongestionWindow = (uint32_t)max(AimdWindow, Cc->CongestionWindow + 1);
Cc->CongestionWindow = (uint32_t)CXPLAT_MAX(AimdWindow, Cc->CongestionWindow + 1);
} else {
//
// Here we increment by a fraction of the difference, per the spec,
@@ -473,7 +473,7 @@ QuicCongestionControlOnDataAcknowledged(
// the cubic window may be significantly different from SlowStartThreshold.
//
Cc->CongestionWindow +=
(uint32_t)max(
(uint32_t)CXPLAT_MAX(
((CubicWindow - Cc->CongestionWindow) * Connection->Paths[0].Mtu) / Cc->CongestionWindow,
1);
}
4 changes: 2 additions & 2 deletions src/core/connection.c
Original file line number Diff line number Diff line change
@@ -1511,7 +1511,7 @@ QuicConnTryClose(
QuicConnTimerSet(
Connection,
QUIC_CONN_TIMER_SHUTDOWN,
max(15, US_TO_MS(Connection->Paths[0].SmoothedRtt * 2)));
CXPLAT_MAX(15, US_TO_MS(Connection->Paths[0].SmoothedRtt * 2)));

QuicSendSetSendFlag(
&Connection->Send,
@@ -1574,7 +1574,7 @@ QuicConnTryClose(
QuicConnTimerSet(
Connection,
QUIC_CONN_TIMER_SHUTDOWN,
max(15, US_TO_MS(Connection->Paths[0].SmoothedRtt * 2)));
CXPLAT_MAX(15, US_TO_MS(Connection->Paths[0].SmoothedRtt * 2)));
}

IsFirstCloseForConnection = FALSE;
2 changes: 1 addition & 1 deletion src/core/connection.h
Original file line number Diff line number Diff line change
@@ -1442,7 +1442,7 @@ QuicConnGetMaxMtuForPath(
(uint16_t)Connection->PeerTransportParams.MaxUdpPayloadSize);
}
uint16_t SettingsMtu = Connection->Settings.MaximumMtu;
return min(min(LocalMtu, RemoteMtu), SettingsMtu);
return CXPLAT_MIN(CXPLAT_MIN(LocalMtu, RemoteMtu), SettingsMtu);
}

//
2 changes: 1 addition & 1 deletion src/core/library.c
Original file line number Diff line number Diff line change
@@ -318,7 +318,7 @@ MsQuicLibraryInitialize(
}
MsQuicLib.ProcessorCount = (uint16_t)CxPlatProcActiveCount();
CXPLAT_FRE_ASSERT(MsQuicLib.ProcessorCount > 0);
MsQuicLib.PartitionCount = (uint16_t)min(MsQuicLib.ProcessorCount, DefaultMaxPartitionCount);
MsQuicLib.PartitionCount = (uint16_t)CXPLAT_MIN(MsQuicLib.ProcessorCount, DefaultMaxPartitionCount);

MsQuicCalculatePartitionMask();

8 changes: 4 additions & 4 deletions src/core/loss_detection.c
Original file line number Diff line number Diff line change
@@ -312,7 +312,7 @@ QuicLossDetectionUpdateTimer(
// If it expires, we'll consider the packet lost.
//
TimeoutType = LOSS_TIMER_RACK;
uint32_t RttUs = max(Path->SmoothedRtt, Path->LatestRttSample);
uint32_t RttUs = CXPLAT_MAX(Path->SmoothedRtt, Path->LatestRttSample);
TimeFires = OldestPacket->SentTime + QUIC_TIME_REORDER_THRESHOLD(RttUs);

} else if (!Path->GotFirstRttSample) {
@@ -784,7 +784,7 @@ QuicLossDetectionRetransmitFrames(
uint32_t TimeNow = CxPlatTimeUs32();
CXPLAT_DBG_ASSERT(Connection->Configuration != NULL);
uint32_t ValidationTimeout =
max(QuicLossDetectionComputeProbeTimeout(LossDetection, Path, 3),
CXPLAT_MAX(QuicLossDetectionComputeProbeTimeout(LossDetection, Path, 3),
6 * MS_TO_US(Connection->Settings.InitialRttMs));
if (CxPlatTimeDiff32(Path->PathValidationStartTime, TimeNow) > ValidationTimeout) {
QuicTraceLogConnInfo(
@@ -930,7 +930,7 @@ QuicLossDetectionDetectAndHandleLostPackets(
// because it is not needed to keep timers from firing early.
//
const QUIC_PATH* Path = &Connection->Paths[0]; // TODO - Correct?
uint32_t Rtt = max(Path->SmoothedRtt, Path->LatestRttSample);
uint32_t Rtt = CXPLAT_MAX(Path->SmoothedRtt, Path->LatestRttSample);
uint32_t TimeReorderThreshold = QUIC_TIME_REORDER_THRESHOLD(Rtt);
uint64_t LargestLostPacketNumber = 0;
QUIC_SENT_PACKET_METADATA* PrevPacket = NULL;
@@ -1400,7 +1400,7 @@ QuicLossDetectionProcessAckBlocks(
Packet->PacketNumber,
QuicPacketTraceType(Packet));

SmallestRtt = min(SmallestRtt, PacketRtt);
SmallestRtt = CXPLAT_MIN(SmallestRtt, PacketRtt);

QuicLossDetectionOnPacketAcknowledged(LossDetection, EncryptLevel, Packet);
}
2 changes: 1 addition & 1 deletion src/core/mtu_discovery.c
Original file line number Diff line number Diff line change
@@ -87,7 +87,7 @@ QuicGetNextProbeSize(
// be less then a full increment.
//
if (Path->Mtu < 1280) {
return min(1280, MtuDiscovery->MaxMtu);
return CXPLAT_MIN(1280, MtuDiscovery->MaxMtu);
}

uint16_t Mtu = Path->Mtu + QUIC_DPLPMTUD_INCREMENT;
2 changes: 1 addition & 1 deletion src/core/packet.h
Original file line number Diff line number Diff line change
@@ -560,7 +560,7 @@ QuicPacketHash(
CxPlatToeplitzHashCompute(
&MsQuicLib.ToeplitzHash,
RemoteCid,
min(RemoteCidLength, QUIC_MAX_CONNECTION_ID_LENGTH_V1),
CXPLAT_MIN(RemoteCidLength, QUIC_MAX_CONNECTION_ID_LENGTH_V1),
Offset);
}
return Key;
2 changes: 1 addition & 1 deletion src/core/stream.c
Original file line number Diff line number Diff line change
@@ -296,7 +296,7 @@ QuicStreamStart(
if (Stream->MaxAllowedSendOffset == 0) {
Stream->OutFlowBlockedReasons |= QUIC_FLOW_BLOCKED_STREAM_FLOW_CONTROL;
}
Stream->SendWindow = (uint32_t)min(Stream->MaxAllowedSendOffset, UINT32_MAX);
Stream->SendWindow = (uint32_t)CXPLAT_MIN(Stream->MaxAllowedSendOffset, UINT32_MAX);

if (Stream->OutFlowBlockedReasons != 0) {
QuicTraceEvent(
2 changes: 1 addition & 1 deletion src/core/stream_recv.c
Original file line number Diff line number Diff line change
@@ -512,7 +512,7 @@ QuicStreamRecv(
// MAX_STREAM_DATA.
//
Stream->SendWindow =
(uint32_t)min(Stream->MaxAllowedSendOffset - Stream->UnAckedOffset, UINT32_MAX);
(uint32_t)CXPLAT_MIN(Stream->MaxAllowedSendOffset - Stream->UnAckedOffset, UINT32_MAX);

QuicSendBufferStreamAdjust(Stream);

2 changes: 1 addition & 1 deletion src/core/stream_set.c
Original file line number Diff line number Diff line change
@@ -326,7 +326,7 @@ QuicStreamSetInitializeTransportParameters(
if (Stream->MaxAllowedSendOffset < NewMaxAllowedSendOffset) {
Stream->MaxAllowedSendOffset = NewMaxAllowedSendOffset;
FlowBlockedFlagsToRemove |= QUIC_FLOW_BLOCKED_STREAM_FLOW_CONTROL;
Stream->SendWindow = (uint32_t)min(Stream->MaxAllowedSendOffset, UINT32_MAX);
Stream->SendWindow = (uint32_t)CXPLAT_MIN(Stream->MaxAllowedSendOffset, UINT32_MAX);
}

if (FlowBlockedFlagsToRemove) {
2 changes: 1 addition & 1 deletion src/inc/msquichelper.h
Original file line number Diff line number Diff line change
@@ -289,7 +289,7 @@ IsValue(
_In_z_ const char* toTestAgainst
)
{
return _strnicmp(name, toTestAgainst, min(strlen(name), strlen(toTestAgainst))) == 0;
return _strnicmp(name, toTestAgainst, CXPLAT_MIN(strlen(name), strlen(toTestAgainst))) == 0;
}

inline
4 changes: 4 additions & 0 deletions src/inc/quic_platform.h
Original file line number Diff line number Diff line change
@@ -28,6 +28,10 @@ Supported Environments:

#define IS_POWER_OF_TWO(x) (((x) != 0) && (((x) & ((x) - 1)) == 0))

#define CXPLAT_MAX(a,b) (((a) > (b)) ? (a) : (b))

#define CXPLAT_MIN(a,b) (((a) < (b)) ? (a) : (b))

//
// Time unit conversion.
//
4 changes: 0 additions & 4 deletions src/inc/quic_platform_posix.h
Original file line number Diff line number Diff line change
@@ -92,10 +92,6 @@ CxPlatUninitialize(

#define SOCKET_ERROR (-1)

#define max(a,b) (((a) > (b)) ? (a) : (b))

#define min(a,b) (((a) < (b)) ? (a) : (b))

#define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0]))

#define UNREFERENCED_PARAMETER(P) (void)(P)
2 changes: 1 addition & 1 deletion src/perf/bin/appmain.cpp
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ QuicHandleRpsClient(
ExtraData += sizeof(CachedCompletedRequests);
uint32_t RestOfBufferLength = Length - sizeof(RunTime) - sizeof(CachedCompletedRequests);
RestOfBufferLength &= 0xFFFFFFFC; // Round down to nearest multiple of 4
uint32_t MaxCount = min(CachedCompletedRequests, RestOfBufferLength);
uint32_t MaxCount = CXPLAT_MIN(CachedCompletedRequests, RestOfBufferLength);

uint32_t RPS = (uint32_t)((CachedCompletedRequests * 1000ull) / (uint64_t)RunTime);
if (RPS == 0) {
2 changes: 1 addition & 1 deletion src/perf/lib/PerfServer.cpp
Original file line number Diff line number Diff line change
@@ -175,7 +175,7 @@ PerfServer::StreamCallback(
uint8_t* Dest = (uint8_t*)&Context->ResponseSize;
uint64_t Offset = Event->RECEIVE.AbsoluteOffset;
for (uint32_t i = 0; Offset < sizeof(uint64_t) && i < Event->RECEIVE.BufferCount; ++i) {
uint32_t Length = min((uint32_t)(sizeof(uint64_t) - Offset), Event->RECEIVE.Buffers[i].Length);
uint32_t Length = CXPLAT_MIN((uint32_t)(sizeof(uint64_t) - Offset), Event->RECEIVE.Buffers[i].Length);
memcpy(Dest + Offset, Event->RECEIVE.Buffers[i].Buffer, Length);
Offset += Length;
}
2 changes: 1 addition & 1 deletion src/platform/unittest/TlsTest.cpp
Original file line number Diff line number Diff line change
@@ -398,7 +398,7 @@ struct TlsTest : public ::testing::TestWithParam<bool>
BufferLength -= ConsumedBuffer;
} else {
ConsumedBuffer = FragmentSize * ++Count;
ConsumedBuffer = min(ConsumedBuffer, BufferLength);
ConsumedBuffer = CXPLAT_MIN(ConsumedBuffer, BufferLength);
}

} while (BufferLength != 0 && !(Result & CXPLAT_TLS_RESULT_ERROR));
4 changes: 2 additions & 2 deletions src/test/lib/TestStream.cpp
Original file line number Diff line number Diff line change
@@ -124,7 +124,7 @@ TestStream::StartPing(
BytesToSend = PayloadLength / MaxSendBuffers;

do {
auto SendBufferLength = (uint32_t)min(BytesToSend, (int64_t)MaxSendLength);
auto SendBufferLength = (uint32_t)CXPLAT_MIN(BytesToSend, (int64_t)MaxSendLength);
auto SendBuffer = new(std::nothrow) QuicSendBuffer(MaxSendBuffers, SendBufferLength);
if (SendBuffer == nullptr) {
TEST_FAILURE("Failed to alloc QuicSendBuffer");
@@ -277,7 +277,7 @@ TestStream::HandleStreamSendComplete(
delete SendBuffer;
} else {
QUIC_SEND_FLAGS Flags = QUIC_SEND_FLAG_NONE;
auto SendBufferLength = (uint32_t)min(BytesToSend, (int64_t)MaxSendLength);
auto SendBufferLength = (uint32_t)CXPLAT_MIN(BytesToSend, (int64_t)MaxSendLength);
for (uint32_t i = 0; i < SendBuffer->BufferCount; ++i) {
SendBuffer->Buffers[i].Length = SendBufferLength;
}

0 comments on commit 128759d

Please sign in to comment.