Skip to content

Commit

Permalink
perftune.py: support kvm-clock on tune-clock
Browse files Browse the repository at this point in the history
On KVM guest, optimal clocksource should be 'kvm-clock' instead of 'tsc'.
This adds 'kvm' as another architecture, and set preferred clocksource to 'kvm-clock'.
This is also needed for Amazon Nitro VMs, since it is KVM based VM.

Related scylladb/scylladb#7444

Closes scylladb#826

Reviewed-by: Vlad Zolotarov <[email protected]>
  • Loading branch information
syuu1228 authored and penberg committed Nov 16, 2020
1 parent 11f5132 commit 08b76e4
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions scripts/perftune.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,18 +789,27 @@ class PreferredClockSourceNotAvailableException(Exception):

def __init__(self, args):
self.__args = args
self._preferred = {"x86_64": "tsc"}
self._arch = platform.machine()
self._preferred = {"x86_64": "tsc", "kvm": "kvm-clock"}
self._arch = self._get_arch()
self._available_clocksources_file = "/sys/devices/system/clocksource/clocksource0/available_clocksource"
self._current_clocksource_file = "/sys/devices/system/clocksource/clocksource0/current_clocksource"
self._recommendation_if_unavailable = { "x86_64": "The tsc clocksource is not available. Consider using a hardware platform where the tsc clocksource is available, or try forcing it withe the tsc=reliable boot option" }
self._recommendation_if_unavailable = { "x86_64": "The tsc clocksource is not available. Consider using a hardware platform where the tsc clocksource is available, or try forcing it withe the tsc=reliable boot option", "kvm": "kvm-clock is not available" }

def _available_clocksources(self):
return open(self._available_clocksources_file).readline().split()

def _current_clocksource(self):
return open(self._current_clocksource_file).readline().strip()

def _get_arch(self):
try:
virt = run_read_only_command(['systemd-detect-virt']).strip()
if virt == "kvm":
return virt
except:
pass
return platform.machine()

def enforce_preferred_clocksource(self):
fwriteln(self._current_clocksource_file, self._preferred[self._arch], "Setting clocksource to {}".format(self._preferred[self._arch]))

Expand Down

0 comments on commit 08b76e4

Please sign in to comment.