|
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Minios-devel] [UNIKRAFT PATCH v3 0/7] Thread-local storage support
This is v3 of the TLS series that allows the use of __thread variables. The
main changes from v2 are:
* Added a patch (1/7) that makes the plat/linuxu linker script
preprocessable. Used that to use the same macros in that linker script as
in the kvm and Xen ones.
* Fixed indentation.
* Moved a copyright notice.
*** v2 text below for reference ***
This is v2 of the TLS series that allows the use of __thread variables. I
reordered and refactored the patches quite extensively in the hopes of
making them more easy to follow and fix potential breaking of compiles.
The main changes from v1 are:
* Unifying the TLS section entries for the linker script by adding them to
common.lds.h that was added in patch e6a88d61.
* The first two patches aren't directly related to the series, but likewise
leverage e6a88d61 for further linker script unification and replacement of
numbers with defines.
* The implementation of the architecture-dependent helper functions is now
done both for x86 and for the Arm stub versions in one patch, and before
any of the functionality is used in plat/ code. That fixes a problem with
builds breaking for Arm before the last patch in the series.
* Renamed several header files to tls.h. I could still imagine those being
of more general use in the future (e.g., putting the extended register
switching code in there), but we can always rename them if and when that
happens.
*** v1 text below for reference ***
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 (7):
plat/linuxu: make linker script preprocessable
plat: move common section definitions from linker script to include
file
plat: Replace 0x1000 / 4096 with __PAGE_SIZE
plat: prepare linker script for thread-local storage
arch: provide thread-local storage helper functions
lib/uksched: create and delete thread-local storage area
plat: switch thread-local storage area on context switch
arch/arm/arm/include/uk/asm/tls.h | 62 ++++++++++++++++
arch/arm/arm64/include/uk/asm/tls.h | 72 ++++++++++++++++++
arch/x86/x86_64/include/uk/asm/tls.h | 73 +++++++++++++++++++
include/uk/arch/tls.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 | 35 ++++++++-
lib/uksched/thread.c | 13 ++--
plat/common/include/common.lds.h | 51 ++++++++++++-
plat/common/include/sections.h | 5 ++
plat/common/include/sw_ctx.h | 1 +
plat/common/include/tls.h | 41 +++++++++++
plat/common/include/x86/cpu_defs.h | 5 ++
plat/common/include/x86/tls.h | 39 ++++++++++
plat/common/sw_ctx.c | 10 ++-
plat/kvm/arm/link64.lds.S | 30 +-------
plat/kvm/x86/link64.lds.S | 15 ++--
plat/linuxu/Linker.uk | 8 +-
plat/linuxu/Makefile.uk | 4 +
plat/linuxu/arm/link.lds | 11 ---
plat/linuxu/arm/link.lds.S | 7 ++
plat/linuxu/include/linuxu/syscall-x86_64.h | 1 +
plat/linuxu/include/linuxu/syscall.h | 8 ++
.../x86/link64.lds => linuxu/include/tls.h} | 31 ++------
plat/linuxu/x86/link64.lds | 6 --
plat/linuxu/x86/link64.lds.S | 16 ++++
plat/xen/arm/link32.lds.S | 37 ++--------
plat/xen/x86/link64.lds.S | 13 +++-
29 files changed, 523 insertions(+), 125 deletions(-)
create mode 100644 arch/arm/arm/include/uk/asm/tls.h
create mode 100644 arch/arm/arm64/include/uk/asm/tls.h
create mode 100644 arch/x86/x86_64/include/uk/asm/tls.h
create mode 100644 include/uk/arch/tls.h
create mode 100644 plat/common/include/tls.h
create mode 100644 plat/common/include/x86/tls.h
delete mode 100644 plat/linuxu/arm/link.lds
create mode 100644 plat/linuxu/arm/link.lds.S
rename plat/{common/x86/link64.lds => linuxu/include/tls.h} (77%)
delete mode 100644 plat/linuxu/x86/link64.lds
create mode 100644 plat/linuxu/x86/link64.lds.S
--
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 |