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