diff options
author | Nathan Binkert <nate@binkert.org> | 2008-08-03 18:19:55 -0700 |
---|---|---|
committer | Nathan Binkert <nate@binkert.org> | 2008-08-03 18:19:55 -0700 |
commit | 50ef39af82413ef463609f24173b22af13fad268 (patch) | |
tree | 44fb10aeaf17c5055c2ae315f5bc52e25180a3d3 /src | |
parent | ede89c2d541051c2ed647e2967712e10b3c0fab0 (diff) | |
download | gem5-50ef39af82413ef463609f24173b22af13fad268.tar.xz |
sockets: Add a function to disable all listening sockets.
When invoking several copies of m5 on the same machine at the same
time, there can be a race for TCP ports for the terminal connections
or remote gdb. Expose a function to disable those ports, and have the
regression scripts disable them. There are some SimObjects that have
no other function than to be used with ports (NativeTrace and
EtherTap), so they will panic if the ports are disabled.
Diffstat (limited to 'src')
-rw-r--r-- | src/base/remote_gdb.cc | 5 | ||||
-rw-r--r-- | src/base/socket.cc | 18 | ||||
-rw-r--r-- | src/base/socket.hh | 8 | ||||
-rw-r--r-- | src/cpu/nativetrace.cc | 6 | ||||
-rw-r--r-- | src/dev/ethertap.cc | 3 | ||||
-rw-r--r-- | src/dev/terminal.cc | 5 | ||||
-rw-r--r-- | src/python/m5/simulate.py | 2 | ||||
-rw-r--r-- | src/python/swig/core.i | 3 |
8 files changed, 49 insertions, 1 deletions
diff --git a/src/base/remote_gdb.cc b/src/base/remote_gdb.cc index 51293e118..06e04e19e 100644 --- a/src/base/remote_gdb.cc +++ b/src/base/remote_gdb.cc @@ -195,6 +195,11 @@ GDBListener::name() void GDBListener::listen() { + if (ListenSocket::allDisabled()) { + warn_once("Sockets disabled, not accepting gdb connections"); + return; + } + while (!listener.listen(port, true)) { DPRINTF(GDBMisc, "Can't bind port %d\n", port); port++; diff --git a/src/base/socket.cc b/src/base/socket.cc index adcc48735..bcc5236b0 100644 --- a/src/base/socket.cc +++ b/src/base/socket.cc @@ -43,6 +43,23 @@ using namespace std; +bool ListenSocket::listeningDisabled = false; +bool ListenSocket::anyListening = false; + +void +ListenSocket::disableAll() +{ + if (anyListening) + panic("Too late to disable all listeners, already have a listener"); + listeningDisabled = true; +} + +bool +ListenSocket::allDisabled() +{ + return listeningDisabled; +} + //////////////////////////////////////////////////////////////////////// // // @@ -92,6 +109,7 @@ ListenSocket::listen(int port, bool reuse) listening = true; + anyListening = true; return true; } diff --git a/src/base/socket.hh b/src/base/socket.hh index 8e55eae72..942318e45 100644 --- a/src/base/socket.hh +++ b/src/base/socket.hh @@ -34,6 +34,14 @@ class ListenSocket { protected: + static bool listeningDisabled; + static bool anyListening; + + public: + static void disableAll(); + static bool allDisabled(); + + protected: bool listening; int fd; diff --git a/src/cpu/nativetrace.cc b/src/cpu/nativetrace.cc index 7152602fe..c23a9e4ad 100644 --- a/src/cpu/nativetrace.cc +++ b/src/cpu/nativetrace.cc @@ -50,8 +50,12 @@ using namespace TheISA; namespace Trace { -NativeTrace::NativeTrace(const Params *p) : InstTracer(p) +NativeTrace::NativeTrace(const Params *p) + : InstTracer(p) { + if (ListenSocket::allDisabled()) + fatal("All listeners are disabled!"); + int port = 8000; while(!native_listener.listen(port, true)) { diff --git a/src/dev/ethertap.cc b/src/dev/ethertap.cc index 81b84d179..c7b292c8a 100644 --- a/src/dev/ethertap.cc +++ b/src/dev/ethertap.cc @@ -130,6 +130,9 @@ EtherTap::EtherTap(const Params *p) : EtherObject(p), event(NULL), socket(-1), buflen(p->bufsz), dump(p->dump), interface(NULL), txEvent(this) { + if (ListenSocket::allDisabled()) + fatal("All listeners are disabled! EtherTap can't work!"); + buffer = new char[buflen]; listener = new TapListener(this, p->port); listener->listen(); diff --git a/src/dev/terminal.cc b/src/dev/terminal.cc index 47f280ad3..58371a2bd 100644 --- a/src/dev/terminal.cc +++ b/src/dev/terminal.cc @@ -125,6 +125,11 @@ Terminal::~Terminal() void Terminal::listen(int port) { + if (ListenSocket::allDisabled()) { + warn_once("Sockets disabled, not accepting terminal connections"); + return; + } + while (!listener.listen(port, true)) { DPRINTF(Terminal, ": can't bind address terminal port %d inuse PID %d\n", diff --git a/src/python/m5/simulate.py b/src/python/m5/simulate.py index 3d91da368..e4dbd5784 100644 --- a/src/python/m5/simulate.py +++ b/src/python/m5/simulate.py @@ -182,3 +182,5 @@ def switchCpus(cpuList): for old_cpu, new_cpu in cpuList: new_cpu.takeOverFrom(old_cpu) + +from internal.core import disableAllListeners diff --git a/src/python/swig/core.i b/src/python/swig/core.i index 53d992ac6..3d360c017 100644 --- a/src/python/swig/core.i +++ b/src/python/swig/core.i @@ -34,6 +34,7 @@ %{ #include "python/swig/pyobject.hh" +#include "base/socket.hh" #include "sim/core.hh" #include "sim/host.hh" #include "sim/startup.hh" @@ -42,6 +43,7 @@ extern const char *compileDate; std::vector<std::string> compileFlags(); extern const char *hgRev; extern const char *hgDate; +inline void disableAllListeners() { ListenSocket::disableAll(); } %} %include "stdint.i" @@ -53,6 +55,7 @@ void setOutputDir(const std::string &dir); void setOutputFile(const std::string &file); void SimStartup(); void doExitCleanup(); +void disableAllListeners(); %immutable compileDate; char *compileDate; |