From 8882dc1283771463a20194c083f4b8940a2d574b Mon Sep 17 00:00:00 2001 From: Steve Reinhardt Date: Wed, 15 Apr 2009 13:13:47 -0700 Subject: Get rid of the Unallocated thread context state. Basically merge it in with Halted. Also had to get rid of a few other functions that called ThreadContext::deallocate(), including: - InOrderCPU's setThreadRescheduleCondition. - ThreadContext::exit(). This function was there to avoid terminating simulation when one thread out of a multi-thread workload exits, but we need to find a better (non-cpu-centric) way. --- src/sim/process.cc | 2 +- src/sim/syscall_emul.cc | 9 +++++++-- src/sim/system.cc | 11 +++++++++++ src/sim/system.hh | 10 ++++++---- 4 files changed, 25 insertions(+), 7 deletions(-) (limited to 'src/sim') diff --git a/src/sim/process.cc b/src/sim/process.cc index 4be97f2f6..c45844a51 100644 --- a/src/sim/process.cc +++ b/src/sim/process.cc @@ -221,7 +221,7 @@ Process::findFreeContext() ThreadContext *tc; for (int i = 0; i < size; ++i) { tc = system->getThreadContext(contextIds[i]); - if (tc->status() == ThreadContext::Unallocated) { + if (tc->status() == ThreadContext::Halted) { // inactive context, free to use return tc; } diff --git a/src/sim/syscall_emul.cc b/src/sim/syscall_emul.cc index 5fe30c269..f0a693db0 100644 --- a/src/sim/syscall_emul.cc +++ b/src/sim/syscall_emul.cc @@ -42,6 +42,7 @@ #include "cpu/base.hh" #include "mem/page_table.hh" #include "sim/process.hh" +#include "sim/system.hh" #include "sim/sim_exit.hh" @@ -91,9 +92,13 @@ SyscallReturn exitFunc(SyscallDesc *desc, int callnum, LiveProcess *process, ThreadContext *tc) { - if (tc->exit()) { + if (process->system->numRunningContexts() == 1) { + // Last running context... exit simulator exitSimLoop("target called exit()", - process->getSyscallArg(tc, 0) & 0xff); + process->getSyscallArg(tc, 0) & 0xff); + } else { + // other running threads... just halt this one + tc->halt(); } return 1; diff --git a/src/sim/system.cc b/src/sim/system.cc index d16524c41..f10167bba 100644 --- a/src/sim/system.cc +++ b/src/sim/system.cc @@ -211,6 +211,17 @@ System::registerThreadContext(ThreadContext *tc, int assigned) return id; } +int +System::numRunningContexts() +{ + int running = 0; + for (int i = 0; i < _numContexts; ++i) { + if (threadContexts[i]->status() != ThreadContext::Halted) + ++running; + } + return running; +} + void System::startup() { diff --git a/src/sim/system.hh b/src/sim/system.hh index bfa5ea8bb..e1c30490b 100644 --- a/src/sim/system.hh +++ b/src/sim/system.hh @@ -89,19 +89,21 @@ class System : public SimObject std::vector threadContexts; int _numContexts; - ThreadContext * getThreadContext(int tid) + ThreadContext *getThreadContext(int tid) { return threadContexts[tid]; } int numContexts() { - if (_numContexts != threadContexts.size()) - panic("cpu array not fully populated!"); - + assert(_numContexts == threadContexts.size()); return _numContexts; } + /** Return number of running (non-halted) thread contexts in + * system. These threads could be Active or Suspended. */ + int numRunningContexts(); + #if FULL_SYSTEM Platform *platform; uint64_t init_param; -- cgit v1.2.3