Commit 0f2abe84 authored by Tom Barbette's avatar Tom Barbette

Use aligned allocation if supported

parent d7908e80
......@@ -8,6 +8,12 @@
/* Define if accept() uses socklen_t. */
#undef HAVE_ACCEPT_SOCKLEN_T
/* Define if aligned_alloc is implemented */
#undef HAVE_ALIGNED_ALLOC
/* Define if the compiler supports aligned new (C++ 17) */
#undef HAVE_ALIGNED_NEW
/* Define if kqueue() may be used to wait for file descriptor events. */
#undef HAVE_ALLOW_KQUEUE
......
......@@ -1956,6 +1956,48 @@ fi
} # ac_fn_cxx_try_cpp
# ac_fn_cxx_try_run LINENO
# ------------------------
# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes
# that executables *can* be run.
ac_fn_cxx_try_run ()
{
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
if { { ac_try="$ac_link"
case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
(eval "$ac_link") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; } && { ac_try='./conftest$ac_exeext'
{ { case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
(eval "$ac_try") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; }; then :
ac_retval=0
else
$as_echo "$as_me: program exited with status $ac_status" >&5
$as_echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
ac_retval=$ac_status
fi
rm -rf conftest.dSYM conftest_ipa8_conftest.oo
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
as_fn_set_status $ac_retval
} # ac_fn_cxx_try_run
# ac_fn_cxx_check_header_mongrel LINENO HEADER VAR INCLUDES
# ---------------------------------------------------------
# Tests whether HEADER exists, giving a warning if it cannot be compiled using
......@@ -2202,48 +2244,6 @@ $as_echo "$ac_res" >&6; }
} # ac_fn_c_check_func
# ac_fn_cxx_try_run LINENO
# ------------------------
# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes
# that executables *can* be run.
ac_fn_cxx_try_run ()
{
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
if { { ac_try="$ac_link"
case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
(eval "$ac_link") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; } && { ac_try='./conftest$ac_exeext'
{ { case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
(eval "$ac_try") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; }; then :
ac_retval=0
else
$as_echo "$as_me: program exited with status $ac_status" >&5
$as_echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
ac_retval=$ac_status
fi
rm -rf conftest.dSYM conftest_ipa8_conftest.oo
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
as_fn_set_status $ac_retval
} # ac_fn_cxx_try_run
# ac_fn_cxx_compute_int LINENO EXPR VAR INCLUDES
# ----------------------------------------------
# Tries to find the compile-time value of EXPR in a program that includes
......@@ -5824,6 +5824,32 @@ ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ex
ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
if test "$cross_compiling" = yes; then :
{ { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5
$as_echo "$as_me: error: in \`$ac_pwd':" >&2;}
as_fn_error $? "cannot run test program while cross compiling
See \`config.log' for more details" "$LINENO" 5; }
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <new>
int main() {
std::size_t sz = 8;
std::align_val_t al{64};
void* a = operator new(sz,al);
return (a == nullptr?1:0);
}
_ACEOF
if ac_fn_cxx_try_run "$LINENO"; then :
$as_echo "#define HAVE_ALIGNED_NEW 1" >>confdefs.h
fi
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
conftest.$ac_objext conftest.beam conftest.$ac_ext
fi
test -z "$ac_user_kernel_cc" && \
......@@ -7679,7 +7705,7 @@ esac
fi
for ac_func in random snprintf strnlen strtof strtold strtoul tcgetpgrp vsnprintf
for ac_func in random snprintf strnlen strtof strtold strtoul tcgetpgrp vsnprintf aligned_alloc
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
......
......@@ -52,6 +52,15 @@ AC_C_INLINE
CLICK_PROG_CXX
AC_PROG_CXXCPP
AC_TRY_RUN([#include <new>
int main() {
std::size_t sz = 8;
std::align_val_t al{64};
void* a = operator new(sz,al);
return (a == nullptr?1:0);
}],AC_DEFINE([HAVE_ALIGNED_NEW]))
CLICK_PROG_KERNEL_CC
CLICK_PROG_KERNEL_CXX
......@@ -706,7 +715,7 @@ dnl
AC_LANG_C
AC_REPLACE_FUNCS(strerror)
AC_CHECK_FUNCS(random snprintf strnlen strtof strtold strtoul tcgetpgrp vsnprintf)
AC_CHECK_FUNCS(random snprintf strnlen strtof strtold strtoul tcgetpgrp vsnprintf aligned_alloc)
AC_LANG_CPLUSPLUS
......
......@@ -134,6 +134,21 @@ void click_lfree(volatile void *p, size_t size);
# define CLICK_LFREE(p, size) delete[] ((void) (size), (uint8_t *)(p))
#endif
#if HAVE_ALIGNED_NEW
# define CLICK_ALIGNED_NEW(T,size) (new T[_size])
# define CLICK_ALIGNED_DELETE(p,T,size) (delete[] p)
#else
# if HAVE_ALIGNED_ALLOC
# define CLICK_ALIGNED_ALLOC(T,size) ((T*)(aligned_alloc(64, sizeof(T) * size)))
# define CLICK_ALIGNED_FREE(p,T,size) (free(p))
# else
# warning Using normal allocation instead of aligned one, please use a compiler that supports aligned_alloc
# define CLICK_ALIGNED_ALLOC(T,size) CLICK_LALLOC(sizeof(T) * size)
# define CLICK_ALIGNED_FREE(p,T,size) CLICK_LFREE(p,sizeof(T) * size);
# endif
# define CLICK_ALIGNED_NEW(T,size) ({T* v = CLICK_ALIGNED_ALLOC(T,size);for (unsigned i = 0; i < size; i++) {new(&v[i]) T();};v;})
# define CLICK_ALIGNED_DELETE(p,T,size) {for (unsigned i = 0; i < size; i++) p[i].~T();CLICK_ALIGNED_FREE(p,T,size);}
#endif
// RANDOMNESS
......
......@@ -62,7 +62,7 @@ private:
void initialize(unsigned int n, T v) {
_size = n;
storage = new AT[_size];
storage = CLICK_ALIGNED_NEW(AT,_size);
for (unsigned i = 0; i < n; i++) {
storage[i].v = v;
}
......@@ -73,7 +73,7 @@ private:
public:
explicit per_thread() {
_size = click_max_cpu_ids();
storage = new AT[_size];
storage = CLICK_ALIGNED_NEW(AT,_size);
}
explicit per_thread(T v) {
......@@ -90,13 +90,13 @@ public:
* This will destroy all data
*/
void resize(unsigned int max_cpu_id, T v) {
delete[] storage;
CLICK_ALIGNED_DELETE(storage, AT, _size);
initialize(max_cpu_id,v);
}
~per_thread() {
if (_size) {
delete[] storage;
CLICK_ALIGNED_DELETE(storage,AT,_size);
_size = 0;
}
}
......@@ -137,8 +137,8 @@ public:
inline void operator=(const per_thread<T>& pt) {
if (_size != pt._size) {
if (storage)
delete[] storage;
storage = new AT[_size];
CLICK_ALIGNED_DELETE(storage,AT, _size);
storage = CLICK_ALIGNED_NEW(AT, _size);
}
for (int i = 0; i < pt.weight(); i++) {
storage[i] = pt.storage[i];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment