core_thread.cc 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #include "core_thread.h"
  2. #include "core_manager.h"
  3. #include "performance_model.h"
  4. #include "log.h"
  5. #include "simulator.h"
  6. #include "core.h"
  7. #include "sim_thread_manager.h"
  8. #include "sim_api.h"
  9. #include <unistd.h>
  10. CoreThread::CoreThread()
  11. : m_thread(NULL)
  12. {
  13. }
  14. CoreThread::~CoreThread()
  15. {
  16. delete m_thread;
  17. }
  18. void CoreThread::run()
  19. {
  20. core_id_t core_id = Sim()->getCoreManager()->registerSimThread(CoreManager::CORE_THREAD);
  21. // Set thread name for Sniper-in-Sniper simulations
  22. String threadName = String("core-") + itostr(core_id);
  23. SimSetThreadName(threadName.c_str());
  24. LOG_PRINT("Core thread starting...");
  25. Network *net = Sim()->getCoreManager()->getCoreFromID(core_id)->getNetwork();
  26. volatile bool cont = true;
  27. Sim()->getSimThreadManager()->simThreadStartCallback();
  28. // Turn off cont when we receive a quit message
  29. net->registerCallback(CORE_THREAD_TERMINATE_THREADS,
  30. terminateFunc,
  31. (void *)&cont);
  32. PerformanceModel *prfmdl = Sim()->getCoreManager()->getCurrentCore()->getPerformanceModel();
  33. while (cont) {
  34. prfmdl->iterate();
  35. usleep(1000); // Reduce system load while there's nothing to do (outside ROI)
  36. }
  37. Sim()->getSimThreadManager()->simThreadExitCallback();
  38. LOG_PRINT("Core thread exiting");
  39. }
  40. void CoreThread::spawn()
  41. {
  42. m_thread = _Thread::create(this);
  43. m_thread->run();
  44. }
  45. void CoreThread::terminateFunc(void *vp, NetPacket pkt)
  46. {
  47. bool *pcont = (bool*) vp;
  48. *pcont = false;
  49. }