Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Updated logic to make use of the config affinity mask for cases where…
… there are < 65 cores and the user passed in a config related to the 0th CPU Group
  • Loading branch information
mrsharm committed Apr 20, 2022
commit 5980bd464ac9fa3ee3ac922679d724dfd0e0ab8a
2 changes: 1 addition & 1 deletion src/coreclr/gc/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43845,7 +43845,7 @@ HRESULT GCHeap::Initialize()
AffinitySet config_affinity_set;
GCConfigStringHolder cpu_index_ranges_holder(GCConfig::GetGCHeapAffinitizeRanges());

uintptr_t config_affinity_mask;
uintptr_t config_affinity_mask = 0;
if (!ParseGCHeapAffinitizeRanges(cpu_index_ranges_holder.Get(), &config_affinity_set, config_affinity_mask))
{
return CLR_E_GC_BAD_AFFINITY_CONFIG_FORMAT;
Expand Down
77 changes: 47 additions & 30 deletions src/coreclr/gc/gcconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,45 +85,62 @@ bool ParseGCHeapAffinitizeRanges(const char* cpu_index_ranges, AffinitySet* conf
{
bool success = true;

// Unix:
// The cpu index ranges is a comma separated list of indices or ranges of indices (e.g. 1-5).
// Example 1,3,5,7-9,12
// Windows:
// The cpu index ranges is a comma separated list of group-annotated indices or ranges of indices.
// The group number always prefixes index or range and is followed by colon.
// Example 0:1,0:3,0:5,1:7-9,1:12

if (cpu_index_ranges != NULL)
config_affinity_mask = static_cast<uintptr_t>(GCConfig::GetGCHeapAffinitizeMask());

// Case 1: config_affinity_mask and config_affinity_set are both null. No affinitization.
// Case 2: config_affinity_mask is not null but config_affinity_set is null. Affinitization is based on config_affinity_mask.
if (cpu_index_ranges == nullptr)
{
const char* number_end = cpu_index_ranges;
return success;
}

do
// Case 3: config_affinity_mask is null but cpu_index_ranges isn't.
// To facilitate the case where there are less than 65 cores but the user passes in an affinitized range associated
// with the 0th CPU Group, we override the config_affinity_mask with the same contents as the cpu_index_ranges.
else if (config_affinity_mask == 0 && cpu_index_ranges != nullptr)
{
// Unix:
// The cpu index ranges is a comma separated list of indices or ranges of indices (e.g. 1-5).
// Example 1,3,5,7-9,12
// Windows:
// The cpu index ranges is a comma separated list of group-annotated indices or ranges of indices.
// The group number always prefixes index or range and is followed by colon.
// Example 0:1,0:3,0:5,1:7-9,1:12

if (cpu_index_ranges != nullptr)
{
size_t start_index, end_index;
if (!GCToOSInterface::ParseGCHeapAffinitizeRangesEntry(&cpu_index_ranges, &start_index, &end_index))
{
break;
}
const char* number_end = cpu_index_ranges;

if ((start_index >= MAX_SUPPORTED_CPUS) || (end_index >= MAX_SUPPORTED_CPUS) || (end_index < start_index))
do
{
// Invalid CPU index values or range
break;
size_t start_index, end_index;
if (!GCToOSInterface::ParseGCHeapAffinitizeRangesEntry(&cpu_index_ranges, &start_index, &end_index))
{
break;
}

if ((start_index >= MAX_SUPPORTED_CPUS) || (end_index >= MAX_SUPPORTED_CPUS) || (end_index < start_index))
{
// Invalid CPU index values or range
break;
}

static const size_t BitsPerBitsetEntry = 8 * sizeof(uintptr_t);

for (size_t i = start_index; i <= end_index; i++)
{
config_affinity_set->Add(i);
config_affinity_mask |= (uintptr_t)1 << (i & (BitsPerBitsetEntry - 1));
}

number_end = cpu_index_ranges;
cpu_index_ranges++;
}
while (*number_end == ',');

for (size_t i = start_index; i <= end_index; i++)
{
config_affinity_set->Add(i);
}

number_end = cpu_index_ranges;
cpu_index_ranges++;
success = (*number_end == '\0');
}
while (*number_end == ',');

success = (*number_end == '\0');
}

config_affinity_mask = static_cast<uintptr_t>(GCConfig::GetGCHeapAffinitizeMask());
return success;
}
11 changes: 0 additions & 11 deletions src/coreclr/gc/windows/gcenv.windows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -944,17 +944,6 @@ const AffinitySet* GCToOSInterface::SetGCThreadsAffinitySet(uintptr_t configAffi
}
}
}
else if (!configAffinitySet->IsEmpty())
{
// Update the process affinity set using the configured set
for (size_t i = 0; i < MAX_SUPPORTED_CPUS; i++)
{
if (g_processAffinitySet.Contains(i) && !configAffinitySet->Contains(i))
{
g_processAffinitySet.Remove(i);
}
}
}
}

return &g_processAffinitySet;
Expand Down
11 changes: 0 additions & 11 deletions src/coreclr/vm/gcenv.os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -737,17 +737,6 @@ const AffinitySet* GCToOSInterface::SetGCThreadsAffinitySet(uintptr_t configAffi
}
}
}
else if (!configAffinitySet->IsEmpty())
{
// Update the process affinity set using the configured set
for (size_t i = 0; i < MAX_SUPPORTED_CPUS; i++)
{
if (g_processAffinitySet.Contains(i) && !configAffinitySet->Contains(i))
{
g_processAffinitySet.Remove(i);
}
}
}
}
#endif // !TARGET_UNIX

Expand Down