subr_turnstile.c (70861) | subr_turnstile.c (71228) |
---|---|
1/*- 2 * Copyright (c) 1998 Berkeley Software Design, Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. --- 13 unchanged lines hidden (view full) --- 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * from BSDI $Id: mutex_witness.c,v 1.1.2.20 2000/04/27 03:10:27 cp Exp $ 29 * and BSDI $Id: synch_machdep.c,v 2.3.2.39 2000/04/27 03:10:25 cp Exp $ | 1/*- 2 * Copyright (c) 1998 Berkeley Software Design, Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. --- 13 unchanged lines hidden (view full) --- 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 * 28 * from BSDI $Id: mutex_witness.c,v 1.1.2.20 2000/04/27 03:10:27 cp Exp $ 29 * and BSDI $Id: synch_machdep.c,v 2.3.2.39 2000/04/27 03:10:25 cp Exp $ |
30 * $FreeBSD: head/sys/kern/subr_turnstile.c 70861 2001-01-10 04:43:51Z jake $ | 30 * $FreeBSD: head/sys/kern/subr_turnstile.c 71228 2001-01-19 01:59:14Z bmilekic $ |
31 */ 32 33/* 34 * Main Entry: witness 35 * Pronunciation: 'wit-n&s 36 * Function: noun 37 * Etymology: Middle English witnesse, from Old English witnes knowledge, 38 * testimony, witness, from 2wit --- 215 unchanged lines hidden (view full) --- 254 struct proc *p = CURPROC; 255 256 KASSERT(p != NULL, ("curproc is NULL in mutex")); 257 258 switch (type) { 259 case MTX_DEF: 260 if ((m->mtx_lock & MTX_FLAGMASK) == (uintptr_t)p) { 261 m->mtx_recurse++; | 31 */ 32 33/* 34 * Main Entry: witness 35 * Pronunciation: 'wit-n&s 36 * Function: noun 37 * Etymology: Middle English witnesse, from Old English witnes knowledge, 38 * testimony, witness, from 2wit --- 215 unchanged lines hidden (view full) --- 254 struct proc *p = CURPROC; 255 256 KASSERT(p != NULL, ("curproc is NULL in mutex")); 257 258 switch (type) { 259 case MTX_DEF: 260 if ((m->mtx_lock & MTX_FLAGMASK) == (uintptr_t)p) { 261 m->mtx_recurse++; |
262 atomic_set_ptr(&m->mtx_lock, MTX_RECURSE); | 262 atomic_set_ptr(&m->mtx_lock, MTX_RECURSED); |
263 if ((type & MTX_QUIET) == 0) 264 CTR1(KTR_LOCK, "mtx_enter: 0x%p recurse", m); 265 return; 266 } 267 if ((type & MTX_QUIET) == 0) 268 CTR3(KTR_LOCK, 269 "mtx_enter: 0x%p contested (lock=%p) [0x%p]", 270 m, (void *)m->mtx_lock, (void *)RETIP(m)); --- 158 unchanged lines hidden (view full) --- 429 struct proc *p, *p1; 430 struct mtx *m1; 431 int pri; 432 433 p = CURPROC; 434 switch (type) { 435 case MTX_DEF: 436 case MTX_DEF | MTX_NOSWITCH: | 263 if ((type & MTX_QUIET) == 0) 264 CTR1(KTR_LOCK, "mtx_enter: 0x%p recurse", m); 265 return; 266 } 267 if ((type & MTX_QUIET) == 0) 268 CTR3(KTR_LOCK, 269 "mtx_enter: 0x%p contested (lock=%p) [0x%p]", 270 m, (void *)m->mtx_lock, (void *)RETIP(m)); --- 158 unchanged lines hidden (view full) --- 429 struct proc *p, *p1; 430 struct mtx *m1; 431 int pri; 432 433 p = CURPROC; 434 switch (type) { 435 case MTX_DEF: 436 case MTX_DEF | MTX_NOSWITCH: |
437 if (m->mtx_recurse != 0) { | 437 if (mtx_recursed(m)) { |
438 if (--(m->mtx_recurse) == 0) | 438 if (--(m->mtx_recurse) == 0) |
439 atomic_clear_ptr(&m->mtx_lock, MTX_RECURSE); | 439 atomic_clear_ptr(&m->mtx_lock, MTX_RECURSED); |
440 if ((type & MTX_QUIET) == 0) 441 CTR1(KTR_LOCK, "mtx_exit: 0x%p unrecurse", m); 442 return; 443 } 444 mtx_enter(&sched_lock, MTX_SPIN); 445 if ((type & MTX_QUIET) == 0) 446 CTR1(KTR_LOCK, "mtx_exit: 0x%p contested", m); 447 p1 = TAILQ_FIRST(&m->mtx_blocked); --- 48 unchanged lines hidden (view full) --- 496 CTR2(KTR_LOCK, 497 "mtx_exit: 0x%p resuming lock=0x%p", 498 m, (void *)m->mtx_lock); 499 } 500 mtx_exit(&sched_lock, MTX_SPIN); 501 break; 502 case MTX_SPIN: 503 case MTX_SPIN | MTX_FIRST: | 440 if ((type & MTX_QUIET) == 0) 441 CTR1(KTR_LOCK, "mtx_exit: 0x%p unrecurse", m); 442 return; 443 } 444 mtx_enter(&sched_lock, MTX_SPIN); 445 if ((type & MTX_QUIET) == 0) 446 CTR1(KTR_LOCK, "mtx_exit: 0x%p contested", m); 447 p1 = TAILQ_FIRST(&m->mtx_blocked); --- 48 unchanged lines hidden (view full) --- 496 CTR2(KTR_LOCK, 497 "mtx_exit: 0x%p resuming lock=0x%p", 498 m, (void *)m->mtx_lock); 499 } 500 mtx_exit(&sched_lock, MTX_SPIN); 501 break; 502 case MTX_SPIN: 503 case MTX_SPIN | MTX_FIRST: |
504 if (m->mtx_recurse != 0) { | 504 if (mtx_recursed(m)) { |
505 m->mtx_recurse--; 506 return; 507 } 508 MPASS(mtx_owned(m)); 509 _release_lock_quick(m); 510 if (type & MTX_FIRST) 511 enable_intr(); /* XXX is this kosher? */ 512 else { 513 MPASS(m->mtx_saveintr != 0xbeefface); 514 restore_intr(m->mtx_saveintr); 515 } 516 break; 517 case MTX_SPIN | MTX_TOPHALF: | 505 m->mtx_recurse--; 506 return; 507 } 508 MPASS(mtx_owned(m)); 509 _release_lock_quick(m); 510 if (type & MTX_FIRST) 511 enable_intr(); /* XXX is this kosher? */ 512 else { 513 MPASS(m->mtx_saveintr != 0xbeefface); 514 restore_intr(m->mtx_saveintr); 515 } 516 break; 517 case MTX_SPIN | MTX_TOPHALF: |
518 if (m->mtx_recurse != 0) { | 518 if (mtx_recursed(m)) { |
519 m->mtx_recurse--; 520 return; 521 } 522 MPASS(mtx_owned(m)); 523 _release_lock_quick(m); 524 break; 525 default: 526 panic("mtx_exit_hard: unsupported type 0x%x\n", type); --- 123 unchanged lines hidden (view full) --- 650#ifdef MUTEX_DEBUG 651 if (m->mtx_next == NULL) 652 panic("mtx_destroy: %p (%s) already destroyed", 653 m, m->mtx_description); 654 655 if (!mtx_owned(m)) { 656 MPASS(m->mtx_lock == MTX_UNOWNED); 657 } else { | 519 m->mtx_recurse--; 520 return; 521 } 522 MPASS(mtx_owned(m)); 523 _release_lock_quick(m); 524 break; 525 default: 526 panic("mtx_exit_hard: unsupported type 0x%x\n", type); --- 123 unchanged lines hidden (view full) --- 650#ifdef MUTEX_DEBUG 651 if (m->mtx_next == NULL) 652 panic("mtx_destroy: %p (%s) already destroyed", 653 m, m->mtx_description); 654 655 if (!mtx_owned(m)) { 656 MPASS(m->mtx_lock == MTX_UNOWNED); 657 } else { |
658 MPASS((m->mtx_lock & (MTX_RECURSE|MTX_CONTESTED)) == 0); | 658 MPASS((m->mtx_lock & (MTX_RECURSED|MTX_CONTESTED)) == 0); |
659 } 660 mtx_validate(m, MV_DESTROY); /* diagnostic */ 661#endif 662 663#ifdef WITNESS 664 if (m->mtx_witness) 665 witness_destroy(m); 666#endif /* WITNESS */ --- 29 unchanged lines hidden (view full) --- 696 const char *w_description; 697 const char *w_file; 698 int w_line; 699 struct witness *w_morechildren; 700 u_char w_childcnt; 701 u_char w_Giant_squawked:1; 702 u_char w_other_squawked:1; 703 u_char w_same_squawked:1; | 659 } 660 mtx_validate(m, MV_DESTROY); /* diagnostic */ 661#endif 662 663#ifdef WITNESS 664 if (m->mtx_witness) 665 witness_destroy(m); 666#endif /* WITNESS */ --- 29 unchanged lines hidden (view full) --- 696 const char *w_description; 697 const char *w_file; 698 int w_line; 699 struct witness *w_morechildren; 700 u_char w_childcnt; 701 u_char w_Giant_squawked:1; 702 u_char w_other_squawked:1; 703 u_char w_same_squawked:1; |
704 u_char w_sleep:1; 705 u_char w_spin:1; /* this is a spin mutex */ | 704 u_char w_sleep:1; /* MTX_DEF type mutex. */ 705 u_char w_spin:1; /* MTX_SPIN type mutex. */ 706 u_char w_recurse:1; /* MTX_RECURSE mutex option. */ |
706 u_int w_level; 707 struct witness *w_children[WITNESS_NCHILDREN]; 708}; 709 710struct witness_blessed { 711 char *b_lock1; 712 char *b_lock2; 713}; --- 119 unchanged lines hidden (view full) --- 833#endif /* DDB */ 834 835 if (panicstr) 836 return; 837 w = m->mtx_witness; 838 p = CURPROC; 839 840 if (flags & MTX_SPIN) { | 707 u_int w_level; 708 struct witness *w_children[WITNESS_NCHILDREN]; 709}; 710 711struct witness_blessed { 712 char *b_lock1; 713 char *b_lock2; 714}; --- 119 unchanged lines hidden (view full) --- 834#endif /* DDB */ 835 836 if (panicstr) 837 return; 838 w = m->mtx_witness; 839 p = CURPROC; 840 841 if (flags & MTX_SPIN) { |
841 if (!w->w_spin) | 842 if (!(w->w_spin)) |
842 panic("mutex_enter: MTX_SPIN on MTX_DEF mutex %s @" 843 " %s:%d", m->mtx_description, file, line); | 843 panic("mutex_enter: MTX_SPIN on MTX_DEF mutex %s @" 844 " %s:%d", m->mtx_description, file, line); |
844 if (m->mtx_recurse != 0) | 845 if (mtx_recursed(m)) { 846 if (!(w->w_recurse)) 847 panic("mutex_enter: recursion on non-recursive" 848 " mutex %s @ %s:%d", m->mtx_description, 849 file, line); |
845 return; | 850 return; |
851 } |
|
846 mtx_enter(&w_mtx, MTX_SPIN | MTX_QUIET); 847 i = PCPU_GET(witness_spin_check); 848 if (i != 0 && w->w_level < i) { 849 mtx_exit(&w_mtx, MTX_SPIN | MTX_QUIET); 850 panic("mutex_enter(%s:%x, MTX_SPIN) out of order @" 851 " %s:%d already holding %s:%x", 852 m->mtx_description, w->w_level, file, line, 853 spin_order_list[ffs(i)-1], i); --- 5 unchanged lines hidden (view full) --- 859 m->mtx_line = line; 860 m->mtx_file = file; 861 return; 862 } 863 if (w->w_spin) 864 panic("mutex_enter: MTX_DEF on MTX_SPIN mutex %s @ %s:%d", 865 m->mtx_description, file, line); 866 | 852 mtx_enter(&w_mtx, MTX_SPIN | MTX_QUIET); 853 i = PCPU_GET(witness_spin_check); 854 if (i != 0 && w->w_level < i) { 855 mtx_exit(&w_mtx, MTX_SPIN | MTX_QUIET); 856 panic("mutex_enter(%s:%x, MTX_SPIN) out of order @" 857 " %s:%d already holding %s:%x", 858 m->mtx_description, w->w_level, file, line, 859 spin_order_list[ffs(i)-1], i); --- 5 unchanged lines hidden (view full) --- 865 m->mtx_line = line; 866 m->mtx_file = file; 867 return; 868 } 869 if (w->w_spin) 870 panic("mutex_enter: MTX_DEF on MTX_SPIN mutex %s @ %s:%d", 871 m->mtx_description, file, line); 872 |
867 if (m->mtx_recurse != 0) | 873 if (mtx_recursed(m)) { 874 if (!(w->w_recurse)) 875 panic("mutex_enter: recursion on non-recursive" 876 " mutex %s @ %s:%d", m->mtx_description, 877 file, line); |
868 return; | 878 return; |
879 } |
|
869 if (witness_dead) 870 goto out; 871 if (cold) 872 goto out; 873 874 if (!mtx_legal2block()) 875 panic("blockable mtx_enter() of %s when not legal @ %s:%d", 876 m->mtx_description, file, line); --- 89 unchanged lines hidden (view full) --- 966{ 967 struct witness *w; 968 969 if (panicstr) 970 return; 971 w = m->mtx_witness; 972 973 if (flags & MTX_SPIN) { | 880 if (witness_dead) 881 goto out; 882 if (cold) 883 goto out; 884 885 if (!mtx_legal2block()) 886 panic("blockable mtx_enter() of %s when not legal @ %s:%d", 887 m->mtx_description, file, line); --- 89 unchanged lines hidden (view full) --- 977{ 978 struct witness *w; 979 980 if (panicstr) 981 return; 982 w = m->mtx_witness; 983 984 if (flags & MTX_SPIN) { |
974 if (!w->w_spin) | 985 if (!(w->w_spin)) |
975 panic("mutex_exit: MTX_SPIN on MTX_DEF mutex %s @" 976 " %s:%d", m->mtx_description, file, line); | 986 panic("mutex_exit: MTX_SPIN on MTX_DEF mutex %s @" 987 " %s:%d", m->mtx_description, file, line); |
977 if (m->mtx_recurse != 0) | 988 if (mtx_recursed(m)) { 989 if (!(w->w_recurse)) 990 panic("mutex_exit: recursion on non-recursive" 991 " mutex %s @ %s:%d", m->mtx_description, 992 file, line); |
978 return; | 993 return; |
994 } |
|
979 mtx_enter(&w_mtx, MTX_SPIN | MTX_QUIET); 980 PCPU_SET(witness_spin_check, 981 PCPU_GET(witness_spin_check) & ~w->w_level); 982 mtx_exit(&w_mtx, MTX_SPIN | MTX_QUIET); 983 return; 984 } 985 if (w->w_spin) 986 panic("mutex_exit: MTX_DEF on MTX_SPIN mutex %s @ %s:%d", 987 m->mtx_description, file, line); 988 | 995 mtx_enter(&w_mtx, MTX_SPIN | MTX_QUIET); 996 PCPU_SET(witness_spin_check, 997 PCPU_GET(witness_spin_check) & ~w->w_level); 998 mtx_exit(&w_mtx, MTX_SPIN | MTX_QUIET); 999 return; 1000 } 1001 if (w->w_spin) 1002 panic("mutex_exit: MTX_DEF on MTX_SPIN mutex %s @ %s:%d", 1003 m->mtx_description, file, line); 1004 |
989 if (m->mtx_recurse != 0) | 1005 if (mtx_recursed(m)) { 1006 if (!(w->w_recurse)) 1007 panic("mutex_exit: recursion on non-recursive" 1008 " mutex %s @ %s:%d", m->mtx_description, 1009 file, line); |
990 return; | 1010 return; |
1011 } |
|
991 992 if ((flags & MTX_NOSWITCH) == 0 && !mtx_legal2block() && !cold) 993 panic("switchable mtx_exit() of %s when not legal @ %s:%d", 994 m->mtx_description, file, line); 995 LIST_REMOVE(m, mtx_held); 996 m->mtx_held.le_prev = NULL; 997} 998 999void 1000witness_try_enter(struct mtx *m, int flags, const char *file, int line) 1001{ 1002 struct proc *p; 1003 struct witness *w = m->mtx_witness; 1004 1005 if (panicstr) 1006 return; 1007 if (flags & MTX_SPIN) { | 1012 1013 if ((flags & MTX_NOSWITCH) == 0 && !mtx_legal2block() && !cold) 1014 panic("switchable mtx_exit() of %s when not legal @ %s:%d", 1015 m->mtx_description, file, line); 1016 LIST_REMOVE(m, mtx_held); 1017 m->mtx_held.le_prev = NULL; 1018} 1019 1020void 1021witness_try_enter(struct mtx *m, int flags, const char *file, int line) 1022{ 1023 struct proc *p; 1024 struct witness *w = m->mtx_witness; 1025 1026 if (panicstr) 1027 return; 1028 if (flags & MTX_SPIN) { |
1008 if (!w->w_spin) | 1029 if (!(w->w_spin)) |
1009 panic("mutex_try_enter: " 1010 "MTX_SPIN on MTX_DEF mutex %s @ %s:%d", 1011 m->mtx_description, file, line); | 1030 panic("mutex_try_enter: " 1031 "MTX_SPIN on MTX_DEF mutex %s @ %s:%d", 1032 m->mtx_description, file, line); |
1012 if (m->mtx_recurse != 0) | 1033 if (mtx_recursed(m)) { 1034 if (!(w->w_recurse)) 1035 panic("mutex_try_enter: recursion on" 1036 " non-recursive mutex %s @ %s:%d", 1037 m->mtx_description, file, line); |
1013 return; | 1038 return; |
1039 } |
|
1014 mtx_enter(&w_mtx, MTX_SPIN | MTX_QUIET); 1015 PCPU_SET(witness_spin_check, 1016 PCPU_GET(witness_spin_check) | w->w_level); 1017 mtx_exit(&w_mtx, MTX_SPIN | MTX_QUIET); 1018 w->w_file = file; 1019 w->w_line = line; 1020 m->mtx_line = line; 1021 m->mtx_file = file; 1022 return; 1023 } 1024 1025 if (w->w_spin) 1026 panic("mutex_try_enter: MTX_DEF on MTX_SPIN mutex %s @ %s:%d", 1027 m->mtx_description, file, line); 1028 | 1040 mtx_enter(&w_mtx, MTX_SPIN | MTX_QUIET); 1041 PCPU_SET(witness_spin_check, 1042 PCPU_GET(witness_spin_check) | w->w_level); 1043 mtx_exit(&w_mtx, MTX_SPIN | MTX_QUIET); 1044 w->w_file = file; 1045 w->w_line = line; 1046 m->mtx_line = line; 1047 m->mtx_file = file; 1048 return; 1049 } 1050 1051 if (w->w_spin) 1052 panic("mutex_try_enter: MTX_DEF on MTX_SPIN mutex %s @ %s:%d", 1053 m->mtx_description, file, line); 1054 |
1029 if (m->mtx_recurse != 0) | 1055 if (mtx_recursed(m)) { 1056 if (!(w->w_recurse)) 1057 panic("mutex_try_enter: recursion on non-recursive" 1058 " mutex %s @ %s:%d", m->mtx_description, file, 1059 line); |
1030 return; | 1060 return; |
1031 | 1061 } |
1032 w->w_file = file; 1033 w->w_line = line; 1034 m->mtx_line = line; 1035 m->mtx_file = file; 1036 p = CURPROC; 1037 MPASS(m->mtx_held.le_prev == NULL); 1038 LIST_INSERT_HEAD(&p->p_heldmtx, (struct mtx*)m, mtx_held); 1039} --- 111 unchanged lines hidden (view full) --- 1151 for (order = spin_order_list; *order != NULL; order++) { 1152 if (strcmp(description, *order) == 0) 1153 break; 1154 i <<= 1; 1155 } 1156 if (*order == NULL) 1157 panic("spin lock %s not in order list", description); 1158 w->w_level = i; | 1062 w->w_file = file; 1063 w->w_line = line; 1064 m->mtx_line = line; 1065 m->mtx_file = file; 1066 p = CURPROC; 1067 MPASS(m->mtx_held.le_prev == NULL); 1068 LIST_INSERT_HEAD(&p->p_heldmtx, (struct mtx*)m, mtx_held); 1069} --- 111 unchanged lines hidden (view full) --- 1181 for (order = spin_order_list; *order != NULL; order++) { 1182 if (strcmp(description, *order) == 0) 1183 break; 1184 i <<= 1; 1185 } 1186 if (*order == NULL) 1187 panic("spin lock %s not in order list", description); 1188 w->w_level = i; |
1159 } | 1189 } else 1190 w->w_sleep = 1; 1191 1192 if (flag & MTX_RECURSE) 1193 w->w_recurse = 1; 1194 |
1160 return (w); 1161} 1162 1163static int 1164itismychild(struct witness *parent, struct witness *child) 1165{ 1166 static int recursed; 1167 --- 97 unchanged lines hidden (view full) --- 1265} 1266 1267void 1268witness_levelall (void) 1269{ 1270 struct witness *w, *w1; 1271 1272 for (w = w_all; w; w = w->w_next) | 1195 return (w); 1196} 1197 1198static int 1199itismychild(struct witness *parent, struct witness *child) 1200{ 1201 static int recursed; 1202 --- 97 unchanged lines hidden (view full) --- 1300} 1301 1302void 1303witness_levelall (void) 1304{ 1305 struct witness *w, *w1; 1306 1307 for (w = w_all; w; w = w->w_next) |
1273 if (!w->w_spin) | 1308 if (!(w->w_spin)) |
1274 w->w_level = 0; 1275 for (w = w_all; w; w = w->w_next) { 1276 if (w->w_spin) 1277 continue; 1278 for (w1 = w_all; w1; w1 = w1->w_next) { 1279 if (isitmychild(w1, w)) 1280 break; 1281 } --- 134 unchanged lines hidden --- | 1309 w->w_level = 0; 1310 for (w = w_all; w; w = w->w_next) { 1311 if (w->w_spin) 1312 continue; 1313 for (w1 = w_all; w1; w1 = w1->w_next) { 1314 if (isitmychild(w1, w)) 1315 break; 1316 } --- 134 unchanged lines hidden --- |