Changeset 0366d09d in mainline


Ignore:
Timestamp:
2023-02-07T16:49:43Z (16 months ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
78acbc72
Parents:
1eaead4
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2022-08-14 14:08:42)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2023-02-07 16:49:43)
Message:

Avoid separate allocation for FPU context

With _Alignas, we can encode alignment in the type itself and
include it directly as a member of thread_t, thus removing
the need for a separate allocation.

The alignment requirement is never more than 16 bytes,
so this adds only minimal extra padding to the structure.

Location:
kernel
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/abs32le/include/arch/fpu_context.h

    r1eaead4 r0366d09d  
    3636#define KERN_abs32le_FPU_CONTEXT_H_
    3737
    38 #define FPU_CONTEXT_ALIGN  16
    39 
    4038/*
    4139 * On real hardware this stores the FPU registers
  • kernel/arch/arm32/include/arch/fpu_context.h

    r1eaead4 r0366d09d  
    4040#include <stdint.h>
    4141
    42 #define FPU_CONTEXT_ALIGN    8
    43 
    4442/*
    4543 * ARM Architecture reference manual, p B-1529.
    4644 */
    4745typedef struct {
    48         uint32_t fpexc;
     46        _Alignas(8) uint32_t fpexc;
    4947        uint32_t fpscr;
    5048        uint32_t s[64];
  • kernel/arch/arm64/include/arch/fpu_context.h

    r1eaead4 r0366d09d  
    3939#include <arch/fpu_context_struct.h>
    4040
    41 #define FPU_CONTEXT_ALIGN  16
    42 
    4341#endif
    4442
  • kernel/arch/arm64/include/arch/fpu_context_struct.h

    r1eaead4 r0366d09d  
    4242/** ARM64 FPU context. */
    4343typedef struct fpu_context {
    44         uint128_t vregs[32];
     44        _Alignas(16) uint128_t vregs[32];
    4545        uint32_t fpcr;
    4646        uint32_t fpsr;
  • kernel/arch/ia32/include/arch/fpu_context.h

    r1eaead4 r0366d09d  
    3838#include <stdint.h>
    3939
    40 #define FPU_CONTEXT_ALIGN  16
    41 
    4240typedef struct {
    43         uint8_t fpu[512];  /* FXSAVE & FXRSTOR storage area */
     41        _Alignas(16) uint8_t fpu[512];  /* FXSAVE & FXRSTOR storage area */
    4442} fpu_context_t;
    4543
  • kernel/arch/ia64/include/arch/fpu_context.h

    r1eaead4 r0366d09d  
    3636#define KERN_ia64_FPU_CONTEXT_H_
    3737
    38 #define FPU_CONTEXT_ALIGN 16
    39 
    4038#include <_bits/int128_t.h>
    4139
     
    4341
    4442typedef struct {
    45         uint128_t fr[FRS];
     43        _Alignas(16) uint128_t fr[FRS];
    4644} fpu_context_t;
    4745
  • kernel/arch/mips32/include/arch/fpu_context.h

    r1eaead4 r0366d09d  
    3939#include <arch/fpu_context_struct.h>
    4040
    41 #define FPU_CONTEXT_ALIGN    sizeof(sysarg_t)
    42 
    4341#endif
    4442
  • kernel/arch/mips32/include/arch/fpu_context_struct.h

    r1eaead4 r0366d09d  
    4242
    4343typedef struct fpu_context {
    44         sysarg_t dregs[32];
     44        _Alignas(sizeof(sysarg_t)) sysarg_t dregs[32];
    4545        sysarg_t cregs[32];
    4646} fpu_context_t;
  • kernel/arch/ppc32/include/arch/fpu_context.h

    r1eaead4 r0366d09d  
    3636#define KERN_ppc32_FPU_CONTEXT_H_
    3737
    38 #define FPU_CONTEXT_ALIGN       8
    39 
    4038#include <arch/fpu_context_struct.h>
    4139
  • kernel/arch/ppc32/include/arch/fpu_context_struct.h

    r1eaead4 r0366d09d  
    7070
    7171typedef struct fpu_context {
    72         uint64_t fr0;
     72        _Alignas(8) uint64_t fr0;
    7373        uint64_t fr1;
    7474        uint64_t fr2;
  • kernel/arch/sparc64/include/arch/fpu_context.h

    r1eaead4 r0366d09d  
    3838#include <stdint.h>
    3939
    40 #define FPU_CONTEXT_ALIGN       8
    41 
    4240typedef struct {
    43         uint64_t        d[32];
    44         uint64_t        fsr;
     41        _Alignas(8) uint64_t d[32];
     42        uint64_t fsr;
    4543} fpu_context_t;
    4644
  • kernel/generic/include/proc/thread.h

    r1eaead4 r0366d09d  
    151151        link_t joiner_link;
    152152
    153         fpu_context_t *saved_fpu_context;
     153#ifdef CONFIG_FPU
     154        fpu_context_t fpu_context;
     155#endif
    154156        bool fpu_context_exists;
    155157
  • kernel/generic/src/proc/scheduler.c

    r1eaead4 r0366d09d  
    9797        fpu_enable();
    9898        if (THREAD->fpu_context_exists)
    99                 fpu_context_restore(THREAD->saved_fpu_context);
     99                fpu_context_restore(&THREAD->fpu_context);
    100100        else {
    101101                fpu_init();
     
    140140        if (CPU->fpu_owner != NULL) {
    141141                irq_spinlock_lock(&CPU->fpu_owner->lock, false);
    142                 fpu_context_save(CPU->fpu_owner->saved_fpu_context);
     142                fpu_context_save(&CPU->fpu_owner->fpu_context);
    143143
    144144                /* Don't prevent migration */
     
    150150        irq_spinlock_lock(&THREAD->lock, false);
    151151        if (THREAD->fpu_context_exists) {
    152                 fpu_context_restore(THREAD->saved_fpu_context);
     152                fpu_context_restore(&THREAD->fpu_context);
    153153        } else {
    154154                fpu_init();
     
    325325
    326326#if (defined CONFIG_FPU) && (!defined CONFIG_FPU_LAZY)
    327                 fpu_context_save(THREAD->saved_fpu_context);
     327                fpu_context_save(&THREAD->fpu_context);
    328328#endif
    329329                if (!context_save(&THREAD->saved_context)) {
  • kernel/generic/src/proc/thread.c

    r1eaead4 r0366d09d  
    102102static slab_cache_t *thread_cache;
    103103
    104 #ifdef CONFIG_FPU
    105 slab_cache_t *fpu_context_cache;
    106 #endif
    107 
    108104static void *threads_getkey(odlink_t *);
    109105static int threads_cmp(void *, void *);
     
    164160        /* call the architecture-specific part of the constructor */
    165161        thr_constructor_arch(thread);
    166 
    167 #ifdef CONFIG_FPU
    168         thread->saved_fpu_context = slab_alloc(fpu_context_cache,
    169             FRAME_ATOMIC | kmflags);
    170         if (!thread->saved_fpu_context)
    171                 return ENOMEM;
    172 #endif /* CONFIG_FPU */
    173162
    174163        /*
     
    198187        uintptr_t stack_phys =
    199188            frame_alloc(STACK_FRAMES, kmflags, STACK_SIZE - 1);
    200         if (!stack_phys) {
    201 #ifdef CONFIG_FPU
    202                 assert(thread->saved_fpu_context);
    203                 slab_free(fpu_context_cache, thread->saved_fpu_context);
    204 #endif
     189        if (!stack_phys)
    205190                return ENOMEM;
    206         }
    207191
    208192        thread->kstack = (uint8_t *) PA2KA(stack_phys);
     
    225209        frame_free(KA2PA(thread->kstack), STACK_FRAMES);
    226210
    227 #ifdef CONFIG_FPU
    228         assert(thread->saved_fpu_context);
    229         slab_free(fpu_context_cache, thread->saved_fpu_context);
    230 #endif
    231 
    232211        return STACK_FRAMES;  /* number of frames freed */
    233212}
     
    243222
    244223        atomic_store(&nrdy, 0);
    245         thread_cache = slab_cache_create("thread_t", sizeof(thread_t), 0,
     224        thread_cache = slab_cache_create("thread_t", sizeof(thread_t), _Alignof(thread_t),
    246225            thr_constructor, thr_destructor, 0);
    247 
    248 #ifdef CONFIG_FPU
    249         fpu_context_cache = slab_cache_create("fpu_context_t",
    250             sizeof(fpu_context_t), FPU_CONTEXT_ALIGN, NULL, NULL, 0);
    251 #endif
    252226
    253227        odict_initialize(&threads, threads_getkey, threads_cmp);
Note: See TracChangeset for help on using the changeset viewer.