217 togglesync(tc); 218 break; 219 220 default: 221 warn("Unhandled m5 op: 0x%x\n", func); 222 break; 223 } 224 225 return 0; 226} 227 228void 229arm(ThreadContext *tc) 230{ 231 DPRINTF(PseudoInst, "PseudoInst::arm()\n"); 232 if (!FullSystem) 233 panicFsOnlyPseudoInst("arm"); 234 235 if (tc->getKernelStats()) 236 tc->getKernelStats()->arm(); 237} 238 239void 240quiesce(ThreadContext *tc) 241{ 242 DPRINTF(PseudoInst, "PseudoInst::quiesce()\n"); 243 tc->quiesce(); 244} 245 246void 247quiesceSkip(ThreadContext *tc) 248{ 249 DPRINTF(PseudoInst, "PseudoInst::quiesceSkip()\n"); 250 tc->quiesceTick(tc->getCpuPtr()->nextCycle() + 1); 251} 252 253void 254quiesceNs(ThreadContext *tc, uint64_t ns) 255{ 256 DPRINTF(PseudoInst, "PseudoInst::quiesceNs(%i)\n", ns); 257 tc->quiesceTick(curTick() + SimClock::Int::ns * ns); 258} 259 260void 261quiesceCycles(ThreadContext *tc, uint64_t cycles) 262{ 263 DPRINTF(PseudoInst, "PseudoInst::quiesceCycles(%i)\n", cycles); 264 tc->quiesceTick(tc->getCpuPtr()->clockEdge(Cycles(cycles))); 265} 266 267uint64_t 268quiesceTime(ThreadContext *tc) 269{ 270 DPRINTF(PseudoInst, "PseudoInst::quiesceTime()\n"); 271 272 return (tc->readLastActivate() - tc->readLastSuspend()) / 273 SimClock::Int::ns; 274} 275 276uint64_t 277rpns(ThreadContext *tc) 278{ 279 DPRINTF(PseudoInst, "PseudoInst::rpns()\n"); 280 return curTick() / SimClock::Int::ns; 281} 282 283void 284wakeCPU(ThreadContext *tc, uint64_t cpuid) 285{ 286 DPRINTF(PseudoInst, "PseudoInst::wakeCPU(%i)\n", cpuid); 287 System *sys = tc->getSystemPtr(); 288 289 if (sys->numContexts() <= cpuid) { 290 warn("PseudoInst::wakeCPU(%i), cpuid greater than number of contexts" 291 "(%i)\n",cpuid, sys->numContexts()); 292 return; 293 } 294 295 ThreadContext *other_tc = sys->threadContexts[cpuid]; 296 if (other_tc->status() == ThreadContext::Suspended) 297 other_tc->activate(); 298} 299 300void 301m5exit(ThreadContext *tc, Tick delay) 302{ 303 DPRINTF(PseudoInst, "PseudoInst::m5exit(%i)\n", delay); 304 if (DistIface::readyToExit(delay)) { 305 Tick when = curTick() + delay * SimClock::Int::ns; 306 exitSimLoop("m5_exit instruction encountered", 0, when, 0, true); 307 } 308} 309 310void 311m5fail(ThreadContext *tc, Tick delay, uint64_t code) 312{ 313 DPRINTF(PseudoInst, "PseudoInst::m5fail(%i, %i)\n", delay, code); 314 Tick when = curTick() + delay * SimClock::Int::ns; 315 exitSimLoop("m5_fail instruction encountered", code, when, 0, true); 316} 317 318void 319loadsymbol(ThreadContext *tc) 320{ 321 DPRINTF(PseudoInst, "PseudoInst::loadsymbol()\n"); 322 if (!FullSystem) 323 panicFsOnlyPseudoInst("loadsymbol"); 324 325 const string &filename = tc->getCpuPtr()->system->params()->symbolfile; 326 if (filename.empty()) { 327 return; 328 } 329 330 std::string buffer; 331 ifstream file(filename.c_str()); 332 333 if (!file) 334 fatal("file error: Can't open symbol table file %s\n", filename); 335 336 while (!file.eof()) { 337 getline(file, buffer); 338 339 if (buffer.empty()) 340 continue; 341 342 string::size_type idx = buffer.find(' '); 343 if (idx == string::npos) 344 continue; 345 346 string address = "0x" + buffer.substr(0, idx); 347 eat_white(address); 348 if (address.empty()) 349 continue; 350 351 // Skip over letter and space 352 string symbol = buffer.substr(idx + 3); 353 eat_white(symbol); 354 if (symbol.empty()) 355 continue; 356 357 Addr addr; 358 if (!to_number(address, addr)) 359 continue; 360 361 if (!tc->getSystemPtr()->kernelSymtab->insert(addr, symbol)) 362 continue; 363 364 365 DPRINTF(Loader, "Loaded symbol: %s @ %#llx\n", symbol, addr); 366 } 367 file.close(); 368} 369 370void 371addsymbol(ThreadContext *tc, Addr addr, Addr symbolAddr) 372{ 373 DPRINTF(PseudoInst, "PseudoInst::addsymbol(0x%x, 0x%x)\n", 374 addr, symbolAddr); 375 if (!FullSystem) 376 panicFsOnlyPseudoInst("addSymbol"); 377 378 char symb[100]; 379 CopyStringOut(tc, symb, symbolAddr, 100); 380 std::string symbol(symb); 381 382 DPRINTF(Loader, "Loaded symbol: %s @ %#llx\n", symbol, addr); 383 384 tc->getSystemPtr()->kernelSymtab->insert(addr,symbol); 385 debugSymbolTable->insert(addr,symbol); 386} 387 388uint64_t 389initParam(ThreadContext *tc, uint64_t key_str1, uint64_t key_str2) 390{ 391 DPRINTF(PseudoInst, "PseudoInst::initParam() key:%s%s\n", (char *)&key_str1, 392 (char *)&key_str2); 393 if (!FullSystem) { 394 panicFsOnlyPseudoInst("initParam"); 395 return 0; 396 } 397 398 // The key parameter string is passed in via two 64-bit registers. We copy 399 // out the characters from the 64-bit integer variables here and concatenate 400 // them in the key_str character buffer 401 const int len = 2 * sizeof(uint64_t) + 1; 402 char key_str[len]; 403 memset(key_str, '\0', len); 404 if (key_str1 == 0) { 405 assert(key_str2 == 0); 406 } else { 407 strncpy(key_str, (char *)&key_str1, sizeof(uint64_t)); 408 } 409 410 if (strlen(key_str) == sizeof(uint64_t)) { 411 strncpy(key_str + sizeof(uint64_t), (char *)&key_str2, 412 sizeof(uint64_t)); 413 } else { 414 assert(key_str2 == 0); 415 } 416 417 // Compare the key parameter with the known values to select the return 418 // value 419 uint64_t val; 420 if (strcmp(key_str, InitParamKey::DEFAULT) == 0) { 421 val = tc->getCpuPtr()->system->init_param; 422 } else if (strcmp(key_str, InitParamKey::DIST_RANK) == 0) { 423 val = DistIface::rankParam(); 424 } else if (strcmp(key_str, InitParamKey::DIST_SIZE) == 0) { 425 val = DistIface::sizeParam(); 426 } else { 427 panic("Unknown key for initparam pseudo instruction:\"%s\"", key_str); 428 } 429 return val; 430} 431 432 433void 434resetstats(ThreadContext *tc, Tick delay, Tick period) 435{ 436 DPRINTF(PseudoInst, "PseudoInst::resetstats(%i, %i)\n", delay, period); 437 if (!tc->getCpuPtr()->params()->do_statistics_insts) 438 return; 439 440 441 Tick when = curTick() + delay * SimClock::Int::ns; 442 Tick repeat = period * SimClock::Int::ns; 443 444 Stats::schedStatEvent(false, true, when, repeat); 445} 446 447void 448dumpstats(ThreadContext *tc, Tick delay, Tick period) 449{ 450 DPRINTF(PseudoInst, "PseudoInst::dumpstats(%i, %i)\n", delay, period); 451 if (!tc->getCpuPtr()->params()->do_statistics_insts) 452 return; 453 454 455 Tick when = curTick() + delay * SimClock::Int::ns; 456 Tick repeat = period * SimClock::Int::ns; 457 458 Stats::schedStatEvent(true, false, when, repeat); 459} 460 461void 462dumpresetstats(ThreadContext *tc, Tick delay, Tick period) 463{ 464 DPRINTF(PseudoInst, "PseudoInst::dumpresetstats(%i, %i)\n", delay, period); 465 if (!tc->getCpuPtr()->params()->do_statistics_insts) 466 return; 467 468 469 Tick when = curTick() + delay * SimClock::Int::ns; 470 Tick repeat = period * SimClock::Int::ns; 471 472 Stats::schedStatEvent(true, true, when, repeat); 473} 474 475void 476m5checkpoint(ThreadContext *tc, Tick delay, Tick period) 477{ 478 DPRINTF(PseudoInst, "PseudoInst::m5checkpoint(%i, %i)\n", delay, period); 479 if (!tc->getCpuPtr()->params()->do_checkpoint_insts) 480 return; 481 482 if (DistIface::readyToCkpt(delay, period)) { 483 Tick when = curTick() + delay * SimClock::Int::ns; 484 Tick repeat = period * SimClock::Int::ns; 485 exitSimLoop("checkpoint", 0, when, repeat); 486 } 487} 488 489uint64_t 490readfile(ThreadContext *tc, Addr vaddr, uint64_t len, uint64_t offset) 491{ 492 DPRINTF(PseudoInst, "PseudoInst::readfile(0x%x, 0x%x, 0x%x)\n", 493 vaddr, len, offset); 494 if (!FullSystem) { 495 panicFsOnlyPseudoInst("readfile"); 496 return 0; 497 } 498 499 const string &file = tc->getSystemPtr()->params()->readfile; 500 if (file.empty()) { 501 return ULL(0); 502 } 503 504 uint64_t result = 0; 505 506 int fd = ::open(file.c_str(), O_RDONLY, 0); 507 if (fd < 0) 508 panic("could not open file %s\n", file); 509 510 if (::lseek(fd, offset, SEEK_SET) < 0) 511 panic("could not seek: %s", strerror(errno)); 512 513 char *buf = new char[len]; 514 char *p = buf; 515 while (len > 0) { 516 int bytes = ::read(fd, p, len); 517 if (bytes <= 0) 518 break; 519 520 p += bytes; 521 result += bytes; 522 len -= bytes; 523 } 524 525 close(fd); 526 CopyIn(tc, vaddr, buf, result); 527 delete [] buf; 528 return result; 529} 530 531uint64_t 532writefile(ThreadContext *tc, Addr vaddr, uint64_t len, uint64_t offset, 533 Addr filename_addr) 534{ 535 DPRINTF(PseudoInst, "PseudoInst::writefile(0x%x, 0x%x, 0x%x, 0x%x)\n", 536 vaddr, len, offset, filename_addr); 537 538 // copy out target filename 539 char fn[100]; 540 std::string filename; 541 CopyStringOut(tc, fn, filename_addr, 100); 542 filename = std::string(fn); 543 544 OutputStream *out; 545 if (offset == 0) { 546 // create a new file (truncate) 547 out = simout.create(filename, true, true); 548 } else { 549 // do not truncate file if offset is non-zero 550 // (ios::in flag is required as well to keep the existing data 551 // intact, otherwise existing data will be zeroed out.) 552 out = simout.open(filename, ios::in | ios::out | ios::binary, true); 553 } 554 555 ostream *os(out->stream()); 556 if (!os) 557 panic("could not open file %s\n", filename); 558 559 // seek to offset 560 os->seekp(offset); 561 562 // copy out data and write to file 563 char *buf = new char[len]; 564 CopyOut(tc, buf, vaddr, len); 565 os->write(buf, len); 566 if (os->fail() || os->bad()) 567 panic("Error while doing writefile!\n"); 568 569 simout.close(out); 570 571 delete [] buf; 572 573 return len; 574} 575 576void 577debugbreak(ThreadContext *tc) 578{ 579 DPRINTF(PseudoInst, "PseudoInst::debugbreak()\n"); 580 Debug::breakpoint(); 581} 582 583void 584switchcpu(ThreadContext *tc) 585{ 586 DPRINTF(PseudoInst, "PseudoInst::switchcpu()\n"); 587 exitSimLoop("switchcpu"); 588} 589 590void 591togglesync(ThreadContext *tc) 592{ 593 DPRINTF(PseudoInst, "PseudoInst::togglesync()\n"); 594 DistIface::toggleSync(tc); 595} 596 597// 598// This function is executed when annotated work items begin. Depending on 599// what the user specified at the command line, the simulation may exit and/or 600// take a checkpoint when a certain work item begins. 601// 602void 603workbegin(ThreadContext *tc, uint64_t workid, uint64_t threadid) 604{ 605 DPRINTF(PseudoInst, "PseudoInst::workbegin(%i, %i)\n", workid, threadid); 606 System *sys = tc->getSystemPtr(); 607 const System::Params *params = sys->params(); 608 609 if (params->exit_on_work_items) { 610 exitSimLoop("workbegin", static_cast<int>(workid)); 611 return; 612 } 613 614 DPRINTF(WorkItems, "Work Begin workid: %d, threadid %d\n", workid, 615 threadid); 616 tc->getCpuPtr()->workItemBegin(); 617 sys->workItemBegin(threadid, workid); 618 619 // 620 // If specified, determine if this is the specific work item the user 621 // identified 622 // 623 if (params->work_item_id == -1 || params->work_item_id == workid) { 624 625 uint64_t systemWorkBeginCount = sys->incWorkItemsBegin(); 626 int cpuId = tc->getCpuPtr()->cpuId(); 627 628 if (params->work_cpus_ckpt_count != 0 && 629 sys->markWorkItem(cpuId) >= params->work_cpus_ckpt_count) { 630 // 631 // If active cpus equals checkpoint count, create checkpoint 632 // 633 exitSimLoop("checkpoint"); 634 } 635 636 if (systemWorkBeginCount == params->work_begin_ckpt_count) { 637 // 638 // Note: the string specified as the cause of the exit event must 639 // exactly equal "checkpoint" inorder to create a checkpoint 640 // 641 exitSimLoop("checkpoint"); 642 } 643 644 if (systemWorkBeginCount == params->work_begin_exit_count) { 645 // 646 // If a certain number of work items started, exit simulation 647 // 648 exitSimLoop("work started count reach"); 649 } 650 651 if (cpuId == params->work_begin_cpu_id_exit) { 652 // 653 // If work started on the cpu id specified, exit simulation 654 // 655 exitSimLoop("work started on specific cpu"); 656 } 657 } 658} 659 660// 661// This function is executed when annotated work items end. Depending on 662// what the user specified at the command line, the simulation may exit and/or 663// take a checkpoint when a certain work item ends. 664// 665void 666workend(ThreadContext *tc, uint64_t workid, uint64_t threadid) 667{ 668 DPRINTF(PseudoInst, "PseudoInst::workend(%i, %i)\n", workid, threadid); 669 System *sys = tc->getSystemPtr(); 670 const System::Params *params = sys->params(); 671 672 if (params->exit_on_work_items) { 673 exitSimLoop("workend", static_cast<int>(workid)); 674 return; 675 } 676 677 DPRINTF(WorkItems, "Work End workid: %d, threadid %d\n", workid, threadid); 678 tc->getCpuPtr()->workItemEnd(); 679 sys->workItemEnd(threadid, workid); 680 681 // 682 // If specified, determine if this is the specific work item the user 683 // identified 684 // 685 if (params->work_item_id == -1 || params->work_item_id == workid) { 686 687 uint64_t systemWorkEndCount = sys->incWorkItemsEnd(); 688 int cpuId = tc->getCpuPtr()->cpuId(); 689 690 if (params->work_cpus_ckpt_count != 0 && 691 sys->markWorkItem(cpuId) >= params->work_cpus_ckpt_count) { 692 // 693 // If active cpus equals checkpoint count, create checkpoint 694 // 695 exitSimLoop("checkpoint"); 696 } 697 698 if (params->work_end_ckpt_count != 0 && 699 systemWorkEndCount == params->work_end_ckpt_count) { 700 // 701 // If total work items completed equals checkpoint count, create 702 // checkpoint 703 // 704 exitSimLoop("checkpoint"); 705 } 706 707 if (params->work_end_exit_count != 0 && 708 systemWorkEndCount == params->work_end_exit_count) { 709 // 710 // If total work items completed equals exit count, exit simulation 711 // 712 exitSimLoop("work items exit count reached"); 713 } 714 } 715} 716 717} // namespace PseudoInst
| 219 togglesync(tc); 220 break; 221 222 default: 223 warn("Unhandled m5 op: 0x%x\n", func); 224 break; 225 } 226 227 return 0; 228} 229 230void 231arm(ThreadContext *tc) 232{ 233 DPRINTF(PseudoInst, "PseudoInst::arm()\n"); 234 if (!FullSystem) 235 panicFsOnlyPseudoInst("arm"); 236 237 if (tc->getKernelStats()) 238 tc->getKernelStats()->arm(); 239} 240 241void 242quiesce(ThreadContext *tc) 243{ 244 DPRINTF(PseudoInst, "PseudoInst::quiesce()\n"); 245 tc->quiesce(); 246} 247 248void 249quiesceSkip(ThreadContext *tc) 250{ 251 DPRINTF(PseudoInst, "PseudoInst::quiesceSkip()\n"); 252 tc->quiesceTick(tc->getCpuPtr()->nextCycle() + 1); 253} 254 255void 256quiesceNs(ThreadContext *tc, uint64_t ns) 257{ 258 DPRINTF(PseudoInst, "PseudoInst::quiesceNs(%i)\n", ns); 259 tc->quiesceTick(curTick() + SimClock::Int::ns * ns); 260} 261 262void 263quiesceCycles(ThreadContext *tc, uint64_t cycles) 264{ 265 DPRINTF(PseudoInst, "PseudoInst::quiesceCycles(%i)\n", cycles); 266 tc->quiesceTick(tc->getCpuPtr()->clockEdge(Cycles(cycles))); 267} 268 269uint64_t 270quiesceTime(ThreadContext *tc) 271{ 272 DPRINTF(PseudoInst, "PseudoInst::quiesceTime()\n"); 273 274 return (tc->readLastActivate() - tc->readLastSuspend()) / 275 SimClock::Int::ns; 276} 277 278uint64_t 279rpns(ThreadContext *tc) 280{ 281 DPRINTF(PseudoInst, "PseudoInst::rpns()\n"); 282 return curTick() / SimClock::Int::ns; 283} 284 285void 286wakeCPU(ThreadContext *tc, uint64_t cpuid) 287{ 288 DPRINTF(PseudoInst, "PseudoInst::wakeCPU(%i)\n", cpuid); 289 System *sys = tc->getSystemPtr(); 290 291 if (sys->numContexts() <= cpuid) { 292 warn("PseudoInst::wakeCPU(%i), cpuid greater than number of contexts" 293 "(%i)\n",cpuid, sys->numContexts()); 294 return; 295 } 296 297 ThreadContext *other_tc = sys->threadContexts[cpuid]; 298 if (other_tc->status() == ThreadContext::Suspended) 299 other_tc->activate(); 300} 301 302void 303m5exit(ThreadContext *tc, Tick delay) 304{ 305 DPRINTF(PseudoInst, "PseudoInst::m5exit(%i)\n", delay); 306 if (DistIface::readyToExit(delay)) { 307 Tick when = curTick() + delay * SimClock::Int::ns; 308 exitSimLoop("m5_exit instruction encountered", 0, when, 0, true); 309 } 310} 311 312void 313m5fail(ThreadContext *tc, Tick delay, uint64_t code) 314{ 315 DPRINTF(PseudoInst, "PseudoInst::m5fail(%i, %i)\n", delay, code); 316 Tick when = curTick() + delay * SimClock::Int::ns; 317 exitSimLoop("m5_fail instruction encountered", code, when, 0, true); 318} 319 320void 321loadsymbol(ThreadContext *tc) 322{ 323 DPRINTF(PseudoInst, "PseudoInst::loadsymbol()\n"); 324 if (!FullSystem) 325 panicFsOnlyPseudoInst("loadsymbol"); 326 327 const string &filename = tc->getCpuPtr()->system->params()->symbolfile; 328 if (filename.empty()) { 329 return; 330 } 331 332 std::string buffer; 333 ifstream file(filename.c_str()); 334 335 if (!file) 336 fatal("file error: Can't open symbol table file %s\n", filename); 337 338 while (!file.eof()) { 339 getline(file, buffer); 340 341 if (buffer.empty()) 342 continue; 343 344 string::size_type idx = buffer.find(' '); 345 if (idx == string::npos) 346 continue; 347 348 string address = "0x" + buffer.substr(0, idx); 349 eat_white(address); 350 if (address.empty()) 351 continue; 352 353 // Skip over letter and space 354 string symbol = buffer.substr(idx + 3); 355 eat_white(symbol); 356 if (symbol.empty()) 357 continue; 358 359 Addr addr; 360 if (!to_number(address, addr)) 361 continue; 362 363 if (!tc->getSystemPtr()->kernelSymtab->insert(addr, symbol)) 364 continue; 365 366 367 DPRINTF(Loader, "Loaded symbol: %s @ %#llx\n", symbol, addr); 368 } 369 file.close(); 370} 371 372void 373addsymbol(ThreadContext *tc, Addr addr, Addr symbolAddr) 374{ 375 DPRINTF(PseudoInst, "PseudoInst::addsymbol(0x%x, 0x%x)\n", 376 addr, symbolAddr); 377 if (!FullSystem) 378 panicFsOnlyPseudoInst("addSymbol"); 379 380 char symb[100]; 381 CopyStringOut(tc, symb, symbolAddr, 100); 382 std::string symbol(symb); 383 384 DPRINTF(Loader, "Loaded symbol: %s @ %#llx\n", symbol, addr); 385 386 tc->getSystemPtr()->kernelSymtab->insert(addr,symbol); 387 debugSymbolTable->insert(addr,symbol); 388} 389 390uint64_t 391initParam(ThreadContext *tc, uint64_t key_str1, uint64_t key_str2) 392{ 393 DPRINTF(PseudoInst, "PseudoInst::initParam() key:%s%s\n", (char *)&key_str1, 394 (char *)&key_str2); 395 if (!FullSystem) { 396 panicFsOnlyPseudoInst("initParam"); 397 return 0; 398 } 399 400 // The key parameter string is passed in via two 64-bit registers. We copy 401 // out the characters from the 64-bit integer variables here and concatenate 402 // them in the key_str character buffer 403 const int len = 2 * sizeof(uint64_t) + 1; 404 char key_str[len]; 405 memset(key_str, '\0', len); 406 if (key_str1 == 0) { 407 assert(key_str2 == 0); 408 } else { 409 strncpy(key_str, (char *)&key_str1, sizeof(uint64_t)); 410 } 411 412 if (strlen(key_str) == sizeof(uint64_t)) { 413 strncpy(key_str + sizeof(uint64_t), (char *)&key_str2, 414 sizeof(uint64_t)); 415 } else { 416 assert(key_str2 == 0); 417 } 418 419 // Compare the key parameter with the known values to select the return 420 // value 421 uint64_t val; 422 if (strcmp(key_str, InitParamKey::DEFAULT) == 0) { 423 val = tc->getCpuPtr()->system->init_param; 424 } else if (strcmp(key_str, InitParamKey::DIST_RANK) == 0) { 425 val = DistIface::rankParam(); 426 } else if (strcmp(key_str, InitParamKey::DIST_SIZE) == 0) { 427 val = DistIface::sizeParam(); 428 } else { 429 panic("Unknown key for initparam pseudo instruction:\"%s\"", key_str); 430 } 431 return val; 432} 433 434 435void 436resetstats(ThreadContext *tc, Tick delay, Tick period) 437{ 438 DPRINTF(PseudoInst, "PseudoInst::resetstats(%i, %i)\n", delay, period); 439 if (!tc->getCpuPtr()->params()->do_statistics_insts) 440 return; 441 442 443 Tick when = curTick() + delay * SimClock::Int::ns; 444 Tick repeat = period * SimClock::Int::ns; 445 446 Stats::schedStatEvent(false, true, when, repeat); 447} 448 449void 450dumpstats(ThreadContext *tc, Tick delay, Tick period) 451{ 452 DPRINTF(PseudoInst, "PseudoInst::dumpstats(%i, %i)\n", delay, period); 453 if (!tc->getCpuPtr()->params()->do_statistics_insts) 454 return; 455 456 457 Tick when = curTick() + delay * SimClock::Int::ns; 458 Tick repeat = period * SimClock::Int::ns; 459 460 Stats::schedStatEvent(true, false, when, repeat); 461} 462 463void 464dumpresetstats(ThreadContext *tc, Tick delay, Tick period) 465{ 466 DPRINTF(PseudoInst, "PseudoInst::dumpresetstats(%i, %i)\n", delay, period); 467 if (!tc->getCpuPtr()->params()->do_statistics_insts) 468 return; 469 470 471 Tick when = curTick() + delay * SimClock::Int::ns; 472 Tick repeat = period * SimClock::Int::ns; 473 474 Stats::schedStatEvent(true, true, when, repeat); 475} 476 477void 478m5checkpoint(ThreadContext *tc, Tick delay, Tick period) 479{ 480 DPRINTF(PseudoInst, "PseudoInst::m5checkpoint(%i, %i)\n", delay, period); 481 if (!tc->getCpuPtr()->params()->do_checkpoint_insts) 482 return; 483 484 if (DistIface::readyToCkpt(delay, period)) { 485 Tick when = curTick() + delay * SimClock::Int::ns; 486 Tick repeat = period * SimClock::Int::ns; 487 exitSimLoop("checkpoint", 0, when, repeat); 488 } 489} 490 491uint64_t 492readfile(ThreadContext *tc, Addr vaddr, uint64_t len, uint64_t offset) 493{ 494 DPRINTF(PseudoInst, "PseudoInst::readfile(0x%x, 0x%x, 0x%x)\n", 495 vaddr, len, offset); 496 if (!FullSystem) { 497 panicFsOnlyPseudoInst("readfile"); 498 return 0; 499 } 500 501 const string &file = tc->getSystemPtr()->params()->readfile; 502 if (file.empty()) { 503 return ULL(0); 504 } 505 506 uint64_t result = 0; 507 508 int fd = ::open(file.c_str(), O_RDONLY, 0); 509 if (fd < 0) 510 panic("could not open file %s\n", file); 511 512 if (::lseek(fd, offset, SEEK_SET) < 0) 513 panic("could not seek: %s", strerror(errno)); 514 515 char *buf = new char[len]; 516 char *p = buf; 517 while (len > 0) { 518 int bytes = ::read(fd, p, len); 519 if (bytes <= 0) 520 break; 521 522 p += bytes; 523 result += bytes; 524 len -= bytes; 525 } 526 527 close(fd); 528 CopyIn(tc, vaddr, buf, result); 529 delete [] buf; 530 return result; 531} 532 533uint64_t 534writefile(ThreadContext *tc, Addr vaddr, uint64_t len, uint64_t offset, 535 Addr filename_addr) 536{ 537 DPRINTF(PseudoInst, "PseudoInst::writefile(0x%x, 0x%x, 0x%x, 0x%x)\n", 538 vaddr, len, offset, filename_addr); 539 540 // copy out target filename 541 char fn[100]; 542 std::string filename; 543 CopyStringOut(tc, fn, filename_addr, 100); 544 filename = std::string(fn); 545 546 OutputStream *out; 547 if (offset == 0) { 548 // create a new file (truncate) 549 out = simout.create(filename, true, true); 550 } else { 551 // do not truncate file if offset is non-zero 552 // (ios::in flag is required as well to keep the existing data 553 // intact, otherwise existing data will be zeroed out.) 554 out = simout.open(filename, ios::in | ios::out | ios::binary, true); 555 } 556 557 ostream *os(out->stream()); 558 if (!os) 559 panic("could not open file %s\n", filename); 560 561 // seek to offset 562 os->seekp(offset); 563 564 // copy out data and write to file 565 char *buf = new char[len]; 566 CopyOut(tc, buf, vaddr, len); 567 os->write(buf, len); 568 if (os->fail() || os->bad()) 569 panic("Error while doing writefile!\n"); 570 571 simout.close(out); 572 573 delete [] buf; 574 575 return len; 576} 577 578void 579debugbreak(ThreadContext *tc) 580{ 581 DPRINTF(PseudoInst, "PseudoInst::debugbreak()\n"); 582 Debug::breakpoint(); 583} 584 585void 586switchcpu(ThreadContext *tc) 587{ 588 DPRINTF(PseudoInst, "PseudoInst::switchcpu()\n"); 589 exitSimLoop("switchcpu"); 590} 591 592void 593togglesync(ThreadContext *tc) 594{ 595 DPRINTF(PseudoInst, "PseudoInst::togglesync()\n"); 596 DistIface::toggleSync(tc); 597} 598 599// 600// This function is executed when annotated work items begin. Depending on 601// what the user specified at the command line, the simulation may exit and/or 602// take a checkpoint when a certain work item begins. 603// 604void 605workbegin(ThreadContext *tc, uint64_t workid, uint64_t threadid) 606{ 607 DPRINTF(PseudoInst, "PseudoInst::workbegin(%i, %i)\n", workid, threadid); 608 System *sys = tc->getSystemPtr(); 609 const System::Params *params = sys->params(); 610 611 if (params->exit_on_work_items) { 612 exitSimLoop("workbegin", static_cast<int>(workid)); 613 return; 614 } 615 616 DPRINTF(WorkItems, "Work Begin workid: %d, threadid %d\n", workid, 617 threadid); 618 tc->getCpuPtr()->workItemBegin(); 619 sys->workItemBegin(threadid, workid); 620 621 // 622 // If specified, determine if this is the specific work item the user 623 // identified 624 // 625 if (params->work_item_id == -1 || params->work_item_id == workid) { 626 627 uint64_t systemWorkBeginCount = sys->incWorkItemsBegin(); 628 int cpuId = tc->getCpuPtr()->cpuId(); 629 630 if (params->work_cpus_ckpt_count != 0 && 631 sys->markWorkItem(cpuId) >= params->work_cpus_ckpt_count) { 632 // 633 // If active cpus equals checkpoint count, create checkpoint 634 // 635 exitSimLoop("checkpoint"); 636 } 637 638 if (systemWorkBeginCount == params->work_begin_ckpt_count) { 639 // 640 // Note: the string specified as the cause of the exit event must 641 // exactly equal "checkpoint" inorder to create a checkpoint 642 // 643 exitSimLoop("checkpoint"); 644 } 645 646 if (systemWorkBeginCount == params->work_begin_exit_count) { 647 // 648 // If a certain number of work items started, exit simulation 649 // 650 exitSimLoop("work started count reach"); 651 } 652 653 if (cpuId == params->work_begin_cpu_id_exit) { 654 // 655 // If work started on the cpu id specified, exit simulation 656 // 657 exitSimLoop("work started on specific cpu"); 658 } 659 } 660} 661 662// 663// This function is executed when annotated work items end. Depending on 664// what the user specified at the command line, the simulation may exit and/or 665// take a checkpoint when a certain work item ends. 666// 667void 668workend(ThreadContext *tc, uint64_t workid, uint64_t threadid) 669{ 670 DPRINTF(PseudoInst, "PseudoInst::workend(%i, %i)\n", workid, threadid); 671 System *sys = tc->getSystemPtr(); 672 const System::Params *params = sys->params(); 673 674 if (params->exit_on_work_items) { 675 exitSimLoop("workend", static_cast<int>(workid)); 676 return; 677 } 678 679 DPRINTF(WorkItems, "Work End workid: %d, threadid %d\n", workid, threadid); 680 tc->getCpuPtr()->workItemEnd(); 681 sys->workItemEnd(threadid, workid); 682 683 // 684 // If specified, determine if this is the specific work item the user 685 // identified 686 // 687 if (params->work_item_id == -1 || params->work_item_id == workid) { 688 689 uint64_t systemWorkEndCount = sys->incWorkItemsEnd(); 690 int cpuId = tc->getCpuPtr()->cpuId(); 691 692 if (params->work_cpus_ckpt_count != 0 && 693 sys->markWorkItem(cpuId) >= params->work_cpus_ckpt_count) { 694 // 695 // If active cpus equals checkpoint count, create checkpoint 696 // 697 exitSimLoop("checkpoint"); 698 } 699 700 if (params->work_end_ckpt_count != 0 && 701 systemWorkEndCount == params->work_end_ckpt_count) { 702 // 703 // If total work items completed equals checkpoint count, create 704 // checkpoint 705 // 706 exitSimLoop("checkpoint"); 707 } 708 709 if (params->work_end_exit_count != 0 && 710 systemWorkEndCount == params->work_end_exit_count) { 711 // 712 // If total work items completed equals exit count, exit simulation 713 // 714 exitSimLoop("work items exit count reached"); 715 } 716 } 717} 718 719} // namespace PseudoInst
|