X-Git-Url: https://git.saurik.com/apple/libpthread.git/blobdiff_plain/215aeb0310146fee62c0f2602966571180f8eb63..c6e5f90c4dd303939f631da331df7b356da942e6:/kern/workqueue_internal.h diff --git a/kern/workqueue_internal.h b/kern/workqueue_internal.h index cad0b50..c044fe7 100644 --- a/kern/workqueue_internal.h +++ b/kern/workqueue_internal.h @@ -33,127 +33,18 @@ * duplicate definitions that used to exist in both projects, when separate. */ -/* workq_kernreturn commands */ -#define WQOPS_THREAD_RETURN 4 -#define WQOPS_QUEUE_NEWSPISUPP 0x10 /* this is to check for newer SPI support */ -#define WQOPS_QUEUE_REQTHREADS 0x20 /* request number of threads of a prio */ -#define WQOPS_QUEUE_REQTHREADS2 0x30 /* request a number of threads in a given priority bucket */ - -/* flag values for reuse field in the libc side _pthread_wqthread */ -#define WQ_FLAG_THREAD_PRIOMASK 0x0000ffff -#define WQ_FLAG_THREAD_PRIOSHIFT (8ull) -#define WQ_FLAG_THREAD_OVERCOMMIT 0x00010000 /* thread is with overcommit prio */ -#define WQ_FLAG_THREAD_REUSE 0x00020000 /* thread is being reused */ -#define WQ_FLAG_THREAD_NEWSPI 0x00040000 /* the call is with new SPIs */ - -/* These definitions are only available to the kext, to avoid bleeding constants and types across the boundary to - * the userspace library. - */ -#ifdef KERNEL - -/* These defines come from kern/thread.h but are XNU_KERNEL_PRIVATE so do not get - * exported to kernel extensions. - */ -#define SCHED_CALL_BLOCK 0x1 -#define SCHED_CALL_UNBLOCK 0x2 - -// kwe_state -enum { - KWE_THREAD_INWAIT = 1, - KWE_THREAD_PREPOST, - KWE_THREAD_BROADCAST, -}; - -/* old workq priority scheme */ - -#define WORKQUEUE_HIGH_PRIOQUEUE 0 /* high priority queue */ -#define WORKQUEUE_DEFAULT_PRIOQUEUE 1 /* default priority queue */ -#define WORKQUEUE_LOW_PRIOQUEUE 2 /* low priority queue */ -#define WORKQUEUE_BG_PRIOQUEUE 3 /* background priority queue */ - -#define WORKQUEUE_NUM_BUCKETS 6 - -/* wq_max_constrained_threads = max(64, N_CPU * WORKQUEUE_CONSTRAINED_FACTOR) - * This used to be WORKQUEUE_NUM_BUCKETS + 1 when NUM_BUCKETS was 4, yielding - * N_CPU * 5. When NUM_BUCKETS changed, we decided that the limit should - * not change. So the factor is now always 5. - */ -#define WORKQUEUE_CONSTRAINED_FACTOR 5 - -#define WORKQUEUE_OVERCOMMIT 0x10000 - -struct threadlist { - TAILQ_ENTRY(threadlist) th_entry; - thread_t th_thread; - int th_flags; - uint8_t th_priority; - uint8_t th_policy; - struct workqueue *th_workq; - mach_vm_size_t th_stacksize; - mach_vm_size_t th_allocsize; - mach_vm_offset_t th_stackaddr; - mach_port_name_t th_thport; -}; -#define TH_LIST_INITED 0x01 -#define TH_LIST_RUNNING 0x02 -#define TH_LIST_BLOCKED 0x04 -#define TH_LIST_SUSPENDED 0x08 -#define TH_LIST_BUSY 0x10 -#define TH_LIST_NEED_WAKEUP 0x20 -#define TH_LIST_CONSTRAINED 0x40 - - -struct workqueue { - proc_t wq_proc; - vm_map_t wq_map; - task_t wq_task; - thread_call_t wq_atimer_call; - int wq_flags; - int wq_lflags; - uint64_t wq_thread_yielded_timestamp; - uint32_t wq_thread_yielded_count; - uint32_t wq_timer_interval; - uint32_t wq_max_concurrency; - uint32_t wq_threads_scheduled; - uint32_t wq_constrained_threads_scheduled; - uint32_t wq_nthreads; - uint32_t wq_thidlecount; - uint32_t wq_reqcount; - TAILQ_HEAD(, threadlist) wq_thrunlist; - TAILQ_HEAD(, threadlist) wq_thidlelist; - uint16_t wq_requests[WORKQUEUE_NUM_BUCKETS]; - uint16_t wq_ocrequests[WORKQUEUE_NUM_BUCKETS]; - uint16_t wq_reqconc[WORKQUEUE_NUM_BUCKETS]; /* requested concurrency for each priority level */ - uint16_t wq_thscheduled_count[WORKQUEUE_NUM_BUCKETS]; - uint32_t wq_thactive_count[WORKQUEUE_NUM_BUCKETS] __attribute__((aligned(4))); /* must be uint32_t since we OSAddAtomic on these */ - uint64_t wq_lastblocked_ts[WORKQUEUE_NUM_BUCKETS] __attribute__((aligned(8))); -}; -#define WQ_LIST_INITED 0x01 -#define WQ_ATIMER_RUNNING 0x02 -#define WQ_EXITING 0x04 - -#define WQL_ATIMER_BUSY 0x01 -#define WQL_ATIMER_WAITING 0x02 -#define WQL_EXCEEDED_CONSTRAINED_THREAD_LIMIT 0x04 -#define WQL_EXCEEDED_TOTAL_THREAD_LIMIT 0x08 - - -#define WQ_VECT_SET_BIT(vector, bit) \ - vector[(bit) / 32] |= (1 << ((bit) % 32)) - -#define WQ_VECT_CLEAR_BIT(vector, bit) \ - vector[(bit) / 32] &= ~(1 << ((bit) % 32)) - -#define WQ_VECT_TEST_BIT(vector, bit) \ - vector[(bit) / 32] & (1 << ((bit) % 32)) - -#define WORKQUEUE_MAXTHREADS 512 -#define WQ_YIELDED_THRESHOLD 2000 -#define WQ_YIELDED_WINDOW_USECS 30000 -#define WQ_STALLED_WINDOW_USECS 200 -#define WQ_REDUCE_POOL_WINDOW_USECS 5000000 -#define WQ_MAX_TIMER_INTERVAL_USECS 50000 - -#endif // KERNEL +// Sometimes something gets passed a bucket number and we need a way to express +// that it's actually the event manager. Use the (0)th bucket for that. +#define WORKQ_THREAD_QOS_MIN (THREAD_QOS_MAINTENANCE) +#define WORKQ_THREAD_QOS_MAX (THREAD_QOS_LAST - 1) +#define WORKQ_THREAD_QOS_CLEANUP (THREAD_QOS_LEGACY) +#define WORKQ_THREAD_QOS_MANAGER (THREAD_QOS_LAST) // outside of MIN/MAX + +#define WORKQ_NUM_QOS_BUCKETS (WORKQ_THREAD_QOS_MAX) +#define WORKQ_NUM_BUCKETS (WORKQ_THREAD_QOS_MAX + 1) +#define WORKQ_IDX(qos) ((qos) - 1) // 0 based index + +// magical `nkevents` values for _pthread_wqthread +#define WORKQ_EXIT_THREAD_NKEVENT (-1) #endif // _WORKQUEUE_INTERNAL_H_