Skip to content

Commit

Permalink
fixed issues with new SST core
Browse files Browse the repository at this point in the history
  • Loading branch information
jjwilke committed Mar 8, 2016
1 parent d4337c8 commit 0e03795
Show file tree
Hide file tree
Showing 17 changed files with 122 additions and 36 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ bin/compile
tests/reference/upd
sstmac/common/config.h.in
sstmac/common/config.h.in~

*.pyc
24 changes: 20 additions & 4 deletions acinclude/check_threading.m4
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@


AC_DEFUN([CHECK_THREADING], [
at_least_one_threading=no
# Find out if we want to use pthreads instead of a user-space threads.
AH_TEMPLATE([HAVE_PTHREAD], [Define to allow use of pthreads])
AC_ARG_ENABLE(pthread,
Expand Down Expand Up @@ -45,6 +49,9 @@ AC_ARG_ENABLE(ucontext,
]
)
if test "X$have_integrated_core" = "Xyes"; then
AC_MSG_RESULT([pthread virtual thread interface not compatible with unified core])
else
if test "$enable_pthread" != no; then
AC_MSG_CHECKING([whether pthreads is automatically usable])
AC_LINK_IFELSE(
Expand Down Expand Up @@ -86,9 +93,10 @@ if test "$enable_pthread" != no; then
fi
if test "$enable_pthread" = yes; then
at_least_one_threading=yes
AC_DEFINE(HAVE_PTHREAD)
fi
fi
fi
if test "$enable_ucontext" != no; then
Expand All @@ -109,6 +117,7 @@ if test "$enable_ucontext" != no; then
enable_ucontext="yes"
AC_DEFINE(HAVE_UCONTEXT)
AM_CONDITIONAL(HAVE_UCONTEXT, true)
at_least_one_threading=yes
], [
AC_MSG_RESULT([no])
AM_CONDITIONAL(HAVE_UCONTEXT, false)
Expand All @@ -126,13 +135,11 @@ fi
# If pth is enabled, but we're not using the builtin version, then
# test whether or not it works.
PTH_PATH=none
if test "$enable_pth" != "no" -a "$enable_pth" != builtin; then
if test "$enable_pth" != "no"; then
if test "$enable_pth" != "yes"; then
CXXFLAGS="$CXXFLAGS -I$enable_pth/include"
LDFLAGS="$LDFLAGS -L$enable_pth/lib"
PTH_PATH="$enable_pth"
else
PTH_PATH="default"
fi
dnl First check for a custom pth.
AC_CHECK_LIB(
Expand All @@ -141,6 +148,7 @@ if test "$enable_pth" != "no" -a "$enable_pth" != builtin; then
[LIBS="-lpth $LIBS"],
[AC_MSG_ERROR([GNU pth enabled but not found])]
)
at_least_one_threading=yes
AC_DEFINE(HAVE_PTH)
fi
Expand All @@ -166,5 +174,13 @@ elif test "$default_threading" = ucontext -a "$enable_ucontext" != no; then
elif test "$default_threading" = pthread -a "$enable_pthread" != no; then
AC_DEFINE(USE_PTHREAD)
fi
if test "X$at_least_one_threading" = "Xno"; then
AC_MSG_ERROR([No valid virtual threading interfaces available - must have pth, ucontext, or pthread
ucontext is not available on Mac OS X
pthread is not compatible with integrated SST core
pth must downloaded from https://www.gnu.org/software/pth
])
fi
])

2 changes: 1 addition & 1 deletion acinclude/sst_core.m4
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ AC_ARG_WITH([integrated-core],
CPPFLAGS="$CPPFLAGS $PY_INCLUDES"
AC_CHECK_HEADERS([Python.h], [],
[AC_MSG_ERROR([Could not locate Python installation needed by SST core])])
AC_CHECK_HEADERS([sst/sst_config.h], [],
AC_CHECK_HEADERS([sst/core/element.h], [],
[AC_MSG_ERROR([Could not locate SST core header files at $SST])])
have_integrated_core="yes"
], [
Expand Down
2 changes: 1 addition & 1 deletion dumpi
Submodule dumpi updated from 2635b2 to f5f99e
7 changes: 1 addition & 6 deletions sstmac/hardware/nic/nic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,7 @@ nic::handle(const sst_message::ptr& msg)
} else {
recv_message(msg);
}
// don't use handle for sending anymore
//else if (msg->fromaddr() == msg->toaddr()){
// intranode_send(ptr_safe_cast(network_message, msg));
//}
//else if (msg->fromaddr() == my_addr_){
// internode_send(ptr_safe_cast(network_message, msg));

}

void
Expand Down
3 changes: 2 additions & 1 deletion sstmac/hardware/node/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,6 @@ node::send_to_nic(const network_message::ptr& netmsg)
} else {
nic_->internode_send(netmsg);
}
//SCHEDULE_NOW(nic_, netmsg);
}

#if SSTMAC_INTEGRATED_SST_CORE
Expand All @@ -242,6 +241,8 @@ node::launch()
std::list<sw::launch_message::ptr>::iterator it, end = launchers_.end();
for (it=launchers_.begin(); it != end; ++it){
sw::launch_message::ptr lmsg = *it;
node_debug("launching task %d on node %d",
int(lmsg->tid()), int(addr()));
os_->handle_message(lmsg);
}
}
Expand Down
34 changes: 29 additions & 5 deletions sstmac/software/process/operating_system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,25 @@ static bool you_have_been_warned = false;
bool operating_system::cxa_finalizing_ = false;
operating_system::os_thread_context operating_system::cxa_finalize_context_;


#if SSTMAC_HAVE_PTH
#define pth_available "pth,"
#else
#define pth_available ""
#endif

#if SSTMAC_HAVE_PTHREAD
#define pthread_available "pthread,"
#else
#define pthread_available ""
#endif

#if SSTMAC_HAVE_UCONTEXT
#define ucontext_available "ucontext,"
#else
#define ucontext_available ""
#endif

void
operating_system::init_threading()
{
Expand Down Expand Up @@ -127,6 +146,11 @@ operating_system::init_threading()
threading_string = "ucontext";
#elif defined(SSTMAC_HAVE_PTHREAD)
threading_string = "pthread";
#else
#error no valid thread interfaces available (pth, pthread, ucontext supported)
#error ucontext is not available on MAC
#error pthread is not compatible with integrated SST core
#error pth must be downloaded and installed from GNU site
#endif
#endif
}
Expand Down Expand Up @@ -178,8 +202,8 @@ operating_system::init_threading()
}
else {
spkt_throw_printf(sprockit::value_error,
"operating_system: invalid value %s for SSTMAC_THREADING environmental variable.\n"
"choose one of pth, pthread, ucontext.\n",
"operating_system: invalid value %s for SSTMAC_THREADING environmental variable\n"
"choose one of " pth_available pthread_available ucontext_available,
threading_string.c_str());
}

Expand Down Expand Up @@ -416,8 +440,6 @@ operating_system::current_os_thread_context()
{
#if SSTMAC_USE_MULTITHREAD
int thr = thread_id();
//std::cout << sprockit::printf("OS on node %d is on thread %d\n",
// int(my_addr()), thr);
return os_thread_contexts_[thr];
#else
return os_thread_context_;
Expand Down Expand Up @@ -470,7 +492,7 @@ operating_system::switch_to_thread(thread_data_t tothread)
/** back to main thread */
current_thread_id_ = old_id;
ctxt.current_thread = old_thread;
os_debug("size of threadstack %d, switching back to thread %d\n",
os_debug("size of threadstack %d, switching back to thread %d",
threadstack_.size(), current_thread_id_);
}

Expand Down Expand Up @@ -942,6 +964,8 @@ operating_system::add_task(const task_id& id)
void
operating_system::start_app(app* theapp)
{
os_debug("starting app %d:%d on thread %d",
int(theapp->tid()), int(theapp->aid()), thread_id());
//this should be called from the actual thread running it
init_threading();
#if SSTMAC_HAVE_GRAPHVIZ
Expand Down
61 changes: 52 additions & 9 deletions sstmac/software/threading/threading_pthread.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,42 @@
*/

#include <sprockit/errors.h>
#include <sprockit/debug.h>
#include <sstmac/common/thread_info.h>
#include <sstmac/common/thread_lock.h>
#include <sstmac/software/threading/threading_pthread.h>

MakeDebugSlot(pth);
#define pthread_ctx_debug(ctx,...) \
debug_printf(sprockit::dbg::pth, "context=%p,thread=%p: %s", \
ctx, pthread_self(), sprockit::printf(__VA_ARGS__).c_str())
#define pthread_debug(...) \
pthread_ctx_debug(&context_, __VA_ARGS__)

namespace sstmac {
namespace sw {
#ifdef SSTMAC_HAVE_PTHREAD

std::vector<pthread_mutex_t> threading_pthread::context_switch_mutexes;

void
send_signal(threadcontext_t* context)
{
context->waiting = false;
pthread_cond_signal(&context->ready);
}

void
wait_signal(threadcontext_t* context)
{
do {
pthread_cond_wait(&context->ready, context->context_switch_lock);
}
while (context->waiting);
//go back to wait mode
context->waiting = true;
}

threading_pthread::threading_pthread(int thread_id, int nthread) :
thread_id_(thread_id),
nthread_(nthread)
Expand All @@ -29,7 +55,9 @@ threading_pthread::threading_pthread(int thread_id, int nthread) :
if (context_switch_mutexes.size() == 0){
//not yet done
context_switch_mutexes.resize(nthread);
pthread_debug("initializing pthread app stack for %d real threads", nthread);
for (int i=0; i < nthread; ++i){
pthread_debug("init context switch mutex %d", i);
pthread_mutex_init(&context_switch_mutexes[i], NULL);
}
}
Expand All @@ -45,20 +73,28 @@ pthreadfunc(void*args)
void* thread_args = thread_info->args;
void (*func)(void*) = thread_info->func;

pthread_ctx_debug(thread_info->context, "launched new pthread application stack");

// The following code handles the initial context switch
// starting this thread. After that, swap_context
// performs all context switches.

// Grab the context lock.
pthread_mutex_lock(thread_info->context->context_switch_lock);

pthread_ctx_debug(thread_info->context,
"locked new pthread application stack");

// Put this thread to sleep, if it has not
// already been started.
if (!thread_info->context->started) {
pthread_cond_wait(&thread_info->context->ready,
thread_info->context->context_switch_lock);
pthread_ctx_debug(thread_info->context,
"putting thread to sleep");
wait_signal(thread_info->context);
}

pthread_ctx_debug(thread_info->context, "thread awoken - unlocking mutex");

pthread_mutex_unlock(thread_info->context->context_switch_lock);

//delete the thread info here
Expand All @@ -69,7 +105,8 @@ pthreadfunc(void*args)
(*func)(thread_args);

spkt_throw_printf(sprockit::illformed_error,
"pthreadfunc arrived at end of function. complete_context should have terminated this with pthread_exit");
"pthreadfunc arrived at end of function\n"
"complete_context should have terminated this with pthread_exit");

return NULL;
}
Expand All @@ -82,6 +119,7 @@ threading_pthread::init_context_common(threadcontext_t &context)
context_.context_switch_lock = &context_switch_mutexes[thread_id_];
pthread_cond_init(&context.ready, NULL);
context.started = false;
context.waiting = true;
}

/// Initialize the context to be that for the currently running thread.
Expand Down Expand Up @@ -116,6 +154,8 @@ threading_pthread::start_context(int physical_thread_id,
init_context_common(context_);

//thread_info::register_kernel_space_virtual_thread(physical_thread_id, &context_.thread, &thread_attr);
pthread_debug("starting pthread %p with stack %p of size %lu on physical thread %d",
&context_, &context_.thread, stack, stacksize, physical_thread_id);

threadargs *targs = new threadargs(func, args, &context_);
pthread_create(&context_.thread, &thread_attr, &pthreadfunc, (void*) targs);
Expand All @@ -136,7 +176,6 @@ threading_pthread::complete_context(threading_interface *to)
else {
spkt_throw_printf(sprockit::illformed_error,
"received non-pthread context on complete_context");
//pthread_cond_signal(NULL);
}
pthread_exit(0);
}
Expand All @@ -161,9 +200,6 @@ threading_pthread::swap_context(threading_interface *to)
// (lock) c2 signals c1 to start
// c2 begins waiting on signals (unlock)

// Grab the context lock.
pthread_mutex_lock(context_.context_switch_lock);

#if SSTMAC_SANITY_CHECK
threading_pthread *casted = dynamic_cast<threading_pthread*>(to);
if (!casted){
Expand All @@ -174,14 +210,21 @@ threading_pthread::swap_context(threading_interface *to)
threading_pthread *casted = static_cast<threading_pthread*>(to);
#endif

// Grab the context lock.
pthread_debug("locking context switch to start swap to thread");
pthread_mutex_lock(context_.context_switch_lock);

casted->context_.started = true;

// Wake up the to context.
pthread_cond_signal(&casted->context_.ready);
pthread_debug("cond signal to cause swap context");
send_signal(&casted->context_);

// Put the from thread to sleep.
pthread_cond_wait(&context_.ready, context_.context_switch_lock);
pthread_debug("wait on cond in swap context");
wait_signal(&context_);

pthread_debug("resuming, unlocking context switch");
pthread_mutex_unlock(context_.context_switch_lock);
}

Expand Down
5 changes: 2 additions & 3 deletions sstmac/software/threading/threading_pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ namespace sw {
#ifdef SSTMAC_HAVE_PTHREAD


class threadcontext_t
struct threadcontext_t
{
public:
pthread_t thread;
pthread_cond_t ready;
pthread_mutex_t* context_switch_lock;
bool started;
bool waiting;
};

class threading_pthread : public threading_interface
Expand Down Expand Up @@ -78,7 +78,6 @@ class threading_pthread : public threading_interface

static std::vector<pthread_mutex_t> context_switch_mutexes;


virtual
threading_interface* copy() {
return new threading_pthread(thread_id_, nthread_);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Runtime = 5000.1002ms
*** Event queue empty, exiting simulation... ***
Simulation is complete, simulated time: 18.4467 Ms
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Runtime = 5000.1292ms
Runtime = 5000.1283ms
*** Event queue empty, exiting simulation... ***
Simulation is complete, simulated time: 18.4467 Ms
3 changes: 3 additions & 0 deletions tests/reference/test_core_apps_ping_all_null_arb.sst-out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Runtime = 5000.0631ms
*** Event queue empty, exiting simulation... ***
Simulation is complete, simulated time: 18.4467 Ms
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Runtime = 5000.0635ms
Runtime = 5000.0631ms
*** Event queue empty, exiting simulation... ***
Simulation is complete, simulated time: 18.4467 Ms
Loading

0 comments on commit 0e03795

Please sign in to comment.