Skip to content

Commit

Permalink
Parse DOTNET_PROCESSOR_COUNT with a 10 radix not 16 (#53208)
Browse files Browse the repository at this point in the history
* Parse DOTNET_PROCESSOR_COUNT with a 10 radix not 16

* Update test for DOTNET_PROCESSOR_COUNT
  • Loading branch information
AaronRobinsonMSFT authored May 25, 2021
1 parent 7d2c493 commit cc8d9b3
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
6 changes: 5 additions & 1 deletion src/coreclr/inc/clrconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ class CLRConfig

// Remove any whitespace at beginning and end of value. (Only applicable for
// *string* configuration values.)
TrimWhiteSpaceFromStringValue = 0x2
TrimWhiteSpaceFromStringValue = 0x2,

// The configuration should be parsed using a 10 radix as opposed to the
// default of 16.
ParseIntegerAsBase10 = 0x4,
};

// Struct used to store information about where/how to find a Config DWORD.
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/inc/clrconfigvalues.h
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ RETAIL_CONFIG_DWORD_INFO(INTERNAL_Thread_DeadThreadCountThresholdForGCTrigger, W
RETAIL_CONFIG_DWORD_INFO(INTERNAL_Thread_DeadThreadGCTriggerPeriodMilliseconds, W("Thread_DeadThreadGCTriggerPeriodMilliseconds"), 1000 * 60 * 30, "In the heuristics to clean up dead threads, this much time must have elapsed since the previous max-generation GC before triggering another GC will be considered")
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_Thread_UseAllCpuGroups, W("Thread_UseAllCpuGroups"), 0, "Specifies whether to query and use CPU group information for determining the processor count.")
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_Thread_AssignCpuGroups, W("Thread_AssignCpuGroups"), 1, "Specifies whether to automatically distribute threads created by the CLR across CPU Groups. Effective only when Thread_UseAllCpuGroups and GCCpuGroup are enabled.")
RETAIL_CONFIG_DWORD_INFO(EXTERNAL_ProcessorCount, W("PROCESSOR_COUNT"), 0, "Specifies the number of processors available for the process, which is returned by Environment.ProcessorCount")
RETAIL_CONFIG_DWORD_INFO_EX(EXTERNAL_ProcessorCount, W("PROCESSOR_COUNT"), 0, "Specifies the number of processors available for the process, which is returned by Environment.ProcessorCount", CLRConfig::LookupOptions::ParseIntegerAsBase10)

///
/// Threadpool
Expand Down
6 changes: 5 additions & 1 deletion src/coreclr/utilcode/clrconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,16 @@ namespace

FAULT_NOT_FATAL(); // We don't report OOM errors here, we return a default value.

int radix = CheckLookupOption(options, LookupOptions::ParseIntegerAsBase10)
? 10
: 16; // Parse as hex by default.

NewArrayHolder<WCHAR> val = EnvGetString(name, options);
if (val != NULL)
{
errno = 0;
LPWSTR endPtr;
DWORD configMaybe = wcstoul(val, &endPtr, 16); // treat it has hex
DWORD configMaybe = wcstoul(val, &endPtr, radix);
BOOL fSuccess = ((errno != ERANGE) && (endPtr != val));
if (fSuccess)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private static unsafe int ParseProcessorCount(string settingValue)
fixed (char *ptr = settingValue)
{
char *endptr;
int value = (int)wcstoul(ptr, &endptr, 16);
int value = (int)wcstoul(ptr, &endptr, 10);

if (0 < value && value <= MAX_PROCESSOR_COUNT)
return value;
Expand Down Expand Up @@ -69,7 +69,7 @@ public void ProcessorCount_Windows_MatchesGetSystemInfo()
[InlineData(8000, 2000, null)]
[InlineData(8000, 0, "1")]
[InlineData(2000, 0, null)]
[InlineData(2000, 0, " 0x11 ")]
[InlineData(2000, 0, " 17 ")]
[InlineData(0, 0, "3")]
public static unsafe void ProcessorCount_Windows_RespectsJobCpuRateAndConfigurationSetting(
ushort maxRate, ushort minRate, string procCountConfig)
Expand Down

0 comments on commit cc8d9b3

Please sign in to comment.