From c9f5e591b150f93a3a6b7d58fbb67a7c63db9d2f Mon Sep 17 00:00:00 2001 From: Brian Barrett Date: Fri, 12 Aug 2005 13:29:26 +0000 Subject: [PATCH] * make sure to try munmap when testing the hooks * add check to see impact of our hooks with malloc/free timings This commit was SVN r6817. --- test/memory/Makefile.am | 9 ++++- test/memory/opal_memory_basic.c | 4 +++ test/memory/opal_memory_speed.c | 59 +++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 test/memory/opal_memory_speed.c diff --git a/test/memory/Makefile.am b/test/memory/Makefile.am index 18960b378b..985063d0d8 100644 --- a/test/memory/Makefile.am +++ b/test/memory/Makefile.am @@ -17,7 +17,8 @@ include $(top_srcdir)/test/support/Makefile.options check_PROGRAMS = \ - opal_memory_basic + opal_memory_basic \ + opal_memory_speed TESTS = \ $(check_PROGRAMS) @@ -27,3 +28,9 @@ opal_memory_basic_LDADD = \ $(top_builddir)/opal/libopal.la \ $(top_builddir)/test/support/libsupport.a opal_memory_basic_DEPENDENCIES = $(opal_memory_basic_LDADD) + +opal_memory_speed_SOURCES = opal_memory_speed.c +opal_memory_speed_LDADD = \ + $(top_builddir)/opal/libopal.la \ + $(top_builddir)/test/support/libsupport.a +opal_memory_speed_DEPENDENCIES = $(opal_memory_speed_LDADD) diff --git a/test/memory/opal_memory_basic.c b/test/memory/opal_memory_basic.c index 318fa0ab8f..c7ff69d1cd 100644 --- a/test/memory/opal_memory_basic.c +++ b/test/memory/opal_memory_basic.c @@ -18,6 +18,7 @@ #include #include +#include #include "ompi/include/constants.h" #include "opal/runtime/opal.h" @@ -53,6 +54,9 @@ main(int argc, char *argv[]) foo = malloc(size); free(foo); + /* and check munmap directly */ + munmap(NULL, 0); + retval = opal_mem_free_unregister_handler(callback); if (retval != OMPI_SUCCESS) return retval; diff --git a/test/memory/opal_memory_speed.c b/test/memory/opal_memory_speed.c new file mode 100644 index 0000000000..bf3a3460e0 --- /dev/null +++ b/test/memory/opal_memory_speed.c @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2004-2005 The Trustees of Indiana University. + * All rights reserved. + * Copyright (c) 2004-2005 The Trustees of the University of Tennessee. + * All rights reserved. + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, + * University of Stuttgart. All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +#include "ompi_config.h" + +#include +#include +#include + +#include "ompi/include/constants.h" +#include "opal/runtime/opal.h" +#include "opal/memory/memory.h" + +#define iters 10000 + +static void* ptrs[iters]; + +int +main(int argc, char *argv[]) +{ + int i; + struct timeval start, end; + long time; + + gettimeofday(&start, NULL); + for (i = 0 ; i < iters ; ++i) { + /* malloc out a random size from 1 to 256 bytes */ + ptrs[i] = malloc((rand() & 0xff) + 1); + } + gettimeofday(&end, NULL); + time = ((end.tv_sec - start.tv_sec) * 1000 * 1000) + + (end.tv_usec - start.tv_usec); + printf("malloc: %d calls in %ld microseconds. %lf microseconds/call\n", + iters, time, (double) time / iters); + gettimeofday(&start, NULL); + for (i = 0 ; i < iters ; ++i) { + free(ptrs[i]); + } + gettimeofday(&end, NULL); + time = ((end.tv_sec - start.tv_sec) * 1000 * 1000) + + (end.tv_usec - start.tv_usec); + printf("free: %d calls in %ld microseconds. %lf microseconds/call\n", + iters, time, (double) time / iters); + + return 0; +}