2 * Copyright (c) 2000-2003 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #ifndef _SYS_PTHREAD_INTERNAL_H_
30 #define _SYS_PTHREAD_INTERNAL_H_
32 #undef pthread_mutexattr_t;
34 #include <kern/thread_call.h>
36 #define WORKITEM_SIZE 64
37 #define WORKQUEUE_NUMPRIOS 3
39 #define WORKQUEUE_OVERCOMMIT 0x10000
42 TAILQ_ENTRY(threadlist
) th_entry
;
45 uint16_t th_affinity_tag
;
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
;
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
62 TAILQ_ENTRY(workitem
) wi_entry
;
68 TAILQ_HEAD(, workitem
) wl_itemlist
;
69 TAILQ_HEAD(, workitem
) wl_freelist
;
73 struct workitem wq_array
[WORKITEM_SIZE
* WORKQUEUE_NUMPRIOS
];
77 thread_call_t wq_atimer_call
;
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
;
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
];
97 #define WQ_LIST_INITED 0x01
98 #define WQ_ATIMER_RUNNING 0x02
99 #define WQ_EXITING 0x04
101 #define WQL_ATIMER_BUSY 0x01
102 #define WQL_ATIMER_WAITING 0x02
105 #define WQ_VECT_SET_BIT(vector, bit) \
106 vector[(bit) / 32] |= (1 << ((bit) % 32))
108 #define WQ_VECT_CLEAR_BIT(vector, bit) \
109 vector[(bit) / 32] &= ~(1 << ((bit) % 32))
111 #define WQ_VECT_TEST_BIT(vector, bit) \
112 vector[(bit) / 32] & (1 << ((bit) % 32))
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
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
128 #define PTH_DEFAULT_STACKSIZE 512*1024
129 #define PTH_DEFAULT_GUARDSIZE 4*1024
130 #define MAX_PTHREAD_SIZE 64*1024
132 void workqueue_exit(struct proc
*);
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
;
139 #endif /* _SYS_PTHREAD_INTERNAL_H_ */