initial port to C (very incomplete)
This commit was SVN r8.
Этот коммит содержится в:
родитель
dd175ab70f
Коммит
e952ab1f88
@ -7,12 +7,13 @@ dnl This file is part of the LAM/MPI software package. For license
|
||||
dnl information, see the LICENSE file in the top level directory of the
|
||||
dnl LAM/MPI source distribution.
|
||||
dnl
|
||||
dnl $Id: acinclude.m4,v 1.1 2003/11/22 16:36:20 jsquyres Exp $
|
||||
dnl $Id: acinclude.m4,v 1.2 2003/12/22 16:29:11 twoodall Exp $
|
||||
dnl
|
||||
|
||||
#
|
||||
# CMPI-specific tests
|
||||
#
|
||||
|
||||
sinclude(config/cmpi_functions.m4)
|
||||
sinclude(config/cmpi_get_version.m4)
|
||||
sinclude(config/lam_functions.m4)
|
||||
sinclude(config/lam_get_version.m4)
|
||||
sinclude(config/ax_create_stdint_h.m4)
|
||||
|
569
config/ax_create_stdint_h.m4
Обычный файл
569
config/ax_create_stdint_h.m4
Обычный файл
@ -0,0 +1,569 @@
|
||||
dnl @synopsis AX_CREATE_STDINT_H [( HEADER-TO-GENERATE [, HEDERS-TO-CHECK])]
|
||||
dnl
|
||||
dnl the "ISO C9X: 7.18 Integer types <stdint.h>" section requires the
|
||||
dnl existence of an include file <stdint.h> that defines a set of
|
||||
dnl typedefs, especially uint8_t,int32_t,uintptr_t.
|
||||
dnl Many older installations will not provide this file, but some will
|
||||
dnl have the very same definitions in <inttypes.h>. In other enviroments
|
||||
dnl we can use the inet-types in <sys/types.h> which would define the
|
||||
dnl typedefs int8_t and u_int8_t respectivly.
|
||||
dnl
|
||||
dnl This macros will create a local "_stdint.h" or the headerfile given as
|
||||
dnl an argument. In many cases that file will just "#include <stdint.h>"
|
||||
dnl or "#include <inttypes.h>", while in other environments it will provide
|
||||
dnl the set of basic 'stdint's definitions/typedefs:
|
||||
dnl int8_t,uint8_t,int16_t,uint16_t,int32_t,uint32_t,intptr_t,uintptr_t
|
||||
dnl int_least32_t.. int_fast32_t.. intmax_t
|
||||
dnl which may or may not rely on the definitions of other files,
|
||||
dnl or using the AC_CHECK_SIZEOF macro to determine the actual
|
||||
dnl sizeof each type.
|
||||
dnl
|
||||
dnl if your header files require the stdint-types you will want to create an
|
||||
dnl installable file mylib-int.h that all your other installable header
|
||||
dnl may include. So if you have a library package named "mylib", just use
|
||||
dnl AX_CREATE_STDINT_H(mylib-int.h)
|
||||
dnl in configure.ac and go to install that very header file in Makefile.am
|
||||
dnl along with the other headers (mylib.h) - and the mylib-specific headers
|
||||
dnl can simply use "#include <mylib-int.h>" to obtain the stdint-types.
|
||||
dnl
|
||||
dnl Remember, if the system already had a valid <stdint.h>, the generated
|
||||
dnl file will include it directly. No need for fuzzy HAVE_STDINT_H things...
|
||||
dnl
|
||||
dnl @, (status: used on new platforms) (see http://ac-archive.sf.net/gstdint/)
|
||||
dnl @version $Id: ax_create_stdint_h.m4,v 1.1 2003/12/22 16:29:11 twoodall Exp $
|
||||
dnl @author Guido Draheim <guidod@gmx.de>
|
||||
|
||||
AC_DEFUN([AX_CREATE_STDINT_H],
|
||||
[# ------ AX CREATE STDINT H -------------------------------------
|
||||
AC_MSG_CHECKING([for stdint types])
|
||||
ac_stdint_h=`echo ifelse($1, , _stdint.h, $1)`
|
||||
# try to shortcircuit - if the default include path of the compiler
|
||||
# can find a "stdint.h" header then we assume that all compilers can.
|
||||
AC_CACHE_VAL([ac_cv_header_stdint_t],[
|
||||
old_CXXFLAGS="$CXXFLAGS" ; CXXFLAGS=""
|
||||
old_CPPFLAGS="$CPPFLAGS" ; CPPFLAGS=""
|
||||
old_CFLAGS="$CFLAGS" ; CFLAGS=""
|
||||
AC_TRY_COMPILE([#include <stdint.h>],[int_least32_t v = 0;],
|
||||
[ac_cv_stdint_result="(assuming C99 compatible system)"
|
||||
ac_cv_header_stdint_t="stdint.h"; ],
|
||||
[ac_cv_header_stdint_t=""])
|
||||
CXXFLAGS="$old_CXXFLAGS"
|
||||
CPPFLAGS="$old_CPPFLAGS"
|
||||
CFLAGS="$old_CFLAGS" ])
|
||||
|
||||
v="... $ac_cv_header_stdint_h"
|
||||
if test "$ac_stdint_h" = "stdint.h" ; then
|
||||
AC_MSG_RESULT([(are you sure you want them in ./stdint.h?)])
|
||||
elif test "$ac_stdint_h" = "inttypes.h" ; then
|
||||
AC_MSG_RESULT([(are you sure you want them in ./inttypes.h?)])
|
||||
elif test "_$ac_cv_header_stdint_t" = "_" ; then
|
||||
AC_MSG_RESULT([(putting them into $ac_stdint_h)$v])
|
||||
else
|
||||
ac_cv_header_stdint="$ac_cv_header_stdint_t"
|
||||
AC_MSG_RESULT([$ac_cv_header_stdint (shortcircuit)])
|
||||
fi
|
||||
|
||||
if test "_$ac_cv_header_stdint_t" = "_" ; then # can not shortcircuit..
|
||||
|
||||
dnl .....intro message done, now do a few system checks.....
|
||||
dnl btw, all CHECK_TYPE macros do automatically "DEFINE" a type, therefore
|
||||
dnl we use the autoconf implementation detail _AC CHECK_TYPE_NEW instead
|
||||
|
||||
inttype_headers=`echo $2 | sed -e 's/,/ /g'`
|
||||
|
||||
ac_cv_stdint_result="(no helpful system typedefs seen)"
|
||||
AC_CACHE_CHECK([for stdint uintptr_t], [ac_cv_header_stdint_x],[
|
||||
ac_cv_header_stdint_x="" # the 1997 typedefs (inttypes.h)
|
||||
AC_MSG_RESULT([(..)])
|
||||
for i in stdint.h inttypes.h sys/inttypes.h $inttype_headers ; do
|
||||
unset ac_cv_type_uintptr_t
|
||||
unset ac_cv_type_uint64_t
|
||||
_AC_CHECK_TYPE_NEW(uintptr_t,[ac_cv_header_stdint_x=$i],dnl
|
||||
continue,[#include <$i>])
|
||||
AC_CHECK_TYPE(uint64_t,[and64="/uint64_t"],[and64=""],[#include<$i>])
|
||||
ac_cv_stdint_result="(seen uintptr_t$and64 in $i)"
|
||||
break;
|
||||
done
|
||||
AC_MSG_CHECKING([for stdint uintptr_t])
|
||||
])
|
||||
|
||||
if test "_$ac_cv_header_stdint_x" = "_" ; then
|
||||
AC_CACHE_CHECK([for stdint uint32_t], [ac_cv_header_stdint_o],[
|
||||
ac_cv_header_stdint_o="" # the 1995 typedefs (sys/inttypes.h)
|
||||
AC_MSG_RESULT([(..)])
|
||||
for i in inttypes.h sys/inttypes.h stdint.h $inttype_headers ; do
|
||||
unset ac_cv_type_uint32_t
|
||||
unset ac_cv_type_uint64_t
|
||||
AC_CHECK_TYPE(uint32_t,[ac_cv_header_stdint_o=$i],dnl
|
||||
continue,[#include <$i>])
|
||||
AC_CHECK_TYPE(uint64_t,[and64="/uint64_t"],[and64=""],[#include<$i>])
|
||||
ac_cv_stdint_result="(seen uint32_t$and64 in $i)"
|
||||
break;
|
||||
done
|
||||
AC_MSG_CHECKING([for stdint uint32_t])
|
||||
])
|
||||
fi
|
||||
|
||||
if test "_$ac_cv_header_stdint_x" = "_" ; then
|
||||
if test "_$ac_cv_header_stdint_o" = "_" ; then
|
||||
AC_CACHE_CHECK([for stdint u_int32_t], [ac_cv_header_stdint_u],[
|
||||
ac_cv_header_stdint_u="" # the BSD typedefs (sys/types.h)
|
||||
AC_MSG_RESULT([(..)])
|
||||
for i in sys/types.h inttypes.h sys/inttypes.h $inttype_headers ; do
|
||||
unset ac_cv_type_u_int32_t
|
||||
unset ac_cv_type_u_int64_t
|
||||
AC_CHECK_TYPE(u_int32_t,[ac_cv_header_stdint_u=$i],dnl
|
||||
continue,[#include <$i>])
|
||||
AC_CHECK_TYPE(u_int64_t,[and64="/u_int64_t"],[and64=""],[#include<$i>])
|
||||
ac_cv_stdint_result="(seen u_int32_t$and64 in $i)"
|
||||
break;
|
||||
done
|
||||
AC_MSG_CHECKING([for stdint u_int32_t])
|
||||
])
|
||||
fi fi
|
||||
|
||||
dnl if there was no good C99 header file, do some typedef checks...
|
||||
if test "_$ac_cv_header_stdint_x" = "_" ; then
|
||||
AC_MSG_CHECKING([for stdint datatype model])
|
||||
AC_MSG_RESULT([(..)])
|
||||
AC_CHECK_SIZEOF(char)
|
||||
AC_CHECK_SIZEOF(short)
|
||||
AC_CHECK_SIZEOF(int)
|
||||
AC_CHECK_SIZEOF(long)
|
||||
AC_CHECK_SIZEOF(void*)
|
||||
ac_cv_stdint_char_model=""
|
||||
ac_cv_stdint_char_model="$ac_cv_stdint_char_model$ac_cv_sizeof_char"
|
||||
ac_cv_stdint_char_model="$ac_cv_stdint_char_model$ac_cv_sizeof_short"
|
||||
ac_cv_stdint_char_model="$ac_cv_stdint_char_model$ac_cv_sizeof_int"
|
||||
ac_cv_stdint_long_model=""
|
||||
ac_cv_stdint_long_model="$ac_cv_stdint_long_model$ac_cv_sizeof_int"
|
||||
ac_cv_stdint_long_model="$ac_cv_stdint_long_model$ac_cv_sizeof_long"
|
||||
ac_cv_stdint_long_model="$ac_cv_stdint_long_model$ac_cv_sizeof_voidp"
|
||||
name="$ac_cv_stdint_long_model"
|
||||
case "$ac_cv_stdint_char_model/$ac_cv_stdint_long_model" in
|
||||
122/242) name="$name, IP16 (standard 16bit machine)" ;;
|
||||
122/244) name="$name, LP32 (standard 32bit mac/win)" ;;
|
||||
122/*) name="$name (unusual int16 model)" ;;
|
||||
124/444) name="$name, ILP32 (standard 32bit unixish)" ;;
|
||||
124/488) name="$name, LP64 (standard 64bit unixish)" ;;
|
||||
124/448) name="$name, LLP64 (unusual 64bit unixish)" ;;
|
||||
124/*) name="$name (unusual int32 model)" ;;
|
||||
128/888) name="$name, ILP64 (unusual 64bit numeric)" ;;
|
||||
128/*) name="$name (unusual int64 model)" ;;
|
||||
222/*|444/*) name="$name (unusual dsptype)" ;;
|
||||
*) name="$name (very unusal model)" ;;
|
||||
esac
|
||||
AC_MSG_RESULT([combined for stdint datatype model... $name])
|
||||
fi
|
||||
|
||||
if test "_$ac_cv_header_stdint_x" != "_" ; then
|
||||
ac_cv_header_stdint="$ac_cv_header_stdint_x"
|
||||
elif test "_$ac_cv_header_stdint_o" != "_" ; then
|
||||
ac_cv_header_stdint="$ac_cv_header_stdint_o"
|
||||
elif test "_$ac_cv_header_stdint_u" != "_" ; then
|
||||
ac_cv_header_stdint="$ac_cv_header_stdint_u"
|
||||
else
|
||||
ac_cv_header_stdint="stddef.h"
|
||||
fi
|
||||
|
||||
AC_MSG_CHECKING([for extra inttypes in chosen header])
|
||||
AC_MSG_RESULT([($ac_cv_header_stdint)])
|
||||
dnl see if int_least and int_fast types are present in _this_ header.
|
||||
unset ac_cv_type_int_least32_t
|
||||
unset ac_cv_type_int_fast32_t
|
||||
AC_CHECK_TYPE(int_least32_t,,,[#include <$ac_cv_header_stdint>])
|
||||
AC_CHECK_TYPE(int_fast32_t,,,[#include<$ac_cv_header_stdint>])
|
||||
AC_CHECK_TYPE(intmax_t,,,[#include <$ac_cv_header_stdint>])
|
||||
|
||||
fi # shortcircut to system "stdint.h"
|
||||
# ------------------ PREPARE VARIABLES ------------------------------
|
||||
if test "$GCC" = "yes" ; then
|
||||
ac_cv_stdint_message="using gnu compiler "`$CC --version | head -1`
|
||||
else
|
||||
ac_cv_stdint_message="using $CC"
|
||||
fi
|
||||
|
||||
AC_MSG_RESULT([make use of $ac_cv_header_stdint in $ac_stdint_h dnl
|
||||
$ac_cv_stdint_result])
|
||||
|
||||
# ----------------- DONE inttypes.h checks START header -------------
|
||||
AC_CONFIG_COMMANDS([$ac_stdint_h],[
|
||||
AC_MSG_NOTICE(creating $ac_stdint_h : $_ac_stdint_h)
|
||||
ac_stdint=$tmp/_stdint.h
|
||||
|
||||
echo "#ifndef" $_ac_stdint_h >$ac_stdint
|
||||
echo "#define" $_ac_stdint_h "1" >>$ac_stdint
|
||||
echo "#ifndef" _GENERATED_STDINT_H >>$ac_stdint
|
||||
echo "#define" _GENERATED_STDINT_H '"'$PACKAGE $VERSION'"' >>$ac_stdint
|
||||
echo "/* generated $ac_cv_stdint_message */" >>$ac_stdint
|
||||
if test "_$ac_cv_header_stdint_t" != "_" ; then
|
||||
echo "#define _STDINT_HAVE_STDINT_H" "1" >>$ac_stdint
|
||||
fi
|
||||
|
||||
cat >>$ac_stdint <<STDINT_EOF
|
||||
|
||||
/* ................... shortcircuit part ........................... */
|
||||
|
||||
#if defined HAVE_STDINT_H || defined _STDINT_HAVE_STDINT_H
|
||||
#include <stdint.h>
|
||||
#else
|
||||
#include <stddef.h>
|
||||
|
||||
/* .................... configured part ............................ */
|
||||
|
||||
STDINT_EOF
|
||||
|
||||
echo "/* whether we have a C99 compatible stdint header file */" >>$ac_stdint
|
||||
if test "_$ac_cv_header_stdint_x" != "_" ; then
|
||||
ac_header="$ac_cv_header_stdint_x"
|
||||
echo "#define _STDINT_HEADER_INTPTR" '"'"$ac_header"'"' >>$ac_stdint
|
||||
else
|
||||
echo "/* #undef _STDINT_HEADER_INTPTR */" >>$ac_stdint
|
||||
fi
|
||||
|
||||
echo "/* whether we have a C96 compatible inttypes header file */" >>$ac_stdint
|
||||
if test "_$ac_cv_header_stdint_o" != "_" ; then
|
||||
ac_header="$ac_cv_header_stdint_o"
|
||||
echo "#define _STDINT_HEADER_UINT32" '"'"$ac_header"'"' >>$ac_stdint
|
||||
else
|
||||
echo "/* #undef _STDINT_HEADER_UINT32 */" >>$ac_stdint
|
||||
fi
|
||||
|
||||
echo "/* whether we have a BSD compatible inet types header */" >>$ac_stdint
|
||||
if test "_$ac_cv_header_stdint_u" != "_" ; then
|
||||
ac_header="$ac_cv_header_stdint_u"
|
||||
echo "#define _STDINT_HEADER_U_INT32" '"'"$ac_header"'"' >>$ac_stdint
|
||||
else
|
||||
echo "/* #undef _STDINT_HEADER_U_INT32 */" >>$ac_stdint
|
||||
fi
|
||||
|
||||
echo "" >>$ac_stdint
|
||||
|
||||
if test "_$ac_header" != "_" ; then if test "$ac_header" != "stddef.h" ; then
|
||||
echo "#include <$ac_header>" >>$ac_stdint
|
||||
echo "" >>$ac_stdint
|
||||
fi fi
|
||||
|
||||
echo "/* which 64bit typedef has been found */" >>$ac_stdint
|
||||
if test "$ac_cv_type_uint64_t" = "yes" ; then
|
||||
echo "#define _STDINT_HAVE_UINT64_T" "1" >>$ac_stdint
|
||||
else
|
||||
echo "/* #undef _STDINT_HAVE_UINT64_T */" >>$ac_stdint
|
||||
fi
|
||||
if test "$ac_cv_type_u_int64_t" = "yes" ; then
|
||||
echo "#define _STDINT_HAVE_U_INT64_T" "1" >>$ac_stdint
|
||||
else
|
||||
echo "/* #undef _STDINT_HAVE_U_INT64_T */" >>$ac_stdint
|
||||
fi
|
||||
echo "" >>$ac_stdint
|
||||
|
||||
echo "/* which type model has been detected */" >>$ac_stdint
|
||||
if test "_$ac_cv_stdint_char_model" != "_" ; then
|
||||
echo "#define _STDINT_CHAR_MODEL" "$ac_cv_stdint_char_model" >>$ac_stdint
|
||||
echo "#define _STDINT_LONG_MODEL" "$ac_cv_stdint_long_model" >>$ac_stdint
|
||||
else
|
||||
echo "/* #undef _STDINT_CHAR_MODEL // skipped */" >>$ac_stdint
|
||||
echo "/* #undef _STDINT_LONG_MODEL // skipped */" >>$ac_stdint
|
||||
fi
|
||||
echo "" >>$ac_stdint
|
||||
|
||||
echo "/* whether int_least types were detected */" >>$ac_stdint
|
||||
if test "$ac_cv_type_int_least32_t" = "yes"; then
|
||||
echo "#define _STDINT_HAVE_INT_LEAST32_T" "1" >>$ac_stdint
|
||||
else
|
||||
echo "/* #undef _STDINT_HAVE_INT_LEAST32_T */" >>$ac_stdint
|
||||
fi
|
||||
echo "/* whether int_fast types were detected */" >>$ac_stdint
|
||||
if test "$ac_cv_type_int_fast32_t" = "yes"; then
|
||||
echo "#define _STDINT_HAVE_INT_FAST32_T" "1" >>$ac_stdint
|
||||
else
|
||||
echo "/* #undef _STDINT_HAVE_INT_FAST32_T */" >>$ac_stdint
|
||||
fi
|
||||
echo "/* whether intmax_t type was detected */" >>$ac_stdint
|
||||
if test "$ac_cv_type_intmax_t" = "yes"; then
|
||||
echo "#define _STDINT_HAVE_INTMAX_T" "1" >>$ac_stdint
|
||||
else
|
||||
echo "/* #undef _STDINT_HAVE_INTMAX_T */" >>$ac_stdint
|
||||
fi
|
||||
echo "" >>$ac_stdint
|
||||
|
||||
cat >>$ac_stdint <<STDINT_EOF
|
||||
/* .................... detections part ............................ */
|
||||
|
||||
/* whether we need to define bitspecific types from compiler base types */
|
||||
#ifndef _STDINT_HEADER_INTPTR
|
||||
#ifndef _STDINT_HEADER_UINT32
|
||||
#ifndef _STDINT_HEADER_U_INT32
|
||||
#define _STDINT_NEED_INT_MODEL_T
|
||||
#else
|
||||
#define _STDINT_HAVE_U_INT_TYPES
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _STDINT_HAVE_U_INT_TYPES
|
||||
#undef _STDINT_NEED_INT_MODEL_T
|
||||
#endif
|
||||
|
||||
#ifdef _STDINT_CHAR_MODEL
|
||||
#if _STDINT_CHAR_MODEL+0 == 122 || _STDINT_CHAR_MODEL+0 == 124
|
||||
#ifndef _STDINT_BYTE_MODEL
|
||||
#define _STDINT_BYTE_MODEL 12
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef _STDINT_HAVE_INT_LEAST32_T
|
||||
#define _STDINT_NEED_INT_LEAST_T
|
||||
#endif
|
||||
|
||||
#ifndef _STDINT_HAVE_INT_FAST32_T
|
||||
#define _STDINT_NEED_INT_FAST_T
|
||||
#endif
|
||||
|
||||
#ifndef _STDINT_HEADER_INTPTR
|
||||
#define _STDINT_NEED_INTPTR_T
|
||||
#ifndef _STDINT_HAVE_INTMAX_T
|
||||
#define _STDINT_NEED_INTMAX_T
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
/* .................... definition part ............................ */
|
||||
|
||||
/* some system headers have good uint64_t */
|
||||
#ifndef _HAVE_UINT64_T
|
||||
#if defined _STDINT_HAVE_UINT64_T || defined HAVE_UINT64_T
|
||||
#define _HAVE_UINT64_T
|
||||
#elif defined _STDINT_HAVE_U_INT64_T || defined HAVE_U_INT64_T
|
||||
#define _HAVE_UINT64_T
|
||||
typedef u_int64_t uint64_t;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef _HAVE_UINT64_T
|
||||
/* .. here are some common heuristics using compiler runtime specifics */
|
||||
#if defined __STDC_VERSION__ && defined __STDC_VERSION__ >= 199901L
|
||||
#define _HAVE_UINT64_T
|
||||
typedef long long int64_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
|
||||
#elif !defined __STRICT_ANSI__
|
||||
#if defined _MSC_VER || defined __WATCOMC__ || defined __BORLANDC__
|
||||
#define _HAVE_UINT64_T
|
||||
typedef __int64 int64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
|
||||
#elif defined __GNUC__ || defined __MWERKS__ || defined __ELF__
|
||||
/* note: all ELF-systems seem to have loff-support which needs 64-bit */
|
||||
#if !defined _NO_LONGLONG
|
||||
#define _HAVE_UINT64_T
|
||||
typedef long long int64_t;
|
||||
typedef unsigned long long uint64_t;
|
||||
#endif
|
||||
|
||||
#elif defined __alpha || (defined __mips && defined _ABIN32)
|
||||
#if !defined _NO_LONGLONG
|
||||
typedef long int64_t;
|
||||
typedef unsigned long uint64_t;
|
||||
#endif
|
||||
/* compiler/cpu type to define int64_t */
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined _STDINT_HAVE_U_INT_TYPES
|
||||
/* int8_t int16_t int32_t defined by inet code, redeclare the u_intXX types */
|
||||
typedef u_int8_t uint8_t;
|
||||
typedef u_int16_t uint16_t;
|
||||
typedef u_int32_t uint32_t;
|
||||
|
||||
/* glibc compatibility */
|
||||
#ifndef __int8_t_defined
|
||||
#define __int8_t_defined
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _STDINT_NEED_INT_MODEL_T
|
||||
/* we must guess all the basic types. Apart from byte-adressable system, */
|
||||
/* there a few 32-bit-only dsp-systems that we guard with BYTE_MODEL 8-} */
|
||||
/* (btw, those nibble-addressable systems are way off, or so we assume) */
|
||||
|
||||
dnl /* have a look at "64bit and data size neutrality" at */
|
||||
dnl /* http://unix.org/version2/whatsnew/login_64bit.html */
|
||||
dnl /* (the shorthand "ILP" types always have a "P" part) */
|
||||
|
||||
#if defined _STDINT_BYTE_MODEL
|
||||
#if _STDINT_LONG_MODEL+0 == 242
|
||||
/* 2:4:2 = IP16 = a normal 16-bit system */
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned long uint32_t;
|
||||
#ifndef __int8_t_defined
|
||||
#define __int8_t_defined
|
||||
typedef char int8_t;
|
||||
typedef short int16_t;
|
||||
typedef long int32_t;
|
||||
#endif
|
||||
#elif _STDINT_LONG_MODEL+0 == 244 || _STDINT_LONG_MODEL == 444
|
||||
/* 2:4:4 = LP32 = a 32-bit system derived from a 16-bit */
|
||||
/* 4:4:4 = ILP32 = a normal 32-bit system */
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned int uint32_t;
|
||||
#ifndef __int8_t_defined
|
||||
#define __int8_t_defined
|
||||
typedef char int8_t;
|
||||
typedef short int16_t;
|
||||
typedef int int32_t;
|
||||
#endif
|
||||
#elif _STDINT_LONG_MODEL+0 == 484 || _STDINT_LONG_MODEL+0 == 488
|
||||
/* 4:8:4 = IP32 = a 32-bit system prepared for 64-bit */
|
||||
/* 4:8:8 = LP64 = a normal 64-bit system */
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned int uint32_t;
|
||||
#ifndef __int8_t_defined
|
||||
#define __int8_t_defined
|
||||
typedef char int8_t;
|
||||
typedef short int16_t;
|
||||
typedef int int32_t;
|
||||
#endif
|
||||
/* this system has a "long" of 64bit */
|
||||
#ifndef _HAVE_UINT64_T
|
||||
#define _HAVE_UINT64_T
|
||||
typedef unsigned long uint64_t;
|
||||
typedef long int64_t;
|
||||
#endif
|
||||
#elif _STDINT_LONG_MODEL+0 == 448
|
||||
/* LLP64 a 64-bit system derived from a 32-bit system */
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned int uint32_t;
|
||||
#ifndef __int8_t_defined
|
||||
#define __int8_t_defined
|
||||
typedef char int8_t;
|
||||
typedef short int16_t;
|
||||
typedef int int32_t;
|
||||
#endif
|
||||
/* assuming the system has a "long long" */
|
||||
#ifndef _HAVE_UINT64_T
|
||||
#define _HAVE_UINT64_T
|
||||
typedef unsigned long long uint64_t;
|
||||
typedef long long int64_t;
|
||||
#endif
|
||||
#else
|
||||
#define _STDINT_NO_INT32_T
|
||||
#endif
|
||||
#else
|
||||
#define _STDINT_NO_INT8_T
|
||||
#define _STDINT_NO_INT32_T
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/*
|
||||
* quote from SunOS-5.8 sys/inttypes.h:
|
||||
* Use at your own risk. As of February 1996, the committee is squarely
|
||||
* behind the fixed sized types; the "least" and "fast" types are still being
|
||||
* discussed. The probability that the "fast" types may be removed before
|
||||
* the standard is finalized is high enough that they are not currently
|
||||
* implemented.
|
||||
*/
|
||||
|
||||
#if defined _STDINT_NEED_INT_LEAST_T
|
||||
typedef int8_t int_least8_t;
|
||||
typedef int16_t int_least16_t;
|
||||
typedef int32_t int_least32_t;
|
||||
#ifdef _HAVE_UINT64_T
|
||||
typedef int64_t int_least64_t;
|
||||
#endif
|
||||
|
||||
typedef uint8_t uint_least8_t;
|
||||
typedef uint16_t uint_least16_t;
|
||||
typedef uint32_t uint_least32_t;
|
||||
#ifdef _HAVE_UINT64_T
|
||||
typedef uint64_t uint_least64_t;
|
||||
#endif
|
||||
/* least types */
|
||||
#endif
|
||||
|
||||
#if defined _STDINT_NEED_INT_FAST_T
|
||||
typedef int8_t int_fast8_t;
|
||||
typedef int int_fast16_t;
|
||||
typedef int32_t int_fast32_t;
|
||||
#ifdef _HAVE_UINT64_T
|
||||
typedef int64_t int_fast64_t;
|
||||
#endif
|
||||
|
||||
typedef uint8_t uint_fast8_t;
|
||||
typedef unsigned uint_fast16_t;
|
||||
typedef uint32_t uint_fast32_t;
|
||||
#ifdef _HAVE_UINT64_T
|
||||
typedef uint64_t uint_fast64_t;
|
||||
#endif
|
||||
/* fast types */
|
||||
#endif
|
||||
|
||||
#ifdef _STDINT_NEED_INTMAX_T
|
||||
#ifdef _HAVE_UINT64_T
|
||||
typedef int64_t intmax_t;
|
||||
typedef uint64_t uintmax_t;
|
||||
#else
|
||||
typedef long intmax_t;
|
||||
typedef unsigned long uintmax_t;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef _STDINT_NEED_INTPTR_T
|
||||
#ifndef __intptr_t_defined
|
||||
#define __intptr_t_defined
|
||||
/* we encourage using "long" to store pointer values, never use "int" ! */
|
||||
#if _STDINT_LONG_MODEL+0 == 242 || _STDINT_LONG_MODEL+0 == 484
|
||||
typedef unsinged int uintptr_t;
|
||||
typedef int intptr_t;
|
||||
#elif _STDINT_LONG_MODEL+0 == 244 || _STDINT_LONG_MODEL+0 == 444
|
||||
typedef unsigned long uintptr_t;
|
||||
typedef long intptr_t;
|
||||
#elif _STDINT_LONG_MODEL+0 == 448 && defined _HAVE_UINT64_T
|
||||
typedef uint64_t uintptr_t;
|
||||
typedef int64_t intptr_t;
|
||||
#else /* matches typical system types ILP32 and LP64 - but not IP16 or LLP64 */
|
||||
typedef unsigned long uintptr_t;
|
||||
typedef long intptr_t;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* shortcircuit*/
|
||||
#endif
|
||||
/* once */
|
||||
#endif
|
||||
#endif
|
||||
STDINT_EOF
|
||||
if cmp -s $ac_stdint_h $ac_stdint 2>/dev/null; then
|
||||
AC_MSG_NOTICE([$ac_stdint_h is unchanged])
|
||||
else
|
||||
ac_dir=`AS_DIRNAME(["$ac_stdint_h"])`
|
||||
AS_MKDIR_P(["$ac_dir"])
|
||||
rm -f $ac_stdint_h
|
||||
mv $ac_stdint $ac_stdint_h
|
||||
fi
|
||||
],[# variables for create stdint.h replacement
|
||||
PACKAGE="$PACKAGE"
|
||||
VERSION="$VERSION"
|
||||
ac_stdint_h="$ac_stdint_h"
|
||||
_ac_stdint_h=AS_TR_CPP(_$PACKAGE-$ac_stdint_h)
|
||||
ac_cv_stdint_message="$ac_cv_stdint_message"
|
||||
ac_cv_header_stdint_t="$ac_cv_header_stdint_t"
|
||||
ac_cv_header_stdint_x="$ac_cv_header_stdint_x"
|
||||
ac_cv_header_stdint_o="$ac_cv_header_stdint_o"
|
||||
ac_cv_header_stdint_u="$ac_cv_header_stdint_u"
|
||||
ac_cv_type_uint64_t="$ac_cv_type_uint64_t"
|
||||
ac_cv_type_u_int64_t="$ac_cv_type_u_int64_t"
|
||||
ac_cv_stdint_char_model="$ac_cv_stdint_char_model"
|
||||
ac_cv_stdint_long_model="$ac_cv_stdint_long_model"
|
||||
ac_cv_type_int_least32_t="$ac_cv_type_int_least32_t"
|
||||
ac_cv_type_int_fast32_t="$ac_cv_type_int_fast32_t"
|
||||
ac_cv_type_intmax_t="$ac_cv_type_intmax_t"
|
||||
])
|
||||
])
|
49
config/lam_functions.m4
Обычный файл
49
config/lam_functions.m4
Обычный файл
@ -0,0 +1,49 @@
|
||||
dnl -*- shell-script -*-
|
||||
dnl
|
||||
dnl Copyright (c) 2003 The Trustees of Indiana University.
|
||||
dnl All rights reserved.
|
||||
dnl
|
||||
dnl This file is part of the LAM software package. For license
|
||||
dnl information, see the LICENSE file in the top level directory of the
|
||||
dnl LAM source distribution.
|
||||
dnl
|
||||
dnl $Id: lam_functions.m4,v 1.1 2003/12/22 16:29:11 twoodall Exp $
|
||||
dnl
|
||||
|
||||
AC_DEFUN(LAM_CONFIGURE_SETUP,[
|
||||
|
||||
# Some helper script functions. Unfortunately, we cannot use $1 kinds
|
||||
# of arugments here because of the m4 substitution. So we have to set
|
||||
# special variable names before invoking the function. :-\
|
||||
|
||||
lam_show_title() {
|
||||
cat <<EOF
|
||||
|
||||
============================================================================
|
||||
== ${1}
|
||||
============================================================================
|
||||
EOF
|
||||
}
|
||||
|
||||
|
||||
lam_show_subtitle() {
|
||||
cat <<EOF
|
||||
|
||||
*** ${1}
|
||||
EOF
|
||||
}
|
||||
|
||||
#
|
||||
# Save some stats about this build
|
||||
#
|
||||
|
||||
LAM_CONFIGURE_USER="`whoami`"
|
||||
LAM_CONFIGURE_HOST="`hostname | head -n 1`"
|
||||
LAM_CONFIGURE_DATE="`date`"
|
||||
|
||||
#
|
||||
# Make automake clean emacs ~ files for "make clean"
|
||||
#
|
||||
|
||||
CLEANFILES="*~ .\#*"
|
||||
AC_SUBST(CLEANFILES)])dnl
|
39
config/lam_get_version.m4
Обычный файл
39
config/lam_get_version.m4
Обычный файл
@ -0,0 +1,39 @@
|
||||
dnl -*- shell-script -*-
|
||||
dnl
|
||||
dnl Copyright (c) 2003 The Trustees of Indiana University.
|
||||
dnl All rights reserved.
|
||||
dnl
|
||||
dnl This file is part of the LAM software package. For license
|
||||
dnl information, see the LICENSE file in the top level directory of the
|
||||
dnl LAM source distribution.
|
||||
dnl
|
||||
dnl $Id: lam_get_version.m4,v 1.1 2003/12/22 16:29:11 twoodall Exp $
|
||||
dnl
|
||||
|
||||
define(LAM_GET_VERSION,[
|
||||
gv_glv_dir="$1"
|
||||
gv_ver_file="$2"
|
||||
gv_prefix="$3"
|
||||
|
||||
# Find the get_lam_version program
|
||||
|
||||
gv_prog="sh $gv_glv_dir/lam_get_version.sh $gv_ver_file"
|
||||
|
||||
dnl quote eval to suppress macro expansion with non-GNU m4
|
||||
|
||||
gv_run() {
|
||||
[eval] ${gv_prefix}_${2}=`$gv_prog --${1}`
|
||||
}
|
||||
|
||||
gv_run full VERSION
|
||||
gv_run major MAJOR_VERSION
|
||||
gv_run minor MINOR_VERSION
|
||||
gv_run release RELEASE_VERSION
|
||||
gv_run alpha ALPHA_VERSION
|
||||
gv_run beta BETA_VERSION
|
||||
gv_run cvs CVS_VERSION
|
||||
|
||||
# Clean up
|
||||
|
||||
unset gv_glv_dir gv_ver_file gv_prefix gv_prog gv_run
|
||||
])
|
94
config/lam_get_version.sh
Исполняемый файл
94
config/lam_get_version.sh
Исполняемый файл
@ -0,0 +1,94 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright (c) 2003 The Trustees of Indiana University.
|
||||
# All rights reserved.
|
||||
#
|
||||
# This file is part of the CMMPI software package. For license
|
||||
# information, see the LICENSE file in the top level directory of the
|
||||
# LAM source distribution.
|
||||
#
|
||||
# $Id: lam_get_version.sh,v 1.1 2003/12/22 16:29:11 twoodall Exp $
|
||||
#
|
||||
# Since we do this in multiple places, it's worth putting in a
|
||||
# separate shell script. Very primitive script to get the version
|
||||
# number of LAM into a coherent variable. Can query for any of the
|
||||
# individual parts of the version number, too.
|
||||
#
|
||||
|
||||
srcfile="$1"
|
||||
option="$2"
|
||||
|
||||
if test "$srcfile" = ""; then
|
||||
option="--help"
|
||||
else
|
||||
LAM_MAJOR_VERSION="`cat $srcfile | grep major | cut -d= -f2`"
|
||||
LAM_MINOR_VERSION="`cat $srcfile | grep minor | cut -d= -f2`"
|
||||
LAM_RELEASE_VERSION="`cat $srcfile | grep release | cut -d= -f2`"
|
||||
LAM_ALPHA_VERSION="`cat $srcfile | grep alpha | cut -d= -f2`"
|
||||
LAM_BETA_VERSION="`cat $srcfile | grep beta | cut -d= -f2`"
|
||||
LAM_CVS_VERSION="`cat $srcfile | grep cvs | cut -d= -f2`"
|
||||
if test "$LAM_RELEASE_VERSION" != "0" -a "$LAM_RELEASE_VERSION" != ""; then
|
||||
LAM_VERSION="$LAM_MAJOR_VERSION.$LAM_MINOR_VERSION.$LAM_RELEASE_VERSION"
|
||||
else
|
||||
LAM_VERSION="$LAM_MAJOR_VERSION.$LAM_MINOR_VERSION"
|
||||
fi
|
||||
|
||||
if test "`expr $LAM_ALPHA_VERSION \> 0`" = "1"; then
|
||||
LAM_VERSION="${LAM_VERSION}a$LAM_ALPHA_VERSION"
|
||||
elif test "`expr $LAM_BETA_VERSION \> 0`" = "1"; then
|
||||
LAM_VERSION="${LAM_VERSION}b$LAM_BETA_VERSION"
|
||||
fi
|
||||
|
||||
if test "$LAM_CVS_VERSION" = "1"; then
|
||||
LAM_VERSION="${LAM_VERSION}cvs"
|
||||
elif test "`expr $LAM_CVS_VERSION \> 0`" = "1"; then
|
||||
LAM_VERSION="${LAM_VERSION}cvs$LAM_CVS_VERSION"
|
||||
fi
|
||||
|
||||
if test "$option" = ""; then
|
||||
option="--full"
|
||||
fi
|
||||
fi
|
||||
|
||||
case "$option" in
|
||||
--full|-v|--version)
|
||||
echo $LAM_VERSION
|
||||
;;
|
||||
--major)
|
||||
echo $LAM_MAJOR_VERSION
|
||||
;;
|
||||
--minor)
|
||||
echo $LAM_MINOR_VERSION
|
||||
;;
|
||||
--release)
|
||||
echo $LAM_RELEASE_VERSION
|
||||
;;
|
||||
--alpha)
|
||||
echo $LAM_ALPHA_VERSION
|
||||
;;
|
||||
--beta)
|
||||
echo $LAM_BETA_VERSION
|
||||
;;
|
||||
--cvs)
|
||||
echo $LAM_CVS_VERSION
|
||||
;;
|
||||
-h|--help)
|
||||
cat <<EOF
|
||||
$0 <srcfile> [<option>]
|
||||
|
||||
<srcfile> - Text version file
|
||||
<option> - One of:
|
||||
--full - Full version number
|
||||
--major - Major version number
|
||||
--minor - Minor version number
|
||||
--release - Release version number
|
||||
--alpha - Alpha version number
|
||||
--beta - Beta version nmumber
|
||||
--cvs - CVS date stamp
|
||||
--help - This message
|
||||
EOF
|
||||
esac
|
||||
|
||||
# All done
|
||||
|
||||
exit 0
|
135
configure.ac
135
configure.ac
@ -3,11 +3,11 @@
|
||||
# Copyright (c) 2003 The Trustees of Indiana University.
|
||||
# All rights reserved.
|
||||
#
|
||||
# This file is part of the CMPI software package. For license
|
||||
# This file is part of the LAM software package. For license
|
||||
# information, see the LICENSE file in the top level directory of the
|
||||
# CMPI source distribution.
|
||||
# LAM source distribution.
|
||||
#
|
||||
# $Id: configure.ac,v 1.3 2003/11/22 16:57:54 jsquyres Exp $
|
||||
# $Id: configure.ac,v 1.4 2003/12/22 16:29:11 twoodall Exp $
|
||||
#
|
||||
|
||||
|
||||
@ -21,40 +21,40 @@ AC_INIT(./src/mpi/datatype/d_get_name.c)
|
||||
AC_PREREQ(2.52)
|
||||
AC_CONFIG_AUX_DIR(./config)
|
||||
|
||||
# Get the version of CMPI that we are installing
|
||||
# Get the version of LAM that we are installing
|
||||
|
||||
CMPI_GET_VERSION($srcdir/config, $srcdir/VERSION, CMPI)
|
||||
LAM_GET_VERSION($srcdir/config, $srcdir/VERSION, LAM)
|
||||
|
||||
AC_DEFINE_UNQUOTED(CMPI_MAJOR_VERSION, $CMPI_MAJOR_VERSION,
|
||||
[Major CMPI version])
|
||||
AC_DEFINE_UNQUOTED(CMPI_MINOR_VERSION, $CMPI_MINOR_VERSION,
|
||||
[Minor CMPI version])
|
||||
AC_DEFINE_UNQUOTED(CMPI_RELEASE_VERSION, $CMPI_RELEASE_VERSION,
|
||||
[Release CMPI version])
|
||||
AC_DEFINE_UNQUOTED(CMPI_ALPHA_VERSION, $CMPI_ALPHA_VERSION,
|
||||
[Alpha CMPI version])
|
||||
AC_DEFINE_UNQUOTED(CMPI_BETA_VERSION, $CMPI_BETA_VERSION,
|
||||
[Beta CMPI version])
|
||||
AC_DEFINE_UNQUOTED(CMPI_CVS_VERSION, $CMPI_CVS_VERSION,
|
||||
[CVS CMPI version])
|
||||
AC_DEFINE_UNQUOTED(CMPI_VERSION, "$CMPI_VERSION",
|
||||
[Overall CMPI version number])
|
||||
AC_DEFINE_UNQUOTED(LAM_MAJOR_VERSION, $LAM_MAJOR_VERSION,
|
||||
[Major LAM version])
|
||||
AC_DEFINE_UNQUOTED(LAM_MINOR_VERSION, $LAM_MINOR_VERSION,
|
||||
[Minor LAM version])
|
||||
AC_DEFINE_UNQUOTED(LAM_RELEASE_VERSION, $LAM_RELEASE_VERSION,
|
||||
[Release LAM version])
|
||||
AC_DEFINE_UNQUOTED(LAM_ALPHA_VERSION, $LAM_ALPHA_VERSION,
|
||||
[Alpha LAM version])
|
||||
AC_DEFINE_UNQUOTED(LAM_BETA_VERSION, $LAM_BETA_VERSION,
|
||||
[Beta LAM version])
|
||||
AC_DEFINE_UNQUOTED(LAM_CVS_VERSION, $LAM_CVS_VERSION,
|
||||
[CVS LAM version])
|
||||
AC_DEFINE_UNQUOTED(LAM_VERSION, "$LAM_VERSION",
|
||||
[Overall LAM version number])
|
||||
|
||||
AC_SUBST(CMPI_MAJOR_VERSION)
|
||||
AC_SUBST(CMPI_MINOR_VERSION)
|
||||
AC_SUBST(CMPI_RELEASE_VERSION)
|
||||
AC_SUBST(CMPI_ALPHA_VERSION)
|
||||
AC_SUBST(CMPI_BETA_VERSION)
|
||||
AC_SUBST(CMPI_CVS_VERSION)
|
||||
AC_SUBST(CMPI_VERSION)
|
||||
AC_SUBST(LAM_MAJOR_VERSION)
|
||||
AC_SUBST(LAM_MINOR_VERSION)
|
||||
AC_SUBST(LAM_RELEASE_VERSION)
|
||||
AC_SUBST(LAM_ALPHA_VERSION)
|
||||
AC_SUBST(LAM_BETA_VERSION)
|
||||
AC_SUBST(LAM_CVS_VERSION)
|
||||
AC_SUBST(LAM_VERSION)
|
||||
|
||||
#
|
||||
# Start it up
|
||||
#
|
||||
|
||||
CMPI_CONFIGURE_SETUP
|
||||
cmpi_show_title "Configuring CMPI version $CMPI_VERSION"
|
||||
cmpi_show_subtitle "Initialization, setup"
|
||||
LAM_CONFIGURE_SETUP
|
||||
lam_show_title "Configuring LAM version $LAM_VERSION"
|
||||
lam_show_subtitle "Initialization, setup"
|
||||
|
||||
#
|
||||
# Init automake
|
||||
@ -62,39 +62,41 @@ cmpi_show_subtitle "Initialization, setup"
|
||||
# VERSION macors
|
||||
#
|
||||
|
||||
AM_INIT_AUTOMAKE(cmpi, $CMPI_VERSION, 'no')
|
||||
AM_INIT_AUTOMAKE(lam, $LAM_VERSION, 'no')
|
||||
|
||||
CMPI_TOP_BUILDDIR="`pwd`"
|
||||
AC_SUBST(CMPI_TOP_BUILDDIR)
|
||||
LAM_TOP_BUILDDIR="`pwd`"
|
||||
AC_SUBST(LAM_TOP_BUILDDIR)
|
||||
cd "$srcdir"
|
||||
CMPI_TOP_SRCDIR="`pwd`"
|
||||
AC_SUBST(CMPI_TOP_SRCDIR)
|
||||
cd "$CMPI_TOP_BUILDDIR"
|
||||
LAM_TOP_SRCDIR="`pwd`"
|
||||
AC_SUBST(LAM_TOP_SRCDIR)
|
||||
cd "$LAM_TOP_BUILDDIR"
|
||||
|
||||
AC_MSG_NOTICE([builddir: $CMPI_TOP_BUILDDIR])
|
||||
AC_MSG_NOTICE([srcdir: $CMPI_TOP_SRCDIR])
|
||||
if test "$CMPI_TOP_BUILDDIR" != "$CMPI_TOP_SRCDIR"; then
|
||||
AC_MSG_NOTICE([builddir: $LAM_TOP_BUILDDIR])
|
||||
AC_MSG_NOTICE([srcdir: $LAM_TOP_SRCDIR])
|
||||
if test "$LAM_TOP_BUILDDIR" != "$LAM_TOP_SRCDIR"; then
|
||||
AC_MSG_NOTICE([Detected VPATH build])
|
||||
fi
|
||||
|
||||
# Setup the top of the src/include/cmpi_config.h file
|
||||
# Setup the top of the src/include/lam_config.h file
|
||||
|
||||
AH_TOP([/* -*- c -*-
|
||||
*
|
||||
* Copyright (c) 2003 The Trustees of Indiana University.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This file is part of the CMPI software package. For license
|
||||
* This file is part of the LAM software package. For license
|
||||
* information, see the LICENSE file in the top level directory of the
|
||||
* CMPI source distribution.
|
||||
* LAM source distribution.
|
||||
*
|
||||
* Function: - OS, CPU and compiler dependent configuration
|
||||
*/
|
||||
|
||||
#ifndef CMPI_CONFIG_H
|
||||
#define CMPI_CONFIG_H
|
||||
#ifndef LAM_CONFIG_H
|
||||
#define LAM_CONFIG_H
|
||||
])
|
||||
AH_BOTTOM([
|
||||
#endif /* LAM_CONFIG_H */
|
||||
])
|
||||
AH_BOTTOM([#endif /* CMPI_CONFIG_H */])
|
||||
|
||||
# What kind of machine are we on?
|
||||
|
||||
@ -112,7 +114,7 @@ AC_CANONICAL_HOST
|
||||
# ...?
|
||||
|
||||
# amorphous, seem-to-be-good-idea options
|
||||
# --with-cmpi=maintainer_options
|
||||
# --with-lam=maintainer_options
|
||||
# --with-ssi-*
|
||||
# ...?
|
||||
|
||||
@ -130,8 +132,8 @@ AC_CANONICAL_HOST
|
||||
# the user requested something or if the default was set here.
|
||||
#
|
||||
|
||||
cmpi_enable_shared="$enable_shared"
|
||||
cmpi_enable_static="$enable_static"
|
||||
lam_enable_shared="$enable_shared"
|
||||
lam_enable_static="$enable_static"
|
||||
AM_DISABLE_SHARED
|
||||
AM_ENABLE_STATIC
|
||||
|
||||
@ -153,7 +155,8 @@ CFLAGS="$cflags_save"
|
||||
# check for some types
|
||||
# check for type sizes
|
||||
# check for type alignments
|
||||
|
||||
# check for c99 features
|
||||
AC_C_INLINE
|
||||
|
||||
##################################
|
||||
# C++ compiler characteristics
|
||||
@ -175,14 +178,14 @@ CXXFLAGS="$cxx_flags_save"
|
||||
##################################
|
||||
|
||||
if test "$with_f77" != "yes"; then
|
||||
cmpi_show_subtitle "Fortran Compiler -- skipped"
|
||||
CMPI_WANT_FORTRAN=1
|
||||
lam_show_subtitle "Fortran Compiler -- skipped"
|
||||
LAM_WANT_FORTRAN=1
|
||||
else
|
||||
cmpi_show_subtitle "Fortran Compiler"
|
||||
CMPI_WANT_FORTRAN=0
|
||||
lam_show_subtitle "Fortran Compiler"
|
||||
LAM_WANT_FORTRAN=0
|
||||
fi
|
||||
|
||||
if test "$CMPI_WANT_FORTRAN" = "1"; then
|
||||
if test "$LAM_WANT_FORTRAN" = "1"; then
|
||||
# fortran linking style (necessary?)
|
||||
# check for types
|
||||
# check for type sizes
|
||||
@ -190,7 +193,7 @@ if test "$CMPI_WANT_FORTRAN" = "1"; then
|
||||
true
|
||||
fi
|
||||
|
||||
AM_CONDITIONAL(WANT_FORTRAN, test "$CMPI_WANT_FORTRAN" = "1")
|
||||
AM_CONDITIONAL(WANT_FORTRAN, test "$LAM_WANT_FORTRAN" = "1")
|
||||
|
||||
|
||||
##################################
|
||||
@ -251,7 +254,7 @@ AM_CONDITIONAL(WANT_FORTRAN, test "$CMPI_WANT_FORTRAN" = "1")
|
||||
# (after C compiler setup)
|
||||
############################################################################
|
||||
|
||||
cmpi_show_title "Libtool configuration"
|
||||
lam_show_title "Libtool configuration"
|
||||
|
||||
AM_PROG_LIBTOOL
|
||||
|
||||
@ -260,7 +263,7 @@ AM_PROG_LIBTOOL
|
||||
# final wrapper compiler config
|
||||
############################################################################
|
||||
|
||||
cmpi_show_title "Final top-level CMPI configuration"
|
||||
lam_show_title "Final top-level LAM configuration"
|
||||
|
||||
#
|
||||
# This is needed for VPATH builds, so that it will -I the appropriate
|
||||
@ -270,8 +273,8 @@ cmpi_show_title "Final top-level CMPI configuration"
|
||||
# purely aesthetic.
|
||||
#
|
||||
|
||||
CPPFLAGS='-I$(top_srcdir)/share/include'" $CPPFLAGS"
|
||||
CXXCPPFLAGS='-I$(top_srcdir)/share/include'" $CXXCPPFLAGS"
|
||||
CPPFLAGS='-I$(top_srcdir)/src'" $CPPFLAGS"
|
||||
CXXCPPFLAGS='-I$(top_srcdir)/src'" $CXXCPPFLAGS"
|
||||
|
||||
#
|
||||
# Delayed the substitution of CFLAGS and CXXFLAGS until now because
|
||||
@ -289,9 +292,10 @@ AC_SUBST(FFLAGS)
|
||||
# Party on
|
||||
############################################################################
|
||||
|
||||
cmpi_show_subtitle "Final output"
|
||||
lam_show_subtitle "Final output"
|
||||
|
||||
AM_CONFIG_HEADER([src/include/cmpi_config.h])
|
||||
AX_CREATE_STDINT_H([src/include/lam_stdint.h])
|
||||
AM_CONFIG_HEADER([src/include/lam_config.h])
|
||||
AC_CONFIG_FILES([
|
||||
Makefile
|
||||
|
||||
@ -300,9 +304,20 @@ AC_CONFIG_FILES([
|
||||
src/Makefile
|
||||
src/include/Makefile
|
||||
|
||||
src/lam/Makefile
|
||||
src/lam/base/Makefile
|
||||
src/lam/mem/Makefile
|
||||
src/lam/os/Makefile
|
||||
src/lam/threads/Makefile
|
||||
src/lam/util/Makefile
|
||||
|
||||
src/mpi/Makefile
|
||||
src/mpi/communicator/Makefile
|
||||
src/mpi/datatype/Makefile
|
||||
src/mpi/p2p/Makefile
|
||||
src/mpi/p2p/base/Makefile
|
||||
src/mpi/p2p/interface/Makefile
|
||||
src/mpi/p2p/matching/Makefile
|
||||
|
||||
src/tools/Makefile
|
||||
src/tools/wrappers/Makefile
|
||||
|
@ -7,9 +7,9 @@
|
||||
# information, see the LICENSE file in the top level directory of the
|
||||
# CMPI source distribution.
|
||||
#
|
||||
# $Id: Makefile.am,v 1.1 2003/11/22 16:36:24 jsquyres Exp $
|
||||
# $Id: Makefile.am,v 1.2 2003/12/22 16:29:11 twoodall Exp $
|
||||
#
|
||||
|
||||
include $(top_srcdir)/config/Makefile.options
|
||||
|
||||
SUBDIRS = include mpi tools
|
||||
SUBDIRS = include lam mpi tools
|
||||
|
@ -7,7 +7,7 @@
|
||||
# information, see the LICENSE file in the top level directory of the
|
||||
# CMPI source distribution.
|
||||
#
|
||||
# $Id: Makefile.am,v 1.2 2003/11/22 16:57:54 jsquyres Exp $
|
||||
# $Id: Makefile.am,v 1.3 2003/12/22 16:29:11 twoodall Exp $
|
||||
#
|
||||
|
||||
include $(top_srcdir)/config/Makefile.options
|
||||
@ -19,11 +19,12 @@ noinst_HEADERS = \
|
||||
totalview.h
|
||||
|
||||
include_HEADERS = \
|
||||
cmpi_config.h \
|
||||
lam_config.h \
|
||||
lam_stdint.h \
|
||||
mpi.h \
|
||||
mpif.h
|
||||
|
||||
# Add a hook to run *after* the file cmpi_config.h has been installed
|
||||
# Add a hook to run *after* the file lam_config.h has been installed
|
||||
# out to the target location. It changes the pesky PACKAGE_* macros
|
||||
# that autoconf automatically generates (and there is no way of
|
||||
# turning off) into CMPI_PACKAGE_* in order to make <mpi.h> safe to
|
||||
@ -31,7 +32,7 @@ include_HEADERS = \
|
||||
|
||||
install-data-hook:
|
||||
sed -e 's/define PACKAGE/define CMPI_PACKAGE/' \
|
||||
$(DESTDIR)$(includedir)/cmpi_config.h \
|
||||
> $(DESTDIR)$(includedir)/cmpi_config.h.install
|
||||
mv $(DESTDIR)$(includedir)/cmpi_config.h.install \
|
||||
$(DESTDIR)$(includedir)/cmpi_config.h
|
||||
$(DESTDIR)$(includedir)/lam_config.h \
|
||||
> $(DESTDIR)$(includedir)/lam_config.h.install
|
||||
mv $(DESTDIR)$(includedir)/lam_config.h.install \
|
||||
$(DESTDIR)$(includedir)/lam_config.h
|
||||
|
@ -6,21 +6,18 @@
|
||||
* information, see the LICENSE file in the top level directory of the
|
||||
* CMPI source distribution.
|
||||
*
|
||||
* $Id: mpi.h,v 1.2 2003/11/22 16:57:54 jsquyres Exp $
|
||||
* $Id: mpi.h,v 1.3 2003/12/22 16:29:12 twoodall Exp $
|
||||
*/
|
||||
|
||||
#ifndef CMPI_H
|
||||
#define CMPI_H
|
||||
|
||||
#include <cmpi_config.h>
|
||||
|
||||
#define MPI_SUCCESS 0
|
||||
|
||||
#define MPI_MAX_OBJECT_NAME 64
|
||||
|
||||
typedef struct cmpi_communicator *MPI_Comm;
|
||||
typedef struct cmpi_group *MPI_Group;
|
||||
typedef struct cmpi_datatype *MPI_Datatype;
|
||||
typedef struct _lam_communicator *MPI_Comm;
|
||||
typedef struct _lam_group *MPI_Group;
|
||||
typedef struct _lam_datatype *MPI_Datatype;
|
||||
|
||||
extern MPI_Comm MPI_COMM_NULL;
|
||||
extern MPI_Comm MPI_COMM_WORLD;
|
||||
|
42
src/lam/Makefile.am
Обычный файл
42
src/lam/Makefile.am
Обычный файл
@ -0,0 +1,42 @@
|
||||
#
|
||||
# Copyright 2002-2003. The Regents of the University of California. This material
|
||||
# was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
# National Laboratory, which is operated by the University of California for
|
||||
# the U.S. Department of Energy. The Government is granted for itself and
|
||||
# others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
# license in this material to reproduce, prepare derivative works, and
|
||||
# perform publicly and display publicly. Beginning five (5) years after
|
||||
# October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
# Government is granted for itself and others acting on its behalf a paid-up,
|
||||
# nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
# prepare derivative works, distribute copies to the public, perform publicly
|
||||
# and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
# STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
# CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
# IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
# COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
# PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
# OWNED RIGHTS.
|
||||
#
|
||||
# Additionally, this program is free software; you can distribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public License as
|
||||
# published by the Free Software Foundation; either version 2 of the License,
|
||||
# or any later version. Accordingly, this program is distributed in the hope
|
||||
# that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
|
||||
include $(top_srcdir)/config/Makefile.options
|
||||
|
||||
SUBDIRS = base mem os threads util
|
||||
|
||||
lib_LTLIBRARIES = liblam.la
|
||||
|
||||
liblam_la_SOURCES =
|
||||
liblam_la_LIBADD = \
|
||||
$(top_builddir)/src/lam/base/libbase.la \
|
||||
$(top_builddir)/src/lam/mem/libmem.la \
|
||||
$(top_builddir)/src/lam/threads/libthreads.la \
|
||||
$(top_builddir)/src/lam/util/libutil.la
|
||||
|
39
src/lam/lfc/Makefile.am
Обычный файл
39
src/lam/lfc/Makefile.am
Обычный файл
@ -0,0 +1,39 @@
|
||||
#
|
||||
# Copyright 2002-2003. The Regents of the University of California. This material
|
||||
# was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
# National Laboratory, which is operated by the University of California for
|
||||
# the U.S. Department of Energy. The Government is granted for itself and
|
||||
# others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
# license in this material to reproduce, prepare derivative works, and
|
||||
# perform publicly and display publicly. Beginning five (5) years after
|
||||
# October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
# Government is granted for itself and others acting on its behalf a paid-up,
|
||||
# nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
# prepare derivative works, distribute copies to the public, perform publicly
|
||||
# and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
# STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
# CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
# IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
# COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
# PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
# OWNED RIGHTS.
|
||||
#
|
||||
# Additionally, this program is free software; you can distribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public License as
|
||||
# published by the Free Software Foundation; either version 2 of the License,
|
||||
# or any later version. Accordingly, this program is distributed in the hope
|
||||
# that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
|
||||
include $(top_srcdir)/config/Makefile.options
|
||||
|
||||
lib_LTLIBRARIES = libbase.la
|
||||
|
||||
libbase_la_SOURCES = \
|
||||
array.c \
|
||||
hash_table.c \
|
||||
list.c \
|
||||
object.c
|
||||
|
76
src/lam/lfc/array.c
Обычный файл
76
src/lam/lfc/array.c
Обычный файл
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
#include "lam/base/array.h"
|
||||
|
||||
lam_class_info_t array_cls = {"lam_array_t", &object_cls,
|
||||
(class_init_t) lam_arr_init, (class_destroy_t)lam_arr_destroy};
|
||||
|
||||
void lam_arr_init(lam_array_t *arr)
|
||||
{
|
||||
SUPER_INIT(arr, array_cls.cls_parent);
|
||||
arr->arr_items = NULL;
|
||||
arr->arr_length = 0;
|
||||
}
|
||||
|
||||
void lam_arr_destroy(lam_array_t *arr)
|
||||
{
|
||||
free(arr->arr_items);
|
||||
SUPER_DESTROY(arr, array_cls.cls_parent);
|
||||
}
|
||||
|
||||
void lam_arr_init_with(lam_array_t *arr, size_t length)
|
||||
{
|
||||
/* initializes array with fixed length.
|
||||
lam_arr_init() must have been called first. */
|
||||
if ( !arr->arr_items )
|
||||
{
|
||||
arr->arr_items = malloc(sizeof(lam_object_t *)*length);
|
||||
arr->arr_length = length;
|
||||
bzero(arr->arr_items, sizeof(lam_object_t *)*length);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void lam_arr_remove_item(lam_array_t *arr, int index)
|
||||
{
|
||||
if ( (index >=0) && (index < arr->arr_length) )
|
||||
{
|
||||
arr->arr_items[index] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void lam_arr_set_item(lam_array_t *arr, lam_object_t *item, int index)
|
||||
{
|
||||
if ( (index >=0) && (index < arr->arr_length) )
|
||||
{
|
||||
arr->arr_items[index] = item;
|
||||
}
|
||||
}
|
||||
|
69
src/lam/lfc/array.h
Обычный файл
69
src/lam/lfc/array.h
Обычный файл
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
#ifndef ARRAY_H
|
||||
#define ARRAY_H
|
||||
|
||||
#include "lam_types.h"
|
||||
#include "lam/base/object.h"
|
||||
|
||||
typedef struct lam_array
|
||||
{
|
||||
lam_object_t super;
|
||||
lam_object_t **arr_items;
|
||||
size_t arr_length;
|
||||
} lam_array_t;
|
||||
|
||||
extern lam_class_info_t array_cls;
|
||||
|
||||
void lam_arr_init(lam_array_t *arr);
|
||||
void lam_arr_destroy(lam_array_t *arr);
|
||||
|
||||
/* initializes array with fixed length.
|
||||
* lam_arr_init() must have been called first.
|
||||
*/
|
||||
void lam_arr_init_with(lam_array_t *arr, size_t length);
|
||||
|
||||
static inline lam_object_t *lam_arr_get_item(lam_array_t *arr, int index)
|
||||
{
|
||||
if ( (index >=0) && (index < arr->arr_length) )
|
||||
{
|
||||
return arr->arr_items[index];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void lam_arr_remove_item(lam_array_t *arr, int index);
|
||||
void lam_arr_set_item(lam_array_t *arr, lam_object_t *item, int index);
|
||||
|
||||
|
||||
#endif /* ARRAY_H */
|
||||
|
||||
|
278
src/lam/lfc/hash_table.c
Обычный файл
278
src/lam/lfc/hash_table.c
Обычный файл
@ -0,0 +1,278 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "lam_config.h"
|
||||
#include "lam_constants.h"
|
||||
#include "lam/base/hash_table.h"
|
||||
|
||||
#define BUCKET_ALLOC_SZ 5
|
||||
|
||||
lam_class_info_t lam_fast_hash_cls = {
|
||||
"lam_fast_hash_t", &object_cls, (class_init_t)lam_fh_init,
|
||||
(class_destroy_t)lam_fh_destroy
|
||||
};
|
||||
|
||||
/*
|
||||
*
|
||||
* Private hash table functions
|
||||
*
|
||||
*/
|
||||
#define MULTIPLIER 31
|
||||
|
||||
static inline uint32_t lam_hash_value(const char * key, uint32_t keysize)
|
||||
{
|
||||
uint32_t h, i;
|
||||
const char *p;
|
||||
|
||||
h = 0;
|
||||
p = key;
|
||||
for (i = 0; i < keysize; i++, p++)
|
||||
h = MULTIPLIER*h + *p;
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
|
||||
static inline void *lam_fh_get_value(lam_fast_hash_t *htbl, void *key, uint32_t keysize)
|
||||
{
|
||||
uint32_t hval, i;
|
||||
lam_fhnode_t *buckets;
|
||||
|
||||
/* ASSERT: table size is power of 2 and table
|
||||
has been initialized using lam_fh_init_with().
|
||||
*/
|
||||
hval = lam_hash_value((const char *)key, keysize) & htbl->fh_mask;
|
||||
buckets = htbl->fh_nodes[hval];
|
||||
if ( !buckets )
|
||||
return 0;
|
||||
|
||||
for ( i = 0; i < htbl->fh_bucket_cnt[hval]; i++ )
|
||||
{
|
||||
if ( (1 == buckets[i].fhn_is_taken) &&
|
||||
(0 == memcmp(&(buckets[i].fhn_key), key, keysize)) )
|
||||
return buckets[i].fhn_value;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static inline void lam_fh_remove_value(lam_fast_hash_t *htbl, void *key, uint32_t keysize)
|
||||
{
|
||||
uint32_t hval, i;
|
||||
lam_fhnode_t *buckets;
|
||||
|
||||
/* ASSERT: table size is power of 2 and table
|
||||
has been initialized using lam_fh_init_with().
|
||||
*/
|
||||
hval = lam_hash_value((const char *)key, keysize) & htbl->fh_mask;
|
||||
buckets = htbl->fh_nodes[hval];
|
||||
if ( !buckets )
|
||||
return ;
|
||||
|
||||
for ( i = 0; i < htbl->fh_bucket_cnt[hval]; i++ )
|
||||
{
|
||||
if ( (1 == buckets[i].fhn_is_taken) &&
|
||||
(0 == memcmp(&(buckets[i].fhn_key), key, keysize)) )
|
||||
{
|
||||
buckets[i].fhn_is_taken = 0;
|
||||
buckets[i].fhn_value = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static inline int lam_fh_set_value(lam_fast_hash_t *htbl, void *val,
|
||||
void *key, uint32_t keysize)
|
||||
{
|
||||
uint32_t hval, i;
|
||||
lam_fhnode_t *buckets;
|
||||
|
||||
/* ASSERT: table size is power of 2 and table
|
||||
has been initialized using lam_fh_init_with().
|
||||
*/
|
||||
hval = lam_hash_value((const char *)key, keysize) & htbl->fh_mask;
|
||||
buckets = htbl->fh_nodes[hval];
|
||||
if ( !buckets )
|
||||
{
|
||||
/* create new array of buckets
|
||||
for collision */
|
||||
htbl->fh_nodes[hval] = (lam_fhnode_t *)malloc(sizeof(lam_fhnode_t)
|
||||
* BUCKET_ALLOC_SZ);
|
||||
if ( !htbl->fh_nodes[hval] )
|
||||
return LAM_ERR_OUT_OF_RESOURCE;
|
||||
|
||||
bzero(htbl->fh_nodes[hval], sizeof(lam_fhnode_t)
|
||||
* BUCKET_ALLOC_SZ);
|
||||
htbl->fh_bucket_cnt[hval] = BUCKET_ALLOC_SZ; /* keep track of array size. */
|
||||
buckets = htbl->fh_nodes[hval];
|
||||
}
|
||||
|
||||
/* find an empty bucket. If no empty buckets,
|
||||
then realloc. */
|
||||
for ( i = 0; i < htbl->fh_bucket_cnt[hval]; i++ )
|
||||
{
|
||||
if ( 0 == buckets[i].fhn_is_taken )
|
||||
{
|
||||
/* found empty bucket */
|
||||
memcpy(&(buckets[i].fhn_key), key, keysize);
|
||||
buckets[i].fhn_value = val;
|
||||
buckets[i].fhn_is_taken = 1;
|
||||
|
||||
htbl->fh_count++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( i == htbl->fh_bucket_cnt[hval] )
|
||||
{
|
||||
/* no empty buckets! */
|
||||
htbl->fh_nodes[hval] = (lam_fhnode_t *)realloc(htbl->fh_nodes[hval],
|
||||
sizeof(lam_fhnode_t)
|
||||
* (htbl->fh_bucket_cnt[hval] + BUCKET_ALLOC_SZ));
|
||||
|
||||
if ( !htbl->fh_nodes[hval] )
|
||||
return LAM_ERR_OUT_OF_RESOURCE;
|
||||
|
||||
/* get ptr to start of newly alloc buckets */
|
||||
buckets = htbl->fh_nodes[hval] + htbl->fh_bucket_cnt[hval];
|
||||
bzero(buckets, sizeof(lam_fhnode_t)
|
||||
* BUCKET_ALLOC_SZ);
|
||||
|
||||
memcpy(&(buckets[i].fhn_key), key, keysize);
|
||||
buckets[0].fhn_value = val;
|
||||
buckets[0].fhn_is_taken = 1;
|
||||
|
||||
htbl->fh_bucket_cnt[hval] += BUCKET_ALLOC_SZ; /* keep track of array size. */
|
||||
}
|
||||
|
||||
return LAM_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Fast hash table interface
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
void lam_fh_init(lam_fast_hash_t *htbl)
|
||||
{
|
||||
SUPER_INIT(htbl, lam_fast_hash_cls.cls_parent);
|
||||
htbl->fh_nodes = 0;
|
||||
htbl->fh_count = 0;
|
||||
htbl->fh_size = 0;
|
||||
htbl->fh_mask = 0;
|
||||
htbl->fh_bucket_cnt = 0;
|
||||
}
|
||||
|
||||
void lam_fh_destroy(lam_fast_hash_t *htbl)
|
||||
{
|
||||
int i;
|
||||
|
||||
if ( htbl->fh_nodes )
|
||||
{
|
||||
for ( i = 0; i < htbl->fh_size; i++ )
|
||||
{
|
||||
if ( htbl->fh_nodes[i] )
|
||||
free(htbl->fh_nodes[i]);
|
||||
}
|
||||
free(htbl->fh_nodes);
|
||||
free(htbl->fh_bucket_cnt);
|
||||
}
|
||||
|
||||
SUPER_DESTROY(htbl, lam_fast_hash_cls.cls_parent);
|
||||
}
|
||||
|
||||
|
||||
/* initialize hash table with fixed size, usually power of 2 or prime */
|
||||
int lam_fh_init_with(lam_fast_hash_t *htbl, uint32_t power2_size)
|
||||
{
|
||||
uint32_t size;
|
||||
|
||||
size = 1 << power2_size;
|
||||
htbl->fh_mask = size - 1;
|
||||
htbl->fh_nodes = (lam_fhnode_t **)malloc(sizeof(lam_fhnode_t *) * size);
|
||||
if ( 0 == htbl->fh_nodes )
|
||||
return LAM_ERR_OUT_OF_RESOURCE;
|
||||
|
||||
htbl->fh_bucket_cnt = (uint32_t *)malloc(sizeof(uint32_t) * size);
|
||||
if ( 0 == htbl->fh_bucket_cnt )
|
||||
{
|
||||
free(htbl->fh_nodes);
|
||||
return LAM_ERR_OUT_OF_RESOURCE;
|
||||
}
|
||||
|
||||
htbl->fh_size = size;
|
||||
bzero(htbl->fh_nodes, sizeof(lam_fhnode_t *)*size);
|
||||
bzero(htbl->fh_bucket_cnt, sizeof(uint32_t)*size);
|
||||
|
||||
return LAM_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
void *lam_fh_get_value_for_ikey(lam_fast_hash_t *htbl, uint32_t key)
|
||||
{
|
||||
return lam_fh_get_value(htbl, &key, sizeof(key));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void lam_fh_remove_value_for_ikey(lam_fast_hash_t *htbl, uint32_t key)
|
||||
{
|
||||
lam_fh_remove_value(htbl, &key, sizeof(key));
|
||||
}
|
||||
|
||||
|
||||
int lam_fh_set_value_for_ikey(lam_fast_hash_t *htbl, void *val, uint32_t key)
|
||||
{
|
||||
return lam_fh_set_value(htbl, val, &key, sizeof(key));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void *lam_fh_get_value_for_skey(lam_fast_hash_t *htbl, const char *key)
|
||||
{
|
||||
return lam_fh_get_value(htbl, (void *)key, strlen(key));
|
||||
}
|
||||
|
||||
void lam_fh_remove_value_for_skey(lam_fast_hash_t *htbl, const char *key)
|
||||
{
|
||||
lam_fh_remove_value(htbl, (void *)key, strlen(key));
|
||||
}
|
||||
|
||||
int lam_fh_set_value_for_skey(lam_fast_hash_t *htbl, void *val, const char *key)
|
||||
{
|
||||
return lam_fh_set_value(htbl, val, (void *)key, strlen(key));
|
||||
}
|
||||
|
84
src/lam/lfc/hash_table.h
Обычный файл
84
src/lam/lfc/hash_table.h
Обычный файл
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
#ifndef HASH_TABLE_H
|
||||
#define HASH_TABLE_H
|
||||
|
||||
#include "lam_stdint.h"
|
||||
#include "lam/base/object.h"
|
||||
|
||||
typedef struct lam_fhnode
|
||||
{
|
||||
union{
|
||||
uint32_t ikey;
|
||||
char *skey;
|
||||
} fhn_key;
|
||||
void *fhn_value;
|
||||
char fhn_is_taken; /* 1->node is occupied, 0-> not occupied */
|
||||
} lam_fhnode_t;
|
||||
|
||||
/* Hash table that only allows integer or string keys. */
|
||||
typedef struct lam_fast_hash
|
||||
{
|
||||
lam_object_t super;
|
||||
lam_fhnode_t **fh_nodes; /* each item is an array of ints */
|
||||
uint32_t fh_count; /* number of values on table */
|
||||
uint32_t *fh_bucket_cnt; /* size of each bucket array */
|
||||
uint32_t fh_mask; /* used to compute the hash value */
|
||||
uint32_t fh_size;
|
||||
} lam_fast_hash_t;
|
||||
|
||||
extern lam_class_info_t lam_fast_hash_cls;
|
||||
|
||||
/*
|
||||
*
|
||||
* Fast hash table interface
|
||||
*
|
||||
*/
|
||||
|
||||
void lam_fh_init(lam_fast_hash_t *htbl);
|
||||
void lam_fh_destroy(lam_fast_hash_t *htbl);
|
||||
|
||||
/* initialize hash table with fixed size 2 ^ (power2_size) */
|
||||
int lam_fh_init_with(lam_fast_hash_t *htbl, uint32_t power2_size);
|
||||
|
||||
void *lam_fh_get_value_for_ikey(lam_fast_hash_t *htbl, uint32_t key);
|
||||
void lam_fh_remove_value_for_ikey(lam_fast_hash_t *htbl, uint32_t key);
|
||||
int lam_fh_set_value_for_ikey(lam_fast_hash_t *htbl, void *val, uint32_t key);
|
||||
|
||||
void *lam_fh_get_value_for_skey(lam_fast_hash_t *htbl, const char *key);
|
||||
void lam_fh_remove_value_for_skey(lam_fast_hash_t *htbl, const char *key);
|
||||
int lam_fh_set_value_for_skey(lam_fast_hash_t *htbl, void *val, const char *key);
|
||||
|
||||
|
||||
/* returns the number of items in the table */
|
||||
static inline uint32_t lam_fh_count(lam_fast_hash_t *htbl) {return htbl->fh_count;}
|
||||
|
||||
#endif /* HASH_TABLE_H */
|
||||
|
209
src/lam/lfc/list.c
Обычный файл
209
src/lam/lfc/list.c
Обычный файл
@ -0,0 +1,209 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
#include "lam/base/list.h"
|
||||
|
||||
|
||||
/*
|
||||
* List classes
|
||||
*/
|
||||
|
||||
|
||||
lam_class_info_t lam_dbl_item_cls = {"lam_dbl_link_item_t", &object_cls,
|
||||
(class_init_t) lam_dbl_item_init, (class_destroy_t)lam_obj_destroy};
|
||||
lam_class_info_t lam_dbl_list_cls = {"lam_dbl_list_t", &object_cls,
|
||||
(class_init_t)lam_dbl_init, (class_destroy_t)lam_dbl_destroy};
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* lam_dbl_link_item_t interface
|
||||
*
|
||||
*/
|
||||
|
||||
void lam_dbl_item_init(lam_dbl_item_t *item)
|
||||
{
|
||||
SUPER_INIT(item, lam_dbl_item_cls.cls_parent);
|
||||
item->lam_dbl_next = item->lam_dbl_prev = 0;
|
||||
item->lam_dbl_type = 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* lam_dbl_list_t interface
|
||||
*
|
||||
*/
|
||||
|
||||
void lam_dbl_init(lam_dbl_list_t *list)
|
||||
{
|
||||
SUPER_INIT(list, lam_dbl_list_cls.cls_parent);
|
||||
list->lam_dbl_head = list->lam_dbl_tail = 0;
|
||||
list->lam_dbl_type = 0;
|
||||
list->lam_dbl_length = 0;
|
||||
}
|
||||
|
||||
void lam_dbl_destroy(lam_dbl_list_t *list)
|
||||
{
|
||||
/* release all items in list */
|
||||
lam_dbl_empty_list(list);
|
||||
SUPER_DESTROY(list, lam_dbl_list_cls.cls_parent);
|
||||
}
|
||||
|
||||
|
||||
void lam_dbl_append(lam_dbl_list_t *list, lam_dbl_item_t *item)
|
||||
{
|
||||
/* Adds item to the end of the list. */
|
||||
item->lam_dbl_next = 0;
|
||||
item->lam_dbl_prev = list->lam_dbl_tail;
|
||||
if ( !(list->lam_dbl_head) )
|
||||
list->lam_dbl_head = item;
|
||||
if ( list->lam_dbl_tail )
|
||||
list->lam_dbl_tail->lam_dbl_next = item;
|
||||
|
||||
list->lam_dbl_tail = item;
|
||||
list->lam_dbl_length++;
|
||||
}
|
||||
|
||||
void lam_dbl_empty_list(lam_dbl_list_t *list)
|
||||
{
|
||||
/* Since we don't retain the items, simply set
|
||||
each item's next and prev pointers to 0. */
|
||||
lam_dbl_item_t *ptr, *next;
|
||||
|
||||
ptr = list->lam_dbl_head;
|
||||
while ( ptr )
|
||||
{
|
||||
next = ptr->lam_dbl_next;
|
||||
ptr->lam_dbl_next = ptr->lam_dbl_prev = 0;
|
||||
ptr = next;
|
||||
}
|
||||
list->lam_dbl_head = list->lam_dbl_tail = 0;
|
||||
list->lam_dbl_length = 0;
|
||||
}
|
||||
|
||||
|
||||
int lam_dbl_insert(lam_dbl_list_t *list, lam_dbl_item_t *item, long long idx)
|
||||
{
|
||||
/* Adds item to list at index and retains item. */
|
||||
int i;
|
||||
lam_dbl_item_t *ptr, *next;
|
||||
|
||||
if ( idx >= list->lam_dbl_length )
|
||||
return 0;
|
||||
|
||||
if ( 0 == idx )
|
||||
{
|
||||
lam_dbl_prepend(list, item);
|
||||
}
|
||||
else
|
||||
{
|
||||
ptr = list->lam_dbl_head;
|
||||
for ( i = 0; i < idx; i++ )
|
||||
ptr = ptr->lam_dbl_next;
|
||||
|
||||
next = ptr->lam_dbl_next;
|
||||
item->lam_dbl_next = next;
|
||||
item->lam_dbl_prev = ptr;
|
||||
next->lam_dbl_prev = item;
|
||||
ptr->lam_dbl_next = item;
|
||||
}
|
||||
|
||||
list->lam_dbl_length++;
|
||||
return 1;
|
||||
}
|
||||
|
||||
lam_dbl_item_t *lam_dbl_get_first_item(lam_dbl_list_t *list)
|
||||
{
|
||||
/* Returns first item on list, but does not remove it from the list. */
|
||||
return list->lam_dbl_head;
|
||||
}
|
||||
|
||||
lam_dbl_item_t *lam_dbl_get_last_item(lam_dbl_list_t *list)
|
||||
{
|
||||
/* Returns last item on list, but does not remove it from the list. */
|
||||
return list->lam_dbl_tail;
|
||||
}
|
||||
|
||||
void lam_dbl_prepend(lam_dbl_list_t *list, lam_dbl_item_t *item)
|
||||
{
|
||||
/* Adds item to the front of the list and retains item. */
|
||||
item->lam_dbl_next = list->lam_dbl_head;
|
||||
item->lam_dbl_prev = 0;
|
||||
if ( list->lam_dbl_head )
|
||||
list->lam_dbl_head->lam_dbl_prev = item;
|
||||
list->lam_dbl_head = item;
|
||||
}
|
||||
|
||||
lam_dbl_item_t *lam_dbl_remove_first(lam_dbl_list_t *list)
|
||||
{
|
||||
/* Removes and returns first item on list.
|
||||
Caller now owns the item and should release the item
|
||||
when caller is done with it.
|
||||
*/
|
||||
lam_dbl_item_t *item;
|
||||
if ( 0 == list->lam_dbl_length )
|
||||
return 0;
|
||||
|
||||
list->lam_dbl_length--;
|
||||
item = list->lam_dbl_head;
|
||||
list->lam_dbl_head = item->lam_dbl_next;
|
||||
if ( list->lam_dbl_length )
|
||||
{
|
||||
item->lam_dbl_next->lam_dbl_prev = 0;
|
||||
}
|
||||
else
|
||||
list->lam_dbl_tail = 0;
|
||||
|
||||
item->lam_dbl_next = item->lam_dbl_prev = 0;
|
||||
return item;
|
||||
}
|
||||
|
||||
lam_dbl_item_t *lam_dbl_remove_last(lam_dbl_list_t *list)
|
||||
{
|
||||
/* Removes, releases and returns last item on list.
|
||||
Caller now owns the item and should release the item
|
||||
when caller is done with it.
|
||||
*/
|
||||
lam_dbl_item_t *item;
|
||||
|
||||
if ( 0 == list->lam_dbl_length )
|
||||
return 0;
|
||||
|
||||
list->lam_dbl_length--;
|
||||
item = list->lam_dbl_head;
|
||||
list->lam_dbl_tail = item->lam_dbl_prev;
|
||||
if ( list->lam_dbl_length )
|
||||
item->lam_dbl_prev->lam_dbl_next = 0;
|
||||
else
|
||||
list->lam_dbl_head = 0;
|
||||
item->lam_dbl_next = item->lam_dbl_prev = 0;
|
||||
return item;
|
||||
}
|
||||
|
164
src/lam/lfc/list.h
Обычный файл
164
src/lam/lfc/list.h
Обычный файл
@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
#ifndef _LIST_H_
|
||||
#define _LIST_H_
|
||||
|
||||
#include "lam/base/object.h"
|
||||
|
||||
/*
|
||||
*
|
||||
* Available Classes
|
||||
*
|
||||
*/
|
||||
|
||||
extern lam_class_info_t lam_dbl_item_cls;
|
||||
extern lam_class_info_t lam_dbl_list_cls;
|
||||
typedef int lam_dbl_type_t;
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* lam_dbl_item_t interface
|
||||
*
|
||||
*/
|
||||
|
||||
typedef struct _lam_dbl_item
|
||||
{
|
||||
lam_object_t super;
|
||||
lam_dbl_type_t lam_dbl_type;
|
||||
struct _lam_dbl_item *lam_dbl_next;
|
||||
struct _lam_dbl_item *lam_dbl_prev;
|
||||
} lam_dbl_item_t;
|
||||
|
||||
void lam_dbl_item_init(lam_dbl_item_t *item);
|
||||
void lam_dbl_item_destroy(lam_dbl_item_t *item);
|
||||
|
||||
#define lam_dbl_get_next(item) \
|
||||
((item) ? (((lam_dbl_item_t*)(item))->lam_dbl_next) : 0)
|
||||
|
||||
#define lam_dbl_get_prev(item) \
|
||||
((item) ? (((lam_dbl_item_t*)(item))->lam_dbl_prev) : 0)
|
||||
|
||||
/*
|
||||
*
|
||||
* lam_dbl_list_t interface
|
||||
*
|
||||
*/
|
||||
|
||||
typedef struct _lam_dbl_list
|
||||
{
|
||||
lam_object_t super;
|
||||
lam_dbl_item_t *lam_dbl_head;
|
||||
lam_dbl_item_t *lam_dbl_tail;
|
||||
lam_dbl_type_t lam_dbl_type;
|
||||
volatile size_t lam_dbl_length;
|
||||
} lam_dbl_list_t;
|
||||
|
||||
|
||||
void lam_dbl_init(lam_dbl_list_t *list);
|
||||
void lam_dbl_destroy(lam_dbl_list_t *list);
|
||||
|
||||
/*
|
||||
* Inlined accessor functions
|
||||
*/
|
||||
|
||||
#define lam_dbl_get_type(list) \
|
||||
((lam_dbl_list_t*)list)->lam_dbl_type
|
||||
|
||||
#define lam_dbl_set_type(list, type) \
|
||||
(((lam_dbl_list_t*)list)->lam_dbl_type = type)
|
||||
|
||||
#define lam_dbl_get_size(list) \
|
||||
((lam_dbl_list_t*)list)->lam_dbl_length
|
||||
|
||||
|
||||
/*
|
||||
* Returns first item on list, but does not remove it from the list.
|
||||
*/
|
||||
#define lam_dbl_get_first(list) \
|
||||
((lam_dbl_list_t*)list)->lam_dbl_head
|
||||
|
||||
|
||||
/*
|
||||
* Returns last item on list, but does not remove it from the list.
|
||||
*/
|
||||
#define lam_dbl_get_last(list) \
|
||||
((lam_dbl_list_t*)list)->lam_dbl_tail
|
||||
|
||||
|
||||
/*
|
||||
* Adds item to the end of the list but does not retain item.
|
||||
*/
|
||||
void lam_dbl_append(lam_dbl_list_t *list, lam_dbl_item_t *item);
|
||||
|
||||
|
||||
/*
|
||||
* Remove item from the list.
|
||||
*/
|
||||
lam_dbl_item_t* lam_dbl_remove(lam_dbl_list_t *list, lam_dbl_item_t *item);
|
||||
|
||||
|
||||
/*
|
||||
* Removes all items in list and sets each
|
||||
* item's next and prev pointer to 0.
|
||||
*/
|
||||
void lam_dbl_empty_list(lam_dbl_list_t *list);
|
||||
|
||||
|
||||
/* Adds item to list at index and retains item.
|
||||
Returns 1 if successful, 0 otherwise.
|
||||
0 <= idx < length_m
|
||||
Example: if idx = 2 and list = item1->item2->item3->item4, then
|
||||
after insert, list = item1->item2->item->item3->item4
|
||||
*/
|
||||
int lam_dbl_insert(lam_dbl_list_t *list, lam_dbl_item_t *item, long long idx);
|
||||
|
||||
|
||||
/*
|
||||
* Adds item to the front of the list and retains item.
|
||||
*/
|
||||
|
||||
void lam_dbl_prepend(lam_dbl_list_t *list, lam_dbl_item_t *item);
|
||||
|
||||
|
||||
/*
|
||||
* Removes and returns first item on list.
|
||||
*/
|
||||
lam_dbl_item_t *lam_dbl_remove_first(lam_dbl_list_t *list);
|
||||
|
||||
|
||||
/*
|
||||
* Removes and returns last item on list.
|
||||
*/
|
||||
lam_dbl_item_t *lam_dbl_remove_last(lam_dbl_list_t *list);
|
||||
|
||||
#endif
|
||||
|
43
src/lam/lfc/object.c
Обычный файл
43
src/lam/lfc/object.c
Обычный файл
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
#include "lam/base/object.h"
|
||||
|
||||
lam_class_info_t object_cls = { "lam_object_t", 0, lam_obj_init, lam_obj_destroy };
|
||||
|
||||
void lam_obj_init(lam_object_t *obj)
|
||||
{
|
||||
obj->obj_refcnt = 1;
|
||||
}
|
||||
|
||||
void lam_obj_destroy(lam_object_t *obj)
|
||||
{
|
||||
free(obj);
|
||||
}
|
||||
|
135
src/lam/lfc/object.h
Обычный файл
135
src/lam/lfc/object.h
Обычный файл
@ -0,0 +1,135 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
#ifndef _OBJECT_H_
|
||||
#define _OBJECT_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "lam_types.h"
|
||||
#include "lam/os/atomic.h"
|
||||
|
||||
/*
|
||||
*
|
||||
* Base data structures
|
||||
*
|
||||
*/
|
||||
|
||||
struct _object;
|
||||
|
||||
typedef void (*class_init_t)(struct _object *);
|
||||
typedef void (*class_destroy_t)(struct _object *);
|
||||
|
||||
typedef struct lam_class_info
|
||||
{
|
||||
const char *cls_name;
|
||||
struct lam_class_info *cls_parent;
|
||||
class_init_t cls_init;
|
||||
class_destroy_t cls_destroy;
|
||||
} lam_class_info_t;
|
||||
|
||||
#define OBJECT(obj) ((lam_object_t *)(obj))
|
||||
#define CREATE_OBJECT(obj, lam_obj_type, cls_ptr) \
|
||||
do { \
|
||||
obj = (lam_obj_type *)malloc(sizeof(lam_obj_type)); \
|
||||
if ( obj ) \
|
||||
{ \
|
||||
OBJECT(obj)->obj_class = cls_ptr; \
|
||||
OBJECT(obj)->obj_class->cls_init(OBJECT(obj)); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
*
|
||||
* Available Classes
|
||||
*
|
||||
*/
|
||||
|
||||
extern lam_class_info_t object_cls;
|
||||
|
||||
/*
|
||||
*
|
||||
* Helpful macros
|
||||
*
|
||||
*/
|
||||
|
||||
#define SUPER(obj) (&((obj)->super))
|
||||
|
||||
/* Use STATIC_INIT to initialize objects that are not
|
||||
dynamically allocated. */
|
||||
#define STATIC_INIT(obj, cls_ptr) \
|
||||
do { \
|
||||
OBJECT(obj)->obj_class = cls_ptr; \
|
||||
OBJECT(obj)->obj_class->cls_init(obj); \
|
||||
} while (0)
|
||||
|
||||
/* super_cls should be the pointer to the obj's parent
|
||||
class info struct. */
|
||||
#define SUPER_INIT(obj, super_cls) \
|
||||
do { \
|
||||
(super_cls)->cls_init(OBJECT(obj)); \
|
||||
} while (0)
|
||||
|
||||
#define SUPER_DESTROY(obj, super_cls) (super_cls)->cls_destroy(OBJECT(obj))
|
||||
#define OBJ_RETAIN(obj) if ( obj ) lam_obj_retain(OBJECT(obj))
|
||||
#define OBJ_RELEASE(obj) if ( obj ) lam_obj_release(OBJECT(obj))
|
||||
|
||||
typedef struct _object
|
||||
{
|
||||
lam_class_info_t *obj_class;
|
||||
int obj_refcnt;
|
||||
} lam_object_t;
|
||||
|
||||
void lam_obj_init(lam_object_t *obj);
|
||||
void lam_obj_destroy(lam_object_t *obj);
|
||||
|
||||
/*
|
||||
returns 1 if object's class is derived from cls, otherwise 0.
|
||||
*/
|
||||
int lam_obj_is_kind_of(lam_object_t *obj, lam_class_info_t *cls);
|
||||
|
||||
static inline int lam_obj_get_ref_count(lam_object_t *obj)
|
||||
{
|
||||
return obj->obj_refcnt;
|
||||
}
|
||||
|
||||
static inline void lam_obj_retain(lam_object_t *obj)
|
||||
{
|
||||
fetchNadd(&obj->obj_refcnt, 1);
|
||||
}
|
||||
|
||||
static inline void lam_obj_release(lam_object_t *obj)
|
||||
{
|
||||
if ( fetchNadd(&obj->obj_refcnt, -1) == 1 )
|
||||
{
|
||||
obj->obj_class->cls_destroy(obj);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
38
src/lam/mem/Makefile.am
Обычный файл
38
src/lam/mem/Makefile.am
Обычный файл
@ -0,0 +1,38 @@
|
||||
#
|
||||
# Copyright 2002-2003. The Regents of the University of California. This material
|
||||
# was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
# National Laboratory, which is operated by the University of California for
|
||||
# the U.S. Department of Energy. The Government is granted for itself and
|
||||
# others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
# license in this material to reproduce, prepare derivative works, and
|
||||
# perform publicly and display publicly. Beginning five (5) years after
|
||||
# October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
# Government is granted for itself and others acting on its behalf a paid-up,
|
||||
# nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
# prepare derivative works, distribute copies to the public, perform publicly
|
||||
# and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
# STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
# CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
# IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
# COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
# PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
# OWNED RIGHTS.
|
||||
#
|
||||
# Additionally, this program is free software; you can distribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public License as
|
||||
# published by the Free Software Foundation; either version 2 of the License,
|
||||
# or any later version. Accordingly, this program is distributed in the hope
|
||||
# that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
|
||||
include $(top_srcdir)/config/Makefile.options
|
||||
|
||||
lib_LTLIBRARIES = libmem.la
|
||||
|
||||
libmem_la_SOURCES = \
|
||||
allocator.c \
|
||||
mem_pool.c \
|
||||
seg_list.c \
|
||||
sharedmem_util.c
|
85
src/lam/mem/allocator.c
Обычный файл
85
src/lam/mem/allocator.c
Обычный файл
@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
#include "lam/mem/allocator.h"
|
||||
#include "lam/mem/sharedmem_util.h"
|
||||
|
||||
void *lam_alc_malloc(lam_allocator_t *allocator, size_t chunk_size);
|
||||
void lam_alc_default_free(lam_allocator_t *allocator, void *base_ptr);
|
||||
|
||||
lam_class_info_t allocator_cls = {"lam_allocator_t", &object_cls,
|
||||
(class_init_t)lam_alc_init, (class_destroy_t)lam_obj_destroy};
|
||||
|
||||
void lam_alc_init(lam_allocator_t *allocator)
|
||||
{
|
||||
SUPER_INIT(allocator, &object_cls);
|
||||
allocator->alc_alloc_fn = lam_alc_malloc;
|
||||
allocator->alc_free_fn = lam_alc_free;
|
||||
allocator->alc_is_shared = 0;
|
||||
allocator->alc_mem_prot = 0;
|
||||
allocator->alc_should_pin = 0;
|
||||
allocator->alc_pinned_offset = 0;
|
||||
allocator->alc_pinned_sz = 0;
|
||||
}
|
||||
|
||||
void *lam_alg_get_chunk(size_t chunk_size, int is_shared,
|
||||
int mem_protect)
|
||||
{
|
||||
if ( !is_shared )
|
||||
return malloc(chunk_size);
|
||||
else
|
||||
{
|
||||
return lam_zero_alloc(chunk_size, mem_protect, MMAP_SHARED_FLAGS);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void *lam_alc_alloc(lam_allocator_t *allocator, size_t chunk_size)
|
||||
{
|
||||
return allocator->alc_alloc_fn(allocator, chunk_size);
|
||||
}
|
||||
|
||||
void lam_alc_free(lam_allocator_t *allocator, void *chunk_ptr)
|
||||
{
|
||||
if ( chunk_ptr )
|
||||
allocator->alc_free_fn(allocator, chunk_ptr);
|
||||
}
|
||||
|
||||
void *lam_alc_malloc(lam_allocator_t *allocator, size_t chunk_size)
|
||||
{
|
||||
return malloc(chunk_size);
|
||||
}
|
||||
|
||||
void lam_alc_default_free(lam_allocator_t *allocator, void *chunk_ptr)
|
||||
{
|
||||
if ( chunk_ptr )
|
||||
free(chunk_ptr);
|
||||
}
|
||||
|
88
src/lam/mem/allocator.h
Обычный файл
88
src/lam/mem/allocator.h
Обычный файл
@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
#ifndef ALLOCATOR_H
|
||||
#define ALLOCATOR_H
|
||||
|
||||
#include "lam/base/object.h"
|
||||
|
||||
/* This class is used to provide a generic and flexible
|
||||
way for the mem pool to allocate memory. It's meant
|
||||
to be derived for device-dependent logic, e.g. GM.
|
||||
|
||||
You should be able to share allocators, but then
|
||||
you will need to protect with a lock.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Base allocator is a wrapper for malloc
|
||||
*/
|
||||
|
||||
typedef struct lam_allocator
|
||||
{
|
||||
lam_object_t super;
|
||||
int alc_is_shared; /* indicates whether to get shared memory */
|
||||
int alc_mem_prot; /* memory protection for shared mem */
|
||||
int alc_should_pin; /* should pin memory when allocating */
|
||||
uint64_t alc_pinned_offset; /* pinned memory offset */
|
||||
uint64_t alc_pinned_sz; /* pinned mem size (may be different from alloc size. */
|
||||
void *(*alc_alloc_fn)(struct lam_allocator *, size_t);
|
||||
void (*alc_free_fn)(struct lam_allocator *, void *);
|
||||
} lam_allocator_t;
|
||||
|
||||
extern lam_class_info_t allocator_cls;
|
||||
|
||||
void lam_alc_init(lam_allocator_t *allocator);
|
||||
|
||||
void *lam_alg_get_chunk(size_t chunk_size, int is_shared,
|
||||
int mem_protect);
|
||||
|
||||
void *lam_alc_alloc(lam_allocator_t *allocator, size_t chunk_size);
|
||||
void lam_alc_free(lam_allocator_t *allocator, void *chunk_ptr);
|
||||
|
||||
static inline int lam_alc_get_is_shared(lam_allocator_t *allocator) {return allocator->alc_is_shared;}
|
||||
static inline void lam_alc_set_is_shared(lam_allocator_t *allocator, int is_shared) {allocator->alc_is_shared = is_shared;}
|
||||
|
||||
static inline int lam_alc_get_mem_prot(lam_allocator_t *allocator) {return allocator->alc_mem_prot;}
|
||||
static inline void lam_alc_set_mem_prot(lam_allocator_t *allocator, int mem_prot) {allocator->alc_mem_prot = mem_prot;}
|
||||
|
||||
static inline int lam_alc_get_should_pin(lam_allocator_t *allocator) {return allocator->alc_should_pin;}
|
||||
static inline void lam_alc_set_should_pin(lam_allocator_t *allocator, int pin) {allocator->alc_should_pin = pin;}
|
||||
|
||||
static inline uint64_t lam_alc_get_pin_offset(lam_allocator_t *allocator) {return allocator->alc_pinned_offset;}
|
||||
static inline void lam_alc_set_pin_offset(lam_allocator_t *allocator, uint64_t pin_offset)
|
||||
{allocator->alc_pinned_offset = pin_offset;}
|
||||
|
||||
static inline uint64_t lam_alc_get_pin_size(lam_allocator_t *allocator) {return allocator->alc_pinned_sz;}
|
||||
static inline void lam_alc_set_pin_size(lam_allocator_t *allocator, uint64_t pin_sz)
|
||||
{allocator->alc_pinned_sz = pin_sz;}
|
||||
|
||||
#endif /* ALLOCATOR_H */
|
||||
|
450
src/lam/mem/free_list.c
Обычный файл
450
src/lam/mem/free_list.c
Обычный файл
@ -0,0 +1,450 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
#include "lam/mem/free_list.h"
|
||||
#include "lam/os/numa.h"
|
||||
|
||||
/* private list functions */
|
||||
void lam_frl_append_nl(lam_free_list_t *flist, void *chunk, int pool_idx);
|
||||
|
||||
int lam_frl_create_more_elts(lam_free_list_t *flist, int pool_idx);
|
||||
|
||||
void *lam_frl_get_mem_chunk(lam_free_list_t *flist, int index, size_t *len, int *err);
|
||||
|
||||
int lam_frl_mem_pool_init(int nlists, long pages_per_list, ssize_t chunk_size,
|
||||
size_t page_size, long min_pages_per_list,
|
||||
long default_min_pages_per_list, long default_pages_per_list,
|
||||
long max_pages_per_list, ssize_t max_mem_in_pool);
|
||||
|
||||
lam_class_info_t free_list_cls = {"lam_free_list_t", &object_cls,
|
||||
(class_init_t)lam_frl_init, (class_destroy_t)lam_frl_destroy};
|
||||
|
||||
|
||||
void lam_frl_init(lam_free_list_t *flist)
|
||||
{
|
||||
SUPER_INIT(flist, free_list_cls.cls_parent);
|
||||
lam_mtx_init(&flist->fl_lock);
|
||||
flist->fl_pool = 0;
|
||||
flist->fl_elt_cls = 0;
|
||||
flist->fl_description = 0;
|
||||
flist->fl_free_lists = 0;
|
||||
flist->fl_is_shared = 0;
|
||||
flist->fl_nlists = 0;
|
||||
flist->fl_elt_per_chunk = 0;
|
||||
flist->fl_elt_size = 0;
|
||||
flist->fl_retry_more_resources = 0;
|
||||
flist->fl_enforce_affinity = 0;
|
||||
flist->fl_affinity = 0;
|
||||
flist->fl_threshold_grow = 0;
|
||||
flist->fl_elt_out = 0;
|
||||
flist->fl_elt_max = 0;
|
||||
flist->fl_elt_sum = 0;
|
||||
flist->fl_nevents = 0;
|
||||
flist->fl_chunks_req= 0;
|
||||
flist->fl_chunks_returned = 0;
|
||||
}
|
||||
|
||||
|
||||
void lam_frl_destroy(lam_free_list_t *flist)
|
||||
{
|
||||
int i;
|
||||
|
||||
OBJ_RELEASE(flist->fl_pool);
|
||||
for ( i = 0; i < flist->fl_nlists; i++ )
|
||||
OBJ_RELEASE(flist->fl_free_lists[i]);
|
||||
|
||||
if ( flist->fl_affinity )
|
||||
free(flist->fl_affinity);
|
||||
|
||||
if ( flist->fl_elt_out )
|
||||
free(flist->fl_elt_out);
|
||||
|
||||
if ( flist->fl_elt_max )
|
||||
free(flist->fl_elt_max);
|
||||
|
||||
if ( flist->fl_elt_sum )
|
||||
free(flist->fl_elt_sum);
|
||||
|
||||
if ( flist->fl_nevents )
|
||||
free(flist->fl_nevents);
|
||||
|
||||
if ( flist->fl_chunks_req )
|
||||
free(flist->fl_chunks_req);
|
||||
|
||||
if ( flist->fl_chunks_returned )
|
||||
free(flist->fl_chunks_returned);
|
||||
|
||||
SUPER_DESTROY(flist, free_list_cls.cls_parent);
|
||||
}
|
||||
|
||||
|
||||
int lam_frl_init_with(
|
||||
lam_free_list_t *flist,
|
||||
int nlists,
|
||||
int pages_per_list,
|
||||
size_t chunk_size,
|
||||
size_t page_size,
|
||||
size_t elt_size,
|
||||
int min_pages_per_list,
|
||||
int max_pages_per_list,
|
||||
int max_consec_req_fail,
|
||||
const char *description,
|
||||
bool_t retry_for_more_resources,
|
||||
lam_affinity_t *affinity,
|
||||
bool_t enforce_affinity,
|
||||
lam_mem_pool_t *mem_pool)
|
||||
{
|
||||
/* lam_frl_init must have been called prior to calling this function */
|
||||
size_t max_mem_in_pool;
|
||||
size_t initial_mem_per_list;
|
||||
long max_mem_per_list;
|
||||
int list,pool;
|
||||
int err;
|
||||
|
||||
flist->fl_description = description;
|
||||
flist->fl_nlists = nlists;
|
||||
|
||||
/* set up the memory pool */
|
||||
if ( mem_pool )
|
||||
{
|
||||
flist->fl_pool = mem_pool;
|
||||
OBJ_RETAIN(flist->fl_pool);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* instantiate memory pool */
|
||||
max_mem_in_pool = max_pages_per_list * page_size;
|
||||
err = lam_mp_init_with(
|
||||
flist->fl_pool,
|
||||
nlists,
|
||||
pages_per_list,
|
||||
chunk_size,
|
||||
page_size,
|
||||
min_pages_per_list,
|
||||
min_pages_per_list,
|
||||
pages_per_list,
|
||||
max_pages_per_list,
|
||||
max_mem_in_pool);
|
||||
if (err != LAM_SUCCESS)
|
||||
{
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
/* reset pool chunk size */
|
||||
chunk_size = lam_mp_get_chunk_size(flist->fl_pool);
|
||||
|
||||
/* Number of elements per chunk */
|
||||
flist->fl_elt_per_chunk = chunk_size / elt_size;
|
||||
|
||||
initial_mem_per_list = min_pages_per_list * page_size;
|
||||
|
||||
/* adjust initial_mem_per_list to increments of chunk_size */
|
||||
if ( initial_mem_per_list < chunk_size )
|
||||
{
|
||||
min_pages_per_list = (((chunk_size - 1) / page_size) + 1);
|
||||
initial_mem_per_list = min_pages_per_list * page_size;
|
||||
}
|
||||
|
||||
/* determine upper limit on number of pages in a given list */
|
||||
if ( (max_pages_per_list != -1) && (max_pages_per_list < min_pages_per_list) )
|
||||
max_pages_per_list = min_pages_per_list;
|
||||
|
||||
if (max_pages_per_list == -1)
|
||||
max_mem_per_list = -1;
|
||||
else
|
||||
max_mem_per_list = max_pages_per_list * page_size;
|
||||
|
||||
/* initialize empty lists of available descriptors */
|
||||
flist->fl_free_lists = (lam_seg_list_t **)
|
||||
malloc(sizeof(lam_seg_list_t *) *
|
||||
flist->fl_nlists);
|
||||
if ( !flist->fl_free_lists )
|
||||
{
|
||||
ulm_exit((-1, "Error: Out of memory\n"));
|
||||
}
|
||||
|
||||
/* run constructors */
|
||||
for (list = 0; list < flist->fl_nlists; list++)
|
||||
{
|
||||
if ( flist->fl_is_shared )
|
||||
{
|
||||
/* process shared memory allocation */
|
||||
flist->fl_free_lists[list] =
|
||||
(lam_seg_list_t *)
|
||||
PerProcSharedMemoryPools.getMemorySegment(
|
||||
sizeof(lam_seg_list_t), CACHE_ALIGNMENT, list);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* process private memory allocation */
|
||||
flist->fl_free_lists[list] =
|
||||
(lam_seg_list_t *)malloc(sizeof(lam_seg_list_t));
|
||||
}
|
||||
|
||||
if (!flist->fl_free_lists[list])
|
||||
ulm_exit((-1, "Error: Out of memory\n"));
|
||||
|
||||
STATIC_INIT(flist->fl_free_lists[list], &seg_list_cls);
|
||||
|
||||
lam_sgl_set_min_bytes_pushed(flist->fl_free_lists[list],
|
||||
initial_mem_per_list);
|
||||
lam_sgl_set_max_bytes_pushed(flist->fl_free_lists[list],
|
||||
max_mem_per_list);
|
||||
lam_sgl_set_max_consec_fail(flist->fl_free_lists[list],
|
||||
max_consec_req_fail);
|
||||
} /* end list loop */
|
||||
|
||||
flist->fl_retry_more_resources = retry_for_more_resources;
|
||||
flist->fl_enforce_affinity = enforce_affinity;
|
||||
if ( enforce_affinity )
|
||||
{
|
||||
flist->fl_affinity = (affinity_t *)malloc(sizeof(affinity_t) *
|
||||
flist->fl_nlists);
|
||||
if ( !flist->fl_affinity )
|
||||
ulm_exit((-1, "Error: Out of memory\n"));
|
||||
|
||||
/* copy policies in */
|
||||
for ( pool = 0; pool < flist->fl_nlists; pool++ )
|
||||
{
|
||||
flist->fl_affinity[pool] = affinity[pool];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// initialize locks for memory pool and individual list and link locks
|
||||
for ( pool = 0; pool < flist->fl_nlists; pool++ ) {
|
||||
|
||||
// gain exclusive use of list
|
||||
if ( 1 == lam_sgl_lock_list(flist->fl_free_lists[pool]) ) {
|
||||
|
||||
while ( lam_sgl_get_bytes_pushed(flist->fl_free_lists[pool])
|
||||
< lam_sgl_get_min_bytes_pushed(flist->fl_free_lists[pool]) )
|
||||
{
|
||||
if (lam_frl_create_more_elts(pool) != LAM_SUCCESS)
|
||||
{
|
||||
ulm_exit((-1, "Error: Setting up initial private "
|
||||
"free list for %s.\n", fl_description));
|
||||
}
|
||||
}
|
||||
|
||||
lam_sgl_unlock_list(flist->fl_free_lists[pool]);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* only 1 process should be initializing the list */
|
||||
ulm_exit((-1, "Error: Setting up initial private free "
|
||||
"list %d for %s.\n", pool, flist->fl_description));
|
||||
}
|
||||
}
|
||||
|
||||
return err;
|
||||
|
||||
}
|
||||
|
||||
|
||||
int lam_frl_mem_pool_init(lam_free_list_t *flist,
|
||||
int nlists, long pages_per_list, ssize_t chunk_size,
|
||||
size_t page_size, long min_pages_per_list,
|
||||
long default_min_pages_per_list, long default_pages_per_list,
|
||||
long max_pages_per_list, ssize_t max_mem_in_pool)
|
||||
{
|
||||
int err = LAM_SUCCESS;
|
||||
long total_pgs_to_alloc;
|
||||
ssize_t mem_in_pool;
|
||||
size_t to_alloc;
|
||||
|
||||
/* set chunksize - multiple of page size */
|
||||
chunk_size =
|
||||
((((chunk_size - 1) / page_size) + 1) * page_size);
|
||||
|
||||
/* determine number how much memory to allocate */
|
||||
if ( pages_per_list == -1 ) {
|
||||
/* minimum size is defaultNPagesPerList*number of local procs */
|
||||
total_pgs_to_alloc = default_pages_per_list * nlists;
|
||||
} else {
|
||||
total_pgs_to_alloc = pages_per_list * nlists;
|
||||
}
|
||||
|
||||
mem_in_pool = total_pgs_to_alloc * page_size;
|
||||
|
||||
/* Initialize memory pool */
|
||||
if ( flist->fl_is_shared ) {
|
||||
/* shared memory allocation */
|
||||
to_alloc = sizeof(lam_mem_pool_t);
|
||||
flist->fl_pool =
|
||||
(lam_mem_pool_t *)SharedMemoryPools.getMemorySegment(to_alloc, CACHE_ALIGNMENT);
|
||||
if ( flist->fl_pool )
|
||||
STATIC_INIT(flist->fl_pool, &shmem_pool_cls);
|
||||
} else {
|
||||
/* process private memory allocation */
|
||||
CREATE_OBJECT(flist->fl_pool, lam_mem_pool_t, &mem_pool_cls);
|
||||
}
|
||||
|
||||
err = lam_mp_init_with(
|
||||
flist->fl_pool,
|
||||
mem_in_pool,
|
||||
max_mem_in_pool,
|
||||
chunk_size,
|
||||
page_size);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
void *lam_frl_get_mem_chunk(lam_free_list_t *flist, int index, size_t *len, int *err)
|
||||
{
|
||||
void *chunk = 0;
|
||||
uint64_t sz_to_add;
|
||||
|
||||
/* check to make sure that the amount to add to the list does not
|
||||
exceed the amount allowed */
|
||||
sz_to_add = lam_mp_get_chunk_size(flist->fl_pool);
|
||||
|
||||
if (OPT_MEMPROFILE) {
|
||||
flist->fl_chunks_req[index]++;
|
||||
}
|
||||
|
||||
if (index >= flist->fl_nlists)
|
||||
{
|
||||
ulm_err(("Error: Array out of bounds\n"));
|
||||
return chunk;
|
||||
}
|
||||
|
||||
if ( lam_sgl_get_max_bytes_pushed(flist->fl_free_lists[index]) != -1 )
|
||||
{
|
||||
if (sz_to_add +
|
||||
lam_sgl_get_bytes_pushed(flist->fl_free_lists[index]) >
|
||||
lam_sgl_get_max_bytes_pushed(flist->fl_free_lists[index]) )
|
||||
{
|
||||
lam_sgl_inc_consec_fail(flist->fl_free_lists[index]);
|
||||
if ( lam_sgl_get_consec_fail(flist->fl_free_lists[index]) >=
|
||||
lam_sgl_get_max_consec_fail(flist->fl_free_lists[index]) )
|
||||
{
|
||||
*err = LAM_ERR_OUT_OF_RESOURCE;
|
||||
ulm_err(("Error: List out of memory in pool for %s\n",
|
||||
flist->fl_description));
|
||||
return chunk;
|
||||
} else
|
||||
*err = LAM_ERR_TEMP_OUT_OF_RESOURCE;
|
||||
|
||||
return chunk;
|
||||
}
|
||||
}
|
||||
// set len
|
||||
*len = sz_to_add;
|
||||
|
||||
|
||||
// get chunk of memory
|
||||
chunk = lam_mp_request_chunk(flist->fl_pool, index);
|
||||
if ( chunk == 0 )
|
||||
{
|
||||
// increment failure count
|
||||
lam_sgl_inc_consec_fail(flist->fl_free_lists[index]);
|
||||
if ( lam_sgl_get_consec_fail(flist->fl_free_lists[index]) >=
|
||||
lam_sgl_get_max_consec_fail(flist->fl_free_lists[index]) )
|
||||
{
|
||||
*err = LAM_ERR_OUT_OF_RESOURCE;
|
||||
ulm_err(("Error: List out of memory in pool for %s\n",
|
||||
flist->fl_description));
|
||||
return chunk;
|
||||
} else
|
||||
*err = LAM_ERR_TEMP_OUT_OF_RESOURCE;
|
||||
|
||||
return chunk;
|
||||
}
|
||||
|
||||
/* set consecutive failure count to 0 - if we fail, we don't get
|
||||
this far in the code. */
|
||||
lam_sgl_set_consec_fail(flist->fl_free_lists[index], 0);
|
||||
|
||||
if (OPT_MEMPROFILE) {
|
||||
flist->fl_chunks_returned[index]++;
|
||||
}
|
||||
|
||||
return chunk;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void lam_frl_append_nl(lam_free_list_t *flist, void *chunk, int pool_idx)
|
||||
{
|
||||
/* ASSERT: mp_chunk_sz >= fl_n_elt_per_chunk * fl_elt_size */
|
||||
// push items onto list
|
||||
lam_sgl_append_elt_chunk(flist->fl_free_lists[pool_idx],
|
||||
chunk, lam_mp_get_chunk_size(flist->fl_pool),
|
||||
flist->fl_n_elt_per_chunk, flist->fl_elt_size);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
int lam_frl_create_more_elts(lam_free_list_t *flist, int pool_idx)
|
||||
{
|
||||
int err = LAM_SUCCESS;
|
||||
size_t len_added;
|
||||
char *current_loc;
|
||||
|
||||
void *ptr = lam_frl_get_mem_chunk(flist, pool_idx, &len_added, &err);
|
||||
|
||||
if (0 == ptr ) {
|
||||
ulm_err(("Error: Can't get new elements for %s\n",
|
||||
flist->fl_description));
|
||||
return err;
|
||||
}
|
||||
|
||||
// attach memory affinity
|
||||
if ( flist->fl_enforce_affinity )
|
||||
{
|
||||
if (!lam_set_affinity(ptr, len_added,
|
||||
flist->fl_affinity[pool_idx]))
|
||||
{
|
||||
err = ULM_ERROR;
|
||||
#ifdef _DEBUGQUEUES
|
||||
ulm_err(("Error: Can't set memory policy (pool_idx=%d)\n",
|
||||
pool_idx));
|
||||
return err;
|
||||
#endif /* _DEBUGQUEUES */
|
||||
}
|
||||
}
|
||||
|
||||
/* Construct new descriptors using placement new */
|
||||
current_loc = (char *) ptr;
|
||||
for (int desc = 0; desc < flist->fl_n_elt_per_chunk; desc++)
|
||||
{
|
||||
STATIC_INIT((lam_flist_elt_t *)current_loc, flist->fl_elt_cls);
|
||||
lam_fle_set_idx(current_loc, pool_idx);
|
||||
current_loc += eleSize_m;
|
||||
}
|
||||
|
||||
/* push chunk of memory onto the list */
|
||||
lam_frl_append_nl(flist, ptr, pool_idx);
|
||||
|
||||
return err;
|
||||
}
|
128
src/lam/mem/free_list.h
Обычный файл
128
src/lam/mem/free_list.h
Обычный файл
@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
#ifndef _FREE_LIST_
|
||||
#define _FREE_LIST_
|
||||
|
||||
#include "lam/base/list.h"
|
||||
#include "lam/threads/mutex.h"
|
||||
#include "lam/mem/seg_list.h"
|
||||
#include "lam/mem/mem_pool.h"
|
||||
|
||||
/*
|
||||
* Free list element interface
|
||||
* Any item that goes into the free list must
|
||||
* inherit from this class.
|
||||
*/
|
||||
|
||||
typedef struct lam_flist_elt
|
||||
{
|
||||
lam_dbl_item_t super;
|
||||
int fle_pool_idx;
|
||||
} lam_flist_elt_t;
|
||||
|
||||
void lam_flist_elt_init(lam_flist_elt_t*);
|
||||
void lam_flist_elt_destroy(lam_flist_elt_t*);
|
||||
|
||||
#define lam_fle_get_idx(elt) (elt)->fle_pool_idx
|
||||
#define lam_fle_set_idx(elt, idx) ((elt)->fle_pool_idx = idx)
|
||||
|
||||
/*
|
||||
* Memory affinity is almost certainly an int everywhere, but let's
|
||||
* make it a typedef in case we need to make it OS dependenent
|
||||
* sometime...
|
||||
*/
|
||||
|
||||
typedef int lam_affinity_t;
|
||||
|
||||
typedef struct lam_free_list
|
||||
{
|
||||
lam_object_t super;
|
||||
lam_mutex_t fl_lock;
|
||||
int fl_is_shared;
|
||||
lam_mem_pool_t *fl_pool;
|
||||
const char *fl_description;
|
||||
int fl_nlists;
|
||||
int fl_elt_per_chunk;
|
||||
size_t fl_elt_size;
|
||||
lam_seg_list_t **fl_free_lists;
|
||||
int fl_retry_more_resources;
|
||||
int fl_enforce_affinity;
|
||||
lam_affinity_t *fl_affinity; /* array of lam_affinity_t */
|
||||
int fl_threshold_grow;
|
||||
lam_class_info_t *fl_elt_cls; /* this will be used to create new free list elements. */
|
||||
|
||||
/* for mem profiling */
|
||||
int *fl_elt_out;
|
||||
int *fl_elt_max;
|
||||
int *fl_elt_sum;
|
||||
int *fl_nevents;
|
||||
int *fl_chunks_req;
|
||||
int *fl_chunks_returned;
|
||||
} lam_free_list_t;
|
||||
|
||||
extern lam_class_info_t free_list_cls;
|
||||
|
||||
void lam_frl_init(lam_free_list_t *flist);
|
||||
void lam_frl_destroy(lam_free_list_t *flist);
|
||||
|
||||
/* lam_frl_init must have been called prior to calling this function */
|
||||
int lam_frl_init_with(lam_free_list_t *flist,
|
||||
int nlists,
|
||||
int pages_per_list,
|
||||
size_t chunk_size,
|
||||
size_t page_size,
|
||||
size_t element_size,
|
||||
int min_pages_per_list,
|
||||
int max_pages_per_list,
|
||||
int max_consec_req_fail,
|
||||
const char *description,
|
||||
bool_t retry_for_more_resources,
|
||||
lam_affinity_t *affinity,
|
||||
bool_t enforce_affinity,
|
||||
lam_mem_pool_t *pool);
|
||||
|
||||
|
||||
lam_flist_elt_t *lam_frl_get_elt(lam_free_list_t *flist, int index, int *err);
|
||||
lam_flist_elt_t *lam_frl_get_elt_nl(lam_free_list_t *flist, int index, int *err);
|
||||
|
||||
int lam_frl_return_elt(lam_free_list_t *flist, int index, lam_flist_elt_t *item);
|
||||
int lam_frl_return_elt_nl(lam_free_list_t *flist, int index, lam_flist_elt_t *item);
|
||||
|
||||
/*
|
||||
* Accessor functions
|
||||
*/
|
||||
|
||||
int lam_frl_get_thresh_grow(lam_free_list_t *flist);
|
||||
void lam_frl_set_thresh_grow(lam_free_list_t *flist, int to_grow);
|
||||
|
||||
#endif
|
||||
|
||||
|
563
src/lam/mem/mem_pool.c
Обычный файл
563
src/lam/mem/mem_pool.c
Обычный файл
@ -0,0 +1,563 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
#include <string.h>
|
||||
#include <sys/errno.h>
|
||||
#include "lam_constants.h"
|
||||
#include "lam/mem/mem_pool.h"
|
||||
#include "lam/mem/sharedmem_util.h"
|
||||
#include "lam/util/lam_log.h"
|
||||
#include "lam/util/malloc.h"
|
||||
#include "lam/os/numa.h"
|
||||
|
||||
lam_class_info_t mem_pool_cls = {"lam_mem_pool_t", &object_cls,
|
||||
(class_init_t)lam_mp_init, (class_destroy_t)lam_mp_destroy};
|
||||
|
||||
/* process-shared mem pool class */
|
||||
lam_class_info_t shmem_pool_cls = {"shmem_pool_t", &object_cls,
|
||||
(class_init_t)lam_mp_shared_init, (class_destroy_t)lam_mp_destroy};
|
||||
|
||||
void lam_mp_init(lam_mem_pool_t *pool)
|
||||
{
|
||||
SUPER_INIT(pool, mem_pool_cls.cls_parent);
|
||||
|
||||
CREATE_OBJECT(pool->mp_private_alloc, lam_allocator_t, &allocator_cls);
|
||||
lam_mtx_init(&(pool->mp_lock));
|
||||
pool->mp_dev_alloc = NULL;
|
||||
}
|
||||
|
||||
void lam_mp_shared_init(lam_mem_pool_t *pool)
|
||||
{
|
||||
SUPER_INIT(pool, shmem_pool_cls.cls_parent);
|
||||
|
||||
CREATE_OBJECT(pool->mp_private_alloc, lam_allocator_t, &allocator_cls);
|
||||
lam_mtx_init(&(pool->mp_lock));
|
||||
lam_alc_set_is_shared(pool->mp_private_alloc, 1);
|
||||
lam_alc_set_mem_prot(pool->mp_private_alloc, MMAP_SHARED_PROT);
|
||||
pool->mp_dev_alloc = NULL;
|
||||
}
|
||||
|
||||
void lam_mp_destroy(lam_mem_pool_t *pool)
|
||||
{
|
||||
if ( pool->mp_dev_alloc )
|
||||
OBJ_RELEASE(pool->mp_dev_alloc);
|
||||
OBJ_RELEASE(pool->mp_private_alloc);
|
||||
|
||||
SUPER_DESTROY(pool, &object_cls);
|
||||
}
|
||||
|
||||
int lam_mp_init_with(lam_mem_pool_t *pool, uint64_t pool_size,
|
||||
uint64_t max_len,
|
||||
uint64_t chunk_size, size_t page_size)
|
||||
{
|
||||
char *ptr = 0;
|
||||
ssize_t wrk_size = pool_size;
|
||||
void *base = 0;
|
||||
ssize_t to_alloc;
|
||||
int retval, chunk;
|
||||
|
||||
pool->mp_page_sz = page_size;
|
||||
if (((pool->mp_page_sz / getpagesize()) * getpagesize()) != pool->mp_page_sz)
|
||||
{
|
||||
return LAM_ERR_BAD_PARAM;
|
||||
}
|
||||
|
||||
pool->mp_chunk_sz = chunk_size;
|
||||
if ( !chunk_size )
|
||||
{
|
||||
return LAM_ERR_BAD_PARAM;
|
||||
}
|
||||
|
||||
/* set upper limit on pool */
|
||||
if (max_len < 0)
|
||||
{
|
||||
/* no upper limit on size */
|
||||
pool->mp_max_chunks = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
pool->mp_max_chunks = ((max_len - 1) / page_size) + 1;
|
||||
if (pool->mp_max_chunks == 0)
|
||||
{
|
||||
return LAM_ERR_BAD_PARAM;
|
||||
}
|
||||
}
|
||||
|
||||
/* round up pool size to multiple of page size */
|
||||
pool_size = ((((pool_size - 1) / chunk_size) + 1) * chunk_size);
|
||||
if (pool_size == 0) {
|
||||
lam_err(("Error: pool_size == 0\n"));
|
||||
return LAM_ERR_BAD_PARAM;
|
||||
}
|
||||
|
||||
if (pool_size < chunk_size) {
|
||||
lam_err(("Error: pool_size < chunk_size\n"));
|
||||
return LAM_ERR_BAD_PARAM;
|
||||
}
|
||||
|
||||
/* add red-zone pages */
|
||||
|
||||
/* set up dev allocator to use pinned memory */
|
||||
lam_alc_set_should_pin(pool->mp_dev_alloc, 1);
|
||||
lam_alc_set_pin_offset(pool->mp_dev_alloc, page_size);
|
||||
|
||||
while (!ptr && wrk_size) {
|
||||
to_alloc = wrk_size + 2 * page_size;
|
||||
|
||||
/* allocate memory. Reset pinned memory size. */
|
||||
lam_alc_set_pin_size(pool->mp_dev_alloc, wrk_size);
|
||||
ptr = lam_alc_alloc(pool->mp_dev_alloc, to_alloc);
|
||||
if (ptr == 0)
|
||||
wrk_size /= 2;
|
||||
else
|
||||
{
|
||||
base = ptr + page_size;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* reset pool size */
|
||||
pool_size = wrk_size;
|
||||
pool->mp_num_chunks = ((pool_size - 1) / chunk_size) + 1;
|
||||
if ((pool->mp_num_chunks > pool->mp_max_chunks) && (pool->mp_max_chunks > 0))
|
||||
{
|
||||
lam_err(("Error: NPoolChunks (%ld) > maxNPoolChunks (%ld)\n",
|
||||
pool->mp_num_chunks, pool->mp_max_chunks));
|
||||
return LAM_ERR_BAD_PARAM;
|
||||
}
|
||||
/* change memory protection for red zones */
|
||||
retval = mprotect(ptr, page_size, PROT_NONE);
|
||||
if (retval != 0)
|
||||
{
|
||||
lam_exit((-1, "Error in red zone 1 mprotect\n"));
|
||||
}
|
||||
/* end red zone */
|
||||
retval =
|
||||
mprotect(ptr + page_size + wrk_size, page_size, PROT_NONE);
|
||||
if (retval != 0)
|
||||
{
|
||||
lam_exit((-1, "Error in red zone 2 mprotect\n"));
|
||||
}
|
||||
|
||||
/* initialize chunk descriptors */
|
||||
to_alloc = sizeof(lam_chunk_desc_t) * pool->mp_num_chunks;
|
||||
pool->mp_chunks = lam_alc_alloc(pool->mp_private_alloc, to_alloc);
|
||||
if ( !pool->mp_chunks )
|
||||
{
|
||||
lam_err(("Error: Out of memory\n"));
|
||||
return LAM_ERROR;
|
||||
}
|
||||
|
||||
ptr = (char *) base;
|
||||
for ( chunk = 0; chunk < pool->mp_num_chunks; chunk++ )
|
||||
{
|
||||
pool->mp_chunks[chunk].chd_flags = ALLOCELEMENT_FLAG_AVAILABLE;
|
||||
pool->mp_chunks[chunk].chd_index = -1;
|
||||
pool->mp_chunks[chunk].chd_base_ptr = ptr;
|
||||
ptr += chunk_size;
|
||||
}
|
||||
// set next available chunk
|
||||
pool->mp_next_avail_chunk = 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
void *lam_mp_request_chunk(lam_mem_pool_t *pool, int pool_index)
|
||||
{
|
||||
void *chunk = 0;
|
||||
int chunk_found;
|
||||
int next_chunk_to_use;
|
||||
lam_chunk_desc_t *chunk_desc;
|
||||
size_t to_alloc;
|
||||
int desc;
|
||||
|
||||
// grab lock on pool
|
||||
lam_mtx_lock(&(pool->mp_lock));
|
||||
|
||||
// Have we used all the allocated memory ?
|
||||
if ( pool->mp_next_avail_chunk == pool->mp_num_chunks )
|
||||
{
|
||||
|
||||
/* can we increase the pool size ? We currently won't grow a shared
|
||||
memory region. */
|
||||
if ( lam_mp_uses_shared_mem(pool) ||
|
||||
((pool->mp_max_chunks > 0) && (pool->mp_num_chunks == pool->mp_max_chunks)) )
|
||||
{
|
||||
lam_mtx_unlock(&(pool->mp_lock));
|
||||
return chunk;
|
||||
}
|
||||
|
||||
/* allocate larger array of chunk descriptors and
|
||||
copy old array into new array */
|
||||
to_alloc = sizeof(lam_chunk_desc_t) * (pool->mp_num_chunks + 1);
|
||||
chunk_desc = lam_alc_alloc(pool->mp_private_alloc, to_alloc);
|
||||
if ( !chunk_desc )
|
||||
{
|
||||
lam_err(("Error! Out of memory!\n"));
|
||||
lam_mtx_unlock(&(pool->mp_lock));
|
||||
return 0;
|
||||
}
|
||||
|
||||
for ( desc = 0; desc < pool->mp_num_chunks; desc++ ) {
|
||||
chunk_desc[desc] = pool->mp_chunks[desc];
|
||||
}
|
||||
|
||||
/* free old array and set old array pointer to point to new array */
|
||||
lam_alc_free(pool->mp_private_alloc, pool->mp_chunks);
|
||||
pool->mp_chunks = chunk_desc;
|
||||
|
||||
/* allocate new memory chunk using device allocator. */
|
||||
lam_alc_set_should_pin(pool->mp_dev_alloc, 1);
|
||||
lam_alc_set_pin_offset(pool->mp_dev_alloc, 0);
|
||||
lam_alc_set_pin_size(pool->mp_dev_alloc, 0);
|
||||
|
||||
pool->mp_chunks[pool->mp_num_chunks].chd_base_ptr =
|
||||
lam_alc_alloc(pool->mp_dev_alloc, pool->mp_chunk_sz);
|
||||
if ( !pool->mp_chunks[pool->mp_num_chunks].chd_base_ptr )
|
||||
{
|
||||
lam_err(("Error: Out of memory\n"));
|
||||
lam_mtx_unlock(&(pool->mp_lock));
|
||||
return chunk;
|
||||
}
|
||||
|
||||
// reset pool chunk counter
|
||||
pool->mp_num_chunks++;
|
||||
}
|
||||
|
||||
/* grab chunk */
|
||||
chunk = pool->mp_chunks[pool->mp_next_avail_chunk].chd_base_ptr;
|
||||
pool->mp_chunks[pool->mp_next_avail_chunk].chd_flags = ALLOCELEMENT_FLAG_INUSE;
|
||||
pool->mp_chunks[pool->mp_next_avail_chunk].chd_index = pool_index;
|
||||
|
||||
/* find next available chunk */
|
||||
chunk_found = 0;
|
||||
next_chunk_to_use = pool->mp_next_avail_chunk + 1;
|
||||
while ( next_chunk_to_use < pool->mp_num_chunks )
|
||||
{
|
||||
if ( pool->mp_chunks[next_chunk_to_use].chd_flags ==
|
||||
ALLOCELEMENT_FLAG_AVAILABLE )
|
||||
{
|
||||
pool->mp_next_avail_chunk = next_chunk_to_use;
|
||||
chunk_found = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
next_chunk_to_use++;
|
||||
}
|
||||
|
||||
/* if no chunks available set next chunk past end of list so that next
|
||||
time around more memory will be allocated */
|
||||
if ( !chunk_found ) {
|
||||
pool->mp_next_avail_chunk = pool->mp_num_chunks;
|
||||
}
|
||||
|
||||
lam_mtx_unlock(&(pool->mp_lock));
|
||||
|
||||
return chunk;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Fixed shared mem pool interface
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
lam_class_info_t fixed_mem_pool_cls = {"lam_fixed_mpool_t", &object_cls,
|
||||
(class_init_t)lam_fmp_init, (class_destroy_t)lam_fmp_destroy};
|
||||
|
||||
void lam_fmp_init(lam_fixed_mpool_t *pool)
|
||||
{
|
||||
SUPER_INIT(pool, &object_cls);
|
||||
|
||||
CREATE_OBJECT(pool->fmp_private_alloc, lam_allocator_t, &allocator_cls);
|
||||
lam_alc_set_is_shared(pool->fmp_private_alloc, 1);
|
||||
lam_alc_set_mem_prot(pool->fmp_private_alloc, MMAP_SHARED_PROT);
|
||||
|
||||
pool->fmp_segments = NULL;
|
||||
pool->fmp_n_segments = NULL;
|
||||
pool->fmp_n_segs_in_array = NULL;
|
||||
pool->fmp_min_alloc_size = 0;
|
||||
pool->fmp_n_elts_to_add = 0;
|
||||
pool->fmp_n_pools = 0;
|
||||
pool->fmp_pool_ok_to_use = 0;
|
||||
pool->fmp_apply_affinity = 0;
|
||||
}
|
||||
|
||||
void lam_fmp_destroy(lam_fixed_mpool_t *pool)
|
||||
{
|
||||
int i;
|
||||
|
||||
if ( pool->fmp_segments )
|
||||
{
|
||||
for ( i = 0; i < pool->fmp_n_pools; i++ )
|
||||
OBJ_RELEASE(pool->fmp_segments[i]);
|
||||
free(pool->fmp_segments);
|
||||
}
|
||||
|
||||
if ( pool->fmp_n_segments )
|
||||
free(pool->fmp_n_segments);
|
||||
|
||||
if ( pool->fmp_n_segs_in_array )
|
||||
free(pool->fmp_n_segs_in_array);
|
||||
|
||||
SUPER_DESTROY(pool, &object_cls);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int lam_fmp_init_with(lam_fixed_mpool_t *pool, ssize_t initial_allocation,
|
||||
ssize_t min_allocation_size,
|
||||
int n_pools, int n_array_elements_to_add, int apply_mem_affinity)
|
||||
{
|
||||
int pool_idx;
|
||||
void *ptr;
|
||||
|
||||
pool->fmp_pool_ok_to_use = 1;
|
||||
pool->fmp_apply_affinity = apply_mem_affinity;
|
||||
pool->fmp_min_alloc_size = min_allocation_size;
|
||||
if (pool->fmp_min_alloc_size < (ssize_t)getpagesize())
|
||||
pool->fmp_min_alloc_size = getpagesize();
|
||||
pool->fmp_n_elts_to_add = n_array_elements_to_add;
|
||||
pool->fmp_n_pools = n_pools;
|
||||
pool->fmp_segments = (lam_memseg_t **)lam_malloc(sizeof(lam_memseg_t *)*n_pools);
|
||||
if ( !pool->fmp_segments )
|
||||
{
|
||||
lam_exit((-1,
|
||||
"Unable to allocate memory for "
|
||||
"pool->fmp_segments, requested %ld bytes, errno %d\n",
|
||||
sizeof(int) * n_pools, errno));
|
||||
}
|
||||
bzero(pool->fmp_segments, sizeof(lam_memseg_t *)*n_pools);
|
||||
|
||||
pool->fmp_n_segs_in_array = (int *) lam_malloc(sizeof(int) * n_pools);
|
||||
if ( !pool->fmp_n_segs_in_array ) {
|
||||
lam_exit((-1,
|
||||
"Unable to allocate memory for "
|
||||
"pool->fmp_n_segs_in_array, requested %ld bytes, errno %d\n",
|
||||
sizeof(int) * n_pools, errno));
|
||||
}
|
||||
bzero(pool->fmp_n_segs_in_array, sizeof(int) * n_pools);
|
||||
|
||||
for ( pool_idx = 0; pool_idx < n_pools; pool_idx++ )
|
||||
{
|
||||
|
||||
ptr = lam_zero_alloc(initial_allocation, MMAP_SHARED_PROT,
|
||||
MMAP_SHARED_FLAGS);
|
||||
if ( !ptr ) {
|
||||
lam_exit((-1,
|
||||
"Unable to allocate "
|
||||
"memory pool , requested %ld, errno %d\n",
|
||||
initial_allocation, errno));
|
||||
}
|
||||
|
||||
if ( apply_mem_affinity )
|
||||
{
|
||||
if (!lam_set_affinity(ptr, initial_allocation, pool_idx))
|
||||
{
|
||||
lam_exit((-1, "Error: setting memory affinity\n"));
|
||||
}
|
||||
}
|
||||
|
||||
/* set lam_memseg_t data */
|
||||
pool->fmp_segments[pool_idx][0].ms_base_ptr = ptr;
|
||||
pool->fmp_segments[pool_idx][0].ms_current_ptr = ptr;
|
||||
pool->fmp_segments[pool_idx][0].ms_length = initial_allocation;
|
||||
pool->fmp_segments[pool_idx][0].ms_mem_available = initial_allocation;
|
||||
|
||||
// update the number of elements in use
|
||||
pool->fmp_n_segments[pool_idx] = 1;
|
||||
|
||||
} /* end pool loop */
|
||||
|
||||
return LAM_SUCCESS;
|
||||
}
|
||||
|
||||
void *lam_fmp_get_mem_segment(lam_fixed_mpool_t *pool,
|
||||
size_t length, size_t alignment, int which_pool)
|
||||
{
|
||||
void *segment = NULL;
|
||||
size_t mask;
|
||||
int idx, seg_idx;
|
||||
ssize_t len_to_alloc;
|
||||
char *ptr;
|
||||
lam_memseg_t *tmp_seg;
|
||||
|
||||
/* return if pool can't be used */
|
||||
if ( !pool->fmp_pool_ok_to_use )
|
||||
return NULL;
|
||||
|
||||
/* get the appropriate mask for the alignment */
|
||||
mask = ~(alignment - 1);
|
||||
|
||||
/* loop over pool->fmp_segments elements to see if available memory
|
||||
exists */
|
||||
idx = -1;
|
||||
len_to_alloc = length;
|
||||
for ( seg_idx = 0; seg_idx < pool->fmp_n_segments[which_pool];
|
||||
seg_idx++ )
|
||||
{
|
||||
|
||||
ptr =
|
||||
(char *) pool->fmp_segments[which_pool][seg_idx].ms_current_ptr;
|
||||
|
||||
/* check to see if pointer is aligned correctly */
|
||||
if ( (((size_t) ptr) & mask) == ((size_t) ptr) )
|
||||
{
|
||||
segment = ptr;
|
||||
len_to_alloc = length;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* align the pointer */
|
||||
ptr = (char *) ((size_t) ptr + alignment);
|
||||
ptr = (char *) ((size_t) ptr & mask);
|
||||
|
||||
len_to_alloc = length +
|
||||
(ptr - (char *) pool->fmp_segments[which_pool][seg_idx].ms_current_ptr);
|
||||
|
||||
/* continue if not enough memory in this segment */
|
||||
if (len_to_alloc >
|
||||
pool->fmp_segments[which_pool][seg_idx].ms_mem_available) {
|
||||
continue;
|
||||
}
|
||||
segment = ptr;
|
||||
}
|
||||
|
||||
if (pool->fmp_segments[which_pool][seg_idx].ms_mem_available >=
|
||||
len_to_alloc)
|
||||
{
|
||||
idx = seg_idx;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* if no available memory exists - get more memory */
|
||||
if ( idx < 0 )
|
||||
{
|
||||
/* if need be, increase the size of pool->fmp_segments[] */
|
||||
if (pool->fmp_n_segments[which_pool] ==
|
||||
pool->fmp_n_segs_in_array[which_pool])
|
||||
{
|
||||
/* create a temp version of pool->fmp_segments[] */
|
||||
tmp_seg = (lam_memseg_t *)
|
||||
lam_malloc(sizeof(lam_memseg_t) *
|
||||
(pool->fmp_n_segments[which_pool] +
|
||||
pool->fmp_n_elts_to_add));
|
||||
if ( !tmp_seg ) {
|
||||
lam_exit((-1, "Unable to "
|
||||
"allocate memory for tmp_seg, errno %d\n",
|
||||
errno));
|
||||
}
|
||||
/* copy old version of pool->fmp_segments to tmp copy */
|
||||
for (seg_idx = 0; seg_idx < pool->fmp_n_segments[which_pool]; seg_idx++)
|
||||
{
|
||||
tmp_seg[seg_idx].ms_base_ptr =
|
||||
pool->fmp_segments[which_pool][seg_idx].ms_base_ptr;
|
||||
tmp_seg[seg_idx].ms_current_ptr =
|
||||
pool->fmp_segments[which_pool][seg_idx].ms_current_ptr;
|
||||
tmp_seg[seg_idx].ms_length =
|
||||
pool->fmp_segments[which_pool][seg_idx].ms_length;
|
||||
tmp_seg[seg_idx].ms_mem_available =
|
||||
pool->fmp_segments[which_pool][seg_idx].ms_mem_available;
|
||||
}
|
||||
|
||||
lam_free(pool->fmp_segments[which_pool]);
|
||||
pool->fmp_segments[which_pool] = tmp_seg;
|
||||
|
||||
/* set the element of pool->fmp_segments to grab */
|
||||
pool->fmp_n_segs_in_array[which_pool] += pool->fmp_n_elts_to_add;
|
||||
|
||||
} /* end increase size of pool->fmp_segments[] */
|
||||
|
||||
idx = pool->fmp_n_segments[which_pool];
|
||||
|
||||
/* allocate more memory */
|
||||
len_to_alloc = 4 * (length + alignment);
|
||||
if (len_to_alloc < pool->fmp_min_alloc_size)
|
||||
len_to_alloc = 2 * pool->fmp_min_alloc_size;
|
||||
void *tmp_ptr =
|
||||
lam_zero_alloc(len_to_alloc, MMAP_SHARED_PROT, MMAP_SHARED_FLAGS);
|
||||
if ( !tmp_ptr )
|
||||
{
|
||||
lam_exit((-1, "Unable to "
|
||||
"allocate memory pool\n"));
|
||||
}
|
||||
|
||||
if ( pool->fmp_apply_affinity )
|
||||
{
|
||||
if ( !lam_set_affinity(tmp_ptr, len_to_alloc, which_pool) )
|
||||
lam_exit((-1, "Error: setting memory affinity\n"));
|
||||
}
|
||||
|
||||
/* fill in pool->fmp_segments */
|
||||
pool->fmp_segments[which_pool][idx].ms_base_ptr = tmp_ptr;
|
||||
pool->fmp_segments[which_pool][idx].ms_current_ptr = tmp_ptr;
|
||||
pool->fmp_segments[which_pool][idx].ms_length =
|
||||
len_to_alloc;
|
||||
pool->fmp_segments[which_pool][idx].ms_mem_available =
|
||||
len_to_alloc;
|
||||
|
||||
pool->fmp_n_segments[which_pool]++;
|
||||
|
||||
/* set pointer and length */
|
||||
ptr =
|
||||
(char *) pool->fmp_segments[which_pool][idx].ms_current_ptr;
|
||||
/* check to see if pointer is aligned correctly */
|
||||
if ((((size_t) ptr) & mask) == ((size_t) ptr)) {
|
||||
segment = ptr;
|
||||
len_to_alloc = length;
|
||||
} else {
|
||||
|
||||
/* align the pointer */
|
||||
ptr = (char *) ((size_t) ptr + alignment);
|
||||
ptr = (char *) ((size_t) ptr & mask);
|
||||
|
||||
segment = ptr;
|
||||
len_to_alloc = length +
|
||||
(ptr -
|
||||
(char *) pool->fmp_segments[which_pool][idx].
|
||||
ms_current_ptr);
|
||||
}
|
||||
|
||||
} /* end " idx < 0 " */
|
||||
|
||||
/* update pool->fmp_segments */
|
||||
pool->fmp_segments[which_pool][idx].ms_current_ptr = (void *)
|
||||
((char *) (pool->fmp_segments[which_pool][idx].ms_current_ptr) +
|
||||
len_to_alloc);
|
||||
|
||||
pool->fmp_segments[which_pool][idx].ms_mem_available -=
|
||||
len_to_alloc;
|
||||
|
||||
return segment;
|
||||
}
|
161
src/lam/mem/mem_pool.h
Обычный файл
161
src/lam/mem/mem_pool.h
Обычный файл
@ -0,0 +1,161 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
#ifndef _MEMORY_POOL_
|
||||
#define _MEMORY_POOL_
|
||||
|
||||
#include "lam_types.h"
|
||||
#include "lam/base/object.h"
|
||||
#include "lam/mem/allocator.h"
|
||||
#include "lam/threads/mutex.h"
|
||||
|
||||
#define ALLOCELEMENT_FLAG_UNUSABLE (0)
|
||||
#define ALLOCELEMENT_FLAG_AVAILABLE (1)
|
||||
#define ALLOCELEMENT_FLAG_INUSE (2)
|
||||
#define ALLOCELEMENT_FLAG_NEVERFREE (4)
|
||||
#define ALLOCELEMENT_FLAG_LOANED (8)
|
||||
|
||||
/*
|
||||
To create a process-private pool, use
|
||||
CREATE_OBJECT(pool, lam_mem_pool_t, &mem_pool_cls);
|
||||
|
||||
To create a process-shared pool, use
|
||||
CREATE_OBJECT(pool, lam_mem_pool_t, &shmem_pool_cls);
|
||||
*/
|
||||
|
||||
typedef struct lam_chunk_desc
|
||||
{
|
||||
uint16_t chd_flags;
|
||||
uint32_t chd_index;
|
||||
void *chd_base_ptr;
|
||||
} lam_chunk_desc_t;
|
||||
|
||||
typedef struct lam_mem_pool
|
||||
{
|
||||
lam_object_t super;
|
||||
lam_allocator_t *mp_dev_alloc; /* possibly device-dependent allocator for registering memory */
|
||||
lam_allocator_t *mp_private_alloc; /* for use by pool only; do not set! */
|
||||
lam_mutex_t mp_lock;
|
||||
uint64_t mp_page_sz;
|
||||
uint64_t mp_chunk_sz;
|
||||
uint32_t mp_num_chunks;
|
||||
uint32_t mp_max_chunks;
|
||||
uint32_t mp_next_avail_chunk;
|
||||
lam_chunk_desc_t *mp_chunks;
|
||||
} lam_mem_pool_t;
|
||||
|
||||
/* process-private mem pool class */
|
||||
extern lam_class_info_t mem_pool_cls;
|
||||
|
||||
/* process-shared mem pool class */
|
||||
extern lam_class_info_t shmem_pool_cls;
|
||||
|
||||
void lam_mp_init(lam_mem_pool_t *pool);
|
||||
void lam_mp_shared_init(lam_mem_pool_t *pool);
|
||||
void lam_mp_destroy(lam_mem_pool_t *pool);
|
||||
|
||||
int lam_mp_init_with(lam_mem_pool_t *pool, uint64_t pool_size,
|
||||
uint64_t max_len,
|
||||
uint64_t chunk_size, size_t pg_size);
|
||||
|
||||
void *lam_mp_request_chunk(lam_mem_pool_t *pool, int pool_index);
|
||||
|
||||
/*
|
||||
*
|
||||
* Memory Pool accessor functions
|
||||
*
|
||||
*/
|
||||
|
||||
/* returns 1 if pool uses shared memory, 0 otherwise. */
|
||||
#define lam_mp_uses_shared_mem(pool) \
|
||||
lam_alc_get_is_shared(pool->mp_private_alloc)
|
||||
|
||||
#define lam_mp_get_dev_allocator(pool) \
|
||||
((pool)->mp_dev_alloc)
|
||||
|
||||
static inline void lam_mp_set_dev_allocator(lam_mem_pool_t *pool, lam_allocator_t *allocator)
|
||||
{
|
||||
/* releases old allocator and retains new one. */
|
||||
if ( pool->mp_dev_alloc )
|
||||
OBJ_RELEASE(pool->mp_dev_alloc);
|
||||
pool->mp_dev_alloc = allocator;
|
||||
OBJ_RETAIN(pool->mp_dev_alloc);
|
||||
}
|
||||
|
||||
#define lam_mp_get_chunk_size(pool) \
|
||||
((pool)->mp_chunk_sz)
|
||||
|
||||
/*
|
||||
*
|
||||
* Fixed shared mem pool interface
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
Class used to satisfy shared memory requests. Assumes that request
|
||||
are made before the child process are forked, and that this memory
|
||||
will not be recycled or freed until the app exits.
|
||||
*/
|
||||
|
||||
typedef struct lam_mem_segment
|
||||
{
|
||||
void *ms_base_ptr;
|
||||
void *ms_current_ptr;
|
||||
size_t ms_length;
|
||||
size_t ms_mem_available;
|
||||
} lam_memseg_t;
|
||||
|
||||
|
||||
typedef struct lam_fixed_mpool
|
||||
{
|
||||
lam_object_t super;
|
||||
lam_allocator_t *fmp_private_alloc;
|
||||
lam_memseg_t **fmp_segments;
|
||||
int *fmp_n_segments;
|
||||
int *fmp_n_segs_in_array;
|
||||
size_t fmp_min_alloc_size;
|
||||
int fmp_n_elts_to_add;
|
||||
int fmp_n_pools;
|
||||
int fmp_pool_ok_to_use;
|
||||
int fmp_apply_affinity;
|
||||
} lam_fixed_mpool_t;
|
||||
|
||||
extern lam_class_info_t fixed_mem_pool_cls;
|
||||
|
||||
void lam_fmp_init(lam_fixed_mpool_t *pool);
|
||||
void lam_fmp_destroy(lam_fixed_mpool_t *pool);
|
||||
int lam_fmp_init_with(lam_fixed_mpool_t *pool, ssize_t initial_allocation,
|
||||
ssize_t min_allocation_size,
|
||||
int n_pools, int n_array_elements_to_add, int apply_mem_affinity);
|
||||
void *lam_fmp_get_mem_segment(lam_fixed_mpool_t *pool,
|
||||
size_t length, size_t align, int which_pool);
|
||||
|
||||
#endif
|
||||
|
76
src/lam/mem/seg_list.c
Обычный файл
76
src/lam/mem/seg_list.c
Обычный файл
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
#include "lam/mem/seg_list.h"
|
||||
|
||||
lam_class_info_t seg_list_cls = {"lam_seg_list_t", &object_cls,
|
||||
(class_init_t)lam_sgl_init, (class_destroy_t)lam_sgl_destroy};
|
||||
|
||||
void lam_sgl_init(lam_seg_list_t *slist)
|
||||
{
|
||||
SUPER_INIT(slist, seg_list_cls.cls_parent);
|
||||
lam_dbl_list_init(&slist->sgl_list);
|
||||
lam_mtx_init(&slist->sgl_lock);
|
||||
slist->sgl_min_bytes_pushed = 0;
|
||||
slist->sgl_max_bytes_pushed = 0;
|
||||
slist->sgl_bytes_pushed = 0;
|
||||
slist->sgl_max_consec_fail = 0;
|
||||
slist->sgl_consec_fail = 0;
|
||||
}
|
||||
|
||||
void lam_sgl_destroy(lam_seg_list_t *slist)
|
||||
{
|
||||
lam_dbl_empty_list(&(slist->sgl_list));
|
||||
SUPER_DESTROY(slist, seg_list_cls.cls_parent);
|
||||
}
|
||||
|
||||
|
||||
void lam_sgl_append_elt_chunk(
|
||||
lam_seg_list_t *slist,
|
||||
void *chunk,
|
||||
size_t chunk_size,
|
||||
int n_elts,
|
||||
size_t elt_size)
|
||||
{
|
||||
/* Since this function could be called frequently, we do not
|
||||
want to compute the number of elements each time, so we
|
||||
require it to be passed as an arg.
|
||||
*/
|
||||
int i;
|
||||
char *ptr;
|
||||
|
||||
ptr = (char *)chunk;
|
||||
slist->sgl_bytes_pushed += chunk_size;
|
||||
for ( i = 0; i < n_elts; i++ )
|
||||
{
|
||||
lam_dbl_append(&(slist->sgl_list), (lam_dbl_item_t *)ptr);
|
||||
ptr += elt_size;
|
||||
}
|
||||
}
|
106
src/lam/mem/seg_list.h
Обычный файл
106
src/lam/mem/seg_list.h
Обычный файл
@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
#ifndef SEG_LIST_H
|
||||
#define SEG_LIST_H
|
||||
|
||||
#include "lam/base/list.h"
|
||||
#include "lam/threads/mutex.h"
|
||||
|
||||
typedef struct lam_seg_list
|
||||
{
|
||||
lam_object_t super;
|
||||
size_t sgl_min_bytes_pushed;
|
||||
size_t sgl_max_bytes_pushed;
|
||||
size_t sgl_bytes_pushed;
|
||||
int sgl_max_consec_fail;
|
||||
int sgl_consec_fail;
|
||||
lam_mutex_t sgl_lock;
|
||||
lam_dbl_list_t sgl_list;
|
||||
} lam_seg_list_t;
|
||||
|
||||
extern lam_class_info_t seg_list_cls;
|
||||
|
||||
void lam_sgl_init(lam_seg_list_t *slist);
|
||||
void lam_sgl_destroy(lam_seg_list_t *slist);
|
||||
void lam_sgl_append_elt_chunk(
|
||||
lam_seg_list_t *slist,
|
||||
void *chunk,
|
||||
size_t chunk_size,
|
||||
int n_elts,
|
||||
size_t elt_size);
|
||||
|
||||
/*
|
||||
*
|
||||
* Segment list accessor functions
|
||||
*
|
||||
*/
|
||||
|
||||
#define lam_sgl_lock_list(slist) lam_mtx_trylock(&slist->sgl_lock)
|
||||
#define lam_sgl_unlock_list(slist) lam_mtx_unlock(&slist->sgl_lock)
|
||||
|
||||
static inline int lam_sgl_is_locked(lam_seg_list_t *slist)
|
||||
{
|
||||
/* returns 1 if list is currently locked, otherwise 0. */
|
||||
int ret;
|
||||
|
||||
ret = lam_mtx_trylock(&slist->sgl_lock);
|
||||
if ( !ret )
|
||||
lam_mtx_unlock(&slist->sgl_lock);
|
||||
return !ret;
|
||||
}
|
||||
|
||||
#define lam_sgl_get_min_bytes_pushed(slist) ((slist)->sgl_min_bytes_pushed)
|
||||
#define lam_sgl_set_min_bytes_pushed(slist, min_bytes) \
|
||||
((slist)->sgl_min_bytes_pushed = min_bytes)
|
||||
|
||||
#define lam_sgl_get_max_bytes_pushed(slist) ((slist)->sgl_max_bytes_pushed)
|
||||
#define lam_sgl_set_max_bytes_pushed(slist, min_bytes) \
|
||||
((slist)->sgl_max_bytes_pushed = min_bytes)
|
||||
|
||||
#define lam_sgl_get_bytes_pushed(slist) ((slist)->sgl_bytes_pushed)
|
||||
#define lam_sgl_set_bytes_pushed(slist, min_bytes) \
|
||||
((slist)->sgl_bytes_pushed = min_bytes)
|
||||
|
||||
#define lam_sgl_get_max_consec_fail(slist) ((slist)->sgl_max_consec_fail)
|
||||
#define lam_sgl_set_max_consec_fail(slist, max_fail) \
|
||||
((slist)->sgl_max_consec_fail = max_fail)
|
||||
|
||||
#define lam_sgl_get_consec_fail(slist) ((slist)->sgl_consec_fail)
|
||||
#define lam_sgl_set_consec_fail(slist, fail) \
|
||||
((slist)->sgl_consec_fail = fail)
|
||||
|
||||
#define lam_sgl_inc_consec_fail(slist) \
|
||||
((slist)->sgl_consec_fail++)
|
||||
|
||||
#endif /* SEG_LIST_H */
|
||||
|
||||
|
||||
|
124
src/lam/mem/sharedmem_util.c
Обычный файл
124
src/lam/mem/sharedmem_util.c
Обычный файл
@ -0,0 +1,124 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/stat.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "lam/mem/sharedmem_util.h"
|
||||
#include "lam/util/lam_log.h"
|
||||
|
||||
void *lam_zero_alloc(size_t len, int mem_prot, int mem_flags)
|
||||
{
|
||||
void *ptr;
|
||||
int fd, flags = mem_flags;
|
||||
#ifndef __osf__
|
||||
fd = -1;
|
||||
|
||||
#ifndef __APPLE__
|
||||
fd = open("/dev/zero", O_RDWR);
|
||||
if (fd < 0)
|
||||
{
|
||||
perror("/dev/zero");
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
flags = flags | MAP_ANON;
|
||||
#endif /* __APPLE__ */
|
||||
|
||||
ptr = mmap(NULL, len, mem_prot, flags, fd, 0);
|
||||
if ( ptr == MAP_FAILED )
|
||||
{
|
||||
lam_err(("Error: mmap failed (%s)\n", strerror(errno)));
|
||||
close(fd);
|
||||
return (void *)0;
|
||||
}
|
||||
close(fd);
|
||||
|
||||
#else /* this is __osf__ */
|
||||
|
||||
if( mem_flags & MAP_PRIVATE ) {
|
||||
//
|
||||
// private memory allocation
|
||||
//
|
||||
fd = open("/dev/zero", O_RDWR);
|
||||
if (fd < 0)
|
||||
{
|
||||
perror("/dev/zero");
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
ptr = mmap(NULL, len, mem_prot, mem_flags, fd, 0);
|
||||
if ( ptr == MAP_FAILED )
|
||||
{
|
||||
fprintf(stderr,
|
||||
" ZeroAlloc :: error in mmap(\"/dev/zero\") call. Bytes Allocated :: %ld\n", len);
|
||||
fprintf(stderr, " errno :: %d\n", errno);
|
||||
perror(" mmap failed");
|
||||
close(fd);
|
||||
return (void *)0;
|
||||
}
|
||||
close(fd);
|
||||
} else {
|
||||
long pageSize = sysconf(_SC_PAGESIZE);
|
||||
long long paddedLen = len + (2 * pageSize);
|
||||
ptr = ulm_malloc(paddedLen * sizeof(char));
|
||||
if (!ptr) {
|
||||
ulm_warn(("ZeroAlloc :: padded ulm_malloc() failed for "
|
||||
"%lld bytes\n", paddedLen));
|
||||
return (void *)0;
|
||||
}
|
||||
memset(ptr, 0, paddedLen * sizeof(char));
|
||||
ptr = (char *)ptr + (pageSize - 1);
|
||||
ptr = (void *)((long)ptr & ~(pageSize - 1));
|
||||
//
|
||||
// shared memory allocation
|
||||
//
|
||||
fd = -1;
|
||||
ptr = mmap(ptr, len, mem_prot, MAP_FIXED | mem_flags, fd, 0);
|
||||
|
||||
if ( ptr == MAP_FAILED )
|
||||
{
|
||||
ulm_warn(("ZeroAlloc shared mmap error :: %d fd %d\n", errno, fd));
|
||||
perror(" mmap failed");
|
||||
return (void *)0;
|
||||
}
|
||||
} // end memory allocation
|
||||
#endif /* __osf__ */
|
||||
|
||||
return ptr;
|
||||
}
|
50
src/lam/mem/sharedmem_util.h
Обычный файл
50
src/lam/mem/sharedmem_util.h
Обычный файл
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
#ifndef SHAREDMEM_UTIL_H
|
||||
#define SHAREDMEM_UTIL_H
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#define MMAP_SHARED_PROT PROT_READ|PROT_WRITE
|
||||
#define MMAP_PRIVATE_PROT PROT_READ|PROT_WRITE
|
||||
#define MMAP_PRIVATE_FLAGS MAP_PRIVATE
|
||||
|
||||
#ifndef __osf__
|
||||
# define MMAP_SHARED_FLAGS MAP_SHARED
|
||||
#else
|
||||
# define MMAP_SHARED_FLAGS MAP_SHARED|MAP_ANONYMOUS
|
||||
#endif
|
||||
|
||||
void *lam_zero_alloc(size_t len, int mem_prot, int mem_flags);
|
||||
|
||||
#endif /* SHAREDMEM_UTIL_H */
|
||||
|
31
src/lam/os/Makefile.am
Обычный файл
31
src/lam/os/Makefile.am
Обычный файл
@ -0,0 +1,31 @@
|
||||
#
|
||||
# Copyright 2002-2003. The Regents of the University of California. This material
|
||||
# was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
# National Laboratory, which is operated by the University of California for
|
||||
# the U.S. Department of Energy. The Government is granted for itself and
|
||||
# others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
# license in this material to reproduce, prepare derivative works, and
|
||||
# perform publicly and display publicly. Beginning five (5) years after
|
||||
# October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
# Government is granted for itself and others acting on its behalf a paid-up,
|
||||
# nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
# prepare derivative works, distribute copies to the public, perform publicly
|
||||
# and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
# STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
# CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
# IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
# COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
# PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
# OWNED RIGHTS.
|
||||
#
|
||||
# Additionally, this program is free software; you can distribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public License as
|
||||
# published by the Free Software Foundation; either version 2 of the License,
|
||||
# or any later version. Accordingly, this program is distributed in the hope
|
||||
# that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
|
||||
include $(top_srcdir)/config/Makefile.options
|
||||
|
96
src/lam/os/atomic.h
Обычный файл
96
src/lam/os/atomic.h
Обычный файл
@ -0,0 +1,96 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of
|
||||
* California. This material was produced under U.S. Government
|
||||
* contract W-7405-ENG-36 for Los Alamos National Laboratory, which is
|
||||
* operated by the University of California for the U.S. Department of
|
||||
* Energy. The Government is granted for itself and others acting on
|
||||
* its behalf a paid-up, nonexclusive, irrevocable worldwide license
|
||||
* in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years
|
||||
* after October 10,2002 subject to additional five-year worldwide
|
||||
* renewals, the Government is granted for itself and others acting on
|
||||
* its behalf a paid-up, nonexclusive, irrevocable worldwide license
|
||||
* in this material to reproduce, prepare derivative works, distribute
|
||||
* copies to the public, perform publicly and display publicly, and to
|
||||
* permit others to do so. NEITHER THE UNITED STATES NOR THE UNITED
|
||||
* STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF CALIFORNIA, NOR
|
||||
* ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR
|
||||
* ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT,
|
||||
* OR PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE
|
||||
* PRIVATELY OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it
|
||||
* and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or any later version. Accordingly, this
|
||||
* program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
#ifndef ATOMIC_H_INCLUDED
|
||||
#define ATOMIC_H_INCLUDED
|
||||
|
||||
/*
|
||||
* Atomic functions
|
||||
*/
|
||||
|
||||
#ifdef __alpha
|
||||
# ifdef __GNUC__
|
||||
# include "lam/os/LINUX/alpha/atomic.h"
|
||||
# else
|
||||
# include "lam/os/TRU64/atomic.h"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined (__linux__) && defined (__i386)
|
||||
#include "lam/os/LINUX/i686/atomic.h"
|
||||
#endif
|
||||
|
||||
#ifdef __CYGWIN__
|
||||
#include "lam/os/CYGWIN/atomic.h"
|
||||
#endif
|
||||
|
||||
#ifdef __ia64
|
||||
#include "lam/os/LINUX/ia64/atomic.h"
|
||||
#endif
|
||||
|
||||
#ifdef __mips
|
||||
#include "lam/os/IRIX/atomic.h"
|
||||
#endif
|
||||
|
||||
#ifdef __APPLE__
|
||||
/* check if PowerPC 970 (G5) */
|
||||
#ifdef __ppc_64__
|
||||
#include "lam/os/DARWIN/ppc_64/atomic.h"
|
||||
#else
|
||||
#include "lam/os/DARWIN/powerpc/atomic.h"
|
||||
#endif
|
||||
|
||||
#endif /* __APPLE__ */
|
||||
|
||||
#ifndef mb
|
||||
#define mb()
|
||||
#endif
|
||||
|
||||
#ifndef rmb
|
||||
#define rmb()
|
||||
#endif
|
||||
|
||||
#ifndef wmb
|
||||
#define wmb()
|
||||
#endif
|
||||
|
||||
/*
|
||||
* macros
|
||||
*/
|
||||
|
||||
#define ATOMIC_LOCK_INIT(LOCKPTR) spinunlock(LOCKPTR)
|
||||
#define ATOMIC_LOCK(LOCKPTR) spinlock(LOCKPTR)
|
||||
#define ATOMIC_UNLOCK(LOCKPTR) spinunlock(LOCKPTR)
|
||||
#define ATOMIC_TRYLOCK(LOCKPTR) spintrylock(LOCKPTR)
|
||||
|
||||
#endif /* ATOMIC_H_INCLUDED */
|
221
src/lam/os/cygwin/atomic.h
Обычный файл
221
src/lam/os/cygwin/atomic.h
Обычный файл
@ -0,0 +1,221 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
|
||||
|
||||
#ifndef CYGWIN_I686_ATOMIC_H_INCLUDED
|
||||
#define CYGWIN_I686_ATOMIC_H_INCLUDED
|
||||
|
||||
/*
|
||||
* Lock structure
|
||||
*/
|
||||
|
||||
enum { LOCK_UNLOCKED = 1 };
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
volatile int lockData_m;
|
||||
char padding[4];
|
||||
} data;
|
||||
} lam_lock_data_t;
|
||||
|
||||
|
||||
/*
|
||||
* 64 bit integer
|
||||
*/
|
||||
typedef struct {
|
||||
lam_lock_data_t lock;
|
||||
volatile unsigned long long data;
|
||||
} bigAtomicUnsignedInt;
|
||||
|
||||
/*
|
||||
#ifdef __INTEL_COMPILER
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
void spinlock(lam_lock_data_t *lockData);
|
||||
int spintrylock(lam_lock_data_t *lockData);
|
||||
int fetchNadd(volatile int *addr, int inc);
|
||||
int fetchNset(volatile int *addr, int setValue);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#else
|
||||
*/
|
||||
|
||||
/*
|
||||
* Spin until I can get the lock
|
||||
*/
|
||||
static inline void spinlock(lam_lock_data_t *lockData)
|
||||
{
|
||||
__asm__ __volatile__(
|
||||
"cmp $1, %0\n"
|
||||
"jl 2f\n"
|
||||
"\n1: "
|
||||
"lock ; decl %0\n"
|
||||
"jz 3f\n"
|
||||
"2:\n"
|
||||
"cmp $1, %0\n"
|
||||
"jl 2b\n"
|
||||
"jmp 1b\n"
|
||||
"3:\n"
|
||||
: "=m" (lockData->data.lockData_m) : : "memory");
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine tries once to obtain the lock
|
||||
*/
|
||||
static inline int spintrylock(lam_lock_data_t *lockData)
|
||||
{
|
||||
int gotLock;
|
||||
|
||||
__asm__ __volatile__(
|
||||
"mov %2, %1\n"
|
||||
"cmp $1, %0\n"
|
||||
"jl 1f\n"
|
||||
"lock ; decl %0\n"
|
||||
"js 1f\n"
|
||||
"mov $1, %1\n"
|
||||
"jmp 2f\n"
|
||||
"1:\n"
|
||||
"mov $0, %1\n"
|
||||
"2:"
|
||||
: "=m" (lockData->data.lockData_m),
|
||||
#ifdef __INTEL_COMPILER
|
||||
"=&r" (gotLock) : "r" (0) : "memory");
|
||||
#else
|
||||
"=r" (gotLock) : "r" (0) : "memory");
|
||||
#endif
|
||||
|
||||
return gotLock;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* atomically add a constant to the input integer returning the
|
||||
* previous value
|
||||
*/
|
||||
static inline int fetchNadd(volatile int *addr, int inc)
|
||||
{
|
||||
int inputValue;
|
||||
__asm__ __volatile__(
|
||||
" mov %2, %1\n" \
|
||||
"lock ; xadd %1, %0\n"
|
||||
#ifdef __INTEL_COMPILER
|
||||
: "=m" (*addr), "=&r" (inputValue) : "r" (inc) : "memory");
|
||||
#else
|
||||
: "=m" (*addr), "=r" (inputValue) : "r" (inc) : "memory");
|
||||
#endif
|
||||
|
||||
return (inputValue);
|
||||
}
|
||||
|
||||
|
||||
static inline int fetchNset(volatile int *addr, int setValue)
|
||||
{
|
||||
int inputValue;
|
||||
|
||||
__asm__ __volatile__(
|
||||
" mov %2, %1\n" \
|
||||
"lock ; xchg %1, %0\n"
|
||||
#ifdef __INTEL_COMPILER
|
||||
: "=m" (*addr), "=&r" (inputValue) : "r" (setValue) : "memory");
|
||||
#else
|
||||
: "=m" (*addr), "=r" (inputValue) : "r" (setValue) : "memory");
|
||||
#endif
|
||||
|
||||
return (inputValue);
|
||||
}
|
||||
|
||||
//#endif /* __INTEL_COMPILER */
|
||||
|
||||
|
||||
/*
|
||||
* Clear the lock
|
||||
*/
|
||||
static inline void spinunlock(lam_lock_data_t *lockData)
|
||||
{
|
||||
lockData->data.lockData_m = 1;
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned long long fetchNaddLong(bigAtomicUnsignedInt *addr,
|
||||
int inc)
|
||||
{
|
||||
unsigned long long returnValue;
|
||||
|
||||
spinlock(&(addr->lock));
|
||||
returnValue = addr->data;
|
||||
(addr->data) += inc;
|
||||
spinunlock(&(addr->lock));
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned long long fetchNsetLong(bigAtomicUnsignedInt *addr,
|
||||
unsigned long long val)
|
||||
{
|
||||
unsigned long long returnValue;
|
||||
|
||||
spinlock(&(addr->lock));
|
||||
returnValue = addr->data;
|
||||
addr->data = val;
|
||||
spinunlock(&(addr->lock));
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned long long fetchNaddLongNoLock(bigAtomicUnsignedInt *addr,
|
||||
int inc)
|
||||
{
|
||||
unsigned long long returnValue;
|
||||
|
||||
returnValue = addr->data;
|
||||
addr->data += inc;
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
static inline void setBigAtomicUnsignedInt(bigAtomicUnsignedInt *addr,
|
||||
unsigned long long value)
|
||||
{
|
||||
addr->data = value;
|
||||
addr->lock.data.lockData_m = LOCK_UNLOCKED;
|
||||
}
|
||||
|
||||
#endif /* CYGWIN_I686_ATOMIC_H_INCLUDED */
|
40
src/lam/os/cygwin/smp_dev_params.h
Обычный файл
40
src/lam/os/cygwin/smp_dev_params.h
Обычный файл
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
static const int LogBase2PageSize = 12;
|
||||
static const int SMPPageSize = 1 << LogBase2PageSize;
|
||||
static const int LogBase2ChunkSize = 16;
|
||||
static const int NumMemoryBuckets = 3;
|
||||
static const int MProt = MMAP_SHARED_PROT;
|
||||
static const int MFlags = MMAP_SHARED_FLAGS;
|
||||
static const int PagesPerDevice = 2048;
|
||||
static const int LogBase2MaxPoolSize = 32;
|
||||
static const int MaxStkElements = 32768;
|
||||
static const bool ZeroAllocBase = false;
|
54
src/lam/os/cygwin/ulm_os.h
Обычный файл
54
src/lam/os/cygwin/ulm_os.h
Обычный файл
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
// ulm_os.h - This file contains CYGWIN OS dependent definitions.
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef __CYGWIN__
|
||||
|
||||
#define RESTRICT_MACRO __restrict__
|
||||
|
||||
#ifdef __i386
|
||||
#define PAGESIZE 4096
|
||||
#define SMPPAGESIZE 4096
|
||||
#define intwordaligned(a) ( ( ((long)(a)&3L) == 0L) ? 1 : 0 )
|
||||
#define MEMCOPY_FUNC bcopy
|
||||
#define SMPFirstFragPayload 3496
|
||||
#define SMPSecondFragPayload 8192
|
||||
#define CACHE_ALIGNMENT 128
|
||||
|
||||
#else
|
||||
#error
|
||||
#endif
|
||||
|
||||
#else
|
||||
#error
|
||||
#endif
|
213
src/lam/os/darwin/ppc_32/atomic.h
Обычный файл
213
src/lam/os/darwin/ppc_32/atomic.h
Обычный файл
@ -0,0 +1,213 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
|
||||
#ifndef DARWIN_POWERPC_ATOMIC_H_INCLUDED
|
||||
#define DARWIN_POWERPC_ATOMIC_H_INCLUDED
|
||||
|
||||
/*
|
||||
* The following atomic operations were adapted from the examples provided in the
|
||||
* PowerPC programming manual available at
|
||||
* http://www-3.ibm.com/chips/techlib/techlib.nsf/techdocs/852569B20050FF778525699600719DF2
|
||||
*/
|
||||
|
||||
#define mb() __asm__ __volatile__("sync")
|
||||
#define rmb() __asm__ __volatile__("sync")
|
||||
#define wmb() __asm__ __volatile__("sync")
|
||||
|
||||
/*
|
||||
* Lock structure
|
||||
*/
|
||||
|
||||
enum { LOCK_UNLOCKED = 0 };
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
volatile int lockData_m;
|
||||
char padding[4];
|
||||
} data;
|
||||
} lam_lock_data_t;
|
||||
|
||||
|
||||
/*
|
||||
* 64 bit integer
|
||||
*/
|
||||
typedef struct {
|
||||
lam_lock_data_t lock;
|
||||
volatile unsigned long long data;
|
||||
} bigAtomicUnsignedInt;
|
||||
|
||||
|
||||
/*
|
||||
* Spin until I can get the lock
|
||||
*/
|
||||
static inline void spinlock(lam_lock_data_t *lockData)
|
||||
{
|
||||
volatile int *lockptr = &(lockData->data.lockData_m);
|
||||
|
||||
__asm__ __volatile__(
|
||||
"mr r6, %0\n" /* save the address of the lock. */
|
||||
"li r4,1\n"
|
||||
"1:\n"
|
||||
"lwarx r5,0,r6\n" /* Get current lock value. */
|
||||
"cmpwi r5,0x0\n" /* Is it unlocked. if not, keep checking. */
|
||||
"bne- 1b\n"
|
||||
"stwcx. r4,0,r6\n" /* Try to atomically set the lock */
|
||||
"bne- 1b\n"
|
||||
"isync\n"
|
||||
: : "r" (lockptr)
|
||||
: "memory", "r4", "r5", "r6");
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine tries once to obtain the lock
|
||||
*/
|
||||
static inline int spintrylock(lam_lock_data_t *lockData)
|
||||
{
|
||||
volatile int *lockptr = &(lockData->data.lockData_m);
|
||||
int gotLock = 0;
|
||||
|
||||
__asm__ __volatile__(
|
||||
"mr r6, %1\n" /* save the address of the lock. */
|
||||
"li r4,0x1\n"
|
||||
"1:\n"
|
||||
"lwarx r5,0,r6\n"
|
||||
"cmpwi r5,0x0\n" /* Is it locked? */
|
||||
"bne- 2f\n" /* Yes, return 0 */
|
||||
"stwcx. r4,0,r6\n" /* Try to atomically set the lock */
|
||||
"bne- 1b\n"
|
||||
"addi %0,0,1\n"
|
||||
"isync\n"
|
||||
"b 3f\n"
|
||||
"2: addi %0,0,0x0\n"
|
||||
"3:"
|
||||
: "=&r" (gotLock) : "r" (lockptr)
|
||||
: "memory", "r4", "r5", "r6" );
|
||||
|
||||
return gotLock;
|
||||
}
|
||||
|
||||
/*
|
||||
* Clear the lock
|
||||
*/
|
||||
static inline void spinunlock(lam_lock_data_t *lockData)
|
||||
{
|
||||
lockData->data.lockData_m = LOCK_UNLOCKED;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* atomically add a constant to the input integer returning the
|
||||
* previous value
|
||||
*/
|
||||
static inline int fetchNadd(volatile int *addr, int inc)
|
||||
{
|
||||
int inputValue;
|
||||
|
||||
__asm__ __volatile__(
|
||||
"mr r5,%2\n" /* Save the increment */
|
||||
"1:\n"
|
||||
"lwarx %0, 0, %1\n" /* Grab the area value */
|
||||
"add r6, %0, r5\n" /* Add the value */
|
||||
"stwcx. r6, 0, %1\n" /* Try to save the new value */
|
||||
"bne- 1b\n" /* Didn't get it, try again... */
|
||||
"isync\n"
|
||||
: "=&r" (inputValue) : "r" (addr), "r" (inc) :
|
||||
"memory", "r5", "r6");
|
||||
|
||||
return inputValue;
|
||||
}
|
||||
|
||||
|
||||
static inline int fetchNset(volatile int *addr, int setValue)
|
||||
{
|
||||
int inputValue;
|
||||
|
||||
__asm__ __volatile__(
|
||||
"mr r5,%2\n" /* Save the value to store */
|
||||
"1:\n"
|
||||
"lwarx %0, 0, %1\n" /* Grab the area value */
|
||||
"stwcx. r5, 0, %1\n" /* Try to save the new value */
|
||||
"bne- 1b\n" /* Didn't get it, try again... */
|
||||
"isync\n"
|
||||
: "=&r" (inputValue) : "r" (addr), "r" (setValue) :
|
||||
"memory", "r5");
|
||||
|
||||
return inputValue;
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned long long fetchNaddLong(bigAtomicUnsignedInt *addr,
|
||||
int inc)
|
||||
{
|
||||
unsigned long long returnValue;
|
||||
|
||||
spinlock(&(addr->lock));
|
||||
returnValue = addr->data;
|
||||
(addr->data) += inc;
|
||||
spinunlock(&(addr->lock));
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned long long fetchNsetLong(bigAtomicUnsignedInt *addr,
|
||||
unsigned long long val)
|
||||
{
|
||||
unsigned long long returnValue;
|
||||
|
||||
spinlock(&(addr->lock));
|
||||
returnValue = addr->data;
|
||||
addr->data = val;
|
||||
spinunlock(&(addr->lock));
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned long long fetchNaddLongNoLock(bigAtomicUnsignedInt *addr,
|
||||
int inc)
|
||||
{
|
||||
unsigned long long returnValue;
|
||||
|
||||
returnValue = addr->data;
|
||||
addr->data += inc;
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
static inline void setBigAtomicUnsignedInt(bigAtomicUnsignedInt *addr,
|
||||
unsigned long long value)
|
||||
{
|
||||
addr->data = value;
|
||||
addr->lock.data.lockData_m = LOCK_UNLOCKED;
|
||||
}
|
||||
|
||||
#endif /* DARWIN_POWERPC_ATOMIC_H_INCLUDED */
|
40
src/lam/os/darwin/ppc_32/smp_dev_params.h
Обычный файл
40
src/lam/os/darwin/ppc_32/smp_dev_params.h
Обычный файл
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
static const int LogBase2PageSize = 12;
|
||||
static const int SMPPageSize = 1 << LogBase2PageSize;
|
||||
static const int LogBase2ChunkSize = 16;
|
||||
static const int NumMemoryBuckets = 3;
|
||||
static const int MProt = MMAP_SHARED_PROT;
|
||||
static const int MFlags = MMAP_SHARED_FLAGS;
|
||||
static const int PagesPerDevice = 2048;
|
||||
static const int LogBase2MaxPoolSize = 32;
|
||||
static const int MaxStkElements = 32768;
|
||||
static const bool ZeroAllocBase = false;
|
229
src/lam/os/darwin/ppc_64/atomic.h
Обычный файл
229
src/lam/os/darwin/ppc_64/atomic.h
Обычный файл
@ -0,0 +1,229 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
|
||||
#ifndef DARWIN_PPC_64_ATOMIC_H_INCLUDED
|
||||
#define DARWIN_PPC_64_ATOMIC_H_INCLUDED
|
||||
|
||||
/*
|
||||
* The following atomic operations were adapted from the examples provided in the
|
||||
* PowerPC programming manual available at
|
||||
* http://www-3.ibm.com/chips/techlib/techlib.nsf/techdocs/852569B20050FF778525699600719DF2
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#define mb() __asm__ __volatile__("sync")
|
||||
#define rmb() __asm__ __volatile__("sync")
|
||||
#define wmb() __asm__ __volatile__("sync")
|
||||
|
||||
/*
|
||||
* Lock structure
|
||||
*/
|
||||
|
||||
enum { LOCK_UNLOCKED = 0 };
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
volatile int lockData_m;
|
||||
char padding[4];
|
||||
} data;
|
||||
} lam_lock_data_t;
|
||||
|
||||
|
||||
/*
|
||||
* 64 bit integer
|
||||
*/
|
||||
typedef volatile unsigned long long bigAtomicUnsignedInt;
|
||||
|
||||
|
||||
/*
|
||||
* Spin until I can get the lock
|
||||
*/
|
||||
static inline void spinlock(lam_lock_data_t *lockData)
|
||||
{
|
||||
volatile int *lockptr = &(lockData->data.lockData_m);
|
||||
|
||||
__asm__ __volatile__(
|
||||
"mr r6, %0\n" /* save the address of the lock. */
|
||||
"li r4,1\n"
|
||||
"1:\n"
|
||||
"lwarx r5,0,r6\n" /* Get current lock value. */
|
||||
"cmpwi r5,0x0\n" /* Is it unlocked. if not, keep checking. */
|
||||
"bne- 1b\n"
|
||||
"stwcx. r4,0,r6\n" /* Try to atomically set the lock */
|
||||
"bne- 1b\n"
|
||||
"isync\n"
|
||||
: : "r" (lockptr)
|
||||
: "memory", "r4", "r5", "r6");
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine tries once to obtain the lock
|
||||
*/
|
||||
static inline int spintrylock(lam_lock_data_t *lockData)
|
||||
{
|
||||
volatile int *lockptr = &(lockData->data.lockData_m);
|
||||
int gotLock = 0;
|
||||
|
||||
__asm__ __volatile__(
|
||||
"mr r6, %1\n" /* save the address of the lock. */
|
||||
"li r4,0x1\n"
|
||||
"1:\n"
|
||||
"lwarx r5,0,r6\n"
|
||||
"cmpwi r5,0x0\n" /* Is it locked? */
|
||||
"bne- 2f\n" /* Yes, return 0 */
|
||||
"stwcx. r4,0,r6\n" /* Try to atomically set the lock */
|
||||
"bne- 1b\n"
|
||||
"addi %0,0,1\n"
|
||||
"isync\n"
|
||||
"b 3f\n"
|
||||
"2: addi %0,0,0x0\n"
|
||||
"3:"
|
||||
: "=&r" (gotLock) : "r" (lockptr)
|
||||
: "memory", "r4", "r5", "r6" );
|
||||
|
||||
return gotLock;
|
||||
}
|
||||
|
||||
/*
|
||||
* Clear the lock
|
||||
*/
|
||||
static inline void spinunlock(lam_lock_data_t *lockData)
|
||||
{
|
||||
lockData->data.lockData_m = LOCK_UNLOCKED;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* atomically add a constant to the input integer returning the
|
||||
* previous value
|
||||
*/
|
||||
static inline int fetchNadd(volatile int *addr, int inc)
|
||||
{
|
||||
int inputValue;
|
||||
|
||||
__asm__ __volatile__(
|
||||
"mr r5,%2\n" /* Save the increment */
|
||||
"1:\n"
|
||||
"lwarx %0, 0, %1\n" /* Grab the value */
|
||||
"add r6, %0, r5\n" /* Add the value */
|
||||
"stwcx. r6, 0, %1\n" /* Try to save the new value */
|
||||
"bne- 1b\n" /* Didn't get it, try again... */
|
||||
"isync\n"
|
||||
: "=&r" (inputValue) : "r" (addr), "r" (inc) :
|
||||
"memory", "r5", "r6");
|
||||
|
||||
return inputValue;
|
||||
}
|
||||
|
||||
|
||||
static inline int fetchNset(volatile int *addr, int setValue)
|
||||
{
|
||||
int inputValue;
|
||||
|
||||
__asm__ __volatile__(
|
||||
"mr r5,%2\n" /* Save the value to store */
|
||||
"1:\n"
|
||||
"lwarx %0, 0, %1\n" /* Grab the area value */
|
||||
"stwcx. r5, 0, %1\n" /* Try to save the new value */
|
||||
"bne- 1b\n" /* Didn't get it, try again... */
|
||||
"isync\n"
|
||||
: "=&r" (inputValue) : "r" (addr), "r" (setValue) :
|
||||
"memory", "r5");
|
||||
|
||||
return inputValue;
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned long long fetchNaddLong(bigAtomicUnsignedInt *addr,
|
||||
int inc)
|
||||
{
|
||||
unsigned long long returnValue;
|
||||
|
||||
__asm__ __volatile__(
|
||||
"mr r5,%2\n" /* Save the increment */
|
||||
"1:\n"
|
||||
"ldarx %0, 0, %1\n" /* Grab the value */
|
||||
"add r6, %0, r5\n" /* Add the value */
|
||||
"stdcx. r6, 0, %1\n" /* Try to save the new value */
|
||||
"bne- 1b\n" /* Didn't get it, try again... */
|
||||
"isync\n"
|
||||
: "=&r" (returnValue) : "r" (addr), "r" (inc) :
|
||||
"memory", "r5", "r6");
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned long long fetchNsetLong(bigAtomicUnsignedInt *addr,
|
||||
unsigned long long val)
|
||||
{
|
||||
unsigned long long returnValue;
|
||||
|
||||
__asm__ __volatile__(
|
||||
"mr r5,%2\n" /* Save the value to store */
|
||||
"1:\n"
|
||||
"ldarx %0, 0, %1\n" /* Grab the area value */
|
||||
"stdcx. r5, 0, %1\n" /* Try to save the new value */
|
||||
"bne- 1b\n" /* Didn't get it, try again... */
|
||||
"isync\n"
|
||||
: "=&r" (returnValue) : "r" (addr), "r" (val) :
|
||||
"memory", "r5");
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned long long fetchNaddLongNoLock(bigAtomicUnsignedInt *addr,
|
||||
int inc)
|
||||
{
|
||||
unsigned long long returnValue;
|
||||
|
||||
returnValue = *addr;
|
||||
*addr += inc;
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
static inline void setBigAtomicUnsignedInt(bigAtomicUnsignedInt *addr,
|
||||
unsigned long long value)
|
||||
{
|
||||
*addr = value;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#endif /* DARWIN_POWERPC_ATOMIC_H_INCLUDED */
|
40
src/lam/os/darwin/ppc_64/smp_dev_params.h
Обычный файл
40
src/lam/os/darwin/ppc_64/smp_dev_params.h
Обычный файл
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
static const int LogBase2PageSize = 12;
|
||||
static const int SMPPageSize = 1 << LogBase2PageSize;
|
||||
static const int LogBase2ChunkSize = 16;
|
||||
static const int NumMemoryBuckets = 3;
|
||||
static const int MProt = MMAP_SHARED_PROT;
|
||||
static const int MFlags = MMAP_SHARED_FLAGS;
|
||||
static const int PagesPerDevice = 2048;
|
||||
static const int LogBase2MaxPoolSize = 32;
|
||||
static const int MaxStkElements = 32768;
|
||||
static const bool ZeroAllocBase = false;
|
59
src/lam/os/darwin/ulm_os.h
Обычный файл
59
src/lam/os/darwin/ulm_os.h
Обычный файл
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
|
||||
|
||||
//
|
||||
// ulm_os.h - This file contains DARWIN OS dependent definitions.
|
||||
//
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef __APPLE__
|
||||
|
||||
#define RESTRICT_MACRO __restrict__
|
||||
|
||||
#ifdef __ppc__
|
||||
#define PAGESIZE 4096
|
||||
#define SMPPAGESIZE 4096
|
||||
#define intwordaligned(a) ( ( ((long)(a)&3L) == 0L) ? 1 : 0 )
|
||||
#define MEMCOPY_FUNC bcopy
|
||||
#define SMPFirstFragPayload 3496
|
||||
#define SMPSecondFragPayload 8192
|
||||
#define CACHE_ALIGNMENT 256
|
||||
// Reference: http://developer.apple.com/hardware/ve/caches.html gives cacheline as 32 bytes
|
||||
|
||||
#else
|
||||
#error
|
||||
#endif
|
||||
|
||||
#else
|
||||
#error
|
||||
#endif
|
75
src/lam/os/irix/atomic.h
Обычный файл
75
src/lam/os/irix/atomic.h
Обычный файл
@ -0,0 +1,75 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
|
||||
|
||||
#ifndef IRIX_ATOMIC_H_INCLUDED
|
||||
#define IRIX_ATOMIC_H_INCLUDED
|
||||
|
||||
#include "internal/linkage.h"
|
||||
|
||||
/*
|
||||
* 64 bit integer
|
||||
*/
|
||||
typedef volatile unsigned long long bigAtomicUnsignedInt;
|
||||
|
||||
/*
|
||||
* Lock structure
|
||||
*/
|
||||
enum { LOCK_UNLOCKED = 0 };
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
volatile int lockData_m;
|
||||
char padding[4];
|
||||
} data;
|
||||
} lam_lock_data_t;
|
||||
|
||||
CDECL_BEGIN
|
||||
|
||||
static inline void spinunlock(lam_lock_data_t *ctlData_m)
|
||||
{
|
||||
ctlData_m->data.lockData_m = LOCK_UNLOCKED;
|
||||
}
|
||||
|
||||
void spinlock(lam_lock_data_t *);
|
||||
int spintrylock(lam_lock_data_t *);
|
||||
int fetchNadd(volatile int *addr, int inc);
|
||||
int fetchNset(volatile int *addr, int val);
|
||||
unsigned long long fetchNaddLong(bigAtomicUnsignedInt *addr, int inc);
|
||||
unsigned long long fetchNsetLong(bigAtomicUnsignedInt *addr,
|
||||
unsigned long long val);
|
||||
void setBigAtomicUnsignedInt(bigAtomicUnsignedInt *addr,
|
||||
unsigned long long val);
|
||||
unsigned long long fetchNaddLongNoLock(bigAtomicUnsignedInt *addr,
|
||||
int inc);
|
||||
CDECL_END
|
||||
|
||||
#endif /* IRIX_ATOMIC_H_INCLUDED */
|
40
src/lam/os/irix/smp_dev_params.h
Обычный файл
40
src/lam/os/irix/smp_dev_params.h
Обычный файл
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
static const int LogBase2PageSize = 14;
|
||||
static const int SMPPageSize = 1 << LogBase2PageSize;
|
||||
static const int LogBase2ChunkSize = 16;
|
||||
static const int NumMemoryBuckets = 3;
|
||||
static const int MProt = MMAP_SHARED_PROT;
|
||||
static const int MFlags = MMAP_SHARED_FLAGS;
|
||||
static const int PagesPerDevice = 2048;
|
||||
static const int LogBase2MaxPoolSize = 32;
|
||||
static const int MaxStkElements = 32768;
|
||||
static const bool ZeroAllocBase = false;
|
53
src/lam/os/irix/ulm_os.h
Обычный файл
53
src/lam/os/irix/ulm_os.h
Обычный файл
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
|
||||
// ulm_os.h - This file contains IRIX OS dependent definitions.
|
||||
|
||||
#ifndef IRIX_ULM_OS
|
||||
#define IRIX_ULM_OS
|
||||
|
||||
#include <strings.h> /* for bcopy */
|
||||
|
||||
// memory page size
|
||||
|
||||
#define LOG2PAGESIZE 14
|
||||
#define SMPPAGESIZE (1 << LOG2PAGESIZE)
|
||||
|
||||
#define RESTRICT_MACRO restrict
|
||||
#define intwordaligned(a) ( ( ((long long)(a)&3L) == 0L) ? 1 : 0 )
|
||||
|
||||
#define PAGESIZE 16384
|
||||
#define CACHE_ALIGNMENT 128
|
||||
|
||||
/* memory copy function */
|
||||
#define MEMCOPY_FUNC bcopy
|
||||
|
||||
#endif /* IRIX_ULM_OS */
|
252
src/lam/os/linux/alpha/atomic.h
Обычный файл
252
src/lam/os/linux/alpha/atomic.h
Обычный файл
@ -0,0 +1,252 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
|
||||
|
||||
#ifndef LINUX_ALPHA_ATOMIC_H_INCLUDED
|
||||
#define LINUX_ALPHA_ATOMIC_H_INCLUDED
|
||||
|
||||
|
||||
/*
|
||||
* 64 bit integer
|
||||
*/
|
||||
typedef volatile unsigned long long bigAtomicUnsignedInt;
|
||||
|
||||
#include "internal/linkage.h"
|
||||
|
||||
CDECL_BEGIN
|
||||
|
||||
/*
|
||||
* Lock structure
|
||||
*/
|
||||
enum { LOCK_UNLOCKED = 0 };
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
volatile int lockData_m;
|
||||
char padding[4];
|
||||
} data;
|
||||
} lam_lock_data_t;
|
||||
|
||||
#define mb() \
|
||||
__asm__ __volatile__("mb": : :"memory")
|
||||
|
||||
#define rmb() \
|
||||
__asm__ __volatile__("mb": : :"memory")
|
||||
|
||||
#define wmb() \
|
||||
__asm__ __volatile__("wmb": : :"memory")
|
||||
|
||||
|
||||
/*
|
||||
* This is routine spins until the lock is obtained
|
||||
* A value of 0 indicates that the lock is available
|
||||
* 1 or more the lock is held by someone
|
||||
*/
|
||||
INLINE void spinlock(lam_lock_data_t *lock)
|
||||
{
|
||||
/*** sungeun *** ref: alpha-linux spinlock sources ***/
|
||||
int tmp = 0;
|
||||
|
||||
/* Use sub-sections to put the actual loop at the end
|
||||
of this object file's text section so as to perfect
|
||||
branch prediction. */
|
||||
__asm__ __volatile__(
|
||||
"1: ldl %0,%1\n"
|
||||
" blbs %0,2f\n"
|
||||
" ldl_l %0,%1\n"
|
||||
" blbs %0,2f\n"
|
||||
" or %0,1,%0\n"
|
||||
" stl_c %0,%1\n"
|
||||
" beq %0,2f\n"
|
||||
" mb\n"
|
||||
".subsection 2\n"
|
||||
"2: ldl %0,%1\n"
|
||||
" blbs %0,2b\n"
|
||||
" br 1b\n"
|
||||
".previous"
|
||||
: "=&r" (tmp), "=m" (lock->data.lockData_m)
|
||||
: "m"(lock->data.lockData_m) : "memory");
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* This routine tries once to obtain the lock
|
||||
*/
|
||||
INLINE int spintrylock(lam_lock_data_t *lock)
|
||||
{
|
||||
int got_lock = 0;
|
||||
int tmp = 0;
|
||||
|
||||
__asm__ __volatile__(
|
||||
" ldl %0,%2\n"
|
||||
" blbs %0,1f\n"
|
||||
" ldl_l %0,%2\n"
|
||||
" blbs %0,1f\n"
|
||||
" or %0,1,%0\n"
|
||||
" stl_c %0,%2\n"
|
||||
" beq %0,1f\n"
|
||||
" mov 1,%1\n"
|
||||
"1: mb\n"
|
||||
: "=&r" (tmp), "=&r" (got_lock), "=m" (lock->data.lockData_m)
|
||||
: "m"(lock->data.lockData_m) : "memory");
|
||||
|
||||
return got_lock;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Clear the lock - alpha specific - need memory barrier
|
||||
*/
|
||||
INLINE void spinunlock(lam_lock_data_t *lock)
|
||||
{
|
||||
mb();
|
||||
lock->data.lockData_m = 0;
|
||||
}
|
||||
|
||||
INLINE int fetchNadd(volatile int *addr, int inc)
|
||||
{
|
||||
int oldval = 0;
|
||||
int tmp = 0;
|
||||
|
||||
__asm__ __volatile__(
|
||||
"1: ldl_l %1, %0\n"
|
||||
" addl %1, %2, %3\n"
|
||||
" stl_c %3, %0\n"
|
||||
" beq %3, 2f\n"
|
||||
" br 3f\n"
|
||||
"2:\n"
|
||||
" br 1b\n"
|
||||
"3:\n"
|
||||
" mb\n"
|
||||
: "=m" (*addr), "=r" (oldval)
|
||||
: "r" (inc), "r" (tmp)
|
||||
: "memory");
|
||||
|
||||
return oldval;
|
||||
}
|
||||
|
||||
|
||||
|
||||
INLINE int fetchNset(volatile int *addr, int val)
|
||||
{
|
||||
int oldval = 0;
|
||||
int tmp = 0;
|
||||
|
||||
__asm__ __volatile__(
|
||||
"1: ldl_l %1, %0\n"
|
||||
" mov %2, %3\n"
|
||||
" stl_c %3, %0\n"
|
||||
" beq %3, 2f\n"
|
||||
" br 3f\n"
|
||||
"2:\n"
|
||||
" br 1b\n"
|
||||
"3:\n"
|
||||
" mb\n"
|
||||
: "=m" (*addr), "=r" (oldval)
|
||||
: "r" (val), "r" (tmp)
|
||||
: "memory");
|
||||
|
||||
return oldval;
|
||||
}
|
||||
|
||||
|
||||
INLINE unsigned long long fetchNaddLong(bigAtomicUnsignedInt *addr, int inc)
|
||||
{
|
||||
unsigned long long oldval = 0;
|
||||
unsigned long long tmp = 0;
|
||||
|
||||
__asm__ __volatile__(
|
||||
/* load the contents of addr */
|
||||
"1: ldq_l %1, %0\n"
|
||||
/* increment count */
|
||||
" addq %1, %2, %3\n"
|
||||
/* conditional store */
|
||||
" stq_c %3, %0\n"
|
||||
/* store conditional failed - loop again */
|
||||
" beq %3, 1b\n"
|
||||
/* store conditional passed - go to memory barrier */
|
||||
" br 3f\n"
|
||||
/* loop again */
|
||||
"2: br 1b\n"
|
||||
/* memory barrier and exit */
|
||||
"3: mb\n"
|
||||
: "=m" (*addr), "=r" (oldval)
|
||||
: "r" (inc), "r" (tmp)
|
||||
: "memory");
|
||||
|
||||
return oldval;
|
||||
}
|
||||
|
||||
|
||||
INLINE unsigned long long fetchNaddLongNoLock(bigAtomicUnsignedInt *addr,
|
||||
int inc)
|
||||
{
|
||||
unsigned long long val;
|
||||
|
||||
val = *addr;
|
||||
*addr += inc;
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
INLINE unsigned long long fetchNsetLong(volatile unsigned long long *addr,
|
||||
unsigned long long val)
|
||||
{
|
||||
unsigned long long oldval = 0;
|
||||
unsigned long long tmp = 0;
|
||||
|
||||
__asm__ __volatile__(
|
||||
"1: ldq_l %1, %0\n"
|
||||
" mov %2, %3\n"
|
||||
" stq_c %3, %0\n"
|
||||
" beq %3, 2f\n"
|
||||
" br 3f\n"
|
||||
"2:\n"
|
||||
" br 1b\n"
|
||||
"3:\n"
|
||||
" mb\n"
|
||||
: "=m" (*addr), "=r" (oldval)
|
||||
: "r" (val), "r" (tmp)
|
||||
: "memory");
|
||||
|
||||
return oldval;
|
||||
}
|
||||
|
||||
|
||||
INLINE void setBigAtomicUnsignedInt(bigAtomicUnsignedInt *addr,
|
||||
unsigned long long val)
|
||||
{
|
||||
*addr = val;
|
||||
}
|
||||
|
||||
CDECL_END
|
||||
|
||||
#endif /* LINUX_ALPHA_ATOMIC_H_INCLUDED */
|
40
src/lam/os/linux/alpha/smp_dev_params.h
Обычный файл
40
src/lam/os/linux/alpha/smp_dev_params.h
Обычный файл
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
static const int LogBase2PageSize = 13;
|
||||
static const int SMPPageSize = 1 << LogBase2PageSize;
|
||||
static const int LogBase2ChunkSize = 16;
|
||||
static const int NumMemoryBuckets = 3;
|
||||
static const int MProt = MMAP_SHARED_PROT;
|
||||
static const int MFlags = MMAP_SHARED_FLAGS;
|
||||
static const int PagesPerDevice = 2048;
|
||||
static const int LogBase2MaxPoolSize = 32;
|
||||
static const int MaxStkElements = 32768;
|
||||
static const bool ZeroAllocBase = false;
|
221
src/lam/os/linux/i686/atomic.h
Обычный файл
221
src/lam/os/linux/i686/atomic.h
Обычный файл
@ -0,0 +1,221 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
|
||||
|
||||
#ifndef LINUX_I686_ATOMIC_H_INCLUDED
|
||||
#define LINUX_I686_ATOMIC_H_INCLUDED
|
||||
|
||||
/*
|
||||
* Lock structure
|
||||
*/
|
||||
|
||||
enum { LOCK_UNLOCKED = 1 };
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
volatile int lockData_m;
|
||||
char padding[4];
|
||||
} data;
|
||||
} lam_lock_data_t;
|
||||
|
||||
|
||||
/*
|
||||
* 64 bit integer
|
||||
*/
|
||||
typedef struct {
|
||||
lam_lock_data_t lock;
|
||||
volatile unsigned long long data;
|
||||
} bigAtomicUnsignedInt;
|
||||
|
||||
/*
|
||||
#ifdef __INTEL_COMPILER
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
void spinlock(lam_lock_data_t *lockData);
|
||||
int spintrylock(lam_lock_data_t *lockData);
|
||||
int fetchNadd(volatile int *addr, int inc);
|
||||
int fetchNset(volatile int *addr, int setValue);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#else
|
||||
*/
|
||||
|
||||
/*
|
||||
* Spin until I can get the lock
|
||||
*/
|
||||
static inline void spinlock(lam_lock_data_t *lockData)
|
||||
{
|
||||
__asm__ __volatile__(
|
||||
"cmp $1, %0\n"
|
||||
"jl 2f\n"
|
||||
"\n1: "
|
||||
"lock ; decl %0\n"
|
||||
"jz 3f\n"
|
||||
"2:\n"
|
||||
"cmp $1, %0\n"
|
||||
"jl 2b\n"
|
||||
"jmp 1b\n"
|
||||
"3:\n"
|
||||
: "=m" (lockData->data.lockData_m) : : "memory");
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine tries once to obtain the lock
|
||||
*/
|
||||
static inline int spintrylock(lam_lock_data_t *lockData)
|
||||
{
|
||||
int gotLock;
|
||||
|
||||
__asm__ __volatile__(
|
||||
"mov %2, %1\n"
|
||||
"cmp $1, %0\n"
|
||||
"jl 1f\n"
|
||||
"lock ; decl %0\n"
|
||||
"js 1f\n"
|
||||
"mov $1, %1\n"
|
||||
"jmp 2f\n"
|
||||
"1:\n"
|
||||
"mov $0, %1\n"
|
||||
"2:"
|
||||
: "=m" (lockData->data.lockData_m),
|
||||
#ifdef __INTEL_COMPILER
|
||||
"=&r" (gotLock) : "r" (0) : "memory");
|
||||
#else
|
||||
"=r" (gotLock) : "r" (0) : "memory");
|
||||
#endif
|
||||
|
||||
return gotLock;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* atomically add a constant to the input integer returning the
|
||||
* previous value
|
||||
*/
|
||||
static inline int fetchNadd(volatile int *addr, int inc)
|
||||
{
|
||||
int inputValue;
|
||||
__asm__ __volatile__(
|
||||
" mov %2, %1\n" \
|
||||
"lock ; xadd %1, %0\n"
|
||||
#ifdef __INTEL_COMPILER
|
||||
: "=m" (*addr), "=&r" (inputValue) : "r" (inc) : "memory");
|
||||
#else
|
||||
: "=m" (*addr), "=r" (inputValue) : "r" (inc) : "memory");
|
||||
#endif
|
||||
|
||||
return (inputValue);
|
||||
}
|
||||
|
||||
|
||||
static inline int fetchNset(volatile int *addr, int setValue)
|
||||
{
|
||||
int inputValue;
|
||||
|
||||
__asm__ __volatile__(
|
||||
" mov %2, %1\n" \
|
||||
"lock ; xchg %1, %0\n"
|
||||
#ifdef __INTEL_COMPILER
|
||||
: "=m" (*addr), "=&r" (inputValue) : "r" (setValue) : "memory");
|
||||
#else
|
||||
: "=m" (*addr), "=r" (inputValue) : "r" (setValue) : "memory");
|
||||
#endif
|
||||
|
||||
return (inputValue);
|
||||
}
|
||||
|
||||
//#endif /* __INTEL_COMPILER */
|
||||
|
||||
|
||||
/*
|
||||
* Clear the lock
|
||||
*/
|
||||
static inline void spinunlock(lam_lock_data_t *lockData)
|
||||
{
|
||||
lockData->data.lockData_m = 1;
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned long long fetchNaddLong(bigAtomicUnsignedInt *addr,
|
||||
int inc)
|
||||
{
|
||||
unsigned long long returnValue;
|
||||
|
||||
spinlock(&(addr->lock));
|
||||
returnValue = addr->data;
|
||||
(addr->data) += inc;
|
||||
spinunlock(&(addr->lock));
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned long long fetchNsetLong(bigAtomicUnsignedInt *addr,
|
||||
unsigned long long val)
|
||||
{
|
||||
unsigned long long returnValue;
|
||||
|
||||
spinlock(&(addr->lock));
|
||||
returnValue = addr->data;
|
||||
addr->data = val;
|
||||
spinunlock(&(addr->lock));
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned long long fetchNaddLongNoLock(bigAtomicUnsignedInt *addr,
|
||||
int inc)
|
||||
{
|
||||
unsigned long long returnValue;
|
||||
|
||||
returnValue = addr->data;
|
||||
addr->data += inc;
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
static inline void setBigAtomicUnsignedInt(bigAtomicUnsignedInt *addr,
|
||||
unsigned long long value)
|
||||
{
|
||||
addr->data = value;
|
||||
addr->lock.data.lockData_m = LOCK_UNLOCKED;
|
||||
}
|
||||
|
||||
#endif /* LINUX_I686_ATOMIC_H_INCLUDED */
|
71
src/lam/os/linux/i686/lock.s
Обычный файл
71
src/lam/os/linux/i686/lock.s
Обычный файл
@ -0,0 +1,71 @@
|
||||
#include <asm.h>
|
||||
|
||||
.text
|
||||
|
||||
.global spinlock
|
||||
|
||||
spinlock:
|
||||
push %ebp
|
||||
mov %esp,%ebp
|
||||
mov 0x8(%ebp),%eax
|
||||
cmpl $0x1,(%eax)
|
||||
jl 2f
|
||||
1:
|
||||
lock decl (%eax)
|
||||
jz 3f
|
||||
2:
|
||||
cmpl $0x1,(%eax)
|
||||
jl 2b
|
||||
jmp 1b
|
||||
3:
|
||||
pop %ebp
|
||||
ret
|
||||
|
||||
.global spintrylock
|
||||
|
||||
spintrylock:
|
||||
push %ebp
|
||||
mov %esp,%ebp
|
||||
sub $0x4,%esp
|
||||
mov 0x8(%ebp),%edx
|
||||
mov $0x0,%eax
|
||||
cmpl $0x1,(%edx)
|
||||
jl 1f
|
||||
lock decl (%edx)
|
||||
js 1f
|
||||
mov $0x1,%eax
|
||||
jmp 2f
|
||||
1:
|
||||
mov $0x0,%eax
|
||||
2:
|
||||
mov %eax,0xfffffffc(%ebp)
|
||||
leave
|
||||
ret
|
||||
|
||||
.global fetchNadd
|
||||
|
||||
fetchNadd:
|
||||
push %ebp
|
||||
mov %esp,%ebp
|
||||
sub $0x4,%esp
|
||||
mov 0x8(%ebp),%edx
|
||||
mov 0xc(%ebp),%eax
|
||||
lock xadd %eax,(%edx)
|
||||
mov %eax,0xfffffffc(%ebp)
|
||||
leave
|
||||
ret
|
||||
|
||||
.global fetchNset
|
||||
|
||||
fetchNset:
|
||||
push %ebp
|
||||
mov %esp,%ebp
|
||||
sub $0x4,%esp
|
||||
mov 0x8(%ebp),%edx
|
||||
mov 0xc(%ebp),%eax
|
||||
lock xchg %eax,(%edx)
|
||||
mov %eax,0xfffffffc(%ebp)
|
||||
leave
|
||||
ret
|
||||
|
||||
|
40
src/lam/os/linux/i686/smp_dev_params.h
Обычный файл
40
src/lam/os/linux/i686/smp_dev_params.h
Обычный файл
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
static const int LogBase2PageSize = 12;
|
||||
static const int SMPPageSize = 1 << LogBase2PageSize;
|
||||
static const int LogBase2ChunkSize = 16;
|
||||
static const int NumMemoryBuckets = 3;
|
||||
static const int MProt = MMAP_SHARED_PROT;
|
||||
static const int MFlags = MMAP_SHARED_FLAGS;
|
||||
static const int PagesPerDevice = 2048;
|
||||
static const int LogBase2MaxPoolSize = 32;
|
||||
static const int MaxStkElements = 32768;
|
||||
static const bool ZeroAllocBase = false;
|
201
src/lam/os/linux/ia64/atomic.h
Обычный файл
201
src/lam/os/linux/ia64/atomic.h
Обычный файл
@ -0,0 +1,201 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
|
||||
|
||||
#ifndef LINUX_IA64_ATOMIC_H_INCLUDED
|
||||
#define LINUX_IA64_ATOMIC_H_INCLUDED
|
||||
|
||||
/*
|
||||
* Lock structure
|
||||
*/
|
||||
|
||||
enum { LOCK_UNLOCKED = 1 };
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
volatile int lockData_m;
|
||||
char padding[4];
|
||||
} data;
|
||||
} lam_lock_data_t;
|
||||
|
||||
|
||||
/*
|
||||
* 64 bit integer
|
||||
*/
|
||||
typedef struct {
|
||||
lam_lock_data_t lock;
|
||||
volatile unsigned long long data;
|
||||
} bigAtomicUnsignedInt;
|
||||
|
||||
|
||||
#ifdef __INTEL_COMPILER
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
void spinlock(lam_lock_data_t *lockData);
|
||||
int spintrylock(lam_lock_data_t *lockData);
|
||||
int fetchNadd(volatile int *addr, int inc);
|
||||
int fetchNset(volatile int *addr, int setValue);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#else
|
||||
|
||||
/*
|
||||
* Spin until I can get the lock
|
||||
*/
|
||||
INLINE void spinlock(lam_lock_data_t *lockData)
|
||||
{
|
||||
|
||||
__asm__ __volatile__ (
|
||||
"mov r30=1\n"
|
||||
"mov ar.ccv=r0\n"
|
||||
";;\n"
|
||||
"cmpxchg4.acq r30=[%0],r30,ar.ccv\n"
|
||||
";;\n"
|
||||
"cmp.ne p15,p0=r30,r0\n"
|
||||
"(p15) br.call.spnt.few b7=ia64_spinlock_contention\n"
|
||||
";;\n"
|
||||
"1:\n" /* force a new bundle */
|
||||
:: "r"(*lockData)
|
||||
: "ar.ccv", "ar.pfs", "b7", "p15", "r28", "r29", "r30", "memory");
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine tries once to obtain the lock
|
||||
*/
|
||||
INLINE int spintrylock(lam_lock_data_t *lockData)
|
||||
{
|
||||
|
||||
int gotLock;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
"mov ar.ccv=r0\n"
|
||||
";;\n"
|
||||
"cmpxchg4.acq %0=[%2],%1,ar.ccv\n"
|
||||
: "=r"(gotLock) : "r"(1), "r"(&(lockData)->data.lockData_m) : "ar.ccv", "memory");
|
||||
|
||||
return gotLock;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* atomically add a constant to the input integer returning the
|
||||
* previous value
|
||||
*/
|
||||
|
||||
INLINE int fetchNadd(volatile int *addr, int inc)
|
||||
{
|
||||
int inputValue;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
"fetchadd4.rel %0=[%1],%2" \
|
||||
: "=r"(*addr) : "r"(inputValue), "i"(inc) : "memory");
|
||||
|
||||
return (inputValue);
|
||||
}
|
||||
|
||||
|
||||
INLINE int fetchNset(volatile int *addr, int setValue)
|
||||
{
|
||||
int inputValue;
|
||||
|
||||
__asm__ __volatile__ (
|
||||
"xchg4 %0=[%1],%2" \
|
||||
: "=r"(*addr) : "r"(inputValue), "i"(setValue) : "memory");
|
||||
|
||||
return (inputValue);
|
||||
}
|
||||
|
||||
#endif /* __INTEL_COMPILER */
|
||||
|
||||
/*
|
||||
* Clear the lock
|
||||
*/
|
||||
INLINE void spinunlock(lam_lock_data_t *lockData)
|
||||
{
|
||||
lockData->data.lockData_m = LOCK_UNLOCKED;
|
||||
}
|
||||
|
||||
INLINE unsigned long long fetchNaddLong(bigAtomicUnsignedInt *addr,
|
||||
int inc)
|
||||
{
|
||||
unsigned long long returnValue;
|
||||
|
||||
spinlock(&(addr->lock));
|
||||
returnValue = addr->data;
|
||||
(addr->data) += inc;
|
||||
spinunlock(&(addr->lock));
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
INLINE unsigned long long fetchNsetLong(bigAtomicUnsignedInt *addr,
|
||||
unsigned long long val)
|
||||
{
|
||||
unsigned long long returnValue;
|
||||
|
||||
spinlock(&(addr->lock));
|
||||
returnValue = addr->data;
|
||||
addr->data = val;
|
||||
spinunlock(&(addr->lock));
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
INLINE unsigned long long fetchNaddLongNoLock(bigAtomicUnsignedInt *addr,
|
||||
int inc)
|
||||
{
|
||||
unsigned long long returnValue;
|
||||
|
||||
returnValue = addr->data;
|
||||
addr->data += inc;
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
INLINE void setBigAtomicUnsignedInt(bigAtomicUnsignedInt *addr,
|
||||
unsigned long long value)
|
||||
{
|
||||
addr->data = value;
|
||||
addr->lock.data.lockData_m = LOCK_UNLOCKED;
|
||||
}
|
||||
|
||||
#endif /* LINUX_IA64_ATOMIC_H_INCLUDED */
|
71
src/lam/os/linux/ia64/lock.s
Обычный файл
71
src/lam/os/linux/ia64/lock.s
Обычный файл
@ -0,0 +1,71 @@
|
||||
#include <asm.h>
|
||||
|
||||
.text
|
||||
|
||||
.global spinlock
|
||||
|
||||
spinlock:
|
||||
push %ebp
|
||||
mov %esp,%ebp
|
||||
mov 0x8(%ebp),%eax
|
||||
cmpl $0x1,(%eax)
|
||||
jl 2f
|
||||
1:
|
||||
lock decl (%eax)
|
||||
jz 3f
|
||||
2:
|
||||
cmpl $0x1,(%eax)
|
||||
jl 2b
|
||||
jmp 1b
|
||||
3:
|
||||
pop %ebp
|
||||
ret
|
||||
|
||||
.global spintrylock
|
||||
|
||||
spintrylock:
|
||||
push %ebp
|
||||
mov %esp,%ebp
|
||||
sub $0x4,%esp
|
||||
mov 0x8(%ebp),%edx
|
||||
mov $0x0,%eax
|
||||
cmpl $0x1,(%edx)
|
||||
jl 1f
|
||||
lock decl (%edx)
|
||||
js 1f
|
||||
mov $0x1,%eax
|
||||
jmp 2f
|
||||
1:
|
||||
mov $0x0,%eax
|
||||
2:
|
||||
mov %eax,0xfffffffc(%ebp)
|
||||
leave
|
||||
ret
|
||||
|
||||
.global fetchNadd
|
||||
|
||||
fetchNadd:
|
||||
push %ebp
|
||||
mov %esp,%ebp
|
||||
sub $0x4,%esp
|
||||
mov 0x8(%ebp),%edx
|
||||
mov 0xc(%ebp),%eax
|
||||
lock xadd %eax,(%edx)
|
||||
mov %eax,0xfffffffc(%ebp)
|
||||
leave
|
||||
ret
|
||||
|
||||
.global fetchNset
|
||||
|
||||
fetchNset:
|
||||
push %ebp
|
||||
mov %esp,%ebp
|
||||
sub $0x4,%esp
|
||||
mov 0x8(%ebp),%edx
|
||||
mov 0xc(%ebp),%eax
|
||||
lock xchg %eax,(%edx)
|
||||
mov %eax,0xfffffffc(%ebp)
|
||||
leave
|
||||
ret
|
||||
|
||||
|
40
src/lam/os/linux/ia64/smp_dev_params.h
Обычный файл
40
src/lam/os/linux/ia64/smp_dev_params.h
Обычный файл
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
static const int LogBase2PageSize = 14;
|
||||
static const int SMPPageSize = 1 << LogBase2PageSize;
|
||||
static const int LogBase2ChunkSize = 16;
|
||||
static const int NumMemoryBuckets = 3;
|
||||
static const int MProt = MMAP_SHARED_PROT;
|
||||
static const int MFlags = MMAP_SHARED_FLAGS;
|
||||
static const int PagesPerDevice = 2048;
|
||||
static const int LogBase2MaxPoolSize = 32;
|
||||
static const int MaxStkElements = 32768;
|
||||
static const bool ZeroAllocBase = false;
|
70
src/lam/os/linux/ulm_os.h
Обычный файл
70
src/lam/os/linux/ulm_os.h
Обычный файл
@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
// ulm_os.h - This file contains LINUX OS dependent definitions.
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#ifdef __linux__
|
||||
|
||||
#define RESTRICT_MACRO __restrict__
|
||||
|
||||
#ifdef __i386
|
||||
#define PAGESIZE 4096
|
||||
#define SMPPAGESIZE 4096
|
||||
#define intwordaligned(a) ( ( ((long)(a)&3L) == 0L) ? 1 : 0 )
|
||||
#define MEMCOPY_FUNC bcopy
|
||||
#define SMPFirstFragPayload 3496
|
||||
#define SMPSecondFragPayload 8192
|
||||
#define CACHE_ALIGNMENT 128
|
||||
|
||||
#else
|
||||
#ifdef __ia64
|
||||
#define PAGESIZE 16384
|
||||
#define SMPPAGESIZE 16384
|
||||
#define CACHE_ALIGNMENT 128
|
||||
#define intwordaligned(a) ( ( ((long)(a)&3L) == 0L) ? 1 : 0 )
|
||||
|
||||
#else
|
||||
#ifdef __alpha
|
||||
#define PAGESIZE 8192
|
||||
#define SMPPAGESIZE 8192
|
||||
#define CACHE_ALIGNMENT 128
|
||||
#define intwordaligned(a) ( ( ((long long)(a)&3L) == 0L) ? 1 : 0 )
|
||||
|
||||
#else
|
||||
#error
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#else
|
||||
#error
|
||||
#endif
|
221
src/lam/os/linux/x86_64/atomic.h
Обычный файл
221
src/lam/os/linux/x86_64/atomic.h
Обычный файл
@ -0,0 +1,221 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
|
||||
|
||||
#ifndef LINUX_X86_64_ATOMIC_H_INCLUDED
|
||||
#define LINUX_X86_64_ATOMIC_H_INCLUDED
|
||||
|
||||
/*
|
||||
* Lock structure
|
||||
*/
|
||||
|
||||
enum { LOCK_UNLOCKED = 1 };
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
volatile int lockData_m;
|
||||
char padding[4];
|
||||
} data;
|
||||
} lam_lock_data_t;
|
||||
|
||||
|
||||
/*
|
||||
* 64 bit integer
|
||||
*/
|
||||
typedef struct {
|
||||
lam_lock_data_t lock;
|
||||
volatile unsigned long long data;
|
||||
} bigAtomicUnsignedInt;
|
||||
|
||||
/*
|
||||
#ifdef __INTEL_COMPILER
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
void spinlock(lam_lock_data_t *lockData);
|
||||
int spintrylock(lam_lock_data_t *lockData);
|
||||
int fetchNadd(volatile int *addr, int inc);
|
||||
int fetchNset(volatile int *addr, int setValue);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#else
|
||||
*/
|
||||
|
||||
/*
|
||||
* Spin until I can get the lock
|
||||
*/
|
||||
INLINE void spinlock(lam_lock_data_t *lockData)
|
||||
{
|
||||
__asm__ __volatile__(
|
||||
"cmp $1, %0\n"
|
||||
"jl 2f\n"
|
||||
"\n1: "
|
||||
"lock ; decl %0\n"
|
||||
"jz 3f\n"
|
||||
"2:\n"
|
||||
"cmp $1, %0\n"
|
||||
"jl 2b\n"
|
||||
"jmp 1b\n"
|
||||
"3:\n"
|
||||
: "=m" (lockData->data.lockData_m) : : "memory");
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine tries once to obtain the lock
|
||||
*/
|
||||
INLINE int spintrylock(lam_lock_data_t *lockData)
|
||||
{
|
||||
int gotLock;
|
||||
|
||||
__asm__ __volatile__(
|
||||
"mov %2, %1\n"
|
||||
"cmp $1, %0\n"
|
||||
"jl 1f\n"
|
||||
"lock ; decl %0\n"
|
||||
"js 1f\n"
|
||||
"mov $1, %1\n"
|
||||
"jmp 2f\n"
|
||||
"1:\n"
|
||||
"mov $0, %1\n"
|
||||
"2:"
|
||||
: "=m" (lockData->data.lockData_m),
|
||||
#ifdef __INTEL_COMPILER
|
||||
"=&r" (gotLock) : "r" (0) : "memory");
|
||||
#else
|
||||
"=r" (gotLock) : "r" (0) : "memory");
|
||||
#endif
|
||||
|
||||
return gotLock;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* atomically add a constant to the input integer returning the
|
||||
* previous value
|
||||
*/
|
||||
INLINE int fetchNadd(volatile int *addr, int inc)
|
||||
{
|
||||
int inputValue;
|
||||
__asm__ __volatile__(
|
||||
" mov %2, %1\n" \
|
||||
"lock ; xadd %1, %0\n"
|
||||
#ifdef __INTEL_COMPILER
|
||||
: "=m" (*addr), "=&r" (inputValue) : "r" (inc) : "memory");
|
||||
#else
|
||||
: "=m" (*addr), "=r" (inputValue) : "r" (inc) : "memory");
|
||||
#endif
|
||||
|
||||
return (inputValue);
|
||||
}
|
||||
|
||||
|
||||
INLINE int fetchNset(volatile int *addr, int setValue)
|
||||
{
|
||||
int inputValue;
|
||||
|
||||
__asm__ __volatile__(
|
||||
" mov %2, %1\n" \
|
||||
"lock ; xchg %1, %0\n"
|
||||
#ifdef __INTEL_COMPILER
|
||||
: "=m" (*addr), "=&r" (inputValue) : "r" (setValue) : "memory");
|
||||
#else
|
||||
: "=m" (*addr), "=r" (inputValue) : "r" (setValue) : "memory");
|
||||
#endif
|
||||
|
||||
return (inputValue);
|
||||
}
|
||||
|
||||
//#endif /* __INTEL_COMPILER */
|
||||
|
||||
|
||||
/*
|
||||
* Clear the lock
|
||||
*/
|
||||
INLINE void spinunlock(lam_lock_data_t *lockData)
|
||||
{
|
||||
lockData->data.lockData_m = 1;
|
||||
}
|
||||
|
||||
|
||||
INLINE unsigned long long fetchNaddLong(bigAtomicUnsignedInt *addr,
|
||||
int inc)
|
||||
{
|
||||
unsigned long long returnValue;
|
||||
|
||||
spinlock(&(addr->lock));
|
||||
returnValue = addr->data;
|
||||
(addr->data) += inc;
|
||||
spinunlock(&(addr->lock));
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
INLINE unsigned long long fetchNsetLong(bigAtomicUnsignedInt *addr,
|
||||
unsigned long long val)
|
||||
{
|
||||
unsigned long long returnValue;
|
||||
|
||||
spinlock(&(addr->lock));
|
||||
returnValue = addr->data;
|
||||
addr->data = val;
|
||||
spinunlock(&(addr->lock));
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
|
||||
INLINE unsigned long long fetchNaddLongNoLock(bigAtomicUnsignedInt *addr,
|
||||
int inc)
|
||||
{
|
||||
unsigned long long returnValue;
|
||||
|
||||
returnValue = addr->data;
|
||||
addr->data += inc;
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
INLINE void setBigAtomicUnsignedInt(bigAtomicUnsignedInt *addr,
|
||||
unsigned long long value)
|
||||
{
|
||||
addr->data = value;
|
||||
addr->lock.data.lockData_m = LOCK_UNLOCKED;
|
||||
}
|
||||
|
||||
#endif /* LINUX_X86_64_ATOMIC_H_INCLUDED */
|
40
src/lam/os/linux/x86_64/smp_dev_params.h
Обычный файл
40
src/lam/os/linux/x86_64/smp_dev_params.h
Обычный файл
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
static const int LogBase2PageSize = 12;
|
||||
static const int SMPPageSize = 1 << LogBase2PageSize;
|
||||
static const int LogBase2ChunkSize = 16;
|
||||
static const int NumMemoryBuckets = 3;
|
||||
static const int MProt = MMAP_SHARED_PROT;
|
||||
static const int MFlags = MMAP_SHARED_FLAGS;
|
||||
static const int PagesPerDevice = 2048;
|
||||
static const int LogBase2MaxPoolSize = 32;
|
||||
static const int MaxStkElements = 32768;
|
||||
static const bool ZeroAllocBase = false;
|
58
src/lam/os/numa.h
Обычный файл
58
src/lam/os/numa.h
Обычный файл
@ -0,0 +1,58 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of
|
||||
* California. This material was produced under U.S. Government
|
||||
* contract W-7405-ENG-36 for Los Alamos National Laboratory, which is
|
||||
* operated by the University of California for the U.S. Department of
|
||||
* Energy. The Government is granted for itself and others acting on
|
||||
* its behalf a paid-up, nonexclusive, irrevocable worldwide license
|
||||
* in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years
|
||||
* after October 10,2002 subject to additional five-year worldwide
|
||||
* renewals, the Government is granted for itself and others acting on
|
||||
* its behalf a paid-up, nonexclusive, irrevocable worldwide license
|
||||
* in this material to reproduce, prepare derivative works, distribute
|
||||
* copies to the public, perform publicly and display publicly, and to
|
||||
* permit others to do so. NEITHER THE UNITED STATES NOR THE UNITED
|
||||
* STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF CALIFORNIA, NOR
|
||||
* ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR
|
||||
* ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT,
|
||||
* OR PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE
|
||||
* PRIVATELY OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it
|
||||
* and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or any later version. Accordingly, this
|
||||
* program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
#include "lam/base/object.h"
|
||||
|
||||
typedef int affinity_t;
|
||||
|
||||
#ifndef ENABLE_NUMA
|
||||
|
||||
static inline int lam_set_affinity(void *addr, size_t size, affinity_t affinity)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
static inline int lam_get_cpu_set(void)
|
||||
{
|
||||
return LAM_SUCCESS;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
# OS / architecture specific implementation elsewhere
|
||||
|
||||
int lam_set_affinity(void *addr, size_t size, affinity_t affinity);
|
||||
|
||||
int lam_get_cpu_set(void)
|
||||
|
||||
#endif
|
223
src/lam/os/tru64/atomic.h
Обычный файл
223
src/lam/os/tru64/atomic.h
Обычный файл
@ -0,0 +1,223 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of
|
||||
* California. This material was produced under U.S. Government
|
||||
* contract W-7405-ENG-36 for Los Alamos National Laboratory, which is
|
||||
* operated by the University of California for the U.S. Department of
|
||||
* Energy. The Government is granted for itself and others acting on
|
||||
* its behalf a paid-up, nonexclusive, irrevocable worldwide license
|
||||
* in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years
|
||||
* after October 10,2002 subject to additional five-year worldwide
|
||||
* renewals, the Government is granted for itself and others acting on
|
||||
* its behalf a paid-up, nonexclusive, irrevocable worldwide license
|
||||
* in this material to reproduce, prepare derivative works, distribute
|
||||
* copies to the public, perform publicly and display publicly, and to
|
||||
* permit others to do so. NEITHER THE UNITED STATES NOR THE UNITED
|
||||
* STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF CALIFORNIA, NOR
|
||||
* ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR
|
||||
* ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT,
|
||||
* OR PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE
|
||||
* PRIVATELY OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it
|
||||
* and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or any later version. Accordingly, this
|
||||
* program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
#ifndef TRU64_ATOMIC_H_INCLUDED
|
||||
#define TRU64_ATOMIC_H_INCLUDED
|
||||
|
||||
#include <c_asm.h>
|
||||
#include <regdef.h>
|
||||
|
||||
#define mb() asm("mb\n");
|
||||
|
||||
#define rmb() asm("mb\n");
|
||||
|
||||
#define wmb() asm("wmb\n");
|
||||
|
||||
/*
|
||||
* Lock structure
|
||||
*/
|
||||
enum { LOCK_UNLOCKED = 0 };
|
||||
|
||||
typedef struct {
|
||||
union {
|
||||
volatile int lockData_m;
|
||||
char padding[4];
|
||||
} data;
|
||||
} lam_lock_data_t;
|
||||
|
||||
/*
|
||||
* 64 bit integer
|
||||
*/
|
||||
typedef volatile unsigned long long bigAtomicUnsignedInt;
|
||||
|
||||
|
||||
static inline void spinlock(lam_lock_data_t *lock)
|
||||
{
|
||||
asm("loop:\n"
|
||||
" ldl %t1, (%a0)\n"
|
||||
" blbs %t1, already_set\n"
|
||||
" ldl_l %t1, (%a0)\n"
|
||||
" blbs %t1, already_set\n"
|
||||
" or %t1, 1, %t2\n"
|
||||
" stl_c %t2, (%a0)\n"
|
||||
" beq %t2, stl_c_failed\n"
|
||||
" br lock_set\n"
|
||||
"already_set:\n"
|
||||
"stl_c_failed:\n"
|
||||
" br loop\n"
|
||||
"lock_set:\n"
|
||||
" mb\n",
|
||||
&(lock->data.lockData_m));
|
||||
}
|
||||
|
||||
/*
|
||||
* locked load - store conditional pair can fail for
|
||||
* any number of implementation dependent reasons, so
|
||||
* we try up to 4 times before declaring failure to
|
||||
* obtain the lock...
|
||||
*/
|
||||
|
||||
static inline int spintrylock(lam_lock_data_t *lock)
|
||||
{
|
||||
int result = asm("mov %zero, %t3\n"
|
||||
"loop:\n"
|
||||
" ldl %t1, (%a0)\n"
|
||||
" blbs %t1, already_set\n"
|
||||
" ldl_l %t1, (%a0)\n"
|
||||
" blbs %t1, already_set\n"
|
||||
" or %t1, 1, %t2\n"
|
||||
" stl_c %t2, (%a0)\n"
|
||||
" beq %t2, stl_c_failed\n"
|
||||
" mov 1, %v0\n"
|
||||
" br lock_set\n"
|
||||
"stl_c_failed:\n"
|
||||
" addl %t3, 1, %t3\n"
|
||||
" mov %t3, %t4\n"
|
||||
" subl %t4, 3, %t4\n"
|
||||
" ble %t4, loop\n"
|
||||
"already_set:\n"
|
||||
" mov %zero, %v0\n"
|
||||
"lock_set:\n"
|
||||
" mb\n",
|
||||
&(lock->data.lockData_m));
|
||||
return result;
|
||||
}
|
||||
|
||||
/* alpha specific unlock function - need the memory barrier */
|
||||
static inline void spinunlock(lam_lock_data_t *lock)
|
||||
{
|
||||
asm("mb");
|
||||
lock->data.lockData_m = LOCK_UNLOCKED;
|
||||
}
|
||||
|
||||
static inline int fetchNadd(volatile int *addr, int inc)
|
||||
{
|
||||
int oldval;
|
||||
|
||||
oldval = asm("try_again:\n"
|
||||
" ldl_l %v0, (%a0)\n"
|
||||
" addl %v0, %a1, %t1\n"
|
||||
" stl_c %t1, (%a0)\n"
|
||||
" beq %t1, no_store\n"
|
||||
" br store\n"
|
||||
"no_store:\n"
|
||||
" br try_again\n"
|
||||
"store:\n"
|
||||
" mb\n",
|
||||
addr, inc);
|
||||
|
||||
return oldval;
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned long long fetchNaddLong(bigAtomicUnsignedInt *addr,
|
||||
int inc)
|
||||
{
|
||||
unsigned long long oldval;
|
||||
|
||||
oldval = asm("try_again:\n"
|
||||
" ldq_l %v0, (%a0)\n"
|
||||
" addq %v0, %a1, %t1\n"
|
||||
" stq_c %t1, (%a0)\n"
|
||||
" beq %t1, no_store\n"
|
||||
" br store\n"
|
||||
"no_store:\n"
|
||||
" br try_again\n"
|
||||
"store:\n"
|
||||
" mb\n",
|
||||
addr, inc);
|
||||
|
||||
return oldval;
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned long long
|
||||
fetchNaddLongNoLock(bigAtomicUnsignedInt *addr, int inc)
|
||||
{
|
||||
unsigned long long oldval;
|
||||
|
||||
oldval = *addr;
|
||||
*addr += inc;
|
||||
|
||||
return oldval;
|
||||
}
|
||||
|
||||
|
||||
static inline int fetchNset(volatile int *addr, int val)
|
||||
{
|
||||
int oldval;
|
||||
|
||||
oldval = asm("try_again:\n"
|
||||
" ldl_l %v0, (%a0)\n"
|
||||
" mov %a1, %t1\n"
|
||||
" stl_c %t1, (%a0)\n"
|
||||
" beq %t1, no_store\n"
|
||||
" br store\n"
|
||||
"no_store:\n"
|
||||
" br try_again\n"
|
||||
"store:\n"
|
||||
" mb\n",
|
||||
addr, val);
|
||||
|
||||
return oldval;
|
||||
}
|
||||
|
||||
|
||||
static inline unsigned long long fetchNsetLong(bigAtomicUnsignedInt *addr,
|
||||
unsigned long long val)
|
||||
{
|
||||
unsigned long long oldval;
|
||||
|
||||
oldval = asm("try_again:\n"
|
||||
" ldq_l %v0, (%a0)\n"
|
||||
" mov %a1, %t1\n"
|
||||
" stq_c %t1, (%a0)\n"
|
||||
" beq %t1, no_store\n"
|
||||
" br store\n"
|
||||
"no_store:\n"
|
||||
" br try_again\n"
|
||||
"store:\n"
|
||||
" mb\n",
|
||||
addr, val);
|
||||
|
||||
return oldval;
|
||||
}
|
||||
|
||||
|
||||
static inline void setBigAtomicUnsignedInt(bigAtomicUnsignedInt *addr,
|
||||
unsigned long long val)
|
||||
{
|
||||
*addr = val;
|
||||
}
|
||||
|
||||
#endif /* TRU64_ATOMIC_H_INCLUDED */
|
40
src/lam/os/tru64/smp_dev_params.h
Обычный файл
40
src/lam/os/tru64/smp_dev_params.h
Обычный файл
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
static const int LogBase2PageSize = 13;
|
||||
static const int SMPPageSize = 1 << LogBase2PageSize;
|
||||
static const int LogBase2ChunkSize = 16;
|
||||
static const int NumMemoryBuckets = 3;
|
||||
static const int MProt = MMAP_SHARED_PROT;
|
||||
static const int MFlags = MMAP_SHARED_FLAGS;
|
||||
static const int PagesPerDevice = 2048;
|
||||
static const int LogBase2MaxPoolSize = 32;
|
||||
static const int MaxStkElements = 32768;
|
||||
static const bool ZeroAllocBase = false;
|
56
src/lam/os/tru64/ulm_os.h
Обычный файл
56
src/lam/os/tru64/ulm_os.h
Обычный файл
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
// ulm_os.h - This file contains IRIX OS dependent definitions.
|
||||
|
||||
// memory page size
|
||||
|
||||
#define LOG2PAGESIZE 13
|
||||
#define SMPPAGESIZE (1 << LOG2PAGESIZE)
|
||||
|
||||
#ifndef PAGESIZE
|
||||
#define PAGESIZE 8192
|
||||
#endif
|
||||
|
||||
#define CACHE_ALIGNMENT 64
|
||||
|
||||
// if cxx is invoked with -model ansi -accept restrict_keyword
|
||||
#ifdef __MODEL_ANSI
|
||||
#define RESTRICT_MACRO __restrict
|
||||
#else
|
||||
#define RESTRICT_MACRO
|
||||
#endif
|
||||
|
||||
#define intwordaligned(a) ( ( ((long long)(a)&3L) == 0L) ? 1 : 0 )
|
||||
|
||||
#define MEMCOPY_FUNC bcopy
|
||||
#define SMPSecondFragPayload 65536
|
||||
#define SMPFirstFragPayload 3496
|
||||
|
35
src/lam/threads/Makefile.am
Обычный файл
35
src/lam/threads/Makefile.am
Обычный файл
@ -0,0 +1,35 @@
|
||||
#
|
||||
# Copyright 2002-2003. The Regents of the University of California. This material
|
||||
# was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
# National Laboratory, which is operated by the University of California for
|
||||
# the U.S. Department of Energy. The Government is granted for itself and
|
||||
# others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
# license in this material to reproduce, prepare derivative works, and
|
||||
# perform publicly and display publicly. Beginning five (5) years after
|
||||
# October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
# Government is granted for itself and others acting on its behalf a paid-up,
|
||||
# nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
# prepare derivative works, distribute copies to the public, perform publicly
|
||||
# and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
# STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
# CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
# IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
# COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
# PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
# OWNED RIGHTS.
|
||||
#
|
||||
# Additionally, this program is free software; you can distribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public License as
|
||||
# published by the Free Software Foundation; either version 2 of the License,
|
||||
# or any later version. Accordingly, this program is distributed in the hope
|
||||
# that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
|
||||
include $(top_srcdir)/config/Makefile.options
|
||||
|
||||
lib_LTLIBRARIES = libthreads.la
|
||||
|
||||
libthreads_la_SOURCES = \
|
||||
thread.c
|
40
src/lam/threads/mutex.h
Обычный файл
40
src/lam/threads/mutex.h
Обычный файл
@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
#ifndef _MUTEX_H_
|
||||
#define _MUTEX_H_
|
||||
|
||||
#if defined(USE_SPINWAIT)
|
||||
#include "lam/threads/mutex_spinwait.h"
|
||||
#else
|
||||
#include "lam/threads/mutex_spinlock.h"
|
||||
#endif
|
||||
#endif
|
||||
|
43
src/lam/threads/mutex_spinlock.h
Обычный файл
43
src/lam/threads/mutex_spinlock.h
Обычный файл
@ -0,0 +1,43 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
#ifndef _MUTEX_SPINLOCK_
|
||||
#define _MUTEX_SPINLOCK_
|
||||
|
||||
#include "lam/os/atomic.h"
|
||||
typedef lam_lock_data_t lam_mutex_t;
|
||||
|
||||
#define lam_mtx_init(m) spinunlock(m)
|
||||
#define lam_mtx_lock(m) spinlock(m)
|
||||
#define lam_mtx_trylock(m) spintrylock(m)
|
||||
#define lam_mtx_unlock(m) spinunlock(m)
|
||||
|
||||
#endif
|
||||
|
92
src/lam/threads/mutex_spinwait.h
Обычный файл
92
src/lam/threads/mutex_spinwait.h
Обычный файл
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
#ifndef _MUTEX_SPINWAIT_
|
||||
#define _MUTEX_SPINWAIT_
|
||||
|
||||
#include <pthread.h>
|
||||
#include "os/atomic.h"
|
||||
|
||||
#ifndef MUTEX_SPINWAIT
|
||||
#define MUTEX_SPINWAIT 10000
|
||||
#endif
|
||||
|
||||
|
||||
typedef struct lam_mutex {
|
||||
volatile int mtx_spinlock;
|
||||
volatile int mtx_waiting;
|
||||
pthread_mutex_t mtx_lock;
|
||||
pthread_cond_t mtx_cond;
|
||||
} lam_mutex_t;
|
||||
|
||||
|
||||
static inline void lam_mtx_init(lam_mutex_t* m)
|
||||
{
|
||||
m->mtx_spinlock = 0;
|
||||
m->mtx_waiting = 0;
|
||||
pthread_mutex_init(&m->mtx_lock, 0);
|
||||
pthread_cond_init(&m->mtx_cond, 0);
|
||||
}
|
||||
|
||||
|
||||
static inline void lam_mtx_lock(lam_mutex_t* m)
|
||||
{
|
||||
unsigned long cnt = 0;
|
||||
int locked;
|
||||
|
||||
fetchNadd(&m->mtx_waiting, 1);
|
||||
while((locked = fetchNset(&m->mtx_spinlock, 1)) == 1 && cnt++ < MUTEX_SPINWAIT)
|
||||
;
|
||||
if(locked) {
|
||||
pthread_mutex_lock(&m->mtx_lock);
|
||||
while(fetchNset(&m->mtx_spinlock, 1) == 1)
|
||||
pthread_cond_wait(&m->mtx_cond, &m->mtx_lock);
|
||||
pthread_mutex_unlock(&m->mtx_lock);
|
||||
}
|
||||
fetchNadd(&m->mtx_waiting, -1);
|
||||
}
|
||||
|
||||
|
||||
static inline int lam_mtx_trylock(lam_mutex_t* m)
|
||||
{
|
||||
return (fetchNset(&m->mtx_spinlock, 1) == 0);
|
||||
}
|
||||
|
||||
|
||||
static inline void lam_mtx_unlock(lam_mutex_t* m)
|
||||
{
|
||||
fetchNset(&m->mtx_spinlock, 0);
|
||||
if(m->mtx_waiting) {
|
||||
pthread_cond_signal(&m->mtx_cond);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
32
src/lam/threads/thread.c
Обычный файл
32
src/lam/threads/thread.c
Обычный файл
@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
#include "lam/threads/thread.h"
|
||||
|
48
src/lam/threads/thread.h
Обычный файл
48
src/lam/threads/thread.h
Обычный файл
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
#ifndef THREAD_H
|
||||
#define THREAD_H
|
||||
|
||||
#include "lam/base/object.h"
|
||||
|
||||
typedef struct lam_thread
|
||||
{
|
||||
lam_object_t super;
|
||||
void (*thr_run)(lam_object_t*);
|
||||
} lam_thread_t;
|
||||
|
||||
|
||||
void lam_thr_init(lam_thread_t *a_thread);
|
||||
lam_thread_t *lam_thr_create(lam_object_t *arg);
|
||||
|
||||
#endif
|
||||
|
||||
|
36
src/lam/util/Makefile.am
Обычный файл
36
src/lam/util/Makefile.am
Обычный файл
@ -0,0 +1,36 @@
|
||||
#
|
||||
# Copyright 2002-2003. The Regents of the University of California. This material
|
||||
# was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
# National Laboratory, which is operated by the University of California for
|
||||
# the U.S. Department of Energy. The Government is granted for itself and
|
||||
# others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
# license in this material to reproduce, prepare derivative works, and
|
||||
# perform publicly and display publicly. Beginning five (5) years after
|
||||
# October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
# Government is granted for itself and others acting on its behalf a paid-up,
|
||||
# nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
# prepare derivative works, distribute copies to the public, perform publicly
|
||||
# and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
# STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
# CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
# IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
# COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
# PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
# OWNED RIGHTS.
|
||||
#
|
||||
# Additionally, this program is free software; you can distribute it and/or
|
||||
# modify it under the terms of the GNU Lesser General Public License as
|
||||
# published by the Free Software Foundation; either version 2 of the License,
|
||||
# or any later version. Accordingly, this program is distributed in the hope
|
||||
# that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
|
||||
include $(top_srcdir)/config/Makefile.options
|
||||
|
||||
lib_LTLIBRARIES = libutil.la
|
||||
|
||||
libutil_la_SOURCES = \
|
||||
lam_log.c \
|
||||
reactor.c
|
107
src/lam/util/lam_log.c
Обычный файл
107
src/lam/util/lam_log.c
Обычный файл
@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
#include "lam_log.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#define FILE_LINE_MAX 255
|
||||
static char file_line[FILE_LINE_MAX + 1] = "";
|
||||
|
||||
void _lam_log(FILE *fd, const char *fmt, va_list ap)
|
||||
{
|
||||
/* Write to a file descriptor and the log file */
|
||||
|
||||
if (fd != NULL) {
|
||||
fprintf(fd, file_line);
|
||||
vfprintf(fd, fmt, ap);
|
||||
fflush(fd);
|
||||
}
|
||||
|
||||
file_line[0] = '\0';
|
||||
}
|
||||
|
||||
void _lam_print(FILE * fd, const char *fmt, va_list ap)
|
||||
{
|
||||
/* Write to a file descriptor (usually stdout or stderr) */
|
||||
|
||||
if (fd != NULL) {
|
||||
fprintf(fd, file_line);
|
||||
vfprintf(fd, fmt, ap);
|
||||
fflush(fd);
|
||||
}
|
||||
file_line[0] = '\0';
|
||||
}
|
||||
|
||||
void _lam_set_file_line(const char *name, int line)
|
||||
{
|
||||
sprintf(file_line, "LAM/MPI:%s:%d: ", name, line);
|
||||
}
|
||||
|
||||
void _lam_err(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
_lam_log(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
void _lam_warn(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
_lam_log(stderr, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void _lam_dbg(const char *fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
_lam_log(stdout, fmt, ap);
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
void _lam_exit(int status, const char* fmt, ...)
|
||||
{
|
||||
va_list ap;
|
||||
|
||||
if (fmt) {
|
||||
va_start(ap, fmt);
|
||||
if (status != 0) {
|
||||
_lam_log(stderr, fmt, ap);
|
||||
}
|
||||
else {
|
||||
_lam_print(stdout, fmt, ap);
|
||||
}
|
||||
va_end(ap);
|
||||
}
|
||||
|
||||
exit(status);
|
||||
}
|
81
src/lam/util/lam_log.h
Обычный файл
81
src/lam/util/lam_log.h
Обычный файл
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
#ifndef LAM_LOG_H
|
||||
#define LAM_LOG_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#define lam_dbg(x) \
|
||||
do { \
|
||||
if (OPT_DBG) { \
|
||||
_lam_set_file_line( __FILE__, __LINE__) ; \
|
||||
_lam_dbg x ; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define lam_err(x) \
|
||||
do { \
|
||||
_lam_set_file_line(__FILE__, __LINE__) ; \
|
||||
_lam_err x ; \
|
||||
} while (0)
|
||||
|
||||
#define lam_warn(x) \
|
||||
do { \
|
||||
_lam_set_file_line(__FILE__, __LINE__) ; \
|
||||
_lam_warn x ; \
|
||||
} while (0)
|
||||
|
||||
#define lam_exit(x) \
|
||||
do { \
|
||||
_lam_set_file_line(__FILE__, __LINE__) ; \
|
||||
_lam_exit x ; \
|
||||
} while (0)
|
||||
|
||||
/* Error condition */
|
||||
void _lam_err(const char* fmt, ...);
|
||||
|
||||
/* Warning condition */
|
||||
void _lam_warn(const char* fmt, ...);
|
||||
|
||||
/* Debugging message */
|
||||
void _lam_dbg(const char* fmt, ...);
|
||||
|
||||
/* Exit with error message */
|
||||
void _lam_exit(int status, const char* fmt, ...);
|
||||
|
||||
/* Set file and line info */
|
||||
void _lam_set_file_line(const char *file, int lineno);
|
||||
|
||||
|
||||
#endif /* LAM_LOG_H */
|
||||
|
||||
|
97
src/lam/util/malloc.h
Обычный файл
97
src/lam/util/malloc.h
Обычный файл
@ -0,0 +1,97 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of California. This material
|
||||
* was produced under U.S. Government contract W-7405-ENG-36 for Los Alamos
|
||||
* National Laboratory, which is operated by the University of California for
|
||||
* the U.S. Department of Energy. The Government is granted for itself and
|
||||
* others acting on its behalf a paid-up, nonexclusive, irrevocable worldwide
|
||||
* license in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years after
|
||||
* October 10,2002 subject to additional five-year worldwide renewals, the
|
||||
* Government is granted for itself and others acting on its behalf a paid-up,
|
||||
* nonexclusive, irrevocable worldwide license in this material to reproduce,
|
||||
* prepare derivative works, distribute copies to the public, perform publicly
|
||||
* and display publicly, and to permit others to do so. NEITHER THE UNITED
|
||||
* STATES NOR THE UNITED STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF
|
||||
* CALIFORNIA, NOR ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR
|
||||
* IMPLIED, OR ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT, OR
|
||||
* PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE PRIVATELY
|
||||
* OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of the License,
|
||||
* or any later version. Accordingly, this program is distributed in the hope
|
||||
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
||||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
#ifndef _LAM_MALLOC_H_
|
||||
#define _LAM_MALLOC_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "lam_config.h"
|
||||
#include "lam/util/lam_log.h"
|
||||
|
||||
/*
|
||||
* Set LAM_MALLOC_DEBUG_LEVEL to
|
||||
* 0 for no checking
|
||||
* 1 for basic error checking
|
||||
* 2 for more error checking
|
||||
*/
|
||||
|
||||
#ifndef LAM_MALLOC_DEBUG_LEVEL
|
||||
#define LAM_MALLOC_DEBUG_LEVEL 2
|
||||
#endif
|
||||
|
||||
/*
|
||||
* malloc and free with error checking
|
||||
*/
|
||||
|
||||
static inline void *_lam_malloc(ssize_t size, int debug_level, char *file, int line)
|
||||
{
|
||||
void *addr = NULL;
|
||||
if (debug_level > 1) {
|
||||
if (size <= 0) {
|
||||
_lam_set_file_line(file, line);
|
||||
_lam_warn("Warning: ulm_malloc: Request for %ld bytes\n",
|
||||
(long) size);
|
||||
}
|
||||
}
|
||||
addr = malloc((size_t) size);
|
||||
if (debug_level > 0) {
|
||||
if (addr == NULL) {
|
||||
_lam_set_file_line(file, line);
|
||||
_lam_err("Error: ulm_malloc: Request for %ld bytes failed\n",
|
||||
(long) size);
|
||||
}
|
||||
}
|
||||
|
||||
return addr;
|
||||
}
|
||||
|
||||
static inline void _lam_free(void *addr, int debug_level, char *file, int line)
|
||||
{
|
||||
if (debug_level > 1 && addr == NULL) {
|
||||
_lam_set_file_line(file, line);
|
||||
_lam_warn("Warning: ulm_free: Invalid pointer %p\n", addr);
|
||||
return;
|
||||
}
|
||||
free(addr);
|
||||
}
|
||||
|
||||
#if LAM_MALLOC_DEBUG_LEVEL > 0
|
||||
|
||||
#define lam_malloc(SIZE) _lam_malloc(SIZE, LAM_MALLOC_DEBUG_LEVEL, __FILE__, __LINE__)
|
||||
#define lam_free(ADDR) \
|
||||
do { _lam_free((ADDR), LAM_MALLOC_DEBUG_LEVEL, __FILE__, __LINE__); ADDR = NULL; } while (0)
|
||||
|
||||
#else
|
||||
|
||||
#define lam_malloc(SIZE) malloc(SIZE)
|
||||
#define lam_free(ADDR) free(ADDR)
|
||||
|
||||
#endif
|
||||
#endif
|
316
src/lam/util/reactor.c
Обычный файл
316
src/lam/util/reactor.c
Обычный файл
@ -0,0 +1,316 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of
|
||||
* California. This material was produced under U.S. Government
|
||||
* contract W-7405-ENG-36 for Los Alamos National Laboratory, which is
|
||||
* operated by the University of California for the U.S. Department of
|
||||
* Energy. The Government is granted for itself and others acting on
|
||||
* its behalf a paid-up, nonexclusive, irrevocable worldwide license
|
||||
* in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years
|
||||
* after October 10,2002 subject to additional five-year worldwide
|
||||
* renewals, the Government is granted for itself and others acting on
|
||||
* its behalf a paid-up, nonexclusive, irrevocable worldwide license
|
||||
* in this material to reproduce, prepare derivative works, distribute
|
||||
* copies to the public, perform publicly and display publicly, and to
|
||||
* permit others to do so. NEITHER THE UNITED STATES NOR THE UNITED
|
||||
* STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF CALIFORNIA, NOR
|
||||
* ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR
|
||||
* ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT,
|
||||
* OR PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE
|
||||
* PRIVATELY OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it
|
||||
* and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or any later version. Accordingly, this
|
||||
* program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include "lam/util/reactor.h"
|
||||
|
||||
|
||||
const int LAM_NOTIFY_RECV = 1;
|
||||
const int LAM_NOTIFY_SEND = 2;
|
||||
const int LAM_NOTIFY_EXCEPT = 4;
|
||||
const int LAM_NOTIFY_ALL = 7;
|
||||
|
||||
#define MAX_DESCRIPTOR_POOL_SIZE 256
|
||||
|
||||
|
||||
lam_class_info_t lam_reactor_cls = {
|
||||
"lam_reactor_t", &object_cls, (class_init_t)lam_reactor_init,
|
||||
(class_destroy_t)lam_reactor_destroy
|
||||
};
|
||||
|
||||
lam_class_info_t lam_reactor_descriptor_cls = {
|
||||
"lam_reactor_t", &lam_dbl_item_cls, (class_init_t)lam_reactor_descriptor_init,
|
||||
(class_destroy_t)lam_reactor_descriptor_destroy
|
||||
};
|
||||
|
||||
|
||||
void lam_reactor_descriptor_init(lam_reactor_descriptor_t* rd)
|
||||
{
|
||||
lam_dbl_item_init(&rd->rd_base);
|
||||
rd->rd_base.super.obj_class = &lam_reactor_descriptor_cls;
|
||||
}
|
||||
|
||||
|
||||
void lam_reactor_descriptor_destroy(lam_reactor_descriptor_t* rd)
|
||||
{
|
||||
lam_dbl_item_destroy(&rd->rd_base);
|
||||
}
|
||||
|
||||
|
||||
static inline lam_reactor_descriptor_t* lam_reactor_get_descriptor(lam_reactor_t* r, int sd)
|
||||
{
|
||||
lam_reactor_descriptor_t *descriptor;
|
||||
if(lam_dbl_get_size(&r->r_free))
|
||||
descriptor = (lam_reactor_descriptor_t*)lam_dbl_remove_first_item(&r->r_free);
|
||||
else {
|
||||
descriptor = (lam_reactor_descriptor_t*)lam_malloc(sizeof(lam_reactor_descriptor_t));
|
||||
lam_reactor_descriptor_init(descriptor);
|
||||
}
|
||||
if(descriptor == 0) {
|
||||
lam_err(("lam_reactor_get_descriptor(): malloc(%d) failed.", sizeof(lam_reactor_descriptor_t)));
|
||||
return 0;
|
||||
}
|
||||
descriptor->rd = sd;
|
||||
descriptor->rd_flags = 0;
|
||||
descriptor->rd_recv = 0;
|
||||
descriptor->rd_send = 0;
|
||||
descriptor->rd_except = 0;
|
||||
return descriptor;
|
||||
}
|
||||
|
||||
|
||||
void lam_reactor_init(lam_reactor_t* r)
|
||||
{
|
||||
lam_obj_init(&r->r_base);
|
||||
r->r_base.obj_class = &lam_reactor_cls;
|
||||
|
||||
lam_mutex_init(&r->r_mutex);
|
||||
lam_dbl_init(&r->r_active);
|
||||
lam_dbl_init(&r->r_free);
|
||||
lam_dbl_init(&r->r_pending);
|
||||
lam_fh_init(&r->r_hash);
|
||||
lam_fh_init_with(&r->r_hash, 1024);
|
||||
|
||||
r->r_max = -1;
|
||||
r->r_run = TRUE;
|
||||
r->r_changes = 0;
|
||||
|
||||
LAM_FD_ZERO(&r->r_recv_set);
|
||||
LAM_FD_ZERO(&r->r_send_set);
|
||||
LAM_FD_ZERO(&r->r_except_set);
|
||||
}
|
||||
|
||||
|
||||
void lam_reactor_destroy(lam_reactor_t* r)
|
||||
{
|
||||
lam_dbl_destroy(&r->r_active);
|
||||
lam_dbl_destroy(&r->r_free);
|
||||
lam_dbl_destroy(&r->r_pending);
|
||||
lam_fh_destroy(&r->r_hash);
|
||||
lam_obj_destroy(&r->r_base);
|
||||
}
|
||||
|
||||
|
||||
bool_t lam_reactor_insert(lam_reactor_t* r, int sd, lam_reactor_listener_t* listener, int flags)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
if(sd < 0 || sd > LAM_FD_SETSIZE) {
|
||||
lam_err(("Reactor::insertListener(%d) invalid descriptor.\n", sd));
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
lam_mtx_lock(&r->r_mutex);
|
||||
lam_reactor_descriptor_t *descriptor = (lam_reactor_descriptor_t*)lam_dbl_remove_first(&r->r_free);
|
||||
if(descriptor == 0) {
|
||||
descriptor = lam_reactor_get_descriptor(r, sd);
|
||||
if(descriptor == 0) {
|
||||
lam_mtx_unlock(&r->r_mutex);
|
||||
return FALSE;
|
||||
}
|
||||
lam_dbl_append(&r->r_pending, &descriptor->rd_base);
|
||||
lam_fh_set_value_for_ikey(&r->r_hash,descriptor,sd);
|
||||
}
|
||||
|
||||
descriptor->rd_flags |= flags;
|
||||
if(flags & LAM_NOTIFY_RECV) {
|
||||
descriptor->rd_recv = listener;
|
||||
LAM_FD_SET(sd, &r->r_recv_set);
|
||||
}
|
||||
if(flags & LAM_NOTIFY_SEND) {
|
||||
descriptor->rd_send = listener;
|
||||
LAM_FD_SET(sd, &r->r_send_set);
|
||||
}
|
||||
if(flags & LAM_NOTIFY_EXCEPT) {
|
||||
descriptor->rd_except = listener;
|
||||
LAM_FD_SET(sd, &r->r_except_set);
|
||||
}
|
||||
r->r_changes++;
|
||||
lam_mtx_unlock(&r->r_mutex);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
bool_t lam_reactor_remove(lam_reactor_t* r, int sd, lam_reactor_listener_t* rl, int flags)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
if(sd < 0 || sd > LAM_FD_SETSIZE) {
|
||||
lam_err(("lam_reactor_remove(%d) invalid descriptor.\n", sd));
|
||||
return FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
lam_mtx_lock(&r->r_mutex);
|
||||
lam_reactor_descriptor_t* descriptor = (lam_reactor_descriptor_t*)lam_fh_get_value_for_ikey(&r->r_hash, sd);
|
||||
if(descriptor == 0) {
|
||||
lam_err(("lam_reactor_remove(%d): descriptor not registered.\n", sd));
|
||||
lam_mtx_unlock(&r->r_mutex);
|
||||
return FALSE;
|
||||
}
|
||||
descriptor->rd_flags &= ~flags;
|
||||
if(flags & LAM_NOTIFY_RECV) {
|
||||
descriptor->rd_recv = 0;
|
||||
LAM_FD_CLR(sd, &r->r_recv_set);
|
||||
}
|
||||
if(flags & LAM_NOTIFY_SEND) {
|
||||
descriptor->rd_send = 0;
|
||||
LAM_FD_CLR(sd, &r->r_send_set);
|
||||
}
|
||||
if(flags & LAM_NOTIFY_EXCEPT) {
|
||||
descriptor->rd_except = 0;
|
||||
LAM_FD_CLR(sd, &r->r_except_set);
|
||||
}
|
||||
r->r_changes++;
|
||||
lam_mtx_unlock(&r->r_mutex);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
void lam_reactor_dispatch(lam_reactor_t* r, int cnt, lam_fd_set_t* rset, lam_fd_set_t* sset, lam_fd_set_t* eset)
|
||||
{
|
||||
// walk through the active list w/out holding lock, as this thread
|
||||
// is the only one that modifies the active list. however, note
|
||||
// that the descriptor flags could have been cleared in a callback,
|
||||
// so check that the flag is still set before invoking the callbacks
|
||||
|
||||
lam_reactor_descriptor_t *descriptor;
|
||||
for(descriptor = (lam_reactor_descriptor_t*)lam_dbl_get_first(&r->r_active);
|
||||
descriptor != 0;
|
||||
descriptor = (lam_reactor_descriptor_t*)lam_dbl_get_next(descriptor)) {
|
||||
int rd = descriptor->rd;
|
||||
int flags = 0;
|
||||
if(LAM_FD_ISSET(rd, rset) && descriptor->rd_flags & LAM_NOTIFY_RECV) {
|
||||
descriptor->rd_recv->rl_recv_handler(descriptor->rd_recv, rd);
|
||||
flags |= LAM_NOTIFY_RECV;
|
||||
}
|
||||
if(LAM_FD_ISSET(rd, sset) && descriptor->rd_flags & LAM_NOTIFY_SEND) {
|
||||
descriptor->rd_send->rl_send_handler(descriptor->rd_send, rd);
|
||||
flags |= LAM_NOTIFY_SEND;
|
||||
}
|
||||
if(LAM_FD_ISSET(rd, eset) && descriptor->rd_flags & LAM_NOTIFY_EXCEPT) {
|
||||
descriptor->rd_except->rl_except_handler(descriptor->rd_except, rd);
|
||||
flags |= LAM_NOTIFY_EXCEPT;
|
||||
}
|
||||
if(flags) cnt--;
|
||||
}
|
||||
|
||||
lam_mtx_lock(&r->r_mutex);
|
||||
if(r->r_changes == 0) {
|
||||
lam_mtx_unlock(&r->r_mutex);
|
||||
return;
|
||||
}
|
||||
|
||||
// cleanup any pending deletes while holding the lock
|
||||
descriptor = (lam_reactor_descriptor_t*)lam_dbl_get_first(&r->r_active);
|
||||
while(descriptor != 0) {
|
||||
lam_reactor_descriptor_t* next = (lam_reactor_descriptor_t*)lam_dbl_get_next(&r->r_active);
|
||||
if(descriptor->rd_flags == 0) {
|
||||
lam_fh_remove_value_for_ikey(&r->r_hash, descriptor->rd);
|
||||
lam_dbl_list_remove(&r->r_active, descriptor);
|
||||
if(lam_dbl_get_size(&r->r_free) < MAX_DESCRIPTOR_POOL_SIZE) {
|
||||
lam_dbl_append(&r->r_free, &descriptor->rd_base);
|
||||
} else {
|
||||
lam_reactor_descriptor_destroy(descriptor);
|
||||
lam_free(descriptor);
|
||||
}
|
||||
}
|
||||
descriptor = next;
|
||||
}
|
||||
|
||||
// add any other pending inserts/deletes
|
||||
while(lam_dbl_get_size(&r->r_pending)) {
|
||||
lam_reactor_descriptor_t* descriptor = (lam_reactor_descriptor_t*)lam_dbl_remove_first(&r->r_pending);
|
||||
if(descriptor->rd_flags == 0) {
|
||||
lam_fh_remove_value_for_ikey(&r->r_hash, descriptor->rd);
|
||||
if(lam_dbl_get_size(&r->r_free) < MAX_DESCRIPTOR_POOL_SIZE) {
|
||||
lam_dbl_append(&r->r_free, &descriptor->rd_base);
|
||||
} else {
|
||||
lam_reactor_descriptor_destroy(descriptor);
|
||||
lam_free(descriptor);
|
||||
}
|
||||
} else {
|
||||
lam_dbl_append(&r->r_active, &descriptor->rd_base);
|
||||
if(descriptor->rd > r->r_max)
|
||||
r->r_max = descriptor->rd;
|
||||
}
|
||||
}
|
||||
|
||||
r->r_changes = 0;
|
||||
lam_mtx_unlock(&r->r_mutex);
|
||||
}
|
||||
|
||||
|
||||
void lam_reactor_poll(lam_reactor_t* r)
|
||||
{
|
||||
struct timeval tm;
|
||||
tm.tv_sec = 0;
|
||||
tm.tv_usec = 0;
|
||||
lam_fd_set_t rset = r->r_recv_set;
|
||||
lam_fd_set_t sset = r->r_send_set;
|
||||
lam_fd_set_t eset = r->r_except_set;
|
||||
int rc = select(r->r_max+1, (fd_set*)&rset, (fd_set*)&sset, (fd_set*)&eset, &tm);
|
||||
if(rc < 0) {
|
||||
#ifndef WIN32
|
||||
if(errno != EINTR)
|
||||
#endif
|
||||
lam_exit((-1, "lam_reactor_poll: select() failed with errno=%d\n", errno));
|
||||
return;
|
||||
}
|
||||
lam_reactor_dispatch(r, rc, &rset, &sset, &eset);
|
||||
}
|
||||
|
||||
|
||||
void lam_reactor_run(lam_reactor_t* r)
|
||||
{
|
||||
while(r->r_run == TRUE) {
|
||||
lam_fd_set_t rset = r->r_recv_set;
|
||||
lam_fd_set_t sset = r->r_send_set;
|
||||
lam_fd_set_t eset = r->r_except_set;
|
||||
int rc = select(r->r_max+1, (fd_set*)&rset, (fd_set*)&sset, (fd_set*)&eset, 0);
|
||||
if(rc < 0) {
|
||||
#ifndef WIN32
|
||||
if(errno != EINTR)
|
||||
#endif
|
||||
lam_exit((-1, "lam_reactor_run: select() failed with errno=%d\n", errno));
|
||||
continue;
|
||||
}
|
||||
lam_reactor_dispatch(r, rc, &rset, &sset, &eset);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
103
src/lam/util/reactor.h
Обычный файл
103
src/lam/util/reactor.h
Обычный файл
@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright 2002-2003. The Regents of the University of
|
||||
* California. This material was produced under U.S. Government
|
||||
* contract W-7405-ENG-36 for Los Alamos National Laboratory, which is
|
||||
* operated by the University of California for the U.S. Department of
|
||||
* Energy. The Government is granted for itself and others acting on
|
||||
* its behalf a paid-up, nonexclusive, irrevocable worldwide license
|
||||
* in this material to reproduce, prepare derivative works, and
|
||||
* perform publicly and display publicly. Beginning five (5) years
|
||||
* after October 10,2002 subject to additional five-year worldwide
|
||||
* renewals, the Government is granted for itself and others acting on
|
||||
* its behalf a paid-up, nonexclusive, irrevocable worldwide license
|
||||
* in this material to reproduce, prepare derivative works, distribute
|
||||
* copies to the public, perform publicly and display publicly, and to
|
||||
* permit others to do so. NEITHER THE UNITED STATES NOR THE UNITED
|
||||
* STATES DEPARTMENT OF ENERGY, NOR THE UNIVERSITY OF CALIFORNIA, NOR
|
||||
* ANY OF THEIR EMPLOYEES, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR
|
||||
* ASSUMES ANY LEGAL LIABILITY OR RESPONSIBILITY FOR THE ACCURACY,
|
||||
* COMPLETENESS, OR USEFULNESS OF ANY INFORMATION, APPARATUS, PRODUCT,
|
||||
* OR PROCESS DISCLOSED, OR REPRESENTS THAT ITS USE WOULD NOT INFRINGE
|
||||
* PRIVATELY OWNED RIGHTS.
|
||||
|
||||
* Additionally, this program is free software; you can distribute it
|
||||
* and/or modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or any later version. Accordingly, this
|
||||
* program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*/
|
||||
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
|
||||
|
||||
#ifndef _LAM_REACTOR_
|
||||
#define _LAM_REACTOR_
|
||||
|
||||
#include "lam_types.h"
|
||||
#include "lam/base/list.h"
|
||||
#include "lam/base/hash_table.h"
|
||||
#include "lam/threads/mutex.h"
|
||||
|
||||
extern const int LAM_NOTIFY_ALL;
|
||||
extern const int LAM_NOTIFY_RECV;
|
||||
extern const int LAM_NOTIFY_SEND;
|
||||
extern const int LAM_NOTIFY_EXCEPT;
|
||||
|
||||
extern lam_class_info_t lam_reactor_cls;
|
||||
|
||||
|
||||
//
|
||||
// Utilizes select() to provide callbacks when an event (e.g. readable,writeable,exception)
|
||||
// occurs on a designated descriptor. Objects interested in receiving callbacks must implement
|
||||
// the lam_reactor_listener_t interface.
|
||||
//
|
||||
|
||||
typedef struct _lam_reactor_listener {
|
||||
void *rl_user_data;
|
||||
void (*rl_recv_handler)(struct _lam_reactor_listener*, int sd);
|
||||
void (*rl_send_handler)(struct _lam_reactor_listener*, int sd);
|
||||
void (*rl_except_handler)(struct _lam_reactor_listener*, int sd);
|
||||
} lam_reactor_listener_t;
|
||||
|
||||
|
||||
typedef struct _lam_reactor_descriptor {
|
||||
lam_dbl_item_t rd_base;
|
||||
int rd;
|
||||
volatile int rd_flags;
|
||||
lam_reactor_listener_t *rd_recv;
|
||||
lam_reactor_listener_t *rd_send;
|
||||
lam_reactor_listener_t *rd_except;
|
||||
} lam_reactor_descriptor_t;
|
||||
|
||||
|
||||
void lam_reactor_descriptor_init(lam_reactor_descriptor_t*);
|
||||
void lam_reactor_descriptor_destroy(lam_reactor_descriptor_t*);
|
||||
|
||||
|
||||
typedef struct _lam_reactor {
|
||||
lam_object_t r_base;
|
||||
lam_mutex_t r_mutex;
|
||||
lam_dbl_list_t r_active;
|
||||
lam_dbl_list_t r_free;
|
||||
lam_dbl_list_t r_pending;
|
||||
lam_fast_hash_t r_hash;
|
||||
int r_max;
|
||||
bool_t r_run;
|
||||
int r_changes;
|
||||
lam_fd_set_t r_send_set;
|
||||
lam_fd_set_t r_recv_set;
|
||||
lam_fd_set_t r_except_set;
|
||||
} lam_reactor_t;
|
||||
|
||||
|
||||
void lam_reactor_init(lam_reactor_t*);
|
||||
void lam_reactor_destroy(lam_reactor_t*);
|
||||
|
||||
bool_t lam_reactor_insert(lam_reactor_t*, int sd, lam_reactor_listener_t*, int flags);
|
||||
bool_t lam_reactor_remove(lam_reactor_t*, int sd, lam_reactor_listener_t*, int flags);
|
||||
void lam_reactor_poll(lam_reactor_t*);
|
||||
void lam_reactor_run(lam_reactor_t*);
|
||||
|
||||
#endif
|
||||
|
@ -7,16 +7,17 @@
|
||||
# information, see the LICENSE file in the top level directory of the
|
||||
# CMPI source distribution.
|
||||
#
|
||||
# $Id: Makefile.am,v 1.1 2003/11/22 16:36:25 jsquyres Exp $
|
||||
# $Id: Makefile.am,v 1.2 2003/12/22 16:29:21 twoodall Exp $
|
||||
#
|
||||
|
||||
include $(top_srcdir)/config/Makefile.options
|
||||
|
||||
SUBDIRS = communicator datatype
|
||||
SUBDIRS = communicator datatype p2p
|
||||
|
||||
lib_LTLIBRARIES = libmpi.la
|
||||
|
||||
libmpi_la_SOURCES =
|
||||
libmpi_la_LIBADD = \
|
||||
$(top_builddir)/src/mpi/communicator/libcommunicator.la \
|
||||
$(top_builddir)/src/mpi/datatype/libdatatype.la
|
||||
$(top_builddir)/src/mpi/datatype/libdatatype.la \
|
||||
$(top_builddir)/src/mpi/p2p/libp2p.la
|
||||
|
@ -7,16 +7,17 @@
|
||||
# information, see the LICENSE file in the top level directory of the
|
||||
# CMPI source distribution.
|
||||
#
|
||||
# $Id: Makefile.am,v 1.1 2003/11/22 16:36:25 jsquyres Exp $
|
||||
# $Id: Makefile.am,v 1.2 2003/12/22 16:29:21 twoodall Exp $
|
||||
#
|
||||
|
||||
include $(top_srcdir)/config/Makefile.options
|
||||
|
||||
SUBDIRS = communicator datatype
|
||||
SUBDIRS = communicator datatype p2p
|
||||
|
||||
lib_LTLIBRARIES = libmpi.la
|
||||
|
||||
libmpi_la_SOURCES =
|
||||
libmpi_la_LIBADD = \
|
||||
$(top_builddir)/src/mpi/communicator/libcommunicator.la \
|
||||
$(top_builddir)/src/mpi/datatype/libdatatype.la
|
||||
$(top_builddir)/src/mpi/datatype/libdatatype.la \
|
||||
$(top_builddir)/src/mpi/p2p/libp2p.la
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user