x86: Store pointer to the current thread in gs:0
Apparently, reading from dr3 is slower than reading from memory with cache hit. Also, depending on hypervisor configuration, accessing dr3 may cause a VM exit (and, at least on kvm, it does), what makes it much slower than a memory access even when there is a cache miss.
This commit is contained in:
@@ -38,6 +38,8 @@
|
||||
#define USER_CODE_SELECTOR ((USER_CODE_SEGMENT << 3) | DPL_USER)
|
||||
#define USER_DATA_SELECTOR ((USER_DATA_SEGMENT << 3) | DPL_USER)
|
||||
|
||||
#define KERNEL_TLS_SELECTOR ((KERNEL_TLS_SEGMENT << 3) | DPL_KERNEL)
|
||||
|
||||
|
||||
#ifndef _ASSEMBLER
|
||||
// this file can also be included from assembler as well
|
||||
|
||||
@@ -30,9 +30,6 @@ void x86_restart_syscall(struct iframe* frame);
|
||||
void x86_set_tls_context(Thread* thread);
|
||||
|
||||
|
||||
#ifdef __x86_64__
|
||||
|
||||
|
||||
static inline Thread*
|
||||
arch_thread_get_current_thread(void)
|
||||
{
|
||||
@@ -42,6 +39,9 @@ arch_thread_get_current_thread(void)
|
||||
}
|
||||
|
||||
|
||||
#ifdef __x86_64__
|
||||
|
||||
|
||||
static inline void
|
||||
arch_thread_set_current_thread(Thread* t)
|
||||
{
|
||||
@@ -59,18 +59,10 @@ arch_thread_set_current_thread(Thread* t)
|
||||
void arch_syscall_64_bit_return_value(void);
|
||||
|
||||
|
||||
static inline Thread*
|
||||
arch_thread_get_current_thread(void)
|
||||
{
|
||||
Thread* t = (Thread*)x86_read_dr3();
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
static inline void
|
||||
arch_thread_set_current_thread(Thread* t)
|
||||
{
|
||||
x86_write_dr3(t);
|
||||
asm volatile("mov %0, %%gs:0" : : "r" (t));
|
||||
}
|
||||
|
||||
|
||||
@@ -82,3 +74,4 @@ arch_thread_set_current_thread(Thread* t)
|
||||
#endif
|
||||
|
||||
#endif /* _KERNEL_ARCH_x86_THREAD_H */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user