sim_events.cc (9952:7437cc334df1) sim_events.cc (9983:2cce74fe359e)
1/*
2 * Copyright (c) 2013 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Copyright (c) 2002-2005 The Regents of The University of Michigan
1/*
2 * Copyright (c) 2013 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Copyright (c) 2002-2005 The Regents of The University of Michigan
15 * Copyright (c) 2013 Advanced Micro Devices, Inc.
16 * Copyright (c) 2013 Mark D. Hill and David A. Wood
15 * All rights reserved.
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions are
19 * met: redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer;
21 * redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the

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

46#include "base/hostinfo.hh"
47#include "sim/eventq_impl.hh"
48#include "sim/sim_events.hh"
49#include "sim/sim_exit.hh"
50#include "sim/stats.hh"
51
52using namespace std;
53
17 * All rights reserved.
18 *
19 * Redistribution and use in source and binary forms, with or without
20 * modification, are permitted provided that the following conditions are
21 * met: redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer;
23 * redistributions in binary form must reproduce the above copyright
24 * notice, this list of conditions and the following disclaimer in the

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

48#include "base/hostinfo.hh"
49#include "sim/eventq_impl.hh"
50#include "sim/sim_events.hh"
51#include "sim/sim_exit.hh"
52#include "sim/stats.hh"
53
54using namespace std;
55
54SimLoopExitEvent::SimLoopExitEvent()
56GlobalSimLoopExitEvent::GlobalSimLoopExitEvent(Tick when,
57 const std::string &_cause,
58 int c, Tick r, bool serialize)
59 : GlobalEvent(when, Sim_Exit_Pri,
60 IsExitEvent | (serialize ? AutoSerialize : 0)),
61 cause(_cause), code(c), repeat(r)
62{
63}
64
65const char *
66GlobalSimLoopExitEvent::description() const
67{
68 return "global simulation loop exit";
69}
70
71//
72// handle termination event
73//
74void
75GlobalSimLoopExitEvent::process()
76{
77 if (repeat) {
78 schedule(curTick() + repeat);
79 }
80}
81
82void
83exitSimLoop(const std::string &message, int exit_code, Tick when, Tick repeat,
84 bool serialize)
85{
86 new GlobalSimLoopExitEvent(when + simQuantum, message, exit_code, repeat,
87 serialize);
88}
89
90LocalSimLoopExitEvent::LocalSimLoopExitEvent()
55 : Event(Sim_Exit_Pri, IsExitEvent | AutoSerialize),
56 cause(""), code(0), repeat(0)
57{
58}
59
91 : Event(Sim_Exit_Pri, IsExitEvent | AutoSerialize),
92 cause(""), code(0), repeat(0)
93{
94}
95
60SimLoopExitEvent::SimLoopExitEvent(const std::string &_cause, int c, Tick r,
61 bool serialize)
96LocalSimLoopExitEvent::LocalSimLoopExitEvent(const std::string &_cause, int c,
97 Tick r, bool serialize)
62 : Event(Sim_Exit_Pri, IsExitEvent | (serialize ? AutoSerialize : 0)),
63 cause(_cause), code(c), repeat(r)
64{
65}
66
98 : Event(Sim_Exit_Pri, IsExitEvent | (serialize ? AutoSerialize : 0)),
99 cause(_cause), code(c), repeat(r)
100{
101}
102
67
68//
69// handle termination event
70//
71void
103//
104// handle termination event
105//
106void
72SimLoopExitEvent::process()
107LocalSimLoopExitEvent::process()
73{
108{
74 // if this got scheduled on a different queue (e.g. the committed
75 // instruction queue) then make a corresponding event on the main
76 // queue.
77 if (!isFlagSet(IsMainQueue)) {
78 exitSimLoop(cause, code);
79 setFlags(AutoDelete);
80 }
81
82 // otherwise do nothing... the IsExitEvent flag takes care of
83 // exiting the simulation loop and returning this object to Python
84
85 // but if you are doing this on intervals, don't forget to make another
86 if (repeat) {
87 assert(isFlagSet(IsMainQueue));
88 mainEventQueue.schedule(this, curTick() + repeat);
89 }
109 exitSimLoop(cause, 0);
90}
91
92
93const char *
110}
111
112
113const char *
94SimLoopExitEvent::description() const
114LocalSimLoopExitEvent::description() const
95{
96 return "simulation loop exit";
97}
98
99void
115{
116 return "simulation loop exit";
117}
118
119void
100SimLoopExitEvent::serialize(ostream &os)
120LocalSimLoopExitEvent::serialize(ostream &os)
101{
102 paramOut(os, "type", string("SimLoopExitEvent"));
103 Event::serialize(os);
104
105 SERIALIZE_SCALAR(cause);
106 SERIALIZE_SCALAR(code);
107 SERIALIZE_SCALAR(repeat);
108}
109
110void
121{
122 paramOut(os, "type", string("SimLoopExitEvent"));
123 Event::serialize(os);
124
125 SERIALIZE_SCALAR(cause);
126 SERIALIZE_SCALAR(code);
127 SERIALIZE_SCALAR(repeat);
128}
129
130void
111SimLoopExitEvent::unserialize(Checkpoint *cp, const string §ion)
131LocalSimLoopExitEvent::unserialize(Checkpoint *cp, const string &section)
112{
113 Event::unserialize(cp, section);
114
115 UNSERIALIZE_SCALAR(cause);
116 UNSERIALIZE_SCALAR(code);
117 UNSERIALIZE_SCALAR(repeat);
118}
119
132{
133 Event::unserialize(cp, section);
134
135 UNSERIALIZE_SCALAR(cause);
136 UNSERIALIZE_SCALAR(code);
137 UNSERIALIZE_SCALAR(repeat);
138}
139
120Serializable *
121SimLoopExitEvent::createForUnserialize(Checkpoint *cp, const string &section)
140void
141LocalSimLoopExitEvent::unserialize(Checkpoint *cp, const string &section,
142 EventQueue *eventq)
122{
143{
123 return new SimLoopExitEvent();
144 Event::unserialize(cp, section, eventq);
145
146 UNSERIALIZE_SCALAR(cause);
147 UNSERIALIZE_SCALAR(code);
148 UNSERIALIZE_SCALAR(repeat);
124}
125
149}
150
126REGISTER_SERIALIZEABLE("SimLoopExitEvent", SimLoopExitEvent)
127
128void
129exitSimLoop(const std::string &message, int exit_code, Tick when, Tick repeat,
130 bool serialize)
151Serializable *
152LocalSimLoopExitEvent::createForUnserialize(Checkpoint *cp,
153 const string &section)
131{
154{
132 Event *event = new SimLoopExitEvent(message, exit_code, repeat, serialize);
133 mainEventQueue.schedule(event, when);
155 return new LocalSimLoopExitEvent();
134}
135
156}
157
158REGISTER_SERIALIZEABLE("LocalSimLoopExitEvent", LocalSimLoopExitEvent)
159
136//
137// constructor: automatically schedules at specified time
138//
139CountedExitEvent::CountedExitEvent(const std::string &_cause, int &counter)
140 : Event(Sim_Exit_Pri), cause(_cause), downCounter(counter)
141{
142 // catch stupid mistakes
143 assert(downCounter > 0);

--- 20 unchanged lines hidden ---
160//
161// constructor: automatically schedules at specified time
162//
163CountedExitEvent::CountedExitEvent(const std::string &_cause, int &counter)
164 : Event(Sim_Exit_Pri), cause(_cause), downCounter(counter)
165{
166 // catch stupid mistakes
167 assert(downCounter > 0);

--- 20 unchanged lines hidden ---