Gabe Black has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/54024 )
Change subject: sim-se: (Re)add support for retrying system calls.
......................................................................
sim-se: (Re)add support for retrying system calls.
The previous incarnation of this support used faults to make the CPU
reexecute the system call instruction again and again to prevent
emulating/passing through blocking system calls from blocking gem5 as
a whole. That support was accidentally removed a while ago. This new
version suspends the thread context executing the system call, and
periodically wakes it up to retry using a periodically scheduled event.
Change-Id: I4fad23bd119021df23fe6082891fbcd0ee8fb839
---
M src/sim/syscall_desc.cc
M src/sim/syscall_desc.hh
2 files changed, 45 insertions(+), 2 deletions(-)
diff --git a/src/sim/syscall_desc.cc b/src/sim/syscall_desc.cc
index 7427f41..8efaebc 100644
--- a/src/sim/syscall_desc.cc
+++ b/src/sim/syscall_desc.cc
@@ -30,6 +30,7 @@
#include "sim/syscall_desc.hh"
#include "base/types.hh"
+#include "sim/eventq.hh"
#include "sim/syscall_debug_macros.hh"
namespace gem5
@@ -45,8 +46,32 @@
SyscallReturn retval = executor(this, tc);
if (retval.needsRetry()) {
- DPRINTF_SYSCALL(Base, "Needs retry.\n", name());
- } else if (retval.suppressed()) {
+ DPRINTF_SYSCALL(Base, "%s needs retry.\n", name());
+ retrying = true;
+
+ // Suspend this ThreadContext while the syscall is pending.
+ tc->suspend();
+
+ // Create an event which will retry the system call later.
+ auto retry = [this, tc]() {
+ DPRINTF_SYSCALL(Base, "About to retry %s...\n",
+ dumper(name(), tc));
+ doSyscall(tc);
+ };
+ auto *event = new EventFunctionWrapper(retry, name(), true);
+
+ // Schedule it in about 100 CPU cycles. That will give other
contexts
+ // a chance to execute a bit of code before trying again.
+ auto *cpu = tc->getCpuPtr();
+ curEventQueue()->schedule(event,
+ curTick() + cpu->cyclesToTicks(Cycles(100)));
+ return;
+ } else if (retrying) {
+ retrying = false;
+ tc->activate();
+ }
+
+ if (retval.suppressed()) {
DPRINTF_SYSCALL(Base, "No return value.\n", name());
} else {
returnInto(tc, retval);
diff --git a/src/sim/syscall_desc.hh b/src/sim/syscall_desc.hh
index 6ded904..6a5802b 100644
--- a/src/sim/syscall_desc.hh
+++ b/src/sim/syscall_desc.hh
@@ -100,6 +100,8 @@
std::string _name;
int _num;
+ bool retrying = false;
+
/** Mechanism for ISAs to connect to the emul function definitions */
Executor executor;
Dumper dumper;
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/54024
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: I4fad23bd119021df23fe6082891fbcd0ee8fb839
Gerrit-Change-Number: 54024
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s