usb-device: Increase refresh time during init phase
Refresh time of 10 ms for the first 10 minutes of boot up to make sure
that we detect the device as soon as possible and change to 2 seconds
after the system have settle down. This helps us avoid race condition at
boot up when devices are coming up and depend on those imformation.
Google-Bug-Id: 312236217
Change-Id: I90521aa0f230a6b75970db3320385b4d262c9a18
Signed-off-by: Willy Tu <wltu@google.com>
diff --git a/recipes-phosphor/configuration/entity-manager/0001-Add-USB-Device-discovery-daemon.patch b/recipes-phosphor/configuration/entity-manager/0001-Add-USB-Device-discovery-daemon.patch
index 910adb0..a6f4b1d 100644
--- a/recipes-phosphor/configuration/entity-manager/0001-Add-USB-Device-discovery-daemon.patch
+++ b/recipes-phosphor/configuration/entity-manager/0001-Add-USB-Device-discovery-daemon.patch
@@ -1,4 +1,4 @@
-From 740ac33c7813be454d27d1e88aa6f96453da977c Mon Sep 17 00:00:00 2001
+From 189ded323cfaed5ea0c0d447f682f528d7dc3ff6 Mon Sep 17 00:00:00 2001
From: Harsh Tyagi <harshtya@google.com>
Date: Tue, 14 Mar 2023 17:53:22 -0700
Subject: [PATCH] Add USB Device discovery daemon
@@ -29,9 +29,9 @@
meson_options.txt | 6 +
service_files/meson.build | 1 +
.../xyz.openbmc_project.UsbDevice.service | 10 +
- src/meson.build | 25 ++
- src/usb_device.cpp | 422 ++++++++++++++++++
- 5 files changed, 464 insertions(+)
+ src/meson.build | 25 +
+ src/usb_device.cpp | 436 ++++++++++++++++++
+ 5 files changed, 478 insertions(+)
create mode 100644 service_files/xyz.openbmc_project.UsbDevice.service
create mode 100644 src/usb_device.cpp
@@ -62,7 +62,7 @@
+ ['xyz.openbmc_project.UsbDevice.service', 'usb-device'],
['xyz.openbmc_project.EntityManager.service', ''],
]
-
+
diff --git a/service_files/xyz.openbmc_project.UsbDevice.service b/service_files/xyz.openbmc_project.UsbDevice.service
new file mode 100644
index 0000000..c0e80a6
@@ -114,10 +114,10 @@
+endif
diff --git a/src/usb_device.cpp b/src/usb_device.cpp
new file mode 100644
-index 0000000..9c070a2
+index 0000000..3d12bb1
--- /dev/null
+++ b/src/usb_device.cpp
-@@ -0,0 +1,422 @@
+@@ -0,0 +1,436 @@
+#include "config.h"
+
+#include <libudev.h>
@@ -142,6 +142,11 @@
+#include <vector>
+
+constexpr bool DEBUG = false;
++constexpr std::chrono::duration<int64_t, std::milli> INITIAL_WAITTIME =
++ std::chrono::milliseconds(10);
++constexpr std::chrono::duration<int64_t> WAITTIME = std::chrono::seconds(2);
++constexpr std::chrono::duration<int64_t> INITIAL_TIMEOUT =
++ std::chrono::minutes(10);
+struct UsbDevice
+{
+ std::string path;
@@ -166,8 +171,10 @@
+class ManageUsbDevices
+{
+ public:
-+ ManageUsbDevices()
++ ManageUsbDevices() : init(true)
+ {
++ startTime = std::chrono::system_clock::now();
++
+ std::ifstream configJson(USB_DEVICE_CONFIG);
+ if (configJson.is_open())
+ {
@@ -239,7 +246,12 @@
+ const std::shared_ptr<boost::asio::steady_timer>& timer,
+ const std::shared_ptr<sdbusplus::asio::object_server>& objectServer)
+ {
-+ timer->expires_from_now(std::chrono::seconds(2));
++ if (init &&
++ std::chrono::system_clock::now() - startTime > INITIAL_TIMEOUT)
++ {
++ init = false;
++ }
++ timer->expires_from_now(init ? INITIAL_WAITTIME : WAITTIME);
+ timer->async_wait(
+ [this, timer, objectServer](const boost::system::error_code& ec) {
+ MonitorUsbDeviceHandler(timer, objectServer, ec);
@@ -260,6 +272,8 @@
+
+ int fd;
+ udev_monitor* monitor;
++ bool init;
++ std::chrono::system_clock::time_point startTime;
+};
+
+bool ManageUsbDevices::EnumerateDevices(std::string_view type)
@@ -540,6 +554,6 @@
+ io.run();
+ return 0;
+}
---
-2.42.0.582.g8ccd20d70d-goog
+--
+2.43.0.rc1.413.gea7ed67945-goog