Subversion Repositories HelenOS

Rev

Rev 2071 | Rev 2089 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2071 Rev 2087
Line 202... Line 202...
202
void thread_init(void)
202
void thread_init(void)
203
{
203
{
204
    THREAD = NULL;
204
    THREAD = NULL;
205
    atomic_set(&nrdy,0);
205
    atomic_set(&nrdy,0);
206
    thread_slab = slab_cache_create("thread_slab", sizeof(thread_t), 0,
206
    thread_slab = slab_cache_create("thread_slab", sizeof(thread_t), 0,
207
        thr_constructor, thr_destructor, 0);
207
        thr_constructor, thr_destructor, 0);
208
 
208
 
209
#ifdef ARCH_HAS_FPU
209
#ifdef ARCH_HAS_FPU
210
    fpu_context_slab = slab_cache_create("fpu_slab", sizeof(fpu_context_t),
210
    fpu_context_slab = slab_cache_create("fpu_slab", sizeof(fpu_context_t),
211
        FPU_CONTEXT_ALIGN, NULL, NULL, 0);
211
        FPU_CONTEXT_ALIGN, NULL, NULL, 0);
212
#endif
212
#endif
213
 
213
 
214
    btree_create(&threads_btree);
214
    btree_create(&threads_btree);
215
}
215
}
216
 
216
 
Line 326... Line 326...
326
    if (!t)
326
    if (!t)
327
        return NULL;
327
        return NULL;
328
   
328
   
329
    /* Not needed, but good for debugging */
329
    /* Not needed, but good for debugging */
330
    memsetb((uintptr_t) t->kstack, THREAD_STACK_SIZE * 1 << STACK_FRAMES,
330
    memsetb((uintptr_t) t->kstack, THREAD_STACK_SIZE * 1 << STACK_FRAMES,
331
        0);
331
        0);
332
   
332
   
333
    ipl = interrupts_disable();
333
    ipl = interrupts_disable();
334
    spinlock_lock(&tidlock);
334
    spinlock_lock(&tidlock);
335
    t->tid = ++last_tid;
335
    t->tid = ++last_tid;
336
    spinlock_unlock(&tidlock);
336
    spinlock_unlock(&tidlock);
337
    interrupts_restore(ipl);
337
    interrupts_restore(ipl);
338
   
338
   
339
    context_save(&t->saved_context);
339
    context_save(&t->saved_context);
340
    context_set(&t->saved_context, FADDR(cushion), (uintptr_t) t->kstack,
340
    context_set(&t->saved_context, FADDR(cushion), (uintptr_t) t->kstack,
341
        THREAD_STACK_SIZE);
341
        THREAD_STACK_SIZE);
342
   
342
   
343
    the_initialize((the_t *) t->kstack);
343
    the_initialize((the_t *) t->kstack);
344
   
344
   
345
    ipl = interrupts_disable();
345
    ipl = interrupts_disable();
346
    t->saved_context.ipl = interrupts_read();
346
    t->saved_context.ipl = interrupts_read();
Line 402... Line 402...
402
    /*
402
    /*
403
     * Register this thread in the system-wide list.
403
     * Register this thread in the system-wide list.
404
     */
404
     */
405
    spinlock_lock(&threads_lock);
405
    spinlock_lock(&threads_lock);
406
    btree_insert(&threads_btree, (btree_key_t) ((uintptr_t) t), (void *) t,
406
    btree_insert(&threads_btree, (btree_key_t) ((uintptr_t) t), (void *) t,
407
        NULL);
407
        NULL);
408
    spinlock_unlock(&threads_lock);
408
    spinlock_unlock(&threads_lock);
409
   
409
   
410
    interrupts_restore(ipl);
410
    interrupts_restore(ipl);
411
   
411
   
412
    return t;
412
    return t;
Line 558... Line 558...
558
   
558
   
559
    /* Messing with thread structures, avoid deadlock */
559
    /* Messing with thread structures, avoid deadlock */
560
    ipl = interrupts_disable();
560
    ipl = interrupts_disable();
561
    spinlock_lock(&threads_lock);
561
    spinlock_lock(&threads_lock);
562
   
562
   
563
    printf("tid    name       address    state    task       ctx code       stack      cycles     cpu  kstack     waitqueue\n");
563
    printf("tid    name       address    state    task       ctx code    "
-
 
564
        "   stack      cycles     cpu  kstack     waitqueue\n");
564
    printf("------ ---------- ---------- -------- ---------- --- ---------- ---------- ---------- ---- ---------- ----------\n");
565
    printf("------ ---------- ---------- -------- ---------- --- --------"
-
 
566
        "-- ---------- ---------- ---- ---------- ----------\n");
565
 
567
 
-
 
568
    for (cur = threads_btree.leaf_head.next;
566
    for (cur = threads_btree.leaf_head.next; cur != &threads_btree.leaf_head; cur = cur->next) {
569
        cur != &threads_btree.leaf_head; cur = cur->next) {
567
        btree_node_t *node;
570
        btree_node_t *node;
568
        int i;
571
        int i;
569
 
572
 
570
        node = list_get_instance(cur, btree_node_t, leaf_link);
573
        node = list_get_instance(cur, btree_node_t, leaf_link);
571
        for (i = 0; i < node->keys; i++) {
574
        for (i = 0; i < node->keys; i++) {
Line 575... Line 578...
575
           
578
           
576
            uint64_t cycles;
579
            uint64_t cycles;
577
            char suffix;
580
            char suffix;
578
            order(t->cycles, &cycles, &suffix);
581
            order(t->cycles, &cycles, &suffix);
579
           
582
           
-
 
583
            printf("%-6zd %-10s %#10zx %-8s %#10zx %-3ld %#10zx "
-
 
584
                "%#10zx %9llu%c ", t->tid, t->name, t,
580
            printf("%-6zd %-10s %#10zx %-8s %#10zx %-3ld %#10zx %#10zx %9llu%c ", t->tid, t->name, t, thread_states[t->state], t->task, t->task->context, t->thread_code, t->kstack, cycles, suffix);
585
                thread_states[t->state], t->task, t->task->context,
-
 
586
                t->thread_code, t->kstack, cycles, suffix);
581
           
587
           
582
            if (t->cpu)
588
            if (t->cpu)
583
                printf("%-4zd", t->cpu->id);
589
                printf("%-4zd", t->cpu->id);
584
            else
590
            else
585
                printf("none");
591
                printf("none");
586
           
592
           
587
            if (t->state == Sleeping)
593
            if (t->state == Sleeping)
588
                printf(" %#10zx %#10zx", t->kstack, t->sleep_queue);
594
                printf(" %#10zx %#10zx", t->kstack,
-
 
595
                    t->sleep_queue);
589
           
596
           
590
            printf("\n");
597
            printf("\n");
591
        }
598
        }
592
    }
599
    }
593
 
600
 
Line 606... Line 613...
606
 */
613
 */
607
bool thread_exists(thread_t *t)
614
bool thread_exists(thread_t *t)
608
{
615
{
609
    btree_node_t *leaf;
616
    btree_node_t *leaf;
610
   
617
   
611
    return btree_search(&threads_btree, (btree_key_t) ((uintptr_t) t), &leaf) != NULL;
618
    return btree_search(&threads_btree, (btree_key_t) ((uintptr_t) t),
-
 
619
        &leaf) != NULL;
612
}
620
}
613
 
621
 
614
 
622
 
615
/** Update accounting of current thread.
623
/** Update accounting of current thread.
616
 *
624
 *
Line 645... Line 653...
645
    if (rc != 0) {
653
    if (rc != 0) {
646
        free(kernel_uarg);
654
        free(kernel_uarg);
647
        return (unative_t) rc;
655
        return (unative_t) rc;
648
    }
656
    }
649
 
657
 
650
    if ((t = thread_create(uinit, kernel_uarg, TASK, THREAD_FLAG_USPACE, namebuf, false))) {
658
    t = thread_create(uinit, kernel_uarg, TASK, THREAD_FLAG_USPACE, namebuf,
-
 
659
        false);
-
 
660
    if (t) {
651
        tid = t->tid;
661
        tid = t->tid;
652
        thread_ready(t);
662
        thread_ready(t);
653
        return (unative_t) tid;
663
        return (unative_t) tid;
654
    } else {
664
    } else {
655
        free(kernel_uarg);
665
        free(kernel_uarg);
Line 668... Line 678...
668
    return 0;
678
    return 0;
669
}
679
}
670
 
680
 
671
/** @}
681
/** @}
672
 */
682
 */
-
 
683