-
Notifications
You must be signed in to change notification settings - Fork 223
Description
Go (also known as Golang) is one of the languages currently popular for writing applications in. Ideally it would be possible to run those within Gramine. However, some issues within the Go runtime make that unreliable and slow.
Syscall interface
Gramine needs to be in charge of handling all syscalls made by the application. The recommended way to achieve this is to use a specific call instruction instead of syscall. We carry patches for glibc and musl to handle this for most applications. However, because of an interesting decision made by the Go team, Go doesn't use the libc to issue syscalls. This is not the first time this has caused issues.
For Gramine, the impact is that the fallback that traps the syscall instruction will be used. This causes a significant performance degradation, as many more context switches are required for each syscall. This is signalled by the following message printed during startup:
Emulating a raw syscall instruction. This degrades performance, consider patching your application to use Gramine syscall API.
As Go binaries are fully statically linked, the only solution seems to be patching the Go toolchain to create binaries with the Gramine-specific syscall ABI. Apart from the overhead of maintaining the patches, this would be somewhat annoying for users, as for most other stacks, the build system doesn't need to know about Gramine, and the binaries produced can be run on Linux directly for testing.
Go runtime thread count
Due to SGX limitations, we need to specify the total number of threads each process in the enclave might use (this is the sgx.thread_num manifest key). However, the number of threads the Go runtime may use is unbounded. The closest we have to limiting this is the GOMAXPROCS environment variable, however this doesn't count the threads that are blocked on a syscall, so it doesn't solve the problem.
Possible solutions:
- patch Go to introduce a proper thread count limit
- as above, but campaign to have it included upstream to ease the maintenance burden
- set
sgx.thread_numto a somewhat high number, cross your fingers and hope for the best (this is what's happening in practice right now) - wait for EDMM/SGXv2, which will allow dynamically allocating more threads (requires support in hardware, the Linux kernel and Gramine)