Skip to content

Commit

Permalink
some code clean up in heap_select (dotnet#99855)
Browse files Browse the repository at this point in the history
noticed some unused code
  • Loading branch information
Maoni0 committed Mar 19, 2024
1 parent 886bca3 commit d814174
Showing 1 changed file with 17 additions and 67 deletions.
84 changes: 17 additions & 67 deletions src/coreclr/gc/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6250,12 +6250,14 @@ class heap_select
static uint16_t proc_no_to_heap_no[MAX_SUPPORTED_CPUS];
static uint16_t heap_no_to_proc_no[MAX_SUPPORTED_CPUS];
static uint16_t heap_no_to_numa_node[MAX_SUPPORTED_CPUS];
static uint16_t proc_no_to_numa_node[MAX_SUPPORTED_CPUS];
static uint16_t numa_node_to_heap_map[MAX_SUPPORTED_CPUS+4];

#ifdef HEAP_BALANCE_INSTRUMENTATION
// Note this is the total numa nodes GC heaps are on. There might be
// more on the machine if GC threads aren't using all of them.
static uint16_t total_numa_nodes;
static node_heap_count heaps_on_node[MAX_SUPPORTED_NODES];
#endif

static int access_time(uint8_t *sniff_buffer, int heap_number, unsigned sniff_index, unsigned n_sniff_buffers)
{
Expand Down Expand Up @@ -6324,7 +6326,6 @@ class heap_select
// we found a heap on cur_node_no
heap_no_to_proc_no[cur_heap_no] = proc_no[i];
heap_no_to_numa_node[cur_heap_no] = cur_node_no;
proc_no_to_numa_node[proc_no[i]] = cur_node_no;

cur_heap_no++;
}
Expand Down Expand Up @@ -6412,37 +6413,16 @@ class heap_select
return GCToOSInterface::CanGetCurrentProcessorNumber();
}

static uint16_t find_heap_no_from_proc_no(uint16_t proc_no)
{
return proc_no_to_heap_no[proc_no];
}

static uint16_t find_proc_no_from_heap_no(int heap_number)
{
return heap_no_to_proc_no[heap_number];
}

static void set_proc_no_for_heap(int heap_number, uint16_t proc_no)
{
heap_no_to_proc_no[heap_number] = proc_no;
}

static uint16_t find_numa_node_from_heap_no(int heap_number)
{
return heap_no_to_numa_node[heap_number];
}

static uint16_t find_numa_node_from_proc_no (uint16_t proc_no)
{
return proc_no_to_numa_node[proc_no];
}

static void set_numa_node_for_heap_and_proc(int heap_number, uint16_t proc_no, uint16_t numa_node)
{
heap_no_to_numa_node[heap_number] = numa_node;
proc_no_to_numa_node[proc_no] = numa_node;
}

static void init_numa_node_to_heap_map(int nheaps)
{
// Called right after GCHeap::Init() for each heap
Expand All @@ -6451,29 +6431,38 @@ class heap_select
// numa_node_to_heap_map[numa_node + 1] is set to the first heap number not on that node
// Set the start of the heap number range for the first NUMA node
numa_node_to_heap_map[heap_no_to_numa_node[0]] = 0;
#ifdef HEAP_BALANCE_INSTRUMENTATION
total_numa_nodes = 0;
memset (heaps_on_node, 0, sizeof (heaps_on_node));
heaps_on_node[0].node_no = heap_no_to_numa_node[0];
heaps_on_node[0].heap_count = 1;
#endif //HEAP_BALANCE_INSTRUMENTATION

for (int i=1; i < nheaps; i++)
{
if (heap_no_to_numa_node[i] != heap_no_to_numa_node[i-1])
{
#ifdef HEAP_BALANCE_INSTRUMENTATION
total_numa_nodes++;
heaps_on_node[total_numa_nodes].node_no = heap_no_to_numa_node[i];
#endif

// Set the end of the heap number range for the previous NUMA node
numa_node_to_heap_map[heap_no_to_numa_node[i-1] + 1] =
// Set the start of the heap number range for the current NUMA node
numa_node_to_heap_map[heap_no_to_numa_node[i]] = (uint16_t)i;
}
#ifdef HEAP_BALANCE_INSTRUMENTATION
(heaps_on_node[total_numa_nodes].heap_count)++;
#endif
}

// Set the end of the heap range for the last NUMA node
numa_node_to_heap_map[heap_no_to_numa_node[nheaps-1] + 1] = (uint16_t)nheaps; //mark the end with nheaps

#ifdef HEAP_BALANCE_INSTRUMENTATION
total_numa_nodes++;
#endif
}

static bool get_info_proc (int index, uint16_t* proc_no, uint16_t* node_no, int* start_heap, int* end_heap)
Expand Down Expand Up @@ -6521,8 +6510,6 @@ class heap_select
proc_no_to_heap_no[proc_no] = current_heap_no % gc_heap::n_heaps;
(current_heap_no)++;
}

proc_no_to_numa_node[proc_no] = node_no;
}
}
else
Expand Down Expand Up @@ -6561,7 +6548,6 @@ class heap_select
}

proc_no_to_heap_no[proc_no] = (uint16_t)current_heap_on_node;
proc_no_to_numa_node[proc_no] = (uint16_t)node_no;

current_heap_on_node++;
}
Expand All @@ -6578,54 +6564,18 @@ class heap_select
dprintf(HEAP_BALANCE_TEMP_LOG, ("TEMPget_heap_range: %d is in numa node %d, start = %d, end = %d", hn, numa_node, *start, *end));
#endif //HEAP_BALANCE_INSTRUMENTATION
}

// This gets the next valid numa node index starting at current_index+1.
// It assumes that current_index is a valid node index.
// If current_index+1 is at the end this will start at the beginning. So this will
// always return a valid node index, along with that node's start/end heaps.
static uint16_t get_next_numa_node (uint16_t current_index, int* start, int* end)
{
int start_index = current_index + 1;
int nheaps = gc_heap::n_heaps;

bool found_node_with_heaps_p = false;
do
{
int start_heap = (int)numa_node_to_heap_map[start_index];
int end_heap = (int)numa_node_to_heap_map[start_index + 1];
if (start_heap == nheaps)
{
// This is the last node.
start_index = 0;
continue;
}

if ((end_heap - start_heap) == 0)
{
// This node has no heaps.
start_index++;
}
else
{
found_node_with_heaps_p = true;
*start = start_heap;
*end = end_heap;
}
} while (!found_node_with_heaps_p);

return (uint16_t)start_index;
}
};
uint8_t* heap_select::sniff_buffer;
unsigned heap_select::n_sniff_buffers;
unsigned heap_select::cur_sniff_index;
uint16_t heap_select::proc_no_to_heap_no[MAX_SUPPORTED_CPUS];
uint16_t heap_select::heap_no_to_proc_no[MAX_SUPPORTED_CPUS];
uint16_t heap_select::heap_no_to_numa_node[MAX_SUPPORTED_CPUS];
uint16_t heap_select::proc_no_to_numa_node[MAX_SUPPORTED_CPUS];
uint16_t heap_select::numa_node_to_heap_map[MAX_SUPPORTED_CPUS+4];
#ifdef HEAP_BALANCE_INSTRUMENTATION
uint16_t heap_select::total_numa_nodes;
node_heap_count heap_select::heaps_on_node[MAX_SUPPORTED_NODES];
#endif

#ifdef HEAP_BALANCE_INSTRUMENTATION
// This records info we use to look at effect of different strategies
Expand Down Expand Up @@ -19241,7 +19191,7 @@ void gc_heap::balance_heaps (alloc_context* acontext)

#ifdef HEAP_BALANCE_INSTRUMENTATION
int current_proc_no_before_set_ideal = GCToOSInterface::GetCurrentProcessorNumber ();
if (current_proc_no_before_set_ideal != last_proc_no)
if ((uint16_t)current_proc_no_before_set_ideal != last_proc_no)
{
dprintf (HEAP_BALANCE_TEMP_LOG, ("TEMPSPa: %d->%d", last_proc_no, current_proc_no_before_set_ideal));
multiple_procs_p = true;
Expand Down Expand Up @@ -48782,13 +48732,13 @@ HRESULT GCHeap::Initialize()
for (int numa_node_index = 0; numa_node_index < total_numa_nodes_on_machine; numa_node_index++)
{
int hb_info_size_per_node = hb_info_size_per_proc * procs_per_numa_node;
uint8_t* numa_mem = (uint8_t*)GCToOSInterface::VirtualReserve (hb_info_size_per_node, 0, 0, numa_node_index);
uint8_t* numa_mem = (uint8_t*)GCToOSInterface::VirtualReserve (hb_info_size_per_node, 0, 0, (uint16_t)numa_node_index);
if (!numa_mem)
{
GCToEEInterface::LogErrorToHost("Reservation of numa_mem failed");
return E_FAIL;
}
if (!GCToOSInterface::VirtualCommit (numa_mem, hb_info_size_per_node, numa_node_index))
if (!GCToOSInterface::VirtualCommit (numa_mem, hb_info_size_per_node, (uint16_t)numa_node_index))
{
GCToEEInterface::LogErrorToHost("Commit of numa_mem failed");
return E_FAIL;
Expand Down

0 comments on commit d814174

Please sign in to comment.