serialize.cc revision 10386
12SN/A/* 21762SN/A * Copyright (c) 2002-2005 The Regents of The University of Michigan 39983Sstever@gmail.com * Copyright (c) 2013 Advanced Micro Devices, Inc. 49983Sstever@gmail.com * Copyright (c) 2013 Mark D. Hill and David A. Wood 52SN/A * All rights reserved. 62SN/A * 72SN/A * Redistribution and use in source and binary forms, with or without 82SN/A * modification, are permitted provided that the following conditions are 92SN/A * met: redistributions of source code must retain the above copyright 102SN/A * notice, this list of conditions and the following disclaimer; 112SN/A * redistributions in binary form must reproduce the above copyright 122SN/A * notice, this list of conditions and the following disclaimer in the 132SN/A * documentation and/or other materials provided with the distribution; 142SN/A * neither the name of the copyright holders nor the names of its 152SN/A * contributors may be used to endorse or promote products derived from 162SN/A * this software without specific prior written permission. 172SN/A * 182SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 192SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 202SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 212SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 222SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 232SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 242SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 252SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 262SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 272SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 282SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 292665Ssaidi@eecs.umich.edu * 302760Sbinkertn@umich.edu * Authors: Nathan Binkert 312760Sbinkertn@umich.edu * Erik Hallnor 322665Ssaidi@eecs.umich.edu * Steve Reinhardt 332SN/A */ 342SN/A 358229Snate@binkert.org#include <sys/stat.h> 362SN/A#include <sys/time.h> 37363SN/A#include <sys/types.h> 382SN/A 398229Snate@binkert.org#include <cerrno> 402SN/A#include <fstream> 412SN/A#include <list> 422SN/A#include <string> 432SN/A#include <vector> 442SN/A 45363SN/A#include "base/inifile.hh" 4656SN/A#include "base/misc.hh" 471388SN/A#include "base/output.hh" 48217SN/A#include "base/str.hh" 49363SN/A#include "base/trace.hh" 5056SN/A#include "sim/eventq.hh" 5156SN/A#include "sim/serialize.hh" 5256SN/A#include "sim/sim_events.hh" 531638SN/A#include "sim/sim_exit.hh" 5456SN/A#include "sim/sim_object.hh" 552SN/A 562356SN/A// For stat reset hack 572356SN/A#include "sim/stat_control.hh" 582356SN/A 592SN/Ausing namespace std; 602SN/A 614000Ssaidi@eecs.umich.eduextern SimObject *resolveSimObject(const string &); 624000Ssaidi@eecs.umich.edu 634762Snate@binkert.org// 644762Snate@binkert.org// The base implementations use to_number for parsing and '<<' for 654762Snate@binkert.org// displaying, suitable for integer types. 664762Snate@binkert.org// 674762Snate@binkert.orgtemplate <class T> 684762Snate@binkert.orgbool 694762Snate@binkert.orgparseParam(const string &s, T &value) 704762Snate@binkert.org{ 714762Snate@binkert.org return to_number(s, value); 724762Snate@binkert.org} 734762Snate@binkert.org 744762Snate@binkert.orgtemplate <class T> 754762Snate@binkert.orgvoid 764762Snate@binkert.orgshowParam(ostream &os, const T &value) 774762Snate@binkert.org{ 784762Snate@binkert.org os << value; 794762Snate@binkert.org} 804762Snate@binkert.org 814762Snate@binkert.org// 824762Snate@binkert.org// Template specializations: 834762Snate@binkert.org// - char (8-bit integer) 844762Snate@binkert.org// - floating-point types 854762Snate@binkert.org// - bool 864762Snate@binkert.org// - string 874762Snate@binkert.org// 884762Snate@binkert.org 894762Snate@binkert.org// Treat 8-bit ints (chars) as ints on output, not as chars 904762Snate@binkert.orgtemplate <> 914762Snate@binkert.orgvoid 927494Ssteve.reinhardt@amd.comshowParam(ostream &os, const char &value) 937494Ssteve.reinhardt@amd.com{ 947494Ssteve.reinhardt@amd.com os << (int)value; 957494Ssteve.reinhardt@amd.com} 967494Ssteve.reinhardt@amd.com 977494Ssteve.reinhardt@amd.com 987494Ssteve.reinhardt@amd.comtemplate <> 997494Ssteve.reinhardt@amd.comvoid 1007490Ssteve.reinhardt@amd.comshowParam(ostream &os, const signed char &value) 1014762Snate@binkert.org{ 1024762Snate@binkert.org os << (int)value; 1034762Snate@binkert.org} 1044762Snate@binkert.org 1054762Snate@binkert.org 1064762Snate@binkert.orgtemplate <> 1074762Snate@binkert.orgvoid 1084762Snate@binkert.orgshowParam(ostream &os, const unsigned char &value) 1094762Snate@binkert.org{ 1104762Snate@binkert.org os << (unsigned int)value; 1114762Snate@binkert.org} 1124762Snate@binkert.org 1134762Snate@binkert.org 1144762Snate@binkert.orgtemplate <> 1154762Snate@binkert.orgbool 1164762Snate@binkert.orgparseParam(const string &s, float &value) 1174762Snate@binkert.org{ 11810386Sandreas.hansson@arm.com return to_number(s, value); 1194762Snate@binkert.org} 1204762Snate@binkert.org 1214762Snate@binkert.orgtemplate <> 1224762Snate@binkert.orgbool 1234762Snate@binkert.orgparseParam(const string &s, double &value) 1244762Snate@binkert.org{ 12510386Sandreas.hansson@arm.com return to_number(s, value); 1264762Snate@binkert.org} 1274762Snate@binkert.org 1284762Snate@binkert.orgtemplate <> 1294762Snate@binkert.orgbool 1304762Snate@binkert.orgparseParam(const string &s, bool &value) 1314762Snate@binkert.org{ 13210386Sandreas.hansson@arm.com return to_bool(s, value); 1334762Snate@binkert.org} 1344762Snate@binkert.org 1354762Snate@binkert.org// Display bools as strings 1364762Snate@binkert.orgtemplate <> 1374762Snate@binkert.orgvoid 1384762Snate@binkert.orgshowParam(ostream &os, const bool &value) 1394762Snate@binkert.org{ 1404762Snate@binkert.org os << (value ? "true" : "false"); 1414762Snate@binkert.org} 1424762Snate@binkert.org 1434762Snate@binkert.org 1444762Snate@binkert.org// String requires no processing to speak of 1454762Snate@binkert.orgtemplate <> 1464762Snate@binkert.orgbool 1474762Snate@binkert.orgparseParam(const string &s, string &value) 1484762Snate@binkert.org{ 1494762Snate@binkert.org value = s; 1504762Snate@binkert.org return true; 1514762Snate@binkert.org} 1524762Snate@binkert.org 1532287SN/Aint Serializable::ckptMaxCount = 0; 1542287SN/Aint Serializable::ckptCount = 0; 1552287SN/Aint Serializable::ckptPrevCount = -1; 1561637SN/A 1572SN/Avoid 158395SN/ASerializable::nameOut(ostream &os) 1592SN/A{ 160217SN/A os << "\n[" << name() << "]\n"; 1612SN/A} 1622SN/A 1632SN/Avoid 164395SN/ASerializable::nameOut(ostream &os, const string &_name) 1652SN/A{ 166217SN/A os << "\n[" << _name << "]\n"; 1672SN/A} 1682SN/A 169217SN/Atemplate <class T> 1702SN/Avoid 1716225Snate@binkert.orgparamOut(ostream &os, const string &name, const T ¶m) 1722SN/A{ 173217SN/A os << name << "="; 174217SN/A showParam(os, param); 175217SN/A os << "\n"; 1762SN/A} 1772SN/A 1784841Ssaidi@eecs.umich.edutemplate <class T> 1794841Ssaidi@eecs.umich.eduvoid 1806225Snate@binkert.orgarrayParamOut(ostream &os, const string &name, const vector<T> ¶m) 1814841Ssaidi@eecs.umich.edu{ 1826227Snate@binkert.org typename vector<T>::size_type size = param.size(); 1834841Ssaidi@eecs.umich.edu os << name << "="; 1844841Ssaidi@eecs.umich.edu if (size > 0) 1854841Ssaidi@eecs.umich.edu showParam(os, param[0]); 1866227Snate@binkert.org for (typename vector<T>::size_type i = 1; i < size; ++i) { 1874841Ssaidi@eecs.umich.edu os << " "; 1884841Ssaidi@eecs.umich.edu showParam(os, param[i]); 1894841Ssaidi@eecs.umich.edu } 1904841Ssaidi@eecs.umich.edu os << "\n"; 1914841Ssaidi@eecs.umich.edu} 1924841Ssaidi@eecs.umich.edu 1937948SAli.Saidi@ARM.comtemplate <class T> 1947948SAli.Saidi@ARM.comvoid 1957948SAli.Saidi@ARM.comarrayParamOut(ostream &os, const string &name, const list<T> ¶m) 1967948SAli.Saidi@ARM.com{ 1977948SAli.Saidi@ARM.com typename list<T>::const_iterator it = param.begin(); 1987948SAli.Saidi@ARM.com 1997948SAli.Saidi@ARM.com os << name << "="; 2007948SAli.Saidi@ARM.com if (param.size() > 0) 2017948SAli.Saidi@ARM.com showParam(os, *it); 2027948SAli.Saidi@ARM.com it++; 2037948SAli.Saidi@ARM.com while (it != param.end()) { 2047948SAli.Saidi@ARM.com os << " "; 2057948SAli.Saidi@ARM.com showParam(os, *it); 2067948SAli.Saidi@ARM.com it++; 2077948SAli.Saidi@ARM.com } 2087948SAli.Saidi@ARM.com os << "\n"; 2097948SAli.Saidi@ARM.com} 210217SN/A 211217SN/Atemplate <class T> 212217SN/Avoid 2136225Snate@binkert.orgparamIn(Checkpoint *cp, const string §ion, const string &name, T ¶m) 2142SN/A{ 2156225Snate@binkert.org string str; 216237SN/A if (!cp->find(section, name, str) || !parseParam(str, param)) { 217217SN/A fatal("Can't unserialize '%s:%s'\n", section, name); 218217SN/A } 2192SN/A} 2202SN/A 2216820SLisa.Hsu@amd.comtemplate <class T> 2226820SLisa.Hsu@amd.combool 2236820SLisa.Hsu@amd.comoptParamIn(Checkpoint *cp, const string §ion, const string &name, T ¶m) 2246820SLisa.Hsu@amd.com{ 2256820SLisa.Hsu@amd.com string str; 2266820SLisa.Hsu@amd.com if (!cp->find(section, name, str) || !parseParam(str, param)) { 2276820SLisa.Hsu@amd.com warn("optional parameter %s:%s not present\n", section, name); 2286820SLisa.Hsu@amd.com return false; 2296820SLisa.Hsu@amd.com } else { 2306820SLisa.Hsu@amd.com return true; 2316820SLisa.Hsu@amd.com } 2326820SLisa.Hsu@amd.com} 233217SN/A 234217SN/Atemplate <class T> 235217SN/Avoid 2366227Snate@binkert.orgarrayParamOut(ostream &os, const string &name, const T *param, unsigned size) 237217SN/A{ 238217SN/A os << name << "="; 239217SN/A if (size > 0) 240217SN/A showParam(os, param[0]); 2416227Snate@binkert.org for (unsigned i = 1; i < size; ++i) { 242217SN/A os << " "; 243217SN/A showParam(os, param[i]); 244217SN/A } 245217SN/A os << "\n"; 246217SN/A} 247217SN/A 248217SN/A 249217SN/Atemplate <class T> 250217SN/Avoid 2516225Snate@binkert.orgarrayParamIn(Checkpoint *cp, const string §ion, const string &name, 2526227Snate@binkert.org T *param, unsigned size) 253217SN/A{ 2546225Snate@binkert.org string str; 255237SN/A if (!cp->find(section, name, str)) { 256217SN/A fatal("Can't unserialize '%s:%s'\n", section, name); 257217SN/A } 258217SN/A 259217SN/A // code below stolen from VectorParam<T>::parse(). 260217SN/A // it would be nice to unify these somehow... 261217SN/A 262217SN/A vector<string> tokens; 263217SN/A 264217SN/A tokenize(tokens, str, ' '); 265217SN/A 266217SN/A // Need this if we were doing a vector 267217SN/A // value.resize(tokens.size()); 268217SN/A 269217SN/A if (tokens.size() != size) { 270217SN/A fatal("Array size mismatch on %s:%s'\n", section, name); 271217SN/A } 272217SN/A 2736227Snate@binkert.org for (vector<string>::size_type i = 0; i < tokens.size(); i++) { 274217SN/A // need to parse into local variable to handle vector<bool>, 275217SN/A // for which operator[] returns a special reference class 276217SN/A // that's not the same as 'bool&', (since it's a packed 277217SN/A // vector) 2787576SAli.Saidi@ARM.com T scalar_value = 0; 279217SN/A if (!parseParam(tokens[i], scalar_value)) { 280217SN/A string err("could not parse \""); 281217SN/A 282217SN/A err += str; 283217SN/A err += "\""; 284217SN/A 285217SN/A fatal(err); 286217SN/A } 287217SN/A 288217SN/A // assign parsed value to vector 289217SN/A param[i] = scalar_value; 290217SN/A } 291217SN/A} 292217SN/A 2934841Ssaidi@eecs.umich.edutemplate <class T> 2944841Ssaidi@eecs.umich.eduvoid 2956225Snate@binkert.orgarrayParamIn(Checkpoint *cp, const string §ion, 2966225Snate@binkert.org const string &name, vector<T> ¶m) 2974841Ssaidi@eecs.umich.edu{ 2986225Snate@binkert.org string str; 2994841Ssaidi@eecs.umich.edu if (!cp->find(section, name, str)) { 3004841Ssaidi@eecs.umich.edu fatal("Can't unserialize '%s:%s'\n", section, name); 3014841Ssaidi@eecs.umich.edu } 3024841Ssaidi@eecs.umich.edu 3034841Ssaidi@eecs.umich.edu // code below stolen from VectorParam<T>::parse(). 3044841Ssaidi@eecs.umich.edu // it would be nice to unify these somehow... 3054841Ssaidi@eecs.umich.edu 3064841Ssaidi@eecs.umich.edu vector<string> tokens; 3074841Ssaidi@eecs.umich.edu 3084841Ssaidi@eecs.umich.edu tokenize(tokens, str, ' '); 3094841Ssaidi@eecs.umich.edu 3104841Ssaidi@eecs.umich.edu // Need this if we were doing a vector 3114841Ssaidi@eecs.umich.edu // value.resize(tokens.size()); 3124841Ssaidi@eecs.umich.edu 3134841Ssaidi@eecs.umich.edu param.resize(tokens.size()); 3144841Ssaidi@eecs.umich.edu 3156227Snate@binkert.org for (vector<string>::size_type i = 0; i < tokens.size(); i++) { 3164841Ssaidi@eecs.umich.edu // need to parse into local variable to handle vector<bool>, 3174841Ssaidi@eecs.umich.edu // for which operator[] returns a special reference class 3184841Ssaidi@eecs.umich.edu // that's not the same as 'bool&', (since it's a packed 3194841Ssaidi@eecs.umich.edu // vector) 3207576SAli.Saidi@ARM.com T scalar_value = 0; 3214841Ssaidi@eecs.umich.edu if (!parseParam(tokens[i], scalar_value)) { 3224841Ssaidi@eecs.umich.edu string err("could not parse \""); 3234841Ssaidi@eecs.umich.edu 3244841Ssaidi@eecs.umich.edu err += str; 3254841Ssaidi@eecs.umich.edu err += "\""; 3264841Ssaidi@eecs.umich.edu 3274841Ssaidi@eecs.umich.edu fatal(err); 3284841Ssaidi@eecs.umich.edu } 3294841Ssaidi@eecs.umich.edu 3304841Ssaidi@eecs.umich.edu // assign parsed value to vector 3314841Ssaidi@eecs.umich.edu param[i] = scalar_value; 3324841Ssaidi@eecs.umich.edu } 3334841Ssaidi@eecs.umich.edu} 3344841Ssaidi@eecs.umich.edu 3357948SAli.Saidi@ARM.comtemplate <class T> 3367948SAli.Saidi@ARM.comvoid 3377948SAli.Saidi@ARM.comarrayParamIn(Checkpoint *cp, const string §ion, 3387948SAli.Saidi@ARM.com const string &name, list<T> ¶m) 3397948SAli.Saidi@ARM.com{ 3407948SAli.Saidi@ARM.com string str; 3417948SAli.Saidi@ARM.com if (!cp->find(section, name, str)) { 3427948SAli.Saidi@ARM.com fatal("Can't unserialize '%s:%s'\n", section, name); 3437948SAli.Saidi@ARM.com } 3447948SAli.Saidi@ARM.com param.clear(); 3457948SAli.Saidi@ARM.com 3467948SAli.Saidi@ARM.com vector<string> tokens; 3477948SAli.Saidi@ARM.com tokenize(tokens, str, ' '); 3487948SAli.Saidi@ARM.com 3497948SAli.Saidi@ARM.com for (vector<string>::size_type i = 0; i < tokens.size(); i++) { 3507948SAli.Saidi@ARM.com T scalar_value = 0; 3517948SAli.Saidi@ARM.com if (!parseParam(tokens[i], scalar_value)) { 3527948SAli.Saidi@ARM.com string err("could not parse \""); 3537948SAli.Saidi@ARM.com 3547948SAli.Saidi@ARM.com err += str; 3557948SAli.Saidi@ARM.com err += "\""; 3567948SAli.Saidi@ARM.com 3577948SAli.Saidi@ARM.com fatal(err); 3587948SAli.Saidi@ARM.com } 3597948SAli.Saidi@ARM.com 3607948SAli.Saidi@ARM.com // assign parsed value to vector 3617948SAli.Saidi@ARM.com param.push_back(scalar_value); 3627948SAli.Saidi@ARM.com } 3637948SAli.Saidi@ARM.com} 3647948SAli.Saidi@ARM.com 3657948SAli.Saidi@ARM.com 366237SN/Avoid 3676225Snate@binkert.orgobjParamIn(Checkpoint *cp, const string §ion, 3686225Snate@binkert.org const string &name, SimObject * ¶m) 369237SN/A{ 370237SN/A if (!cp->findObj(section, name, param)) { 371237SN/A fatal("Can't unserialize '%s:%s'\n", section, name); 372237SN/A } 373237SN/A} 374237SN/A 375237SN/A 3765543Ssaidi@eecs.umich.edu#define INSTANTIATE_PARAM_TEMPLATES(type) \ 3775543Ssaidi@eecs.umich.edutemplate void \ 3786225Snate@binkert.orgparamOut(ostream &os, const string &name, type const ¶m); \ 3795543Ssaidi@eecs.umich.edutemplate void \ 3806225Snate@binkert.orgparamIn(Checkpoint *cp, const string §ion, \ 3816225Snate@binkert.org const string &name, type & param); \ 3826820SLisa.Hsu@amd.comtemplate bool \ 3836820SLisa.Hsu@amd.comoptParamIn(Checkpoint *cp, const string §ion, \ 3846820SLisa.Hsu@amd.com const string &name, type & param); \ 3855543Ssaidi@eecs.umich.edutemplate void \ 3866225Snate@binkert.orgarrayParamOut(ostream &os, const string &name, \ 3876227Snate@binkert.org type const *param, unsigned size); \ 3885543Ssaidi@eecs.umich.edutemplate void \ 3896225Snate@binkert.orgarrayParamIn(Checkpoint *cp, const string §ion, \ 3906227Snate@binkert.org const string &name, type *param, unsigned size); \ 3915543Ssaidi@eecs.umich.edutemplate void \ 3926225Snate@binkert.orgarrayParamOut(ostream &os, const string &name, \ 3936225Snate@binkert.org const vector<type> ¶m); \ 3945543Ssaidi@eecs.umich.edutemplate void \ 3956225Snate@binkert.orgarrayParamIn(Checkpoint *cp, const string §ion, \ 3967948SAli.Saidi@ARM.com const string &name, vector<type> ¶m); \ 3977948SAli.Saidi@ARM.comtemplate void \ 3987948SAli.Saidi@ARM.comarrayParamOut(ostream &os, const string &name, \ 3997948SAli.Saidi@ARM.com const list<type> ¶m); \ 4007948SAli.Saidi@ARM.comtemplate void \ 4017948SAli.Saidi@ARM.comarrayParamIn(Checkpoint *cp, const string §ion, \ 4027948SAli.Saidi@ARM.com const string &name, list<type> ¶m); 403217SN/A 4047494Ssteve.reinhardt@amd.comINSTANTIATE_PARAM_TEMPLATES(char) 4051642SN/AINSTANTIATE_PARAM_TEMPLATES(signed char) 4061642SN/AINSTANTIATE_PARAM_TEMPLATES(unsigned char) 4071642SN/AINSTANTIATE_PARAM_TEMPLATES(signed short) 4081642SN/AINSTANTIATE_PARAM_TEMPLATES(unsigned short) 4091642SN/AINSTANTIATE_PARAM_TEMPLATES(signed int) 4101642SN/AINSTANTIATE_PARAM_TEMPLATES(unsigned int) 4111642SN/AINSTANTIATE_PARAM_TEMPLATES(signed long) 4121642SN/AINSTANTIATE_PARAM_TEMPLATES(unsigned long) 4131642SN/AINSTANTIATE_PARAM_TEMPLATES(signed long long) 4141642SN/AINSTANTIATE_PARAM_TEMPLATES(unsigned long long) 415219SN/AINSTANTIATE_PARAM_TEMPLATES(bool) 4165992Snate@binkert.orgINSTANTIATE_PARAM_TEMPLATES(float) 4175992Snate@binkert.orgINSTANTIATE_PARAM_TEMPLATES(double) 418217SN/AINSTANTIATE_PARAM_TEMPLATES(string) 419217SN/A 420217SN/A 421395SN/A///////////////////////////// 422395SN/A 423395SN/A/// Container for serializing global variables (not associated with 424395SN/A/// any serialized object). 425395SN/Aclass Globals : public Serializable 4262SN/A{ 427395SN/A public: 428512SN/A const string name() const; 429510SN/A void serialize(ostream &os); 4308737Skoansin.tan@gmail.com void unserialize(Checkpoint *cp, const std::string §ion); 431395SN/A}; 4322SN/A 433395SN/A/// The one and only instance of the Globals class. 434395SN/AGlobals globals; 4352SN/A 436512SN/Aconst string 437395SN/AGlobals::name() const 4382SN/A{ 439395SN/A return "Globals"; 4402SN/A} 4412SN/A 4422SN/Avoid 443510SN/AGlobals::serialize(ostream &os) 4442SN/A{ 445395SN/A nameOut(os); 4467864Ssteve.reinhardt@amd.com paramOut(os, "curTick", curTick()); 447395SN/A 4489983Sstever@gmail.com paramOut(os, "numMainEventQueues", numMainEventQueues); 4499983Sstever@gmail.com 4509983Sstever@gmail.com for (uint32_t i = 0; i < numMainEventQueues; ++i) { 4519983Sstever@gmail.com nameOut(os, "MainEventQueue"); 4529983Sstever@gmail.com mainEventQueue[i]->serialize(os); 4539983Sstever@gmail.com } 4542SN/A} 4552SN/A 4562SN/Avoid 4578737Skoansin.tan@gmail.comGlobals::unserialize(Checkpoint *cp, const std::string §ion) 4582SN/A{ 4597823Ssteve.reinhardt@amd.com Tick tick; 4607823Ssteve.reinhardt@amd.com paramIn(cp, section, "curTick", tick); 4619983Sstever@gmail.com paramIn(cp, section, "numMainEventQueues", numMainEventQueues); 4622SN/A 4639983Sstever@gmail.com for (uint32_t i = 0; i < numMainEventQueues; ++i) { 4649983Sstever@gmail.com mainEventQueue[i]->setCurTick(tick); 4659983Sstever@gmail.com mainEventQueue[i]->unserialize(cp, "MainEventQueue"); 4669983Sstever@gmail.com } 4672SN/A} 4682SN/A 4695739Snate@binkert.orgSerializable::Serializable() 4705739Snate@binkert.org{ 4715739Snate@binkert.org} 4725739Snate@binkert.org 4735739Snate@binkert.orgSerializable::~Serializable() 4745739Snate@binkert.org{ 4755739Snate@binkert.org} 4765739Snate@binkert.org 4775739Snate@binkert.orgvoid 4786225Snate@binkert.orgSerializable::serialize(ostream &os) 4795739Snate@binkert.org{ 4805739Snate@binkert.org} 4815739Snate@binkert.org 4825739Snate@binkert.orgvoid 4836225Snate@binkert.orgSerializable::unserialize(Checkpoint *cp, const string §ion) 4845739Snate@binkert.org{ 4855739Snate@binkert.org} 4865739Snate@binkert.org 4872SN/Avoid 4886225Snate@binkert.orgSerializable::serializeAll(const string &cpt_dir) 4892SN/A{ 4907491Ssteve.reinhardt@amd.com string dir = Checkpoint::setDir(cpt_dir); 491363SN/A if (mkdir(dir.c_str(), 0775) == -1 && errno != EEXIST) 492449SN/A fatal("couldn't mkdir %s\n", dir); 493363SN/A 494449SN/A string cpt_file = dir + Checkpoint::baseFilename; 495395SN/A ofstream outstream(cpt_file.c_str()); 4962SN/A time_t t = time(NULL); 4975581Ssaidi@eecs.umich.edu if (!outstream.is_open()) 4985581Ssaidi@eecs.umich.edu fatal("Unable to open file %s for writing\n", cpt_file.c_str()); 4996818SLisa.Hsu@amd.com outstream << "## checkpoint generated: " << ctime(&t); 5002SN/A 501395SN/A globals.serialize(outstream); 502395SN/A SimObject::serializeAll(outstream); 503395SN/A} 5042SN/A 5052797Sktlim@umich.eduvoid 506395SN/ASerializable::unserializeGlobals(Checkpoint *cp) 507395SN/A{ 5088737Skoansin.tan@gmail.com globals.unserialize(cp, globals.name()); 509395SN/A} 5102SN/A 5112SN/Avoid 5126225Snate@binkert.orgdebug_serialize(const string &cpt_dir) 5132SN/A{ 5142868Sktlim@umich.edu Serializable::serializeAll(cpt_dir); 5152SN/A} 5162SN/A 5172SN/A 5182SN/A//////////////////////////////////////////////////////////////////////// 5192SN/A// 520395SN/A// SerializableClass member definitions 5212SN/A// 5222SN/A//////////////////////////////////////////////////////////////////////// 5232SN/A 524395SN/A// Map of class names to SerializableBuilder creation functions. 5252SN/A// Need to make this a pointer so we can force initialization on the 526395SN/A// first reference; otherwise, some SerializableClass constructors 5272SN/A// may be invoked before the classMap constructor. 5286225Snate@binkert.orgmap<string, SerializableClass::CreateFunc> *SerializableClass::classMap = 0; 5292SN/A 530395SN/A// SerializableClass constructor: add mapping to classMap 531395SN/ASerializableClass::SerializableClass(const string &className, 5326225Snate@binkert.org CreateFunc createFunc) 5332SN/A{ 5342SN/A if (classMap == NULL) 5356225Snate@binkert.org classMap = new map<string, SerializableClass::CreateFunc>(); 5362SN/A 5372SN/A if ((*classMap)[className]) 5386225Snate@binkert.org fatal("Error: simulation object class %s redefined\n", className); 5392SN/A 5402SN/A // add className --> createFunc to class map 5412SN/A (*classMap)[className] = createFunc; 5422SN/A} 5432SN/A 5442SN/A// 5452SN/A// 546395SN/ASerializable * 5476225Snate@binkert.orgSerializableClass::createObject(Checkpoint *cp, const string §ion) 5482SN/A{ 549237SN/A string className; 5502SN/A 551237SN/A if (!cp->find(section, "type", className)) { 552395SN/A fatal("Serializable::create: no 'type' entry in section '%s'.\n", 553237SN/A section); 5542SN/A } 5552SN/A 556237SN/A CreateFunc createFunc = (*classMap)[className]; 557237SN/A 558237SN/A if (createFunc == NULL) { 559395SN/A fatal("Serializable::create: no create function for class '%s'.\n", 560237SN/A className); 5612SN/A } 5622SN/A 563395SN/A Serializable *object = createFunc(cp, section); 5642SN/A 5652SN/A assert(object != NULL); 5662SN/A 5672SN/A return object; 5682SN/A} 5692SN/A 570237SN/A 571395SN/ASerializable * 5726225Snate@binkert.orgSerializable::create(Checkpoint *cp, const string §ion) 573237SN/A{ 574395SN/A Serializable *object = SerializableClass::createObject(cp, section); 575237SN/A object->unserialize(cp, section); 576237SN/A return object; 577237SN/A} 578237SN/A 579237SN/A 5807491Ssteve.reinhardt@amd.comconst char *Checkpoint::baseFilename = "m5.cpt"; 5817491Ssteve.reinhardt@amd.com 5827491Ssteve.reinhardt@amd.comstring Checkpoint::currentDirectory; 5837491Ssteve.reinhardt@amd.com 5847491Ssteve.reinhardt@amd.comstring 5857491Ssteve.reinhardt@amd.comCheckpoint::setDir(const string &name) 5867491Ssteve.reinhardt@amd.com{ 5877823Ssteve.reinhardt@amd.com // use csprintf to insert curTick() into directory name if it 5887491Ssteve.reinhardt@amd.com // appears to have a format placeholder in it. 5897491Ssteve.reinhardt@amd.com currentDirectory = (name.find("%") != string::npos) ? 5907823Ssteve.reinhardt@amd.com csprintf(name, curTick()) : name; 5917491Ssteve.reinhardt@amd.com if (currentDirectory[currentDirectory.size() - 1] != '/') 5927491Ssteve.reinhardt@amd.com currentDirectory += "/"; 5937491Ssteve.reinhardt@amd.com return currentDirectory; 5947491Ssteve.reinhardt@amd.com} 5957491Ssteve.reinhardt@amd.com 5967491Ssteve.reinhardt@amd.comstring 5977491Ssteve.reinhardt@amd.comCheckpoint::dir() 5987491Ssteve.reinhardt@amd.com{ 5997491Ssteve.reinhardt@amd.com return currentDirectory; 6007491Ssteve.reinhardt@amd.com} 6017491Ssteve.reinhardt@amd.com 6027491Ssteve.reinhardt@amd.com 6037491Ssteve.reinhardt@amd.comCheckpoint::Checkpoint(const string &cpt_dir) 6047532Ssteve.reinhardt@amd.com : db(new IniFile), cptDir(setDir(cpt_dir)) 605237SN/A{ 6067532Ssteve.reinhardt@amd.com string filename = cptDir + "/" + Checkpoint::baseFilename; 607237SN/A if (!db->load(filename)) { 608237SN/A fatal("Can't load checkpoint file '%s'\n", filename); 609237SN/A } 610237SN/A} 611237SN/A 6129086Sandreas.hansson@arm.comCheckpoint::~Checkpoint() 6139086Sandreas.hansson@arm.com{ 6149086Sandreas.hansson@arm.com delete db; 6159086Sandreas.hansson@arm.com} 616237SN/A 617237SN/Abool 6186225Snate@binkert.orgCheckpoint::find(const string §ion, const string &entry, string &value) 619237SN/A{ 620237SN/A return db->find(section, entry, value); 621237SN/A} 622237SN/A 623237SN/A 624237SN/Abool 6256225Snate@binkert.orgCheckpoint::findObj(const string §ion, const string &entry, 6264000Ssaidi@eecs.umich.edu SimObject *&value) 627237SN/A{ 628237SN/A string path; 629237SN/A 630237SN/A if (!db->find(section, entry, path)) 631237SN/A return false; 632237SN/A 6334000Ssaidi@eecs.umich.edu value = resolveSimObject(path); 6344000Ssaidi@eecs.umich.edu return true; 635237SN/A} 636304SN/A 637304SN/A 638304SN/Abool 6396225Snate@binkert.orgCheckpoint::sectionExists(const string §ion) 640304SN/A{ 641304SN/A return db->sectionExists(section); 642304SN/A} 643