diff options
author | kib <kib@FreeBSD.org> | 2012-07-19 19:09:12 +0000 |
---|---|---|
committer | kib <kib@FreeBSD.org> | 2012-07-19 19:09:12 +0000 |
commit | ebf0cf4fd1e5909a88ee09a6231268d30c9f14d7 (patch) | |
tree | be675caf28ff4a939913574d8fc2b7e490e94fd0 /sys/amd64/include | |
parent | 223e24232e0e22efa530b704fdcd40845e18cce8 (diff) | |
download | FreeBSD-src-ebf0cf4fd1e5909a88ee09a6231268d30c9f14d7.zip FreeBSD-src-ebf0cf4fd1e5909a88ee09a6231268d30c9f14d7.tar.gz |
Introduce curpcb magic variable, similar to curthread, which is MD
amd64. It is implemented as __pure2 inline with non-volatile asm read
from pcpu, which allows a compiler to cache its results.
Convert most PCPU_GET(pcb) and curthread->td_pcb accesses into curpcb.
Note that __curthread() uses magic value 0 as an offsetof(struct pcpu,
pc_curthread). It seems to be done this way due to machine/pcpu.h
needs to be processed before sys/pcpu.h, because machine/pcpu.h
contributes machine-depended fields to the struct pcpu definition. As
result, machine/pcpu.h cannot use struct pcpu yet.
The __curpcb() also uses a magic constant instead of offsetof(struct
pcpu, pc_curpcb) for the same reason. The constants are now defined as
symbols and CTASSERTs are added to ensure that future KBI changes do
not break the code.
Requested and reviewed by: bde
MFC after: 3 weeks
Diffstat (limited to 'sys/amd64/include')
-rw-r--r-- | sys/amd64/include/pcpu.h | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/sys/amd64/include/pcpu.h b/sys/amd64/include/pcpu.h index d07dbac..5d1fd4d 100644 --- a/sys/amd64/include/pcpu.h +++ b/sys/amd64/include/pcpu.h @@ -216,16 +216,29 @@ extern struct pcpu *pcpup; #define PCPU_PTR(member) __PCPU_PTR(pc_ ## member) #define PCPU_SET(member, val) __PCPU_SET(pc_ ## member, val) +#define OFFSETOF_CURTHREAD 0 static __inline __pure2 struct thread * __curthread(void) { struct thread *td; - __asm("movq %%gs:0,%0" : "=r" (td)); + __asm("movq %%gs:%1,%0" : "=r" (td) + : "m" (*(char *)OFFSETOF_CURTHREAD)); return (td); } #define curthread (__curthread()) +#define OFFSETOF_CURPCB 32 +static __inline __pure2 struct pcb * +__curpcb(void) +{ + struct pcb *pcb; + + __asm("movq %%gs:%1,%0" : "=r" (pcb) : "m" (*(char *)OFFSETOF_CURPCB)); + return (pcb); +} +#define curpcb (__curpcb()) + #define IS_BSP() (PCPU_GET(cpuid) == 0) #else /* !lint || defined(__GNUCLIKE_ASM) && defined(__GNUCLIKE___TYPEOF) */ |