Skip to content

Commit

Permalink
lkl: add support for direct syscalls
Browse files Browse the repository at this point in the history
This patch reworks the LKL syscall interface to avoid the performance
penalty caused by the context switch between the host thread and the
associated syscall kernel thread.

The main idea is to associate Linux threads (struct task_struct) with
existing host threads instead of creating a new coresponding "syscall
thread" for host threads that issue system calls.

When issuing a system call, from a host thread, all we need to do is:
(a) make sure we exclusively have the cpu by calling lkl_cpu_get() and
(b) make sure we are in the right Linux thread context by calling
switch_to_host_task().

When a host thread finishes a system call, while it does yield the cpu,
it does not scheduled out the Linux thread context to keep it available
for the next system call. This means that while interrupts will run,
kernel threads will be delayed until the next system call.

The patch improves the LKL sycall latency by ~60 times on my machine on
synthetic benchmarks.

This patch also removes the lkl_create_syscall_thread() and
lkl_stop_syscall_thread() as they are not necessary anymore.

Signed-off-by: Octavian Purdila <tavi@cs.pub.ro>
  • Loading branch information
tavip committed Oct 15, 2016
1 parent 6fcd650 commit e1cd839
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 369 deletions.
4 changes: 2 additions & 2 deletions arch/lkl/include/asm/syscalls.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#ifndef _ASM_LKL_SYSCALLS_H
#define _ASM_LKL_SYSCALLS_H

int initial_syscall_thread(void *);
void free_initial_syscall_thread(void);
int syscalls_init(void);
void syscalls_cleanup(void);
long lkl_syscall(long no, long *params);

#define sys_mmap sys_mmap_pgoff
Expand Down
1 change: 0 additions & 1 deletion arch/lkl/include/asm/unistd.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include <uapi/asm/unistd.h>

__SYSCALL(__NR_create_syscall_thread, sys_create_syscall_thread)
__SYSCALL(__NR_virtio_mmio_device_add, sys_virtio_mmio_device_add)

#define __SC_ASCII(t, a) #t "," #a
Expand Down
3 changes: 1 addition & 2 deletions arch/lkl/include/uapi/asm/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@

#include <asm-generic/unistd.h>

#define __NR_create_syscall_thread (__NR_arch_specific_syscall + 0)
#define __NR_virtio_mmio_device_add (__NR_arch_specific_syscall + 1)
#define __NR_virtio_mmio_device_add (__NR_arch_specific_syscall + 0)
13 changes: 10 additions & 3 deletions arch/lkl/kernel/setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,12 @@ int __init lkl_start_kernel(struct lkl_host_operations *ops,
}

lkl_ops->sem_down(init_sem);
current_thread_info()->tid = lkl_ops->thread_self();
lkl_cpu_change_owner(current_thread_info()->tid);

lkl_cpu_put();
is_running = 1;

return 0;

out_free_init_sem:
Expand Down Expand Up @@ -118,7 +122,7 @@ long lkl_sys_halt(void)

lkl_cpu_wait_shutdown();

free_initial_syscall_thread();
syscalls_cleanup();
threads_cleanup();
/* Shutdown the clockevents source. */
tick_suspend_local();
Expand Down Expand Up @@ -151,9 +155,12 @@ static int lkl_run_init(struct linux_binprm *bprm)

set_binfmt(&lkl_run_init_binfmt);

initial_syscall_thread(init_sem);
init_pid_ns.child_reaper = 0;

syscalls_init();

kernel_halt();
lkl_ops->sem_up(init_sem);
lkl_ops->thread_exit();

return 0;
}
Expand Down
Loading

0 comments on commit e1cd839

Please sign in to comment.