sim_events.cc (10906:3ab1d7ed6545) sim_events.cc (11070:d9560edaf0a9)
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
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
25 * documentation and/or other materials provided with the distribution;
26 * neither the name of the copyright holders nor the names of its
27 * contributors may be used to endorse or promote products derived from
28 * this software without specific prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
40 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 *
42 * Authors: Nathan Binkert
43 */
44
45#include <string>
46
47#include "base/callback.hh"
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
56GlobalSimLoopExitEvent::GlobalSimLoopExitEvent(Tick when,
57 const std::string &_cause,
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
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
25 * documentation and/or other materials provided with the distribution;
26 * neither the name of the copyright holders nor the names of its
27 * contributors may be used to endorse or promote products derived from
28 * this software without specific prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
40 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 *
42 * Authors: Nathan Binkert
43 */
44
45#include <string>
46
47#include "base/callback.hh"
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
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)),
58 int c, Tick r)
59 : GlobalEvent(when, Sim_Exit_Pri, IsExitEvent),
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{
60 cause(_cause), code(c), repeat(r)
61{
62}
63
64const char *
65GlobalSimLoopExitEvent::description() const
66{
67 return "global simulation loop exit";
68}
69
70//
71// handle termination event
72//
73void
74GlobalSimLoopExitEvent::process()
75{
76 if (repeat) {
77 schedule(curTick() + repeat);
78 }
79}
80
81void
82exitSimLoop(const std::string &message, int exit_code, Tick when, Tick repeat,
83 bool serialize)
84{
86 new GlobalSimLoopExitEvent(when + simQuantum, message, exit_code, repeat,
87 serialize);
88}
85 warn_if(serialize && (when != curTick() || repeat),
86 "exitSimLoop called with a delay and auto serialization. This is "
87 "currently unsupported.");
89
88
90LocalSimLoopExitEvent::LocalSimLoopExitEvent()
91 : Event(Sim_Exit_Pri, IsExitEvent | AutoSerialize),
92 cause(""), code(0), repeat(0)
93{
89 new GlobalSimLoopExitEvent(when + simQuantum, message, exit_code, repeat);
94}
95
96LocalSimLoopExitEvent::LocalSimLoopExitEvent(const std::string &_cause, int c,
90}
91
92LocalSimLoopExitEvent::LocalSimLoopExitEvent(const std::string &_cause, int c,
97 Tick r, bool serialize)
98 : Event(Sim_Exit_Pri, IsExitEvent | (serialize ? AutoSerialize : 0)),
93 Tick r)
94 : Event(Sim_Exit_Pri, IsExitEvent),
99 cause(_cause), code(c), repeat(r)
100{
101}
102
103//
104// handle termination event
105//
106void
107LocalSimLoopExitEvent::process()
108{
109 exitSimLoop(cause, 0);
110}
111
112
113const char *
114LocalSimLoopExitEvent::description() const
115{
116 return "simulation loop exit";
117}
118
119void
120LocalSimLoopExitEvent::serialize(CheckpointOut &cp) const
121{
95 cause(_cause), code(c), repeat(r)
96{
97}
98
99//
100// handle termination event
101//
102void
103LocalSimLoopExitEvent::process()
104{
105 exitSimLoop(cause, 0);
106}
107
108
109const char *
110LocalSimLoopExitEvent::description() const
111{
112 return "simulation loop exit";
113}
114
115void
116LocalSimLoopExitEvent::serialize(CheckpointOut &cp) const
117{
122 paramOut(cp, "type", string("SimLoopExitEvent"));
123 Event::serialize(cp);
124
125 SERIALIZE_SCALAR(cause);
126 SERIALIZE_SCALAR(code);
127 SERIALIZE_SCALAR(repeat);
128}
129
130void
131LocalSimLoopExitEvent::unserialize(CheckpointIn &cp)
132{
133 Event::unserialize(cp);
134
135 UNSERIALIZE_SCALAR(cause);
136 UNSERIALIZE_SCALAR(code);
137 UNSERIALIZE_SCALAR(repeat);
138}
139
118 Event::serialize(cp);
119
120 SERIALIZE_SCALAR(cause);
121 SERIALIZE_SCALAR(code);
122 SERIALIZE_SCALAR(repeat);
123}
124
125void
126LocalSimLoopExitEvent::unserialize(CheckpointIn &cp)
127{
128 Event::unserialize(cp);
129
130 UNSERIALIZE_SCALAR(cause);
131 UNSERIALIZE_SCALAR(code);
132 UNSERIALIZE_SCALAR(repeat);
133}
134
140Serializable *
141LocalSimLoopExitEvent::createForUnserialize(CheckpointIn &cp,
142 const string &section)
143{
144 return new LocalSimLoopExitEvent();
145}
146
147REGISTER_SERIALIZEABLE("LocalSimLoopExitEvent", LocalSimLoopExitEvent)
148
149//
150// constructor: automatically schedules at specified time
151//
152CountedExitEvent::CountedExitEvent(const std::string &_cause, int &counter)
153 : Event(Sim_Exit_Pri), cause(_cause), downCounter(counter)
154{
155 // catch stupid mistakes
156 assert(downCounter > 0);
157}
158
159
160//
161// handle termination event
162//
163void
164CountedExitEvent::process()
165{
166 if (--downCounter == 0) {
167 exitSimLoop(cause, 0);
168 }
169}
170
171
172const char *
173CountedExitEvent::description() const
174{
175 return "counted exit";
176}
135//
136// constructor: automatically schedules at specified time
137//
138CountedExitEvent::CountedExitEvent(const std::string &_cause, int &counter)
139 : Event(Sim_Exit_Pri), cause(_cause), downCounter(counter)
140{
141 // catch stupid mistakes
142 assert(downCounter > 0);
143}
144
145
146//
147// handle termination event
148//
149void
150CountedExitEvent::process()
151{
152 if (--downCounter == 0) {
153 exitSimLoop(cause, 0);
154 }
155}
156
157
158const char *
159CountedExitEvent::description() const
160{
161 return "counted exit";
162}