gem5  v20.1.0.0
fs_workload.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2013, 2016 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(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()->atags_addr + _loadAddrOffset);
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().
106  offset(params()->atags_addr + _loadAddrOffset).
107  write(system->physProxy);
108  delete dtb_file;
109  } else {
110  // Using ATAGS
111  // Warn if the kernel supports FDT and we haven't specified one
112  if (kernel_has_fdt_support) {
113  assert(!dtb_file_specified);
114  warn("Kernel supports device tree, but no DTB file specified\n");
115  }
116  // Warn if the kernel doesn't support FDT and we have specified one
117  if (dtb_file_specified) {
118  assert(!kernel_has_fdt_support);
119  warn("DTB file specified, but no device tree support in kernel\n");
120  }
121 
122  AtagCore ac;
123  ac.flags(1); // read-only
124  ac.pagesize(8192);
125  ac.rootdev(0);
126 
128  fatal_if(atagRanges.size() != 1,
129  "Expected a single ATAG memory entry but got %d",
130  atagRanges.size());
131  AtagMem am;
132  am.memSize(atagRanges.begin()->size());
133  am.memStart(atagRanges.begin()->start());
134 
135  AtagCmdline ad;
136  ad.cmdline(commandLine);
137 
138  DPRINTF(Loader, "boot command line %d bytes: %s\n",
139  ad.size() << 2, commandLine);
140 
141  AtagNone an;
142 
143  uint32_t size = ac.size() + am.size() + ad.size() + an.size();
144  uint32_t offset = 0;
145  uint8_t *boot_data = new uint8_t[size << 2];
146 
147  offset += ac.copyOut(boot_data + offset);
148  offset += am.copyOut(boot_data + offset);
149  offset += ad.copyOut(boot_data + offset);
150  offset += an.copyOut(boot_data + offset);
151 
152  DPRINTF(Loader, "Boot atags was %d bytes in total\n", size << 2);
153  DDUMP(Loader, boot_data, size << 2);
154 
156  boot_data, size << 2);
157 
158  delete[] boot_data;
159  }
160 
161  // Kernel boot requirements to set up r0, r1 and r2 in ARMv7
162  for (auto *tc: system->threads) {
163  tc->setIntReg(0, 0);
164  tc->setIntReg(1, params()->machine_type);
165  tc->setIntReg(2, params()->atags_addr + _loadAddrOffset);
166  }
167 }
168 
170 {
171  delete debugPrintk;
172  delete skipUDelay;
173  delete skipConstUDelay;
174  delete kernelOops;
175  delete kernelPanic;
176 
177  delete dumpStats;
178 }
179 
180 void
182 {
184 
186  if (getArch() == Loader::Arm64)
187  dumpStats = addKernelFuncEvent<DumpStats64>("__switch_to");
188  else
189  dumpStats = addKernelFuncEvent<DumpStats>("__switch_to");
190 
191  panic_if(!dumpStats, "dumpStats not created!");
192 
193  std::string task_filename = "tasks.txt";
194  taskFile = simout.create(name() + "." + task_filename);
195 
196  for (auto *tc: system->threads) {
197  uint32_t pid = tc->getCpuPtr()->getPid();
198  if (pid != BaseCPU::invldPid) {
199  mapPid(tc, pid);
200  tc->getCpuPtr()->taskId(taskMap[pid]);
201  }
202  }
203  }
204 
205  const std::string dmesg_output = name() + ".dmesg";
206  if (params()->panic_on_panic) {
207  kernelPanic = addKernelFuncEventOrPanic<Linux::KernelPanic>(
208  "panic", "Kernel panic in simulated kernel", dmesg_output);
209  } else {
210  kernelPanic = addKernelFuncEventOrPanic<Linux::DmesgDump>(
211  "panic", "Kernel panic in simulated kernel", dmesg_output);
212  }
213 
214  if (params()->panic_on_oops) {
215  kernelOops = addKernelFuncEventOrPanic<Linux::KernelPanic>(
216  "oops_exit", "Kernel oops in guest", dmesg_output);
217  } else {
218  kernelOops = addKernelFuncEventOrPanic<Linux::DmesgDump>(
219  "oops_exit", "Kernel oops in guest", dmesg_output);
220  }
221 
222  // With ARM udelay() is #defined to __udelay
223  // newer kernels use __loop_udelay and __loop_const_udelay symbols
224  skipUDelay = addKernelFuncEvent<SkipUDelay<SkipFunc>>(
225  "__loop_udelay", "__udelay", 1000, 0);
226  if (!skipUDelay)
227  skipUDelay = addKernelFuncEventOrPanic<SkipUDelay<SkipFunc>>(
228  "__udelay", "__udelay", 1000, 0);
229 
230  // constant arguments to udelay() have some precomputation done ahead of
231  // time. Constant comes from code.
232  skipConstUDelay = addKernelFuncEvent<SkipUDelay<SkipFunc>>(
233  "__loop_const_udelay", "__const_udelay", 1000, 107374);
234  if (!skipConstUDelay) {
235  skipConstUDelay = addKernelFuncEventOrPanic<SkipUDelay<SkipFunc>>(
236  "__const_udelay", "__const_udelay", 1000, 107374);
237  }
238 
239  if (getArch() == Loader::Arm64) {
241  DebugPrintk<SkipFuncLinux64>>("dprintk");
242  } else {
244  DebugPrintk<SkipFuncLinux32>>("dprintk");
245  }
246 }
247 
248 void
249 FsLinux::mapPid(ThreadContext *tc, uint32_t pid)
250 {
251  // Create a new unique identifier for this pid
252  std::map<uint32_t, uint32_t>::iterator itr = taskMap.find(pid);
253  if (itr == taskMap.end()) {
254  uint32_t map_size = taskMap.size();
255  if (map_size > ContextSwitchTaskId::MaxNormalTaskId + 1) {
256  warn_once("Error out of identifiers for cache occupancy stats");
258  } else {
259  taskMap[pid] = map_size;
260  }
261  }
262 }
263 
264 void
266 {
267  Linux::dumpDmesg(system->threads[0], std::cout);
268 }
269 
278 void
280  uint32_t &tgid, std::string &next_task_str, int32_t &mm) {
281 
282  Linux::ThreadInfo ti(tc);
283  Addr task_descriptor = tc->readIntReg(2);
284  pid = ti.curTaskPID(task_descriptor);
285  tgid = ti.curTaskTGID(task_descriptor);
286  next_task_str = ti.curTaskName(task_descriptor);
287 
288  // Streamline treats pid == -1 as the kernel process.
289  // Also pid == 0 implies idle process (except during Linux boot)
290  mm = ti.curTaskMm(task_descriptor);
291 }
292 
300 void
302  uint32_t &tgid, std::string &next_task_str, int32_t &mm) {
303 
304  Linux::ThreadInfo ti(tc);
305  Addr task_struct = tc->readIntReg(1);
306  pid = ti.curTaskPIDFromTaskStruct(task_struct);
307  tgid = ti.curTaskTGIDFromTaskStruct(task_struct);
308  next_task_str = ti.curTaskNameFromTaskStruct(task_struct);
309 
310  // Streamline treats pid == -1 as the kernel process.
311  // Also pid == 0 implies idle process (except during Linux boot)
312  mm = ti.curTaskMmFromTaskStruct(task_struct);
313 }
314 
318 void
320 {
321  uint32_t pid = 0;
322  uint32_t tgid = 0;
323  std::string next_task_str;
324  int32_t mm = 0;
325 
326  getTaskDetails(tc, pid, tgid, next_task_str, mm);
327 
328  bool is_kernel = (mm == 0);
329  if (is_kernel && (pid != 0)) {
330  pid = -1;
331  tgid = -1;
332  next_task_str = "kernel";
333  }
334 
335  FsLinux* wl = dynamic_cast<FsLinux *>(tc->getSystemPtr()->workload);
336  panic_if(!wl, "System workload is not ARM Linux!");
337  std::map<uint32_t, uint32_t>& taskMap = wl->taskMap;
338 
339  // Create a new unique identifier for this pid
340  wl->mapPid(tc, pid);
341 
342  // Set cpu task id, output process info, and dump stats
343  tc->getCpuPtr()->taskId(taskMap[pid]);
344  tc->getCpuPtr()->setPid(pid);
345 
346  OutputStream* taskFile = wl->taskFile;
347 
348  // Task file is read by cache occupancy plotting script or
349  // Streamline conversion script.
350  ccprintf(*(taskFile->stream()),
351  "tick=%lld %d cpu_id=%d next_pid=%d next_tgid=%d next_task=%s\n",
352  curTick(), taskMap[pid], tc->cpuId(), (int)pid, (int)tgid,
353  next_task_str);
354  taskFile->stream()->flush();
355 
356  // Dump and reset statistics
357  Stats::schedStatEvent(true, true, curTick(), 0);
358 }
359 
360 } // namespace ArmISA
361 
363 ArmFsLinuxParams::create()
364 {
365  return new ArmISA::FsLinux(this);
366 }
events.hh
warn
#define warn(...)
Definition: logging.hh:239
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:72
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:96
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:324
Linux::ThreadInfo
Definition: threadinfo.hh:37
ArmISA::FsLinux::params
const Params * params() const
Definition: fs_workload.hh:89
KernelWorkload::addKernelFuncEvent
T * addKernelFuncEvent(const char *lbl, Args... args)
Add a function-based event to a kernel symbol.
Definition: kernel_workload.hh:129
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:130
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:106
ArmISA::FsWorkload::Params
ArmFsWorkloadParams Params
Definition: fs_workload.hh:90
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:209
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:64
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:319
Linux::DebugPrintk
Definition: events.hh:60
system.hh
ArmISA
Definition: ccregs.hh:41
BaseCPU::invldPid
static const uint32_t invldPid
Invalid or unknown Pid.
Definition: base.hh:261
ContextSwitchTaskId::Unknown
@ Unknown
Definition: request.hh:75
AtagNone
Definition: atag.hh:168
System::getPhysMem
PhysicalMemory & getPhysMem()
Get a pointer to access the physical memory of the system.
Definition: system.hh:342
Loader::SymbolTable::find
const_iterator find(Addr address) const
Definition: symtab.hh:181
ArmISA::FsLinux::dumpStats
PCEvent * dumpStats
Definition: fs_workload.hh:83
ArmISA::FsLinux::~FsLinux
~FsLinux()
Definition: fs_workload.cc:169
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:96
AtagCmdline
Definition: atag.hh:141
KernelWorkload::kernelSymtab
Loader::SymbolTable kernelSymtab
Definition: kernel_workload.hh:74
Loader
Definition: process.hh:39
Loader::debugSymbolTable
SymbolTable debugSymbolTable
Global unified debugging symbol table (for target).
Definition: symtab.cc:47
System::workload
Workload * workload
OS kernel.
Definition: system.hh:327
Loader::ObjectFile::symtab
const SymbolTable & symtab() const
Definition: object_file.hh:102
ThreadContext
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Definition: thread_context.hh:88
KernelWorkload::_loadAddrOffset
Addr _loadAddrOffset
Offset that should be used for binary/symbol loading.
Definition: kernel_workload.hh:65
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:249
OutputStream::stream
std::ostream * stream() const
Get the output underlying output stream.
Definition: output.hh:59
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
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:144
ThreadContext::cpuId
virtual int cpuId() const =0
ArmISA::FsWorkload
Definition: fs_workload.hh:62
BaseCPU::setPid
void setPid(uint32_t pid)
Definition: base.hh:207
ArmISA::FsLinux::startup
void startup() override
startup() is the final initialization call before simulation.
Definition: fs_workload.cc:181
mm
Definition: mm.h:8
KernelWorkload::kernelObj
Loader::ObjectFile * kernelObj
Definition: kernel_workload.hh:71
ArmISA::FsWorkload::getArch
Loader::Arch getArch() const override
Definition: fs_workload.hh:107
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
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:279
DDUMP
#define DDUMP(x, data, count)
DPRINTF is a debugging trace facility that allows one to selectively enable tracing statements.
Definition: trace.hh:233
utility.hh
Stats::schedStatEvent
void schedStatEvent(bool dump, bool reset, Tick when, Tick repeat)
Schedule statistics dumping.
Definition: stat_control.cc:237
Loader::SymbolTable::globals
SymbolTablePtr globals() const
Definition: symtab.hh:159
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:102
BaseCPU::taskId
uint32_t taskId() const
Get cpu task id.
Definition: base.hh:202
ArmISA::FsLinux::dumpDmesg
void dumpDmesg()
Dump the kernel's dmesg buffer to stdout.
Definition: fs_workload.cc:265
SimObject::name
virtual const std::string name() const
Definition: sim_object.hh:133
AtagCmdline::cmdline
void cmdline(const std::string &s)
Definition: atag.hh:147
Loader::SymbolTable::end
const_iterator end() const
Definition: symtab.hh:126
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:309
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:137
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:127
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
Loader::SymbolTable::insert
bool insert(const Symbol &symbol)
Definition: symtab.cc:58
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:258
simout
OutputDirectory simout
Definition: output.cc:61
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
KernelWorkload::commandLine
const std::string commandLine
Definition: kernel_workload.hh:76
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:58
curTick
Tick curTick()
The current simulated tick.
Definition: core.hh:45
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:301

Generated on Wed Sep 30 2020 14:01:59 for gem5 by doxygen 1.8.17