Andreas Sandberg has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/50409 )

Change subject: cpu-kvm: Reinitialize threads on drainResume
......................................................................

cpu-kvm: Reinitialize threads on drainResume

Event queue service threads may have been re-created while the
simulator was drained. We therefore need to initialize the new thread
by setting correct signal masks and re-attaching performance counters.

Change-Id: Ic0dab80543928327021cade037770c917e73a47f
Signed-off-by: Andreas Sandberg <andreas.sandb...@arm.com>
---
M src/cpu/kvm/base.cc
M src/cpu/kvm/base.hh
2 files changed, 21 insertions(+), 8 deletions(-)



diff --git a/src/cpu/kvm/base.cc b/src/cpu/kvm/base.cc
index c7c72a8..ea43595 100644
--- a/src/cpu/kvm/base.cc
+++ b/src/cpu/kvm/base.cc
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2015, 2017 ARM Limited
+ * Copyright (c) 2012, 2015, 2017, 2021 ARM Limited
  * All rights reserved
  *
  * The license below extends only to copyright in the software and shall
@@ -154,9 +154,9 @@
         inform("KVM: Coalesced not supported by host OS\n");
     }

-    Event *startupEvent(
- new EventFunctionWrapper([this]{ startupThread(); }, name(), true));
-    schedule(startupEvent, curTick());
+    schedule(new EventFunctionWrapper([this]{
+                restartEqThread();
+            }, name(), true), curTick());
 }

 BaseKvmCPU::Status
@@ -228,7 +228,7 @@
 }

 void
-BaseKvmCPU::startupThread()
+BaseKvmCPU::restartEqThread()
 {
     // Do thread-specific initialization. We need to setup signal
     // delivery for counters and timers from within the thread that
@@ -381,6 +381,13 @@
 {
     assert(!tickEvent.scheduled());

+    /* The simulator may have terminated the threads servicing event
+     * queues. In that case, we need to re-initialize the new
+     * threads. */
+    schedule(new EventFunctionWrapper([this]{
+                restartEqThread();
+            }, name(), true), curTick());
+
     // We might have been switched out. In that case, we don't need to
     // do anything.
     if (switchedOut())
@@ -1275,6 +1282,11 @@
             .samplePeriod(42);
     }

+    // We might be re-attaching counters due threads being
+    // re-initialised after fork.
+    if (hwCycles.attached())
+        hwCycles.detach();
+
     hwCycles.attach(cfgCycles,
                     0); // TID (0 => currentThread)

diff --git a/src/cpu/kvm/base.hh b/src/cpu/kvm/base.hh
index e5b047e..4f40064 100644
--- a/src/cpu/kvm/base.hh
+++ b/src/cpu/kvm/base.hh
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012 ARM Limited
+ * Copyright (c) 2012, 2021 ARM Limited
  * All rights reserved
  *
  * The license below extends only to copyright in the software and shall
@@ -682,11 +682,12 @@
      * example, when setting up timers, we need to know the TID of the
      * thread executing in KVM in order to deliver the timer signal to
      * that thread. This method is called as the first event in this
-     * SimObject's event queue.
+     * SimObject's event queue and after drainResume to handle changes
+     * to event queue service threads.
      *
      * @see startup
      */
-    void startupThread();
+    void restartEqThread();

     /** Try to drain the CPU if a drain is pending */
     bool tryDrain();

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/50409
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: Ic0dab80543928327021cade037770c917e73a47f
Gerrit-Change-Number: 50409
Gerrit-PatchSet: 1
Gerrit-Owner: Andreas Sandberg <andreas.sandb...@arm.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