summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCedric BAIL <cedric@efl.so>2013-11-10 09:25:16 +0100
committerCedric BAIL <cedric@efl.so>2013-11-10 09:25:16 +0100
commitecaca1d365b998b3e339b387897c0646b2b3556f (patch)
tree83867cd16388a17448756507cf93ca9d4be54eac
parent35228f32f189f90975729ca2dd0f3755f0e3db03 (diff)
eina: detect page size in a portable way.
-rw-r--r--configure.ac2
-rw-r--r--m4/efl_check_funcs.m414
-rw-r--r--src/lib/eina/eina_cpu.c41
-rw-r--r--src/lib/eina/eina_cpu.h1
4 files changed, 57 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac
index 6e32846fb..7671dcca2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -825,7 +825,7 @@ EFL_CHECK_GCC_BUILTIN([bswap64], [HAVE_BSWAP64])
AC_CHECK_FUNCS([fchmod])
-EFL_CHECK_FUNCS([EINA], [dlopen dladdr iconv shm_open splice setxattr])
+EFL_CHECK_FUNCS([EINA], [dlopen dladdr iconv shm_open splice setxattr getpagesize])
enable_log="no"
if test "x${efl_func_fnmatch}" = "xyes" && test "x${want_log}" = "xyes" ; then
diff --git a/m4/efl_check_funcs.m4 b/m4/efl_check_funcs.m4
index b976caa0e..9edbf089c 100644
--- a/m4/efl_check_funcs.m4
+++ b/m4/efl_check_funcs.m4
@@ -235,6 +235,20 @@ long ret = splice(0, 0, 1, 0, 400, 0);
]])
])
+dnl _EFL_CHECK_FUNC_GETPAGESIZE is for internal use
+dnl _EFL_CHECK_FUNC_GETPAGESIZE(EFL, VARIABLE)
+AC_DEFUN([_EFL_CHECK_FUNC_GETPAGESIZE],
+[EFL_FIND_LIB_FOR_CODE([$1], [], [$2], [[
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+]],
+[[
+long sz;
+sz = getpagesize();
+]])
+])
+
dnl Macro that checks function availability
dnl
dnl EFL_CHECK_FUNC(EFL, FUNCTION)
diff --git a/src/lib/eina/eina_cpu.c b/src/lib/eina/eina_cpu.c
index 670b21c5d..82c0f047d 100644
--- a/src/lib/eina/eina_cpu.c
+++ b/src/lib/eina/eina_cpu.c
@@ -46,13 +46,17 @@
#include <stdio.h>
#include <string.h>
#include <errno.h>
+#include <unistd.h>
+#include "eina_log.h"
#include "eina_cpu.h"
/*============================================================================*
* Local *
*============================================================================*/
+static void _eina_page_size(void);
+
/* FIXME this ifdefs should be replaced */
#if defined(__i386__) || defined(__x86_64__)
/* We save ebx and restore it to be PIC compatible */
@@ -140,6 +144,9 @@ eina_cpu_init(void)
#endif
// FIXME: Handle NEON and friends
+ // Figure out the page size for this system
+ _eina_page_size();
+
return EINA_TRUE;
}
@@ -237,6 +244,40 @@ _eina_cpu_count_internal(void)
#endif
}
+static int _page_size = 0;
+
+static void
+_eina_page_size(void)
+{
+#ifdef _WIN32
+ SYSTEM_INFO si;
+
+ GetSystemInfo(&si);
+
+ _page_size = (int)si.dwPageSize;
+#elif defined _SC_PAGESIZE
+ _page_size = (int)sysconf(_SC_PAGESIZE);
+#elif defined _SC_PAGE_SIZE
+ _page_size = (int)sysconf(_SC_PAGE_SIZE);
+#elif defined HAVE_GETPAGESIZE
+ _page_size = getpagesize();
+#else
+# warn "Falling back to a safe default page size (4K) !"
+ _page_size = 4096;
+#endif
+ if (_page_size < 1)
+ {
+ EINA_LOG_ERR("system reported weird value for PAGESIZE, assuming 4096.");
+ _page_size = 4096;
+ }
+}
+
+EAPI int eina_cpu_page_size(void)
+{
+ if (_page_size == 0) _eina_page_size();
+ return _page_size;
+}
+
EAPI int eina_cpu_count(void)
{
return _cpu_count;
diff --git a/src/lib/eina/eina_cpu.h b/src/lib/eina/eina_cpu.h
index 651d92565..e31ed7673 100644
--- a/src/lib/eina/eina_cpu.h
+++ b/src/lib/eina/eina_cpu.h
@@ -40,6 +40,7 @@ EAPI extern Eina_Cpu_Features eina_cpu_features;
EAPI Eina_Cpu_Features eina_cpu_features_get(void);
EAPI int eina_cpu_count(void);
+EAPI int eina_cpu_page_size(void);
static inline unsigned short eina_swap16(unsigned short x);
static inline unsigned int eina_swap32(unsigned int x);