summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authordeischen <deischen@FreeBSD.org>2003-04-30 15:05:17 +0000
committerdeischen <deischen@FreeBSD.org>2003-04-30 15:05:17 +0000
commit63fd7f747915e38a5553bbcb55939d5e483445c7 (patch)
tree9350a8aef34768a87292c8deae80e7fc8f1af999 /lib
parent7a4c9eae2ed9416c9c848f1f44a8aa02b7e6da7f (diff)
downloadFreeBSD-src-63fd7f747915e38a5553bbcb55939d5e483445c7.zip
FreeBSD-src-63fd7f747915e38a5553bbcb55939d5e483445c7.tar.gz
Move the mailbox to the beginning of the thread and align the
thread so that the context (SSE FPU state) is also aligned.
Diffstat (limited to 'lib')
-rw-r--r--lib/libkse/arch/i386/include/pthread_md.h3
-rw-r--r--lib/libkse/thread/thr_create.c3
-rw-r--r--lib/libkse/thread/thr_init.c3
-rw-r--r--lib/libkse/thread/thr_kern.c12
-rw-r--r--lib/libkse/thread/thr_private.h10
-rw-r--r--lib/libpthread/arch/i386/include/pthread_md.h3
-rw-r--r--lib/libpthread/thread/thr_create.c3
-rw-r--r--lib/libpthread/thread/thr_init.c3
-rw-r--r--lib/libpthread/thread/thr_kern.c12
-rw-r--r--lib/libpthread/thread/thr_private.h10
10 files changed, 48 insertions, 14 deletions
diff --git a/lib/libkse/arch/i386/include/pthread_md.h b/lib/libkse/arch/i386/include/pthread_md.h
index 2611101..cb5a344 100644
--- a/lib/libkse/arch/i386/include/pthread_md.h
+++ b/lib/libkse/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/libkse/thread/thr_create.c b/lib/libkse/thread/thr_create.c
index 4c65d3c..0c9edbd 100644
--- a/lib/libkse/thread/thr_create.c
+++ b/lib/libkse/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/libkse/thread/thr_init.c b/lib/libkse/thread/thr_init.c
index d43adf5..f06df6c 100644
--- a/lib/libkse/thread/thr_init.c
+++ b/lib/libkse/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/libkse/thread/thr_kern.c b/lib/libkse/thread/thr_kern.c
index a153a4d..54d9dd7 100644
--- a/lib/libkse/thread/thr_kern.c
+++ b/lib/libkse/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/libkse/thread/thr_private.h b/lib/libkse/thread/thr_private.h
index 4d43242..22d2445 100644
--- a/lib/libkse/thread/thr_private.h
+++ b/lib/libkse/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;
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;
OpenPOWER on IntegriCloud