Changeset c680333 in mainline


Ignore:
Timestamp:
2023-04-07T18:23:19Z (19 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
2a230b6, dd218ea
Parents:
3118355
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2023-03-04 18:17:37)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2023-04-07 18:23:19)
Message:

Move task switch handling into a separate function

Location:
kernel/generic/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/mm/as.c

    r3118355 rc680333  
    16881688        spinlock_unlock(&asidlock);
    16891689
     1690        if (AS)
     1691                as_release(AS);
     1692
    16901693        AS = new_as;
     1694
     1695        as_hold(AS);
    16911696}
    16921697
  • kernel/generic/src/proc/scheduler.c

    r3118355 rc680333  
    7070atomic_size_t nrdy;  /**< Number of ready threads in the system. */
    7171
    72 /** Carry out actions before new task runs. */
    73 static void before_task_runs(void)
    74 {
    75         before_task_runs_arch();
    76 }
    77 
    7872/** Take actions before new thread runs.
    7973 *
     
    255249
    256250        goto loop;
     251}
     252
     253static void switch_task(task_t *task)
     254{
     255        /* If the task stays the same, a lot of work is avoided. */
     256        if (TASK == task)
     257                return;
     258
     259        as_t *old_as = AS;
     260        as_t *new_as = task->as;
     261
     262        /* It is possible for two tasks to share one address space. */
     263        if (old_as != new_as)
     264                as_switch(old_as, new_as);
     265
     266        if (TASK)
     267                task_release(TASK);
     268
     269        TASK = task;
     270
     271        task_hold(TASK);
     272
     273        before_task_runs_arch();
    257274}
    258275
     
    403420void scheduler_separated_stack(void)
    404421{
    405         task_t *old_task = TASK;
    406         as_t *old_as = AS;
    407 
    408422        assert((!THREAD) || (irq_spinlock_locked(&THREAD->lock)));
    409423        assert(CPU != NULL);
    410424        assert(interrupts_disabled());
    411 
    412         /*
    413          * Hold the current task and the address space to prevent their
    414          * possible destruction should thread_destroy() be called on this or any
    415          * other processor while the scheduler is still using them.
    416          */
    417         if (old_task)
    418                 task_hold(old_task);
    419 
    420         if (old_as)
    421                 as_hold(old_as);
    422425
    423426        if (THREAD) {
     
    471474        relink_rq(priority);
    472475
    473         /*
    474          * If both the old and the new task are the same,
    475          * lots of work is avoided.
    476          */
    477         if (TASK != THREAD->task) {
    478                 as_t *new_as = THREAD->task->as;
    479 
    480                 /*
    481                  * Note that it is possible for two tasks
    482                  * to share one address space.
    483                  */
    484                 if (old_as != new_as) {
    485                         /*
    486                          * Both tasks and address spaces are different.
    487                          * Replace the old one with the new one.
    488                          */
    489                         as_switch(old_as, new_as);
    490                 }
    491 
    492                 TASK = THREAD->task;
    493                 before_task_runs();
    494         }
    495 
    496         if (old_task)
    497                 task_release(old_task);
    498 
    499         if (old_as)
    500                 as_release(old_as);
     476        switch_task(THREAD->task);
    501477
    502478        irq_spinlock_lock(&THREAD->lock, false);
Note: See TracChangeset for help on using the changeset viewer.