scheduler_static.cc 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "scheduler_static.h"
  2. #include "core_manager.h"
  3. #include "simulator.h"
  4. #include "config.hpp"
  5. #include "thread.h"
  6. #include "log.h"
  7. SchedulerStatic::SchedulerStatic(ThreadManager *thread_manager)
  8. : Scheduler(thread_manager)
  9. {
  10. m_core_mask.resize(Sim()->getConfig()->getApplicationCores());
  11. for (core_id_t core_id = 0; core_id < (core_id_t)Sim()->getConfig()->getApplicationCores(); core_id++)
  12. {
  13. m_core_mask[core_id] = Sim()->getCfg()->getBoolArray("scheduler/static/core_mask", core_id);
  14. }
  15. }
  16. core_id_t SchedulerStatic::findFirstFreeMaskedCore()
  17. {
  18. for (core_id_t core_id = 0; core_id < (core_id_t)Sim()->getConfig()->getApplicationCores(); core_id++)
  19. {
  20. if (m_core_mask[core_id] && Sim()->getCoreManager()->getCoreFromID(core_id)->getState() == Core::IDLE)
  21. {
  22. return core_id;
  23. }
  24. }
  25. return INVALID_CORE_ID;
  26. }
  27. core_id_t SchedulerStatic::threadCreate(thread_id_t thread_id)
  28. {
  29. core_id_t core_id = findFirstFreeMaskedCore();
  30. LOG_ASSERT_ERROR(core_id != INVALID_CORE_ID, "No cores available for spawnThread request.");
  31. app_id_t app_id = Sim()->getThreadManager()->getThreadFromID(thread_id)->getAppId();
  32. LOG_PRINT("Scheduler: thread %d from application %d now scheduled to core %d", thread_id, app_id, core_id);
  33. return core_id;
  34. }