Earlier quoted context omitted.
System calls in x86 are fast. Other archs behave differently. And the syscall time is not the only thing that matters, but potentially yielding execution
I thought they were fast because x86 has multiple register files, enough for kernel space and user space to have their own, so that entry/exit to system calls doesn't require flushing registers to L1 (in the common case). If that's true, then one test where you have a single process spinning into and out of a single syscall will have very different performance characteristics than a test where you have more processes…
How setting the TZ environment variable avoids thousands of system calls
81–90 of 148 posts
Re: How setting the TZ environment variable avoids thousands of system calls
#82If you enjoyed this post, you may also enjoy our deep dive explaining exactly how system calls work on Linux[1].
[1]: https://blog.packagecloud.io/eng/2016/04/05/the-definitive-g...
Re: How setting the TZ environment variable avoids thousands of system calls
#83Is there a reason why the path to the timezone file is prefixed with a colon? TZ=:/etc/localtime I've set TZ sometimes without the colon and it seem to work. I did a quick online search and didn't find anything relevant.
Here is the answer: https://www.gnu.org/software/libc/manual/html_node/TZ-Variab... The third format looks like this: :characters Each operating system interprets this format differently; in the GNU C Library, characters is the name of a file which describes the time zone. The other formats specify the timezone directly, such as EST+5EDT. Interestingly, it seems to work okay without the colon. Perhaps the leading sla…
Re: How setting the TZ environment variable avoids thousands of system calls
#84[1] https://github.com/systemd/systemd/blob/master/src/timedate/...
Re: How setting the TZ environment variable avoids thousands of system calls
#85- Why does glibc check /etc/localtime every time localtime is called? Wild guess: so that new values of /etc/localtime are picked at runtime without restarting programs.
- Corollary: why does glibc not check /etc/localtime every time localtime is called, when TZ is set to :/etc/localtime? Arguably the reason above should still apply when TZ is set to a file name, shouldn't it?
Re: How setting the TZ environment variable avoids thousands of system calls
#86My favorite part:
> WTF?? Why is ls(1) running stat() on /etc/localtime for every line of output?
[1] http://www.brendangregg.com/blog/2014-05-11/strace-wow-much-...
Re: How setting the TZ environment variable avoids thousands of system calls
#87System calls in Linux are really fast. So saving "thousands" of system calls when /etc/localtime is in cache doesn't actually save that much actual CPU time. I ran an experiment where I timed the runtime of the sample program provided in the OP, except I changed the number of calls to localtime() from ten times to a million. I then timed the difference with and without export TZ=:/etc/localhost. The net savings was .…
This might be true for your system and libc, where the system calls make use of things like vDSO for gettimeofday go fast, but in general this isn't guaranteed at all. Even on x64, for certain libc implementations, like musl, if I recall correctly, syscalls are made the old fashioned way by trapping 0x80, which would mean you would see a much bigger effect by reducing the number of syscalls.
On x86_64, syscalls only use SYSCALL. It's very fast if audit and such are off and reasonably fast otherwise. (I extensively rewrote this code recently. Older teardowns of the syscall path are dated.)
Re: How setting the TZ environment variable avoids thousands of system calls
#88What is missing in this post is: - Why does glibc check /etc/localtime every time localtime is called? Wild guess: so that new values of /etc/localtime are picked at runtime without restarting programs. - Corollary: why does glibc not check /etc/localtime every time localtime is called, when TZ is set to :/etc/localtime? Arguably the reason above should still apply when TZ is set to a file name, shouldn't it?
First:
> What’s going on here is that the first call to localtime in glibc opens and reads the contents of /etc/localtime. All subsequent calls to localtime internally call stat, but they do this to ensure that the timezone file has not changed.
and second: read the section titled "Preventing extraneous system calls" for the answer to your second question.
Re: How setting the TZ environment variable avoids thousands of system calls
#89What is missing in this post is: - Why does glibc check /etc/localtime every time localtime is called? Wild guess: so that new values of /etc/localtime are picked at runtime without restarting programs. - Corollary: why does glibc not check /etc/localtime every time localtime is called, when TZ is set to :/etc/localtime? Arguably the reason above should still apply when TZ is set to a file name, shouldn't it?
Hi, both are answered in the article: First: > What’s going on here is that the first call to localtime in glibc opens and reads the contents of /etc/localtime. All subsequent calls to localtime internally call stat, but they do this to ensure that the timezone file has not changed. and second: read the section titled "Preventing extraneous system calls" for the answer to your second question.
Re: How setting the TZ environment variable avoids thousands of system calls
#90Earlier quoted context omitted.
Hi, both are answered in the article: First: > What’s going on here is that the first call to localtime in glibc opens and reads the contents of /etc/localtime. All subsequent calls to localtime internally call stat, but they do this to ensure that the timezone file has not changed. and second: read the section titled "Preventing extraneous system calls" for the answer to your second question.
Those "answers" are more about how than why.