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

Generated on Tue Sep 21 2021 12:24:31 for gem5 by doxygen 1.8.17