[add] first
This commit is contained in:
		| @@ -0,0 +1,116 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include <vector> | ||||
|  | ||||
| #include "Baselib.h" | ||||
| #include "Cpp/Atomic.h" | ||||
| #include "Cpp/ReentrantLock.h" | ||||
| #include "Cpp/ConditionVariable.h" | ||||
|  | ||||
| #include "os/Mutex.h" | ||||
|  | ||||
| struct Il2CppDomain; | ||||
| struct Il2CppInternalThread; | ||||
|  | ||||
| union ThreadPoolCounter | ||||
| { | ||||
|     struct | ||||
|     { | ||||
|         int16_t max_working; /* determined by heuristic */ | ||||
|         int16_t active; /* executing worker_thread */ | ||||
|         int16_t working; /* actively executing worker_thread, not parked */ | ||||
|         int16_t parked; /* parked */ | ||||
|     } _; | ||||
|     int64_t as_int64_t; | ||||
| }; | ||||
|  | ||||
| struct ThreadPoolDomain | ||||
| { | ||||
|     Il2CppDomain* domain; | ||||
|     int32_t outstanding_request; | ||||
| }; | ||||
|  | ||||
| struct ThreadPoolHillClimbing | ||||
| { | ||||
|     int32_t wave_period; | ||||
|     int32_t samples_to_measure; | ||||
|     double target_throughput_ratio; | ||||
|     double target_signal_to_noise_ratio; | ||||
|     double max_change_per_second; | ||||
|     double max_change_per_sample; | ||||
|     int32_t max_thread_wave_magnitude; | ||||
|     int32_t sample_interval_low; | ||||
|     double thread_magnitude_multiplier; | ||||
|     int32_t sample_interval_high; | ||||
|     double throughput_error_smoothing_factor; | ||||
|     double gain_exponent; | ||||
|     double max_sample_error; | ||||
|  | ||||
|     double current_control_setting; | ||||
|     int64_t total_samples; | ||||
|     int16_t last_thread_count; | ||||
|     double elapsed_since_last_change; | ||||
|     double completions_since_last_change; | ||||
|  | ||||
|     double average_throughput_noise; | ||||
|  | ||||
|     double *samples; | ||||
|     double *thread_counts; | ||||
|  | ||||
|     uint32_t current_sample_interval; | ||||
|     void* random_interval_generator; | ||||
|  | ||||
|     int32_t accumulated_completion_count; | ||||
|     double accumulated_sample_duration; | ||||
| }; | ||||
|  | ||||
| struct ThreadPool | ||||
| { | ||||
|     ThreadPool(); | ||||
|  | ||||
|     ThreadPoolCounter counters; | ||||
|  | ||||
|     std::vector<ThreadPoolDomain*> domains; | ||||
|     baselib::ReentrantLock domains_lock; | ||||
|  | ||||
|     std::vector<Il2CppInternalThread*> working_threads; | ||||
|     int32_t parked_threads_count; | ||||
|     baselib::ConditionVariable parked_threads_cond; | ||||
|     baselib::Lock active_threads_lock; /* protect access to working_threads and parked_threads */ | ||||
|  | ||||
|     uint32_t worker_creation_current_second; | ||||
|     uint32_t worker_creation_current_count; | ||||
|     baselib::ReentrantLock worker_creation_lock; | ||||
|  | ||||
|     baselib::atomic<int32_t> heuristic_completions; | ||||
|     int64_t heuristic_sample_start; | ||||
|     int64_t heuristic_last_dequeue; // ms | ||||
|     int64_t heuristic_last_adjustment; // ms | ||||
|     int64_t heuristic_adjustment_interval; // ms | ||||
|     ThreadPoolHillClimbing heuristic_hill_climbing; | ||||
|     baselib::ReentrantLock heuristic_lock; | ||||
|  | ||||
|     int32_t limit_worker_min; | ||||
|     int32_t limit_worker_max; | ||||
|     int32_t limit_io_min; | ||||
|     int32_t limit_io_max; | ||||
|  | ||||
|     void* cpu_usage_state; | ||||
|     int32_t cpu_usage; | ||||
|  | ||||
|     /* suspended by the debugger */ | ||||
|     bool suspended; | ||||
| }; | ||||
|  | ||||
| enum ThreadPoolHeuristicStateTransition | ||||
| { | ||||
|     TRANSITION_WARMUP, | ||||
|     TRANSITION_INITIALIZING, | ||||
|     TRANSITION_RANDOM_MOVE, | ||||
|     TRANSITION_CLIMBING_MOVE, | ||||
|     TRANSITION_CHANGE_POINT, | ||||
|     TRANSITION_STABILIZING, | ||||
|     TRANSITION_STARVATION, | ||||
|     TRANSITION_THREAD_TIMED_OUT, | ||||
|     TRANSITION_UNDEFINED, | ||||
| }; | ||||
| @@ -0,0 +1,27 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include "os/Atomic.h" | ||||
|  | ||||
| #define COUNTER_CHECK(counter) \ | ||||
|     do { \ | ||||
|         IL2CPP_ASSERT(counter._.max_working > 0); \ | ||||
|         IL2CPP_ASSERT(counter._.working >= 0); \ | ||||
|         IL2CPP_ASSERT(counter._.active >= 0); \ | ||||
|     } while (0) | ||||
|  | ||||
| #define COUNTER_READ() (il2cpp::os::Atomic::Read64 (&g_ThreadPool->counters.as_int64_t)) | ||||
|  | ||||
| #define COUNTER_ATOMIC(var, block) \ | ||||
|     do { \ | ||||
|         ThreadPoolCounter __old; \ | ||||
|         do { \ | ||||
|             IL2CPP_ASSERT(g_ThreadPool); \ | ||||
|             __old.as_int64_t = COUNTER_READ (); \ | ||||
|             (var) = __old; \ | ||||
|             { block; } \ | ||||
|             COUNTER_CHECK (var); \ | ||||
|         } while (il2cpp::os::Atomic::CompareExchange64 (&g_ThreadPool->counters.as_int64_t, (var).as_int64_t, __old.as_int64_t) != __old.as_int64_t); \ | ||||
|     } while (0) | ||||
|  | ||||
| #define CPU_USAGE_LOW 80 | ||||
| #define CPU_USAGE_HIGH 95 | ||||
| @@ -0,0 +1,11 @@ | ||||
| #pragma once | ||||
|  | ||||
| enum MonitorStatus | ||||
| { | ||||
|     MONITOR_STATUS_REQUESTED, | ||||
|     MONITOR_STATUS_WAITING_FOR_REQUEST, | ||||
|     MONITOR_STATUS_NOT_RUNNING, | ||||
| }; | ||||
|  | ||||
| void monitor_ensure_running(); | ||||
| MonitorStatus GetMonitorStatus(); | ||||
| @@ -0,0 +1,3 @@ | ||||
| #pragma once | ||||
|  | ||||
| bool worker_try_create(); | ||||
| @@ -0,0 +1,19 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include "il2cpp-config.h" | ||||
|  | ||||
| bool poll_init(int wakeup_pipe_fd); | ||||
|  | ||||
| void poll_register_fd(int fd, int events, bool is_new); | ||||
|  | ||||
| int poll_event_wait(void(*callback)(int fd, int events, void* user_data), void* user_data); | ||||
|  | ||||
| void poll_remove_fd(int fd); | ||||
|  | ||||
| /* Keep in sync with System.IOOperation in mcs/class/System/System/IOSelector.cs */ | ||||
| enum Il2CppIOOperation | ||||
| { | ||||
|     EVENT_IN = 1 << 0, | ||||
|     EVENT_OUT = 1 << 1, | ||||
|     EVENT_ERR = 1 << 2, /* not in managed */ | ||||
| }; | ||||
| @@ -0,0 +1,13 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include "il2cpp-config.h" | ||||
| #include "il2cpp-object-internals.h" | ||||
|  | ||||
| struct Il2CppIOSelectorJob; | ||||
|  | ||||
| void threadpool_ms_io_remove_socket(int fd); | ||||
| //void mono_threadpool_ms_io_remove_domain_jobs (MonoDomain *domain); | ||||
| void threadpool_ms_io_cleanup(void); | ||||
|  | ||||
| LIBIL2CPP_CODEGEN_API void ves_icall_System_IOSelector_Add(intptr_t handle, Il2CppIOSelectorJob *job); | ||||
| LIBIL2CPP_CODEGEN_API void ves_icall_System_IOSelector_Remove(intptr_t handle); | ||||
							
								
								
									
										43
									
								
								Libraries/libil2cpp/include/mono/ThreadPool/threadpool-ms.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								Libraries/libil2cpp/include/mono/ThreadPool/threadpool-ms.h
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,43 @@ | ||||
| #pragma once | ||||
|  | ||||
| #include "il2cpp-config.h" | ||||
| #include "mono/ThreadPool/ThreadPoolDataStructures.h" | ||||
|  | ||||
| struct Il2CppObject; | ||||
| struct Il2CppDomain; | ||||
| struct Il2CppArray; | ||||
| struct Il2CppAsyncResult; | ||||
| struct MethodInfo; | ||||
| struct Il2CppNativeOverlapped; | ||||
|  | ||||
| #define SMALL_STACK (sizeof (void*) * 32 * 1024) | ||||
|  | ||||
| void threadpool_ms_cleanup(void); | ||||
|  | ||||
| Il2CppAsyncResult * threadpool_ms_begin_invoke(Il2CppDomain *domain, Il2CppObject *target, MethodInfo *method, void* *params); | ||||
| Il2CppObject * threadpool_ms_end_invoke(Il2CppAsyncResult *ares, Il2CppArray **out_args, Il2CppObject **exc); | ||||
|  | ||||
| void threadpool_ms_suspend(void); | ||||
| void threadpool_ms_resume(void); | ||||
|  | ||||
| LIBIL2CPP_CODEGEN_API void ves_icall_System_Threading_ThreadPool_GetAvailableThreadsNative(int32_t *worker_threads, int32_t *completion_port_threads); | ||||
| LIBIL2CPP_CODEGEN_API void ves_icall_System_Threading_ThreadPool_GetMinThreadsNative(int32_t *worker_threads, int32_t *completion_port_threads); | ||||
| LIBIL2CPP_CODEGEN_API void ves_icall_System_Threading_ThreadPool_GetMaxThreadsNative(int32_t *worker_threads, int32_t *completion_port_threads); | ||||
| LIBIL2CPP_CODEGEN_API bool ves_icall_System_Threading_ThreadPool_SetMinThreadsNative(int32_t worker_threads, int32_t completion_port_threads); | ||||
| LIBIL2CPP_CODEGEN_API bool ves_icall_System_Threading_ThreadPool_SetMaxThreadsNative(int32_t worker_threads, int32_t completion_port_threads); | ||||
| LIBIL2CPP_CODEGEN_API void ves_icall_System_Threading_ThreadPool_InitializeVMTp(bool *enable_worker_tracking); | ||||
| LIBIL2CPP_CODEGEN_API bool ves_icall_System_Threading_ThreadPool_NotifyWorkItemComplete(void); | ||||
| LIBIL2CPP_CODEGEN_API void ves_icall_System_Threading_ThreadPool_NotifyWorkItemProgressNative(void); | ||||
| LIBIL2CPP_CODEGEN_API void ves_icall_System_Threading_ThreadPool_ReportThreadStatus(bool is_working); | ||||
| LIBIL2CPP_CODEGEN_API bool ves_icall_System_Threading_ThreadPool_RequestWorkerThread(void); | ||||
| LIBIL2CPP_CODEGEN_API bool ves_icall_System_Threading_ThreadPool_PostQueuedCompletionStatus(Il2CppNativeOverlapped *native_overlapped); | ||||
| LIBIL2CPP_CODEGEN_API bool ves_icall_System_Threading_ThreadPool_BindIOCompletionCallbackNative(void* file_handle); | ||||
| LIBIL2CPP_CODEGEN_API bool ves_icall_System_Threading_ThreadPool_IsThreadPoolHosted(void); | ||||
| LIBIL2CPP_CODEGEN_API void ves_icall_System_Threading_ThreadPool_NotifyWorkItemQueued(void); | ||||
|  | ||||
| /* Internals */ | ||||
| bool threadpool_ms_enqueue_work_item(Il2CppDomain *domain, Il2CppObject *work_item); | ||||
|  | ||||
| extern ::ThreadPool* g_ThreadPool; | ||||
| bool worker_try_unpark(); | ||||
| void hill_climbing_force_change(int16_t new_thread_count, ThreadPoolHeuristicStateTransition transition); | ||||
		Reference in New Issue
	
	Block a user