Changeset ed7e057 in mainline for kernel/generic/src


Ignore:
Timestamp:
2024-01-16T15:46:47Z (19 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master
Children:
29029ac0, a5b5f17
Parents:
4ed7870
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2024-01-15 20:09:30)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2024-01-16 15:46:47)
Message:

Add functions context_create(), context_replace() and context_swap()

and use them where appropriate, removing context_save() in the process.
Much like in userspace, context_swap() maintains natural control flow
as opposed to context_save()'s return-twice mechanic.

Beyond that, in the future, context_replace() and context_swap()
can be implemented more efficiently than the context_save()/
context_restore() pair. As of now, the original implementation is
retained.

Location:
kernel/generic/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/main/main.c

    r4ed7870 red7e057  
    8080#include <arch/arch.h>
    8181#include <arch.h>
    82 #include <arch/faddr.h>
    8382#include <ipc/ipc.h>
    8483#include <macros.h>
     
    174173            ALIGN_UP((uintptr_t) kdata_end - config.base, PAGE_SIZE);
    175174
    176         context_save(&ctx);
    177         context_set(&ctx, FADDR(main_bsp_separated_stack),
     175        context_create(&ctx, main_bsp_separated_stack,
    178176            bootstrap_stack, bootstrap_stack_size);
    179177        context_restore(&ctx);
     
    336334         * switch to this cpu's private stack prior to waking kmp up.
    337335         */
    338         context_t ctx;
    339         context_save(&ctx);
    340         context_set(&ctx, FADDR(main_ap_separated_stack),
    341             (uintptr_t) CPU_LOCAL->stack, STACK_SIZE);
    342         context_restore(&ctx);
     336        context_replace(main_ap_separated_stack, CPU_LOCAL->stack, STACK_SIZE);
    343337        /* not reached */
    344338}
  • kernel/generic/src/proc/scheduler.c

    r4ed7870 red7e057  
    309309
    310310        current_copy(CURRENT, (current_t *) CPU_LOCAL->stack);
    311 
    312         context_t ctx;
    313         context_save(&ctx);
    314         context_set(&ctx, FADDR(scheduler_separated_stack),
    315             (uintptr_t) CPU_LOCAL->stack, STACK_SIZE);
    316         context_restore(&ctx);
    317 
     311        context_replace(scheduler_separated_stack, CPU_LOCAL->stack, STACK_SIZE);
    318312        unreachable();
    319313}
     
    452446                /* Prefer the thread after it's woken up. */
    453447                THREAD->priority = -1;
    454         }
    455 
    456         if (!context_save(&THREAD->saved_context)) {
    457                 /*
    458                  * This is the place where threads leave scheduler();
    459                  */
    460 
    461                 irq_spinlock_unlock(&THREAD->lock, false);
    462                 interrupts_restore(ipl);
    463                 return;
    464448        }
    465449
     
    486470         */
    487471        context_t ctx;
    488         context_save(&ctx);
    489         context_set(&ctx, FADDR(scheduler_separated_stack),
    490             (uintptr_t) CPU_LOCAL->stack, STACK_SIZE);
    491         context_restore(&ctx);
    492 
    493         /* Not reached */
     472        context_create(&ctx, scheduler_separated_stack,
     473            CPU_LOCAL->stack, STACK_SIZE);
     474
     475        /* Switch to scheduler context and store current thread's context. */
     476        context_swap(&THREAD->saved_context, &ctx);
     477
     478        /* Returned from scheduler. */
     479
     480        irq_spinlock_unlock(&THREAD->lock, false);
     481        interrupts_restore(ipl);
    494482}
    495483
  • kernel/generic/src/proc/thread.c

    r4ed7870 red7e057  
    6060#include <arch/interrupt.h>
    6161#include <smp/ipi.h>
    62 #include <arch/faddr.h>
    6362#include <atomic.h>
    6463#include <memw.h>
     
    310309        irq_spinlock_unlock(&tidlock, true);
    311310
    312         memset(&thread->saved_context, 0, sizeof(thread->saved_context));
    313         context_set(&thread->saved_context, FADDR(cushion),
    314             (uintptr_t) thread->kstack, STACK_SIZE);
     311        context_create(&thread->saved_context, cushion, thread->kstack, STACK_SIZE);
    315312
    316313        current_initialize((current_t *) thread->kstack);
Note: See TracChangeset for help on using the changeset viewer.