You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 22, 2020. It is now read-only.
TL;DR: Using TSC as clocksource (clocksource=tsc as a boot parameter in /etc/default/grub or echo "tsc" > /sys/devices/system/clocksource/clocksource0/current_clocksource) reduces kernel context switches for anything calling gettimeofday() resulting in lower resource usage.
When running under a xen hypervisor as is the case for most EC2 instances (c5.* and m5.* being the exception) Ubuntu will by default use the hypervisor as clock source. This means that every time an application needs to check the current time (translating to the syscalls gettimeofday() or clock_gettime()) a context switch into the kernel and a call to the hypervisor is required, resulting in a lot of overhead. This effect is especially noticeable when running a profiler. Switching the clocksource to tsc circumvents this by making the time directly available in userspace leading to a significant reduction of CPU cycles spent in the kernel. This sounds like a micro-optimization but I've seen cases where it reduced system CPU usage by over 30% (web application using new relic for profiling).
To change the clocksource to tsc one simply has to pass "clocksource=tsc" to the kernel (for example in /etc/default/grub) or change it in sysfs (/sys/devices/system/clocksource/clocksource0/current_clocksource).
The text was updated successfully, but these errors were encountered:
The performance impact of this is probably a lot higher with KPTI enabled since context switches will become a lot more expensive on Intel CPUs and pre 4.14 kernels.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
TL;DR: Using TSC as clocksource (
clocksource=tsc
as a boot parameter in /etc/default/grub orecho "tsc" > /sys/devices/system/clocksource/clocksource0/current_clocksource
) reduces kernel context switches for anything calling gettimeofday() resulting in lower resource usage.When running under a xen hypervisor as is the case for most EC2 instances (c5.* and m5.* being the exception) Ubuntu will by default use the hypervisor as clock source. This means that every time an application needs to check the current time (translating to the syscalls gettimeofday() or clock_gettime()) a context switch into the kernel and a call to the hypervisor is required, resulting in a lot of overhead. This effect is especially noticeable when running a profiler. Switching the clocksource to tsc circumvents this by making the time directly available in userspace leading to a significant reduction of CPU cycles spent in the kernel. This sounds like a micro-optimization but I've seen cases where it reduced system CPU usage by over 30% (web application using new relic for profiling).
A comprehensive article on this can be found here: https://blog.packagecloud.io/eng/2017/03/08/system-calls-are-much-slower-on-ec2/ (the warning about the time drift doesn't really apply to modern Intel Platforms).
To change the clocksource to tsc one simply has to pass "clocksource=tsc" to the kernel (for example in /etc/default/grub) or change it in sysfs (/sys/devices/system/clocksource/clocksource0/current_clocksource).
The text was updated successfully, but these errors were encountered: