thr_private.h (113658) | thr_private.h (113661) |
---|---|
1/* 2 * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * Private thread definitions for the uthread kernel. 33 * | 1/* 2 * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * Private thread definitions for the uthread kernel. 33 * |
34 * $FreeBSD: head/lib/libkse/thread/thr_private.h 113658 2003-04-18 05:04:16Z deischen $ | 34 * $FreeBSD: head/lib/libkse/thread/thr_private.h 113661 2003-04-18 07:09:43Z deischen $ |
35 */ 36 37#ifndef _THR_PRIVATE_H 38#define _THR_PRIVATE_H 39 40/* 41 * Include files. 42 */ --- 105 unchanged lines hidden (view full) --- 148/* 149 * Each KSEG has a scheduling queue. For now, threads that exist in their 150 * own KSEG (system scope) will get a full priority queue. In the future 151 * this can be optimized for the single thread per KSEG case. 152 */ 153struct sched_queue { 154 pq_queue_t sq_runq; 155 TAILQ_HEAD(, pthread) sq_waitq; /* waiting in userland */ | 35 */ 36 37#ifndef _THR_PRIVATE_H 38#define _THR_PRIVATE_H 39 40/* 41 * Include files. 42 */ --- 105 unchanged lines hidden (view full) --- 148/* 149 * Each KSEG has a scheduling queue. For now, threads that exist in their 150 * own KSEG (system scope) will get a full priority queue. In the future 151 * this can be optimized for the single thread per KSEG case. 152 */ 153struct sched_queue { 154 pq_queue_t sq_runq; 155 TAILQ_HEAD(, pthread) sq_waitq; /* waiting in userland */ |
156 TAILQ_HEAD(, pthread) sq_blockedq; /* waiting in kernel */ | |
157}; 158 159/* Used to maintain pending and active signals: */ 160struct sigstatus { 161 siginfo_t *info; /* arg 2 to signal handler */ 162 int pending; /* Is this a pending signal? */ 163 int blocked; /* 164 * This signal has occured and hasn't --- 10 unchanged lines hidden (view full) --- 175#define MAX_KSE_LOCKLEVEL 3 176struct kse { 177 struct kse_mailbox k_mbx; /* kernel kse mailbox */ 178 /* -- location and order specific items for gdb -- */ 179 struct pthread *k_curthread; /* current thread */ 180 struct kse_group *k_kseg; /* parent KSEG */ 181 struct sched_queue *k_schedq; /* scheduling queue */ 182 /* -- end of location and order specific items -- */ | 156}; 157 158/* Used to maintain pending and active signals: */ 159struct sigstatus { 160 siginfo_t *info; /* arg 2 to signal handler */ 161 int pending; /* Is this a pending signal? */ 162 int blocked; /* 163 * This signal has occured and hasn't --- 10 unchanged lines hidden (view full) --- 174#define MAX_KSE_LOCKLEVEL 3 175struct kse { 176 struct kse_mailbox k_mbx; /* kernel kse mailbox */ 177 /* -- location and order specific items for gdb -- */ 178 struct pthread *k_curthread; /* current thread */ 179 struct kse_group *k_kseg; /* parent KSEG */ 180 struct sched_queue *k_schedq; /* scheduling queue */ 181 /* -- end of location and order specific items -- */ |
183 TAILQ_ENTRY(kse) k_qe; /* link entry */ | 182 TAILQ_ENTRY(kse) k_qe; /* KSE list link entry */ 183 TAILQ_ENTRY(kse) k_kgqe; /* KSEG's KSE list entry */ |
184 struct ksd k_ksd; /* KSE specific data */ 185 /* 186 * Items that are only modified by the kse, or that otherwise 187 * don't need to be locked when accessed 188 */ 189 struct lock k_lock; 190 struct lockuser k_lockusers[MAX_KSE_LOCKLEVEL]; 191 int k_locklevel; --- 24 unchanged lines hidden (view full) --- 216 int kg_threadcount; /* # of assigned threads */ 217 int kg_idle_kses; 218 int kg_flags; 219#define KGF_SINGLE_THREAD 0x0001 /* scope system kse group */ 220#define KGF_SCHEDQ_INITED 0x0002 /* has an initialized schedq */ 221}; 222 223/* | 184 struct ksd k_ksd; /* KSE specific data */ 185 /* 186 * Items that are only modified by the kse, or that otherwise 187 * don't need to be locked when accessed 188 */ 189 struct lock k_lock; 190 struct lockuser k_lockusers[MAX_KSE_LOCKLEVEL]; 191 int k_locklevel; --- 24 unchanged lines hidden (view full) --- 216 int kg_threadcount; /* # of assigned threads */ 217 int kg_idle_kses; 218 int kg_flags; 219#define KGF_SINGLE_THREAD 0x0001 /* scope system kse group */ 220#define KGF_SCHEDQ_INITED 0x0002 /* has an initialized schedq */ 221}; 222 223/* |
224 * Add/remove threads from a KSE's scheduling queue. 225 * For now the scheduling queue is hung off the KSEG. 226 */ 227#define KSEG_THRQ_ADD(kseg, thr) \ 228do { \ 229 TAILQ_INSERT_TAIL(&(kseg)->kg_threadq, thr, kle);\ 230 (kseg)->kg_threadcount++; \ 231} while (0) 232 233#define KSEG_THRQ_REMOVE(kseg, thr) \ 234do { \ 235 TAILQ_REMOVE(&(kseg)->kg_threadq, thr, kle); \ 236 (kseg)->kg_threadcount--; \ 237} while (0) 238 239 240/* |
|
224 * Lock acquire and release for KSEs. 225 */ 226#define KSE_LOCK_ACQUIRE(kse, lck) \ 227do { \ 228 if ((kse)->k_locklevel >= MAX_KSE_LOCKLEVEL) \ 229 PANIC("Exceeded maximum lock level"); \ 230 else { \ 231 (kse)->k_locklevel++; \ --- 623 unchanged lines hidden (view full) --- 855#define THR_LIST_REMOVE(thrd) do { \ 856 if (((thrd)->flags & THR_FLAGS_IN_TDLIST) != 0) { \ 857 TAILQ_REMOVE(&_thread_list, thrd, tle); \ 858 (thrd)->flags &= ~THR_FLAGS_IN_TDLIST; \ 859 } \ 860} while (0) 861#define THR_GCLIST_ADD(thrd) do { \ 862 if (((thrd)->flags & THR_FLAGS_IN_GCLIST) == 0) { \ | 241 * Lock acquire and release for KSEs. 242 */ 243#define KSE_LOCK_ACQUIRE(kse, lck) \ 244do { \ 245 if ((kse)->k_locklevel >= MAX_KSE_LOCKLEVEL) \ 246 PANIC("Exceeded maximum lock level"); \ 247 else { \ 248 (kse)->k_locklevel++; \ --- 623 unchanged lines hidden (view full) --- 872#define THR_LIST_REMOVE(thrd) do { \ 873 if (((thrd)->flags & THR_FLAGS_IN_TDLIST) != 0) { \ 874 TAILQ_REMOVE(&_thread_list, thrd, tle); \ 875 (thrd)->flags &= ~THR_FLAGS_IN_TDLIST; \ 876 } \ 877} while (0) 878#define THR_GCLIST_ADD(thrd) do { \ 879 if (((thrd)->flags & THR_FLAGS_IN_GCLIST) == 0) { \ |
863 TAILQ_INSERT_HEAD(&_thread_gc_list, thrd, tle); \ | 880 TAILQ_INSERT_HEAD(&_thread_gc_list, thrd, gcle);\ |
864 (thrd)->flags |= THR_FLAGS_IN_GCLIST; \ | 881 (thrd)->flags |= THR_FLAGS_IN_GCLIST; \ |
882 _gc_count++; \ |
|
865 } \ 866} while (0) 867#define THR_GCLIST_REMOVE(thrd) do { \ 868 if (((thrd)->flags & THR_FLAGS_IN_GCLIST) != 0) { \ | 883 } \ 884} while (0) 885#define THR_GCLIST_REMOVE(thrd) do { \ 886 if (((thrd)->flags & THR_FLAGS_IN_GCLIST) != 0) { \ |
869 TAILQ_REMOVE(&_thread_gc_list, thrd, tle); \ | 887 TAILQ_REMOVE(&_thread_gc_list, thrd, gcle); \ |
870 (thrd)->flags &= ~THR_FLAGS_IN_GCLIST; \ | 888 (thrd)->flags &= ~THR_FLAGS_IN_GCLIST; \ |
889 _gc_count--; \ |
|
871 } \ 872} while (0) 873 | 890 } \ 891} while (0) 892 |
893#define GC_NEEDED() (atomic_load_acq_int(&_gc_count) >= 5) 894 |
|
874/* 875 * Locking the scheduling queue for another thread uses that thread's 876 * KSEG lock. 877 */ 878#define THR_SCHED_LOCK(curthr, thr) do { \ 879 (curthr)->critical[(curthr)->locklevel] = _kse_critical_enter(); \ 880 (curthr)->locklevel++; \ 881 KSE_SCHED_LOCK((curthr)->kse, (thr)->kseg); \ --- 78 unchanged lines hidden (view full) --- 960SCLASS sigset_t _thr_proc_sigmask SCLASS_PRESET({{0, 0, 0, 0}}); 961SCLASS siginfo_t _thr_proc_siginfo[NSIG]; 962 963SCLASS pid_t _thr_pid SCLASS_PRESET(0); 964 965/* Garbage collector lock. */ 966SCLASS struct lock _gc_lock; 967SCLASS int _gc_check SCLASS_PRESET(0); | 895/* 896 * Locking the scheduling queue for another thread uses that thread's 897 * KSEG lock. 898 */ 899#define THR_SCHED_LOCK(curthr, thr) do { \ 900 (curthr)->critical[(curthr)->locklevel] = _kse_critical_enter(); \ 901 (curthr)->locklevel++; \ 902 KSE_SCHED_LOCK((curthr)->kse, (thr)->kseg); \ --- 78 unchanged lines hidden (view full) --- 981SCLASS sigset_t _thr_proc_sigmask SCLASS_PRESET({{0, 0, 0, 0}}); 982SCLASS siginfo_t _thr_proc_siginfo[NSIG]; 983 984SCLASS pid_t _thr_pid SCLASS_PRESET(0); 985 986/* Garbage collector lock. */ 987SCLASS struct lock _gc_lock; 988SCLASS int _gc_check SCLASS_PRESET(0); |
968SCLASS pthread_t _gc_thread; | 989SCLASS int _gc_count SCLASS_PRESET(0); |
969 970SCLASS struct lock _mutex_static_lock; 971SCLASS struct lock _rwlock_static_lock; 972SCLASS struct lock _keytable_lock; 973SCLASS struct lock _thread_list_lock; 974SCLASS int _thr_guard_default; 975SCLASS int _thr_page_size; 976 --- 8 unchanged lines hidden (view full) --- 985 * Function prototype definitions. 986 */ 987__BEGIN_DECLS 988int _cond_reinit(pthread_cond_t *); 989void _cond_wait_backout(struct pthread *); 990struct pthread *_get_curthread(void); 991struct kse *_get_curkse(void); 992void _set_curkse(struct kse *); | 990 991SCLASS struct lock _mutex_static_lock; 992SCLASS struct lock _rwlock_static_lock; 993SCLASS struct lock _keytable_lock; 994SCLASS struct lock _thread_list_lock; 995SCLASS int _thr_guard_default; 996SCLASS int _thr_page_size; 997 --- 8 unchanged lines hidden (view full) --- 1006 * Function prototype definitions. 1007 */ 1008__BEGIN_DECLS 1009int _cond_reinit(pthread_cond_t *); 1010void _cond_wait_backout(struct pthread *); 1011struct pthread *_get_curthread(void); 1012struct kse *_get_curkse(void); 1013void _set_curkse(struct kse *); |
993struct kse *_kse_alloc(struct kse *); | 1014struct kse *_kse_alloc(struct pthread *); |
994kse_critical_t _kse_critical_enter(void); 995void _kse_critical_leave(kse_critical_t); | 1015kse_critical_t _kse_critical_enter(void); 1016void _kse_critical_leave(kse_critical_t); |
996void _kse_free(struct kse *, struct kse *); | 1017void _kse_free(struct pthread *, struct kse *); |
997void _kse_init(); | 1018void _kse_init(); |
998struct kse_group *_kseg_alloc(struct kse *); | 1019struct kse_group *_kseg_alloc(struct pthread *); |
999void _kse_lock_wait(struct lock *, struct lockuser *lu); 1000void _kse_lock_wakeup(struct lock *, struct lockuser *lu); 1001void _kse_sig_check_pending(struct kse *); 1002void _kse_single_thread(struct pthread *); 1003void _kse_start(struct kse *); 1004void _kse_setthreaded(int); 1005int _kse_isthreaded(void); 1006int _mutex_cv_lock(pthread_mutex_t *); 1007int _mutex_cv_unlock(pthread_mutex_t *); 1008void _mutex_lock_backout(struct pthread *); 1009void _mutex_notify_priochange(struct pthread *, struct pthread *, int); 1010int _mutex_reinit(struct pthread_mutex *); 1011void _mutex_unlock_private(struct pthread *); 1012void _libpthread_init(struct pthread *); 1013int _pq_alloc(struct pq_queue *, int, int); | 1020void _kse_lock_wait(struct lock *, struct lockuser *lu); 1021void _kse_lock_wakeup(struct lock *, struct lockuser *lu); 1022void _kse_sig_check_pending(struct kse *); 1023void _kse_single_thread(struct pthread *); 1024void _kse_start(struct kse *); 1025void _kse_setthreaded(int); 1026int _kse_isthreaded(void); 1027int _mutex_cv_lock(pthread_mutex_t *); 1028int _mutex_cv_unlock(pthread_mutex_t *); 1029void _mutex_lock_backout(struct pthread *); 1030void _mutex_notify_priochange(struct pthread *, struct pthread *, int); 1031int _mutex_reinit(struct pthread_mutex *); 1032void _mutex_unlock_private(struct pthread *); 1033void _libpthread_init(struct pthread *); 1034int _pq_alloc(struct pq_queue *, int, int); |
1035void _pq_free(struct pq_queue *); |
|
1014int _pq_init(struct pq_queue *); 1015void _pq_remove(struct pq_queue *pq, struct pthread *); 1016void _pq_insert_head(struct pq_queue *pq, struct pthread *); 1017void _pq_insert_tail(struct pq_queue *pq, struct pthread *); 1018struct pthread *_pq_first(struct pq_queue *pq); 1019void *_pthread_getspecific(pthread_key_t); 1020int _pthread_key_create(pthread_key_t *, void (*) (void *)); 1021int _pthread_key_delete(pthread_key_t); 1022int _pthread_mutex_destroy(pthread_mutex_t *); 1023int _pthread_mutex_init(pthread_mutex_t *, const pthread_mutexattr_t *); 1024int _pthread_mutex_lock(pthread_mutex_t *); 1025int _pthread_mutex_trylock(pthread_mutex_t *); 1026int _pthread_mutex_unlock(pthread_mutex_t *); 1027int _pthread_mutexattr_init(pthread_mutexattr_t *); 1028int _pthread_mutexattr_destroy(pthread_mutexattr_t *); 1029int _pthread_mutexattr_settype(pthread_mutexattr_t *, int); 1030int _pthread_once(pthread_once_t *, void (*) (void)); 1031struct pthread *_pthread_self(void); 1032int _pthread_setspecific(pthread_key_t, const void *); | 1036int _pq_init(struct pq_queue *); 1037void _pq_remove(struct pq_queue *pq, struct pthread *); 1038void _pq_insert_head(struct pq_queue *pq, struct pthread *); 1039void _pq_insert_tail(struct pq_queue *pq, struct pthread *); 1040struct pthread *_pq_first(struct pq_queue *pq); 1041void *_pthread_getspecific(pthread_key_t); 1042int _pthread_key_create(pthread_key_t *, void (*) (void *)); 1043int _pthread_key_delete(pthread_key_t); 1044int _pthread_mutex_destroy(pthread_mutex_t *); 1045int _pthread_mutex_init(pthread_mutex_t *, const pthread_mutexattr_t *); 1046int _pthread_mutex_lock(pthread_mutex_t *); 1047int _pthread_mutex_trylock(pthread_mutex_t *); 1048int _pthread_mutex_unlock(pthread_mutex_t *); 1049int _pthread_mutexattr_init(pthread_mutexattr_t *); 1050int _pthread_mutexattr_destroy(pthread_mutexattr_t *); 1051int _pthread_mutexattr_settype(pthread_mutexattr_t *, int); 1052int _pthread_once(pthread_once_t *, void (*) (void)); 1053struct pthread *_pthread_self(void); 1054int _pthread_setspecific(pthread_key_t, const void *); |
1033struct pthread *_thr_alloc(struct kse *); | 1055struct pthread *_thr_alloc(struct pthread *); 1056int _thread_enter_uts(struct kse_thr_mailbox *, struct kse_mailbox *); 1057int _thread_switch(struct kse_thr_mailbox *, struct kse_thr_mailbox **); |
1034void _thr_exit(char *, int, char *); 1035void _thr_exit_cleanup(void); 1036void _thr_lock_wait(struct lock *lock, struct lockuser *lu); 1037void _thr_lock_wakeup(struct lock *lock, struct lockuser *lu); 1038int _thr_ref_add(struct pthread *, struct pthread *, int); 1039void _thr_ref_delete(struct pthread *, struct pthread *); 1040void _thr_schedule_add(struct pthread *, struct pthread *); 1041void _thr_schedule_remove(struct pthread *, struct pthread *); 1042void _thr_setrunnable(struct pthread *curthread, struct pthread *thread); 1043void _thr_setrunnable_unlocked(struct pthread *thread); 1044void _thr_sig_add(struct pthread *, int, siginfo_t *, ucontext_t *); 1045void _thr_sig_dispatch(struct kse *, int, siginfo_t *); 1046int _thr_stack_alloc(struct pthread_attr *); 1047void _thr_stack_free(struct pthread_attr *); 1048void _thr_exit_cleanup(void); | 1058void _thr_exit(char *, int, char *); 1059void _thr_exit_cleanup(void); 1060void _thr_lock_wait(struct lock *lock, struct lockuser *lu); 1061void _thr_lock_wakeup(struct lock *lock, struct lockuser *lu); 1062int _thr_ref_add(struct pthread *, struct pthread *, int); 1063void _thr_ref_delete(struct pthread *, struct pthread *); 1064void _thr_schedule_add(struct pthread *, struct pthread *); 1065void _thr_schedule_remove(struct pthread *, struct pthread *); 1066void _thr_setrunnable(struct pthread *curthread, struct pthread *thread); 1067void _thr_setrunnable_unlocked(struct pthread *thread); 1068void _thr_sig_add(struct pthread *, int, siginfo_t *, ucontext_t *); 1069void _thr_sig_dispatch(struct kse *, int, siginfo_t *); 1070int _thr_stack_alloc(struct pthread_attr *); 1071void _thr_stack_free(struct pthread_attr *); 1072void _thr_exit_cleanup(void); |
1049void _thr_free(struct kse *, struct pthread *); | 1073void _thr_free(struct pthread *, struct pthread *); 1074void _thr_gc(struct pthread *); |
1050void _thr_panic_exit(char *, int, char *); 1051void _thread_cleanupspecific(void); 1052void _thread_dump_info(void); 1053void _thread_printf(int, const char *, ...); 1054void _thr_sched_frame(struct pthread_sigframe *); 1055void _thr_sched_switch(struct pthread *); 1056void _thr_set_timeout(const struct timespec *); 1057void _thr_sig_handler(int, siginfo_t *, ucontext_t *); --- 92 unchanged lines hidden --- | 1075void _thr_panic_exit(char *, int, char *); 1076void _thread_cleanupspecific(void); 1077void _thread_dump_info(void); 1078void _thread_printf(int, const char *, ...); 1079void _thr_sched_frame(struct pthread_sigframe *); 1080void _thr_sched_switch(struct pthread *); 1081void _thr_set_timeout(const struct timespec *); 1082void _thr_sig_handler(int, siginfo_t *, ucontext_t *); --- 92 unchanged lines hidden --- |