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