Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/proc/thread.c

    rf22dc820 rc0699467  
    173173#endif /* CONFIG_FPU */
    174174       
    175         /*
    176          * Allocate the kernel stack from the low-memory to prevent an infinite
    177          * nesting of TLB-misses when accessing the stack from the part of the
    178          * TLB-miss handler written in C.
    179          *
    180          * Note that low-memory is safe to be used for the stack as it will be
    181          * covered by the kernel identity mapping, which guarantees not to
    182          * nest TLB-misses infinitely (either via some hardware mechanism or
    183          * by the construciton of the assembly-language part of the TLB-miss
    184          * handler).
    185          *
    186          * This restriction can be lifted once each architecture provides
    187          * a similar guarantee, for example by locking the kernel stack
    188          * in the TLB whenever it is allocated from the high-memory and the
    189          * thread is being scheduled to run.
    190          */
    191         kmflags |= FRAME_LOWMEM;
    192         kmflags &= ~FRAME_HIGHMEM;
    193        
    194175        thread->kstack = (uint8_t *) frame_alloc(STACK_FRAMES, FRAME_KA | kmflags);
    195176        if (!thread->kstack) {
     
    236217       
    237218        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,
    239220            thr_constructor, thr_destructor, 0);
    240221       
    241222#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);
    244225#endif
    245226       
     
    247228}
    248229
    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 */
     237void thread_ready(thread_t *thread)
    255238{
    256239        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 ready
    263  *
    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);
    272240       
    273241        ASSERT(thread->state != Ready);
    274242       
    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) {
    280248                ASSERT(thread->cpu != NULL);
    281249                cpu = thread->cpu;
    282         } else
    283                 cpu = CPU;
    284        
     250        }
    285251        thread->state = Ready;
    286252       
     
    313279 * @param flags     Thread flags.
    314280 * @param name      Symbolic name (a copy is made).
     281 * @param uncounted Thread's accounting doesn't affect accumulated task
     282 *                  accounting.
    315283 *
    316284 * @return New thread's structure on success, NULL on failure.
     
    318286 */
    319287thread_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)
    321289{
    322290        thread_t *thread = (thread_t *) slab_alloc(thread_slab, 0);
     
    348316        thread->ucycles = 0;
    349317        thread->kcycles = 0;
    350         thread->uncounted =
    351             ((flags & THREAD_FLAG_UNCOUNTED) == THREAD_FLAG_UNCOUNTED);
     318        thread->uncounted = uncounted;
    352319        thread->priority = -1;          /* Start in rq[0] */
    353320        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;
    359322        thread->nomigrate = 0;
    360323        thread->state = Entering;
     
    374337        thread->task = task;
    375338       
    376         thread->fpu_context_exists = false;
    377         thread->fpu_context_engaged = false;
     339        thread->fpu_context_exists = 0;
     340        thread->fpu_context_engaged = 0;
    378341       
    379342        avltree_node_initialize(&thread->threads_tree_node);
     
    389352        thread_create_arch(thread);
    390353       
    391         if ((flags & THREAD_FLAG_NOATTACH) != THREAD_FLAG_NOATTACH)
     354        if (!(flags & THREAD_FLAG_NOATTACH))
    392355                thread_attach(thread, task);
    393356       
     
    455418       
    456419        /* Must not count kbox thread into lifecount */
    457         if (thread->uspace)
     420        if (thread->flags & THREAD_FLAG_USPACE)
    458421                atomic_inc(&task->lifecount);
    459422       
     
    477440void thread_exit(void)
    478441{
    479         if (THREAD->uspace) {
     442        if (THREAD->flags & THREAD_FLAG_USPACE) {
    480443#ifdef CONFIG_UDEBUG
    481444                /* Generate udebug THREAD_E event */
    482445                udebug_thread_e_event();
    483                
     446
    484447                /*
    485448                 * This thread will not execute any code or system calls from
     
    524487{
    525488        ASSERT(THREAD);
    526        
     489
    527490        THREAD->nomigrate++;
    528491}
     
    533496        ASSERT(THREAD);
    534497        ASSERT(THREAD->nomigrate > 0);
    535        
    536         if (THREAD->nomigrate > 0)
    537                 THREAD->nomigrate--;
     498
     499        THREAD->nomigrate--;
    538500}
    539501
     
    873835         * In case of failure, kernel_uarg will be deallocated in this function.
    874836         * In case of success, kernel_uarg will be freed in uinit().
     837         *
    875838         */
    876839        uspace_arg_t *kernel_uarg =
     
    884847       
    885848        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);
    887850        if (thread) {
    888851                if (uspace_thread_id != NULL) {
Note: See TracChangeset for help on using the changeset viewer.