]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/pthread_internal.h
xnu-1699.24.23.tar.gz
[apple/xnu.git] / bsd / sys / pthread_internal.h
CommitLineData
2d21ac55
A
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
6d2010ae 32#include <sys/user.h>
2d21ac55
A
33#include <kern/thread_call.h>
34
6d2010ae
A
35struct ksyn_waitq_element {
36 TAILQ_ENTRY(ksyn_waitq_element) kwe_list; /* link to other list members */
37 void * kwe_kwqqueue; /* queue blocked on */
38 uint32_t kwe_flags; /* flags */
39 uint32_t kwe_lockseq; /* the sequence of the entry */
40 uint32_t kwe_count; /* upper bound on number of matches still pending */
41 uint32_t kwe_psynchretval; /* thread retval */
42 void *kwe_uth; /* uthread */
43};
44typedef struct ksyn_waitq_element * ksyn_waitq_element_t;
45
46/* kew_flags defns */
47#define KWE_THREAD_INWAIT 1
48#define KWE_THREAD_PREPOST 2
49#define KWE_THREAD_BROADCAST 4
50
51
2d21ac55 52#define WORKITEM_SIZE 64
6d2010ae
A
53
54#define WORKQUEUE_HIGH_PRIOQUEUE 0 /* high priority queue */
55#define WORKQUEUE_DEFAULT_PRIOQUEUE 1 /* default priority queue */
56#define WORKQUEUE_LOW_PRIOQUEUE 2 /* low priority queue */
57#define WORKQUEUE_BG_PRIOQUEUE 3 /* background priority queue */
58
59#define WORKQUEUE_NUMPRIOS 4
b0d623f7
A
60
61#define WORKQUEUE_OVERCOMMIT 0x10000
2d21ac55
A
62
63struct threadlist {
64 TAILQ_ENTRY(threadlist) th_entry;
65 thread_t th_thread;
66 int th_flags;
b0d623f7
A
67 uint16_t th_affinity_tag;
68 uint8_t th_priority;
69 uint8_t th_policy;
2d21ac55
A
70 struct workqueue *th_workq;
71 mach_vm_size_t th_stacksize;
72 mach_vm_size_t th_allocsize;
73 mach_vm_offset_t th_stackaddr;
b0d623f7 74 mach_port_name_t th_thport;
2d21ac55
A
75};
76#define TH_LIST_INITED 0x01
77#define TH_LIST_RUNNING 0x02
78#define TH_LIST_BLOCKED 0x04
79#define TH_LIST_SUSPENDED 0x08
b0d623f7 80#define TH_LIST_BUSY 0x10
b7266188 81#define TH_LIST_NEED_WAKEUP 0x20
6d2010ae
A
82#define TH_LIST_CONSTRAINED 0x40
83
2d21ac55
A
84
85struct workitem {
86 TAILQ_ENTRY(workitem) wi_entry;
87 user_addr_t wi_item;
b0d623f7 88 uint32_t wi_affinity;
2d21ac55
A
89};
90
91struct workitemlist {
92 TAILQ_HEAD(, workitem) wl_itemlist;
93 TAILQ_HEAD(, workitem) wl_freelist;
94};
95
2d21ac55
A
96struct workqueue {
97 struct workitem wq_array[WORKITEM_SIZE * WORKQUEUE_NUMPRIOS];
98 proc_t wq_proc;
99 vm_map_t wq_map;
100 task_t wq_task;
b0d623f7 101 thread_call_t wq_atimer_call;
2d21ac55 102 int wq_flags;
b0d623f7 103 int wq_lflags;
2d21ac55 104 int wq_itemcount;
b0d623f7
A
105 uint64_t wq_thread_yielded_timestamp;
106 uint32_t wq_thread_yielded_count;
107 uint32_t wq_timer_interval;
2d21ac55
A
108 uint32_t wq_affinity_max;
109 uint32_t wq_threads_scheduled;
6d2010ae 110 uint32_t wq_constrained_threads_scheduled;
2d21ac55 111 uint32_t wq_nthreads;
b0d623f7
A
112 uint32_t wq_thidlecount;
113 uint32_t wq_reqconc[WORKQUEUE_NUMPRIOS]; /* requested concurrency for each priority level */
114 struct workitemlist wq_list[WORKQUEUE_NUMPRIOS]; /* priority based item list */
115 uint32_t wq_list_bitmap;
2d21ac55 116 TAILQ_HEAD(, threadlist) wq_thrunlist;
b0d623f7
A
117 TAILQ_HEAD(, threadlist) wq_thidlelist;
118 uint32_t *wq_thactive_count[WORKQUEUE_NUMPRIOS];
119 uint32_t *wq_thscheduled_count[WORKQUEUE_NUMPRIOS];
120 uint64_t *wq_lastblocked_ts[WORKQUEUE_NUMPRIOS];
2d21ac55
A
121};
122#define WQ_LIST_INITED 0x01
b0d623f7
A
123#define WQ_ATIMER_RUNNING 0x02
124#define WQ_EXITING 0x04
125
126#define WQL_ATIMER_BUSY 0x01
127#define WQL_ATIMER_WAITING 0x02
6d2010ae
A
128#define WQL_EXCEEDED_CONSTRAINED_THREAD_LIMIT 0x04
129#define WQL_EXCEEDED_TOTAL_THREAD_LIMIT 0x08
b0d623f7
A
130
131
132#define WQ_VECT_SET_BIT(vector, bit) \
133 vector[(bit) / 32] |= (1 << ((bit) % 32))
134
135#define WQ_VECT_CLEAR_BIT(vector, bit) \
136 vector[(bit) / 32] &= ~(1 << ((bit) % 32))
137
138#define WQ_VECT_TEST_BIT(vector, bit) \
139 vector[(bit) / 32] & (1 << ((bit) % 32))
140
2d21ac55 141
b0d623f7
A
142#define WORKQUEUE_MAXTHREADS 512
143#define WQ_YIELDED_THRESHOLD 2000
144#define WQ_YIELDED_WINDOW_USECS 30000
145#define WQ_STALLED_WINDOW_USECS 200
146#define WQ_REDUCE_POOL_WINDOW_USECS 5000000
147#define WQ_MAX_TIMER_INTERVAL_USECS 50000
2d21ac55 148
b0d623f7 149/* workq_kernreturn commands */
2d21ac55 150#define WQOPS_QUEUE_ADD 1
6d2010ae 151#define WQOPS_QUEUE_REMOVE_OBSOLETE 2
2d21ac55 152#define WQOPS_THREAD_RETURN 4
b0d623f7 153#define WQOPS_THREAD_SETCONC 8
2d21ac55
A
154
155#define PTH_DEFAULT_STACKSIZE 512*1024
156#define PTH_DEFAULT_GUARDSIZE 4*1024
157#define MAX_PTHREAD_SIZE 64*1024
158
b0d623f7
A
159extern lck_grp_attr_t *pthread_lck_grp_attr;
160extern lck_grp_t *pthread_lck_grp;
161extern lck_attr_t *pthread_lck_attr;
2d21ac55 162
6d2010ae
A
163void workqueue_exit(struct proc *);
164void pthread_init(void);
165void psynch_zoneinit(void);
2d21ac55
A
166#endif /* _SYS_PTHREAD_INTERNAL_H_ */
167