sim,util: Remove event dependencies from serialize.hh
With this change serialize.hh is no longer responsible for the (un)serialization of events. As a general rule, rules to (un)serialize non-basic types should be defined at the file that introduces that type. Therefore, (UN)SERIALIZE_EVENT have been moved to eventq.hh. Globals has a single instance which must be serialized and unserialized. Instead of having a stray global variable handled by Serialization, we pass its management to Root. As a side effect, Globals is assigned its own files: sim/globals.(cc/hh). Finally, 'unserializeGlobals()' is removed, so that Root can fully handle Globals' serialization. This breaks checkpoint compatibility, so a checkpoint upgrader is added. Change-Id: I9c8e57306f83f9cc30ab2b745a4972755191bec4 Signed-off-by: Daniel R. Carvalho <odanrc@yahoo.com.br> Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/43586 Tested-by: kokoro <noreply+kokoro@google.com> Maintainer: Bobby R. Bruce <bbruce@ucdavis.edu> Reviewed-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
This commit is contained in:
committed by
Daniel Carvalho
parent
c493d2c4ad
commit
19c7429520
@@ -142,7 +142,6 @@ def instantiate(ckpt_dir=None):
|
||||
if ckpt_dir:
|
||||
_drain_manager.preCheckpointRestore()
|
||||
ckpt = _m5.core.getCheckpoint(ckpt_dir)
|
||||
_m5.core.unserializeGlobals(ckpt);
|
||||
for obj in root.descendants(): obj.loadState(ckpt)
|
||||
else:
|
||||
for obj in root.descendants(): obj.initState()
|
||||
|
||||
@@ -308,7 +308,6 @@ pybind_init_core(py::module_ &m_native)
|
||||
*/
|
||||
m_core
|
||||
.def("serializeAll", &Serializable::serializeAll)
|
||||
.def("unserializeGlobals", &Serializable::unserializeGlobals)
|
||||
.def("getCheckpoint", [](const std::string &cpt_dir) {
|
||||
SimObject::setSimObjectResolver(&pybindSimObjectResolver);
|
||||
return new CheckpointIn(cpt_dir);
|
||||
|
||||
@@ -54,6 +54,7 @@ Source('py_interact.cc', add_tags='python')
|
||||
Source('eventq.cc')
|
||||
Source('futex_map.cc')
|
||||
Source('global_event.cc')
|
||||
Source('globals.cc')
|
||||
Source('init.cc', add_tags='python')
|
||||
Source('init_signals.cc')
|
||||
Source('main.cc', tags='main')
|
||||
|
||||
@@ -1152,4 +1152,22 @@ class EventFunctionWrapper : public Event
|
||||
const char *description() const { return "EventFunctionWrapped"; }
|
||||
};
|
||||
|
||||
/**
|
||||
* \def SERIALIZE_EVENT(event)
|
||||
*
|
||||
* @ingroup api_serialize
|
||||
*/
|
||||
#define SERIALIZE_EVENT(event) event.serializeSection(cp, #event);
|
||||
|
||||
/**
|
||||
* \def UNSERIALIZE_EVENT(event)
|
||||
*
|
||||
* @ingroup api_serialize
|
||||
*/
|
||||
#define UNSERIALIZE_EVENT(event) \
|
||||
do { \
|
||||
event.unserializeSection(cp, #event); \
|
||||
eventQueue()->checkpointReschedule(&event); \
|
||||
} while (0)
|
||||
|
||||
#endif // __SIM_EVENTQ_HH__
|
||||
|
||||
121
src/sim/globals.cc
Normal file
121
src/sim/globals.cc
Normal file
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright (c) 2015 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) 2002-2005 The Regents of The University of Michigan
|
||||
* Copyright (c) 2013 Advanced Micro Devices, Inc.
|
||||
* Copyright (c) 2013 Mark D. Hill and David A. Wood
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "sim/globals.hh"
|
||||
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include "base/logging.hh"
|
||||
#include "sim/cur_tick.hh"
|
||||
|
||||
/// The version tags for this build of the simulator, to be stored in the
|
||||
/// Globals section during serialization and compared upon unserialization.
|
||||
extern std::set<std::string> version_tags;
|
||||
|
||||
void
|
||||
Globals::serialize(CheckpointOut &cp) const
|
||||
{
|
||||
paramOut(cp, "curTick", curTick());
|
||||
SERIALIZE_CONTAINER(version_tags);
|
||||
}
|
||||
|
||||
void
|
||||
Globals::unserialize(CheckpointIn &cp)
|
||||
{
|
||||
paramIn(cp, "curTick", unserializedCurTick);
|
||||
|
||||
const std::string divider =
|
||||
"**********************************************************\n";
|
||||
const std::string §ion(Serializable::currentSection());
|
||||
std::string str;
|
||||
if (!cp.find(section, "version_tags", str)) {
|
||||
warn(divider);
|
||||
warn("!!!! Checkpoint uses an old versioning scheme. !!!!\n");
|
||||
warn("Run the checkpoint upgrader (util/cpt_upgrader.py) on your "
|
||||
"checkpoint\n");
|
||||
warn(divider);
|
||||
return;
|
||||
}
|
||||
|
||||
std::set<std::string> cpt_tags;
|
||||
arrayParamIn(cp, "version_tags", cpt_tags); // UNSERIALIZE_CONTAINER
|
||||
|
||||
bool err = false;
|
||||
for (const auto& t : version_tags) {
|
||||
if (cpt_tags.find(t) == cpt_tags.end()) {
|
||||
// checkpoint is missing tag that this binary has
|
||||
if (!err) {
|
||||
warn(divider);
|
||||
warn(
|
||||
"!!! Checkpoint is missing the following version tags:\n");
|
||||
err = true;
|
||||
}
|
||||
warn(" %s\n", t);
|
||||
}
|
||||
}
|
||||
if (err) {
|
||||
warn("You might experience some issues when restoring and should run "
|
||||
"the checkpoint upgrader (util/cpt_upgrader.py) on your "
|
||||
"checkpoint\n");
|
||||
warn(divider);
|
||||
}
|
||||
|
||||
err = false;
|
||||
for (const auto& t : cpt_tags) {
|
||||
if (version_tags.find(t) == version_tags.end()) {
|
||||
// gem5 binary is missing tag that this checkpoint has
|
||||
if (!err) {
|
||||
warn(divider);
|
||||
warn("!!!! gem5 is missing the following version tags:\n");
|
||||
err = true;
|
||||
}
|
||||
warn(" %s\n", t);
|
||||
}
|
||||
}
|
||||
if (err) {
|
||||
warn("Running a checkpoint with incompatible version tags is not "
|
||||
"supported. While it might work, you may experience incorrect "
|
||||
"behavior or crashes.\n");
|
||||
warn(divider);
|
||||
}
|
||||
}
|
||||
63
src/sim/globals.hh
Normal file
63
src/sim/globals.hh
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2015 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) 2002-2005 The Regents of The University of Michigan
|
||||
* Copyright (c) 2013 Advanced Micro Devices, Inc.
|
||||
* Copyright (c) 2013 Mark D. Hill and David A. Wood
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef __SIM_GLOBALS_HH__
|
||||
#define __SIM_GLOBALS_HH__
|
||||
|
||||
#include "base/types.hh"
|
||||
#include "sim/serialize.hh"
|
||||
|
||||
/// Container for serializing global variables (not associated with
|
||||
/// any serialized object).
|
||||
class Globals : public Serializable
|
||||
{
|
||||
public:
|
||||
Globals() : unserializedCurTick(0) {}
|
||||
~Globals() = default;
|
||||
|
||||
void serialize(CheckpointOut &cp) const override;
|
||||
void unserialize(CheckpointIn &cp) override;
|
||||
|
||||
Tick unserializedCurTick;
|
||||
};
|
||||
|
||||
#endif // __SIM_GLOBALS_HH__
|
||||
@@ -203,8 +203,17 @@ Root::serialize(CheckpointOut &cp) const
|
||||
SERIALIZE_SCALAR(FullSystem);
|
||||
std::string isa = THE_ISA_STR;
|
||||
SERIALIZE_SCALAR(isa);
|
||||
|
||||
globals.serializeSection(cp, "globals");
|
||||
}
|
||||
|
||||
void
|
||||
Root::unserialize(CheckpointIn &cp)
|
||||
{
|
||||
globals.unserializeSection(cp, "globals");
|
||||
for (uint32_t i = 0; i < numMainEventQueues; ++i)
|
||||
mainEventQueue[i]->setCurTick(globals.unserializedCurTick);
|
||||
}
|
||||
|
||||
bool FullSystem;
|
||||
unsigned int FullSystemInt;
|
||||
|
||||
@@ -56,6 +56,7 @@
|
||||
#include "base/types.hh"
|
||||
#include "params/Root.hh"
|
||||
#include "sim/eventq.hh"
|
||||
#include "sim/globals.hh"
|
||||
#include "sim/sim_object.hh"
|
||||
|
||||
class Root : public SimObject
|
||||
@@ -71,6 +72,8 @@ class Root : public SimObject
|
||||
|
||||
Time lastTime;
|
||||
|
||||
Globals globals;
|
||||
|
||||
void timeSync();
|
||||
EventFunctionWrapper syncEvent;
|
||||
|
||||
@@ -143,6 +146,7 @@ class Root : public SimObject
|
||||
void startup() override;
|
||||
|
||||
void serialize(CheckpointOut &cp) const override;
|
||||
void unserialize(CheckpointIn &cp) override;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -57,9 +57,6 @@
|
||||
#include "base/output.hh"
|
||||
#include "base/trace.hh"
|
||||
#include "debug/Checkpoint.hh"
|
||||
#include "sim/eventq.hh"
|
||||
#include "sim/sim_events.hh"
|
||||
#include "sim/sim_exit.hh"
|
||||
#include "sim/sim_object.hh"
|
||||
|
||||
// For stat reset hack
|
||||
@@ -72,92 +69,6 @@ std::stack<std::string> Serializable::path;
|
||||
|
||||
/////////////////////////////
|
||||
|
||||
/// Container for serializing global variables (not associated with
|
||||
/// any serialized object).
|
||||
class Globals : public Serializable
|
||||
{
|
||||
public:
|
||||
Globals()
|
||||
: unserializedCurTick(0) {}
|
||||
|
||||
void serialize(CheckpointOut &cp) const override;
|
||||
void unserialize(CheckpointIn &cp) override;
|
||||
|
||||
Tick unserializedCurTick;
|
||||
};
|
||||
|
||||
/// The one and only instance of the Globals class.
|
||||
Globals globals;
|
||||
|
||||
/// The version tags for this build of the simulator, to be stored in the
|
||||
/// Globals section during serialization and compared upon unserialization.
|
||||
extern std::set<std::string> version_tags;
|
||||
|
||||
void
|
||||
Globals::serialize(CheckpointOut &cp) const
|
||||
{
|
||||
paramOut(cp, "curTick", curTick());
|
||||
SERIALIZE_CONTAINER(version_tags);
|
||||
}
|
||||
|
||||
void
|
||||
Globals::unserialize(CheckpointIn &cp)
|
||||
{
|
||||
paramIn(cp, "curTick", unserializedCurTick);
|
||||
|
||||
const std::string §ion(Serializable::currentSection());
|
||||
std::string str;
|
||||
if (!cp.find(section, "version_tags", str)) {
|
||||
warn("**********************************************************\n");
|
||||
warn("!!!! Checkpoint uses an old versioning scheme. !!!!\n");
|
||||
warn("Run the checkpoint upgrader (util/cpt_upgrader.py) on your "
|
||||
"checkpoint\n");
|
||||
warn("**********************************************************\n");
|
||||
return;
|
||||
}
|
||||
|
||||
std::set<std::string> cpt_tags;
|
||||
arrayParamIn(cp, "version_tags", cpt_tags); // UNSERIALIZE_CONTAINER
|
||||
|
||||
bool err = false;
|
||||
for (const auto& t : version_tags) {
|
||||
if (cpt_tags.find(t) == cpt_tags.end()) {
|
||||
// checkpoint is missing tag that this binary has
|
||||
if (!err) {
|
||||
warn("*****************************************************\n");
|
||||
warn("!!!! Checkpoint is missing the following version tags:\n");
|
||||
err = true;
|
||||
}
|
||||
warn(" %s\n", t);
|
||||
}
|
||||
}
|
||||
if (err) {
|
||||
warn("You might experience some issues when restoring and should run "
|
||||
"the checkpoint upgrader (util/cpt_upgrader.py) on your "
|
||||
"checkpoint\n");
|
||||
warn("**********************************************************\n");
|
||||
}
|
||||
|
||||
err = false;
|
||||
for (const auto& t : cpt_tags) {
|
||||
if (version_tags.find(t) == version_tags.end()) {
|
||||
// gem5 binary is missing tag that this checkpoint has
|
||||
if (!err) {
|
||||
warn("*****************************************************\n");
|
||||
warn("!!!! gem5 is missing the following version tags:\n");
|
||||
err = true;
|
||||
}
|
||||
warn(" %s\n", t);
|
||||
}
|
||||
}
|
||||
if (err) {
|
||||
warn("Running a checkpoint with incompatible version tags is not "
|
||||
"supported. While it might work, you may experience incorrect "
|
||||
"behavior or crashes.\n");
|
||||
warn("**********************************************************\n");
|
||||
}
|
||||
}
|
||||
|
||||
Serializable::Serializable()
|
||||
{
|
||||
}
|
||||
@@ -194,20 +105,9 @@ Serializable::serializeAll(const std::string &cpt_dir)
|
||||
fatal("Unable to open file %s for writing\n", cpt_file.c_str());
|
||||
outstream << "## checkpoint generated: " << ctime(&t);
|
||||
|
||||
globals.serializeSection(outstream, "Globals");
|
||||
|
||||
SimObject::serializeAll(outstream);
|
||||
}
|
||||
|
||||
void
|
||||
Serializable::unserializeGlobals(CheckpointIn &cp)
|
||||
{
|
||||
globals.unserializeSection(cp, "Globals");
|
||||
|
||||
for (uint32_t i = 0; i < numMainEventQueues; ++i)
|
||||
mainEventQueue[i]->setCurTick(globals.unserializedCurTick);
|
||||
}
|
||||
|
||||
Serializable::ScopedCheckpointSection::~ScopedCheckpointSection()
|
||||
{
|
||||
assert(!path.empty());
|
||||
|
||||
@@ -307,11 +307,6 @@ class Serializable
|
||||
*/
|
||||
static void serializeAll(const std::string &cpt_dir);
|
||||
|
||||
/**
|
||||
* @ingroup api_serialize
|
||||
*/
|
||||
static void unserializeGlobals(CheckpointIn &cp);
|
||||
|
||||
private:
|
||||
static std::stack<std::string> path;
|
||||
};
|
||||
@@ -645,24 +640,6 @@ mappingParamIn(CheckpointIn &cp, const char* sectionName,
|
||||
#define UNSERIALIZE_CONTAINER(member) \
|
||||
arrayParamIn(cp, #member, member)
|
||||
|
||||
/**
|
||||
* \def SERIALIZE_EVENT(event)
|
||||
*
|
||||
* @ingroup api_serialize
|
||||
*/
|
||||
#define SERIALIZE_EVENT(event) event.serializeSection(cp, #event);
|
||||
|
||||
/**
|
||||
* \def UNSERIALIZE_EVENT(event)
|
||||
*
|
||||
* @ingroup api_serialize
|
||||
*/
|
||||
#define UNSERIALIZE_EVENT(event) \
|
||||
do { \
|
||||
event.unserializeSection(cp, #event); \
|
||||
eventQueue()->checkpointReschedule(&event); \
|
||||
} while (0)
|
||||
|
||||
/**
|
||||
* \def SERIALIZE_OBJ(obj)
|
||||
*
|
||||
|
||||
@@ -142,7 +142,6 @@ SimObject::serializeAll(CheckpointOut &cp)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
//
|
||||
// static function: flag which objects should have the debugger break
|
||||
|
||||
@@ -218,8 +218,12 @@ def process_file(path, **kwargs):
|
||||
change = True
|
||||
|
||||
cpt.remove_option('root', 'cpt_ver')
|
||||
# @todo The 'Globals' option is deprecated, and should be removed in the
|
||||
# future
|
||||
elif cpt.has_option('Globals','version_tags'):
|
||||
tags = set((''.join(cpt.get('Globals','version_tags'))).split())
|
||||
elif cpt.has_option('root.globals','version_tags'):
|
||||
tags = set((''.join(cpt.get('root.globals','version_tags'))).split())
|
||||
else:
|
||||
print("fatal: no version information in checkpoint")
|
||||
exit(1)
|
||||
@@ -253,7 +257,7 @@ def process_file(path, **kwargs):
|
||||
verboseprint("...nothing to do")
|
||||
return
|
||||
|
||||
cpt.set('Globals', 'version_tags', ' '.join(tags))
|
||||
cpt.set('root.globals', 'version_tags', ' '.join(tags))
|
||||
|
||||
# Write the old data back
|
||||
verboseprint("...completed")
|
||||
|
||||
13
util/cpt_upgraders/globals-to-root.py
Normal file
13
util/cpt_upgraders/globals-to-root.py
Normal file
@@ -0,0 +1,13 @@
|
||||
# This upgrader renames section "Globals" as "root.globals".
|
||||
def upgrader(cpt):
|
||||
import re
|
||||
for sec in cpt.sections():
|
||||
if re.match('Globals', sec):
|
||||
# rename the section
|
||||
items = cpt.items(sec)
|
||||
cpt.add_section('root.globals')
|
||||
for item in items:
|
||||
cpt.set('root.globals', item[0], item[1])
|
||||
cpt.remove_section(sec)
|
||||
|
||||
legacy_version = 16
|
||||
Reference in New Issue
Block a user