diff --git a/configure.ac b/configure.ac index 6e32846fb8..7671dcca2a 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 b976caa0e8..9edbf089c2 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 +#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 670b21c5d0..82c0f047d4 100644 --- a/src/lib/eina/eina_cpu.c +++ b/src/lib/eina/eina_cpu.c @@ -46,13 +46,17 @@ #include #include #include +#include +#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 651d925653..e31ed76735 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);