Changeset 8565a42 in mainline for kernel/generic/src/proc/scheduler.c


Ignore:
Timestamp:
2018-03-02T20:34:50Z (7 years ago)
Author:
GitHub <noreply@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a1a81f69, d5e5fd1
Parents:
3061bc1 (diff), 34e1206 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:34:50)
git-committer:
GitHub <noreply@…> (2018-03-02 20:34:50)
Message:

Remove all trailing whitespace, everywhere.

See individual commit messages for details.

File:
1 edited

Legend:

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

    r3061bc1 r8565a42  
    9090        before_thread_runs_arch();
    9191        rcu_before_thread_runs();
    92        
     92
    9393#ifdef CONFIG_FPU_LAZY
    9494        if (THREAD == CPU->fpu_owner)
     
    105105        }
    106106#endif
    107        
     107
    108108#ifdef CONFIG_UDEBUG
    109109        if (THREAD->btrace) {
     
    113113                        stack_trace_istate(istate);
    114114                }
    115                
     115
    116116                THREAD->btrace = false;
    117117        }
     
    141141        fpu_enable();
    142142        irq_spinlock_lock(&CPU->lock, false);
    143        
     143
    144144        /* Save old context */
    145145        if (CPU->fpu_owner != NULL) {
    146146                irq_spinlock_lock(&CPU->fpu_owner->lock, false);
    147147                fpu_context_save(CPU->fpu_owner->saved_fpu_context);
    148                
     148
    149149                /* Don't prevent migration */
    150150                CPU->fpu_owner->fpu_context_engaged = false;
     
    152152                CPU->fpu_owner = NULL;
    153153        }
    154        
     154
    155155        irq_spinlock_lock(&THREAD->lock, false);
    156156        if (THREAD->fpu_context_exists) {
     
    164164                        THREAD->saved_fpu_context =
    165165                            (fpu_context_t *) slab_alloc(fpu_context_cache, 0);
    166                        
     166
    167167                        /* We may have switched CPUs during slab_alloc */
    168168                        goto restart;
     
    171171                THREAD->fpu_context_exists = true;
    172172        }
    173        
     173
    174174        CPU->fpu_owner = THREAD;
    175175        THREAD->fpu_context_engaged = true;
    176176        irq_spinlock_unlock(&THREAD->lock, false);
    177        
     177
    178178        irq_spinlock_unlock(&CPU->lock, false);
    179179}
     
    201201{
    202202        assert(CPU != NULL);
    203        
     203
    204204loop:
    205        
     205
    206206        if (atomic_get(&CPU->nrdy) == 0) {
    207207                /*
     
    214214                irq_spinlock_unlock(&CPU->lock, false);
    215215                interrupts_enable();
    216                
     216
    217217                /*
    218218                 * An interrupt might occur right now and wake up a thread.
     
    226226
    227227        assert(!CPU->idle);
    228        
     228
    229229        unsigned int i;
    230230        for (i = 0; i < RQ_COUNT; i++) {
     
    237237                        continue;
    238238                }
    239                
     239
    240240                atomic_dec(&CPU->nrdy);
    241241                atomic_dec(&nrdy);
    242242                CPU->rq[i].n--;
    243                
     243
    244244                /*
    245245                 * Take the first thread from the queue.
     
    248248                    list_first(&CPU->rq[i].rq), thread_t, rq_link);
    249249                list_remove(&thread->rq_link);
    250                
     250
    251251                irq_spinlock_pass(&(CPU->rq[i].lock), &thread->lock);
    252                
     252
    253253                thread->cpu = CPU;
    254254                thread->ticks = us2ticks((i + 1) * 10000);
    255255                thread->priority = i;  /* Correct rq index */
    256                
     256
    257257                /*
    258258                 * Clear the stolen flag so that it can be migrated
     
    261261                thread->stolen = false;
    262262                irq_spinlock_unlock(&thread->lock, false);
    263                
     263
    264264                return thread;
    265265        }
    266        
     266
    267267        goto loop;
    268268}
     
    282282{
    283283        list_t list;
    284        
     284
    285285        list_initialize(&list);
    286286        irq_spinlock_lock(&CPU->lock, false);
    287        
     287
    288288        if (CPU->needs_relink > NEEDS_RELINK_MAX) {
    289289                int i;
    290290                for (i = start; i < RQ_COUNT - 1; i++) {
    291291                        /* Remember and empty rq[i + 1] */
    292                        
     292
    293293                        irq_spinlock_lock(&CPU->rq[i + 1].lock, false);
    294294                        list_concat(&list, &CPU->rq[i + 1].rq);
     
    296296                        CPU->rq[i + 1].n = 0;
    297297                        irq_spinlock_unlock(&CPU->rq[i + 1].lock, false);
    298                        
     298
    299299                        /* Append rq[i + 1] to rq[i] */
    300                        
     300
    301301                        irq_spinlock_lock(&CPU->rq[i].lock, false);
    302302                        list_concat(&CPU->rq[i].rq, &list);
     
    304304                        irq_spinlock_unlock(&CPU->rq[i].lock, false);
    305305                }
    306                
     306
    307307                CPU->needs_relink = 0;
    308308        }
    309        
     309
    310310        irq_spinlock_unlock(&CPU->lock, false);
    311311}
     
    321321{
    322322        volatile ipl_t ipl;
    323        
     323
    324324        assert(CPU != NULL);
    325        
     325
    326326        ipl = interrupts_disable();
    327        
     327
    328328        if (atomic_get(&haltstate))
    329329                halt();
    330        
     330
    331331        if (THREAD) {
    332332                irq_spinlock_lock(&THREAD->lock, false);
    333                
     333
    334334                /* Update thread kernel accounting */
    335335                THREAD->kcycles += get_cycle() - THREAD->last_cycle;
    336                
     336
    337337#if (defined CONFIG_FPU) && (!defined CONFIG_FPU_LAZY)
    338338                fpu_context_save(THREAD->saved_fpu_context);
     
    342342                         * This is the place where threads leave scheduler();
    343343                         */
    344                        
     344
    345345                        /* Save current CPU cycle */
    346346                        THREAD->last_cycle = get_cycle();
    347                        
     347
    348348                        irq_spinlock_unlock(&THREAD->lock, false);
    349349                        interrupts_restore(THREAD->saved_context.ipl);
    350                        
     350
    351351                        return;
    352352                }
    353                
     353
    354354                /*
    355355                 * Interrupt priority level of preempted thread is recorded
     
    360360                THREAD->saved_context.ipl = ipl;
    361361        }
    362        
     362
    363363        /*
    364364         * Through the 'THE' structure, we keep track of THREAD, TASK, CPU, AS
     
    368368         */
    369369        the_copy(THE, (the_t *) CPU->stack);
    370        
     370
    371371        /*
    372372         * We may not keep the old stack.
     
    386386            (uintptr_t) CPU->stack, STACK_SIZE);
    387387        context_restore(&CPU->saved_context);
    388        
     388
    389389        /* Not reached */
    390390}
     
    402402        task_t *old_task = TASK;
    403403        as_t *old_as = AS;
    404        
     404
    405405        assert((!THREAD) || (irq_spinlock_locked(&THREAD->lock)));
    406406        assert(CPU != NULL);
    407407        assert(interrupts_disabled());
    408        
     408
    409409        /*
    410410         * Hold the current task and the address space to prevent their
     
    414414        if (old_task)
    415415                task_hold(old_task);
    416        
     416
    417417        if (old_as)
    418418                as_hold(old_as);
    419        
     419
    420420        if (THREAD) {
    421421                /* Must be run after the switch to scheduler stack */
    422422                after_thread_ran();
    423                
     423
    424424                switch (THREAD->state) {
    425425                case Running:
     
    427427                        thread_ready(THREAD);
    428428                        break;
    429                
     429
    430430                case Exiting:
    431431                        rcu_thread_exiting();
     
    452452                                    WAKEUP_FIRST);
    453453                                irq_spinlock_unlock(&THREAD->join_wq.lock, false);
    454                                
     454
    455455                                THREAD->state = Lingering;
    456456                                irq_spinlock_unlock(&THREAD->lock, false);
    457457                        }
    458458                        break;
    459                        
     459
    460460                case Sleeping:
    461461                        /*
     
    463463                         */
    464464                        THREAD->priority = -1;
    465                        
     465
    466466                        /*
    467467                         * We need to release wq->lock which we locked in
     
    470470                         */
    471471                        irq_spinlock_unlock(&THREAD->sleep_queue->lock, false);
    472                        
     472
    473473                        irq_spinlock_unlock(&THREAD->lock, false);
    474474                        break;
    475                
     475
    476476                default:
    477477                        /*
     
    482482                        break;
    483483                }
    484                
     484
    485485                THREAD = NULL;
    486486        }
    487        
     487
    488488        THREAD = find_best_thread();
    489        
     489
    490490        irq_spinlock_lock(&THREAD->lock, false);
    491491        int priority = THREAD->priority;
    492492        irq_spinlock_unlock(&THREAD->lock, false);
    493        
     493
    494494        relink_rq(priority);
    495        
     495
    496496        /*
    497497         * If both the old and the new task are the same,
     
    500500        if (TASK != THREAD->task) {
    501501                as_t *new_as = THREAD->task->as;
    502                
     502
    503503                /*
    504504                 * Note that it is possible for two tasks
     
    512512                        as_switch(old_as, new_as);
    513513                }
    514                
     514
    515515                TASK = THREAD->task;
    516516                before_task_runs();
    517517        }
    518        
     518
    519519        if (old_task)
    520520                task_release(old_task);
    521        
     521
    522522        if (old_as)
    523523                as_release(old_as);
    524        
     524
    525525        irq_spinlock_lock(&THREAD->lock, false);
    526526        THREAD->state = Running;
    527        
     527
    528528#ifdef SCHEDULER_VERBOSE
    529529        log(LF_OTHER, LVL_DEBUG,
     
    532532            THREAD->ticks, atomic_get(&CPU->nrdy));
    533533#endif
    534        
     534
    535535        /*
    536536         * Some architectures provide late kernel PA2KA(identity)
     
    542542         */
    543543        before_thread_runs();
    544        
     544
    545545        /*
    546546         * Copy the knowledge of CPU, TASK, THREAD and preemption counter to
     
    548548         */
    549549        the_copy(THE, (the_t *) THREAD->kstack);
    550        
     550
    551551        context_restore(&THREAD->saved_context);
    552        
     552
    553553        /* Not reached */
    554554}
     
    567567        atomic_count_t average;
    568568        atomic_count_t rdy;
    569        
     569
    570570        /*
    571571         * Detach kcpulb as nobody will call thread_join_timeout() on it.
    572572         */
    573573        thread_detach(THREAD);
    574        
     574
    575575loop:
    576576        /*
     
    578578         */
    579579        thread_sleep(1);
    580        
     580
    581581not_satisfied:
    582582        /*
     
    588588        average = atomic_get(&nrdy) / config.cpu_active + 1;
    589589        rdy = atomic_get(&CPU->nrdy);
    590        
     590
    591591        if (average <= rdy)
    592592                goto satisfied;
    593        
     593
    594594        atomic_count_t count = average - rdy;
    595        
     595
    596596        /*
    597597         * Searching least priority queues on all CPU's first and most priority
     
    601601        size_t acpu_bias = 0;
    602602        int rq;
    603        
     603
    604604        for (rq = RQ_COUNT - 1; rq >= 0; rq--) {
    605605                for (acpu = 0; acpu < config.cpu_active; acpu++) {
    606606                        cpu_t *cpu = &cpus[(acpu + acpu_bias) % config.cpu_active];
    607                        
     607
    608608                        /*
    609609                         * Not interested in ourselves.
     
    614614                        if (CPU == cpu)
    615615                                continue;
    616                        
     616
    617617                        if (atomic_get(&cpu->nrdy) <= average)
    618618                                continue;
    619                        
     619
    620620                        irq_spinlock_lock(&(cpu->rq[rq].lock), true);
    621621                        if (cpu->rq[rq].n == 0) {
     
    623623                                continue;
    624624                        }
    625                        
     625
    626626                        thread_t *thread = NULL;
    627                        
     627
    628628                        /* Search rq from the back */
    629629                        link_t *link = cpu->rq[rq].rq.head.prev;
    630                        
     630
    631631                        while (link != &(cpu->rq[rq].rq.head)) {
    632632                                thread = (thread_t *) list_get_instance(link,
    633633                                    thread_t, rq_link);
    634                                
     634
    635635                                /*
    636636                                 * Do not steal CPU-wired threads, threads
     
    640640                                 */
    641641                                irq_spinlock_lock(&thread->lock, false);
    642                                
     642
    643643                                if ((!thread->wired) && (!thread->stolen) &&
    644644                                    (!thread->nomigrate) &&
     
    649649                                        irq_spinlock_unlock(&thread->lock,
    650650                                            false);
    651                                        
     651
    652652                                        atomic_dec(&cpu->nrdy);
    653653                                        atomic_dec(&nrdy);
    654                                        
     654
    655655                                        cpu->rq[rq].n--;
    656656                                        list_remove(&thread->rq_link);
    657                                        
     657
    658658                                        break;
    659659                                }
    660                                
     660
    661661                                irq_spinlock_unlock(&thread->lock, false);
    662                                
     662
    663663                                link = link->prev;
    664664                                thread = NULL;
    665665                        }
    666                        
     666
    667667                        if (thread) {
    668668                                /*
    669669                                 * Ready thread on local CPU
    670670                                 */
    671                                
     671
    672672                                irq_spinlock_pass(&(cpu->rq[rq].lock),
    673673                                    &thread->lock);
    674                                
     674
    675675#ifdef KCPULB_VERBOSE
    676676                                log(LF_OTHER, LVL_DEBUG,
     
    680680                                    atomic_get(&nrdy) / config.cpu_active);
    681681#endif
    682                                
     682
    683683                                thread->stolen = true;
    684684                                thread->state = Entering;
    685                                
     685
    686686                                irq_spinlock_unlock(&thread->lock, true);
    687687                                thread_ready(thread);
    688                                
     688
    689689                                if (--count == 0)
    690690                                        goto satisfied;
    691                                
     691
    692692                                /*
    693693                                 * We are not satisfied yet, focus on another
     
    696696                                 */
    697697                                acpu_bias++;
    698                                
     698
    699699                                continue;
    700700                        } else
    701701                                irq_spinlock_unlock(&(cpu->rq[rq].lock), true);
    702                        
    703                 }
    704         }
    705        
     702
     703                }
     704        }
     705
    706706        if (atomic_get(&CPU->nrdy)) {
    707707                /*
     
    718718                goto loop;
    719719        }
    720        
     720
    721721        goto not_satisfied;
    722        
     722
    723723satisfied:
    724724        goto loop;
     
    735735                if (!cpus[cpu].active)
    736736                        continue;
    737                
     737
    738738                irq_spinlock_lock(&cpus[cpu].lock, true);
    739                
     739
    740740                printf("cpu%u: address=%p, nrdy=%" PRIua ", needs_relink=%zu\n",
    741741                    cpus[cpu].id, &cpus[cpu], atomic_get(&cpus[cpu].nrdy),
    742742                    cpus[cpu].needs_relink);
    743                
     743
    744744                unsigned int i;
    745745                for (i = 0; i < RQ_COUNT; i++) {
     
    749749                                continue;
    750750                        }
    751                        
     751
    752752                        printf("\trq[%u]: ", i);
    753753                        list_foreach(cpus[cpu].rq[i].rq, rq_link, thread_t,
     
    757757                        }
    758758                        printf("\n");
    759                        
     759
    760760                        irq_spinlock_unlock(&(cpus[cpu].rq[i].lock), false);
    761761                }
    762                
     762
    763763                irq_spinlock_unlock(&cpus[cpu].lock, true);
    764764        }
Note: See TracChangeset for help on using the changeset viewer.