Skip to content

Commit

Permalink
Return void for CxPlatSocketSend (#4516)
Browse files Browse the repository at this point in the history
  • Loading branch information
nibanks authored Aug 29, 2024
1 parent e5c95b2 commit 51e1e18
Show file tree
Hide file tree
Showing 20 changed files with 165 additions and 281 deletions.
33 changes: 3 additions & 30 deletions src/core/binding.c
Original file line number Diff line number Diff line change
Expand Up @@ -1781,7 +1781,7 @@ QuicBindingUnreachable(
}

_IRQL_requires_max_(DISPATCH_LEVEL)
QUIC_STATUS
void
QuicBindingSend(
_In_ QUIC_BINDING* Binding,
_In_ const CXPLAT_ROUTE* Route,
Expand All @@ -1790,8 +1790,6 @@ QuicBindingSend(
_In_ uint32_t DatagramsToSend
)
{
QUIC_STATUS Status;

#if QUIC_TEST_DATAPATH_HOOKS_ENABLED
QUIC_TEST_DATAPATH_HOOKS* Hooks = MsQuicLib.TestDatapathHooks;
if (Hooks != NULL) {
Expand All @@ -1810,42 +1808,17 @@ QuicBindingSend(
"[bind][%p] Test dropped packet",
Binding);
CxPlatSendDataFree(SendData);
Status = QUIC_STATUS_SUCCESS;
} else {
Status =
CxPlatSocketSend(
Binding->Socket,
&RouteCopy,
SendData);
if (QUIC_FAILED(Status)) {
QuicTraceLogWarning(
BindingSendFailed,
"[bind][%p] Send failed, 0x%x",
Binding,
Status);
}
CxPlatSocketSend(Binding->Socket, &RouteCopy, SendData);
}
} else {
#endif
Status =
CxPlatSocketSend(
Binding->Socket,
Route,
SendData);
if (QUIC_FAILED(Status)) {
QuicTraceLogWarning(
BindingSendFailed,
"[bind][%p] Send failed, 0x%x",
Binding,
Status);
}
CxPlatSocketSend(Binding->Socket, Route, SendData);
#if QUIC_TEST_DATAPATH_HOOKS_ENABLED
}
#endif

QuicPerfCounterAdd(QUIC_PERF_COUNTER_UDP_SEND, DatagramsToSend);
QuicPerfCounterAdd(QUIC_PERF_COUNTER_UDP_SEND_BYTES, BytesToSend);
QuicPerfCounterIncrement(QUIC_PERF_COUNTER_UDP_SEND_CALLS);

return Status;
}
2 changes: 1 addition & 1 deletion src/core/binding.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ QuicBindingReleaseStatelessOperation(
// the duration of the send operation.
//
_IRQL_requires_max_(DISPATCH_LEVEL)
QUIC_STATUS
void
QuicBindingSend(
_In_ QUIC_BINDING* Binding,
_In_ const CXPLAT_ROUTE* Route,
Expand Down
14 changes: 8 additions & 6 deletions src/generated/linux/Tcp.cpp.clog.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,18 @@ tracepoint(CLOG_TCP_CPP, PerfTcpReceiveCallback , arg2);\

/*----------------------------------------------------------
// Decoder Ring for PerfTcpSendCompleteCallback
// [perf][tcp][%p] SendComplete callback
// [perf][tcp][%p] SendComplete callback, %u
// QuicTraceLogVerbose(
PerfTcpSendCompleteCallback,
"[perf][tcp][%p] SendComplete callback",
This);
"[perf][tcp][%p] SendComplete callback, %u",
This,
(uint32_t)Status);
// arg2 = arg2 = This = arg2
// arg3 = arg3 = (uint32_t)Status = arg3
----------------------------------------------------------*/
#ifndef _clog_3_ARGS_TRACE_PerfTcpSendCompleteCallback
#define _clog_3_ARGS_TRACE_PerfTcpSendCompleteCallback(uniqueId, encoded_arg_string, arg2)\
tracepoint(CLOG_TCP_CPP, PerfTcpSendCompleteCallback , arg2);\
#ifndef _clog_4_ARGS_TRACE_PerfTcpSendCompleteCallback
#define _clog_4_ARGS_TRACE_PerfTcpSendCompleteCallback(uniqueId, encoded_arg_string, arg2, arg3)\
tracepoint(CLOG_TCP_CPP, PerfTcpSendCompleteCallback , arg2, arg3);\

#endif

Expand Down
12 changes: 8 additions & 4 deletions src/generated/linux/Tcp.cpp.clog.h.lttng.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,18 +102,22 @@ TRACEPOINT_EVENT(CLOG_TCP_CPP, PerfTcpReceiveCallback,

/*----------------------------------------------------------
// Decoder Ring for PerfTcpSendCompleteCallback
// [perf][tcp][%p] SendComplete callback
// [perf][tcp][%p] SendComplete callback, %u
// QuicTraceLogVerbose(
PerfTcpSendCompleteCallback,
"[perf][tcp][%p] SendComplete callback",
This);
"[perf][tcp][%p] SendComplete callback, %u",
This,
(uint32_t)Status);
// arg2 = arg2 = This = arg2
// arg3 = arg3 = (uint32_t)Status = arg3
----------------------------------------------------------*/
TRACEPOINT_EVENT(CLOG_TCP_CPP, PerfTcpSendCompleteCallback,
TP_ARGS(
const void *, arg2),
const void *, arg2,
unsigned int, arg3),
TP_FIELDS(
ctf_integer_hex(uint64_t, arg2, (uint64_t)arg2)
ctf_integer(unsigned int, arg3, arg3)
)
)

Expand Down
20 changes: 0 additions & 20 deletions src/generated/linux/binding.c.clog.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,6 @@ tracepoint(CLOG_BINDING_C, BindingListenerAlreadyRegistered , arg2, arg3);\



/*----------------------------------------------------------
// Decoder Ring for BindingSendFailed
// [bind][%p] Send failed, 0x%x
// QuicTraceLogWarning(
BindingSendFailed,
"[bind][%p] Send failed, 0x%x",
Binding,
Status);
// arg2 = arg2 = Binding = arg2
// arg3 = arg3 = Status = arg3
----------------------------------------------------------*/
#ifndef _clog_4_ARGS_TRACE_BindingSendFailed
#define _clog_4_ARGS_TRACE_BindingSendFailed(uniqueId, encoded_arg_string, arg2, arg3)\
tracepoint(CLOG_BINDING_C, BindingSendFailed , arg2, arg3);\

#endif




/*----------------------------------------------------------
// Decoder Ring for PacketTxVersionNegotiation
// [S][TX][-] VN
Expand Down
23 changes: 0 additions & 23 deletions src/generated/linux/binding.c.clog.h.lttng.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,29 +23,6 @@ TRACEPOINT_EVENT(CLOG_BINDING_C, BindingListenerAlreadyRegistered,



/*----------------------------------------------------------
// Decoder Ring for BindingSendFailed
// [bind][%p] Send failed, 0x%x
// QuicTraceLogWarning(
BindingSendFailed,
"[bind][%p] Send failed, 0x%x",
Binding,
Status);
// arg2 = arg2 = Binding = arg2
// arg3 = arg3 = Status = arg3
----------------------------------------------------------*/
TRACEPOINT_EVENT(CLOG_BINDING_C, BindingSendFailed,
TP_ARGS(
const void *, arg2,
unsigned int, arg3),
TP_FIELDS(
ctf_integer_hex(uint64_t, arg2, (uint64_t)arg2)
ctf_integer(unsigned int, arg3, arg3)
)
)



/*----------------------------------------------------------
// Decoder Ring for PacketTxVersionNegotiation
// [S][TX][-] VN
Expand Down
2 changes: 1 addition & 1 deletion src/inc/quic_datapath.h
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ CxPlatSendDataIsFull(
// Sends the data over the socket.
//
_IRQL_requires_max_(DISPATCH_LEVEL)
QUIC_STATUS
void
CxPlatSocketSend(
_In_ CXPLAT_SOCKET* Socket,
_In_ const CXPLAT_ROUTE* Route,
Expand Down
10 changes: 7 additions & 3 deletions src/manifest/clog.sidecar
Original file line number Diff line number Diff line change
Expand Up @@ -8672,12 +8672,16 @@
},
"PerfTcpSendCompleteCallback": {
"ModuleProperites": {},
"TraceString": "[perf][tcp][%p] SendComplete callback",
"TraceString": "[perf][tcp][%p] SendComplete callback, %u",
"UniqueId": "PerfTcpSendCompleteCallback",
"splitArgs": [
{
"DefinationEncoding": "p",
"MacroVariableName": "arg2"
},
{
"DefinationEncoding": "u",
"MacroVariableName": "arg3"
}
],
"macroName": "QuicTraceLogVerbose"
Expand Down Expand Up @@ -15912,9 +15916,9 @@
"EncodingString": "[perf][tcp][%p] Receive callback"
},
{
"UniquenessHash": "c0732f05-6611-2c1d-ad74-42718c7269cc",
"UniquenessHash": "40ccb9a5-a92a-6a46-3b50-7628487e2415",
"TraceID": "PerfTcpSendCompleteCallback",
"EncodingString": "[perf][tcp][%p] SendComplete callback"
"EncodingString": "[perf][tcp][%p] SendComplete callback, %u"
},
{
"UniquenessHash": "87a3325f-51ea-bece-2c7f-5a1e55cf6415",
Expand Down
48 changes: 25 additions & 23 deletions src/perf/lib/Tcp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,10 +519,11 @@ TcpConnection::ConnectCallback(
Connected);
if (Connected) {
This->StartTls = true;
} else {
This->Queue();
} else if (!This->Shutdown) {
This->Shutdown = true;
This->Queue();
}
This->Queue();
}

_IRQL_requires_max_(DISPATCH_LEVEL)
Expand Down Expand Up @@ -566,22 +567,30 @@ void
TcpConnection::SendCompleteCallback(
_In_ CXPLAT_SOCKET* /* Socket */,
_In_ void* Context,
_In_ QUIC_STATUS /* Status */,
_In_ QUIC_STATUS Status,
_In_ uint32_t ByteCount
)
{
TcpConnection* This = (TcpConnection*)Context;
bool QueueWork = false;
QuicTraceLogVerbose(
PerfTcpSendCompleteCallback,
"[perf][tcp][%p] SendComplete callback",
This);
"[perf][tcp][%p] SendComplete callback, %u",
This,
(uint32_t)Status);
CxPlatDispatchLockAcquire(&This->Lock);
if (This->TotalSendCompleteOffset != UINT64_MAX) {
if (QUIC_FAILED(Status)) {
if (!This->Shutdown) {
This->Shutdown = true;
QueueWork = true;
}
} else if (This->TotalSendCompleteOffset != UINT64_MAX) {
This->TotalSendCompleteOffset += ByteCount;
This->IndicateSendComplete = true;
QueueWork = true;
}
CxPlatDispatchLockRelease(&This->Lock);
if (This->TotalSendCompleteOffset != UINT64_MAX) {
if (QueueWork) {
This->Queue();
}
}
Expand Down Expand Up @@ -656,10 +665,7 @@ void TcpConnection::Process()
}
}
if (BatchedSendData && !Shutdown) {
if (QUIC_FAILED(
CxPlatSocketSend(Socket, &Route, BatchedSendData))) {
Shutdown = true;
}
CxPlatSocketSend(Socket, &Route, BatchedSendData);
BatchedSendData = nullptr;
}
if (IndicateSendComplete) {
Expand Down Expand Up @@ -754,7 +760,7 @@ bool TcpConnection::ProcessTls(const uint8_t* Buffer, uint32_t BufferLength)
IndicateConnect = true;
}

while (BaseOffset < TlsState.BufferTotalLength) {
while (!Shutdown && BaseOffset < TlsState.BufferTotalLength) {
if (TlsState.BufferOffsetHandshake) {
if (BaseOffset < TlsState.BufferOffsetHandshake) {
uint16_t Length = (uint16_t)(TlsState.BufferOffsetHandshake - BaseOffset);
Expand Down Expand Up @@ -808,7 +814,9 @@ bool TcpConnection::SendTlsData(const uint8_t* Buffer, uint16_t BufferLength, ui
}

SendBuffer->Length = sizeof(TcpFrame) + Frame->Length + CXPLAT_ENCRYPTION_OVERHEAD;
return FinalizeSendBuffer(SendBuffer);
FinalizeSendBuffer(SendBuffer);

return true;
}

bool TcpConnection::ProcessReceive()
Expand Down Expand Up @@ -1008,11 +1016,9 @@ bool TcpConnection::ProcessSend()
}

SendBuffer->Length = sizeof(TcpFrame) + Frame->Length + CXPLAT_ENCRYPTION_OVERHEAD;
if (!FinalizeSendBuffer(SendBuffer)) {
return false;
}
FinalizeSendBuffer(SendBuffer);

} while (NextSendData->Length > Offset);
} while (!Shutdown && NextSendData->Length > Offset);

NextSendData->Offset = TotalSendOffset;
NextSendData = NextSendData->Next;
Expand Down Expand Up @@ -1088,18 +1094,14 @@ void TcpConnection::FreeSendBuffer(QUIC_BUFFER* SendBuffer)
CxPlatSendDataFreeBuffer(BatchedSendData, SendBuffer);
}

bool TcpConnection::FinalizeSendBuffer(QUIC_BUFFER* SendBuffer)
void TcpConnection::FinalizeSendBuffer(QUIC_BUFFER* SendBuffer)
{
TotalSendOffset += SendBuffer->Length;
if (SendBuffer->Length != TLS_BLOCK_SIZE ||
CxPlatSendDataIsFull(BatchedSendData)) {
auto Status = CxPlatSocketSend(Socket, &Route, BatchedSendData);
CxPlatSocketSend(Socket, &Route, BatchedSendData);
BatchedSendData = nullptr;
if (QUIC_FAILED(Status)) {
return false;
}
}
return true;
}

bool TcpConnection::Send(TcpSendData* Data)
Expand Down
2 changes: 1 addition & 1 deletion src/perf/lib/Tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ class TcpConnection {
bool EncryptFrame(TcpFrame* Frame);
QUIC_BUFFER* NewSendBuffer();
void FreeSendBuffer(QUIC_BUFFER* SendBuffer);
bool FinalizeSendBuffer(QUIC_BUFFER* SendBuffer);
void FinalizeSendBuffer(QUIC_BUFFER* SendBuffer);
bool TryAddRef() { return CxPlatRefIncrementNonZero(&Ref, 1) != FALSE; }
void Release() { if (CxPlatRefDecrement(&Ref)) delete this; }
public:
Expand Down
10 changes: 3 additions & 7 deletions src/platform/datapath_epoll.c
Original file line number Diff line number Diff line change
Expand Up @@ -2222,7 +2222,7 @@ CxPlatSendDataSend(
_In_ CXPLAT_SEND_DATA* SendData
);

QUIC_STATUS
void
SocketSend(
_In_ CXPLAT_SOCKET* Socket,
_In_ const CXPLAT_ROUTE* Route,
Expand Down Expand Up @@ -2272,14 +2272,13 @@ SocketSend(
&SocketContext->FlushTxSqe.Sqe,
&SocketContext->FlushTxSqe));
}
return QUIC_STATUS_SUCCESS;
return;
}

//
// Go ahead and try to send on the socket.
//
QUIC_STATUS Status = CxPlatSendDataSend(SendData);
if (Status == QUIC_STATUS_PENDING) {
if (CxPlatSendDataSend(SendData) == QUIC_STATUS_PENDING) {
//
// Couldn't send right now, so queue up the send and wait for send
// (EPOLLOUT) to be ready.
Expand All @@ -2288,7 +2287,6 @@ SocketSend(
CxPlatListInsertTail(&SocketContext->TxQueue, &SendData->TxEntry);
CxPlatLockRelease(&SocketContext->TxQueueLock);
CxPlatSocketContextSetEvents(SocketContext, EPOLL_CTL_MOD, EPOLLIN | EPOLLOUT);
Status = QUIC_STATUS_SUCCESS;
} else {
if (Socket->Type != CXPLAT_SOCKET_UDP) {
SocketContext->Binding->Datapath->TcpHandlers.SendComplete(
Expand All @@ -2299,8 +2297,6 @@ SocketSend(
}
CxPlatSendDataFree(SendData);
}

return Status;
}

//
Expand Down
Loading

0 comments on commit 51e1e18

Please sign in to comment.