scheduler.cc 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include "scheduler.h"
  2. #include "scheduler_static.h"
  3. #include "scheduler_pinned.h"
  4. #include "scheduler_roaming.h"
  5. #include "scheduler_big_small.h"
  6. #include "simulator.h"
  7. #include "config.hpp"
  8. #include "core_manager.h"
  9. #include "thread_manager.h"
  10. #include "thread.h"
  11. Scheduler* Scheduler::create(ThreadManager *thread_manager)
  12. {
  13. String type = Sim()->getCfg()->getString("scheduler/type");
  14. if (type == "static")
  15. return new SchedulerStatic(thread_manager);
  16. else if (type == "pinned")
  17. return new SchedulerPinned(thread_manager);
  18. else if (type == "roaming")
  19. return new SchedulerRoaming(thread_manager);
  20. else if (type == "big_small")
  21. return new SchedulerBigSmall(thread_manager);
  22. else
  23. LOG_PRINT_ERROR("Unknown scheduler type %s", type.c_str());
  24. }
  25. Scheduler::Scheduler(ThreadManager *thread_manager)
  26. : m_thread_manager(thread_manager)
  27. {
  28. }
  29. core_id_t Scheduler::findFirstFreeCore()
  30. {
  31. for (core_id_t core_id = 0; core_id < (core_id_t)Sim()->getConfig()->getApplicationCores(); core_id++)
  32. {
  33. if (Sim()->getCoreManager()->getCoreFromID(core_id)->getState() == Core::IDLE)
  34. {
  35. return core_id;
  36. }
  37. }
  38. return INVALID_CORE_ID;
  39. }
  40. void Scheduler::printMapping()
  41. {
  42. // Print mapping
  43. for (core_id_t core_id = 0; core_id < (core_id_t)Sim()->getConfig()->getApplicationCores(); core_id++)
  44. {
  45. if (Sim()->getCoreManager()->getCoreFromID(core_id)->getState() != Core::IDLE)
  46. {
  47. char state;
  48. switch(Sim()->getThreadManager()->getThreadState(Sim()->getCoreManager()->getCoreFromID(core_id)->getThread()->getId() ))
  49. {
  50. case Core::INITIALIZING:
  51. state = 'I';
  52. break;
  53. case Core::RUNNING:
  54. state = 'R';
  55. break;
  56. case Core::STALLED:
  57. state = 'S';
  58. break;
  59. case Core::SLEEPING:
  60. state = 's';
  61. break;
  62. case Core::WAKING_UP:
  63. state = 'W';
  64. break;
  65. case Core::IDLE:
  66. state = 'i';
  67. break;
  68. case Core::BROKEN:
  69. state = 'B';
  70. break;
  71. case Core::NUM_STATES:
  72. default:
  73. state = '?';
  74. break;
  75. }
  76. std::cout << "( t" << Sim()->getCoreManager()->getCoreFromID(core_id)->getThread()->getId() << "@c" << core_id << "[" << state << "])" ;
  77. }
  78. else
  79. {
  80. std::cout << "( tx" << "@c" << core_id << "[i])";
  81. }
  82. }
  83. std::cout << std::endl;
  84. }