ThreadPoolDataStructures.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #pragma once
  2. #if NET_4_0
  3. #include <vector>
  4. #include "os/ConditionVariable.h"
  5. #include "os/Mutex.h"
  6. struct Il2CppDomain;
  7. struct Il2CppInternalThread;
  8. union ThreadPoolCounter
  9. {
  10. struct
  11. {
  12. int16_t max_working; /* determined by heuristic */
  13. int16_t active; /* executing worker_thread */
  14. int16_t working; /* actively executing worker_thread, not parked */
  15. int16_t parked; /* parked */
  16. } _;
  17. int64_t as_int64_t;
  18. };
  19. struct ThreadPoolDomain
  20. {
  21. Il2CppDomain* domain;
  22. int32_t outstanding_request;
  23. };
  24. struct ThreadPoolHillClimbing
  25. {
  26. int32_t wave_period;
  27. int32_t samples_to_measure;
  28. double target_throughput_ratio;
  29. double target_signal_to_noise_ratio;
  30. double max_change_per_second;
  31. double max_change_per_sample;
  32. int32_t max_thread_wave_magnitude;
  33. int32_t sample_interval_low;
  34. double thread_magnitude_multiplier;
  35. int32_t sample_interval_high;
  36. double throughput_error_smoothing_factor;
  37. double gain_exponent;
  38. double max_sample_error;
  39. double current_control_setting;
  40. int64_t total_samples;
  41. int16_t last_thread_count;
  42. double elapsed_since_last_change;
  43. double completions_since_last_change;
  44. double average_throughput_noise;
  45. double *samples;
  46. double *thread_counts;
  47. uint32_t current_sample_interval;
  48. void* random_interval_generator;
  49. int32_t accumulated_completion_count;
  50. double accumulated_sample_duration;
  51. };
  52. struct ThreadPool
  53. {
  54. ThreadPool();
  55. ThreadPoolCounter counters;
  56. std::vector<ThreadPoolDomain*> domains;
  57. il2cpp::os::FastMutex domains_lock;
  58. std::vector<Il2CppInternalThread*> working_threads;
  59. int32_t parked_threads_count;
  60. il2cpp::os::ConditionVariable parked_threads_cond;
  61. il2cpp::os::FastMutex active_threads_lock; /* protect access to working_threads and parked_threads */
  62. uint32_t worker_creation_current_second;
  63. uint32_t worker_creation_current_count;
  64. il2cpp::os::FastMutex worker_creation_lock;
  65. int32_t heuristic_completions;
  66. int64_t heuristic_sample_start;
  67. int64_t heuristic_last_dequeue; // ms
  68. int64_t heuristic_last_adjustment; // ms
  69. int64_t heuristic_adjustment_interval; // ms
  70. ThreadPoolHillClimbing heuristic_hill_climbing;
  71. il2cpp::os::Mutex heuristic_lock;
  72. int32_t limit_worker_min;
  73. int32_t limit_worker_max;
  74. int32_t limit_io_min;
  75. int32_t limit_io_max;
  76. void* cpu_usage_state;
  77. int32_t cpu_usage;
  78. /* suspended by the debugger */
  79. bool suspended;
  80. };
  81. enum ThreadPoolHeuristicStateTransition
  82. {
  83. TRANSITION_WARMUP,
  84. TRANSITION_INITIALIZING,
  85. TRANSITION_RANDOM_MOVE,
  86. TRANSITION_CLIMBING_MOVE,
  87. TRANSITION_CHANGE_POINT,
  88. TRANSITION_STABILIZING,
  89. TRANSITION_STARVATION,
  90. TRANSITION_THREAD_TIMED_OUT,
  91. TRANSITION_UNDEFINED,
  92. };
  93. #endif // NET_4_0