Skip to content

Commit 2975db0

Browse files
author
Keegan Caruso
committed
Feedback:
Use different keys from reading from env vs config
1 parent 50d14f5 commit 2975db0

File tree

9 files changed

+49
-43
lines changed

9 files changed

+49
-43
lines changed

src/coreclr/nativeaot/Runtime/RhConfig.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,27 @@ bool RhConfig::ReadConfigValue(_In_z_ const char *name, uint64_t* pValue, bool d
139139
return false;
140140
}
141141

142+
bool RhConfig::ReadConfigValue(_In_z_ const char* envName, _In_z_ const char* configName, uint64_t* pValue, bool decimal)
143+
{
144+
uint64_t uiValue;
145+
if (g_pRhConfig->ReadConfigValue(envName, &uiValue))
146+
{
147+
*pValue = uiValue;
148+
return true;
149+
}
150+
151+
if (configName)
152+
{
153+
if (g_pRhConfig->ReadKnobUInt64Value(configName, &uiValue))
154+
{
155+
*pValue = uiValue;
156+
return true;
157+
}
158+
}
159+
160+
return false;
161+
}
162+
142163
bool RhConfig::ReadKnobUInt64Value(_In_z_ const char *name, uint64_t* pValue)
143164
{
144165
const char *embeddedValue = nullptr;

src/coreclr/nativeaot/Runtime/RhConfig.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class RhConfig
4545
};
4646

4747
bool ReadConfigValue(_In_z_ const char* wszName, uint64_t* pValue, bool decimal = false);
48+
bool ReadConfigValue(_In_z_ const char* wszEnvName, _In_z_ const char* wszConfigName, uint64_t* pValue, bool decimal = false);
4849
bool ReadKnobUInt64Value(_In_z_ const char* wszName, uint64_t* pValue);
4950
bool ReadKnobBooleanValue(_In_z_ const char* wszName, bool* pValue);
5051

src/coreclr/nativeaot/Runtime/RhConfigValues.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ RETAIL_CONFIG_VALUE(StressLogLevel)
1414
RETAIL_CONFIG_VALUE(TotalStressLogSize)
1515
RETAIL_CONFIG_VALUE(gcServer)
1616
RETAIL_CONFIG_VALUE(gcConservative) // Enables conservative stack reporting
17-
RETAIL_CONFIG_VALUE(DefaultStackSize) // Enables setting the default stack size
1817
DEBUG_CONFIG_VALUE(GcStressThrottleMode) // gcstm_TriggerAlways / gcstm_TriggerOnFirstHit / gcstm_TriggerRandom
1918
DEBUG_CONFIG_VALUE(GcStressFreqCallsite) // Number of times to force GC out of GcStressFreqDenom (for GCSTM_RANDOM)
2019
DEBUG_CONFIG_VALUE(GcStressFreqLoop) // Number of times to force GC out of GcStressFreqDenom (for GCSTM_RANDOM)

src/coreclr/nativeaot/Runtime/gcenv.ee.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -768,21 +768,12 @@ bool GCToEEInterface::GetIntConfigValue(const char* privateKey, const char* publ
768768
}
769769

770770
uint64_t uiValue;
771-
if (g_pRhConfig->ReadConfigValue(privateKey, &uiValue))
771+
if (g_pRhConfig->ReadConfigValue(privateKey, publicKey, &uiValue))
772772
{
773773
*value = uiValue;
774774
return true;
775775
}
776776

777-
if (publicKey)
778-
{
779-
if (g_pRhConfig->ReadKnobUInt64Value(publicKey, &uiValue))
780-
{
781-
*value = uiValue;
782-
return true;
783-
}
784-
}
785-
786777
return false;
787778
}
788779

src/coreclr/nativeaot/Runtime/unix/PalRedhawkUnix.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -689,12 +689,14 @@ REDHAWK_PALEXPORT bool REDHAWK_PALAPI PalStartBackgroundWork(_In_ BackgroundCall
689689
const size_t minStack = 0x10000; // 64K
690690
const size_t maxStack = 0x80000000; // 2G
691691

692-
uint64_t stacksize = g_pRhConfig->GetDefaultStackSize();
693-
694-
if (stacksize < maxStack && stacksize >= minStack)
692+
uint64_t stackSize;
693+
if (g_pRhConfig->ReadConfigValue("Threading_DefaultStackSize", "System.Threading.DefaultStackSize", &stackSize))
695694
{
696-
st = pthread_attr_setstacksize(&attrs, (size_t)stacksize);
697-
ASSERT(st == 0);
695+
if (stacksize < maxStack && stacksize >= minStack)
696+
{
697+
st = pthread_attr_setstacksize(&attrs, (size_t)stacksize);
698+
ASSERT(st == 0);
699+
}
698700
}
699701

700702
static const int NormalPriority = 0;

src/coreclr/nativeaot/Runtime/windows/PalRedhawkMinWin.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -897,11 +897,15 @@ REDHAWK_PALEXPORT bool REDHAWK_PALAPI PalStartBackgroundWork(_In_ BackgroundCall
897897
const size_t minStack = 0x10000; // 64K
898898
const size_t maxStack = 0x80000000; // 2G
899899

900-
uint64_t stacksize = g_pRhConfig->GetDefaultStackSize();
900+
uint64_t stacksize = 0;
901901

902-
if (stacksize >= maxStack || stacksize < minStack)
902+
uint64_t uiStacksize;
903+
if (g_pRhConfig->ReadConfigValue("Threading_DefaultStackSize", "System.Threading.DefaultStackSize", &uiStacksize))
903904
{
904-
stacksize = 0;
905+
if (uiStacksize < maxStack || uiStacksize >= minStack)
906+
{
907+
stacksize = uiStacksize;
908+
}
905909
}
906910

907911
HANDLE hThread = CreateThread(

src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.Unix.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private unsafe bool CreateThread(GCHandle thisThreadHandle)
9898

9999
if (stackSize <= 0)
100100
{
101-
stackSize = StackSizeFromConfig;
101+
stackSize = _stackSizeFromConfig;
102102
}
103103

104104
if (!Interop.Sys.CreateThread((IntPtr)stackSize, &ThreadEntryPoint, (IntPtr)thisThreadHandle))

src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.Windows.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ private unsafe bool CreateThread(GCHandle thisThreadHandle)
182182

183183
if (stackSize <= 0)
184184
{
185-
stackSize = StackSizeFromConfig;
185+
stackSize = _stackSizeFromConfig;
186186
}
187187

188188
if ((0 < stackSize) && (stackSize < AllocationGranularity))

src/coreclr/nativeaot/System.Private.CoreLib/src/System/Threading/Thread.NativeAot.cs

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -483,36 +483,24 @@ private static void StopThread(Thread thread)
483483
}
484484
}
485485

486-
487-
private static int StackSizeFromConfig
488-
{
489-
get => _stackSizeFromConfig ??= GetDefaultStackSize();
490-
}
491-
492-
private static int? _stackSizeFromConfig;
486+
private static int _stackSizeFromConfig = GetDefaultStackSize();
493487

494488
internal static int GetDefaultStackSize()
495489
{
496490
// Keep the same arbitrary minimum and maximum from the coreclr\vm layer.
491+
// The max was 0x80000000 (2G).
492+
// This is checked by the value being parsed into an int32.
497493
const uint minStack = 0x10000; // 64K
498-
const uint maxStack = 0x80000000; // 2G
499-
500-
const string stackSizeVar = "DefaultStackSize";
501-
const string stackSizeEnvVar = "DOTNET_DefaultStackSize";
502-
503-
// Values in RuntimeHostConfigurationOptions get mapped as knobs, knobs get exposed through
504-
// the AppContext class.
505-
// To have similar behavior as RhConfig, also read from environment variables, which have priority.
506494

507-
string? valueFromConfig = Environment.GetEnvironmentVariable(stackSizeEnvVar) ?? AppContext.GetData(stackSizeVar)?.ToString();
495+
int sizeFromConfig = AppContextConfigHelper.GetInt32Config(
496+
"System.Threading.DefaultStackSize",
497+
"DOTNET_Threading_DefaultStackSize",
498+
0,
499+
false);
508500

509-
if (!string.IsNullOrEmpty(valueFromConfig) &&
510-
uint.TryParse(valueFromConfig, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out uint sizeFromConfig) &&
511-
sizeFromConfig >= minStack &&
512-
sizeFromConfig < maxStack)
501+
if (sizeFromConfig >= minStack)
513502
{
514-
// Less than the maxStack size means it will fit in a signed int32.
515-
return (int)sizeFromConfig;
503+
return sizeFromConfig;
516504
}
517505

518506
return 0;

0 commit comments

Comments
 (0)