Changeset deada67 in mainline for kernel/test/synch
- Timestamp:
- 2006-12-19T17:54:50Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 730376d
- Parents:
- 6536a4a9
- Location:
- kernel/test/synch
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/test/synch/rwlock1.c
r6536a4a9 rdeada67 60 60 rwlock_read_unlock(&rwlock); 61 61 62 63 62 rwlock_write_lock(&rwlock); 64 63 rwlock_write_unlock(&rwlock); -
kernel/test/synch/rwlock2.c
r6536a4a9 rdeada67 39 39 40 40 static rwlock_t rwlock; 41 static bool sh_quiet; 41 42 42 43 static void writer(void *arg) 43 44 { 44 45 thread_detach(THREAD); 46 47 printf("Trying to lock rwlock for writing....\n"); 48 45 if (!sh_quiet) 46 printf("Trying to lock rwlock for writing....\n"); 47 49 48 rwlock_write_lock(&rwlock); 50 49 rwlock_write_unlock(&rwlock); 51 50 52 printf("Trying to lock rwlock for reading....\n"); 51 if (!sh_quiet) 52 printf("Trying to lock rwlock for reading....\n"); 53 53 54 rwlock_read_lock(&rwlock); 54 55 rwlock_read_unlock(&rwlock); 55 printf("Test passed.\n");56 56 } 57 57 … … 59 59 { 60 60 thread_t *thrd; 61 sh_quiet = quiet; 61 62 62 63 rwlock_initialize(&rwlock); … … 80 81 rwlock_read_unlock(&rwlock); 81 82 83 thread_join(thrd); 84 thread_detach(thrd); 85 82 86 return NULL; 83 87 } -
kernel/test/synch/rwlock3.c
r6536a4a9 rdeada67 35 35 #include <synch/rwlock.h> 36 36 37 #define READERS 50 38 #define WRITERS 50 37 #define THREADS 4 39 38 39 static atomic_t thread_count; 40 40 static rwlock_t rwlock; 41 static bool sh_quiet; 41 42 42 43 static void reader(void *arg) 43 44 { 44 45 thread_detach(THREAD); 45 46 printf("cpu%d, tid %d: trying to lock rwlock for reading....\n", CPU->id, THREAD->tid); 46 47 if (!sh_quiet) 48 printf("cpu%d, tid %d: trying to lock rwlock for reading....\n", CPU->id, THREAD->tid); 49 47 50 rwlock_read_lock(&rwlock); 48 rwlock_read_unlock(&rwlock); 49 printf("cpu%d, tid %d: success\n", CPU->id, THREAD->tid); 50 51 printf("cpu%d, tid %d: trying to lock rwlock for writing....\n", CPU->id, THREAD->tid); 51 rwlock_read_unlock(&rwlock); 52 53 if (!sh_quiet) { 54 printf("cpu%d, tid %d: success\n", CPU->id, THREAD->tid); 55 printf("cpu%d, tid %d: trying to lock rwlock for writing....\n", CPU->id, THREAD->tid); 56 } 52 57 53 58 rwlock_write_lock(&rwlock); 54 59 rwlock_write_unlock(&rwlock); 55 printf("cpu%d, tid %d: success\n", CPU->id, THREAD->tid); 60 61 if (!sh_quiet) 62 printf("cpu%d, tid %d: success\n", CPU->id, THREAD->tid); 63 64 atomic_dec(&thread_count); 56 65 } 57 66 … … 60 69 int i; 61 70 thread_t *thrd; 71 sh_quiet = quiet; 72 73 atomic_set(&thread_count, THREADS); 62 74 63 75 rwlock_initialize(&rwlock); 64 76 rwlock_write_lock(&rwlock); 65 77 66 for (i = 0; i < 4; i++) {78 for (i = 0; i < THREADS; i++) { 67 79 thrd = thread_create(reader, NULL, TASK, 0, "reader", false); 68 80 if (thrd) 69 81 thread_ready(thrd); 70 else 82 else if (!quiet) 71 83 printf("Could not create reader %d\n", i); 72 84 } 73 85 74 86 thread_sleep(1); 87 rwlock_write_unlock(&rwlock); 75 88 76 rwlock_write_unlock(&rwlock); 89 while (atomic_get(&thread_count) > 0) { 90 if (!quiet) 91 printf("Threads left: %d\n", atomic_get(&thread_count)); 92 thread_sleep(1); 93 } 77 94 78 95 return NULL; -
kernel/test/synch/rwlock4.c
r6536a4a9 rdeada67 44 44 #define WRITERS 50 45 45 46 static atomic_t thread_count; 46 47 static rwlock_t rwlock; 47 48 static atomic_t threads_fault; 49 static bool sh_quiet; 48 50 49 51 SPINLOCK_INITIALIZE(rw_lock); … … 71 73 72 74 to = random(40000); 73 printf("cpu%d, tid %d w+ (%d)\n", CPU->id, THREAD->tid, to); 75 76 if (!sh_quiet) 77 printf("cpu%d, tid %d w+ (%d)\n", CPU->id, THREAD->tid, to); 78 74 79 rc = rwlock_write_lock_timeout(&rwlock, to); 75 80 if (SYNCH_FAILED(rc)) { 76 printf("cpu%d, tid %d w!\n", CPU->id, THREAD->tid); 81 if (!sh_quiet) 82 printf("cpu%d, tid %d w!\n", CPU->id, THREAD->tid); 83 atomic_dec(&thread_count); 77 84 return; 78 85 } 79 printf("cpu%d, tid %d w=\n", CPU->id, THREAD->tid); 86 87 if (!sh_quiet) 88 printf("cpu%d, tid %d w=\n", CPU->id, THREAD->tid); 80 89 81 90 if (rwlock.readers_in) { 82 printf("Oops."); 91 if (!sh_quiet) 92 printf("Oops."); 83 93 atomic_inc(&threads_fault); 94 atomic_dec(&thread_count); 84 95 return; 85 96 } 86 97 thread_usleep(random(1000000)); 87 98 if (rwlock.readers_in) { 88 printf("Oops."); 99 if (!sh_quiet) 100 printf("Oops."); 89 101 atomic_inc(&threads_fault); 102 atomic_dec(&thread_count); 90 103 return; 91 104 } 92 105 93 106 rwlock_write_unlock(&rwlock); 94 printf("cpu%d, tid %d w-\n", CPU->id, THREAD->tid); 107 108 if (!sh_quiet) 109 printf("cpu%d, tid %d w-\n", CPU->id, THREAD->tid); 110 atomic_dec(&thread_count); 95 111 } 96 112 … … 102 118 103 119 to = random(2000); 104 printf("cpu%d, tid %d r+ (%d)\n", CPU->id, THREAD->tid, to); 120 121 if (!sh_quiet) 122 printf("cpu%d, tid %d r+ (%d)\n", CPU->id, THREAD->tid, to); 123 105 124 rc = rwlock_read_lock_timeout(&rwlock, to); 106 125 if (SYNCH_FAILED(rc)) { 107 printf("cpu%d, tid %d r!\n", CPU->id, THREAD->tid); 126 if (!sh_quiet) 127 printf("cpu%d, tid %d r!\n", CPU->id, THREAD->tid); 128 atomic_dec(&thread_count); 108 129 return; 109 130 } 110 printf("cpu%d, tid %d r=\n", CPU->id, THREAD->tid); 131 132 if (!sh_quiet) 133 printf("cpu%d, tid %d r=\n", CPU->id, THREAD->tid); 134 111 135 thread_usleep(30000); 112 136 rwlock_read_unlock(&rwlock); 113 printf("cpu%d, tid %d r-\n", CPU->id, THREAD->tid); 137 138 if (!sh_quiet) 139 printf("cpu%d, tid %d r-\n", CPU->id, THREAD->tid); 140 atomic_dec(&thread_count); 114 141 } 115 142 … … 117 144 { 118 145 context_t ctx; 119 uint32_t i, k; 146 uint32_t i; 147 sh_quiet = quiet; 120 148 121 149 waitq_initialize(&can_start); … … 123 151 atomic_set(&threads_fault, 0); 124 152 153 uint32_t rd = random(7) + 1; 154 uint32_t wr = random(5) + 1; 155 156 atomic_set(&thread_count, rd + wr); 157 125 158 thread_t *thrd; 126 159 127 160 context_save(&ctx); 128 printf("sp=%#x, readers_in=%d\n", ctx.sp, rwlock.readers_in); 161 if (!quiet) { 162 printf("sp=%#x, readers_in=%d\n", ctx.sp, rwlock.readers_in); 163 printf("Creating %d readers\n", rd); 164 } 129 165 130 k = random(7) + 1; 131 printf("Creating %d readers\n", k); 132 for (i = 0; i < k; i++) { 166 for (i = 0; i < rd; i++) { 133 167 thrd = thread_create(reader, NULL, TASK, 0, "reader", false); 134 168 if (thrd) 135 169 thread_ready(thrd); 136 else 170 else if (!quiet) 137 171 printf("Could not create reader %d\n", i); 138 172 } 139 173 140 k = random(5) + 1; 141 printf("Creating %d writers\n", k); 142 for (i = 0; i < k; i++) { 174 if (!quiet) 175 printf("Creating %d writers\n", wr); 176 177 for (i = 0; i < wr; i++) { 143 178 thrd = thread_create(writer, NULL, TASK, 0, "writer", false); 144 179 if (thrd) 145 180 thread_ready(thrd); 146 else 181 else if (!quiet) 147 182 printf("Could not create writer %d\n", i); 148 183 } … … 151 186 waitq_wakeup(&can_start, WAKEUP_ALL); 152 187 188 while (atomic_get(&thread_count) > 0) { 189 if (!quiet) 190 printf("Threads left: %d\n", atomic_get(&thread_count)); 191 thread_sleep(1); 192 } 193 153 194 if (atomic_get(&threads_fault) == 0) 154 195 return NULL;
Note:
See TracChangeset
for help on using the changeset viewer.