From: visa Date: Thu, 20 Apr 2017 16:07:52 +0000 (+0000) Subject: Get TCB address using the RDHWR instruction instead of __get_tcb(). X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=29879bdc832b3287067872faf4c1f759268348c9;p=openbsd Get TCB address using the RDHWR instruction instead of __get_tcb(). This gives fast access to the address on systems that implement the UserLocal register. TCB caching is still used when running in the single-threaded mode in order not to penalize old systems. The kernel counterpart of this change must be in place before using this diff! With guenther@ --- diff --git a/include/tib.h b/include/tib.h index 7dff1168ec9..597d2496bcd 100644 --- a/include/tib.h +++ b/include/tib.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tib.h,v 1.3 2016/05/07 19:05:21 guenther Exp $ */ +/* $OpenBSD: tib.h,v 1.4 2017/04/20 16:07:52 visa Exp $ */ /* * Copyright (c) 2011,2014 Philip Guenther * @@ -84,11 +84,9 @@ */ -/* If doesn't provide a better way, then use the default */ -#ifdef TCB_GET +/* All archs but mips64 have fast TCB_GET() and don't need caching */ +#ifndef __mips64__ # define TCB_HAVE_MD_GET 1 -#else -# define TCB_GET() __get_tcb() #endif #ifdef TCB_SET # define TCB_HAVE_MD_SET 1 diff --git a/lib/libc/include/cancel.h b/lib/libc/include/cancel.h index a858b80a1c2..ada417d3e12 100644 --- a/lib/libc/include/cancel.h +++ b/lib/libc/include/cancel.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cancel.h,v 1.2 2016/05/10 05:42:31 guenther Exp $ */ +/* $OpenBSD: cancel.h,v 1.3 2017/04/20 16:07:52 visa Exp $ */ /* * Copyright (c) 2015 Philip Guenther * @@ -26,11 +26,12 @@ __BEGIN_HIDDEN_DECLS __dead void _thread_canceled(void); __END_HIDDEN_DECLS -#ifdef __LIBC__ +#if defined(__LIBC__) && !defined(TCB_HAVE_MD_SET) /* - * Redirect macros that would use the syscall to instead use our callback + * Override TIB_GET macro to use the caching callback */ -#define __get_tcb() _thread_cb.tc_tcb() +#undef TIB_GET +#define TIB_GET() TCB_TO_TIB(_thread_cb.tc_tcb()) #endif #define PREP_CANCEL_POINT(tib) \ diff --git a/sys/arch/mips64/include/tcb.h b/sys/arch/mips64/include/tcb.h index 3c1ab597ea7..6e7a6b7bedc 100644 --- a/sys/arch/mips64/include/tcb.h +++ b/sys/arch/mips64/include/tcb.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tcb.h,v 1.3 2017/04/20 15:42:26 visa Exp $ */ +/* $OpenBSD: tcb.h,v 1.4 2017/04/20 16:07:52 visa Exp $ */ /* * Copyright (c) 2011 Philip Guenther @@ -42,6 +42,25 @@ __mips64_set_tcb(struct proc *p, void *tcb) /* ELF TLS ABI calls for small TCB, with static TLS data after it */ #define TLS_VARIANT 1 +static inline void * +__mips64_get_tcb(void) +{ + void *tcb; + + /* + * This invokes emulation in kernel if the system does not implement + * the RDHWR instruction or the UserLocal register. + */ + __asm__ volatile ( + " .set push\n" + " .set mips64r2\n" + " rdhwr %0, $29\n" + " .set pop\n" : "=r" (tcb)); + return tcb; +} + +#define TCB_GET() __mips64_get_tcb() + #endif /* _KERNEL */ #endif /* _MACHINE_TCB_H_ */