gem5  v21.0.1.0
fs_workload.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2013, 2016, 2020 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 
42 
43 #include "arch/arm/isa_traits.hh"
44 #include "arch/arm/linux/atag.hh"
45 #include "arch/arm/system.hh"
46 #include "arch/arm/utility.hh"
48 #include "base/loader/dtb_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 "kern/linux/helpers.hh"
57 #include "kern/system_events.hh"
58 #include "mem/physical.hh"
59 #include "sim/stat_control.hh"
60 
61 using namespace Linux;
62 
63 namespace ArmISA
64 {
65 
66 FsLinux::FsLinux(const Params &p) : ArmISA::FsWorkload(p),
67  enableContextSwitchStatsDump(p.enable_context_switch_stats_dump)
68 {}
69 
70 void
72 {
74 
75  // Load symbols at physical address, we might not want
76  // to do this permanently, for but early bootup work
77  // it is helpful.
78  if (params().early_kernel_symbols) {
79  auto phys_globals = kernelObj->symtab().globals()->mask(_loadAddrMask);
80  kernelSymtab.insert(*phys_globals);
81  Loader::debugSymbolTable.insert(*phys_globals);
82  }
83 
84  // Setup boot data structure
85  // Check if the kernel image has a symbol that tells us it supports
86  // device trees.
87  bool kernel_has_fdt_support =
88  kernelSymtab.find("unflatten_device_tree") != kernelSymtab.end();
89  bool dtb_file_specified = params().dtb_filename != "";
90 
91  if (kernel_has_fdt_support && dtb_file_specified) {
92  // Kernel supports flattened device tree and dtb file specified.
93  // Using Device Tree Blob to describe system configuration.
94  inform("Loading DTB file: %s at address %#x\n", params().dtb_filename,
95  params().dtb_addr);
96 
97  auto *dtb_file = new ::Loader::DtbFile(params().dtb_filename);
98 
99  if (!dtb_file->addBootCmdLine(
100  commandLine.c_str(), commandLine.size())) {
101  warn("couldn't append bootargs to DTB file: %s\n",
102  params().dtb_filename);
103  }
104 
105  dtb_file->buildImage().offset(params().dtb_addr)
106  .write(system->physProxy);
107  delete dtb_file;
108  } else {
109  // Using ATAGS
110  // Warn if the kernel supports FDT and we haven't specified one
111  if (kernel_has_fdt_support) {
112  assert(!dtb_file_specified);
113  warn("Kernel supports device tree, but no DTB file specified\n");
114  }
115  // Warn if the kernel doesn't support FDT and we have specified one
116  if (dtb_file_specified) {
117  assert(!kernel_has_fdt_support);
118  warn("DTB file specified, but no device tree support in kernel\n");
119  }
120 
121  AtagCore ac;
122  ac.flags(1); // read-only
123  ac.pagesize(8192);
124  ac.rootdev(0);
125 
127  fatal_if(atagRanges.size() != 1,
128  "Expected a single ATAG memory entry but got %d",
129  atagRanges.size());
130  AtagMem am;
131  am.memSize(atagRanges.begin()->size());
132  am.memStart(atagRanges.begin()->start());
133 
134  AtagCmdline ad;
135  ad.cmdline(commandLine);
136 
137  DPRINTF(Loader, "boot command line %d bytes: %s\n",
138  ad.size() << 2, commandLine);
139 
140  AtagNone an;
141 
142  uint32_t size = ac.size() + am.size() + ad.size() + an.size();
143  uint32_t offset = 0;
144  uint8_t *boot_data = new uint8_t[size << 2];
145 
146  offset += ac.copyOut(boot_data + offset);
147  offset += am.copyOut(boot_data + offset);
148  offset += ad.copyOut(boot_data + offset);
149  offset += an.copyOut(boot_data + offset);
150 
151  DPRINTF(Loader, "Boot atags was %d bytes in total\n", size << 2);
152  DDUMP(Loader, boot_data, size << 2);
153 
154  system->physProxy.writeBlob(params().dtb_addr,
155  boot_data, size << 2);
156 
157  delete[] boot_data;
158  }
159 
160  if (getArch() == Loader::Arm64) {
161  // We inform the bootloader of the kernel entry point. This was added
162  // originally done because the entry offset changed in kernel v5.8.
163  // Previously the bootloader just used a hardcoded address.
164  for (auto *tc: system->threads) {
165  tc->setIntReg(0, params().dtb_addr);
166  tc->setIntReg(5, params().cpu_release_addr);
167  }
168  } else {
169  // Kernel boot requirements to set up r0, r1 and r2 in ARMv7
170  for (auto *tc: system->threads) {
171  tc->setIntReg(0, 0);
172  tc->setIntReg(1, params().machine_type);
173  tc->setIntReg(2, params().dtb_addr);
174  }
175  }
176 }
177 
179 {
180  delete debugPrintk;
181  delete skipUDelay;
182  delete skipConstUDelay;
183  delete kernelOops;
184  delete kernelPanic;
185 
186  delete dumpStats;
187 }
188 
189 void
191 {
193 
195  if (getArch() == Loader::Arm64)
196  dumpStats = addKernelFuncEvent<DumpStats64>("__switch_to");
197  else
198  dumpStats = addKernelFuncEvent<DumpStats>("__switch_to");
199 
200  panic_if(!dumpStats, "dumpStats not created!");
201 
202  std::string task_filename = "tasks.txt";
203  taskFile = simout.create(name() + "." + task_filename);
204 
205  for (auto *tc: system->threads) {
206  uint32_t pid = tc->getCpuPtr()->getPid();
207  if (pid != BaseCPU::invldPid) {
208  mapPid(tc, pid);
209  tc->getCpuPtr()->taskId(taskMap[pid]);
210  }
211  }
212  }
213 
214  const std::string dmesg_output = name() + ".dmesg";
215  if (params().panic_on_panic) {
216  kernelPanic = addKernelFuncEventOrPanic<Linux::KernelPanic>(
217  "panic", "Kernel panic in simulated kernel", dmesg_output);
218  } else {
219  kernelPanic = addKernelFuncEventOrPanic<Linux::DmesgDump>(
220  "panic", "Kernel panic in simulated kernel", dmesg_output);
221  }
222 
223  if (params().panic_on_oops) {
224  kernelOops = addKernelFuncEventOrPanic<Linux::KernelPanic>(
225  "oops_exit", "Kernel oops in guest", dmesg_output);
226  } else {
227  kernelOops = addKernelFuncEventOrPanic<Linux::DmesgDump>(
228  "oops_exit", "Kernel oops in guest", dmesg_output);
229  }
230 
231  // With ARM udelay() is #defined to __udelay
232  // newer kernels use __loop_udelay and __loop_const_udelay symbols
233  skipUDelay = addSkipFunc<SkipUDelay>(
234  "__loop_udelay", "__udelay", 1000, 0);
235  if (!skipUDelay) {
236  skipUDelay = addSkipFuncOrPanic<SkipUDelay>(
237  "__udelay", "__udelay", 1000, 0);
238  }
239 
240  // constant arguments to udelay() have some precomputation done ahead of
241  // time. Constant comes from code.
242  skipConstUDelay = addSkipFunc<SkipUDelay>(
243  "__loop_const_udelay", "__const_udelay", 1000, 107374);
244  if (!skipConstUDelay) {
245  skipConstUDelay = addSkipFuncOrPanic<SkipUDelay>(
246  "__const_udelay", "__const_udelay", 1000, 107374);
247  }
248 
249  debugPrintk = addSkipFunc<DebugPrintk>("dprintk");
250 }
251 
252 void
253 FsLinux::mapPid(ThreadContext *tc, uint32_t pid)
254 {
255  // Create a new unique identifier for this pid
256  std::map<uint32_t, uint32_t>::iterator itr = taskMap.find(pid);
257  if (itr == taskMap.end()) {
258  uint32_t map_size = taskMap.size();
259  if (map_size > ContextSwitchTaskId::MaxNormalTaskId + 1) {
260  warn_once("Error out of identifiers for cache occupancy stats");
262  } else {
263  taskMap[pid] = map_size;
264  }
265  }
266 }
267 
268 void
270 {
271  Linux::dumpDmesg(system->threads[0], std::cout);
272 }
273 
282 void
284  uint32_t &tgid, std::string &next_task_str, int32_t &mm) {
285 
286  Linux::ThreadInfo ti(tc);
287  Addr task_descriptor = tc->readIntReg(2);
288  pid = ti.curTaskPID(task_descriptor);
289  tgid = ti.curTaskTGID(task_descriptor);
290  next_task_str = ti.curTaskName(task_descriptor);
291 
292  // Streamline treats pid == -1 as the kernel process.
293  // Also pid == 0 implies idle process (except during Linux boot)
294  mm = ti.curTaskMm(task_descriptor);
295 }
296 
304 void
306  uint32_t &tgid, std::string &next_task_str, int32_t &mm) {
307 
308  Linux::ThreadInfo ti(tc);
309  Addr task_struct = tc->readIntReg(1);
310  pid = ti.curTaskPIDFromTaskStruct(task_struct);
311  tgid = ti.curTaskTGIDFromTaskStruct(task_struct);
312  next_task_str = ti.curTaskNameFromTaskStruct(task_struct);
313 
314  // Streamline treats pid == -1 as the kernel process.
315  // Also pid == 0 implies idle process (except during Linux boot)
316  mm = ti.curTaskMmFromTaskStruct(task_struct);
317 }
318 
322 void
324 {
325  uint32_t pid = 0;
326  uint32_t tgid = 0;
327  std::string next_task_str;
328  int32_t mm = 0;
329 
330  getTaskDetails(tc, pid, tgid, next_task_str, mm);
331 
332  bool is_kernel = (mm == 0);
333  if (is_kernel && (pid != 0)) {
334  pid = -1;
335  tgid = -1;
336  next_task_str = "kernel";
337  }
338 
339  FsLinux* wl = dynamic_cast<FsLinux *>(tc->getSystemPtr()->workload);
340  panic_if(!wl, "System workload is not ARM Linux!");
341  std::map<uint32_t, uint32_t>& taskMap = wl->taskMap;
342 
343  // Create a new unique identifier for this pid
344  wl->mapPid(tc, pid);
345 
346  // Set cpu task id, output process info, and dump stats
347  tc->getCpuPtr()->taskId(taskMap[pid]);
348  tc->getCpuPtr()->setPid(pid);
349 
350  OutputStream* taskFile = wl->taskFile;
351 
352  // Task file is read by cache occupancy plotting script or
353  // Streamline conversion script.
354  ccprintf(*(taskFile->stream()),
355  "tick=%lld %d cpu_id=%d next_pid=%d next_tgid=%d next_task=%s\n",
356  curTick(), taskMap[pid], tc->cpuId(), (int)pid, (int)tgid,
357  next_task_str);
358  taskFile->stream()->flush();
359 
360  // Dump and reset statistics
361  Stats::schedStatEvent(true, true, curTick(), 0);
362 }
363 
364 } // namespace ArmISA
events.hh
warn
#define warn(...)
Definition: logging.hh:239
SimObject::Params
SimObjectParams Params
Definition: sim_object.hh:162
AtagHeader::copyOut
uint32_t copyOut(uint8_t *p)
Definition: atag.hh:80
MipsISA::ti
Bitfield< 30 > ti
Definition: pra_constants.hh:176
ContextSwitchTaskId::MaxNormalTaskId
@ MaxNormalTaskId
Definition: request.hh:76
ArmISA::FsLinux::enableContextSwitchStatsDump
bool enableContextSwitchStatsDump
When enabled, dump stats/task info on context switches for Streamline and per-thread cache occupancy ...
Definition: fs_workload.hh:91
warn_once
#define warn_once(...)
Definition: logging.hh:243
System::physProxy
PortProxy physProxy
Port to physical memory used for writing object files into ram at boot.
Definition: system.hh:319
Linux::ThreadInfo
Definition: threadinfo.hh:37
X86ISA::ac
Bitfield< 18 > ac
Definition: misc.hh:561
ArmISA::FsLinux::kernelOops
PCEvent * kernelOops
Event to halt the simulator if the kernel calls oopses
Definition: fs_workload.hh:125
ArmISA::FsLinux::debugPrintk
PCEvent * debugPrintk
PC based event to skip the dprink() call and emulate its functionality.
Definition: fs_workload.hh:81
ArmISA::FsLinux
Definition: fs_workload.hh:74
ArmISA::FsLinux::taskFile
OutputStream * taskFile
This is a file that is placed in the run directory that prints out mappings between taskIds and OS pr...
Definition: fs_workload.hh:101
OutputDirectory::create
OutputStream * create(const std::string &name, bool binary=false, bool no_gz=false)
Creates a file in this directory (optionally compressed).
Definition: output.cc:207
ArmISA::FsWorkload::initState
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
Definition: fs_workload.cc:98
dtb_file.hh
Workload::system
System * system
Definition: workload.hh:73
helpers.hh
AtagMem
Definition: atag.hh:103
ArmISA::DumpStats::process
void process(ThreadContext *tc) override
This function is called whenever the the kernel function "__switch_to" is called to change running ta...
Definition: fs_workload.cc:323
system.hh
ArmISA
Definition: ccregs.hh:41
BaseCPU::invldPid
static const uint32_t invldPid
Invalid or unknown Pid.
Definition: base.hh:278
ContextSwitchTaskId::Unknown
@ Unknown
Definition: request.hh:79
AtagNone
Definition: atag.hh:168
System::getPhysMem
PhysicalMemory & getPhysMem()
Get a pointer to access the physical memory of the system.
Definition: system.hh:337
Loader::SymbolTable::find
const_iterator find(Addr address) const
Definition: symtab.hh:179
ArmISA::FsLinux::dumpStats
PCEvent * dumpStats
Definition: fs_workload.hh:83
ArmISA::FsLinux::~FsLinux
~FsLinux()
Definition: fs_workload.cc:178
PortProxy::writeBlob
void writeBlob(Addr addr, const void *p, int size) const
Same as tryWriteBlob, but insists on success.
Definition: port_proxy.hh:187
SimObject::startup
virtual void startup()
startup() is the final initialization call before simulation.
Definition: sim_object.cc:93
AtagCmdline
Definition: atag.hh:141
KernelWorkload::kernelSymtab
Loader::SymbolTable kernelSymtab
Definition: kernel_workload.hh:69
Loader
Definition: process.hh:34
Loader::debugSymbolTable
SymbolTable debugSymbolTable
Global unified debugging symbol table (for target).
Definition: symtab.cc:40
System::workload
Workload * workload
OS kernel.
Definition: system.hh:322
Loader::ObjectFile::symtab
const SymbolTable & symtab() const
Definition: object_file.hh:106
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
ArmISA::FsLinux::mapPid
void mapPid(ThreadContext *tc, uint32_t pid)
This function creates a new task Id for the given pid.
Definition: fs_workload.cc:253
OutputStream::stream
std::ostream * stream() const
Get the output underlying output stream.
Definition: output.hh:59
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:237
SparcISA::am
Bitfield< 3 > am
Definition: miscregs.hh:127
ArmISA::FsLinux::skipConstUDelay
PCEvent * skipConstUDelay
Another PC based skip event for const_udelay().
Definition: fs_workload.hh:139
ThreadContext::cpuId
virtual int cpuId() const =0
ArmISA::FsWorkload
Definition: fs_workload.hh:64
BaseCPU::setPid
void setPid(uint32_t pid)
Definition: base.hh:224
ArmISA::FsLinux::startup
void startup() override
startup() is the final initialization call before simulation.
Definition: fs_workload.cc:190
mm
Definition: mm.h:8
KernelWorkload::kernelObj
Loader::ObjectFile * kernelObj
Definition: kernel_workload.hh:66
ArmISA::FsWorkload::getArch
Loader::Arch getArch() const override
Definition: fs_workload.hh:132
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:148
ArmISA::DumpStats::getTaskDetails
virtual void getTaskDetails(ThreadContext *tc, uint32_t &pid, uint32_t &tgid, std::string &next_task_str, int32_t &mm)
Extracts the information used by the DumpStatsPCEvent by reading the thread_info pointer passed to __...
Definition: fs_workload.cc:283
DDUMP
#define DDUMP(x, data, count)
DPRINTF is a debugging trace facility that allows one to selectively enable tracing statements.
Definition: trace.hh:236
utility.hh
Stats::schedStatEvent
void schedStatEvent(bool dump, bool reset, Tick when, Tick repeat)
Schedule statistics dumping.
Definition: stat_control.cc:101
Loader::SymbolTable::globals
SymbolTablePtr globals() const
Definition: symtab.hh:157
ArmISA::FsLinux::taskMap
std::map< uint32_t, uint32_t > taskMap
This map stores a mapping of OS process IDs to internal Task IDs.
Definition: fs_workload.hh:97
BaseCPU::taskId
uint32_t taskId() const
Get cpu task id.
Definition: base.hh:219
ArmISA::FsLinux::dumpDmesg
void dumpDmesg()
Dump the kernel's dmesg buffer to stdout.
Definition: fs_workload.cc:269
SimObject::name
virtual const std::string name() const
Definition: sim_object.hh:182
AtagCmdline::cmdline
void cmdline(const std::string &s)
Definition: atag.hh:147
Loader::SymbolTable::end
const_iterator end() const
Definition: symtab.hh:125
stat_control.hh
panic_if
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Definition: logging.hh:197
System::threads
Threads threads
Definition: system.hh:304
ArmISA::FsLinux::skipUDelay
PCEvent * skipUDelay
PC based event to skip udelay(<time>) calls and quiesce the processor for the appropriate amount of t...
Definition: fs_workload.hh:132
inform
#define inform(...)
Definition: logging.hh:240
base.hh
pc_event.hh
ArmISA::FsLinux::kernelPanic
PCEvent * kernelPanic
Event to halt the simulator if the kernel calls panic()
Definition: fs_workload.hh:122
OutputStream
Definition: output.hh:53
AtagCore
Definition: atag.hh:89
physical.hh
threadinfo.hh
fs_workload.hh
ccprintf
void ccprintf(cp::Print &print)
Definition: cprintf.hh:127
system_events.hh
Linux::dumpDmesg
void dumpDmesg(ThreadContext *tc, std::ostream &os)
Dump Linux's dmesg log buffer to the an output stream.
isa_traits.hh
Loader::Arm64
@ Arm64
Definition: object_file.hh:51
curTick
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:43
Loader::SymbolTable::insert
bool insert(const Symbol &symbol)
Definition: symtab.cc:51
symtab.hh
PhysicalMemory::getConfAddrRanges
AddrRangeList getConfAddrRanges() const
Get the memory ranges for all memories that are to be reported to the configuration table.
Definition: physical.cc:256
SimObject::params
const Params & params() const
Definition: sim_object.hh:168
simout
OutputDirectory simout
Definition: output.cc:59
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
KernelWorkload::commandLine
const std::string commandLine
Definition: kernel_workload.hh:71
std::list< AddrRange >
atag.hh
ThreadContext::readIntReg
virtual RegVal readIntReg(RegIndex reg_idx) const =0
fatal_if
#define fatal_if(cond,...)
Conditional fatal macro that checks the supplied condition and only causes a fatal error if the condi...
Definition: logging.hh:219
Linux
Definition: threadinfo.hh:35
ThreadContext::getCpuPtr
virtual BaseCPU * getCpuPtr()=0
object_file.hh
ArmISA::FsLinux::initState
void initState() override
initState() is called on each SimObject when not restoring from a checkpoint.
Definition: fs_workload.cc:71
thread_context.hh
AtagHeader::size
uint32_t size() const
Definition: atag.hh:67
ThreadContext::getSystemPtr
virtual System * getSystemPtr()=0
KernelWorkload::_loadAddrMask
Addr _loadAddrMask
Mask that should be anded for binary/symbol loading.
Definition: kernel_workload.hh:53
ArmISA::offset
Bitfield< 23, 0 > offset
Definition: types.hh:153
ArmISA::DumpStats64::getTaskDetails
void getTaskDetails(ThreadContext *tc, uint32_t &pid, uint32_t &tgid, std::string &next_task_str, int32_t &mm) override
Extracts the information used by the DumpStatsPCEvent64 by reading the task_struct pointer passed to ...
Definition: fs_workload.cc:305

Generated on Tue Jun 22 2021 15:28:20 for gem5 by doxygen 1.8.17