serialize.cc (2760:4dbf498165ac) serialize.cc (2797:b5f26b4eacef)
1/*
2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 230 unchanged lines hidden (view full) ---

239
240 string cpt_file = dir + Checkpoint::baseFilename;
241 ofstream outstream(cpt_file.c_str());
242 time_t t = time(NULL);
243 outstream << "// checkpoint generated: " << ctime(&t);
244
245 globals.serialize(outstream);
246 SimObject::serializeAll(outstream);
1/*
2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;

--- 230 unchanged lines hidden (view full) ---

239
240 string cpt_file = dir + Checkpoint::baseFilename;
241 ofstream outstream(cpt_file.c_str());
242 time_t t = time(NULL);
243 outstream << "// checkpoint generated: " << ctime(&t);
244
245 globals.serialize(outstream);
246 SimObject::serializeAll(outstream);
247
248 assert(Serializable::ckptPrevCount + 1 == Serializable::ckptCount);
249 Serializable::ckptPrevCount++;
250 if (ckptMaxCount && ++ckptCount >= ckptMaxCount)
251 exitSimLoop(curTick + 1, "Maximum number of checkpoints dropped");
252
253}
254
247}
248
255
256void
249void
257Serializable::unserializeGlobals(Checkpoint *cp)
250Serializable::unserializeAll()
258{
251{
259 globals.unserialize(cp);
260}
252 string dir = Checkpoint::dir();
253 string cpt_file = dir + Checkpoint::baseFilename;
254 string section = "";
261
255
256 DPRINTFR(Config, "Loading checkpoint dir '%s'\n",
257 dir);
258 Checkpoint *cp = new Checkpoint(dir, section);
259 unserializeGlobals(cp);
262
260
263class SerializeEvent : public Event
264{
265 protected:
266 Tick repeat;
267
268 public:
269 SerializeEvent(Tick _when, Tick _repeat);
270 virtual void process();
271 virtual void serialize(std::ostream &os)
272 {
273 panic("Cannot serialize the SerializeEvent");
274 }
275
276};
277
278SerializeEvent::SerializeEvent(Tick _when, Tick _repeat)
279 : Event(&mainEventQueue, Serialize_Pri), repeat(_repeat)
280{
281 setFlags(AutoDelete);
282 schedule(_when);
261 SimObject::unserializeAll(cp);
283}
284
285void
262}
263
264void
286SerializeEvent::process()
265Serializable::unserializeGlobals(Checkpoint *cp)
287{
266{
288 Serializable::serializeAll();
289 if (repeat)
290 schedule(curTick + repeat);
267 globals.unserialize(cp);
291}
292
293const char *Checkpoint::baseFilename = "m5.cpt";
294
295static string checkpointDirBase;
296
268}
269
270const char *Checkpoint::baseFilename = "m5.cpt";
271
272static string checkpointDirBase;
273
274void
275setCheckpointDir(const std::string &name)
276{
277 checkpointDirBase = name;
278 if (checkpointDirBase[checkpointDirBase.size() - 1] != '/')
279 checkpointDirBase += "/";
280}
281
297string
298Checkpoint::dir()
299{
300 // use csprintf to insert curTick into directory name if it
301 // appears to have a format placeholder in it.
302 return (checkpointDirBase.find("%") != string::npos) ?
303 csprintf(checkpointDirBase, curTick) : checkpointDirBase;
304}
305
306void
282string
283Checkpoint::dir()
284{
285 // use csprintf to insert curTick into directory name if it
286 // appears to have a format placeholder in it.
287 return (checkpointDirBase.find("%") != string::npos) ?
288 csprintf(checkpointDirBase, curTick) : checkpointDirBase;
289}
290
291void
307Checkpoint::setup(Tick when, Tick period)
308{
309 new SerializeEvent(when, period);
310}
311
312class SerializeParamContext : public ParamContext
313{
314 private:
315 SerializeEvent *event;
316
317 public:
318 SerializeParamContext(const string &section);
319 ~SerializeParamContext();
320 void checkParams();
321};
322
323SerializeParamContext serialParams("serialize");
324
325Param<string> serialize_dir(&serialParams, "dir",
326 "dir to stick checkpoint in "
327 "(sprintf format with cycle #)");
328
329Param<Counter> serialize_cycle(&serialParams,
330 "cycle",
331 "cycle to serialize",
332 0);
333
334Param<Counter> serialize_period(&serialParams,
335 "period",
336 "period to repeat serializations",
337 0);
338
339Param<int> serialize_count(&serialParams, "count",
340 "maximum number of checkpoints to drop");
341
342SerializeParamContext::SerializeParamContext(const string &section)
343 : ParamContext(section), event(NULL)
344{ }
345
346SerializeParamContext::~SerializeParamContext()
347{
348}
349
350void
351SerializeParamContext::checkParams()
352{
353 checkpointDirBase = simout.resolve(serialize_dir);
354
355 // guarantee that directory ends with a '/'
356 if (checkpointDirBase[checkpointDirBase.size() - 1] != '/')
357 checkpointDirBase += "/";
358
359 if (serialize_cycle > 0)
360 Checkpoint::setup(serialize_cycle, serialize_period);
361
362 Serializable::ckptMaxCount = serialize_count;
363}
364
365void
366debug_serialize()
367{
368 Serializable::serializeAll();
369}
370
292debug_serialize()
293{
294 Serializable::serializeAll();
295}
296
371void
372debug_serialize(Tick when)
373{
374 new SerializeEvent(when, 0);
375}
376
377////////////////////////////////////////////////////////////////////////
378//
379// SerializableClass member definitions
380//
381////////////////////////////////////////////////////////////////////////
382
383// Map of class names to SerializableBuilder creation functions.

--- 100 unchanged lines hidden ---
297
298////////////////////////////////////////////////////////////////////////
299//
300// SerializableClass member definitions
301//
302////////////////////////////////////////////////////////////////////////
303
304// Map of class names to SerializableBuilder creation functions.

--- 100 unchanged lines hidden ---