From 5dd883833c394d53e7dd086076b94ab84d918109 Mon Sep 17 00:00:00 2001 From: Peter Wemm Date: Thu, 20 Nov 2003 22:54:44 +0000 Subject: [PATCH] Provide a streamlined '#define curthread __curthread()' for amd64 to avoid the compiler having to parse and optimize the PCPU_GET(curthread) so often. __curthread() is an inline optimized version of PCPU_GET(curthread) that knows that pc_curthread is at offset zero in the pcpu struct. Add a CTASSERT() to catch any possible changes to this. This accounts for just over a 1% wall clock speedup for total kernel compile/link time, and 20% compile time speedup on some specific files depending on which compile options are used. Approved by: re (jhb) --- sys/amd64/amd64/machdep.c | 3 +++ sys/amd64/include/pcpu.h | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/sys/amd64/amd64/machdep.c b/sys/amd64/amd64/machdep.c index 2140d7a02845..1e28aa9bd12d 100644 --- a/sys/amd64/amd64/machdep.c +++ b/sys/amd64/amd64/machdep.c @@ -121,6 +121,9 @@ __FBSDID("$FreeBSD$"); #include #include +/* Sanity check for __curthread() */ +CTASSERT(offsetof(struct pcpu, pc_curthread) == 0); + extern u_int64_t hammer_time(u_int64_t, u_int64_t); extern void dblfault_handler(void); diff --git a/sys/amd64/include/pcpu.h b/sys/amd64/include/pcpu.h index 9e0383a8f0a7..b96221b473da 100644 --- a/sys/amd64/include/pcpu.h +++ b/sys/amd64/include/pcpu.h @@ -159,6 +159,16 @@ extern struct pcpu *pcpup; #define PCPU_PTR(member) __PCPU_PTR(pc_ ## member) #define PCPU_SET(member, val) __PCPU_SET(pc_ ## member, val) +static __inline struct thread * +__curthread(void) +{ + struct thread *td; + + __asm __volatile("movq %%gs:0,%0" : "=r" (td)); + return (td); +} +#define Xurthread (__curthread()) + #else #error gcc or lint is required to use this file #endif