xref: /xnu-8020.121.3/bsd/pthread/workqueue_syscalls.h (revision fdd8201d7b966f0c3ea610489d29bd841d358941)
1*fdd8201dSApple OSS Distributions /*
2*fdd8201dSApple OSS Distributions  * Copyright (c) 2017 Apple, Inc. All rights reserved.
3*fdd8201dSApple OSS Distributions  *
4*fdd8201dSApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5*fdd8201dSApple OSS Distributions  *
6*fdd8201dSApple OSS Distributions  * This file contains Original Code and/or Modifications of Original Code
7*fdd8201dSApple OSS Distributions  * as defined in and that are subject to the Apple Public Source License
8*fdd8201dSApple OSS Distributions  * Version 2.0 (the 'License'). You may not use this file except in
9*fdd8201dSApple OSS Distributions  * compliance with the License. The rights granted to you under the License
10*fdd8201dSApple OSS Distributions  * may not be used to create, or enable the creation or redistribution of,
11*fdd8201dSApple OSS Distributions  * unlawful or unlicensed copies of an Apple operating system, or to
12*fdd8201dSApple OSS Distributions  * circumvent, violate, or enable the circumvention or violation of, any
13*fdd8201dSApple OSS Distributions  * terms of an Apple operating system software license agreement.
14*fdd8201dSApple OSS Distributions  *
15*fdd8201dSApple OSS Distributions  * Please obtain a copy of the License at
16*fdd8201dSApple OSS Distributions  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17*fdd8201dSApple OSS Distributions  *
18*fdd8201dSApple OSS Distributions  * The Original Code and all software distributed under the License are
19*fdd8201dSApple OSS Distributions  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20*fdd8201dSApple OSS Distributions  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21*fdd8201dSApple OSS Distributions  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22*fdd8201dSApple OSS Distributions  * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23*fdd8201dSApple OSS Distributions  * Please see the License for the specific language governing rights and
24*fdd8201dSApple OSS Distributions  * limitations under the License.
25*fdd8201dSApple OSS Distributions  *
26*fdd8201dSApple OSS Distributions  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27*fdd8201dSApple OSS Distributions  */
28*fdd8201dSApple OSS Distributions 
29*fdd8201dSApple OSS Distributions #ifndef _PTHREAD_WORKQUEUE_PRIVATE_H_
30*fdd8201dSApple OSS Distributions #define _PTHREAD_WORKQUEUE_PRIVATE_H_
31*fdd8201dSApple OSS Distributions 
32*fdd8201dSApple OSS Distributions #if XNU_KERNEL_PRIVATE && !defined(__PTHREAD_EXPOSE_INTERNALS__)
33*fdd8201dSApple OSS Distributions #define __PTHREAD_EXPOSE_INTERNALS__ 1
34*fdd8201dSApple OSS Distributions #endif // XNU_KERNEL_PRIVATE
35*fdd8201dSApple OSS Distributions 
36*fdd8201dSApple OSS Distributions #ifdef __PTHREAD_EXPOSE_INTERNALS__
37*fdd8201dSApple OSS Distributions /* workq_kernreturn commands */
38*fdd8201dSApple OSS Distributions #define WQOPS_THREAD_RETURN              0x004 /* parks the thread back into the kernel */
39*fdd8201dSApple OSS Distributions #define WQOPS_QUEUE_NEWSPISUPP           0x010 /* this is to check for newer SPI support */
40*fdd8201dSApple OSS Distributions #define WQOPS_QUEUE_REQTHREADS           0x020 /* request number of threads of a prio */
41*fdd8201dSApple OSS Distributions #define WQOPS_QUEUE_REQTHREADS2          0x030 /* request a number of threads in a given priority bucket */
42*fdd8201dSApple OSS Distributions #define WQOPS_THREAD_KEVENT_RETURN       0x040 /* parks the thread after delivering the passed kevent array */
43*fdd8201dSApple OSS Distributions #define WQOPS_SET_EVENT_MANAGER_PRIORITY 0x080 /* max() in the provided priority in the the priority of the event manager */
44*fdd8201dSApple OSS Distributions #define WQOPS_THREAD_WORKLOOP_RETURN     0x100 /* parks the thread after delivering the passed kevent array */
45*fdd8201dSApple OSS Distributions #define WQOPS_SHOULD_NARROW              0x200 /* checks whether we should narrow our concurrency */
46*fdd8201dSApple OSS Distributions #define WQOPS_SETUP_DISPATCH             0x400 /* setup pthread workqueue-related operations */
47*fdd8201dSApple OSS Distributions 
48*fdd8201dSApple OSS Distributions /* flag values for upcall flags field, only 8 bits per struct threadlist */
49*fdd8201dSApple OSS Distributions #define WQ_FLAG_THREAD_PRIO_SCHED               0x00008000
50*fdd8201dSApple OSS Distributions #define WQ_FLAG_THREAD_PRIO_QOS                 0x00004000
51*fdd8201dSApple OSS Distributions #define WQ_FLAG_THREAD_PRIO_MASK                0x00000fff
52*fdd8201dSApple OSS Distributions 
53*fdd8201dSApple OSS Distributions #define WQ_FLAG_THREAD_OVERCOMMIT               0x00010000  /* thread is with overcommit prio */
54*fdd8201dSApple OSS Distributions #define WQ_FLAG_THREAD_REUSE                    0x00020000  /* thread is being reused */
55*fdd8201dSApple OSS Distributions #define WQ_FLAG_THREAD_NEWSPI                   0x00040000  /* the call is with new SPIs */
56*fdd8201dSApple OSS Distributions #define WQ_FLAG_THREAD_KEVENT                   0x00080000  /* thread is response to kevent req */
57*fdd8201dSApple OSS Distributions #define WQ_FLAG_THREAD_EVENT_MANAGER            0x00100000  /* event manager thread */
58*fdd8201dSApple OSS Distributions #define WQ_FLAG_THREAD_TSD_BASE_SET             0x00200000  /* tsd base has already been set */
59*fdd8201dSApple OSS Distributions #define WQ_FLAG_THREAD_WORKLOOP                 0x00400000  /* workloop thread */
60*fdd8201dSApple OSS Distributions #define WQ_FLAG_THREAD_OUTSIDEQOS               0x00800000  /* thread qos changes should not be sent to kernel */
61*fdd8201dSApple OSS Distributions #define WQ_FLAG_THREAD_COOPERATIVE              0x01000000  /* thread is part of cooperative thread pool */
62*fdd8201dSApple OSS Distributions 
63*fdd8201dSApple OSS Distributions #define WQ_KEVENT_LIST_LEN  16 // WORKQ_KEVENT_EVENT_BUFFER_LEN
64*fdd8201dSApple OSS Distributions #define WQ_KEVENT_DATA_SIZE (32 * 1024)
65*fdd8201dSApple OSS Distributions 
66*fdd8201dSApple OSS Distributions /* kqueue_workloop_ctl commands */
67*fdd8201dSApple OSS Distributions #define KQ_WORKLOOP_CREATE                              0x01
68*fdd8201dSApple OSS Distributions #define KQ_WORKLOOP_DESTROY                             0x02
69*fdd8201dSApple OSS Distributions 
70*fdd8201dSApple OSS Distributions /* indicate which fields of kq_workloop_create params are valid */
71*fdd8201dSApple OSS Distributions #define KQ_WORKLOOP_CREATE_SCHED_PRI    0x01
72*fdd8201dSApple OSS Distributions #define KQ_WORKLOOP_CREATE_SCHED_POL    0x02
73*fdd8201dSApple OSS Distributions #define KQ_WORKLOOP_CREATE_CPU_PERCENT  0x04
74*fdd8201dSApple OSS Distributions 
75*fdd8201dSApple OSS Distributions struct kqueue_workloop_params {
76*fdd8201dSApple OSS Distributions 	int kqwlp_version;
77*fdd8201dSApple OSS Distributions 	int kqwlp_flags;
78*fdd8201dSApple OSS Distributions 	uint64_t kqwlp_id;
79*fdd8201dSApple OSS Distributions 	int kqwlp_sched_pri;
80*fdd8201dSApple OSS Distributions 	int kqwlp_sched_pol;
81*fdd8201dSApple OSS Distributions 	int kqwlp_cpu_percent;
82*fdd8201dSApple OSS Distributions 	int kqwlp_cpu_refillms;
83*fdd8201dSApple OSS Distributions } __attribute__((packed));
84*fdd8201dSApple OSS Distributions 
85*fdd8201dSApple OSS Distributions _Static_assert(offsetof(struct kqueue_workloop_params, kqwlp_version) == 0,
86*fdd8201dSApple OSS Distributions     "kqwlp_version should be first");
87*fdd8201dSApple OSS Distributions 
88*fdd8201dSApple OSS Distributions int
89*fdd8201dSApple OSS Distributions __workq_open(void);
90*fdd8201dSApple OSS Distributions 
91*fdd8201dSApple OSS Distributions int
92*fdd8201dSApple OSS Distributions __workq_kernreturn(int op, void *arg2, int arg3, int arg4);
93*fdd8201dSApple OSS Distributions 
94*fdd8201dSApple OSS Distributions int
95*fdd8201dSApple OSS Distributions __kqueue_workloop_ctl(uintptr_t cmd, uint64_t options, void *addr, size_t sz);
96*fdd8201dSApple OSS Distributions 
97*fdd8201dSApple OSS Distributions /* SPI flags between WQ and workq_setup_thread in pthread.kext */
98*fdd8201dSApple OSS Distributions #define WQ_SETUP_NONE           0
99*fdd8201dSApple OSS Distributions #define WQ_SETUP_FIRST_USE      1
100*fdd8201dSApple OSS Distributions #define WQ_SETUP_CLEAR_VOUCHER  2
101*fdd8201dSApple OSS Distributions // was  WQ_SETUP_SET_SCHED_CALL 4
102*fdd8201dSApple OSS Distributions #define WQ_SETUP_EXIT_THREAD    8
103*fdd8201dSApple OSS Distributions 
104*fdd8201dSApple OSS Distributions #endif // __PTHREAD_EXPOSE_INTERNALS__
105*fdd8201dSApple OSS Distributions 
106*fdd8201dSApple OSS Distributions #define WORKQ_DISPATCH_CONFIG_VERSION        2
107*fdd8201dSApple OSS Distributions #define WORKQ_DISPATCH_MIN_SUPPORTED_VERSION 1
108*fdd8201dSApple OSS Distributions #define WORKQ_DISPATCH_SUPPORTED_FLAGS       0
109*fdd8201dSApple OSS Distributions struct workq_dispatch_config {
110*fdd8201dSApple OSS Distributions 	uint32_t wdc_version;
111*fdd8201dSApple OSS Distributions 	uint32_t wdc_flags;
112*fdd8201dSApple OSS Distributions 	uint64_t wdc_queue_serialno_offs;
113*fdd8201dSApple OSS Distributions 	uint64_t wdc_queue_label_offs;
114*fdd8201dSApple OSS Distributions } __attribute__((packed, aligned(4)));
115*fdd8201dSApple OSS Distributions 
116*fdd8201dSApple OSS Distributions #endif // _PTHREAD_WORKQUEUE_PRIVATE_H_
117