config: Add a --without-python option to build process

Add the ability to build libgem5 without embedded Python or the
ability to configure with Python.

This is a prelude to a patch to allow config.ini files to be loaded
into libgem5 using only C++ which would make embedding gem5 within
other simulation systems easier.

This adds a few registration interfaces to things which cross
between Python and C++.  Namely: stats dumping and SimObject resolving
This commit is contained in:
Andrew Bardsley
2014-10-16 05:49:32 -04:00
parent a63ba6c7b7
commit d8502ee46d
23 changed files with 547 additions and 189 deletions

View File

@@ -44,9 +44,11 @@ Source('arguments.cc')
Source('async.cc')
Source('core.cc')
Source('debug.cc')
Source('py_interact.cc', skip_no_python=True)
Source('eventq.cc')
Source('global_event.cc')
Source('init.cc')
Source('init.cc', skip_no_python=True)
Source('init_signals.cc')
Source('main.cc', main=True, skip_lib=True)
Source('root.cc')
Source('serialize.cc')
@@ -57,6 +59,7 @@ Source('sub_system.cc')
Source('ticked_object.cc')
Source('simulate.cc')
Source('stat_control.cc')
Source('stat_register.cc', skip_no_python=True)
Source('clock_domain.cc')
Source('voltage_domain.cc')
Source('system.cc')

View File

@@ -29,8 +29,6 @@
* Steve Reinhardt
*/
#include <Python.h>
#include <string>
#include <vector>
@@ -108,22 +106,6 @@ eventqDump()
}
}
void
py_interact()
{
PyObject *globals;
PyObject *locals;
globals = PyEval_GetGlobals();
Py_INCREF(globals);
locals = PyDict_New();
PyRun_String("import code", Py_file_input, globals, locals);
PyRun_String("code.interact(local=globals())", Py_file_input,
globals, locals);
Py_DECREF(globals);
Py_DECREF(locals);
}
int remote_gdb_base_port = 7000;
int

View File

@@ -53,8 +53,6 @@ void takeCheckpoint(Tick when);
*/
void eventqDump();
void py_interact();
int getRemoteGDBPort();
// Remote gdb base port. 0 disables remote gdb.
void setRemoteGDBPort(int port);

View File

@@ -46,7 +46,6 @@
#include <marshal.h>
#include <zlib.h>
#include <csignal>
#include <iostream>
#include <list>
#include <string>
@@ -65,90 +64,6 @@
using namespace std;
/// Stats signal handler.
void
dumpStatsHandler(int sigtype)
{
async_event = true;
async_statdump = true;
}
void
dumprstStatsHandler(int sigtype)
{
async_event = true;
async_statdump = true;
async_statreset = true;
}
/// Exit signal handler.
void
exitNowHandler(int sigtype)
{
async_event = true;
async_exit = true;
}
/// Abort signal handler.
void
abortHandler(int sigtype)
{
ccprintf(cerr, "Program aborted at tick %d\n", curTick());
}
// Handle SIGIO
static void
ioHandler(int sigtype)
{
async_event = true;
async_io = true;
}
static void
installSignalHandler(int signal, void (*handler)(int sigtype))
{
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sigemptyset(&sa.sa_mask);
sa.sa_handler = handler;
sa.sa_flags = SA_RESTART;
if (sigaction(signal, &sa, NULL) == -1)
panic("Failed to setup handler for signal %i\n", signal);
}
/*
* M5 can do several special things when various signals are sent.
* None are mandatory.
*/
void
initSignals()
{
// Floating point exceptions may happen on misspeculated paths, so
// ignore them
signal(SIGFPE, SIG_IGN);
// We use SIGTRAP sometimes for debugging
signal(SIGTRAP, SIG_IGN);
// Dump intermediate stats
installSignalHandler(SIGUSR1, dumpStatsHandler);
// Dump intermediate stats and reset them
installSignalHandler(SIGUSR2, dumprstStatsHandler);
// Exit cleanly on Interrupt (Ctrl-C)
installSignalHandler(SIGINT, exitNowHandler);
// Print out cycle number on abort
installSignalHandler(SIGABRT, abortHandler);
// Install a SIGIO handler to handle asynchronous file IO. See the
// PollQueue class.
installSignalHandler(SIGIO, ioHandler);
}
// The python library is totally messed up with respect to constness,
// so make a simple macro to make life a little easier
#define PyCC(x) (const_cast<char *>(x))

View File

@@ -76,11 +76,6 @@ struct EmbeddedSwig
static void initAll();
};
void dumpStatsHandler(int sigtype);
void dumprstStatsHandler(int sigtype);
void exitNowHandler(int sigtype);
void abortHandler(int sigtype);
void initSignals();
int initM5Python();
int m5Main(int argc, char **argv);
PyMODINIT_FUNC initm5(void);

138
src/sim/init_signals.cc Normal file
View File

@@ -0,0 +1,138 @@
/*
* Copyright (c) 2012 ARM Limited
* All rights reserved
*
* The license below extends only to copyright in the software and shall
* not be construed as granting a license to any other intellectual
* property including but not limited to intellectual property relating
* to a hardware implementation of the functionality of the software
* licensed hereunder. You may use the software subject to the license
* terms below provided that you ensure that this notice is replicated
* unmodified and in its entirety in all distributions of the software,
* modified or unmodified, in source code or in binary form.
*
* Copyright (c) 2000-2005 The Regents of The University of Michigan
* Copyright (c) 2008 The Hewlett-Packard Development Company
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer;
* redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution;
* neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: Nathan Binkert
*/
#include <csignal>
#include <iostream>
#include <string>
#include "base/cprintf.hh"
#include "sim/async.hh"
#include "sim/core.hh"
#include "sim/init_signals.hh"
using namespace std;
/// Stats signal handler.
void
dumpStatsHandler(int sigtype)
{
async_event = true;
async_statdump = true;
}
void
dumprstStatsHandler(int sigtype)
{
async_event = true;
async_statdump = true;
async_statreset = true;
}
/// Exit signal handler.
void
exitNowHandler(int sigtype)
{
async_event = true;
async_exit = true;
}
/// Abort signal handler.
void
abortHandler(int sigtype)
{
ccprintf(cerr, "Program aborted at cycle %d\n", curTick());
}
// Handle SIGIO
static void
ioHandler(int sigtype)
{
async_event = true;
async_io = true;
}
static void
installSignalHandler(int signal, void (*handler)(int sigtype))
{
struct sigaction sa;
memset(&sa, 0, sizeof(sa));
sigemptyset(&sa.sa_mask);
sa.sa_handler = handler;
sa.sa_flags = SA_RESTART;
if (sigaction(signal, &sa, NULL) == -1)
panic("Failed to setup handler for signal %i\n", signal);
}
/*
* M5 can do several special things when various signals are sent.
* None are mandatory.
*/
void
initSignals()
{
// Floating point exceptions may happen on misspeculated paths, so
// ignore them
signal(SIGFPE, SIG_IGN);
// We use SIGTRAP sometimes for debugging
signal(SIGTRAP, SIG_IGN);
// Dump intermediate stats
installSignalHandler(SIGUSR1, dumpStatsHandler);
// Dump intermediate stats and reset them
installSignalHandler(SIGUSR2, dumprstStatsHandler);
// Exit cleanly on Interrupt (Ctrl-C)
installSignalHandler(SIGINT, exitNowHandler);
// Print out cycle number on abort
installSignalHandler(SIGABRT, abortHandler);
// Install a SIGIO handler to handle asynchronous file IO. See the
// PollQueue class.
installSignalHandler(SIGIO, ioHandler);
}

40
src/sim/init_signals.hh Normal file
View File

@@ -0,0 +1,40 @@
/*
* Copyright (c) 2008 The Hewlett-Packard Development Company
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer;
* redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution;
* neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: Nathan Binkert
*/
#ifndef __SIM_INIT_SIGNALS_HH__
#define __SIM_INIT_SIGNALS_HH__
void dumpStatsHandler(int sigtype);
void dumprstStatsHandler(int sigtype);
void exitNowHandler(int sigtype);
void abortHandler(int sigtype);
void initSignals();
#endif // __SIM_INIT_SIGNALS_HH__

View File

@@ -31,6 +31,7 @@
#include <Python.h>
#include "sim/init.hh"
#include "sim/init_signals.hh"
// main() is now pretty stripped down and just sets up python and then
// calls initM5Python which loads the various embedded python modules

51
src/sim/py_interact.cc Normal file
View File

@@ -0,0 +1,51 @@
/*
* Copyright (c) 2003-2005 The Regents of The University of Michigan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer;
* redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution;
* neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: Nathan Binkert
* Steve Reinhardt
*/
#include <Python.h>
#include "sim/py_interact.hh"
void
py_interact()
{
PyObject *globals;
PyObject *locals;
globals = PyEval_GetGlobals();
Py_INCREF(globals);
locals = PyDict_New();
PyRun_String("import code", Py_file_input, globals, locals);
PyRun_String("code.interact(local=globals())", Py_file_input,
globals, locals);
Py_DECREF(globals);
Py_DECREF(locals);
}

40
src/sim/py_interact.hh Normal file
View File

@@ -0,0 +1,40 @@
/*
* Copyright (c) 2003-2005 The Regents of The University of Michigan
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer;
* redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution;
* neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: Nathan Binkert
*/
#ifndef __SIM_PY_INTERACT_HH__
#define __SIM_PY_INTERACT_HH__
/** @file This file provides py_interact useful for interacting with the
* embedded Python content in a debugger such as gdb.
*/
void py_interact();
#endif // __SIM_PY_INTERACT_HH__

View File

@@ -58,8 +58,6 @@
using namespace std;
extern SimObject *resolveSimObject(const string &);
//
// The base implementations use to_number for parsing and '<<' for
// displaying, suitable for integer types.
@@ -600,8 +598,8 @@ Checkpoint::dir()
}
Checkpoint::Checkpoint(const string &cpt_dir)
: db(new IniFile), cptDir(setDir(cpt_dir))
Checkpoint::Checkpoint(const string &cpt_dir, SimObjectResolver &resolver)
: db(new IniFile), objNameResolver(resolver), cptDir(setDir(cpt_dir))
{
string filename = cptDir + "/" + Checkpoint::baseFilename;
if (!db->load(filename)) {
@@ -630,7 +628,7 @@ Checkpoint::findObj(const string &section, const string &entry,
if (!db->find(section, entry, path))
return false;
value = resolveSimObject(path);
value = objNameResolver.resolveSimObject(path);
return true;
}

View File

@@ -255,14 +255,28 @@ class SerializableClass
SerializableClass the##OBJ_CLASS##Class(CLASS_NAME, \
OBJ_CLASS::createForUnserialize);
// Base class to wrap object resolving functionality. This can be
// provided to Checkpoint to allow it to map object names onto
// object C++ objects in which to unserialize
class SimObjectResolver
{
public:
virtual ~SimObjectResolver() { }
// Find a SimObject given a full path name
virtual SimObject *resolveSimObject(const std::string &name) = 0;
};
class Checkpoint
{
private:
IniFile *db;
SimObjectResolver &objNameResolver;
public:
Checkpoint(const std::string &cpt_dir);
Checkpoint(const std::string &cpt_dir, SimObjectResolver &resolver);
~Checkpoint();
const std::string cptDir;

53
src/sim/stat_register.cc Normal file
View File

@@ -0,0 +1,53 @@
/*
* Copyright (c) 2014 ARM Limited
* All rights reserved
*
* The license below extends only to copyright in the software and shall
* not be construed as granting a license to any other intellectual
* property including but not limited to intellectual property relating
* to a hardware implementation of the functionality of the software
* licensed hereunder. You may use the software subject to the license
* terms below provided that you ensure that this notice is replicated
* unmodified and in its entirety in all distributions of the software,
* modified or unmodified, in source code or in binary form.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer;
* redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution;
* neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: Andrew Bardsley
*/
#include "sim/stat_register.hh"
namespace Stats
{
extern void pythonDump();
extern void pythonReset();
void registerPythonStatsHandlers()
{
registerHandlers(pythonReset, pythonDump);
}
} // namespace Stats

57
src/sim/stat_register.hh Normal file
View File

@@ -0,0 +1,57 @@
/*
* Copyright (c) 2014 ARM Limited
* All rights reserved
*
* The license below extends only to copyright in the software and shall
* not be construed as granting a license to any other intellectual
* property including but not limited to intellectual property relating
* to a hardware implementation of the functionality of the software
* licensed hereunder. You may use the software subject to the license
* terms below provided that you ensure that this notice is replicated
* unmodified and in its entirety in all distributions of the software,
* modified or unmodified, in source code or in binary form.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer;
* redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution;
* neither the name of the copyright holders nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* Authors: Andrew Bardsley
*/
/* Provide a mechanism to register the Python stats reset/dump functions
* defined in src/swig/python/stats.i with the mechanisms in namespace
* Stats */
#ifndef __SIM_STAT_REGISTER_H__
#define __SIM_STAT_REGISTER_H__
#include "base/statistics.hh"
namespace Stats
{
/** Register py_... functions as the statistics handlers */
void registerPythonStatsHandlers();
} // namespace Stats
#endif // __SIM_STAT_REGISTER_H__