[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH v3 3/4] lib/uksched: use posix_memalign to allocate stack



uk_thread_current indentifies the current stack using STACK_MASK_TOP. As a
consequence the stack should be aligned at STACK_SIZE. However the stack is
allocated using palloc which only guarantees page alignment.

Allocate the stack using posix_memalign, explicitely requesting an
alignment at STACK_SIZE.

Signed-off-by: Hugo Lefeuvre <hugo.lefeuvre@xxxxxxxxx>

---
Changes v3:
  - uk_sched_thread_destroy should use uk_free instead of uk_pfree since
    we moved create_stack to uk_posix_memalign.

diff --git a/lib/uksched/sched.c b/lib/uksched/sched.c
index c67f7ce..94ac5aa 100644
--- a/lib/uksched/sched.c
+++ b/lib/uksched/sched.c
@@ -141,7 +141,7 @@ static void *create_stack(struct uk_alloc *allocator)
 {
        void *stack;
 
-       stack = uk_palloc(allocator, STACK_SIZE);
+       uk_posix_memalign(allocator, &stack, STACK_SIZE, STACK_SIZE);
        if (stack == NULL) {
                uk_pr_warn("Error allocating thread stack.");
                return NULL;
@@ -250,7 +250,7 @@ void uk_sched_thread_destroy(struct uk_sched *sched, struct 
uk_thread *thread)
 
        UK_TAILQ_REMOVE(&sched->exited_threads, thread, thread_list);
        uk_thread_fini(thread, sched->allocator);
-       uk_pfree(sched->allocator, thread->stack, STACK_SIZE);
+       uk_free(sched->allocator, thread->stack);
        if (thread->tls)
                uk_free(sched->allocator, thread->tls);
        uk_free(sched->allocator, thread);
-- 
2.7.4


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.