Skip to content

Commit

Permalink
hotplug: wait for device initialization
Browse files Browse the repository at this point in the history
Signed-off-by: Jaroslav Škarvada <[email protected]>
  • Loading branch information
yarda committed May 30, 2024
1 parent 5385fa9 commit e93c17c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tuned/consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,8 @@
"console": LOG_LEVEL_CONSOLE,
"none": None,
}

# number of retries when waiting for device initialization
HOTPLUG_WAIT_FOR_DEV_INIT_RETRIES = 100
# how long to wait for device initialization in seconds during retry
HOTPLUG_WAIT_FOR_DEV_INIT_DELAY = 0.1
8 changes: 8 additions & 0 deletions tuned/hardware/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ def _handle_udev_event(self, event, device):
if not device.subsystem in self._subscriptions:
return

retry = consts.HOTPLUG_WAIT_FOR_DEV_INIT_RETRIES
while not device.is_initialized and retry > 0:
log.debug("Device '%s' is uninitialized, waiting '%d' seconds for its initialization." % (device, consts.HOTPLUG_WAIT_FOR_DEV_INIT_DELAY))
time.sleep(consts.HOTPLUG_WAIT_FOR_DEV_INIT_DELAY)
retry =- 1
if not device.is_initialized:
log.warn("Unsuccessfully waited for device '%s' initialization, continuing with uninitialized device, problems may occur." % device)

for (plugin, callback) in self._subscriptions[device.subsystem]:
try:
callback(event, device)
Expand Down

0 comments on commit e93c17c

Please sign in to comment.