system.cc (9934:b105ac205021) system.cc (10037:5cac77888310)
1/*
1/*
2 * Copyright (c) 2010-2012 ARM Limited
2 * Copyright (c) 2010-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-2006 The Regents of The University of Michigan
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 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 * Authors: Ali Saidi
41 */
42
43#include "arch/arm/linux/atag.hh"
44#include "arch/arm/linux/system.hh"
45#include "arch/arm/isa_traits.hh"
46#include "arch/arm/utility.hh"
47#include "arch/generic/linux/threadinfo.hh"
48#include "base/loader/dtb_object.hh"
49#include "base/loader/object_file.hh"
50#include "base/loader/symtab.hh"
51#include "cpu/base.hh"
52#include "cpu/pc_event.hh"
53#include "cpu/thread_context.hh"
54#include "debug/Loader.hh"
55#include "kern/linux/events.hh"
56#include "mem/fs_translating_port_proxy.hh"
57#include "mem/physical.hh"
58#include "sim/stat_control.hh"
59
60using namespace ArmISA;
61using namespace Linux;
62
63LinuxArmSystem::LinuxArmSystem(Params *p)
64 : ArmSystem(p),
65 enableContextSwitchStatsDump(p->enable_context_switch_stats_dump),
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-2006 The Regents of The University of Michigan
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 * documentation and/or other materials provided with the distribution;
24 * neither the name of the copyright holders nor the names of its
25 * contributors may be used to endorse or promote products derived from
26 * this software without specific prior written permission.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *
40 * Authors: Ali Saidi
41 */
42
43#include "arch/arm/linux/atag.hh"
44#include "arch/arm/linux/system.hh"
45#include "arch/arm/isa_traits.hh"
46#include "arch/arm/utility.hh"
47#include "arch/generic/linux/threadinfo.hh"
48#include "base/loader/dtb_object.hh"
49#include "base/loader/object_file.hh"
50#include "base/loader/symtab.hh"
51#include "cpu/base.hh"
52#include "cpu/pc_event.hh"
53#include "cpu/thread_context.hh"
54#include "debug/Loader.hh"
55#include "kern/linux/events.hh"
56#include "mem/fs_translating_port_proxy.hh"
57#include "mem/physical.hh"
58#include "sim/stat_control.hh"
59
60using namespace ArmISA;
61using namespace Linux;
62
63LinuxArmSystem::LinuxArmSystem(Params *p)
64 : ArmSystem(p),
65 enableContextSwitchStatsDump(p->enable_context_switch_stats_dump),
66 kernelPanicEvent(NULL), kernelOopsEvent(NULL)
66 kernelPanicEvent(NULL), kernelOopsEvent(NULL),
67 bootReleaseAddr(p->boot_release_addr)
67{
68 if (p->panic_on_panic) {
69 kernelPanicEvent = addKernelFuncEventOrPanic<PanicPCEvent>(
70 "panic", "Kernel panic in simulated kernel");
71 } else {
72#ifndef NDEBUG
73 kernelPanicEvent = addKernelFuncEventOrPanic<BreakPCEvent>("panic");
74#endif
75 }
76
77 if (p->panic_on_oops) {
78 kernelOopsEvent = addKernelFuncEventOrPanic<PanicPCEvent>(
79 "oops_exit", "Kernel oops in guest");
80 }
81
82 // With ARM udelay() is #defined to __udelay
83 // newer kernels use __loop_udelay and __loop_const_udelay symbols
84 uDelaySkipEvent = addKernelFuncEvent<UDelayEvent>(
85 "__loop_udelay", "__udelay", 1000, 0);
86 if(!uDelaySkipEvent)
87 uDelaySkipEvent = addKernelFuncEventOrPanic<UDelayEvent>(
88 "__udelay", "__udelay", 1000, 0);
89
90 // constant arguments to udelay() have some precomputation done ahead of
91 // time. Constant comes from code.
92 constUDelaySkipEvent = addKernelFuncEvent<UDelayEvent>(
93 "__loop_const_udelay", "__const_udelay", 1000, 107374);
94 if(!constUDelaySkipEvent)
95 constUDelaySkipEvent = addKernelFuncEventOrPanic<UDelayEvent>(
96 "__const_udelay", "__const_udelay", 1000, 107374);
97
98 secDataPtrAddr = 0;
99 secDataAddr = 0;
100 penReleaseAddr = 0;
68{
69 if (p->panic_on_panic) {
70 kernelPanicEvent = addKernelFuncEventOrPanic<PanicPCEvent>(
71 "panic", "Kernel panic in simulated kernel");
72 } else {
73#ifndef NDEBUG
74 kernelPanicEvent = addKernelFuncEventOrPanic<BreakPCEvent>("panic");
75#endif
76 }
77
78 if (p->panic_on_oops) {
79 kernelOopsEvent = addKernelFuncEventOrPanic<PanicPCEvent>(
80 "oops_exit", "Kernel oops in guest");
81 }
82
83 // With ARM udelay() is #defined to __udelay
84 // newer kernels use __loop_udelay and __loop_const_udelay symbols
85 uDelaySkipEvent = addKernelFuncEvent<UDelayEvent>(
86 "__loop_udelay", "__udelay", 1000, 0);
87 if(!uDelaySkipEvent)
88 uDelaySkipEvent = addKernelFuncEventOrPanic<UDelayEvent>(
89 "__udelay", "__udelay", 1000, 0);
90
91 // constant arguments to udelay() have some precomputation done ahead of
92 // time. Constant comes from code.
93 constUDelaySkipEvent = addKernelFuncEvent<UDelayEvent>(
94 "__loop_const_udelay", "__const_udelay", 1000, 107374);
95 if(!constUDelaySkipEvent)
96 constUDelaySkipEvent = addKernelFuncEventOrPanic<UDelayEvent>(
97 "__const_udelay", "__const_udelay", 1000, 107374);
98
99 secDataPtrAddr = 0;
100 secDataAddr = 0;
101 penReleaseAddr = 0;
102
101 kernelSymtab->findAddress("__secondary_data", secDataPtrAddr);
102 kernelSymtab->findAddress("secondary_data", secDataAddr);
103 kernelSymtab->findAddress("pen_release", penReleaseAddr);
103 kernelSymtab->findAddress("__secondary_data", secDataPtrAddr);
104 kernelSymtab->findAddress("secondary_data", secDataAddr);
105 kernelSymtab->findAddress("pen_release", penReleaseAddr);
106 kernelSymtab->findAddress("secondary_holding_pen_release", pen64ReleaseAddr);
104
105 secDataPtrAddr &= ~ULL(0x7F);
106 secDataAddr &= ~ULL(0x7F);
107 penReleaseAddr &= ~ULL(0x7F);
107
108 secDataPtrAddr &= ~ULL(0x7F);
109 secDataAddr &= ~ULL(0x7F);
110 penReleaseAddr &= ~ULL(0x7F);
111 pen64ReleaseAddr &= ~ULL(0x7F);
112 bootReleaseAddr = (bootReleaseAddr & ~ULL(0x7F)) + loadAddrOffset;
113
108}
109
110bool
111LinuxArmSystem::adderBootUncacheable(Addr a)
112{
113 Addr block = a & ~ULL(0x7F);
114}
115
116bool
117LinuxArmSystem::adderBootUncacheable(Addr a)
118{
119 Addr block = a & ~ULL(0x7F);
120
114 if (block == secDataPtrAddr || block == secDataAddr ||
121 if (block == secDataPtrAddr || block == secDataAddr ||
115 block == penReleaseAddr)
122 block == penReleaseAddr || pen64ReleaseAddr == block ||
123 block == bootReleaseAddr)
116 return true;
124 return true;
125
117 return false;
118}
119
120void
121LinuxArmSystem::initState()
122{
123 // Moved from the constructor to here since it relies on the
124 // address map being resolved in the interconnect
125
126 // Call the initialisation of the super class
127 ArmSystem::initState();
128
129 // Load symbols at physical address, we might not want
130 // to do this permanently, for but early bootup work
131 // it is helpful.
132 if (params()->early_kernel_symbols) {
133 kernel->loadGlobalSymbols(kernelSymtab, loadAddrMask);
134 kernel->loadGlobalSymbols(debugSymbolTable, loadAddrMask);
135 }
136
137 // Setup boot data structure
138 Addr addr = 0;
139 // Check if the kernel image has a symbol that tells us it supports
140 // device trees.
141 bool kernel_has_fdt_support =
142 kernelSymtab->findAddress("unflatten_device_tree", addr);
143 bool dtb_file_specified = params()->dtb_filename != "";
144
145 if (kernel_has_fdt_support && dtb_file_specified) {
146 // Kernel supports flattened device tree and dtb file specified.
147 // Using Device Tree Blob to describe system configuration.
126 return false;
127}
128
129void
130LinuxArmSystem::initState()
131{
132 // Moved from the constructor to here since it relies on the
133 // address map being resolved in the interconnect
134
135 // Call the initialisation of the super class
136 ArmSystem::initState();
137
138 // Load symbols at physical address, we might not want
139 // to do this permanently, for but early bootup work
140 // it is helpful.
141 if (params()->early_kernel_symbols) {
142 kernel->loadGlobalSymbols(kernelSymtab, loadAddrMask);
143 kernel->loadGlobalSymbols(debugSymbolTable, loadAddrMask);
144 }
145
146 // Setup boot data structure
147 Addr addr = 0;
148 // Check if the kernel image has a symbol that tells us it supports
149 // device trees.
150 bool kernel_has_fdt_support =
151 kernelSymtab->findAddress("unflatten_device_tree", addr);
152 bool dtb_file_specified = params()->dtb_filename != "";
153
154 if (kernel_has_fdt_support && dtb_file_specified) {
155 // Kernel supports flattened device tree and dtb file specified.
156 // Using Device Tree Blob to describe system configuration.
148 inform("Loading DTB file: %s\n", params()->dtb_filename);
157 inform("Loading DTB file: %s at address %#x\n", params()->dtb_filename,
158 params()->atags_addr + loadAddrOffset);
149
150 ObjectFile *dtb_file = createObjectFile(params()->dtb_filename, true);
151 if (!dtb_file) {
152 fatal("couldn't load DTB file: %s\n", params()->dtb_filename);
153 }
154
155 DtbObject *_dtb_file = dynamic_cast<DtbObject*>(dtb_file);
156
157 if (_dtb_file) {
158 if (!_dtb_file->addBootCmdLine(params()->boot_osflags.c_str(),
159 params()->boot_osflags.size())) {
160 warn("couldn't append bootargs to DTB file: %s\n",
161 params()->dtb_filename);
162 }
163 } else {
164 warn("dtb_file cast failed; couldn't append bootargs "
165 "to DTB file: %s\n", params()->dtb_filename);
166 }
167
159
160 ObjectFile *dtb_file = createObjectFile(params()->dtb_filename, true);
161 if (!dtb_file) {
162 fatal("couldn't load DTB file: %s\n", params()->dtb_filename);
163 }
164
165 DtbObject *_dtb_file = dynamic_cast<DtbObject*>(dtb_file);
166
167 if (_dtb_file) {
168 if (!_dtb_file->addBootCmdLine(params()->boot_osflags.c_str(),
169 params()->boot_osflags.size())) {
170 warn("couldn't append bootargs to DTB file: %s\n",
171 params()->dtb_filename);
172 }
173 } else {
174 warn("dtb_file cast failed; couldn't append bootargs "
175 "to DTB file: %s\n", params()->dtb_filename);
176 }
177
168 dtb_file->setTextBase(params()->atags_addr);
178 dtb_file->setTextBase(params()->atags_addr + loadAddrOffset);
169 dtb_file->loadSections(physProxy);
170 delete dtb_file;
171 } else {
172 // Using ATAGS
173 // Warn if the kernel supports FDT and we haven't specified one
174 if (kernel_has_fdt_support) {
175 assert(!dtb_file_specified);
176 warn("Kernel supports device tree, but no DTB file specified\n");
177 }
178 // Warn if the kernel doesn't support FDT and we have specified one
179 if (dtb_file_specified) {
180 assert(!kernel_has_fdt_support);
181 warn("DTB file specified, but no device tree support in kernel\n");
182 }
183
184 AtagCore ac;
185 ac.flags(1); // read-only
186 ac.pagesize(8192);
187 ac.rootdev(0);
188
189 AddrRangeList atagRanges = physmem.getConfAddrRanges();
190 if (atagRanges.size() != 1) {
191 fatal("Expected a single ATAG memory entry but got %d\n",
192 atagRanges.size());
193 }
194 AtagMem am;
195 am.memSize(atagRanges.begin()->size());
196 am.memStart(atagRanges.begin()->start());
197
198 AtagCmdline ad;
199 ad.cmdline(params()->boot_osflags);
200
201 DPRINTF(Loader, "boot command line %d bytes: %s\n",
202 ad.size() <<2, params()->boot_osflags.c_str());
203
204 AtagNone an;
205
206 uint32_t size = ac.size() + am.size() + ad.size() + an.size();
207 uint32_t offset = 0;
208 uint8_t *boot_data = new uint8_t[size << 2];
209
210 offset += ac.copyOut(boot_data + offset);
211 offset += am.copyOut(boot_data + offset);
212 offset += ad.copyOut(boot_data + offset);
213 offset += an.copyOut(boot_data + offset);
214
215 DPRINTF(Loader, "Boot atags was %d bytes in total\n", size << 2);
216 DDUMP(Loader, boot_data, size << 2);
217
179 dtb_file->loadSections(physProxy);
180 delete dtb_file;
181 } else {
182 // Using ATAGS
183 // Warn if the kernel supports FDT and we haven't specified one
184 if (kernel_has_fdt_support) {
185 assert(!dtb_file_specified);
186 warn("Kernel supports device tree, but no DTB file specified\n");
187 }
188 // Warn if the kernel doesn't support FDT and we have specified one
189 if (dtb_file_specified) {
190 assert(!kernel_has_fdt_support);
191 warn("DTB file specified, but no device tree support in kernel\n");
192 }
193
194 AtagCore ac;
195 ac.flags(1); // read-only
196 ac.pagesize(8192);
197 ac.rootdev(0);
198
199 AddrRangeList atagRanges = physmem.getConfAddrRanges();
200 if (atagRanges.size() != 1) {
201 fatal("Expected a single ATAG memory entry but got %d\n",
202 atagRanges.size());
203 }
204 AtagMem am;
205 am.memSize(atagRanges.begin()->size());
206 am.memStart(atagRanges.begin()->start());
207
208 AtagCmdline ad;
209 ad.cmdline(params()->boot_osflags);
210
211 DPRINTF(Loader, "boot command line %d bytes: %s\n",
212 ad.size() <<2, params()->boot_osflags.c_str());
213
214 AtagNone an;
215
216 uint32_t size = ac.size() + am.size() + ad.size() + an.size();
217 uint32_t offset = 0;
218 uint8_t *boot_data = new uint8_t[size << 2];
219
220 offset += ac.copyOut(boot_data + offset);
221 offset += am.copyOut(boot_data + offset);
222 offset += ad.copyOut(boot_data + offset);
223 offset += an.copyOut(boot_data + offset);
224
225 DPRINTF(Loader, "Boot atags was %d bytes in total\n", size << 2);
226 DDUMP(Loader, boot_data, size << 2);
227
218 physProxy.writeBlob(params()->atags_addr, boot_data, size << 2);
228 physProxy.writeBlob(params()->atags_addr + loadAddrOffset, boot_data,
229 size << 2);
219
220 delete[] boot_data;
221 }
222
230
231 delete[] boot_data;
232 }
233
234 // Kernel boot requirements to set up r0, r1 and r2 in ARMv7
223 for (int i = 0; i < threadContexts.size(); i++) {
224 threadContexts[i]->setIntReg(0, 0);
225 threadContexts[i]->setIntReg(1, params()->machine_type);
235 for (int i = 0; i < threadContexts.size(); i++) {
236 threadContexts[i]->setIntReg(0, 0);
237 threadContexts[i]->setIntReg(1, params()->machine_type);
226 threadContexts[i]->setIntReg(2, params()->atags_addr);
238 threadContexts[i]->setIntReg(2, params()->atags_addr + loadAddrOffset);
227 }
228}
229
230LinuxArmSystem::~LinuxArmSystem()
231{
232 if (uDelaySkipEvent)
233 delete uDelaySkipEvent;
234 if (constUDelaySkipEvent)
235 delete constUDelaySkipEvent;
236
237 if (dumpStatsPCEvent)
238 delete dumpStatsPCEvent;
239}
240
241LinuxArmSystem *
242LinuxArmSystemParams::create()
243{
244 return new LinuxArmSystem(this);
245}
246
247void
248LinuxArmSystem::startup()
249{
250 if (enableContextSwitchStatsDump) {
251 dumpStatsPCEvent = addKernelFuncEvent<DumpStatsPCEvent>("__switch_to");
252 if (!dumpStatsPCEvent)
253 panic("dumpStatsPCEvent not created!");
254
255 std::string task_filename = "tasks.txt";
256 taskFile = simout.create(name() + "." + task_filename);
257
258 for (int i = 0; i < _numContexts; i++) {
259 ThreadContext *tc = threadContexts[i];
260 uint32_t pid = tc->getCpuPtr()->getPid();
261 if (pid != Request::invldPid) {
262 mapPid(tc, pid);
263 tc->getCpuPtr()->taskId(taskMap[pid]);
264 }
265 }
266 }
267}
268
269void
270LinuxArmSystem::mapPid(ThreadContext *tc, uint32_t pid)
271{
272 // Create a new unique identifier for this pid
273 std::map<uint32_t, uint32_t>::iterator itr = taskMap.find(pid);
274 if (itr == taskMap.end()) {
275 uint32_t map_size = taskMap.size();
276 if (map_size > ContextSwitchTaskId::MaxNormalTaskId + 1) {
277 warn_once("Error out of identifiers for cache occupancy stats");
278 taskMap[pid] = ContextSwitchTaskId::Unknown;
279 } else {
280 taskMap[pid] = map_size;
281 }
282 }
283}
284
285/** This function is called whenever the the kernel function
286 * "__switch_to" is called to change running tasks.
287 *
288 * r0 = task_struct of the previously running process
289 * r1 = task_info of the previously running process
290 * r2 = task_info of the next process to run
291 */
292void
293DumpStatsPCEvent::process(ThreadContext *tc)
294{
295 Linux::ThreadInfo ti(tc);
296 Addr task_descriptor = tc->readIntReg(2);
297 uint32_t pid = ti.curTaskPID(task_descriptor);
298 uint32_t tgid = ti.curTaskTGID(task_descriptor);
299 std::string next_task_str = ti.curTaskName(task_descriptor);
300
301 // Streamline treats pid == -1 as the kernel process.
302 // Also pid == 0 implies idle process (except during Linux boot)
303 int32_t mm = ti.curTaskMm(task_descriptor);
304 bool is_kernel = (mm == 0);
305 if (is_kernel && (pid != 0)) {
306 pid = -1;
307 tgid = -1;
308 next_task_str = "kernel";
309 }
310
311 LinuxArmSystem* sys = dynamic_cast<LinuxArmSystem *>(tc->getSystemPtr());
312 if (!sys) {
313 panic("System is not LinuxArmSystem while getting Linux process info!");
314 }
315 std::map<uint32_t, uint32_t>& taskMap = sys->taskMap;
316
317 // Create a new unique identifier for this pid
318 sys->mapPid(tc, pid);
319
320 // Set cpu task id, output process info, and dump stats
321 tc->getCpuPtr()->taskId(taskMap[pid]);
322 tc->getCpuPtr()->setPid(pid);
323
324 std::ostream* taskFile = sys->taskFile;
325
326 // Task file is read by cache occupancy plotting script or
327 // Streamline conversion script.
328 ccprintf(*taskFile,
329 "tick=%lld %d cpu_id=%d next_pid=%d next_tgid=%d next_task=%s\n",
330 curTick(), taskMap[pid], tc->cpuId(), (int) pid, (int) tgid,
331 next_task_str);
332 taskFile->flush();
333
334 // Dump and reset statistics
335 Stats::schedStatEvent(true, true, curTick(), 0);
336}
337
239 }
240}
241
242LinuxArmSystem::~LinuxArmSystem()
243{
244 if (uDelaySkipEvent)
245 delete uDelaySkipEvent;
246 if (constUDelaySkipEvent)
247 delete constUDelaySkipEvent;
248
249 if (dumpStatsPCEvent)
250 delete dumpStatsPCEvent;
251}
252
253LinuxArmSystem *
254LinuxArmSystemParams::create()
255{
256 return new LinuxArmSystem(this);
257}
258
259void
260LinuxArmSystem::startup()
261{
262 if (enableContextSwitchStatsDump) {
263 dumpStatsPCEvent = addKernelFuncEvent<DumpStatsPCEvent>("__switch_to");
264 if (!dumpStatsPCEvent)
265 panic("dumpStatsPCEvent not created!");
266
267 std::string task_filename = "tasks.txt";
268 taskFile = simout.create(name() + "." + task_filename);
269
270 for (int i = 0; i < _numContexts; i++) {
271 ThreadContext *tc = threadContexts[i];
272 uint32_t pid = tc->getCpuPtr()->getPid();
273 if (pid != Request::invldPid) {
274 mapPid(tc, pid);
275 tc->getCpuPtr()->taskId(taskMap[pid]);
276 }
277 }
278 }
279}
280
281void
282LinuxArmSystem::mapPid(ThreadContext *tc, uint32_t pid)
283{
284 // Create a new unique identifier for this pid
285 std::map<uint32_t, uint32_t>::iterator itr = taskMap.find(pid);
286 if (itr == taskMap.end()) {
287 uint32_t map_size = taskMap.size();
288 if (map_size > ContextSwitchTaskId::MaxNormalTaskId + 1) {
289 warn_once("Error out of identifiers for cache occupancy stats");
290 taskMap[pid] = ContextSwitchTaskId::Unknown;
291 } else {
292 taskMap[pid] = map_size;
293 }
294 }
295}
296
297/** This function is called whenever the the kernel function
298 * "__switch_to" is called to change running tasks.
299 *
300 * r0 = task_struct of the previously running process
301 * r1 = task_info of the previously running process
302 * r2 = task_info of the next process to run
303 */
304void
305DumpStatsPCEvent::process(ThreadContext *tc)
306{
307 Linux::ThreadInfo ti(tc);
308 Addr task_descriptor = tc->readIntReg(2);
309 uint32_t pid = ti.curTaskPID(task_descriptor);
310 uint32_t tgid = ti.curTaskTGID(task_descriptor);
311 std::string next_task_str = ti.curTaskName(task_descriptor);
312
313 // Streamline treats pid == -1 as the kernel process.
314 // Also pid == 0 implies idle process (except during Linux boot)
315 int32_t mm = ti.curTaskMm(task_descriptor);
316 bool is_kernel = (mm == 0);
317 if (is_kernel && (pid != 0)) {
318 pid = -1;
319 tgid = -1;
320 next_task_str = "kernel";
321 }
322
323 LinuxArmSystem* sys = dynamic_cast<LinuxArmSystem *>(tc->getSystemPtr());
324 if (!sys) {
325 panic("System is not LinuxArmSystem while getting Linux process info!");
326 }
327 std::map<uint32_t, uint32_t>& taskMap = sys->taskMap;
328
329 // Create a new unique identifier for this pid
330 sys->mapPid(tc, pid);
331
332 // Set cpu task id, output process info, and dump stats
333 tc->getCpuPtr()->taskId(taskMap[pid]);
334 tc->getCpuPtr()->setPid(pid);
335
336 std::ostream* taskFile = sys->taskFile;
337
338 // Task file is read by cache occupancy plotting script or
339 // Streamline conversion script.
340 ccprintf(*taskFile,
341 "tick=%lld %d cpu_id=%d next_pid=%d next_tgid=%d next_task=%s\n",
342 curTick(), taskMap[pid], tc->cpuId(), (int) pid, (int) tgid,
343 next_task_str);
344 taskFile->flush();
345
346 // Dump and reset statistics
347 Stats::schedStatEvent(true, true, curTick(), 0);
348}
349