58#include "debug/Loader.hh"
59#include "debug/Quiesce.hh"
60#include "debug/WorkItems.hh"
64#include "params/BaseCPU.hh"
77using namespace statistics;
94const std::string DEFAULT =
"";
98const std::string DIST_RANK =
"dist-rank";
102const std::string DIST_SIZE =
"dist-size";
109 DPRINTF(PseudoInst,
"pseudo_inst::arm()\n");
119 DPRINTF(PseudoInst,
"pseudo_inst::quiesce()\n");
126 DPRINTF(PseudoInst,
"pseudo_inst::quiesceSkip()\n");
133 DPRINTF(PseudoInst,
"pseudo_inst::quiesceNs(%i)\n",
ns);
140 DPRINTF(PseudoInst,
"pseudo_inst::quiesceCycles(%i)\n", cycles);
147 DPRINTF(PseudoInst,
"pseudo_inst::quiesceTime()\n");
156 DPRINTF(PseudoInst,
"pseudo_inst::rpns()\n");
163 DPRINTF(PseudoInst,
"pseudo_inst::wakeCPU(%i)\n",
cpuid);
167 warn(
"pseudo_inst::wakeCPU(%i), cpuid greater than number of contexts"
180 DPRINTF(PseudoInst,
"pseudo_inst::m5exit(%i)\n", delay);
183 exitSimLoop(
"m5_exit instruction encountered", 0, when, 0,
true);
190 uint64_t
d, uint64_t
e, uint64_t
f)
192 DPRINTF(PseudoInst,
"pseudo_inst::m5sum(%#x, %#x, %#x, %#x, %#x, %#x)\n",
194 return a +
b +
c +
d +
e +
f;
200 DPRINTF(PseudoInst,
"pseudo_inst::m5fail(%i, %i)\n", delay, code);
202 exitSimLoop(
"m5_fail instruction encountered", code, when, 0,
true);
208 DPRINTF(PseudoInst,
"pseudo_inst::loadsymbol()\n");
211 if (filename.empty()) {
216 std::ifstream file(filename.c_str());
219 fatal(
"file error: Can't open symbol table file %s\n", filename);
221 while (!file.eof()) {
222 getline(file, buffer);
227 std::string::size_type idx = buffer.find(
' ');
228 if (idx == std::string::npos)
231 std::string address =
"0x" + buffer.substr(0, idx);
237 std::string symbol = buffer.substr(idx + 3);
247 { loader::Symbol::Binding::Global,
248 loader::Symbol::SymbolType::Function, symbol, addr })) {
253 DPRINTF(Loader,
"Loaded symbol: %s @ %#llx\n", symbol,
addr);
261 DPRINTF(PseudoInst,
"pseudo_inst::addsymbol(0x%x, 0x%x)\n",
271 DPRINTF(Loader,
"Loaded symbol: %s @ %#llx\n", symbol,
addr.addr);
286 DPRINTF(PseudoInst,
"pseudo_inst::initParam() key:%s%s\n",
287 (
char *)&key_str1, (
char *)&key_str2);
292 const int len = 2 *
sizeof(uint64_t) + 1;
294 std::memset(key,
'\0',
len);
296 std::array<uint64_t, 2> key_regs = {{ key_str1, key_str2 }};
297 key_regs =
letoh(key_regs);
298 std::memcpy(key, key_regs.data(),
sizeof(key_regs));
301 const std::string key_str(key);
304 else if (key == DIST_RANK)
306 else if (key == DIST_SIZE)
309 panic(
"Unknown key for initparam pseudo instruction:\"%s\"", key_str);
316 DPRINTF(PseudoInst,
"pseudo_inst::resetstats(%i, %i)\n", delay, period);
330 DPRINTF(PseudoInst,
"pseudo_inst::dumpstats(%i, %i)\n", delay, period);
344 DPRINTF(PseudoInst,
"pseudo_inst::dumpresetstats(%i, %i)\n", delay,
359 DPRINTF(PseudoInst,
"pseudo_inst::m5checkpoint(%i, %i)\n", delay, period);
373 DPRINTF(PseudoInst,
"pseudo_inst::readfile(0x%x, 0x%x, 0x%x)\n",
383 int fd = ::open(file.c_str(), O_RDONLY, 0);
385 panic(
"could not open file %s\n", file);
387 if (::lseek(
fd,
offset, SEEK_SET) < 0)
388 panic(
"could not seek: %s", strerror(errno));
390 char *buf =
new char[
len];
393 int bytes = ::read(
fd,
p,
len);
416 DPRINTF(PseudoInst,
"pseudo_inst::writefile(0x%x, 0x%x, 0x%x, 0x%x)\n",
420 std::string filename;
436 std::ios::in | std::ios::out | std::ios::binary,
true);
441 panic(
"could not open file %s\n", filename);
449 char *buf =
new char[
len];
453 if (
os->fail() ||
os->bad())
454 panic(
"Error while doing writefile!\n");
466 DPRINTF(PseudoInst,
"pseudo_inst::debugbreak()\n");
473 DPRINTF(PseudoInst,
"pseudo_inst::switchcpu()\n");
480 DPRINTF(PseudoInst,
"pseudo_inst::togglesync()\n");
487 DPRINTF(PseudoInst,
"pseudo_inst::triggerWorkloadEvent()\n");
499 DPRINTF(PseudoInst,
"pseudo_inst::workbegin(%i, %i)\n", workid, threadid);
503 if (params.exit_on_work_items) {
504 exitSimLoop(
"workbegin",
static_cast<int>(workid));
508 DPRINTF(WorkItems,
"Work Begin workid: %d, threadid %d\n", workid,
517 if (params.work_item_id == -1 || params.work_item_id == workid) {
522 if (params.work_cpus_ckpt_count != 0 &&
523 sys->
markWorkItem(cpuId) >= params.work_cpus_ckpt_count) {
530 if (systemWorkBeginCount == params.work_begin_ckpt_count) {
538 if (systemWorkBeginCount == params.work_begin_exit_count) {
545 if (cpuId == params.work_begin_cpu_id_exit) {
562 DPRINTF(PseudoInst,
"pseudo_inst::workend(%i, %i)\n", workid, threadid);
566 if (params.exit_on_work_items) {
571 DPRINTF(WorkItems,
"Work End workid: %d, threadid %d\n", workid, threadid);
579 if (params.work_item_id == -1 || params.work_item_id == workid) {
584 if (params.work_cpus_ckpt_count != 0 &&
585 sys->
markWorkItem(cpuId) >= params.work_cpus_ckpt_count) {
592 if (params.work_end_ckpt_count != 0 &&
593 systemWorkEndCount == params.work_end_ckpt_count) {
601 if (params.work_end_exit_count != 0 &&
602 systemWorkEndCount == params.work_end_exit_count) {
int cpuId() const
Reads this CPU's ID.
Tick clockEdge(Cycles cycles=Cycles(0)) const
Determine the tick when a cycle begins, by default the current one, but the argument also enables the...
Tick nextCycle() const
Based on the clock of the object, determine the start tick of the first cycle that is at least one cy...
Cycles is a wrapper class for representing cycle counts, i.e.
static uint64_t rankParam()
Getter for the dist rank param.
static bool readyToExit(Tick delay)
Initiate the exit from the simulation.
static void toggleSync(ThreadContext *tc)
Trigger the primary to start/stop synchronization.
static bool readyToCkpt(Tick delay, Tick period)
Initiate taking a checkpoint.
static uint64_t sizeParam()
Getter for the dist size param.
void close(OutputStream *file)
Closes an output file and free the corresponding OutputFile.
OutputStream * open(const std::string &name, std::ios_base::openmode mode, bool recreateable=true, bool no_gz=false)
Open a file in this directory (optionally compressed).
OutputStream * create(const std::string &name, bool binary=false, bool no_gz=false)
Creates a file in this directory (optionally compressed).
std::ostream * stream() const
Get the output underlying output stream.
This object is a proxy for a port or other object which implements the functional response protocol,...
void readBlob(Addr addr, void *p, uint64_t size) const
Higher level interfaces based on the above.
void writeBlob(Addr addr, const void *p, uint64_t size) const
Same as tryWriteBlob, but insists on success.
void readString(std::string &str, Addr addr) const
Same as tryReadString, but insists on success.
int markWorkItem(int index)
Called by pseudo_inst to mark the cpus actively executing work items.
uint64_t incWorkItemsEnd()
Called by pseudo_inst to track the number of work items completed by this system.
uint64_t incWorkItemsBegin()
Called by pseudo_inst to track the number of work items started by this system.
void workItemEnd(uint32_t tid, uint32_t workid)
Workload * workload
OS kernel.
void workItemBegin(uint32_t tid, uint32_t workid)
ThreadContext is the external interface to all thread state for anything outside of the CPU.
virtual void activate()=0
Set the status to Active.
virtual System * getSystemPtr()=0
virtual BaseCPU * getCpuPtr()=0
virtual Tick readLastActivate()=0
void quiesceTick(Tick resume)
Quiesce, suspend, and schedule activate at resume.
virtual Tick readLastSuspend()=0
void quiesce()
Quiesce thread context.
@ Suspended
Temporarily inactive.
virtual Status status() const =0
This proxy attempts to translate virtual addresses using the TLBs.
virtual void event(ThreadContext *tc)
virtual bool insertSymbol(const loader::Symbol &symbol)=0
bool insert(const Symbol &symbol)
Insert a new symbol in the table if it does not already exist.
#define panic(...)
This implements a cprintf based panic() function.
#define fatal(...)
This implements a cprintf based fatal() function.
const Params & params() const
SymbolTable debugSymbolTable
Global unified debugging symbol table (for target).
uint64_t m5sum(ThreadContext *tc, uint64_t a, uint64_t b, uint64_t c, uint64_t d, uint64_t e, uint64_t f)
uint64_t rpns(ThreadContext *tc)
void loadsymbol(ThreadContext *tc)
void quiesceCycles(ThreadContext *tc, uint64_t cycles)
void arm(ThreadContext *tc)
void debugbreak(ThreadContext *tc)
void m5fail(ThreadContext *tc, Tick delay, uint64_t code)
void quiesce(ThreadContext *tc)
void quiesceNs(ThreadContext *tc, uint64_t ns)
void m5exit(ThreadContext *tc, Tick delay)
void quiesceSkip(ThreadContext *tc)
void togglesync(ThreadContext *tc)
uint64_t writefile(ThreadContext *tc, GuestAddr vaddr, uint64_t len, uint64_t offset, GuestAddr filename_addr)
void resetstats(ThreadContext *tc, Tick delay, Tick period)
void workend(ThreadContext *tc, uint64_t workid, uint64_t threadid)
uint64_t initParam(ThreadContext *tc, uint64_t key_str1, uint64_t key_str2)
void triggerWorkloadEvent(ThreadContext *tc)
void addsymbol(ThreadContext *tc, GuestAddr addr, GuestAddr symbolAddr)
uint64_t quiesceTime(ThreadContext *tc)
void wakeCPU(ThreadContext *tc, uint64_t cpuid)
uint64_t readfile(ThreadContext *tc, GuestAddr vaddr, uint64_t len, uint64_t offset)
void m5checkpoint(ThreadContext *tc, Tick delay, Tick period)
void workbegin(ThreadContext *tc, uint64_t workid, uint64_t threadid)
void switchcpu(ThreadContext *tc)
void dumpstats(ThreadContext *tc, Tick delay, Tick period)
void dumpresetstats(ThreadContext *tc, Tick delay, Tick period)
void schedStatEvent(bool dump, bool reset, Tick when, Tick repeat)
Schedule statistics dumping.
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
bool to_number(const std::string &value, Pixel &retval)
Tick curTick()
The universal simulation clock.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
uint64_t Tick
Tick count type.
void exitSimLoop(const std::string &message, int exit_code, Tick when, Tick repeat, bool serialize)
Schedule an event to exit the simulation loop (returning to Python) at the end of the current cycle (...
void eat_white(std::string &s)
This struct wrapper for Addr enables m5ops for systems with 32 bit pointer, since it allows to distin...