Skip to content

Commit

Permalink
Video plugin: make hdparm device checks lazy
Browse files Browse the repository at this point in the history
The video plugin checks each device for hdparm
support during initialization. When using many disk
devices, this can lead to unwanted delays in profile
application.

This change makes the hdparm check lazy by postponing
it to the moment when hdparm is actually needed, i.e.,
during dynamic tuning or when setting spindown/apm.
Each device is checked at most once - the plugin now stores
the sets of hdparm-supported devices and hdparm-unsupported
devices).

Resolves: RHEL-6891
  • Loading branch information
zacikpa committed May 29, 2024
1 parent 5512f1d commit 6d4e153
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions tuned/plugins/plugin_disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,20 @@ def _init_devices(self):
self._use_hdparm = True
self._free_devices = set()
self._hdparm_apm_devices = set()
self._no_hdparm_apm_devices = set()
for device in self._hardware_inventory.get_devices("block"):
if self._device_is_supported(device):
self._free_devices.add(device.sys_name)
if self._use_hdparm and self._is_hdparm_apm_supported(device.sys_name):
self._hdparm_apm_devices.add(device.sys_name)

self._assigned_devices = set()

def _get_device_objects(self, devices):
return [self._hardware_inventory.get_device("block", x) for x in devices]

def _is_hdparm_apm_supported(self, device):
if not self._use_hdparm or device in self._no_hdparm_apm_devices:
return False
if device in self._hdparm_apm_devices:
return True
(rc, out, err_msg) = self._cmd.execute(["hdparm", "-C", "/dev/%s" % device], \
no_errors = [errno.ENOENT], return_err=True)
if rc == -errno.ENOENT:
Expand All @@ -122,10 +124,13 @@ def _is_hdparm_apm_supported(self, device):
elif rc:
log.info("Device '%s' not supported by hdparm" % device)
log.debug("(rc: %s, msg: '%s')" % (rc, err_msg))
self._no_hdparm_apm_devices.add(device)
return False
elif "unknown" in out:
log.info("Driver for device '%s' does not support apm command" % device)
self._no_hdparm_apm_devices.add(device)
return False
self._hdparm_apm_devices.add(device)
return True

@classmethod
Expand Down Expand Up @@ -232,7 +237,7 @@ def _drive_spinning(self, device):
return not "standby" in out and not "sleeping" in out

def _instance_update_dynamic(self, instance, device):
if not device in self._hdparm_apm_devices:
if not self._is_hdparm_apm_supported(device):
return
load = instance._load_monitor.get_device_load(device)
if load is None:
Expand Down Expand Up @@ -315,7 +320,7 @@ def _instance_apply_dynamic(self, instance, device):
# At the moment we support dynamic tuning just for devices compatible with hdparm apm commands
# If in future will be added new functionality not connected to this command,
# it is needed to change it here
if device not in self._hdparm_apm_devices:
if not self._is_hdparm_apm_supported(device):
log.info("There is no dynamic tuning available for device '%s' at time" % device)
else:
super(DiskPlugin, self)._instance_apply_dynamic(instance, device)
Expand Down Expand Up @@ -350,7 +355,7 @@ def _get_elevator(self, device, ignore_missing=False):

@command_set("apm", per_device=True)
def _set_apm(self, value, device, sim, remove):
if device not in self._hdparm_apm_devices:
if not self._is_hdparm_apm_supported(device):
if not sim:
log.info("apm option is not supported for device '%s'" % device)
return None
Expand All @@ -366,7 +371,7 @@ def _set_apm(self, value, device, sim, remove):

@command_get("apm")
def _get_apm(self, device, ignore_missing=False):
if device not in self._hdparm_apm_devices:
if not self._is_hdparm_apm_supported(device):
if not ignore_missing:
log.info("apm option is not supported for device '%s'" % device)
return None
Expand All @@ -390,7 +395,7 @@ def _get_apm(self, device, ignore_missing=False):

@command_set("spindown", per_device=True)
def _set_spindown(self, value, device, sim, remove):
if device not in self._hdparm_apm_devices:
if not self._is_hdparm_apm_supported(device):
if not sim:
log.info("spindown option is not supported for device '%s'" % device)
return None
Expand All @@ -406,7 +411,7 @@ def _set_spindown(self, value, device, sim, remove):

@command_get("spindown")
def _get_spindown(self, device, ignore_missing=False):
if device not in self._hdparm_apm_devices:
if not self._is_hdparm_apm_supported(device):
if not ignore_missing:
log.info("spindown option is not supported for device '%s'" % device)
return None
Expand Down

0 comments on commit 6d4e153

Please sign in to comment.