summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohn Mainzer <mainzer@hdfgroup.org>2009-01-30 12:18:29 (GMT)
committerJohn Mainzer <mainzer@hdfgroup.org>2009-01-30 12:18:29 (GMT)
commit46c3b32c0142397a1a2d0862fb7267409cfd7b61 (patch)
tree0762e41819544aa275de00e44cb25d0b5c97d6fb /src
parentf30661caeb2b94c0ac7dc35d0786ed190b63b534 (diff)
downloadhdf5-46c3b32c0142397a1a2d0862fb7267409cfd7b61.zip
hdf5-46c3b32c0142397a1a2d0862fb7267409cfd7b61.tar.gz
hdf5-46c3b32c0142397a1a2d0862fb7267409cfd7b61.tar.bz2
[svn-r16383] A number of items, mostly related to the use of the core file driver in
metadata cache tests. 1) Fixed the core file driver failures previously observed on some platforms when running the cache2 tests with the core file driver enabled. This was done by allocating all needed memory on file open. 2) Added code to cache2.c to allow the use of the core file driver to be forced via the HDF5_DRIVER environment variable. 3) Added code to try to figure out whether using the core file driver in cache2 makes sense, and then use it or not as seems appropriate unless overridden via the HDF5_DRIVER environment variable. This code only works under Linux and BSD (including MacOS). For now at least, we use regular files in all other cases unless directed otherwise. Note that this required a fair bit of configuration code massage. 4) Updated Makefile.am in examples to run the new mdj_api_example.c example. Forgot to "svn add mdj_api_example.c" before this checkin, but will do so shortly. Tested on: Duty (serial), Liberty (serial), tejeda (serial), jam (serial and parallel), and Phoenix (serial and parallel). Note that Phoenix is now 64 bit AMD64 Linux.
Diffstat (limited to 'src')
-rw-r--r--src/H5config.h.in9
-rw-r--r--src/H5private.h6
-rw-r--r--src/H5system.c305
3 files changed, 320 insertions, 0 deletions
diff --git a/src/H5config.h.in b/src/H5config.h.in
index 429b613..9fa1a55 100644
--- a/src/H5config.h.in
+++ b/src/H5config.h.in
@@ -291,6 +291,12 @@
/* Define if `struct videoconfig' is defined */
#undef HAVE_STRUCT_VIDEOCONFIG
+/* Define to 1 if you have the `sysctl' function. */
+#undef HAVE_SYSCTL
+
+/* Define to 1 if you have the `sysinfo' function. */
+#undef HAVE_SYSINFO
+
/* Define to 1 if you have the `system' function. */
#undef HAVE_SYSTEM
@@ -312,6 +318,9 @@
/* Define to 1 if you have the <sys/stat.h> header file. */
#undef HAVE_SYS_STAT_H
+/* Define to 1 if you have the <sys/sysctl.h> header file. */
+#undef HAVE_SYS_SYSCTL_H
+
/* Define to 1 if you have the <sys/sysinfo.h> header file. */
#undef HAVE_SYS_SYSINFO_H
diff --git a/src/H5private.h b/src/H5private.h
index 53ef5c1..d5c412a 100644
--- a/src/H5private.h
+++ b/src/H5private.h
@@ -1980,5 +1980,11 @@ H5_DLL uint32_t H5_hash_string(const char *str);
H5_DLL herr_t H5_buffer_dump(FILE *stream, int indent, uint8_t *buf,
uint8_t *marker, size_t buf_offset, size_t buf_size);
+/* function to obtain data about the host system */
+/* Note that these function don't always work -- on failure they return 0 */
+H5_DLL unsigned long long H5_get_free_ram(void);
+H5_DLL unsigned long long H5_get_free_swap(void);
+H5_DLL unsigned long long H5_get_physical_ram(void);
+
#endif /* _H5private_H */
diff --git a/src/H5system.c b/src/H5system.c
index 6a8a91a..8b35e63 100644
--- a/src/H5system.c
+++ b/src/H5system.c
@@ -33,6 +33,18 @@
/* Headers */
/***********/
#include "H5private.h" /* Generic Functions */
+
+#ifdef H5_HAVE_SYS_TYPES_H
+#ifdef H5_HAVE_SYS_SYSCTL_H
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#endif /* H5_HAVE_SYS_SYSCTL_H */
+#endif /* H5_HAVE_SYS_TYPES_H */
+
+#ifdef H5_HAVE_SYS_SYSINFO_H
+#include <sys/sysinfo.h>
+#endif /* H5_HAVE_SYS_SYSINFO_H */
+
#include "H5Fprivate.h" /* File access */
#include "H5MMprivate.h" /* Memory management */
#include "H5Eprivate.h"
@@ -677,3 +689,296 @@ done:
H5MM_xfree(new_name);
FUNC_LEAVE_NOAPI(ret_value)
} /* H5_build_extpath() */
+
+
+/*
+ *-------------------------------------------------------------------------
+ *
+ * Function: H5_get_free_ram
+ *
+ * Purpose: Determine how much free ram the host system contains, and
+ * return that value in bytes. If this data is not available,
+ * return 0.
+ *
+ * Return: Number of bytes of free ram on the host system, or
+ * zero if unable to determine this value.
+ *
+ * Programmer: John Mainzer
+ * 1/22/09
+ *-------------------------------------------------------------------------
+ */
+
+unsigned long long
+H5_get_free_ram(void)
+{
+ const char * fcn_name = "H5_get_free_ram()";
+ hbool_t verbose = FALSE;
+ unsigned long long free_ram = 0;
+
+#ifdef H5_HAVE_SYS_SYSINFO_H /* LINUX */
+#ifdef H5_HAVE_SYSINFO /* LINUX */
+ {
+ struct sysinfo info;
+
+ if ( sysinfo(&info) != 0 ) {
+
+ if ( verbose ) {
+
+ HDfprintf(stdout, "%s: sysinfo() failed with errno = %d (%s)\n",
+ fcn_name, errno, strerror(errno));
+
+ }
+ } else {
+
+ if ( verbose ) {
+
+ HDfprintf(stdout, "%s: mem_unit = %u\n",
+ fcn_name, info.mem_unit);
+ HDfprintf(stdout, "%s: RAM: total = %lu, free = %lu\n",
+ fcn_name, info.totalram, info.freeram);
+ HDfprintf(stdout, "%s: RAM: shared = %lu, buffer = %lu\n",
+ fcn_name, info.sharedram, info.bufferram);
+ HDfprintf(stdout, "%s: SWAP: total = %lu, free = %lu\n",
+ fcn_name, info.totalswap, info.freeswap);
+ }
+
+ free_ram = ((unsigned long long)(info.freeram)) *
+ ((unsigned long long)(info.mem_unit));
+ }
+ }
+#endif /* H5_HAVE_SYSINFO -- LINUX */
+#endif /* H5_HAVE_SYS_SYSINFO_H -- LINUX */
+
+ if ( verbose ) {
+
+ HDfprintf(stdout, "%s: free ram = %lld.\n",
+ fcn_name, (long long)free_ram);
+ }
+
+ return(free_ram);
+
+} /* H5_get_free_ram() */
+
+
+/*
+ *-------------------------------------------------------------------------
+ *
+ * Function: H5_get_free_swap
+ *
+ * Purpose: Determine how much free swap the host system contains, and
+ * return that value in bytes. If this data is not available,
+ * return 0.
+ *
+ * Return: Number of bytes of free swap on the host system, or
+ * zero if unable to determine this value.
+ *
+ * Programmer: John Mainzer
+ * 1/22/09
+ *-------------------------------------------------------------------------
+ */
+
+unsigned long long
+H5_get_free_swap(void)
+{
+ const char * fcn_name = "H5_get_free_swap()";
+ hbool_t verbose = FALSE;
+ unsigned long long free_swap = 0;
+
+#ifdef H5_HAVE_SYS_SYSINFO_H /* LINUX */
+#ifdef H5_HAVE_SYSINFO /* LINUX */
+ {
+ struct sysinfo info;
+
+ if ( sysinfo(&info) != 0 ) {
+
+ if ( verbose ) {
+
+ HDfprintf(stdout, "%s: sysinfo() failed with errno = %d (%s)\n",
+ fcn_name, errno, strerror(errno));
+
+ }
+ } else {
+
+ if ( verbose ) {
+
+ HDfprintf(stdout, "%s: mem_unit = %u\n",
+ fcn_name, info.mem_unit);
+ HDfprintf(stdout, "%s: RAM: total = %lu, free = %lu\n",
+ fcn_name, info.totalram, info.freeram);
+ HDfprintf(stdout, "%s: RAM: shared = %lu, buffer = %lu\n",
+ fcn_name, info.sharedram, info.bufferram);
+ HDfprintf(stdout, "%s: SWAP: total = %lu, free = %lu\n",
+ fcn_name, info.totalswap, info.freeswap);
+ }
+
+ free_swap = ((unsigned long long)(info.freeswap)) *
+ ((unsigned long long)(info.mem_unit));
+ }
+ }
+#endif /* H5_HAVE_SYSINFO -- LINUX */
+#endif /* H5_HAVE_SYS_SYSINFO_H -- LINUX */
+
+ if ( verbose ) {
+
+ HDfprintf(stdout, "%s: free swap = %lld.\n",
+ fcn_name, (long long)free_swap);
+ }
+
+ return(free_swap);
+
+} /* H5_get_free_swap() */
+
+
+/*
+ *-------------------------------------------------------------------------
+ *
+ * Function: H5_get_physical_ram
+ *
+ * Purpose: Determine how much physical ram the host system contains, and
+ * return that value in bytes. If this data is not available,
+ * return 0.
+ *
+ * Return: Number of bytes of physical ram on the host system, or
+ * zero if unable to determine this value.
+ *
+ * Programmer: John Mainzer
+ * 1/22/09
+ *-------------------------------------------------------------------------
+ */
+
+unsigned long long
+H5_get_physical_ram(void)
+{
+ const char * fcn_name = "H5_get_physical_ram()";
+ hbool_t verbose = FALSE;
+ unsigned long long physical_ram = 0;
+
+#ifdef H5_HAVE_SYS_SYSINFO_H /* LINUX */
+#ifdef H5_HAVE_SYSINFO /* LINUX */
+ {
+ struct sysinfo info;
+
+ if ( sysinfo(&info) != 0 ) {
+
+ if ( verbose ) {
+
+ HDfprintf(stdout, "%s: sysinfo() failed with errno = %d (%s)\n",
+ fcn_name, errno, strerror(errno));
+
+ }
+ } else {
+
+ if ( verbose ) {
+
+ HDfprintf(stdout, "%s: mem_unit = %u\n",
+ fcn_name, info.mem_unit);
+ HDfprintf(stdout, "%s: RAM: total = %lu, free = %lu\n",
+ fcn_name, info.totalram, info.freeram);
+ HDfprintf(stdout, "%s: RAM: shared = %lu, buffer = %lu\n",
+ fcn_name, info.sharedram, info.bufferram);
+ HDfprintf(stdout, "%s: SWAP: total = %lu, free = %lu\n",
+ fcn_name, info.totalswap, info.freeswap);
+ }
+
+ physical_ram = ((unsigned long long)(info.totalram)) *
+ ((unsigned long long)(info.mem_unit));
+ }
+ }
+#endif /* H5_HAVE_SYSINFO -- LINUX */
+#endif /* H5_HAVE_SYS_SYSINFO_H -- LINUX */
+
+#ifdef H5_HAVE_SYS_TYPES_H /* BSD */
+#ifdef H5_HAVE_SYS_SYSCTL_H /* BSD */
+#ifdef H5_HAVE_SYSCTL /* BSD */
+ {
+ size_t len;
+ int pm_mib[2] = {CTL_HW, HW_PHYSMEM};
+ unsigned long l_physical_mem;
+ unsigned long long ll_physical_mem;
+
+ if ( sysctl(pm_mib, 2, NULL, &len, NULL, (size_t)0) == -1 ) {
+
+ if ( verbose ) {
+
+ HDfprintf(stdout, "%s: sysctl(1) failed with errno = %d (%s)\n",
+ fcn_name, errno, strerror(errno));
+ }
+
+ } else {
+
+ if ( verbose ) {
+
+ HDfprintf(stdout, "%s: len = %d.\n", fcn_name, (int)len);
+
+ }
+
+ if ( len == sizeof(l_physical_mem) ) {
+
+ if ( sysctl(pm_mib, 2, &l_physical_mem, &len, NULL, (size_t)0)
+ == -1 ) {
+
+ if ( verbose ) {
+
+ HDfprintf(stdout,
+ "%s: sysctl(2) failed with errno = %d (%s)\n",
+ fcn_name, errno, strerror(errno));
+
+ }
+ } else {
+
+ if ( verbose ) {
+
+ HDfprintf(stdout, "%s: l_physical memory = %ld\n",
+ fcn_name, l_physical_mem);
+ }
+
+ physical_ram = (unsigned long long)l_physical_mem;
+ }
+ } else if ( len == sizeof(ll_physical_mem) ) {
+
+ if ( sysctl(pm_mib, 2, &ll_physical_mem, &len, NULL, (size_t)0)
+ == -1 ) {
+
+ if ( verbose ) {
+
+ HDfprintf(stdout,
+ "%s: sysctl(3) failed with errno = %d (%s)\n",
+ fcn_name, errno, strerror(errno));
+
+ }
+ } else {
+
+ if ( verbose ) {
+
+ HDfprintf(stdout, "%s: ll_physical memory = %lld\n",
+ fcn_name, ll_physical_mem);
+ }
+
+ physical_ram = (unsigned long long)ll_physical_mem;
+ }
+
+ } else {
+
+ if ( verbose ) {
+
+ HDfprintf(stdout, "%s: unexpected len.\n", fcn_name);
+ }
+ }
+ }
+ }
+#endif /* H5_HAVE_SYSCTL -- BSD */
+#endif /* H5_HAVE_SYS_SYSCTL_H -- BSD */
+#endif /* H5_HAVE_SYS_TYPES_H -- BSD */
+
+ if ( verbose ) {
+
+ HDfprintf(stdout, "%s: physical ram = %lld.\n",
+ fcn_name, (long long)physical_ram);
+ }
+
+
+ return(physical_ram);
+
+} /* H5_get_physical_ram() */
+
+