Skip to content
Next Next commit
statically linking GC PAL
The GC PAL will be used for both coreclr and standalone GC on linux
  • Loading branch information
mangod9 committed Oct 13, 2022
commit 41710cbef4faae344e2523de598c1e38de9fa810
2 changes: 2 additions & 0 deletions src/coreclr/dlls/mscoree/coreclr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ set_property(TARGET coreclr APPEND_STRING PROPERTY LINK_DEPENDS ${EXPORTS_FILE})

if (CLR_CMAKE_HOST_UNIX)
set(LIB_UNWINDER unwinder_wks)
set(GC_PAL gc_unix)
endif (CLR_CMAKE_HOST_UNIX)

# IMPORTANT! Please do not rearrange the order of the libraries. The linker on Linux is
Expand All @@ -108,6 +109,7 @@ set(CORECLR_LIBRARIES
System.Globalization.Native-Static
interop
coreclrminipal
${GC_PAL}
)

if(CLR_CMAKE_TARGET_WIN32)
Expand Down
8 changes: 3 additions & 5 deletions src/coreclr/gc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,10 @@ set(GC_SOURCES
handletablecache.cpp)

if(CLR_CMAKE_HOST_UNIX)
add_subdirectory(unix)
include(unix/configure.cmake)
set (GC_SOURCES
${GC_SOURCES}
unix/gcenv.unix.cpp
unix/events.cpp
unix/cgroup.cpp)
${GC_SOURCES})
else()
set (GC_SOURCES
${GC_SOURCES}
Expand Down Expand Up @@ -101,7 +99,7 @@ if(CLR_CMAKE_HOST_WIN32)
kernel32.lib
advapi32.lib)
else()
set (GC_LINK_LIBRARIES)
set (GC_LINK_LIBRARIES gc_unix)
endif(CLR_CMAKE_HOST_WIN32)

list(APPEND GC_SOURCES ${GC_HEADERS})
Expand Down
15 changes: 8 additions & 7 deletions src/coreclr/gc/unix/cgroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ Module Name:

extern bool ReadMemoryValueFromFile(const char* filename, uint64_t* val);

class CGroup

class CGroup_GC
{
// the cgroup version number or 0 to indicate cgroups are not found or not enabled
static int s_cgroup_version;
Expand Down Expand Up @@ -454,24 +455,24 @@ class CGroup
}
};

int CGroup::s_cgroup_version = 0;
char *CGroup::s_memory_cgroup_path = nullptr;
int CGroup_GC::s_cgroup_version = 0;
char *CGroup_GC::s_memory_cgroup_path = nullptr;

void InitializeCGroup()
{
CGroup::Initialize();
CGroup_GC::Initialize();
}

void CleanupCGroup()
{
CGroup::Cleanup();
CGroup_GC::Cleanup();
}

size_t GetRestrictedPhysicalMemoryLimit()
{
uint64_t physical_memory_limit = 0;

if (!CGroup::GetPhysicalMemoryLimit(&physical_memory_limit))
if (!CGroup_GC::GetPhysicalMemoryLimit(&physical_memory_limit))
return 0;

// If there's no memory limit specified on the container this
Expand Down Expand Up @@ -526,7 +527,7 @@ bool GetPhysicalMemoryUsed(size_t* val)
return false;

// Linux uses cgroup usage to trigger oom kills.
if (CGroup::GetPhysicalMemoryUsage(val))
if (CGroup_GC::GetPhysicalMemoryUsage(val))
return true;

// process resident set size.
Expand Down
48 changes: 24 additions & 24 deletions src/coreclr/gc/unix/gcenv.unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,16 +152,16 @@ typedef cpuset_t cpu_set_t;
PER_FUNCTION_BLOCK(numa_node_of_cpu)

// Declare pointers to all the used numa functions
#define PER_FUNCTION_BLOCK(fn) extern decltype(fn)* fn##_ptr;
#define PER_FUNCTION_BLOCK(fn) extern decltype(fn)* fn##_ptr_gc;
FOR_ALL_NUMA_FUNCTIONS
#undef PER_FUNCTION_BLOCK

// Redefine all calls to numa functions as calls through pointers that are set
// to the functions of libnuma in the initialization.
#define mbind(...) mbind_ptr(__VA_ARGS__)
#define numa_available() numa_available_ptr()
#define numa_max_node() numa_max_node_ptr()
#define numa_node_of_cpu(...) numa_node_of_cpu_ptr(__VA_ARGS__)
#define mbind(...) mbind_ptr_gc(__VA_ARGS__)
#define numa_available() numa_available_ptr_gc()
#define numa_max_node() numa_max_node_ptr_gc()
#define numa_node_of_cpu(...) numa_node_of_cpu_ptr_gc(__VA_ARGS__)

#endif // HAVE_NUMA_H

Expand Down Expand Up @@ -234,14 +234,14 @@ uint32_t g_pageSizeUnixInl = 0;
AffinitySet g_processAffinitySet;

// The highest NUMA node available
int g_highestNumaNode = 0;
int g_highestNumaNode_gc = 0;
// Is numa available
bool g_numaAvailable = false;
bool g_numaAvailable_gc = false;

void* g_numaHandle = nullptr;

#if HAVE_NUMA_H
#define PER_FUNCTION_BLOCK(fn) decltype(fn)* fn##_ptr;
#define PER_FUNCTION_BLOCK(fn) decltype(fn)* fn##_ptr_gc;
FOR_ALL_NUMA_FUNCTIONS
#undef PER_FUNCTION_BLOCK

Expand Down Expand Up @@ -297,8 +297,8 @@ void NUMASupportInitialize()
#if HAVE_NUMA_H
if (!ShouldOpenLibNuma())
{
g_numaAvailable = false;
g_highestNumaNode = 0;
g_numaAvailable_gc = false;
g_highestNumaNode_gc = 0;
return;
}

Expand All @@ -314,8 +314,8 @@ void NUMASupportInitialize()
if (g_numaHandle != 0)
{
#define PER_FUNCTION_BLOCK(fn) \
fn##_ptr = (decltype(fn)*)dlsym(g_numaHandle, #fn); \
if (fn##_ptr == NULL) { fprintf(stderr, "Cannot get symbol " #fn " from libnuma\n"); abort(); }
fn##_ptr_gc = (decltype(fn)*)dlsym(g_numaHandle, #fn); \
if (fn##_ptr_gc == NULL) { fprintf(stderr, "Cannot get symbol " #fn " from libnuma\n"); abort(); }
FOR_ALL_NUMA_FUNCTIONS
#undef PER_FUNCTION_BLOCK

Expand All @@ -325,23 +325,23 @@ FOR_ALL_NUMA_FUNCTIONS
}
else
{
g_numaAvailable = true;
g_highestNumaNode = numa_max_node();
g_numaAvailable_gc = true;
g_highestNumaNode_gc = numa_max_node();
}
}
#endif // HAVE_NUMA_H
if (!g_numaAvailable)
if (!g_numaAvailable_gc)
{
// No NUMA
g_highestNumaNode = 0;
g_highestNumaNode_gc = 0;
}
}

// Cleanup of the NUMA support data structures
void NUMASupportCleanup()
{
#if HAVE_NUMA_H
if (g_numaAvailable)
if (g_numaAvailable_gc)
{
dlclose(g_numaHandle);
}
Expand Down Expand Up @@ -725,11 +725,11 @@ bool GCToOSInterface::VirtualCommit(void* address, size_t size, uint16_t node)
bool success = mprotect(address, size, PROT_WRITE | PROT_READ) == 0;

#if HAVE_NUMA_H
if (success && g_numaAvailable && (node != NUMA_NODE_UNDEFINED))
if (success && g_numaAvailable_gc && (node != NUMA_NODE_UNDEFINED))
{
if ((int)node <= g_highestNumaNode)
if ((int)node <= g_highestNumaNode_gc)
{
int usedNodeMaskBits = g_highestNumaNode + 1;
int usedNodeMaskBits = g_highestNumaNode_gc + 1;
int nodeMaskLength = (usedNodeMaskBits + sizeof(unsigned long) - 1) / sizeof(unsigned long);
unsigned long nodeMask[nodeMaskLength];
memset(nodeMask, 0, sizeof(nodeMask));
Expand Down Expand Up @@ -825,7 +825,7 @@ bool GCToOSInterface::GetWriteWatch(bool resetState, void* address, size_t size,
return false;
}

bool ReadMemoryValueFromFile(const char* filename, uint64_t* val)
bool _ReadMemoryValueFromFile(const char* filename, uint64_t* val)
{
bool result = false;
char* line = nullptr;
Expand Down Expand Up @@ -917,11 +917,11 @@ static size_t GetLogicalProcessorCacheSizeFromOS()
{
path_to_size_file[index] = (char)(48 + i);

if (ReadMemoryValueFromFile(path_to_size_file, &size))
if (_ReadMemoryValueFromFile(path_to_size_file, &size))
{
path_to_level_file[index] = (char)(48 + i);

if (ReadMemoryValueFromFile(path_to_level_file, &level))
if (_ReadMemoryValueFromFile(path_to_level_file, &level))
{
UPDATE_CACHE_SIZE_AND_LEVEL(size, level)
}
Expand Down Expand Up @@ -1494,7 +1494,7 @@ uint32_t GCToOSInterface::GetTotalProcessorCount()

bool GCToOSInterface::CanEnableGCNumaAware()
{
return g_numaAvailable;
return g_numaAvailable_gc;
}

bool GCToOSInterface::CanEnableGCCPUGroups()
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ set(VM_SOURCES_WKS
gccover.cpp
gcenv.ee.static.cpp
gcenv.ee.common.cpp
gcenv.os.cpp
gchelpers.cpp
genanalysis.cpp
genmeth.cpp
Expand Down Expand Up @@ -492,6 +491,7 @@ set(GC_SOURCES_WKS
if (CLR_CMAKE_TARGET_ARCH_AMD64 AND CLR_CMAKE_TARGET_WIN32)
set ( GC_SOURCES_WKS
${GC_SOURCES_WKS}
gcenv.os.cpp
../gc/vxsort/isa_detection.cpp
../gc/vxsort/do_vxsort_avx2.cpp
../gc/vxsort/do_vxsort_avx512.cpp
Expand Down