Gabe Black has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/57089 )

Change subject: cpu,sim: Don't tie ThreadContext contextId to the CPU ID.
......................................................................

cpu,sim: Don't tie ThreadContext contextId to the CPU ID.

The contextId is generally treated as (and should be) an opaque index
into the System objects threadContext array. When forcing it to
particular values, that introduces gaps in the threadContext array which
trips up other code which is expecting the array to have only valid
entries.

Change-Id: I4997e989b436a3008f65f348722dfb843b2f110a
---
M src/cpu/base.cc
M src/sim/system.cc
M src/sim/system.hh
3 files changed, 26 insertions(+), 30 deletions(-)



diff --git a/src/cpu/base.cc b/src/cpu/base.cc
index 741ee2d..5e8b7c1 100644
--- a/src/cpu/base.cc
+++ b/src/cpu/base.cc
@@ -431,15 +431,10 @@
              "per thread (%i)\n",
              name(), interrupts.size(), numThreads);

-    ThreadID size = threadContexts.size();
-    for (ThreadID tid = 0; tid < size; ++tid) {
+    for (ThreadID tid = 0; tid < threadContexts.size(); ++tid) {
         ThreadContext *tc = threadContexts[tid];

-        if (system->multiThread) {
-            system->registerThreadContext(tc);
-        } else {
-            system->registerThreadContext(tc, _cpuId);
-        }
+        system->registerThreadContext(tc);

         if (!FullSystem)
             tc->getProcessPtr()->assignThreadContext(tc->contextId());
diff --git a/src/sim/system.cc b/src/sim/system.cc
index db8f44c..d5e5e3f 100644
--- a/src/sim/system.cc
+++ b/src/sim/system.cc
@@ -95,31 +95,18 @@
 }

 void
-System::Threads::insert(ThreadContext *tc, ContextID id)
+System::Threads::insert(ThreadContext *tc)
 {
-    if (id == InvalidContextID) {
-        for (id = 0; id < size(); id++) {
-            if (!threads[id].context)
-                break;
-        }
-    }
-
+    ContextID id = size();
     tc->setContextId(id);

-    if (id >= size())
-        threads.resize(id + 1);
-
-    fatal_if(threads[id].context,
-            "Cannot have two thread contexts with the same id (%d).", id);
-
-    auto *sys = tc->getSystemPtr();
-
-    auto &t = thread(id);
+    auto &t = threads.emplace_back();
     t.context = tc;
     // Look up this thread again on resume, in case the threads vector has
     // been reallocated.
     t.resumeEvent = new EventFunctionWrapper(
-            [this, id](){ thread(id).resume(); }, sys->name());
+            [this, id](){ thread(id).resume(); },
+            tc->getSystemPtr()->name());
 }

 void
@@ -258,9 +245,9 @@
 }

 void
-System::registerThreadContext(ThreadContext *tc, ContextID assigned)
+System::registerThreadContext(ThreadContext *tc)
 {
-    threads.insert(tc, assigned);
+    threads.insert(tc);

     workload->registerThreadContext(tc);

diff --git a/src/sim/system.hh b/src/sim/system.hh
index 7dcd1aa..bb855e0 100644
--- a/src/sim/system.hh
+++ b/src/sim/system.hh
@@ -144,7 +144,7 @@
             return threads[id];
         }

-        void insert(ThreadContext *tc, ContextID id=InvalidContextID);
+        void insert(ThreadContext *tc);
         void replace(ThreadContext *tc, ContextID id);

         friend class System;
@@ -578,8 +578,7 @@

   public:

-    void registerThreadContext(
-            ThreadContext *tc, ContextID assigned=InvalidContextID);
+    void registerThreadContext(ThreadContext *tc);
     void replaceThreadContext(ThreadContext *tc, ContextID context_id);

     void serialize(CheckpointOut &cp) const override;

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/57089
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I4997e989b436a3008f65f348722dfb843b2f110a
Gerrit-Change-Number: 57089
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <gabe.bl...@gmail.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to