thr_private.h (113942) | thr_private.h (114187) |
---|---|
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 113942 2003-04-23 21:46:50Z deischen $ | 34 * $FreeBSD: head/lib/libkse/thread/thr_private.h 114187 2003-04-28 23:56:12Z deischen $ |
35 */ 36 37#ifndef _THR_PRIVATE_H 38#define _THR_PRIVATE_H 39 40/* 41 * Include files. 42 */ --- 95 unchanged lines hidden (view full) --- 138} pq_list_t; 139 140typedef struct pq_queue { 141 TAILQ_HEAD(, pq_list) pq_queue; /* queue of priority lists */ 142 pq_list_t *pq_lists; /* array of all priority lists */ 143 int pq_size; /* number of priority lists */ 144#define PQF_ACTIVE 0x0001 145 int pq_flags; | 35 */ 36 37#ifndef _THR_PRIVATE_H 38#define _THR_PRIVATE_H 39 40/* 41 * Include files. 42 */ --- 95 unchanged lines hidden (view full) --- 138} pq_list_t; 139 140typedef struct pq_queue { 141 TAILQ_HEAD(, pq_list) pq_queue; /* queue of priority lists */ 142 pq_list_t *pq_lists; /* array of all priority lists */ 143 int pq_size; /* number of priority lists */ 144#define PQF_ACTIVE 0x0001 145 int pq_flags; |
146 int pq_threads; |
|
146} pq_queue_t; 147 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 { --- 38 unchanged lines hidden (view full) --- 192 sigset_t k_sigmask; 193 struct sigstatus k_sigq[NSIG]; 194 stack_t k_stack; 195 int k_check_sigq; 196 int k_flags; 197#define KF_STARTED 0x0001 /* kernel kse created */ 198#define KF_INITIALIZED 0x0002 /* initialized on 1st upcall */ 199 int k_waiting; | 147} pq_queue_t; 148 149/* 150 * Each KSEG has a scheduling queue. For now, threads that exist in their 151 * own KSEG (system scope) will get a full priority queue. In the future 152 * this can be optimized for the single thread per KSEG case. 153 */ 154struct sched_queue { --- 38 unchanged lines hidden (view full) --- 193 sigset_t k_sigmask; 194 struct sigstatus k_sigq[NSIG]; 195 stack_t k_stack; 196 int k_check_sigq; 197 int k_flags; 198#define KF_STARTED 0x0001 /* kernel kse created */ 199#define KF_INITIALIZED 0x0002 /* initialized on 1st upcall */ 200 int k_waiting; |
201 int k_idle; /* kse is idle */ |
|
200 int k_error; /* syscall errno in critical */ 201 int k_cpu; /* CPU ID when bound */ 202 int k_done; /* this KSE is done */ 203}; 204 205/* 206 * Each KSE group contains one or more KSEs in which threads can run. 207 * At least for now, there is one scheduling queue per KSE group; KSEs --- 81 unchanged lines hidden (view full) --- 289 (thrd)->flags &= ~THR_FLAGS_IN_WAITQ; \ 290 } \ 291} while (0) 292#define KSE_WAITQ_INSERT(kse, thrd) kse_waitq_insert(thrd) 293#define KSE_WAITQ_FIRST(kse) TAILQ_FIRST(&(kse)->k_schedq->sq_waitq) 294 295#define KSE_SET_WAIT(kse) atomic_store_rel_int(&(kse)->k_waiting, 1) 296 | 202 int k_error; /* syscall errno in critical */ 203 int k_cpu; /* CPU ID when bound */ 204 int k_done; /* this KSE is done */ 205}; 206 207/* 208 * Each KSE group contains one or more KSEs in which threads can run. 209 * At least for now, there is one scheduling queue per KSE group; KSEs --- 81 unchanged lines hidden (view full) --- 291 (thrd)->flags &= ~THR_FLAGS_IN_WAITQ; \ 292 } \ 293} while (0) 294#define KSE_WAITQ_INSERT(kse, thrd) kse_waitq_insert(thrd) 295#define KSE_WAITQ_FIRST(kse) TAILQ_FIRST(&(kse)->k_schedq->sq_waitq) 296 297#define KSE_SET_WAIT(kse) atomic_store_rel_int(&(kse)->k_waiting, 1) 298 |
297#define KSE_CLEAR_WAIT(kse) atomic_set_acq_int(&(kse)->k_waiting, 0) | 299#define KSE_CLEAR_WAIT(kse) atomic_store_rel_int(&(kse)->k_waiting, 0) |
298 299#define KSE_WAITING(kse) (kse)->k_waiting != 0 300#define KSE_WAKEUP(kse) kse_wakeup(&(kse)->k_mbx) 301 | 300 301#define KSE_WAITING(kse) (kse)->k_waiting != 0 302#define KSE_WAKEUP(kse) kse_wakeup(&(kse)->k_mbx) 303 |
304#define KSE_SET_IDLE(kse) ((kse)->k_idle = 1) 305#define KSE_CLEAR_IDLE(kse) ((kse)->k_idle = 0) 306#define KSE_IS_IDLE(kse) ((kse)->k_idle != 0) 307 |
|
302/* 303 * TailQ initialization values. 304 */ 305#define TAILQ_INITIALIZER { NULL, NULL } 306 307/* 308 * lock initialization values. 309 */ --- 343 unchanged lines hidden (view full) --- 653 sigset_t sigmask; 654 sigset_t sigpend; 655 int sigmask_seqno; 656 int check_pending; 657 int refcount; 658 659 /* Thread state: */ 660 enum pthread_state state; | 308/* 309 * TailQ initialization values. 310 */ 311#define TAILQ_INITIALIZER { NULL, NULL } 312 313/* 314 * lock initialization values. 315 */ --- 343 unchanged lines hidden (view full) --- 659 sigset_t sigmask; 660 sigset_t sigpend; 661 int sigmask_seqno; 662 int check_pending; 663 int refcount; 664 665 /* Thread state: */ 666 enum pthread_state state; |
667 int lock_switch; |
|
661 662 /* 663 * Number of microseconds accumulated by this thread when 664 * time slicing is active. 665 */ 666 long slice_usec; 667 668 /* --- 129 unchanged lines hidden (view full) --- 798 */ 799#define THR_IN_CRITICAL(thrd) \ 800 (((thrd)->locklevel > 0) || \ 801 ((thrd)->critical_count > 0)) 802 803#define THR_YIELD_CHECK(thrd) \ 804do { \ 805 if (((thrd)->critical_yield != 0) && \ | 668 669 /* 670 * Number of microseconds accumulated by this thread when 671 * time slicing is active. 672 */ 673 long slice_usec; 674 675 /* --- 129 unchanged lines hidden (view full) --- 805 */ 806#define THR_IN_CRITICAL(thrd) \ 807 (((thrd)->locklevel > 0) || \ 808 ((thrd)->critical_count > 0)) 809 810#define THR_YIELD_CHECK(thrd) \ 811do { \ 812 if (((thrd)->critical_yield != 0) && \ |
806 !(THR_IN_CRITICAL(thrd))) \ | 813 !(THR_IN_CRITICAL(thrd))) { \ 814 THR_LOCK_SWITCH(thrd); \ |
807 _thr_sched_switch(thrd); \ | 815 _thr_sched_switch(thrd); \ |
816 THR_UNLOCK_SWITCH(thrd); \ 817 } \ |
|
808 else if (((thrd)->check_pending != 0) && \ 809 !(THR_IN_CRITICAL(thrd))) \ 810 _thr_sig_check_pending(thrd); \ 811} while (0) 812 813#define THR_LOCK_ACQUIRE(thrd, lck) \ 814do { \ 815 if ((thrd)->locklevel >= MAX_THR_LOCKLEVEL) \ --- 7 unchanged lines hidden (view full) --- 823} while (0) 824 825#define THR_LOCK_RELEASE(thrd, lck) \ 826do { \ 827 if ((thrd)->locklevel > 0) { \ 828 _lock_release((lck), \ 829 &(thrd)->lockusers[(thrd)->locklevel - 1]); \ 830 (thrd)->locklevel--; \ | 818 else if (((thrd)->check_pending != 0) && \ 819 !(THR_IN_CRITICAL(thrd))) \ 820 _thr_sig_check_pending(thrd); \ 821} while (0) 822 823#define THR_LOCK_ACQUIRE(thrd, lck) \ 824do { \ 825 if ((thrd)->locklevel >= MAX_THR_LOCKLEVEL) \ --- 7 unchanged lines hidden (view full) --- 833} while (0) 834 835#define THR_LOCK_RELEASE(thrd, lck) \ 836do { \ 837 if ((thrd)->locklevel > 0) { \ 838 _lock_release((lck), \ 839 &(thrd)->lockusers[(thrd)->locklevel - 1]); \ 840 (thrd)->locklevel--; \ |
831 if ((thrd)->locklevel != 0) \ | 841 if ((thrd)->lock_switch) \ |
832 ; \ | 842 ; \ |
833 else if ((thrd)->critical_yield != 0) \ 834 _thr_sched_switch(thrd); \ 835 else if ((thrd)->check_pending != 0) \ 836 _thr_sig_check_pending(thrd); \ | 843 else { \ 844 THR_YIELD_CHECK(thrd); \ 845 } \ |
837 } \ 838} while (0) 839 | 846 } \ 847} while (0) 848 |
849#define THR_LOCK_SWITCH(thrd) \ 850do { \ 851 THR_ASSERT(!(thrd)->lock_switch, "context switch locked"); \ 852 _kse_critical_enter(); \ 853 KSE_SCHED_LOCK((thrd)->kse, (thrd)->kseg); \ 854 (thrd)->lock_switch = 1; \ 855} while (0) 856 857#define THR_UNLOCK_SWITCH(thrd) \ 858do { \ 859 THR_ASSERT((thrd)->lock_switch, "context switch not locked"); \ 860 THR_ASSERT(_kse_in_critical(), "Er,not in critical region"); \ 861 (thrd)->lock_switch = 0; \ 862 KSE_SCHED_UNLOCK((thrd)->kse, (thrd)->kseg); \ 863 _kse_critical_leave(&thrd->tmbx); \ 864} while (0) 865 |
|
840/* 841 * For now, threads will have their own lock separate from their 842 * KSE scheduling lock. 843 */ 844#define THR_LOCK(thr) THR_LOCK_ACQUIRE(thr, &(thr)->lock) 845#define THR_UNLOCK(thr) THR_LOCK_RELEASE(thr, &(thr)->lock) 846#define THR_THREAD_LOCK(curthrd, thr) THR_LOCK_ACQUIRE(curthrd, &(thr)->lock) 847#define THR_THREAD_UNLOCK(curthrd, thr) THR_LOCK_RELEASE(curthrd, &(thr)->lock) --- 54 unchanged lines hidden (view full) --- 902 (curthr)->locklevel++; \ 903 KSE_SCHED_LOCK((curthr)->kse, (thr)->kseg); \ 904} while (0) 905 906#define THR_SCHED_UNLOCK(curthr, thr) do { \ 907 KSE_SCHED_UNLOCK((curthr)->kse, (thr)->kseg); \ 908 (curthr)->locklevel--; \ 909 _kse_critical_leave((curthr)->critical[(curthr)->locklevel]); \ | 866/* 867 * For now, threads will have their own lock separate from their 868 * KSE scheduling lock. 869 */ 870#define THR_LOCK(thr) THR_LOCK_ACQUIRE(thr, &(thr)->lock) 871#define THR_UNLOCK(thr) THR_LOCK_RELEASE(thr, &(thr)->lock) 872#define THR_THREAD_LOCK(curthrd, thr) THR_LOCK_ACQUIRE(curthrd, &(thr)->lock) 873#define THR_THREAD_UNLOCK(curthrd, thr) THR_LOCK_RELEASE(curthrd, &(thr)->lock) --- 54 unchanged lines hidden (view full) --- 928 (curthr)->locklevel++; \ 929 KSE_SCHED_LOCK((curthr)->kse, (thr)->kseg); \ 930} while (0) 931 932#define THR_SCHED_UNLOCK(curthr, thr) do { \ 933 KSE_SCHED_UNLOCK((curthr)->kse, (thr)->kseg); \ 934 (curthr)->locklevel--; \ 935 _kse_critical_leave((curthr)->critical[(curthr)->locklevel]); \ |
910 if ((curthr)->locklevel == 0) \ 911 THR_YIELD_CHECK(curthr); \ | |
912} while (0) 913 914#define THR_CRITICAL_ENTER(thr) (thr)->critical_count++ 915#define THR_CRITICAL_LEAVE(thr) do { \ 916 (thr)->critical_count--; \ 917 if (((thr)->critical_yield != 0) && \ 918 ((thr)->critical_count == 0)) { \ 919 (thr)->critical_yield = 0; \ | 936} while (0) 937 938#define THR_CRITICAL_ENTER(thr) (thr)->critical_count++ 939#define THR_CRITICAL_LEAVE(thr) do { \ 940 (thr)->critical_count--; \ 941 if (((thr)->critical_yield != 0) && \ 942 ((thr)->critical_count == 0)) { \ 943 (thr)->critical_yield = 0; \ |
944 THR_LOCK_SWITCH(thr); \ |
|
920 _thr_sched_switch(thr); \ | 945 _thr_sched_switch(thr); \ |
946 THR_UNLOCK_SWITCH(thr); \ |
|
921 } \ 922} while (0) 923 924#define THR_IS_ACTIVE(thrd) \ 925 ((thrd)->kse != NULL) && ((thrd)->kse->k_curthread == (thrd)) 926 927#define THR_IN_SYNCQ(thrd) (((thrd)->sflags & THR_FLAGS_IN_SYNCQ) != 0) 928 --- 158 unchanged lines hidden (view full) --- 1087void _thr_sig_rundown(struct pthread *, ucontext_t *, 1088 struct pthread_sigframe *); 1089void _thr_sig_send(struct pthread *pthread, int sig); 1090void _thr_sig_wrapper(void); 1091void _thr_sigframe_restore(struct pthread *thread, struct pthread_sigframe *psf); 1092void _thr_seterrno(struct pthread *, int); 1093void _thr_enter_cancellation_point(struct pthread *); 1094void _thr_leave_cancellation_point(struct pthread *); | 947 } \ 948} while (0) 949 950#define THR_IS_ACTIVE(thrd) \ 951 ((thrd)->kse != NULL) && ((thrd)->kse->k_curthread == (thrd)) 952 953#define THR_IN_SYNCQ(thrd) (((thrd)->sflags & THR_FLAGS_IN_SYNCQ) != 0) 954 --- 158 unchanged lines hidden (view full) --- 1113void _thr_sig_rundown(struct pthread *, ucontext_t *, 1114 struct pthread_sigframe *); 1115void _thr_sig_send(struct pthread *pthread, int sig); 1116void _thr_sig_wrapper(void); 1117void _thr_sigframe_restore(struct pthread *thread, struct pthread_sigframe *psf); 1118void _thr_seterrno(struct pthread *, int); 1119void _thr_enter_cancellation_point(struct pthread *); 1120void _thr_leave_cancellation_point(struct pthread *); |
1121int _thr_setconcurrency(int new_level); 1122int _thr_setmaxconcurrency(void); |
|
1095 1096/* XXX - Stuff that goes away when my sources get more up to date. */ 1097/* #include <sys/kse.h> */ 1098#ifdef SYS_KSE_H 1099int __sys_kse_create(struct kse_mailbox *, int); 1100int __sys_kse_thr_wakeup(struct kse_mailbox *); 1101int __sys_kse_exit(struct kse_mailbox *); 1102int __sys_kse_release(struct kse_mailbox *); --- 75 unchanged lines hidden --- | 1123 1124/* XXX - Stuff that goes away when my sources get more up to date. */ 1125/* #include <sys/kse.h> */ 1126#ifdef SYS_KSE_H 1127int __sys_kse_create(struct kse_mailbox *, int); 1128int __sys_kse_thr_wakeup(struct kse_mailbox *); 1129int __sys_kse_exit(struct kse_mailbox *); 1130int __sys_kse_release(struct kse_mailbox *); --- 75 unchanged lines hidden --- |