Skip to content

Commit 58d72ce

Browse files
authored
Merge pull request #412 from SCOREC/apw/pcu-bsd-support
Increased platform support for PCU
2 parents 604c067 + f6eadd2 commit 58d72ce

File tree

5 files changed

+33
-69
lines changed

5 files changed

+33
-69
lines changed

CMakeLists.txt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -190,16 +190,6 @@ else()
190190
endif()
191191
scorec_export_library(core)
192192

193-
#check for mallinfo2
194-
if(${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
195-
include(CheckCXXSymbolExists)
196-
check_cxx_symbol_exists(mallinfo2 "malloc.h" PUMI_HAS_MALLINFO2)
197-
if(PUMI_HAS_MALLINFO2)
198-
target_compile_definitions(core INTERFACE -DPUMI_HAS_MALLINFO2)
199-
target_compile_definitions(pcu PRIVATE -DPUMI_HAS_MALLINFO2)
200-
endif()
201-
endif()
202-
203193
if(BUILD_EXES)
204194
add_subdirectory(test)
205195
add_subdirectory(capstone_clis)

pcu/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,26 @@ add_library(pcu ${SOURCES})
3939
# see: https://github.com/open-mpi/ompi/issues/5157
4040
target_compile_definitions(pcu PUBLIC OMPI_SKIP_MPICXX)
4141

42+
if(CMAKE_SYSTEM_NAME STREQUAL "FreeBSD" OR CMAKE_SYSTEM_NAME STREQUAL "NetBSD"
43+
OR CMAKE_SYSTEM_NAME STREQUAL "OpenBSD" OR CMAKE_SYSTEM_NAME STREQUAL "DragonFly")
44+
target_link_libraries(pcu PRIVATE execinfo)
45+
endif()
46+
47+
# Check for mallinfo, mallctl for PCU_GetMem().
48+
include(CheckCXXSymbolExists)
49+
check_cxx_symbol_exists(mallinfo "malloc.h" PUMI_HAS_MALLINFO)
50+
check_cxx_symbol_exists(mallinfo2 "malloc.h" PUMI_HAS_MALLINFO2)
51+
check_cxx_symbol_exists(mallctl "malloc_np.h" PUMI_HAS_MALLCTL)
52+
if(PUMI_HAS_MALLINFO)
53+
target_compile_definitions(pcu PRIVATE -DPUMI_HAS_MALLINFO)
54+
endif()
55+
if(PUMI_HAS_MALLINFO2)
56+
target_compile_definitions(pcu PRIVATE -DPUMI_HAS_MALLINFO2)
57+
endif()
58+
if(PUMI_HAS_MALLCTL)
59+
target_compile_definitions(pcu PRIVATE -DPUMI_HAS_MALLCTL)
60+
endif()
61+
4262
# Include directories
4363
target_include_directories(pcu
4464
PUBLIC

pcu/pcu_mem.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
#pragma GCC diagnostic pop
3030
#endif
3131

32+
#elif defined(PUMI_HAVE_MALLCTL)
33+
34+
#include <malloc_np.h>
35+
3236
#else
3337

3438
#include <malloc.h> //warning - this is GNU-specific
@@ -48,10 +52,14 @@ double PCU_GetMem() {
4852
size_t heap;
4953
Kernel_GetMemorySize(KERNEL_MEMSIZE_HEAP, &heap);
5054
return (double)heap/M;
55+
#elif defined(PUMI_HAS_MALLCTL)
56+
size_t size = 0, sizelen = sizeof(size_t);
57+
mallctl("stats.allocated", &size, &sizelen, NULL, 0);
58+
return (double)size/M;
5159
#elif defined(__GNUC__) && defined(PUMI_HAS_MALLINFO2)
5260
struct mallinfo2 meminfo_now = mallinfo2();
5361
return ((double)meminfo_now.arena)/M;
54-
#elif defined(__GNUC__)
62+
#elif defined(__GNUC__) && defined(PUMI_HAS_MALLINFO)
5563
struct mallinfo meminfo_now = mallinfo();
5664
return ((double)meminfo_now.arena)/M;
5765
#endif

pcu/reel/reel.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void reel_fail(const char* format, ...)
2424
abort();
2525
}
2626

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

@@ -59,6 +59,6 @@ void reel_protect(void)
5959
#else
6060
void reel_protect(void)
6161
{
62-
reel_fail("reel_protect only supported on Linux and OS X");
62+
reel_fail("reel_protect only supported on Linux, BSD, and OS X");
6363
}
6464
#endif

test/describe.cc

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -18,38 +18,6 @@
1818
#endif
1919
#include <pcu_util.h>
2020

21-
#ifdef __bgq__
22-
#include <spi/include/kernel/memory.h>
23-
24-
static double get_peak()
25-
{
26-
uint64_t heap;
27-
Kernel_GetMemorySize(KERNEL_MEMSIZE_HEAP, &heap);
28-
return heap;
29-
}
30-
31-
#elif defined (__linux__)
32-
33-
static double get_peak()
34-
{
35-
#if defined(__GNUG__) && defined(PUMI_HAS_MALLINFO2)
36-
return mallinfo2().arena;
37-
#elif defined(__GNUG__)
38-
return mallinfo().arena;
39-
#endif
40-
}
41-
42-
#else
43-
44-
static double get_peak()
45-
{
46-
if(!PCU_Comm_Self())
47-
printf("%s:%d: OS Not supported\n", __FILE__, __LINE__);
48-
return(-1.0);
49-
}
50-
51-
#endif
52-
5321
static void print_stats(const char* name, double value)
5422
{
5523
double min, max, avg;
@@ -62,27 +30,6 @@ static void print_stats(const char* name, double value)
6230
printf("%s: min %f max %f avg %f imb %f\n", name, min, max, avg, imb);
6331
}
6432

65-
#if defined(__linux__)
66-
67-
static double get_chunks()
68-
{
69-
#if defined(__GNUG__) && defined(PUMI_HAS_MALLINFO2)
70-
struct mallinfo2 m = mallinfo2();
71-
#elif defined(__GNUG__)
72-
struct mallinfo m = mallinfo();
73-
#endif
74-
return m.uordblks + m.hblkhd;
75-
}
76-
77-
#else
78-
static double get_chunks()
79-
{
80-
if(!PCU_Comm_Self())
81-
printf("%s:%d: OS Not supported\n", __FILE__, __LINE__);
82-
return(-1.0);
83-
}
84-
#endif
85-
8633
static void list_tags(apf::Mesh* m)
8734
{
8835
if (PCU_Comm_Self())
@@ -107,11 +54,10 @@ int main(int argc, char** argv)
10754
gmi_register_sim();
10855
#endif
10956
gmi_register_mesh();
110-
print_stats("malloc used before", get_chunks());
57+
print_stats("kernel used before", PCU_GetMem());
11158
apf::Mesh2* m = apf::loadMdsMesh(argv[1],argv[2]);
11259
m->verify();
113-
print_stats("kernel heap", get_peak());
114-
print_stats("malloc used", get_chunks());
60+
print_stats("kernel heap", PCU_GetMem());
11561
Parma_PrintPtnStats(m, "");
11662
list_tags(m);
11763
m->destroyNative();

0 commit comments

Comments
 (0)