cpu,sim: Set ThreadContext's ContextID right away.

The code which registers thread contexts originally returned the ID that
it had chosen, and let the CPU actually set the ID in the object itself.
That opened a window where calling contextId() on the ThreadContext
would return the wrong answer.

Instead, we can just set the ID immediately after it's decided. This
also localizes that logic and removes plumbing for the ID between that
decision and where it's actually applied.

Change-Id: I31ad84c3f9bf6f5b6f72457ca640ea929b24f6a0
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/44615
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Carvalho <odanrc@yahoo.com.br>
Reviewed-by: Boris Shingarov <shingarov@gmail.com>
Maintainer: Gabe Black <gabe.black@gmail.com>
This commit is contained in:
Gabe Black
2021-04-19 00:11:22 -07:00
parent 424eb027ff
commit 8467e183c9
3 changed files with 9 additions and 11 deletions

View File

@@ -431,9 +431,9 @@ BaseCPU::registerThreadContexts()
ThreadContext *tc = threadContexts[tid];
if (system->multiThread) {
tc->setContextId(system->registerThreadContext(tc));
system->registerThreadContext(tc);
} else {
tc->setContextId(system->registerThreadContext(tc, _cpuId));
system->registerThreadContext(tc, _cpuId);
}
if (!FullSystem)

View File

@@ -98,7 +98,7 @@ System::Threads::Thread::quiesce() const
workload->recordQuiesce();
}
ContextID
void
System::Threads::insert(ThreadContext *tc, ContextID id)
{
if (id == InvalidContextID) {
@@ -108,6 +108,8 @@ System::Threads::insert(ThreadContext *tc, ContextID id)
}
}
tc->setContextId(id);
if (id >= size())
threads.resize(id + 1);
@@ -129,8 +131,6 @@ System::Threads::insert(ThreadContext *tc, ContextID id)
t.gdb->listen();
}
# endif
return id;
}
void
@@ -296,15 +296,13 @@ System::setMemoryMode(Enums::MemoryMode mode)
memoryMode = mode;
}
ContextID
void
System::registerThreadContext(ThreadContext *tc, ContextID assigned)
{
ContextID id = threads.insert(tc, assigned);
threads.insert(tc, assigned);
for (auto *e: liveEvents)
tc->schedule(e);
return id;
}
bool

View File

@@ -142,7 +142,7 @@ class System : public SimObject, public PCEventScope
return threads[id];
}
ContextID insert(ThreadContext *tc, ContextID id=InvalidContextID);
void insert(ThreadContext *tc, ContextID id=InvalidContextID);
void replace(ThreadContext *tc, ContextID id);
friend class System;
@@ -586,7 +586,7 @@ class System : public SimObject, public PCEventScope
/// @return Starting address of first page
Addr allocPhysPages(int npages);
ContextID registerThreadContext(
void registerThreadContext(
ThreadContext *tc, ContextID assigned=InvalidContextID);
void replaceThreadContext(ThreadContext *tc, ContextID context_id);