[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT PATCH 0/4] Thread-local storage support
This patch series introduces so-called "native" thread-local storage support to unikraft. That is, static variables can be annotated with the keyword '__thread' and then work as thread-local variables. That is, a global or static local variable '__thread int a' will be thread-specific, without any need for other syntactic hoops to jump through (why hello there, pthread keys!). This works by aggregating all these variables into two specific ELF sections, .tdata and .tbss, depending on whether they are initialized at compile time or not. Each thread, on creation, then gets a copy of this area. A register is then set aside to point at this area, allowing immediate and efficient access by just reading from and writing to addresses defined by an offset from the address the register contains. When switching between threads, the register's content is changed to point to the corresponding TLS area. For unikraft, I only implemented this simple implementation. All of this gets a lot more complicated when dynamic linking is added to the mix, requiring relocation, lookup vectors, etc. Thankfully, for a unikernel, none of this matters really... unless someone wants to implement dynamic linking for unikraft, then they'll have to revisit this. Room for improvement: 1) The Arm implementation is by no stretch of imagination complete. There's only boilerplate code for creating the TLS area, and none at all for TLS register switching at context switch. This is mostly because there is, as of yet, no proper scheduling support for Arm, so this will have to be revisited at that point. I tried to set everything up to make adding this feature as painless as possible. 2) The current implementation always mallocs a new area for each thread's TLS. This could be optimized by reducing the number of mallocs. For example, the TLS area could be allocated in one contiguous block with the uk_thread structure or the stack, or, if the TLS area is small, it could be directly allocated on the thread's stack. Florian Schmidt (4): plat: prepare linker script for thread-local storage lib/uksched: create and delete thread-local storage area plat: switch thread-local storage area on context switch arch: boilerplate Arm support for thread-local storage arch/arm/arm/include/uk/asm/thread.h | 60 ++++++++++++++++++ arch/arm/arm64/include/uk/asm/thread.h | 70 +++++++++++++++++++++ arch/x86/x86_64/include/uk/asm/thread.h | 69 ++++++++++++++++++++ include/uk/arch/thread.h | 40 ++++++++++++ include/uk/plat/thread.h | 8 ++- lib/uksched/include/uk/sched.h | 3 + lib/uksched/include/uk/thread.h | 3 +- lib/uksched/sched.c | 54 +++++++++++----- lib/uksched/thread.c | 13 ++-- plat/common/include/sections.h | 5 ++ plat/common/include/sw_ctx.h | 1 + plat/common/include/thread_switch.h | 43 +++++++++++++ plat/common/include/x86/thread_switch.h | 41 ++++++++++++ plat/common/sw_ctx.c | 10 ++- plat/kvm/arm/link64.lds.S | 18 ++++++ plat/kvm/x86/link64.lds | 18 ++++++ plat/linuxu/Linker.uk | 1 + plat/linuxu/include/linuxu/syscall-x86_64.h | 1 + plat/linuxu/include/linuxu/syscall.h | 7 +++ plat/linuxu/include/thread_switch.h | 46 ++++++++++++++ plat/linuxu/link.ld | 22 +++++++ plat/xen/arm/link32.lds | 18 ++++++ plat/xen/x86/link64.lds | 18 ++++++ 23 files changed, 542 insertions(+), 27 deletions(-) create mode 100644 arch/arm/arm/include/uk/asm/thread.h create mode 100644 arch/arm/arm64/include/uk/asm/thread.h create mode 100644 arch/x86/x86_64/include/uk/asm/thread.h create mode 100644 include/uk/arch/thread.h create mode 100644 plat/common/include/thread_switch.h create mode 100644 plat/common/include/x86/thread_switch.h create mode 100644 plat/linuxu/include/thread_switch.h create mode 100644 plat/linuxu/link.ld -- 2.21.0 _______________________________________________ Minios-devel mailing list Minios-devel@xxxxxxxxxxxxxxxxxxxx https://lists.xenproject.org/mailman/listinfo/minios-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |