sim: Move findFreeContext to System.

This method searches through the ThreadContexts stored in the system,
and has no concrete connection to Process other than it happened to be
used by a Process in the clone system call.

By moving it, we can use its functionality in classes other than
Process.

Change-Id: Ic6899c335dc13841c6fe948ea3a4f8ad67e562bb
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/24285
Reviewed-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Reviewed-by: Brandon Potter <Brandon.Potter@amd.com>
Maintainer: Jason Lowe-Power <jason@lowepower.com>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Gabe Black
2020-01-12 22:58:48 -08:00
parent e3c3d2a1a8
commit 46fbd76595
5 changed files with 19 additions and 19 deletions

View File

@@ -280,16 +280,6 @@ Process::regStats()
;
}
ThreadContext *
Process::findFreeContext()
{
for (auto &it : system->threadContexts) {
if (ThreadContext::Halted == it->status())
return it;
}
return nullptr;
}
void
Process::revokeThreadContext(int context_id)
{

View File

@@ -129,9 +129,6 @@ class Process : public SimObject
contextIds.push_back(context_id);
}
// Find a free context to use
ThreadContext *findFreeContext();
/**
* After delegating a thread context to a child process
* no longer should relate to the ThreadContext

View File

@@ -1527,7 +1527,7 @@ cloneFunc(SyscallDesc *desc, int callnum, ThreadContext *tc)
return -EINVAL;
ThreadContext *ctc;
if (!(ctc = p->findFreeContext())) {
if (!(ctc = tc->getSystemPtr()->findFreeContext())) {
DPRINTF_SYSCALL(Verbose, "clone: no spare thread context in system"
"[cpu %d, thread %d]", tc->cpuId(), tc->threadId());
return -EAGAIN;

View File

@@ -302,6 +302,16 @@ System::registerThreadContext(ThreadContext *tc, ContextID assigned)
return id;
}
ThreadContext *
System::findFreeContext()
{
for (auto &it : threadContexts) {
if (ThreadContext::Halted == it->status())
return it;
}
return nullptr;
}
bool
System::schedule(PCEvent *event)
{

View File

@@ -188,6 +188,14 @@ class System : public SimObject, public PCEventScope
unsigned int cacheLineSize() const { return _cacheLineSize; }
std::vector<ThreadContext *> threadContexts;
ThreadContext *findFreeContext();
ThreadContext *
getThreadContext(ContextID tid) const
{
return threadContexts[tid];
}
const bool multiThread;
using SimObject::schedule;
@@ -195,11 +203,6 @@ class System : public SimObject, public PCEventScope
bool schedule(PCEvent *event) override;
bool remove(PCEvent *event) override;
ThreadContext *getThreadContext(ContextID tid) const
{
return threadContexts[tid];
}
unsigned numContexts() const { return threadContexts.size(); }
/** Return number of running (non-halted) thread contexts in