-
Notifications
You must be signed in to change notification settings - Fork 146
reuse the last flying host task for syscall #323
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
Conversation
|
Can one of the admins verify this patch? |
|
This approach allows multiple host threads to use the same lkl kernel task to improve performance. But it also allows one host thread to use multiple lkl kernel tasks. Any task state is not preserved. What if a socket is created by one but accessed by another? |
e963c82 to
5521cad
Compare
|
Hello, could you tell more about it? I think the host thread in the lkl-userspace-mod should not have kernel state associated. otherwise it will be broken even when "multiple host threads to use the same lkl kernel task".
socket in the kernel can be accessed by multiple tasks. What will happen after this patch? |
|
when a thread in the lkl-kernel mod and a signal happens and it call the lkl-syscall again. |
|
This will break the POSIX APIs when we will add support multiple processes. @thehajime is working on integration with rump which will allow that. So it needs to be at least configurable. However, I don't think this is the path to take. I think our optimizations our going into the wrong direction, we should focus on keeping the regular context switch model and optimize the context switch (via userspace threads maybe). |
|
What does "the regular context switch model" mean? |
Could you tell me more about it? |
1) Current tls-based scheme causes some unneeded host task reschedules
If the host thread B enters the syscall after
the host thread A resumed to userspace, the host tasks behind
the threads are different, and a reschedule is needed in
current code.
actually, this reschedule can be eliminated if
the host thread B reuses the same host task of A.
2) use stack(list_head) instead of tls
when tls is not enabled, all the in-syscall threads
compete on the running of the host0, it may cause
wrong wakeup or even dead lock. Example, thread A
had entered syscall and sleep-waited on something.
thread B enters syscall after A, it will wake up the
host0, thread A&B will compete the sched_sem of
the host0 for running, if A win, A will resume running
and sleep again soon. B can't run. even worse when
A was waiting on the event which is depended by B.
A&B will deadlock.
Signed-off-by: Lai Jiangshan <jiangshanlai@gmail.com>
5521cad to
adaf6f2
Compare
I missed it. Thanks for correcting me. |
The idea is that we can connect different userspace processes to LKL instead of the host kernel. In that case we want to keep the process separation so we need to have a strict 1:1 user process to LKL task in order to keep file descriptors and other process resources separated. See #298 on why this mode of operations is useful. With this mode you can basically "mount" a fs in userspace, then have utilities like cp connect via syscall proxy to the LKL instance and work out of the box. |
OK, this might get a bit log, so please bare with me :) Before the great optimizations Yuan did we where using the following simple model: for each host thread we had a Linux task associated which was running in a dedicated host thread that only served system calls. For example, lets say we have only a main application thread. When LKL is initialized, it will create some host threads for the Linux kernel dedicated kernel threads (stuff like ksoftirqd, kworker, etc) as well as the idle thread. Later, when LKL calls /sbin/init, a new host thread is created (we call it a system call thread). This new thread will wait for system calls issued by the main application thread. The problem we had with this approach was significant system call latency. For each system call the following was happening:
So, as you can see, we have 3 host context switches. As, currently, there is no way to explicitly switch between threads at the host level, we have a significant penalty [1]. To avoid this host context switch latency we started to eliminate the dedicated host threads associated with the Linux tasks and thus we significantly reduced the system call latency. Now back to my point :) While I think these optimizations are great in terms of performance, I think we are moving away too much from the Linux kernel task model and sooner or later we will run into trouble. So I am wondering: what if we take the other way around to achieve good performance, i.e. focus on reducing the host context switch. This can be done for example by using user threads instead of full kernel backed threads, which should be very cheap. Doing this kind of work will have other benefits, as we will have a natural way of supporting environments that can't support kernel threads (like bootloaders, UEFI*, etc.).
|
sorry, I wrongly considerred 'support multiple processes' as 'SMP support'. but I'm clear now. thanks! |
|
I am going to close this now as it looks like we are in agreement that such an approach is not reasonable. Please feel free to reopen it if I am wrong. |
Current tls-based scheme causes some unneeded host task reschedules
if the host thread B enters the syscall after the host thread A
resumed to userspace, the host tasks behind
the threads are different, and a reschedule is needed in
current code. actually, this reschedule can be eliminated if
the host thread B reuses the same host task of A.
use stack(list_head) instead of tls
when tls is not enabled, all the in-syscall threads
compete on the running of the host0, it may cause
wrong wakeup or even dead lock. Example, thread A
had entered syscall and sleep-waited on something.
thread B enters syscall after A, it will wake up the
host0, thread A&B will compete the sched_sem of
the host0 for running, if A win, A will resume running
and sleep again soon. B can't run. even worse when
A was waiting on the event which is depended by B.
A&B will deadlock.
Signed-off-by: Lai Jiangshan jiangshanlai@gmail.com
This change is