-
Notifications
You must be signed in to change notification settings - Fork 48
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
Moved uspace field from thread_t to proc_t #289
Conversation
sys/vm_map.c
Outdated
#include <mips/mips.h> | ||
|
||
static vm_map_t kspace; | ||
static vm_map_t *uspace = NULL; |
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 better place to keep it – please move it to pcpu
structure.
mips/switch.S
Outdated
@@ -39,7 +39,7 @@ ctx_resume: | |||
LOAD_PCPU($t0) | |||
sw $s0, PCPU_CURTHREAD($t0) | |||
|
|||
lw $a0, TD_USPACE($s0) | |||
lw $a0, PCPU_USPACE($t0) |
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.
I'm not sure that works at all? Instead of reading which vm_map
this thread process uses, you just activate the one that is currently active. That doesn't change the current map at all, right? Or do I miss something?
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.
Oops... you're right. It's a shame I introduced a bug with this change -_-
As you know We have to find an alternative way to synchronize the parts of kernel that needlessly use |
Yes, I've only used First thing is that I wouldn't worry much about
Side note: I haven't thought about it in greater detail, but what if a thread that activates a particular |
Multithreading doesn't play well with unix process model. Handling properly
A programmer that calls Let's ignore weird corner cases and support the most common scenario well , which is |
I've managed to confirm that Linux destroys all threads on a call to |
sys/vm_map.c
Outdated
it's okay if we get preempted - the working vm map will be restored on | ||
context switch. */ | ||
/* Temporarily switch to the new map, so that we may write contents. */ | ||
critical_enter(); |
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.
Is really critical_enter()
required here? Can we make weaker assumptions?
Perhaps thread_self()->proc->p_nthreads == 1
assertion is just enough to perform this step correctly?
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'd need to check if there is only one thread in this process AND set proc->p_uspace = newmap
for the duration of the copy process.
EDIT: Also, this would only work if clone is called by a user thread. Kernel threads have their userspace map reset to NULL on each context switch.
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.
Ok. So the minimum assumption we must take is that we enter vm_map_clone
with:
- user-space thread (i.e. with
p_uspace
in place), - the only thread in a process – thus we know that no other thread (within the same process) will be started in the meantime.
If that is correct, please drop critical section and enforce above assumptions with assert
.
Moving
td_uspace
top_uspace
turned out to be more complicated than I expected it to be. This is because we've been using thetd_uspace
field in two ways:If we want the
uspace
to be a property of a process and shared between multiple threads, than we can no longer use it for 2, it wouldn't make any sense. Therefore I had to significantly modify the semantics ofvm_map_activate
. Until now, it would activate avm_map
and assign it to the current thread. As threads no longer have each their ownvm_map
reference, the former is no longer possible. So now allvm_map_activate
does is activating thevm_map
for use. This, in turn, means that we need to make sure to disable preemption while we're using an activevm_map
that is not native to the current thread/process. Therefore I've been forced to add extra critical_sections tovm_map_clone
anddo_exec
, as both these temporarily activate a different userspacevm_map
in order to prepare it.I've also had to completely disable the
sched
test - as threads no longer carry auspace
, the test is pointless. It was already marked asKTEST_FLAG_BROKEN
, so it's not like we've been using it a lot.