From ac25910f48624be0a53697d47f5789a2ff17ab3b Mon Sep 17 00:00:00 2001 From: Manish Godse <61718172+mangod9@users.noreply.github.com> Date: Mon, 28 Oct 2024 10:28:26 -0700 Subject: [PATCH 1/3] handle case of Proc Index > MAX_SUPPORTED_CPUS --- src/coreclr/gc/gc.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/coreclr/gc/gc.cpp b/src/coreclr/gc/gc.cpp index 217e90d38c0228..e29bea275c89ee 100644 --- a/src/coreclr/gc/gc.cpp +++ b/src/coreclr/gc/gc.cpp @@ -6404,7 +6404,8 @@ class heap_select if (GCToOSInterface::CanGetCurrentProcessorNumber()) { uint32_t proc_no = GCToOSInterface::GetCurrentProcessorNumber(); - proc_no_to_heap_no[proc_no] = (uint16_t)heap_number; + // mod proc_no in case it exceeds MAX_SUPPORTED_CPUS + proc_no_to_heap_no[proc_no % MAX_SUPPORTED_CPUS] = (uint16_t)heap_number; } } @@ -6426,7 +6427,8 @@ class heap_select if (GCToOSInterface::CanGetCurrentProcessorNumber()) { uint32_t proc_no = GCToOSInterface::GetCurrentProcessorNumber(); - int adjusted_heap = proc_no_to_heap_no[proc_no]; + // mod proc_no in case it exceeds MAX_SUPPORTED_CPUS + int adjusted_heap = proc_no_to_heap_no[proc_no % MAX_SUPPORTED_CPUS]; // with dynamic heap count, need to make sure the value is in range. if (adjusted_heap >= gc_heap::n_heaps) { From 2889ef2e3806f362aa44735c7f75d22e4f7a0ea6 Mon Sep 17 00:00:00 2001 From: Manish Godse <61718172+mangod9@users.noreply.github.com> Date: Mon, 28 Oct 2024 21:09:01 -0700 Subject: [PATCH 2/3] PR feedback --- src/coreclr/gc/gc.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreclr/gc/gc.cpp b/src/coreclr/gc/gc.cpp index e29bea275c89ee..ab850b8357a5dc 100644 --- a/src/coreclr/gc/gc.cpp +++ b/src/coreclr/gc/gc.cpp @@ -6404,7 +6404,7 @@ class heap_select if (GCToOSInterface::CanGetCurrentProcessorNumber()) { uint32_t proc_no = GCToOSInterface::GetCurrentProcessorNumber(); - // mod proc_no in case it exceeds MAX_SUPPORTED_CPUS + // proc_no could likely exceed MAX_SUPPORTED_CPUS on x86 proc_no_to_heap_no[proc_no % MAX_SUPPORTED_CPUS] = (uint16_t)heap_number; } } @@ -6427,7 +6427,7 @@ class heap_select if (GCToOSInterface::CanGetCurrentProcessorNumber()) { uint32_t proc_no = GCToOSInterface::GetCurrentProcessorNumber(); - // mod proc_no in case it exceeds MAX_SUPPORTED_CPUS + // proc_no could likely exceed MAX_SUPPORTED_CPUS on x86 int adjusted_heap = proc_no_to_heap_no[proc_no % MAX_SUPPORTED_CPUS]; // with dynamic heap count, need to make sure the value is in range. if (adjusted_heap >= gc_heap::n_heaps) From 1f74910bcc135b4b33caf1c11c5736fa7d53fe03 Mon Sep 17 00:00:00 2001 From: Manish Godse <61718172+mangod9@users.noreply.github.com> Date: Wed, 30 Oct 2024 10:32:53 -0700 Subject: [PATCH 3/3] Update comment --- src/coreclr/gc/gc.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/coreclr/gc/gc.cpp b/src/coreclr/gc/gc.cpp index ab850b8357a5dc..e0f084cd0338df 100644 --- a/src/coreclr/gc/gc.cpp +++ b/src/coreclr/gc/gc.cpp @@ -6404,7 +6404,10 @@ class heap_select if (GCToOSInterface::CanGetCurrentProcessorNumber()) { uint32_t proc_no = GCToOSInterface::GetCurrentProcessorNumber(); - // proc_no could likely exceed MAX_SUPPORTED_CPUS on x86 + // For a 32-bit process running on a machine with > 64 procs, + // even though the process can only use up to 32 procs, the processor + // index can be >= 64; or in the cpu group case, if the process is not running in cpu group #0, + // the GetCurrentProcessorNumber will return a number that's >= 64. proc_no_to_heap_no[proc_no % MAX_SUPPORTED_CPUS] = (uint16_t)heap_number; } } @@ -6427,7 +6430,10 @@ class heap_select if (GCToOSInterface::CanGetCurrentProcessorNumber()) { uint32_t proc_no = GCToOSInterface::GetCurrentProcessorNumber(); - // proc_no could likely exceed MAX_SUPPORTED_CPUS on x86 + // For a 32-bit process running on a machine with > 64 procs, + // even though the process can only use up to 32 procs, the processor + // index can be >= 64; or in the cpu group case, if the process is not running in cpu group #0, + // the GetCurrentProcessorNumber will return a number that's >= 64. int adjusted_heap = proc_no_to_heap_no[proc_no % MAX_SUPPORTED_CPUS]; // with dynamic heap count, need to make sure the value is in range. if (adjusted_heap >= gc_heap::n_heaps)