Yu-hsin Wang has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/56549 )

Change subject: cpu: System should skip invalid thread when iterating
......................................................................

cpu: System should skip invalid thread when iterating

In System structure, we use a vector to implement map for mapping id and
ThreadContext. Once the id is not assigned in order, it would create
some invalid ThreadContexts within the vector. We should skip those
invalid ThreadContexts when doing iterating.

Change-Id: If016d563c9cbd933e6e4791595e987808dff6d6a
---
M src/sim/system.cc
1 file changed, 36 insertions(+), 2 deletions(-)



diff --git a/src/sim/system.cc b/src/sim/system.cc
index db8f44c..29411dc 100644
--- a/src/sim/system.cc
+++ b/src/sim/system.cc
@@ -141,6 +141,9 @@
 System::Threads::findFree()
 {
     for (auto &thread: threads) {
+        if (thread.context == nullptr) {
+            continue;
+        }
         if (thread.context->status() == ThreadContext::Halted)
             return thread.context;
     }
@@ -152,6 +155,9 @@
 {
     int count = 0;
     for (auto &thread: threads) {
+        if (thread.context == nullptr) {
+            continue;
+        }
         auto status = thread.context->status();
         if (status != ThreadContext::Halted &&
                 status != ThreadContext::Halting) {
@@ -273,8 +279,12 @@
 {
     bool all = true;
     liveEvents.push_back(event);
-    for (auto *tc: threads)
+    for (auto *tc: threads) {
+        if (tc == nullptr) {
+            continue;
+        }
         all = tc->schedule(event) && all;
+    }
     return all;
 }

@@ -283,8 +293,12 @@
 {
     bool all = true;
     liveEvents.remove(event);
-    for (auto *tc: threads)
+    for (auto *tc: threads) {
+        if (tc == nullptr) {
+            continue;
+        }
         all = tc->remove(event) && all;
+    }
     return all;
 }

@@ -352,6 +366,9 @@
 System::serialize(CheckpointOut &cp) const
 {
     for (auto &t: threads.threads) {
+        if (t.context == nullptr) {
+            continue;
+        }
         Tick when = 0;
         if (t.resumeEvent && t.resumeEvent->scheduled())
             when = t.resumeEvent->when();
@@ -368,6 +385,9 @@
 System::unserialize(CheckpointIn &cp)
 {
     for (auto &t: threads.threads) {
+        if (t.context == nullptr) {
+            continue;
+        }
         Tick when = 0;
         ContextID id = t.context->contextId();
         if (!optParamIn(cp, csprintf("quiesceEndTick_%d", id), when) ||

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/56549
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: If016d563c9cbd933e6e4791595e987808dff6d6a
Gerrit-Change-Number: 56549
Gerrit-PatchSet: 1
Gerrit-Owner: Yu-hsin Wang <yuhsi...@google.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