Changeset 23f36a3 in mainline


Ignore:
Timestamp:
2024-01-14T18:24:05Z (4 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master
Children:
6e49dab
Parents:
5663872
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2023-03-04 20:11:55)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2024-01-14 18:24:05)
Message:

Wrap fpu handling code in named functions

File:
1 edited

Legend:

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

    r5663872 r23f36a3  
    6767
    6868static void scheduler_separated_stack(void);
     69static void fpu_restore(void);
    6970
    7071atomic_size_t nrdy;  /**< Number of ready threads in the system. */
     
    8384        before_thread_runs_arch();
    8485
    85 #ifdef CONFIG_FPU_LAZY
    86         /*
    87          * The only concurrent modification possible for fpu_owner here is
    88          * another thread changing it from itself to NULL in its destructor.
    89          */
    90         thread_t *owner = atomic_load_explicit(&CPU->fpu_owner,
    91             memory_order_relaxed);
    92 
    93         if (THREAD == owner)
    94                 fpu_enable();
    95         else
    96                 fpu_disable();
    97 #elif defined CONFIG_FPU
    98         fpu_enable();
    99         if (THREAD->fpu_context_exists)
    100                 fpu_context_restore(&THREAD->fpu_context);
    101         else {
    102                 fpu_init();
    103                 THREAD->fpu_context_exists = true;
    104         }
    105 #endif
     86        fpu_restore();
    10687
    10788#ifdef CONFIG_UDEBUG
     
    341322}
    342323
     324/**
     325 * Do whatever needs to be done with current FPU state before we switch to
     326 * another thread.
     327 */
     328static void fpu_cleanup(void)
     329{
     330#if (defined CONFIG_FPU) && (!defined CONFIG_FPU_LAZY)
     331        fpu_context_save(&THREAD->fpu_context);
     332#endif
     333}
     334
     335/**
     336 * Set correct FPU state for this thread after switch from another thread.
     337 */
     338static void fpu_restore(void)
     339{
     340#ifdef CONFIG_FPU_LAZY
     341        /*
     342         * The only concurrent modification possible for fpu_owner here is
     343         * another thread changing it from itself to NULL in its destructor.
     344         */
     345        thread_t *owner = atomic_load_explicit(&CPU->fpu_owner,
     346            memory_order_relaxed);
     347
     348        if (THREAD == owner)
     349                fpu_enable();
     350        else
     351                fpu_disable();
     352
     353#elif defined CONFIG_FPU
     354        fpu_enable();
     355        if (THREAD->fpu_context_exists)
     356                fpu_context_restore(&THREAD->fpu_context);
     357        else {
     358                fpu_init();
     359                THREAD->fpu_context_exists = true;
     360        }
     361#endif
     362}
     363
    343364void scheduler(void)
    344365{
     
    370391                THREAD->kcycles += get_cycle() - THREAD->last_cycle;
    371392
    372 #if (defined CONFIG_FPU) && (!defined CONFIG_FPU_LAZY)
    373                 fpu_context_save(&THREAD->fpu_context);
    374 #endif
     393                fpu_cleanup();
     394
    375395                if (!context_save(&THREAD->saved_context)) {
    376396                        /*
Note: See TracChangeset for help on using the changeset viewer.