]> git.saurik.com Git - apple/xnu.git/blob - bsd/sys/pthread_internal.h
xnu-1504.9.17.tar.gz
[apple/xnu.git] / bsd / sys / pthread_internal.h
1 /*
2 * Copyright (c) 2000-2003 Apple Computer, 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 _SYS_PTHREAD_INTERNAL_H_
30 #define _SYS_PTHREAD_INTERNAL_H_
31
32 #undef pthread_mutexattr_t;
33
34 #include <kern/thread_call.h>
35
36 #define WORKITEM_SIZE 64
37 #define WORKQUEUE_NUMPRIOS 3
38
39 #define WORKQUEUE_OVERCOMMIT 0x10000
40
41 struct threadlist {
42 TAILQ_ENTRY(threadlist) th_entry;
43 thread_t th_thread;
44 int th_flags;
45 uint16_t th_affinity_tag;
46 uint8_t th_priority;
47 uint8_t th_policy;
48 struct workqueue *th_workq;
49 mach_vm_size_t th_stacksize;
50 mach_vm_size_t th_allocsize;
51 mach_vm_offset_t th_stackaddr;
52 mach_port_name_t th_thport;
53 };
54 #define TH_LIST_INITED 0x01
55 #define TH_LIST_RUNNING 0x02
56 #define TH_LIST_BLOCKED 0x04
57 #define TH_LIST_SUSPENDED 0x08
58 #define TH_LIST_BUSY 0x10
59 #define TH_LIST_NEED_WAKEUP 0x20
60
61 struct workitem {
62 TAILQ_ENTRY(workitem) wi_entry;
63 user_addr_t wi_item;
64 uint32_t wi_affinity;
65 };
66
67 struct workitemlist {
68 TAILQ_HEAD(, workitem) wl_itemlist;
69 TAILQ_HEAD(, workitem) wl_freelist;
70 };
71
72 struct workqueue {
73 struct workitem wq_array[WORKITEM_SIZE * WORKQUEUE_NUMPRIOS];
74 proc_t wq_proc;
75 vm_map_t wq_map;
76 task_t wq_task;
77 thread_call_t wq_atimer_call;
78 int wq_flags;
79 int wq_lflags;
80 int wq_itemcount;
81 uint64_t wq_thread_yielded_timestamp;
82 uint32_t wq_thread_yielded_count;
83 uint32_t wq_timer_interval;
84 uint32_t wq_affinity_max;
85 uint32_t wq_threads_scheduled;
86 uint32_t wq_nthreads;
87 uint32_t wq_thidlecount;
88 uint32_t wq_reqconc[WORKQUEUE_NUMPRIOS]; /* requested concurrency for each priority level */
89 struct workitemlist wq_list[WORKQUEUE_NUMPRIOS]; /* priority based item list */
90 uint32_t wq_list_bitmap;
91 TAILQ_HEAD(, threadlist) wq_thrunlist;
92 TAILQ_HEAD(, threadlist) wq_thidlelist;
93 uint32_t *wq_thactive_count[WORKQUEUE_NUMPRIOS];
94 uint32_t *wq_thscheduled_count[WORKQUEUE_NUMPRIOS];
95 uint64_t *wq_lastblocked_ts[WORKQUEUE_NUMPRIOS];
96 };
97 #define WQ_LIST_INITED 0x01
98 #define WQ_ATIMER_RUNNING 0x02
99 #define WQ_EXITING 0x04
100
101 #define WQL_ATIMER_BUSY 0x01
102 #define WQL_ATIMER_WAITING 0x02
103
104
105 #define WQ_VECT_SET_BIT(vector, bit) \
106 vector[(bit) / 32] |= (1 << ((bit) % 32))
107
108 #define WQ_VECT_CLEAR_BIT(vector, bit) \
109 vector[(bit) / 32] &= ~(1 << ((bit) % 32))
110
111 #define WQ_VECT_TEST_BIT(vector, bit) \
112 vector[(bit) / 32] & (1 << ((bit) % 32))
113
114
115 #define WORKQUEUE_MAXTHREADS 512
116 #define WQ_YIELDED_THRESHOLD 2000
117 #define WQ_YIELDED_WINDOW_USECS 30000
118 #define WQ_STALLED_WINDOW_USECS 200
119 #define WQ_REDUCE_POOL_WINDOW_USECS 5000000
120 #define WQ_MAX_TIMER_INTERVAL_USECS 50000
121
122 /* workq_kernreturn commands */
123 #define WQOPS_QUEUE_ADD 1
124 #define WQOPS_QUEUE_REMOVE 2
125 #define WQOPS_THREAD_RETURN 4
126 #define WQOPS_THREAD_SETCONC 8
127
128 #define PTH_DEFAULT_STACKSIZE 512*1024
129 #define PTH_DEFAULT_GUARDSIZE 4*1024
130 #define MAX_PTHREAD_SIZE 64*1024
131
132 void workqueue_exit(struct proc *);
133
134 void pthread_init(void);
135 extern lck_grp_attr_t *pthread_lck_grp_attr;
136 extern lck_grp_t *pthread_lck_grp;
137 extern lck_attr_t *pthread_lck_attr;
138
139 #endif /* _SYS_PTHREAD_INTERNAL_H_ */
140