PERFORCE change 65493 for review
David Xu
davidxu at FreeBSD.org
Fri Nov 19 18:39:28 PST 2004
http://perforce.freebsd.org/chv.cgi?CH=65493
Change 65493 by davidxu at davidxu_alona on 2004/11/20 02:38:56
1:1 threading only needs tcb, remove kcb.
Affected files ...
.. //depot/projects/davidxu_thread/src/lib/libthread/arch/amd64/Makefile.inc#2 edit
.. //depot/projects/davidxu_thread/src/lib/libthread/arch/amd64/amd64/pthread_md.c#2 edit
.. //depot/projects/davidxu_thread/src/lib/libthread/arch/amd64/include/pthread_md.h#2 edit
.. //depot/projects/davidxu_thread/src/lib/libthread/arch/i386/Makefile.inc#2 edit
.. //depot/projects/davidxu_thread/src/lib/libthread/arch/i386/i386/pthread_md.c#2 edit
.. //depot/projects/davidxu_thread/src/lib/libthread/arch/i386/include/pthread_md.h#2 edit
Differences ...
==== //depot/projects/davidxu_thread/src/lib/libthread/arch/amd64/Makefile.inc#2 (text+ko) ====
@@ -2,4 +2,4 @@
.PATH: ${.CURDIR}/arch/${MACHINE_ARCH}/${MACHINE_ARCH}
-SRCS+= context.S enter_uts.S pthread_md.c
+SRCS+= pthread_md.c
==== //depot/projects/davidxu_thread/src/lib/libthread/arch/amd64/amd64/pthread_md.c#2 (text+ko) ====
@@ -49,7 +49,6 @@
tcb = _rtld_allocate_tls(oldtls, sizeof(struct tcb), 16);
if (tcb) {
tcb->tcb_thread = thread;
- bzero(&tcb->tcb_tmbx, sizeof(tcb->tcb_tmbx));
}
return (tcb);
@@ -60,23 +59,3 @@
{
_rtld_free_tls(tcb, sizeof(struct tcb), 16);
}
-
-struct kcb *
-_kcb_ctor(struct kse *kse)
-{
- struct kcb *kcb;
-
- kcb = malloc(sizeof(struct kcb));
- if (kcb != NULL) {
- bzero(kcb, sizeof(struct kcb));
- kcb->kcb_self = kcb;
- kcb->kcb_kse = kse;
- }
- return (kcb);
-}
-
-void
-_kcb_dtor(struct kcb *kcb)
-{
- free(kcb);
-}
==== //depot/projects/davidxu_thread/src/lib/libthread/arch/amd64/include/pthread_md.h#2 (text+ko) ====
@@ -38,231 +38,75 @@
#include <machine/sysarch.h>
#include <ucontext.h>
-#define KSE_STACKSIZE 16384
#define DTV_OFFSET offsetof(struct tcb, tcb_dtv)
-#define THR_GETCONTEXT(ucp) \
- (void)_amd64_save_context(&(ucp)->uc_mcontext)
-#define THR_SETCONTEXT(ucp) \
- (void)_amd64_restore_context(&(ucp)->uc_mcontext, 0, NULL)
-
-#define PER_KSE
-#undef PER_THREAD
-
-struct kse;
struct pthread;
struct tdv;
/*
- * %fs points to a struct kcb.
+ * %fs points to a struct tcb.
*/
-struct kcb {
- struct tcb *kcb_curtcb;
- struct kcb *kcb_self; /* self reference */
- struct kse *kcb_kse;
- struct kse_mailbox kcb_kmbx;
-};
struct tcb {
struct tcb *tcb_self; /* required by rtld */
void *tcb_dtv; /* required by rtld */
struct pthread *tcb_thread;
void *tcb_spare[1]; /* align tcb_tmbx to 16 bytes */
- struct kse_thr_mailbox tcb_tmbx;
};
/*
* Evaluates to the byte offset of the per-kse variable name.
*/
-#define __kcb_offset(name) __offsetof(struct kcb, name)
+#define __tcb_offset(name) __offsetof(struct tcb, name)
/*
* Evaluates to the type of the per-kse variable name.
*/
-#define __kcb_type(name) __typeof(((struct kcb *)0)->name)
+#define __tcb_type(name) __typeof(((struct tcb *)0)->name)
/*
* Evaluates to the value of the per-kse variable name.
*/
-#define KCB_GET64(name) ({ \
- __kcb_type(name) __result; \
+#define TCB_GET64(name) ({ \
+ __tcb_type(name) __result; \
\
u_long __i; \
__asm __volatile("movq %%fs:%1, %0" \
: "=r" (__i) \
- : "m" (*(u_long *)(__kcb_offset(name)))); \
- __result = (__kcb_type(name))__i; \
- \
- __result; \
-})
-
-/*
- * Sets the value of the per-kse variable name to value val.
- */
-#define KCB_SET64(name, val) ({ \
- __kcb_type(name) __val = (val); \
- \
- u_long __i; \
- __i = (u_long)__val; \
- __asm __volatile("movq %1,%%fs:%0" \
- : "=m" (*(u_long *)(__kcb_offset(name))) \
- : "r" (__i)); \
-})
-
-static __inline u_long
-__kcb_readandclear64(volatile u_long *addr)
-{
- u_long result;
-
- __asm __volatile (
- " xorq %0, %0;"
- " xchgq %%fs:%1, %0;"
- "# __kcb_readandclear64"
- : "=&r" (result)
- : "m" (*addr));
- return (result);
-}
-
-#define KCB_READANDCLEAR64(name) ({ \
- __kcb_type(name) __result; \
+ : "m" (*(u_long *)(__tcb_offset(name)))); \
+ __result = (__tcb_type(name))__i; \
\
- __result = (__kcb_type(name)) \
- __kcb_readandclear64((u_long *)__kcb_offset(name)); \
__result; \
})
-
-#define _kcb_curkcb() KCB_GET64(kcb_self)
-#define _kcb_curtcb() KCB_GET64(kcb_curtcb)
-#define _kcb_curkse() ((struct kse *)KCB_GET64(kcb_kmbx.km_udata))
-#define _kcb_get_tmbx() KCB_GET64(kcb_kmbx.km_curthread)
-#define _kcb_set_tmbx(value) KCB_SET64(kcb_kmbx.km_curthread, (void *)value)
-#define _kcb_readandclear_tmbx() KCB_READANDCLEAR64(kcb_kmbx.km_curthread)
-
/*
* The constructors.
*/
struct tcb *_tcb_ctor(struct pthread *, int);
void _tcb_dtor(struct tcb *tcb);
-struct kcb *_kcb_ctor(struct kse *);
-void _kcb_dtor(struct kcb *);
/* Called from the KSE to set its private data. */
static __inline void
-_kcb_set(struct kcb *kcb)
+_tcb_set(struct tcb *tcb)
{
- amd64_set_fsbase(kcb);
+ amd64_set_fsbase(tcb);
}
/* Get the current kcb. */
-static __inline struct kcb *
-_kcb_get(void)
-{
- return (_kcb_curkcb());
-}
-
-static __inline struct kse_thr_mailbox *
-_kcb_critical_enter(void)
-{
- struct kse_thr_mailbox *crit;
-
- crit = _kcb_readandclear_tmbx();
- return (crit);
-}
-
-static __inline void
-_kcb_critical_leave(struct kse_thr_mailbox *crit)
-{
- _kcb_set_tmbx(crit);
-}
-
-static __inline int
-_kcb_in_critical(void)
-{
- return (_kcb_get_tmbx() == NULL);
-}
-
-static __inline void
-_tcb_set(struct kcb *kcb, struct tcb *tcb)
-{
- kcb->kcb_curtcb = tcb;
-}
-
static __inline struct tcb *
_tcb_get(void)
{
- return (_kcb_curtcb());
+ return TCB_GET64(tcb_self);
}
+extern int _thread_inited;
+
+/* Get the current thread. */
static __inline struct pthread *
_get_curthread(void)
{
- struct tcb *tcb;
-
- tcb = _kcb_curtcb();
- if (tcb != NULL)
- return (tcb->tcb_thread);
- else
- return (NULL);
-}
-
-static __inline struct kse *
-_get_curkse(void)
-{
- return ((struct kse *)_kcb_curkse());
-}
-
-void _amd64_enter_uts(struct kse_mailbox *km, kse_func_t uts, void *stack,
- size_t stacksz);
-int _amd64_restore_context(mcontext_t *mc, intptr_t val, intptr_t *loc);
-int _amd64_save_context(mcontext_t *mc);
-
-static __inline int
-_thread_enter_uts(struct tcb *tcb, struct kcb *kcb)
-{
- int ret;
-
- ret = _amd64_save_context(&tcb->tcb_tmbx.tm_context.uc_mcontext);
- if (ret == 0) {
- _amd64_enter_uts(&kcb->kcb_kmbx, kcb->kcb_kmbx.km_func,
- kcb->kcb_kmbx.km_stack.ss_sp,
- kcb->kcb_kmbx.km_stack.ss_size);
- /* We should not reach here. */
- return (-1);
- }
- else if (ret < 0)
- return (-1);
- return (0);
-}
-
-static __inline int
-_thread_switch(struct kcb *kcb, struct tcb *tcb, int setmbox)
-{
- extern int _libkse_debug;
-
- if ((kcb == NULL) || (tcb == NULL))
- return (-1);
- kcb->kcb_curtcb = tcb;
-
- if (_libkse_debug == 0) {
- tcb->tcb_tmbx.tm_lwp = kcb->kcb_kmbx.km_lwp;
- if (setmbox != 0)
- _amd64_restore_context(
- &tcb->tcb_tmbx.tm_context.uc_mcontext,
- (intptr_t)&tcb->tcb_tmbx,
- (intptr_t *)&kcb->kcb_kmbx.km_curthread);
- else
- _amd64_restore_context(
- &tcb->tcb_tmbx.tm_context.uc_mcontext,
- 0, NULL);
- /* We should not reach here. */
- } else {
- if (setmbox)
- kse_switchin(&tcb->tcb_tmbx, KSE_SWITCHIN_SETTMBX);
- else
- kse_switchin(&tcb->tcb_tmbx, 0);
- }
-
- return (-1);
+ if (_thread_inited)
+ return TCB_GET64(tcb_thread);
+ return NULL;
}
#endif
==== //depot/projects/davidxu_thread/src/lib/libthread/arch/i386/Makefile.inc#2 (text+ko) ====
@@ -2,4 +2,4 @@
.PATH: ${.CURDIR}/arch/${MACHINE_ARCH}/${MACHINE_ARCH}
-SRCS+= thr_enter_uts.S thr_getcontext.S pthread_md.c
+SRCS+= pthread_md.c
==== //depot/projects/davidxu_thread/src/lib/libthread/arch/i386/i386/pthread_md.c#2 (text+ko) ====
@@ -37,7 +37,6 @@
#include <signal.h>
#include <stdlib.h>
#include <string.h>
-#include <ucontext.h>
#include "rtld_tls.h"
#include "pthread_md.h"
@@ -45,76 +44,47 @@
struct tcb *
_tcb_ctor(struct pthread *thread, int initial)
{
+#ifndef COMPAT_32BIT
+ union descriptor ldt;
+#endif
struct tcb *tcb;
void *oldtls;
- if (initial) {
+ if (initial)
__asm __volatile("movl %%gs:0, %0" : "=r" (oldtls));
- } else {
+ else
oldtls = NULL;
- }
tcb = _rtld_allocate_tls(oldtls, sizeof(struct tcb), 16);
if (tcb) {
tcb->tcb_thread = thread;
- tcb->tcb_spare = 0;
- bzero(&tcb->tcb_tmbx, sizeof(tcb->tcb_tmbx));
- }
-
- return (tcb);
-}
-
-void
-_tcb_dtor(struct tcb *tcb)
-{
- _rtld_free_tls(tcb, sizeof(struct tcb), 16);
-}
-
-/*
- * Initialize KSD. This also includes setting up the LDT.
- */
-struct kcb *
-_kcb_ctor(struct kse *kse)
-{
#ifndef COMPAT_32BIT
- union descriptor ldt;
-#endif
- struct kcb *kcb;
-
- kcb = malloc(sizeof(struct kcb));
- if (kcb != NULL) {
- bzero(kcb, sizeof(struct kcb));
- kcb->kcb_self = kcb;
- kcb->kcb_kse = kse;
-#ifndef COMPAT_32BIT
- ldt.sd.sd_hibase = (unsigned int)kcb >> 24;
- ldt.sd.sd_lobase = (unsigned int)kcb & 0xFFFFFF;
- ldt.sd.sd_hilimit = (sizeof(struct kcb) >> 16) & 0xF;
- ldt.sd.sd_lolimit = sizeof(struct kcb) & 0xFFFF;
+ ldt.sd.sd_hibase = (unsigned int)tcb >> 24;
+ ldt.sd.sd_lobase = (unsigned int)tcb & 0xFFFFFF;
+ ldt.sd.sd_hilimit = (sizeof(struct tcb) >> 16) & 0xF;
+ ldt.sd.sd_lolimit = sizeof(struct tcb) & 0xFFFF;
ldt.sd.sd_type = SDT_MEMRWA;
ldt.sd.sd_dpl = SEL_UPL;
ldt.sd.sd_p = 1;
ldt.sd.sd_xx = 0;
ldt.sd.sd_def32 = 1;
ldt.sd.sd_gran = 0; /* no more than 1M */
- kcb->kcb_ldt = i386_set_ldt(LDT_AUTO_ALLOC, &ldt, 1);
- if (kcb->kcb_ldt < 0) {
- free(kcb);
- return (NULL);
+ tcb->tcb_ldt = i386_set_ldt(LDT_AUTO_ALLOC, &ldt, 1);
+ if (tcb->tcb_ldt < 0) {
+ free(tcb);
+ tcb = NULL;
}
#endif
}
- return (kcb);
+ return (tcb);
}
void
-_kcb_dtor(struct kcb *kcb)
+_tcb_dtor(struct tcb *tcb)
{
#ifndef COMPAT_32BIT
- if (kcb->kcb_ldt >= 0) {
- i386_set_ldt(kcb->kcb_ldt, NULL, 1);
- kcb->kcb_ldt = -1; /* just in case */
- }
+ if (tcb->tcb_ldt >= 0)
+ i386_set_ldt(tcb->tcb_ldt, NULL, 1);
#endif
- free(kcb);
+ _rtld_free_tls(tcb, sizeof(struct tcb), 16);
}
==== //depot/projects/davidxu_thread/src/lib/libthread/arch/i386/include/pthread_md.h#2 (text+ko) ====
@@ -1,5 +1,6 @@
/*-
* Copyright (c) 2002 Daniel Eischen <deischen at freebsd.org>.
+ * Copyright (c) 2005 David Xu <davidxu at freebsd.org>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -33,241 +34,83 @@
#include <stddef.h>
#include <sys/types.h>
-#include <sys/kse.h>
#include <machine/sysarch.h>
-#include <ucontext.h>
-extern int _thr_setcontext(mcontext_t *, intptr_t, intptr_t *);
-extern int _thr_getcontext(mcontext_t *);
-
-#define KSE_STACKSIZE 16384
#define DTV_OFFSET offsetof(struct tcb, tcb_dtv)
-#define THR_GETCONTEXT(ucp) _thr_getcontext(&(ucp)->uc_mcontext)
-#define THR_SETCONTEXT(ucp) _thr_setcontext(&(ucp)->uc_mcontext, 0, NULL)
-
-#define PER_KSE
-#undef PER_THREAD
-
-struct kse;
struct pthread;
/*
- * %gs points to a struct kcb.
+ * %gs points to a struct tcb.
*/
-struct kcb {
- struct tcb *kcb_curtcb;
- struct kcb *kcb_self; /* self reference */
- int kcb_ldt;
- struct kse *kcb_kse;
- struct kse_mailbox kcb_kmbx;
-};
-
struct tcb {
struct tcb *tcb_self; /* required by rtld */
void *tcb_dtv; /* required by rtld */
struct pthread *tcb_thread;
- void *tcb_spare; /* align tcb_tmbx to 16 bytes */
- struct kse_thr_mailbox tcb_tmbx;
+ int tcb_ldt;
};
/*
- * Evaluates to the byte offset of the per-kse variable name.
+ * Evaluates to the byte offset of the per-thread variable name.
*/
-#define __kcb_offset(name) __offsetof(struct kcb, name)
+#define __tcb_offset(name) __offsetof(struct tcb, name)
/*
- * Evaluates to the type of the per-kse variable name.
+ * Evaluates to the type of the per-thread variable name.
*/
-#define __kcb_type(name) __typeof(((struct kcb *)0)->name)
+#define __tcb_type(name) __typeof(((struct tcb *)0)->name)
/*
* Evaluates to the value of the per-kse variable name.
*/
-#define KCB_GET32(name) ({ \
- __kcb_type(name) __result; \
+#define TCB_GET32(name) ({ \
+ __tcb_type(name) __result; \
\
u_int __i; \
__asm __volatile("movl %%gs:%1, %0" \
: "=r" (__i) \
- : "m" (*(u_int *)(__kcb_offset(name)))); \
- __result = (__kcb_type(name))__i; \
+ : "m" (*(u_int *)(__tcb_offset(name)))); \
+ __result = (__tcb_type(name))__i; \
\
__result; \
})
/*
- * Sets the value of the per-kse variable name to value val.
- */
-#define KCB_SET32(name, val) ({ \
- __kcb_type(name) __val = (val); \
- \
- u_int __i; \
- __i = (u_int)__val; \
- __asm __volatile("movl %1,%%gs:%0" \
- : "=m" (*(u_int *)(__kcb_offset(name))) \
- : "r" (__i)); \
-})
-
-static __inline u_long
-__kcb_readandclear32(volatile u_long *addr)
-{
- u_long result;
-
- __asm __volatile (
- " xorl %0, %0;"
- " xchgl %%gs:%1, %0;"
- "# __kcb_readandclear32"
- : "=&r" (result)
- : "m" (*addr));
- return (result);
-}
-
-#define KCB_READANDCLEAR32(name) ({ \
- __kcb_type(name) __result; \
- \
- __result = (__kcb_type(name)) \
- __kcb_readandclear32((u_long *)__kcb_offset(name)); \
- __result; \
-})
-
-
-#define _kcb_curkcb() KCB_GET32(kcb_self)
-#define _kcb_curtcb() KCB_GET32(kcb_curtcb)
-#define _kcb_curkse() ((struct kse *)KCB_GET32(kcb_kmbx.km_udata))
-#define _kcb_get_tmbx() KCB_GET32(kcb_kmbx.km_curthread)
-#define _kcb_set_tmbx(value) KCB_SET32(kcb_kmbx.km_curthread, (void *)value)
-#define _kcb_readandclear_tmbx() KCB_READANDCLEAR32(kcb_kmbx.km_curthread)
-
-
-/*
* The constructors.
*/
struct tcb *_tcb_ctor(struct pthread *, int);
void _tcb_dtor(struct tcb *tcb);
-struct kcb *_kcb_ctor(struct kse *);
-void _kcb_dtor(struct kcb *);
-/* Called from the KSE to set its private data. */
+/* Called from the thread to set its private data. */
static __inline void
-_kcb_set(struct kcb *kcb)
+_tcb_set(struct tcb *tcb)
{
#ifndef COMPAT_32BIT
int val;
- val = (kcb->kcb_ldt << 3) | 7;
+ val = (tcb->tcb_ldt << 3) | 7;
__asm __volatile("movl %0, %%gs" : : "r" (val));
#else
- _amd64_set_gsbase(kcb);
+ _amd64_set_gsbase(tcb);
#endif
}
/* Get the current kcb. */
-static __inline struct kcb *
-_kcb_get(void)
-{
- return (_kcb_curkcb());
-}
-
-static __inline struct kse_thr_mailbox *
-_kcb_critical_enter(void)
-{
- struct kse_thr_mailbox *crit;
-
- crit = _kcb_readandclear_tmbx();
- return (crit);
-}
-
-static __inline void
-_kcb_critical_leave(struct kse_thr_mailbox *crit)
-{
- _kcb_set_tmbx(crit);
-}
-
-static __inline int
-_kcb_in_critical(void)
-{
- return (_kcb_get_tmbx() == NULL);
-}
-
-static __inline void
-_tcb_set(struct kcb *kcb, struct tcb *tcb)
-{
- kcb->kcb_curtcb = tcb;
-}
-
static __inline struct tcb *
_tcb_get(void)
{
- return (_kcb_curtcb());
+ return TCB_GET32(tcb_self);
}
+extern int _thread_inited;
+
+/* Get the current thread. */
static __inline struct pthread *
_get_curthread(void)
{
- struct tcb *tcb;
-
- tcb = _kcb_curtcb();
- if (tcb != NULL)
- return (tcb->tcb_thread);
- else
- return (NULL);
-}
-
-static __inline struct kse *
-_get_curkse(void)
-{
- return ((struct kse *)_kcb_curkse());
+ if (_thread_inited)
+ return TCB_GET32(tcb_thread);
+ return NULL;
}
-
-void _i386_enter_uts(struct kse_mailbox *km, kse_func_t uts, void *stack,
- size_t stacksz);
-
-static __inline int
-_thread_enter_uts(struct tcb *tcb, struct kcb *kcb)
-{
- int ret;
-
- ret = _thr_getcontext(&tcb->tcb_tmbx.tm_context.uc_mcontext);
- if (ret == 0) {
- _i386_enter_uts(&kcb->kcb_kmbx, kcb->kcb_kmbx.km_func,
- kcb->kcb_kmbx.km_stack.ss_sp,
- kcb->kcb_kmbx.km_stack.ss_size);
- /* We should not reach here. */
- return (-1);
- }
- else if (ret < 0)
- return (-1);
- return (0);
-}
-
-static __inline int
-_thread_switch(struct kcb *kcb, struct tcb *tcb, int setmbox)
-{
- extern int _libkse_debug;
-
- if ((kcb == NULL) || (tcb == NULL))
- return (-1);
- kcb->kcb_curtcb = tcb;
- if (_libkse_debug == 0) {
- tcb->tcb_tmbx.tm_lwp = kcb->kcb_kmbx.km_lwp;
- if (setmbox != 0)
- _thr_setcontext(&tcb->tcb_tmbx.tm_context.uc_mcontext,
- (intptr_t)&tcb->tcb_tmbx,
- (intptr_t *)&kcb->kcb_kmbx.km_curthread);
- else
- _thr_setcontext(&tcb->tcb_tmbx.tm_context.uc_mcontext,
- 0, NULL);
- } else {
- if (setmbox)
- kse_switchin(&tcb->tcb_tmbx, KSE_SWITCHIN_SETTMBX);
- else
- kse_switchin(&tcb->tcb_tmbx, 0);
- }
-
- /* We should not reach here. */
- return (-1);
-}
-
#endif
More information about the p4-projects
mailing list