Changes in kernel/generic/src/synch/spinlock.c [90c8b8d:98000fb] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/synch/spinlock.c
r90c8b8d r98000fb 45 45 #include <symtab.h> 46 46 47 #ifdef CONFIG_FB 48 #include <genarch/fb/fb.h> 49 #endif 50 47 51 #ifdef CONFIG_SMP 48 52 49 53 /** Initialize spinlock 50 54 * 55 * Initialize spinlock. 56 * 51 57 * @param sl Pointer to spinlock_t structure. 52 *53 58 */ 54 void spinlock_initialize(spinlock_t * lock, char *name)59 void spinlock_initialize(spinlock_t *sl, char *name) 55 60 { 56 atomic_set(& lock->val, 0);61 atomic_set(&sl->val, 0); 57 62 #ifdef CONFIG_DEBUG_SPINLOCK 58 lock->name = name;59 #endif 63 sl->name = name; 64 #endif 60 65 } 61 62 #ifdef CONFIG_DEBUG_SPINLOCK63 66 64 67 /** Lock spinlock … … 68 71 * possible occurence of deadlock. 69 72 * 70 * @param lock Pointer to spinlock_t structure. 71 * 73 * @param sl Pointer to spinlock_t structure. 72 74 */ 73 void spinlock_lock_debug(spinlock_t *lock) 75 #ifdef CONFIG_DEBUG_SPINLOCK 76 void spinlock_lock_debug(spinlock_t *sl) 74 77 { 75 78 size_t i = 0; 76 79 bool deadlock_reported = false; 77 80 78 81 preemption_disable(); 79 while (test_and_set(&lock->val)) { 82 while (test_and_set(&sl->val)) { 83 80 84 /* 81 * We need to be careful about particular locks 82 * which are directly used to report deadlocks 83 * via printf() (and recursively other functions). 84 * This conserns especially printf_lock and the 85 * framebuffer lock. 85 * We need to be careful about printf_lock and fb_lock. 86 * Both of them are used to report deadlocks via 87 * printf() and fb_putchar(). 86 88 * 87 * Any lock whose name is prefixed by "*" will be88 * ignored by this deadlock detection routine89 * as this might cause an infinite recursion.90 89 * We trust our code that there is no possible deadlock 91 * caused by these locks (except when an exception 92 * is triggered for instance by printf()). 90 * caused by these two locks (except when an exception 91 * is triggered for instance by printf() or fb_putchar()). 92 * However, we encountered false positives caused by very 93 * slow VESA framebuffer interaction (especially when 94 * run in a simulator) that caused problems with both 95 * printf_lock and fb_lock. 93 96 * 94 * We encountered false positives caused by very 95 * slow framebuffer interaction (especially when 96 * run in a simulator) that caused problems with both 97 * printf_lock and the framebuffer lock. 98 * 97 * Possible deadlocks on both printf_lock and fb_lock 98 * are therefore not reported as they would cause an 99 * infinite recursion. 99 100 */ 100 if ( lock->name[0] == '*')101 if (sl == &printf_lock) 101 102 continue; 102 103 #ifdef CONFIG_FB 104 if (sl == &fb_lock) 105 continue; 106 #endif 103 107 if (i++ > DEADLOCK_THRESHOLD) { 104 108 printf("cpu%u: looping on spinlock %" PRIp ":%s, " 105 "caller=%" PRIp "(%s)\n", CPU->id, lock, lock->name,109 "caller=%" PRIp "(%s)\n", CPU->id, sl, sl->name, 106 110 CALLER, symtab_fmt_name_lookup(CALLER)); 107 111 … … 110 114 } 111 115 } 112 116 113 117 if (deadlock_reported) 114 118 printf("cpu%u: not deadlocked\n", CPU->id); 115 119 116 120 /* 117 121 * Prevent critical section code from bleeding out this way up. … … 119 123 CS_ENTER_BARRIER(); 120 124 } 121 122 125 #endif 123 126 … … 128 131 * signal failure. 129 132 * 130 * @param lockPointer to spinlock_t structure.133 * @param sl Pointer to spinlock_t structure. 131 134 * 132 135 * @return Zero on failure, non-zero otherwise. 133 *134 136 */ 135 int spinlock_trylock(spinlock_t * lock)137 int spinlock_trylock(spinlock_t *sl) 136 138 { 139 int rc; 140 137 141 preemption_disable(); 138 int rc = !test_and_set(&lock->val);139 142 rc = !test_and_set(&sl->val); 143 140 144 /* 141 145 * Prevent critical section code from bleeding out this way up. 142 146 */ 143 147 CS_ENTER_BARRIER(); 144 148 145 149 if (!rc) 146 150 preemption_enable();
Note:
See TracChangeset
for help on using the changeset viewer.