Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay Start Worker Threads #3930

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
7 changes: 5 additions & 2 deletions scripts/run-gtest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,10 @@ param (
[string]$OsRunner = "",

[Parameter(Mandatory = $false)]
[switch]$UseQtip = $false
[switch]$UseQtip = $false,

[Parameter(Mandatory = $false)]
[Int32]$Timeout = 60000
)

Set-StrictMode -Version 'Latest'
Expand Down Expand Up @@ -385,7 +388,7 @@ function Start-TestCase([String]$Name) {

# Build up the argument list.
$ResultsPath = Join-Path $LocalLogDir "results.xml"
$Arguments = "--gtest_catch_exceptions=0 --gtest_filter=$($Name) --gtest_output=xml:$($ResultsPath) --timeout 60000"
$Arguments = "--gtest_catch_exceptions=0 --gtest_filter=$($Name) --gtest_output=xml:$($ResultsPath) --timeout $Timeout"
if ($BreakOnFailure) {
$Arguments += " --gtest_break_on_failure"
}
Expand Down
7 changes: 5 additions & 2 deletions scripts/test.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,10 @@ param (
[string]$OsRunner = "",

[Parameter(Mandatory = $false)]
[int]$NumIterations = 1
[int]$NumIterations = 1,

[Parameter(Mandatory = $false)]
[Int32]$Timeout = 60000
)

Set-StrictMode -Version 'Latest'
Expand Down Expand Up @@ -285,7 +288,7 @@ if (!(Test-Path $PfxFile)) {
}

# Build up all the arguments to pass to the Powershell script.
$TestArguments = "-IsolationMode $IsolationMode -PfxPath $PfxFile"
$TestArguments = "-IsolationMode $IsolationMode -PfxPath $PfxFile -Timeout $Timeout"

if ($DuoNic) {
$TestArguments += " -DuoNic"
Expand Down
121 changes: 94 additions & 27 deletions src/core/worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,42 @@
_In_ QUIC_WORKER* Worker
);

_IRQL_requires_max_(PASSIVE_LEVEL)
QUIC_STATUS
QuicWorkerStartThread(
_In_ QUIC_WORKER* Worker
)
{
const uint16_t ThreadFlags =

Check warning on line 63 in src/core/worker.c

View check run for this annotation

Codecov / codecov/patch

src/core/worker.c#L62-L63

Added lines #L62 - L63 were not covered by tests
Worker->ExecProfile == QUIC_EXECUTION_PROFILE_TYPE_REAL_TIME ?
CXPLAT_THREAD_FLAG_SET_AFFINITIZE : CXPLAT_THREAD_FLAG_NONE;

CXPLAT_THREAD_CONFIG ThreadConfig = {

Check warning on line 67 in src/core/worker.c

View check run for this annotation

Codecov / codecov/patch

src/core/worker.c#L67

Added line #L67 was not covered by tests
ThreadFlags,
QuicLibraryGetPartitionProcessor(Worker->PartitionIndex),
"quic_worker",
QuicWorkerThread,
Worker
};

QuicTraceLogVerbose(

Check warning on line 75 in src/core/worker.c

View check run for this annotation

Codecov / codecov/patch

src/core/worker.c#L75

Added line #L75 was not covered by tests
WorkerStarting,
"[wrkr][%p] Starting thread",
Worker);

QUIC_STATUS Status = CxPlatThreadCreate(&ThreadConfig, &Worker->Thread);
if (QUIC_FAILED(Status)) {
QuicTraceEvent(

Check warning on line 82 in src/core/worker.c

View check run for this annotation

Codecov / codecov/patch

src/core/worker.c#L80-L82

Added lines #L80 - L82 were not covered by tests
WorkerErrorStatus,
"[wrkr][%p] ERROR, %u, %s.",
Worker,
Status,
"CxPlatThreadCreate");
}

return Status;
}

Check warning on line 91 in src/core/worker.c

View check run for this annotation

Codecov / codecov/patch

src/core/worker.c#L90-L91

Added lines #L90 - L91 were not covered by tests

_IRQL_requires_max_(PASSIVE_LEVEL)
QUIC_STATUS
QuicWorkerInitialize(
Expand All @@ -71,6 +107,7 @@
Registration);

Worker->Enabled = TRUE;
Worker->ExecProfile = ExecProfile;
Worker->PartitionIndex = PartitionIndex;
CxPlatDispatchLockInitialize(&Worker->Lock);
CxPlatEventInitialize(&Worker->Done, TRUE, FALSE);
Expand All @@ -95,36 +132,24 @@
Worker->ExecutionContext.NextTimeUs = UINT64_MAX;
Worker->ExecutionContext.Ready = TRUE;

#ifndef _KERNEL_MODE // Not supported on kernel mode
#ifdef _KERNEL_MODE
//
// Kernel mode always has to start threads up front, because delay load
// requires creating the thread later at PASSIVE_LEVEL, but several of the
// places we would need to do so are at DISPATCH_LEVEL.
//
Status = QuicWorkerStartThread(Worker);
#else
if (ExecProfile != QUIC_EXECUTION_PROFILE_TYPE_MAX_THROUGHPUT) {
Worker->IsExternal = TRUE;
CxPlatAddExecutionContext(&Worker->ExecutionContext, PartitionIndex);
} else
#endif // _KERNEL_MODE
{
const uint16_t ThreadFlags =
ExecProfile == QUIC_EXECUTION_PROFILE_TYPE_REAL_TIME ?
CXPLAT_THREAD_FLAG_SET_AFFINITIZE : CXPLAT_THREAD_FLAG_NONE;

CXPLAT_THREAD_CONFIG ThreadConfig = {
ThreadFlags,
QuicLibraryGetPartitionProcessor(PartitionIndex),
"quic_worker",
QuicWorkerThread,
Worker
};

Status = CxPlatThreadCreate(&ThreadConfig, &Worker->Thread);
if (QUIC_FAILED(Status)) {
QuicTraceEvent(
WorkerErrorStatus,
"[wrkr][%p] ERROR, %u, %s.",
Worker,
Status,
"CxPlatThreadCreate");
goto Error;
}
CxPlatAddExecutionContext(&Worker->ExecutionContext, PartitionIndex, FALSE);
} else {
//
// Don't start the thread until it's needed.
//
Worker->DelayStart = TRUE;

Check warning on line 150 in src/core/worker.c

View check run for this annotation

Codecov / codecov/patch

src/core/worker.c#L150

Added line #L150 was not covered by tests
}
#endif // _KERNEL_MODE

Error:

Expand Down Expand Up @@ -225,6 +250,14 @@

CxPlatDispatchLockAcquire(&Worker->Lock);

#ifndef _KERNEL_MODE // Not supported on kernel mode
BOOLEAN DelayStart = FALSE;
if (Worker->DelayStart) {
DelayStart = TRUE;
Worker->DelayStart = FALSE;

Check warning on line 257 in src/core/worker.c

View check run for this annotation

Codecov / codecov/patch

src/core/worker.c#L256-L257

Added lines #L256 - L257 were not covered by tests
}
#endif // _KERNEL_MODE

BOOLEAN WakeWorkerThread;
if (!Connection->WorkerProcessing && !Connection->HasQueuedWork) {
WakeWorkerThread = QuicWorkerIsIdle(Worker);
Expand Down Expand Up @@ -252,6 +285,12 @@
if (WakeWorkerThread) {
QuicWorkerThreadWake(Worker);
}

#ifndef _KERNEL_MODE
if (DelayStart) {
QuicWorkerStartThread(Worker);

Check warning on line 291 in src/core/worker.c

View check run for this annotation

Codecov / codecov/patch

src/core/worker.c#L291

Added line #L291 was not covered by tests
}
#endif // _KERNEL_MODE
}

_IRQL_requires_max_(DISPATCH_LEVEL)
Expand All @@ -265,6 +304,14 @@

CxPlatDispatchLockAcquire(&Worker->Lock);

#ifndef _KERNEL_MODE // Not supported on kernel mode
BOOLEAN DelayStart = FALSE;
if (Worker->DelayStart) {
DelayStart = TRUE;
Worker->DelayStart = FALSE;

Check warning on line 311 in src/core/worker.c

View check run for this annotation

Codecov / codecov/patch

src/core/worker.c#L310-L311

Added lines #L310 - L311 were not covered by tests
}
#endif // _KERNEL_MODE

BOOLEAN WakeWorkerThread = QuicWorkerIsIdle(Worker);

if (Connection->HasQueuedWork) {
Expand All @@ -283,6 +330,12 @@
if (WakeWorkerThread) {
QuicWorkerThreadWake(Worker);
}

#ifndef _KERNEL_MODE
if (DelayStart) {
QuicWorkerStartThread(Worker);

Check warning on line 336 in src/core/worker.c

View check run for this annotation

Codecov / codecov/patch

src/core/worker.c#L336

Added line #L336 was not covered by tests
}
#endif // _KERNEL_MODE
}

_IRQL_requires_max_(DISPATCH_LEVEL)
Expand All @@ -294,6 +347,14 @@
{
CxPlatDispatchLockAcquire(&Worker->Lock);

#ifndef _KERNEL_MODE // Not supported on kernel mode
BOOLEAN DelayStart = FALSE;
if (Worker->DelayStart) {
DelayStart = TRUE;
Worker->DelayStart = FALSE;

Check warning on line 354 in src/core/worker.c

View check run for this annotation

Codecov / codecov/patch

src/core/worker.c#L353-L354

Added lines #L353 - L354 were not covered by tests
}
#endif // _KERNEL_MODE

BOOLEAN WakeWorkerThread;
if (Worker->OperationCount < MsQuicLib.Settings.MaxStatelessOperations &&
QuicLibraryTryAddRefBinding(Operation->STATELESS.Context->Binding)) {
Expand All @@ -319,6 +380,12 @@
} else if (WakeWorkerThread) {
QuicWorkerThreadWake(Worker);
}

#ifndef _KERNEL_MODE
if (DelayStart) {
QuicWorkerStartThread(Worker);

Check warning on line 386 in src/core/worker.c

View check run for this annotation

Codecov / codecov/patch

src/core/worker.c#L386

Added line #L386 was not covered by tests
}
#endif // _KERNEL_MODE
}

_IRQL_requires_max_(PASSIVE_LEVEL)
Expand Down
14 changes: 12 additions & 2 deletions src/core/worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,25 @@ typedef struct QUIC_CACHEALIGN QUIC_WORKER {
BOOLEAN IsActive;

//
// The index into the partition array (of processors).
// TRUE if the worker still needs its thread to be started.
//
uint16_t PartitionIndex;
BOOLEAN DelayStart;

//
// The execution profile for this worker, inherited from the registration.
//
QUIC_EXECUTION_PROFILE ExecProfile;

//
// The average queue delay connections experience, in microseconds.
//
uint32_t AverageQueueDelay;

//
// The index into the partition array (of processors).
//
uint16_t PartitionIndex;

//
// Timers for the worker's connections.
//
Expand Down
38 changes: 38 additions & 0 deletions src/generated/linux/platform_worker.c.clog.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@
#ifdef __cplusplus
extern "C" {
#endif
/*----------------------------------------------------------
// Decoder Ring for PlatformWorkerThreadStarting
// [ lib][%p] Worker starting
// QuicTraceLogInfo(
PlatformWorkerThreadStarting,
"[ lib][%p] Worker starting",
Worker);
// arg2 = arg2 = Worker = arg2
----------------------------------------------------------*/
#ifndef _clog_3_ARGS_TRACE_PlatformWorkerThreadStarting
#define _clog_3_ARGS_TRACE_PlatformWorkerThreadStarting(uniqueId, encoded_arg_string, arg2)\
tracepoint(CLOG_PLATFORM_WORKER_C, PlatformWorkerThreadStarting , arg2);\

#endif




/*----------------------------------------------------------
// Decoder Ring for PlatformWorkerThreadStart
// [ lib][%p] Worker start
Expand Down Expand Up @@ -99,6 +117,26 @@ tracepoint(CLOG_PLATFORM_WORKER_C, LibraryError , arg2);\



/*----------------------------------------------------------
// Decoder Ring for LibraryErrorStatus
// [ lib] ERROR, %u, %s.
// QuicTraceEvent(
LibraryErrorStatus,
"[ lib] ERROR, %u, %s.",
Status,
"Create platform worker thread failed");
// arg2 = arg2 = Status = arg2
// arg3 = arg3 = "Create platform worker thread failed" = arg3
----------------------------------------------------------*/
#ifndef _clog_4_ARGS_TRACE_LibraryErrorStatus
#define _clog_4_ARGS_TRACE_LibraryErrorStatus(uniqueId, encoded_arg_string, arg2, arg3)\
tracepoint(CLOG_PLATFORM_WORKER_C, LibraryErrorStatus , arg2, arg3);\

#endif




#ifdef __cplusplus
}
#endif
Expand Down
42 changes: 42 additions & 0 deletions src/generated/linux/platform_worker.c.clog.h.lttng.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@



/*----------------------------------------------------------
// Decoder Ring for PlatformWorkerThreadStarting
// [ lib][%p] Worker starting
// QuicTraceLogInfo(
PlatformWorkerThreadStarting,
"[ lib][%p] Worker starting",
Worker);
// arg2 = arg2 = Worker = arg2
----------------------------------------------------------*/
TRACEPOINT_EVENT(CLOG_PLATFORM_WORKER_C, PlatformWorkerThreadStarting,
TP_ARGS(
const void *, arg2),
TP_FIELDS(
ctf_integer_hex(uint64_t, arg2, arg2)
)
)



/*----------------------------------------------------------
// Decoder Ring for PlatformWorkerThreadStart
// [ lib][%p] Worker start
Expand Down Expand Up @@ -78,3 +97,26 @@ TRACEPOINT_EVENT(CLOG_PLATFORM_WORKER_C, LibraryError,
ctf_string(arg2, arg2)
)
)



/*----------------------------------------------------------
// Decoder Ring for LibraryErrorStatus
// [ lib] ERROR, %u, %s.
// QuicTraceEvent(
LibraryErrorStatus,
"[ lib] ERROR, %u, %s.",
Status,
"Create platform worker thread failed");
// arg2 = arg2 = Status = arg2
// arg3 = arg3 = "Create platform worker thread failed" = arg3
----------------------------------------------------------*/
TRACEPOINT_EVENT(CLOG_PLATFORM_WORKER_C, LibraryErrorStatus,
TP_ARGS(
unsigned int, arg2,
const char *, arg3),
TP_FIELDS(
ctf_integer(unsigned int, arg2, arg2)
ctf_string(arg3, arg3)
)
)
Loading
Loading