Hello Andreas Sandberg,
I'd like you to do a code review. Please visit
https://gem5-review.googlesource.com/2821
to review the following change.
Change subject: dev, virtio: kill diod when gem5 dies
......................................................................
dev, virtio: kill diod when gem5 dies
The diod process (a child process of gem5) will now receive a
SIGTERM when the gem5 process dies, by using an exit
callback.
Change-Id: Ie10741e10af52c8d255210cd4bfe0e5d761485d3
Reviewed-by: Sascha Bischoff <[email protected]>
Reviewed-by: Andreas Sandberg <[email protected]>
---
M src/dev/virtio/fs9p.cc
M src/dev/virtio/fs9p.hh
2 files changed, 44 insertions(+), 1 deletion(-)
diff --git a/src/dev/virtio/fs9p.cc b/src/dev/virtio/fs9p.cc
index 7dac79c..61ddd3e 100644
--- a/src/dev/virtio/fs9p.cc
+++ b/src/dev/virtio/fs9p.cc
@@ -45,10 +45,13 @@
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/un.h>
+#include <sys/wait.h>
#include <unistd.h>
+#include <csignal>
#include <fstream>
+#include "base/callback.hh"
#include "base/output.hh"
#include "debug/VIO9P.hh"
#include "debug/VIO9PData.hh"
@@ -313,6 +316,10 @@
: VirtIO9PProxy(params),
fd_to_diod(-1), fd_from_diod(-1), diod_pid(-1)
{
+ // Register an exit callback so we can kill the diod process
+ Callback* cb = new MakeCallback<VirtIO9PDiod,
+ &VirtIO9PDiod::terminateDiod>(this);
+ registerExitCallback(cb);
}
VirtIO9PDiod::~VirtIO9PDiod()
@@ -400,6 +407,8 @@
} else {
close(pipe_rfd[0]);
close(pipe_wfd[1]);
+ inform("Started diod with PID %u, you might need to manually
kill " \
+ " diod if gem5 crashes \n", diod_pid);
}
#undef DIOD_RFD
@@ -428,6 +437,38 @@
parent.serverDataReady();
}
+void
+VirtIO9PDiod::terminateDiod()
+{
+ assert(diod_pid != -1);
+
+ DPRINTF(VIO9P, "Trying to kill diod at pid %u \n", diod_pid);
+
+ if (kill(diod_pid, SIGTERM) != 0) {
+ perror("Killing diod process");
+ warn("Failed to kill diod");
+ }
+
+ // Check if kill worked
+ for (unsigned i = 0; i < 5; i++) {
+ int wait_return = waitpid(diod_pid, NULL, WNOHANG);
+ if (wait_return == diod_pid) {
+ // Managed to kill the process
+ return;
+ } else if (wait_return == 0) {
+ // Diod is not yet killed so wait a bit and try again
+ usleep(500);
+ } else {
+ perror("Waitpid");
+ warn("Failed in waitpid");
+ break;
+ }
+ }
+
+ // If you reach this point, diod has not been killed so warn user
+ warn("gem5 was not able to kill diod (PID %d) \n", diod_pid);
+
+}
VirtIO9PDiod *
VirtIO9PDiodParams::create()
{
diff --git a/src/dev/virtio/fs9p.hh b/src/dev/virtio/fs9p.hh
index 786f584..4652560 100644
--- a/src/dev/virtio/fs9p.hh
+++ b/src/dev/virtio/fs9p.hh
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2015 ARM Limited
+ * Copyright (c) 2014-2017 ARM Limited
* All rights reserved
*
* The license below extends only to copyright in the software and shall
@@ -305,6 +305,8 @@
ssize_t read(uint8_t *data, size_t len);
ssize_t write(const uint8_t *data, size_t len);
+ /** Kill the diod child process at the end of the simulation */
+ void terminateDiod();
private:
class DiodDataEvent : public PollEvent
--
To view, visit https://gem5-review.googlesource.com/2821
To unsubscribe, visit https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie10741e10af52c8d255210cd4bfe0e5d761485d3
Gerrit-Change-Number: 2821
Gerrit-PatchSet: 1
Gerrit-Owner: Anouk Van Laer <[email protected]>
Gerrit-Reviewer: Andreas Sandberg <[email protected]>
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev