Changeset 0366d09d in mainline for kernel/generic/src/proc/thread.c


Ignore:
Timestamp:
2023-02-07T16:49:43Z (21 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.