scheduler_dynamic.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #ifndef __SCHEDULER_DYNAMIC_H
  2. #define __SCHEDULER_DYNAMIC_H
  3. #include "scheduler.h"
  4. #include "hooks_manager.h"
  5. #include <vector>
  6. class SchedulerDynamic : public Scheduler
  7. {
  8. public:
  9. SchedulerDynamic(ThreadManager *thread_manager);
  10. virtual ~SchedulerDynamic();
  11. virtual core_id_t threadCreate(thread_id_t) = 0;
  12. virtual void periodic(SubsecondTime time) {}
  13. virtual void threadStart(thread_id_t thread_id, SubsecondTime time) {}
  14. virtual void threadStall(thread_id_t thread_id, ThreadManager::stall_type_t reason, SubsecondTime time) {}
  15. virtual void threadResume(thread_id_t thread_id, thread_id_t thread_by, SubsecondTime time) {}
  16. virtual void threadExit(thread_id_t thread_id, SubsecondTime time) {}
  17. protected:
  18. std::vector<bool> m_threads_runnable;
  19. void moveThread(thread_id_t thread_id, core_id_t core_id, SubsecondTime time);
  20. private:
  21. bool m_in_periodic;
  22. void __periodic(SubsecondTime time);
  23. void __roi_begin();
  24. void __roi_end();
  25. void __threadStart(thread_id_t thread_id, SubsecondTime time);
  26. void __threadStall(thread_id_t thread_id, ThreadManager::stall_type_t reason, SubsecondTime time);
  27. void __threadResume(thread_id_t thread_id, thread_id_t thread_by, SubsecondTime time);
  28. void __threadExit(thread_id_t thread_id, SubsecondTime time);
  29. // Hook stubs
  30. static SInt64 hook_periodic(UInt64 ptr, UInt64 time)
  31. { ((SchedulerDynamic*)ptr)->__periodic(*(subsecond_time_t*)&time); return 0; }
  32. static SInt64 hook_thread_start(UInt64 ptr, UInt64 _args)
  33. {
  34. HooksManager::ThreadTime *args = (HooksManager::ThreadTime *)_args;
  35. ((SchedulerDynamic*)ptr)->__threadStart(args->thread_id, args->time);
  36. return 0;
  37. }
  38. static SInt64 hook_thread_stall(UInt64 ptr, UInt64 _args)
  39. {
  40. HooksManager::ThreadStall *args = (HooksManager::ThreadStall *)_args;
  41. ((SchedulerDynamic*)ptr)->__threadStall(args->thread_id, args->reason, args->time);
  42. return 0;
  43. }
  44. static SInt64 hook_thread_resume(UInt64 ptr, UInt64 _args)
  45. {
  46. HooksManager::ThreadResume *args = (HooksManager::ThreadResume *)_args;
  47. ((SchedulerDynamic*)ptr)->__threadResume(args->thread_id, args->thread_by, args->time);
  48. return 0;
  49. }
  50. static SInt64 hook_thread_exit(UInt64 ptr, UInt64 _args)
  51. {
  52. HooksManager::ThreadTime *args = (HooksManager::ThreadTime *)_args;
  53. ((SchedulerDynamic*)ptr)->__threadExit(args->thread_id, args->time);
  54. return 0;
  55. }
  56. };
  57. #endif // __SCHEDULER_DYNAMIC_H