From 63fd7f747915e38a5553bbcb55939d5e483445c7 Mon Sep 17 00:00:00 2001 From: deischen Date: Wed, 30 Apr 2003 15:05:17 +0000 Subject: Move the mailbox to the beginning of the thread and align the thread so that the context (SSE FPU state) is also aligned. --- lib/libpthread/arch/i386/include/pthread_md.h | 3 +++ lib/libpthread/thread/thr_create.c | 3 +++ lib/libpthread/thread/thr_init.c | 3 +++ lib/libpthread/thread/thr_kern.c | 12 +++++++++--- lib/libpthread/thread/thr_private.h | 10 ++++++---- 5 files changed, 24 insertions(+), 7 deletions(-) (limited to 'lib/libpthread') diff --git a/lib/libpthread/arch/i386/include/pthread_md.h b/lib/libpthread/arch/i386/include/pthread_md.h index 2611101..cb5a344 100644 --- a/lib/libpthread/arch/i386/include/pthread_md.h +++ b/lib/libpthread/arch/i386/include/pthread_md.h @@ -48,4 +48,7 @@ extern int _thr_getcontext(ucontext_t *); #define THR_GETCONTEXT(ucp) _thr_getcontext(ucp) #define THR_SETCONTEXT(ucp) _thr_setcontext(ucp) + +#define THR_ALIGNBYTES 15 +#define THR_ALIGN(td) (((unsigned)(td) + THR_ALIGNBYTES) & ~THR_ALIGNBYTES) #endif diff --git a/lib/libpthread/thread/thr_create.c b/lib/libpthread/thread/thr_create.c index 4c65d3c..0c9edbd 100644 --- a/lib/libpthread/thread/thr_create.c +++ b/lib/libpthread/thread/thr_create.c @@ -97,6 +97,7 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr, struct pthread *curthread, *new_thread; struct kse *kse = NULL; struct kse_group *kseg = NULL; + void *p; kse_critical_t crit; int i; int ret = 0; @@ -123,7 +124,9 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr, ret = EAGAIN; } else { /* Initialize the thread structure: */ + p = new_thread->alloc_addr; memset(new_thread, 0, sizeof(struct pthread)); + new_thread->alloc_addr = p; /* Check if default thread attributes are required: */ if (attr == NULL || *attr == NULL) diff --git a/lib/libpthread/thread/thr_init.c b/lib/libpthread/thread/thr_init.c index d43adf5..f06df6c 100644 --- a/lib/libpthread/thread/thr_init.c +++ b/lib/libpthread/thread/thr_init.c @@ -311,10 +311,13 @@ _libpthread_init(struct pthread *curthread) static void init_main_thread(struct pthread *thread) { + void *p; int i; /* Zero the initial thread structure. */ + p = thread->alloc_addr; memset(thread, 0, sizeof(struct pthread)); + thread->alloc_addr = p; /* Setup the thread attributes. */ thread->attr = _pthread_attr_default; diff --git a/lib/libpthread/thread/thr_kern.c b/lib/libpthread/thread/thr_kern.c index a153a4d..54d9dd7 100644 --- a/lib/libpthread/thread/thr_kern.c +++ b/lib/libpthread/thread/thr_kern.c @@ -2019,6 +2019,7 @@ struct pthread * _thr_alloc(struct pthread *curthread) { kse_critical_t crit; + void *p; struct pthread *thread = NULL; if (curthread != NULL) { @@ -2035,8 +2036,13 @@ _thr_alloc(struct pthread *curthread) _kse_critical_leave(crit); } } - if (thread == NULL) - thread = (struct pthread *)malloc(sizeof(struct pthread)); + if (thread == NULL) { + p = malloc(sizeof(struct pthread) + THR_ALIGNBYTES); + if (p != NULL) { + thread = (struct pthread *)THR_ALIGN(p); + thread->alloc_addr = p; + } + } return (thread); } @@ -2052,7 +2058,7 @@ _thr_free(struct pthread *curthread, struct pthread *thread) _lockuser_destroy(&thread->lockusers[i]); } _lock_destroy(&thread->lock); - free(thread); + free(thread->alloc_addr); } else { crit = _kse_critical_enter(); diff --git a/lib/libpthread/thread/thr_private.h b/lib/libpthread/thread/thr_private.h index 4d43242..22d2445 100644 --- a/lib/libpthread/thread/thr_private.h +++ b/lib/libpthread/thread/thr_private.h @@ -593,6 +593,12 @@ struct pthread_specific_elem { */ struct pthread { /* + * Thread mailbox is first so it cal be aligned properly. + */ + struct kse_thr_mailbox tmbx; + void *alloc_addr; /* real address (unaligned) */ + + /* * Magic value to help recognize a valid thread structure * from an invalid one: */ @@ -626,10 +632,6 @@ struct pthread { void *arg; struct pthread_attr attr; - /* - * Thread mailbox. - */ - struct kse_thr_mailbox tmbx; int active; /* thread running */ int blocked; /* thread blocked in kernel */ int need_switchout; -- cgit v1.1