]> git.saurik.com Git - apple/xnu.git/blame - bsd/sys/pthread_internal.h
xnu-2050.7.9.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
6d2010ae
A
52#define WORKQUEUE_HIGH_PRIOQUEUE 0 /* high priority queue */
53#define WORKQUEUE_DEFAULT_PRIOQUEUE 1 /* default priority queue */
54#define WORKQUEUE_LOW_PRIOQUEUE 2 /* low priority queue */
55#define WORKQUEUE_BG_PRIOQUEUE 3 /* background priority queue */
56
57#define WORKQUEUE_NUMPRIOS 4
b0d623f7
A
58
59#define WORKQUEUE_OVERCOMMIT 0x10000
2d21ac55
A
60
61struct threadlist {
62 TAILQ_ENTRY(threadlist) th_entry;
63 thread_t th_thread;
64 int th_flags;
b0d623f7
A
65 uint16_t th_affinity_tag;
66 uint8_t th_priority;
67 uint8_t th_policy;
2d21ac55
A
68 struct workqueue *th_workq;
69 mach_vm_size_t th_stacksize;
70 mach_vm_size_t th_allocsize;
71 mach_vm_offset_t th_stackaddr;
b0d623f7 72 mach_port_name_t th_thport;
2d21ac55
A
73};
74#define TH_LIST_INITED 0x01
75#define TH_LIST_RUNNING 0x02
76#define TH_LIST_BLOCKED 0x04
77#define TH_LIST_SUSPENDED 0x08
b0d623f7 78#define TH_LIST_BUSY 0x10
b7266188 79#define TH_LIST_NEED_WAKEUP 0x20
6d2010ae
A
80#define TH_LIST_CONSTRAINED 0x40
81
2d21ac55 82
2d21ac55 83struct workqueue {
2d21ac55
A
84 proc_t wq_proc;
85 vm_map_t wq_map;
86 task_t wq_task;
b0d623f7 87 thread_call_t wq_atimer_call;
2d21ac55 88 int wq_flags;
b0d623f7 89 int wq_lflags;
b0d623f7
A
90 uint64_t wq_thread_yielded_timestamp;
91 uint32_t wq_thread_yielded_count;
92 uint32_t wq_timer_interval;
2d21ac55
A
93 uint32_t wq_affinity_max;
94 uint32_t wq_threads_scheduled;
6d2010ae 95 uint32_t wq_constrained_threads_scheduled;
2d21ac55 96 uint32_t wq_nthreads;
b0d623f7 97 uint32_t wq_thidlecount;
316670eb 98 uint32_t wq_reqcount;
2d21ac55 99 TAILQ_HEAD(, threadlist) wq_thrunlist;
b0d623f7 100 TAILQ_HEAD(, threadlist) wq_thidlelist;
316670eb
A
101 uint16_t wq_requests[WORKQUEUE_NUMPRIOS];
102 uint16_t wq_ocrequests[WORKQUEUE_NUMPRIOS];
103 uint16_t wq_reqconc[WORKQUEUE_NUMPRIOS]; /* requested concurrency for each priority level */
104 uint16_t *wq_thscheduled_count[WORKQUEUE_NUMPRIOS];
105 uint32_t *wq_thactive_count[WORKQUEUE_NUMPRIOS]; /* must be uint32_t since we OSAddAtomic on these */
b0d623f7 106 uint64_t *wq_lastblocked_ts[WORKQUEUE_NUMPRIOS];
2d21ac55
A
107};
108#define WQ_LIST_INITED 0x01
b0d623f7
A
109#define WQ_ATIMER_RUNNING 0x02
110#define WQ_EXITING 0x04
111
112#define WQL_ATIMER_BUSY 0x01
113#define WQL_ATIMER_WAITING 0x02
6d2010ae
A
114#define WQL_EXCEEDED_CONSTRAINED_THREAD_LIMIT 0x04
115#define WQL_EXCEEDED_TOTAL_THREAD_LIMIT 0x08
b0d623f7
A
116
117
118#define WQ_VECT_SET_BIT(vector, bit) \
119 vector[(bit) / 32] |= (1 << ((bit) % 32))
120
121#define WQ_VECT_CLEAR_BIT(vector, bit) \
122 vector[(bit) / 32] &= ~(1 << ((bit) % 32))
123
124#define WQ_VECT_TEST_BIT(vector, bit) \
125 vector[(bit) / 32] & (1 << ((bit) % 32))
126
2d21ac55 127
b0d623f7
A
128#define WORKQUEUE_MAXTHREADS 512
129#define WQ_YIELDED_THRESHOLD 2000
130#define WQ_YIELDED_WINDOW_USECS 30000
131#define WQ_STALLED_WINDOW_USECS 200
132#define WQ_REDUCE_POOL_WINDOW_USECS 5000000
133#define WQ_MAX_TIMER_INTERVAL_USECS 50000
2d21ac55 134
b0d623f7 135/* workq_kernreturn commands */
2d21ac55 136#define WQOPS_QUEUE_ADD 1
6d2010ae 137#define WQOPS_QUEUE_REMOVE_OBSOLETE 2
2d21ac55 138#define WQOPS_THREAD_RETURN 4
b0d623f7 139#define WQOPS_THREAD_SETCONC 8
316670eb
A
140#define WQOPS_QUEUE_NEWSPISUPP 0x10 /* this is to check for newer SPI support */
141#define WQOPS_QUEUE_REQTHREADS 0x20 /* request number of threads of a prio */
2d21ac55
A
142
143#define PTH_DEFAULT_STACKSIZE 512*1024
144#define PTH_DEFAULT_GUARDSIZE 4*1024
145#define MAX_PTHREAD_SIZE 64*1024
146
b0d623f7
A
147extern lck_grp_attr_t *pthread_lck_grp_attr;
148extern lck_grp_t *pthread_lck_grp;
149extern lck_attr_t *pthread_lck_attr;
2d21ac55 150
13f56ec4 151void workqueue_mark_exiting(struct proc *);
6d2010ae
A
152void workqueue_exit(struct proc *);
153void pthread_init(void);
154void psynch_zoneinit(void);
2d21ac55
A
155#endif /* _SYS_PTHREAD_INTERNAL_H_ */
156