Skip to content
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

Plugin makes 6 extra syscalls for every "gettimeofday" call #3227

Open
stevenengler opened this issue Nov 10, 2023 · 0 comments
Open

Plugin makes 6 extra syscalls for every "gettimeofday" call #3227

stevenengler opened this issue Nov 10, 2023 · 0 comments
Labels
Tag: Performance Related to improving shadow's run-time Type: Enhancement New functionality or improved design

Comments

@stevenengler
Copy link
Contributor

stevenengler commented Nov 10, 2023

Whenever glibc tries to get the time, it seems to try to get timezone information first. It does this by reading "/etc/localtime", and in Shadow we handle this as a special-case that returns data from "/usr/share/zoneinfo/UTC" instead. This results in a lot of unnecessary extra syscalls. Every gettimeofday() call (which tor makes a lot of) results in several syscalls trying to mmap this file. All of the syscalls below (including the readlink) are related to the following gettimeofday sycall. These same syscalls are repeated every time that the plugin gets the current time.

00:00:01.000000000 [tid 1000] readlink(...) = <native>
00:00:01.000000000 [tid 1000] ^^^ = SysCallReg { as_i64: 27, as_u64: 27, as_ptr: shadow_shim_helper_rs::syscall_types::ForeignPtr<()> { val: 27 } }
00:00:01.000000000 [tid 1000] open("/etc/localtime", (empty), Mode(0x0)) = 3
00:00:01.000000000 [tid 1000] fstat() = 0
00:00:01.000000000 [tid 1000] mmap(0x0, 118, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7ffff7ffb000
00:00:01.000000000 [tid 1000] close(3) = 0
00:00:01.000000000 [tid 1000] munmap(0x7ffff7ffb000, 118) = <native>
00:00:01.000000000 [tid 1000] ^^^ = SysCallReg { as_i64: 0, as_u64: 0, as_ptr: shadow_shim_helper_rs::syscall_types::ForeignPtr<()> { val: 0 } }
000000001000000000 [tid 1000] gettimeofday(...) = 0

On my local machine, this only happens in tgen processes and not tor processes. On the benchmark runner, it seems to also happen for tor processes.

A workaround is to set the TZ=:/usr/share/zoneinfo/UTC environment variable for all processes. See https://blog.packagecloud.io/set-environment-variable-save-thousands-of-system-calls/. Then we get only:

000000023000000000 [tid 1000] gettimeofday(...) = 0

without any of the other syscalls above.

I'm not sure why glibc is doing all of this extra work, and how we can properly avoid it without requiring the user to configure an environment variable. We could maybe add the environment variable automatically, but that's not really a nice solution.

@stevenengler stevenengler added Type: Enhancement New functionality or improved design Tag: Performance Related to improving shadow's run-time labels Nov 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Tag: Performance Related to improving shadow's run-time Type: Enhancement New functionality or improved design
Projects
None yet
Development

No branches or pull requests

1 participant