-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
making thread_local fiber_local #618
base: main
Are you sure you want to change the base?
Conversation
ATTR must be non-NULL and point to a valid pthread_attr. | ||
PDP must be non-NULL. */ | ||
-static int | ||
+int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
making the internal function allocate_stack()
in lib pthread public and accessible by, say, fiber_create().
@@ -534,14 +540,7 @@ namespace photon | |||
vcpu = current->get_vcpu(); | |||
(plock = &vcpu->runq_lock) -> foreground_lock(); | |||
} | |||
mutable bool update_current = false; | |||
void set_current(thread* th) const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's no longer the need to set/switch the thread-local variable CURRENT as part of context switching, given that it has become a fiber-local varible.
thread/thread.cpp
Outdated
#if defined(__x86_64__) | ||
#if !defined(_WIN64) | ||
asm( | ||
DEF_ASM_FUNC(_photon_switch_context) // (void** rdi_to, void** rsi_from) | ||
R"( | ||
rdfsbase %rax |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Save and restore fs
register as part of context switching. It points to thread control block (TCB) and thread-local storage (TLS).
X86_64 only, for now.
void _photon_thread_die(thread* th) { | ||
static __attribute__((noreturn)) | ||
void _photon_thread_stub() { | ||
register thread* th asm("rbp"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On entry rbp
points to struct thread.
size_t pstacksize; | ||
pthread_attr_t attr; | ||
pthread_attr_init(&attr); | ||
allocate_stack((struct pthread_attr*)&attr, &pd, (void**)&ptr, &pstacksize); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We must make use of allocate_thread()
in lib pthread to allocate the stack, TCB (that compatible to threading facilities) and TLS (for all modules, no matter loaded at startup time or run time).
+#if TLS_TCB_AT_TP | ||
+ /* Reference to the TCB itself. */ | ||
+ pd->header.self = pd; | ||
+ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines are moved from pthread_create(), because fiber_create() doesn't have the definition of *pd, and can not do it outside.
jmp *%rsi | ||
)" | ||
|
||
DEF_ASM_FUNC(_photon_thread_stub) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_photon_thread_stub() becomes more complex and would better be implemented in C++.
No description provided.