Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/core/library.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ MsQuicLibraryLoad(
CxPlatSystemLoad();
CxPlatLockInitialize(&MsQuicLib.Lock);
CxPlatDispatchLockInitialize(&MsQuicLib.DatapathLock);
#if DEBUG
CxPlatDispatchLockInitialize(&QuicStreamTrackerLock);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I'd suggest simplifying this to one lock for all the trackers.

#endif
CxPlatListInitializeHead(&MsQuicLib.Registrations);
CxPlatListInitializeHead(&MsQuicLib.Bindings);
QuicTraceRundownCallback = QuicTraceRundown;
Expand All @@ -87,6 +90,9 @@ MsQuicLibraryUnload(
QUIC_LIB_VERIFY(MsQuicLib.OpenRefCount == 0);
QUIC_LIB_VERIFY(!MsQuicLib.InUse);
MsQuicLib.Loaded = FALSE;
#if DEBUG
CxPlatDispatchLockUninitialize(&QuicStreamTrackerLock);
#endif
CxPlatDispatchLockUninitialize(&MsQuicLib.DatapathLock);
CxPlatLockUninitialize(&MsQuicLib.Lock);
CxPlatSystemUnload();
Expand Down
20 changes: 20 additions & 0 deletions src/core/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@
#include "stream.c.clog.h"
#endif

#if DEBUG
//
// Global stream object tracker for debugging.
//
CXPLAT_LIST_ENTRY QuicStreamTrackerList = { &QuicStreamTrackerList, &QuicStreamTrackerList };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've never seen this pattern before - is there a precedent for it in MsQuic? If not, let's use the init routine.

CXPLAT_DISPATCH_LOCK QuicStreamTrackerLock;
#endif

_IRQL_requires_max_(DISPATCH_LEVEL)
QUIC_STATUS
QuicStreamInitialize(
Expand Down Expand Up @@ -46,6 +54,10 @@ QuicStreamInitialize(
CxPlatDispatchLockAcquire(&Connection->Streams.AllStreamsLock);
CxPlatListInsertTail(&Connection->Streams.AllStreams, &Stream->AllStreamsLink);
CxPlatDispatchLockRelease(&Connection->Streams.AllStreamsLock);

CxPlatDispatchLockAcquire(&QuicStreamTrackerLock);
CxPlatListInsertTail(&QuicStreamTrackerList, &Stream->TrackerLink);
CxPlatDispatchLockRelease(&QuicStreamTrackerLock);
#endif
QuicPerfCounterIncrement(Connection->Partition, QUIC_PERF_COUNTER_STRM_ACTIVE);

Expand Down Expand Up @@ -175,6 +187,10 @@ QuicStreamInitialize(
if (Stream) {
#if DEBUG
CXPLAT_DBG_ASSERT(!CxPlatRefDecrement(&Stream->RefTypeBiasedCount[QUIC_STREAM_REF_APP]));
CxPlatDispatchLockAcquire(&QuicStreamTrackerLock);
CxPlatListEntryRemove(&Stream->TrackerLink);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we may want to introduce some abstractions for these trackers, such that if perf becomes a practical bottleneck on debug builds, we can:

  1. Easily add some more fields beyond the list entry
  2. Easily replace the single global list with something more sophisticated, such as a per-CPU list

CxPlatDispatchLockRelease(&QuicStreamTrackerLock);

CxPlatDispatchLockAcquire(&Connection->Streams.AllStreamsLock);
CxPlatListEntryRemove(&Stream->AllStreamsLink);
CxPlatDispatchLockRelease(&Connection->Streams.AllStreamsLock);
Expand Down Expand Up @@ -214,6 +230,10 @@ QuicStreamFree(
CXPLAT_DBG_ASSERT(Stream->SendRequests == NULL);

#if DEBUG
CxPlatDispatchLockAcquire(&QuicStreamTrackerLock);
CxPlatListEntryRemove(&Stream->TrackerLink);
CxPlatDispatchLockRelease(&QuicStreamTrackerLock);

CxPlatDispatchLockAcquire(&Connection->Streams.AllStreamsLock);
CxPlatListEntryRemove(&Stream->AllStreamsLink);
CxPlatDispatchLockRelease(&Connection->Streams.AllStreamsLock);
Expand Down
12 changes: 12 additions & 0 deletions src/core/stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@

typedef struct QUIC_CONNECTION QUIC_CONNECTION;

#if DEBUG
//
// Global stream object tracker for debugging.
//
extern CXPLAT_DISPATCH_LOCK QuicStreamTrackerLock;
#endif

//
// The stream type is encoded into the low bits of the stream ID:
//
Expand Down Expand Up @@ -265,6 +272,11 @@ typedef struct QUIC_STREAM {
// The list entry in the stream set's list of all allocated streams.
//
CXPLAT_LIST_ENTRY AllStreamsLink;

//
// The list entry in the global stream tracker list.
//
CXPLAT_LIST_ENTRY TrackerLink;
#endif

//
Expand Down
Loading