pseudo_inst.cc (5882:5a047c3f3795) pseudo_inst.cc (5952:c1ee8282291d)
1/*
2 * Copyright (c) 2003-2006 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;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Nathan Binkert
29 */
30
31#include <errno.h>
32#include <fcntl.h>
33#include <unistd.h>
34
35#include <fstream>
36#include <string>
37
38#include "arch/kernel_stats.hh"
39#include "arch/vtophys.hh"
1/*
2 * Copyright (c) 2003-2006 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;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Nathan Binkert
29 */
30
31#include <errno.h>
32#include <fcntl.h>
33#include <unistd.h>
34
35#include <fstream>
36#include <string>
37
38#include "arch/kernel_stats.hh"
39#include "arch/vtophys.hh"
40#include "base/annotate.hh"
41#include "base/debug.hh"
42#include "cpu/base.hh"
43#include "cpu/thread_context.hh"
44#include "cpu/quiesce_event.hh"
45#include "params/BaseCPU.hh"
46#include "sim/pseudo_inst.hh"
47#include "sim/serialize.hh"
48#include "sim/sim_events.hh"
49#include "sim/sim_exit.hh"
50#include "sim/stat_control.hh"
51#include "sim/stats.hh"
52#include "sim/system.hh"
53#if FULL_SYSTEM
54#include "sim/vptr.hh"
55#endif
56
57using namespace std;
58
59using namespace Stats;
60using namespace TheISA;
61
62namespace PseudoInst {
63
64#if FULL_SYSTEM
65
66void
67arm(ThreadContext *tc)
68{
69 if (tc->getKernelStats())
70 tc->getKernelStats()->arm();
71}
72
73void
74quiesce(ThreadContext *tc)
75{
76 if (!tc->getCpuPtr()->params()->do_quiesce)
77 return;
78
79 DPRINTF(Quiesce, "%s: quiesce()\n", tc->getCpuPtr()->name());
80
81 tc->suspend();
82 if (tc->getKernelStats())
83 tc->getKernelStats()->quiesce();
84}
85
86void
87quiesceNs(ThreadContext *tc, uint64_t ns)
88{
89 if (!tc->getCpuPtr()->params()->do_quiesce || ns == 0)
90 return;
91
92 EndQuiesceEvent *quiesceEvent = tc->getQuiesceEvent();
93
94 Tick resume = curTick + Clock::Int::ns * ns;
95
96 mainEventQueue.reschedule(quiesceEvent, resume, true);
97
98 DPRINTF(Quiesce, "%s: quiesceNs(%d) until %d\n",
99 tc->getCpuPtr()->name(), ns, resume);
100
101 tc->suspend();
102 if (tc->getKernelStats())
103 tc->getKernelStats()->quiesce();
104}
105
106void
107quiesceCycles(ThreadContext *tc, uint64_t cycles)
108{
109 if (!tc->getCpuPtr()->params()->do_quiesce || cycles == 0)
110 return;
111
112 EndQuiesceEvent *quiesceEvent = tc->getQuiesceEvent();
113
114 Tick resume = curTick + tc->getCpuPtr()->ticks(cycles);
115
116 mainEventQueue.reschedule(quiesceEvent, resume, true);
117
118 DPRINTF(Quiesce, "%s: quiesceCycles(%d) until %d\n",
119 tc->getCpuPtr()->name(), cycles, resume);
120
121 tc->suspend();
122 if (tc->getKernelStats())
123 tc->getKernelStats()->quiesce();
124}
125
126uint64_t
127quiesceTime(ThreadContext *tc)
128{
129 return (tc->readLastActivate() - tc->readLastSuspend()) / Clock::Int::ns;
130}
131
132#endif
133
134uint64_t
135rpns(ThreadContext *tc)
136{
137 return curTick / Clock::Int::ns;
138}
139
140void
141wakeCPU(ThreadContext *tc, uint64_t cpuid)
142{
143 System *sys = tc->getSystemPtr();
144 ThreadContext *other_tc = sys->threadContexts[cpuid];
145 if (other_tc->status() == ThreadContext::Suspended)
146 other_tc->activate();
147}
148
149void
150m5exit(ThreadContext *tc, Tick delay)
151{
152 Tick when = curTick + delay * Clock::Int::ns;
153 Event *event = new SimLoopExitEvent("m5_exit instruction encountered", 0);
154 mainEventQueue.schedule(event, when);
155}
156
157#if FULL_SYSTEM
158
159void
160loadsymbol(ThreadContext *tc)
161{
162 const string &filename = tc->getCpuPtr()->system->params()->symbolfile;
163 if (filename.empty()) {
164 return;
165 }
166
167 std::string buffer;
168 ifstream file(filename.c_str());
169
170 if (!file)
171 fatal("file error: Can't open symbol table file %s\n", filename);
172
173 while (!file.eof()) {
174 getline(file, buffer);
175
176 if (buffer.empty())
177 continue;
178
179 int idx = buffer.find(' ');
180 if (idx == string::npos)
181 continue;
182
183 string address = "0x" + buffer.substr(0, idx);
184 eat_white(address);
185 if (address.empty())
186 continue;
187
188 // Skip over letter and space
189 string symbol = buffer.substr(idx + 3);
190 eat_white(symbol);
191 if (symbol.empty())
192 continue;
193
194 Addr addr;
195 if (!to_number(address, addr))
196 continue;
197
198 if (!tc->getSystemPtr()->kernelSymtab->insert(addr, symbol))
199 continue;
200
201
202 DPRINTF(Loader, "Loaded symbol: %s @ %#llx\n", symbol, addr);
203 }
204 file.close();
205}
206
207void
208addsymbol(ThreadContext *tc, Addr addr, Addr symbolAddr)
209{
210 char symb[100];
211 CopyStringOut(tc, symb, symbolAddr, 100);
212 std::string symbol(symb);
213
214 DPRINTF(Loader, "Loaded symbol: %s @ %#llx\n", symbol, addr);
215
216 tc->getSystemPtr()->kernelSymtab->insert(addr,symbol);
40#include "base/debug.hh"
41#include "cpu/base.hh"
42#include "cpu/thread_context.hh"
43#include "cpu/quiesce_event.hh"
44#include "params/BaseCPU.hh"
45#include "sim/pseudo_inst.hh"
46#include "sim/serialize.hh"
47#include "sim/sim_events.hh"
48#include "sim/sim_exit.hh"
49#include "sim/stat_control.hh"
50#include "sim/stats.hh"
51#include "sim/system.hh"
52#if FULL_SYSTEM
53#include "sim/vptr.hh"
54#endif
55
56using namespace std;
57
58using namespace Stats;
59using namespace TheISA;
60
61namespace PseudoInst {
62
63#if FULL_SYSTEM
64
65void
66arm(ThreadContext *tc)
67{
68 if (tc->getKernelStats())
69 tc->getKernelStats()->arm();
70}
71
72void
73quiesce(ThreadContext *tc)
74{
75 if (!tc->getCpuPtr()->params()->do_quiesce)
76 return;
77
78 DPRINTF(Quiesce, "%s: quiesce()\n", tc->getCpuPtr()->name());
79
80 tc->suspend();
81 if (tc->getKernelStats())
82 tc->getKernelStats()->quiesce();
83}
84
85void
86quiesceNs(ThreadContext *tc, uint64_t ns)
87{
88 if (!tc->getCpuPtr()->params()->do_quiesce || ns == 0)
89 return;
90
91 EndQuiesceEvent *quiesceEvent = tc->getQuiesceEvent();
92
93 Tick resume = curTick + Clock::Int::ns * ns;
94
95 mainEventQueue.reschedule(quiesceEvent, resume, true);
96
97 DPRINTF(Quiesce, "%s: quiesceNs(%d) until %d\n",
98 tc->getCpuPtr()->name(), ns, resume);
99
100 tc->suspend();
101 if (tc->getKernelStats())
102 tc->getKernelStats()->quiesce();
103}
104
105void
106quiesceCycles(ThreadContext *tc, uint64_t cycles)
107{
108 if (!tc->getCpuPtr()->params()->do_quiesce || cycles == 0)
109 return;
110
111 EndQuiesceEvent *quiesceEvent = tc->getQuiesceEvent();
112
113 Tick resume = curTick + tc->getCpuPtr()->ticks(cycles);
114
115 mainEventQueue.reschedule(quiesceEvent, resume, true);
116
117 DPRINTF(Quiesce, "%s: quiesceCycles(%d) until %d\n",
118 tc->getCpuPtr()->name(), cycles, resume);
119
120 tc->suspend();
121 if (tc->getKernelStats())
122 tc->getKernelStats()->quiesce();
123}
124
125uint64_t
126quiesceTime(ThreadContext *tc)
127{
128 return (tc->readLastActivate() - tc->readLastSuspend()) / Clock::Int::ns;
129}
130
131#endif
132
133uint64_t
134rpns(ThreadContext *tc)
135{
136 return curTick / Clock::Int::ns;
137}
138
139void
140wakeCPU(ThreadContext *tc, uint64_t cpuid)
141{
142 System *sys = tc->getSystemPtr();
143 ThreadContext *other_tc = sys->threadContexts[cpuid];
144 if (other_tc->status() == ThreadContext::Suspended)
145 other_tc->activate();
146}
147
148void
149m5exit(ThreadContext *tc, Tick delay)
150{
151 Tick when = curTick + delay * Clock::Int::ns;
152 Event *event = new SimLoopExitEvent("m5_exit instruction encountered", 0);
153 mainEventQueue.schedule(event, when);
154}
155
156#if FULL_SYSTEM
157
158void
159loadsymbol(ThreadContext *tc)
160{
161 const string &filename = tc->getCpuPtr()->system->params()->symbolfile;
162 if (filename.empty()) {
163 return;
164 }
165
166 std::string buffer;
167 ifstream file(filename.c_str());
168
169 if (!file)
170 fatal("file error: Can't open symbol table file %s\n", filename);
171
172 while (!file.eof()) {
173 getline(file, buffer);
174
175 if (buffer.empty())
176 continue;
177
178 int idx = buffer.find(' ');
179 if (idx == string::npos)
180 continue;
181
182 string address = "0x" + buffer.substr(0, idx);
183 eat_white(address);
184 if (address.empty())
185 continue;
186
187 // Skip over letter and space
188 string symbol = buffer.substr(idx + 3);
189 eat_white(symbol);
190 if (symbol.empty())
191 continue;
192
193 Addr addr;
194 if (!to_number(address, addr))
195 continue;
196
197 if (!tc->getSystemPtr()->kernelSymtab->insert(addr, symbol))
198 continue;
199
200
201 DPRINTF(Loader, "Loaded symbol: %s @ %#llx\n", symbol, addr);
202 }
203 file.close();
204}
205
206void
207addsymbol(ThreadContext *tc, Addr addr, Addr symbolAddr)
208{
209 char symb[100];
210 CopyStringOut(tc, symb, symbolAddr, 100);
211 std::string symbol(symb);
212
213 DPRINTF(Loader, "Loaded symbol: %s @ %#llx\n", symbol, addr);
214
215 tc->getSystemPtr()->kernelSymtab->insert(addr,symbol);
216 debugSymbolTable->insert(addr,symbol);
217}
218
219#endif
220
221
222void
223resetstats(ThreadContext *tc, Tick delay, Tick period)
224{
225 if (!tc->getCpuPtr()->params()->do_statistics_insts)
226 return;
227
228
229 Tick when = curTick + delay * Clock::Int::ns;
230 Tick repeat = period * Clock::Int::ns;
231
232 Stats::StatEvent(false, true, when, repeat);
233}
234
235void
236dumpstats(ThreadContext *tc, Tick delay, Tick period)
237{
238 if (!tc->getCpuPtr()->params()->do_statistics_insts)
239 return;
240
241
242 Tick when = curTick + delay * Clock::Int::ns;
243 Tick repeat = period * Clock::Int::ns;
244
245 Stats::StatEvent(true, false, when, repeat);
246}
247
248void
249dumpresetstats(ThreadContext *tc, Tick delay, Tick period)
250{
251 if (!tc->getCpuPtr()->params()->do_statistics_insts)
252 return;
253
254
255 Tick when = curTick + delay * Clock::Int::ns;
256 Tick repeat = period * Clock::Int::ns;
257
258 Stats::StatEvent(true, true, when, repeat);
259}
260
261void
262m5checkpoint(ThreadContext *tc, Tick delay, Tick period)
263{
264 if (!tc->getCpuPtr()->params()->do_checkpoint_insts)
265 return;
266
267 Tick when = curTick + delay * Clock::Int::ns;
268 Tick repeat = period * Clock::Int::ns;
269
270 Event *event = new SimLoopExitEvent("checkpoint", 0, repeat);
271 mainEventQueue.schedule(event, when);
272}
273
274#if FULL_SYSTEM
275
276uint64_t
277readfile(ThreadContext *tc, Addr vaddr, uint64_t len, uint64_t offset)
278{
279 const string &file = tc->getSystemPtr()->params()->readfile;
280 if (file.empty()) {
281 return ULL(0);
282 }
283
284 uint64_t result = 0;
285
286 int fd = ::open(file.c_str(), O_RDONLY, 0);
287 if (fd < 0)
288 panic("could not open file %s\n", file);
289
290 if (::lseek(fd, offset, SEEK_SET) < 0)
291 panic("could not seek: %s", strerror(errno));
292
293 char *buf = new char[len];
294 char *p = buf;
295 while (len > 0) {
296 int bytes = ::read(fd, p, len);
297 if (bytes <= 0)
298 break;
299
300 p += bytes;
301 result += bytes;
302 len -= bytes;
303 }
304
305 close(fd);
306 CopyIn(tc, vaddr, buf, result);
307 delete [] buf;
308 return result;
309}
310
311#endif
312
313void
314debugbreak(ThreadContext *tc)
315{
316 debug_break();
317}
318
319void
320switchcpu(ThreadContext *tc)
321{
322 exitSimLoop("switchcpu");
323}
324
325/* namespace PseudoInst */ }
217}
218
219#endif
220
221
222void
223resetstats(ThreadContext *tc, Tick delay, Tick period)
224{
225 if (!tc->getCpuPtr()->params()->do_statistics_insts)
226 return;
227
228
229 Tick when = curTick + delay * Clock::Int::ns;
230 Tick repeat = period * Clock::Int::ns;
231
232 Stats::StatEvent(false, true, when, repeat);
233}
234
235void
236dumpstats(ThreadContext *tc, Tick delay, Tick period)
237{
238 if (!tc->getCpuPtr()->params()->do_statistics_insts)
239 return;
240
241
242 Tick when = curTick + delay * Clock::Int::ns;
243 Tick repeat = period * Clock::Int::ns;
244
245 Stats::StatEvent(true, false, when, repeat);
246}
247
248void
249dumpresetstats(ThreadContext *tc, Tick delay, Tick period)
250{
251 if (!tc->getCpuPtr()->params()->do_statistics_insts)
252 return;
253
254
255 Tick when = curTick + delay * Clock::Int::ns;
256 Tick repeat = period * Clock::Int::ns;
257
258 Stats::StatEvent(true, true, when, repeat);
259}
260
261void
262m5checkpoint(ThreadContext *tc, Tick delay, Tick period)
263{
264 if (!tc->getCpuPtr()->params()->do_checkpoint_insts)
265 return;
266
267 Tick when = curTick + delay * Clock::Int::ns;
268 Tick repeat = period * Clock::Int::ns;
269
270 Event *event = new SimLoopExitEvent("checkpoint", 0, repeat);
271 mainEventQueue.schedule(event, when);
272}
273
274#if FULL_SYSTEM
275
276uint64_t
277readfile(ThreadContext *tc, Addr vaddr, uint64_t len, uint64_t offset)
278{
279 const string &file = tc->getSystemPtr()->params()->readfile;
280 if (file.empty()) {
281 return ULL(0);
282 }
283
284 uint64_t result = 0;
285
286 int fd = ::open(file.c_str(), O_RDONLY, 0);
287 if (fd < 0)
288 panic("could not open file %s\n", file);
289
290 if (::lseek(fd, offset, SEEK_SET) < 0)
291 panic("could not seek: %s", strerror(errno));
292
293 char *buf = new char[len];
294 char *p = buf;
295 while (len > 0) {
296 int bytes = ::read(fd, p, len);
297 if (bytes <= 0)
298 break;
299
300 p += bytes;
301 result += bytes;
302 len -= bytes;
303 }
304
305 close(fd);
306 CopyIn(tc, vaddr, buf, result);
307 delete [] buf;
308 return result;
309}
310
311#endif
312
313void
314debugbreak(ThreadContext *tc)
315{
316 debug_break();
317}
318
319void
320switchcpu(ThreadContext *tc)
321{
322 exitSimLoop("switchcpu");
323}
324
325/* namespace PseudoInst */ }