Changeset 266294a9 in mainline
- Timestamp:
- 2006-02-05T17:01:03Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5c9a08b
- Parents:
- 9b9e385
- Location:
- generic
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
generic/include/mm/slab.h
r9b9e385 r266294a9 71 71 size_t size; /**< Size of SLAB position - align_up(sizeof(obj)) */ 72 72 int (*constructor)(void *obj, int kmflag); 73 void(*destructor)(void *obj);73 int (*destructor)(void *obj); 74 74 int flags; /**< Flags changing behaviour of cache */ 75 75 … … 104 104 size_t align, 105 105 int (*constructor)(void *obj, int kmflag), 106 void(*destructor)(void *obj),106 int (*destructor)(void *obj), 107 107 int flags); 108 108 extern void slab_cache_destroy(slab_cache_t *cache); -
generic/include/print.h
r9b9e385 r266294a9 31 31 32 32 #include <arch/types.h> 33 #include <synch/spinlock.h> 33 34 34 35 #define INT8 1 … … 39 40 extern void printf(const char *fmt, ...); 40 41 42 /* We need this address in spinlock to avoid deadlock in deadlock detection */ 43 extern spinlock_t printflock; 44 41 45 #endif -
generic/include/proc/thread.h
r9b9e385 r266294a9 135 135 extern void thread_register_call_me(void (* call_me)(void *), void *call_me_with); 136 136 extern void thread_print_list(void); 137 extern void thread_destroy(thread_t *t); 137 138 138 139 #endif -
generic/src/mm/slab.c
r9b9e385 r266294a9 229 229 slab_t *slab) 230 230 { 231 int freed = 0; 232 231 233 if (!slab) 232 234 slab = obj2slab(obj); … … 235 237 ASSERT(slab->available < cache->objects); 236 238 239 if (cache->destructor) 240 freed = cache->destructor(obj); 241 237 242 spinlock_lock(&cache->slablock); 238 243 … … 247 252 spinlock_unlock(&cache->slablock); 248 253 249 return slab_space_free(cache, slab);254 return freed + slab_space_free(cache, slab); 250 255 251 256 } else if (slab->available == 1) { … … 255 260 } 256 261 spinlock_unlock(&cache->slablock); 257 return 0;262 return freed; 258 263 } 259 264 … … 291 296 slab->nextavail = *((int *)obj); 292 297 slab->available--; 298 293 299 if (! slab->available) 294 300 list_prepend(&slab->link, &cache->full_slabs); … … 297 303 298 304 spinlock_unlock(&cache->slablock); 305 306 if (cache->constructor && cache->constructor(obj, flags)) { 307 /* Bad, bad, construction failed */ 308 slab_obj_destroy(cache, obj, slab); 309 return NULL; 310 } 299 311 return obj; 300 312 } … … 532 544 size_t align, 533 545 int (*constructor)(void *obj, int kmflag), 534 void(*destructor)(void *obj),546 int (*destructor)(void *obj), 535 547 int flags) 536 548 { … … 597 609 size_t align, 598 610 int (*constructor)(void *obj, int kmflag), 599 void(*destructor)(void *obj),611 int (*destructor)(void *obj), 600 612 int flags) 601 613 { -
generic/src/proc/scheduler.c
r9b9e385 r266294a9 238 238 * switch to a new thread. 239 239 * 240 * Assume THREAD->lock is held. 240 241 */ 241 242 static void scheduler_separated_stack(void) … … 254 255 255 256 case Exiting: 256 frame_free((__address) THREAD->kstack); 257 if (THREAD->ustack) { 258 frame_free((__address) THREAD->ustack); 259 } 260 261 /* 262 * Detach from the containing task. 263 */ 264 spinlock_lock(&TASK->lock); 265 list_remove(&THREAD->th_link); 266 spinlock_unlock(&TASK->lock); 267 268 spinlock_unlock(&THREAD->lock); 269 270 spinlock_lock(&threads_lock); 271 list_remove(&THREAD->threads_link); 272 spinlock_unlock(&threads_lock); 273 274 spinlock_lock(&CPU->lock); 275 if(CPU->fpu_owner==THREAD) 276 CPU->fpu_owner=NULL; 277 spinlock_unlock(&CPU->lock); 278 279 free(THREAD); 280 257 thread_destroy(THREAD); 281 258 break; 282 259 283 260 case Sleeping: 284 261 /* -
generic/src/proc/thread.c
r9b9e385 r266294a9 53 53 #include <memstr.h> 54 54 #include <print.h> 55 #include <mm/slab.h> 56 #include <debug.h> 55 57 56 58 char *thread_states[] = {"Invalid", "Running", "Sleeping", "Ready", "Entering", "Exiting"}; /**< Thread states */ … … 61 63 SPINLOCK_INITIALIZE(tidlock); 62 64 __u32 last_tid = 0; 65 66 static slab_cache_t *thread_slab; 63 67 64 68 … … 88 92 } 89 93 94 /** Initialization and allocation for thread_t structure */ 95 static int thr_constructor(void *obj, int kmflags) 96 { 97 thread_t *t = (thread_t *)obj; 98 99 spinlock_initialize(&t->lock, "thread_t_lock"); 100 link_initialize(&t->rq_link); 101 link_initialize(&t->wq_link); 102 link_initialize(&t->th_link); 103 link_initialize(&t->threads_link); 104 105 t->kstack = (__u8 *)frame_alloc(ONE_FRAME, FRAME_KA | kmflags); 106 if (!t->kstack) 107 return -1; 108 109 return 0; 110 } 111 112 /** Destruction of thread_t object */ 113 static int thr_destructor(void *obj) 114 { 115 thread_t *t = (thread_t *)obj; 116 117 frame_free((__address) t->kstack); 118 return 1; /* One page freed */ 119 } 90 120 91 121 /** Initialize threads … … 98 128 THREAD = NULL; 99 129 atomic_set(&nrdy,0); 130 thread_slab = slab_cache_create("thread_slab", 131 sizeof(thread_t),0, 132 thr_constructor, thr_destructor, 0); 100 133 } 101 134 … … 144 177 145 178 179 /** Destroy thread memory structure 180 * 181 * Detach thread from all queues, cpus etc. and destroy it. 182 * 183 * Assume thread->lock is held!! 184 */ 185 void thread_destroy(thread_t *t) 186 { 187 ASSERT(t->state == Exiting); 188 ASSERT(t->task); 189 ASSERT(t->cpu); 190 191 spinlock_lock(&t->cpu->lock); 192 if(t->cpu->fpu_owner==t) 193 t->cpu->fpu_owner=NULL; 194 spinlock_unlock(&t->cpu->lock); 195 196 if (t->ustack) 197 frame_free((__address) t->ustack); 198 199 /* 200 * Detach from the containing task. 201 */ 202 spinlock_lock(&t->task->lock); 203 list_remove(&t->th_link); 204 spinlock_unlock(&t->task->lock); 205 206 spinlock_unlock(&t->lock); 207 208 spinlock_lock(&threads_lock); 209 list_remove(&t->threads_link); 210 spinlock_unlock(&threads_lock); 211 212 slab_free(thread_slab, t); 213 } 214 215 146 216 /** Create new thread 147 217 * … … 159 229 { 160 230 thread_t *t; 161 __address frame_ ks, frame_us = NULL;162 163 t = (thread_t *) malloc(sizeof(thread_t));231 __address frame_us = NULL; 232 233 t = (thread_t *) slab_alloc(thread_slab, 0); 164 234 if (t) { 165 235 ipl_t ipl; 166 236 167 spinlock_initialize(&t->lock, "thread_t_lock");168 169 frame_ks = frame_alloc(ONE_FRAME, FRAME_KA);170 237 if (THREAD_USER_STACK & flags) { 171 238 frame_us = frame_alloc(ONE_FRAME, FRAME_KA); 172 239 } 240 241 /* Not needed, but good for debugging */ 242 memsetb((__address)t->kstack, THREAD_STACK_SIZE, 0); 173 243 174 244 ipl = interrupts_disable(); … … 178 248 interrupts_restore(ipl); 179 249 180 memsetb(frame_ks, THREAD_STACK_SIZE, 0);181 link_initialize(&t->rq_link);182 link_initialize(&t->wq_link);183 link_initialize(&t->th_link);184 link_initialize(&t->threads_link);185 t->kstack = (__u8 *) frame_ks;186 250 t->ustack = (__u8 *) frame_us; 187 251 … … 219 283 * Register this thread in the system-wide list. 220 284 */ 221 ipl = interrupts_disable(); 285 ipl = interrupts_disable(); 222 286 spinlock_lock(&threads_lock); 223 287 list_append(&t->threads_link, &threads_head); -
generic/src/synch/spinlock.c
r9b9e385 r266294a9 69 69 preemption_disable(); 70 70 while (test_and_set(&sl->val)) { 71 if (i++ > 300000 ) {71 if (i++ > 300000 && sl!=&printflock) { 72 72 printf("cpu%d: looping on spinlock %p:%s, caller=%p", 73 73 CPU->id, sl, sl->name, CALLER);
Note:
See TracChangeset
for help on using the changeset viewer.