Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increased platform support for PCU #412

Merged
merged 3 commits into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 0 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,6 @@ else()
endif()
scorec_export_library(core)

#check for mallinfo2
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
include(CheckCXXSymbolExists)
check_cxx_symbol_exists(mallinfo2 "malloc.h" PUMI_HAS_MALLINFO2)
if(PUMI_HAS_MALLINFO2)
target_compile_definitions(core INTERFACE -DPUMI_HAS_MALLINFO2)
target_compile_definitions(pcu PRIVATE -DPUMI_HAS_MALLINFO2)
endif()
endif()

if(BUILD_EXES)
add_subdirectory(test)
add_subdirectory(capstone_clis)
Expand Down
20 changes: 20 additions & 0 deletions pcu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,26 @@ add_library(pcu ${SOURCES})
# see: https://github.com/open-mpi/ompi/issues/5157
target_compile_definitions(pcu PUBLIC OMPI_SKIP_MPICXX)

if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR CMAKE_SYSTEM_NAME STREQUAL "NetBSD"
OR CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" OR CMAKE_SYSTEM_NAME STREQUAL "DragonFly")
target_link_libraries(pcu PRIVATE execinfo)
endif()

# Check for mallinfo, mallctl for PCU_GetMem().
include(CheckCXXSymbolExists)
check_cxx_symbol_exists(mallinfo "malloc.h" PUMI_HAS_MALLINFO)
check_cxx_symbol_exists(mallinfo2 "malloc.h" PUMI_HAS_MALLINFO2)
check_cxx_symbol_exists(mallctl "malloc_np.h" PUMI_HAS_MALLCTL)
if(PUMI_HAS_MALLINFO)
target_compile_definitions(pcu PRIVATE -DPUMI_HAS_MALLINFO)
endif()
if(PUMI_HAS_MALLINFO2)
target_compile_definitions(pcu PRIVATE -DPUMI_HAS_MALLINFO2)
endif()
if(PUMI_HAS_MALLCTL)
target_compile_definitions(pcu PRIVATE -DPUMI_HAS_MALLCTL)
endif()

# Include directories
target_include_directories(pcu
PUBLIC
Expand Down
10 changes: 9 additions & 1 deletion pcu/pcu_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
#pragma GCC diagnostic pop
#endif

#elif defined(PUMI_HAVE_MALLCTL)

#include <malloc_np.h>

#else

#include <malloc.h> //warning - this is GNU-specific
Expand All @@ -48,10 +52,14 @@ double PCU_GetMem() {
size_t heap;
Kernel_GetMemorySize(KERNEL_MEMSIZE_HEAP, &heap);
return (double)heap/M;
#elif defined(PUMI_HAS_MALLCTL)
size_t size = 0, sizelen = sizeof(size_t);
mallctl("stats.allocated", &size, &sizelen, NULL, 0);
return (double)size/M;
#elif defined(__GNUC__) && defined(PUMI_HAS_MALLINFO2)
struct mallinfo2 meminfo_now = mallinfo2();
return ((double)meminfo_now.arena)/M;
#elif defined(__GNUC__)
#elif defined(__GNUC__) && defined(PUMI_HAS_MALLINFO)
struct mallinfo meminfo_now = mallinfo();
return ((double)meminfo_now.arena)/M;
#endif
Expand Down
4 changes: 2 additions & 2 deletions pcu/reel/reel.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ void reel_fail(const char* format, ...)
abort();
}

#if defined(__linux__) || defined(__APPLE__)
#if defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
#include <execinfo.h> /* backtrace for pcu_trace */
#include <signal.h> /* signal for pcu_protect */

Expand Down Expand Up @@ -59,6 +59,6 @@ void reel_protect(void)
#else
void reel_protect(void)
{
reel_fail("reel_protect only supported on Linux and OS X");
reel_fail("reel_protect only supported on Linux, BSD, and OS X");
}
#endif
58 changes: 2 additions & 56 deletions test/describe.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,6 @@
#endif
#include <pcu_util.h>

#ifdef __bgq__
#include <spi/include/kernel/memory.h>

static double get_peak()
{
uint64_t heap;
Kernel_GetMemorySize(KERNEL_MEMSIZE_HEAP, &heap);
return heap;
}

#elif defined (__linux__)

static double get_peak()
{
#if defined(__GNUG__) && defined(PUMI_HAS_MALLINFO2)
return mallinfo2().arena;
#elif defined(__GNUG__)
return mallinfo().arena;
#endif
}

#else

static double get_peak()
{
if(!PCU_Comm_Self())
printf("%s:%d: OS Not supported\n", __FILE__, __LINE__);
return(-1.0);
}

#endif

static void print_stats(const char* name, double value)
{
double min, max, avg;
Expand All @@ -62,27 +30,6 @@ static void print_stats(const char* name, double value)
printf("%s: min %f max %f avg %f imb %f\n", name, min, max, avg, imb);
}

#if defined(__linux__)

static double get_chunks()
{
#if defined(__GNUG__) && defined(PUMI_HAS_MALLINFO2)
struct mallinfo2 m = mallinfo2();
#elif defined(__GNUG__)
struct mallinfo m = mallinfo();
#endif
return m.uordblks + m.hblkhd;
}

#else
static double get_chunks()
{
if(!PCU_Comm_Self())
printf("%s:%d: OS Not supported\n", __FILE__, __LINE__);
return(-1.0);
}
#endif

static void list_tags(apf::Mesh* m)
{
if (PCU_Comm_Self())
Expand All @@ -107,11 +54,10 @@ int main(int argc, char** argv)
gmi_register_sim();
#endif
gmi_register_mesh();
print_stats("malloc used before", get_chunks());
print_stats("kernel used before", PCU_GetMem());
apf::Mesh2* m = apf::loadMdsMesh(argv[1],argv[2]);
m->verify();
print_stats("kernel heap", get_peak());
print_stats("malloc used", get_chunks());
print_stats("kernel heap", PCU_GetMem());
Parma_PrintPtnStats(m, "");
list_tags(m);
m->destroyNative();
Expand Down
Loading