Changes in kernel/generic/src/proc/thread.c [f22dc820:c0699467] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/proc/thread.c
rf22dc820 rc0699467 173 173 #endif /* CONFIG_FPU */ 174 174 175 /*176 * Allocate the kernel stack from the low-memory to prevent an infinite177 * nesting of TLB-misses when accessing the stack from the part of the178 * TLB-miss handler written in C.179 *180 * Note that low-memory is safe to be used for the stack as it will be181 * covered by the kernel identity mapping, which guarantees not to182 * nest TLB-misses infinitely (either via some hardware mechanism or183 * by the construciton of the assembly-language part of the TLB-miss184 * handler).185 *186 * This restriction can be lifted once each architecture provides187 * a similar guarantee, for example by locking the kernel stack188 * in the TLB whenever it is allocated from the high-memory and the189 * thread is being scheduled to run.190 */191 kmflags |= FRAME_LOWMEM;192 kmflags &= ~FRAME_HIGHMEM;193 194 175 thread->kstack = (uint8_t *) frame_alloc(STACK_FRAMES, FRAME_KA | kmflags); 195 176 if (!thread->kstack) { … … 236 217 237 218 atomic_set(&nrdy, 0); 238 thread_slab = slab_cache_create("thread_ t", sizeof(thread_t), 0,219 thread_slab = slab_cache_create("thread_slab", sizeof(thread_t), 0, 239 220 thr_constructor, thr_destructor, 0); 240 221 241 222 #ifdef CONFIG_FPU 242 fpu_context_slab = slab_cache_create("fpu_ context_t",243 sizeof(fpu_context_t),FPU_CONTEXT_ALIGN, NULL, NULL, 0);223 fpu_context_slab = slab_cache_create("fpu_slab", sizeof(fpu_context_t), 224 FPU_CONTEXT_ALIGN, NULL, NULL, 0); 244 225 #endif 245 226 … … 247 228 } 248 229 249 /** Wire thread to the given CPU 250 * 251 * @param cpu CPU to wire the thread to. 252 * 253 */ 254 void thread_wire(thread_t *thread, cpu_t *cpu) 230 /** Make thread ready 231 * 232 * Switch thread to the ready state. 233 * 234 * @param thread Thread to make ready. 235 * 236 */ 237 void thread_ready(thread_t *thread) 255 238 { 256 239 irq_spinlock_lock(&thread->lock, true); 257 thread->cpu = cpu;258 thread->wired = true;259 irq_spinlock_unlock(&thread->lock, true);260 }261 262 /** Make thread ready263 *264 * Switch thread to the ready state.265 *266 * @param thread Thread to make ready.267 *268 */269 void thread_ready(thread_t *thread)270 {271 irq_spinlock_lock(&thread->lock, true);272 240 273 241 ASSERT(thread->state != Ready); 274 242 275 int i = (thread->priority < RQ_COUNT - 1) ?276 ++thread->priority : thread->priority;277 278 cpu_t *cpu ;279 if (thread-> wired || thread->nomigrate || thread->fpu_context_engaged) {243 int i = (thread->priority < RQ_COUNT - 1) 244 ? ++thread->priority : thread->priority; 245 246 cpu_t *cpu = CPU; 247 if (thread->flags & THREAD_FLAG_WIRED) { 280 248 ASSERT(thread->cpu != NULL); 281 249 cpu = thread->cpu; 282 } else 283 cpu = CPU; 284 250 } 285 251 thread->state = Ready; 286 252 … … 313 279 * @param flags Thread flags. 314 280 * @param name Symbolic name (a copy is made). 281 * @param uncounted Thread's accounting doesn't affect accumulated task 282 * accounting. 315 283 * 316 284 * @return New thread's structure on success, NULL on failure. … … 318 286 */ 319 287 thread_t *thread_create(void (* func)(void *), void *arg, task_t *task, 320 thread_flags_t flags, const char *name)288 unsigned int flags, const char *name, bool uncounted) 321 289 { 322 290 thread_t *thread = (thread_t *) slab_alloc(thread_slab, 0); … … 348 316 thread->ucycles = 0; 349 317 thread->kcycles = 0; 350 thread->uncounted = 351 ((flags & THREAD_FLAG_UNCOUNTED) == THREAD_FLAG_UNCOUNTED); 318 thread->uncounted = uncounted; 352 319 thread->priority = -1; /* Start in rq[0] */ 353 320 thread->cpu = NULL; 354 thread->wired = false; 355 thread->stolen = false; 356 thread->uspace = 357 ((flags & THREAD_FLAG_USPACE) == THREAD_FLAG_USPACE); 358 321 thread->flags = flags; 359 322 thread->nomigrate = 0; 360 323 thread->state = Entering; … … 374 337 thread->task = task; 375 338 376 thread->fpu_context_exists = false;377 thread->fpu_context_engaged = false;339 thread->fpu_context_exists = 0; 340 thread->fpu_context_engaged = 0; 378 341 379 342 avltree_node_initialize(&thread->threads_tree_node); … … 389 352 thread_create_arch(thread); 390 353 391 if ( (flags & THREAD_FLAG_NOATTACH) != THREAD_FLAG_NOATTACH)354 if (!(flags & THREAD_FLAG_NOATTACH)) 392 355 thread_attach(thread, task); 393 356 … … 455 418 456 419 /* Must not count kbox thread into lifecount */ 457 if (thread-> uspace)420 if (thread->flags & THREAD_FLAG_USPACE) 458 421 atomic_inc(&task->lifecount); 459 422 … … 477 440 void thread_exit(void) 478 441 { 479 if (THREAD-> uspace) {442 if (THREAD->flags & THREAD_FLAG_USPACE) { 480 443 #ifdef CONFIG_UDEBUG 481 444 /* Generate udebug THREAD_E event */ 482 445 udebug_thread_e_event(); 483 446 484 447 /* 485 448 * This thread will not execute any code or system calls from … … 524 487 { 525 488 ASSERT(THREAD); 526 489 527 490 THREAD->nomigrate++; 528 491 } … … 533 496 ASSERT(THREAD); 534 497 ASSERT(THREAD->nomigrate > 0); 535 536 if (THREAD->nomigrate > 0) 537 THREAD->nomigrate--; 498 499 THREAD->nomigrate--; 538 500 } 539 501 … … 873 835 * In case of failure, kernel_uarg will be deallocated in this function. 874 836 * In case of success, kernel_uarg will be freed in uinit(). 837 * 875 838 */ 876 839 uspace_arg_t *kernel_uarg = … … 884 847 885 848 thread_t *thread = thread_create(uinit, kernel_uarg, TASK, 886 THREAD_FLAG_USPACE | THREAD_FLAG_NOATTACH, namebuf );849 THREAD_FLAG_USPACE | THREAD_FLAG_NOATTACH, namebuf, false); 887 850 if (thread) { 888 851 if (uspace_thread_id != NULL) {
Note:
See TracChangeset
for help on using the changeset viewer.