meta-gbmc-staging: dbus-sensors: gpiosensor: Publish interface after the Present property is set
The existing code set the Present property false as default and then
intialize the interface immediately. This causes the interface to be
published with Present = false. If actual state of the sensor is
asserted true, there will be a false negative happening between the time
the interface is published and the time the property is updated to true.
In order to avoid this false negative, move the interface publishing
after the Present property is set to the actual state.
Tested:
[Before this change]
Step 1. dbus-monitor path=/xyz/openbmc_project/inventory/item/$SENSOR_NAME interface=xyz.openbmc_project.gpiosensor --system
Step 2. systemctl restart xyz.openbmc_project.gpiosensor
Test result:
dbus-monitor path=/xyz/openbmc_project/inventory/item/$SENSOR_NAME interface=xyz.openbmc_project.gpiosensor --system
signal time=1728627723.100853 sender=org.freedesktop.DBus -> destination=:1.2898 serial=4294967295 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameAcquired
string ":1.2898"
signal time=1728627723.100961 sender=org.freedesktop.DBus -> destination=:1.2898 serial=4294967295 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameLost
string ":1.2898"
signal time=1728627727.461779 sender=:1.2907 -> destination=(null destination) serial=17 path=/xyz/openbmc_project/inventory/item/$SENSOR_NAME; interface=org.freedesktop.DBus.Properties; member=Propertied
string "xyz.openbmc_project.GPIOStatus"
array [
dict entry(
string "Present"
variant boolean false
)
]
array [
]
signal time=1728627727.461983 sender=:1.2907 -> destination=(null destination) serial=18 path=/xyz/openbmc_project/inventory/item/$SENSOR_NAME; interface=org.freedesktop.DBus.Properties; member=Propertied
string "xyz.openbmc_project.GPIOStatus"
array [
dict entry(
string "Name"
variant string "$SENSOR_NAME"
)
]
array [
]
method call time=1728627732.623678 sender=:1.81 -> destination=xyz.openbmc_project.GPIOStatus serial=6246 path=/xyz/openbmc_project/inventory/item/$SENSOR_NAME; interface=org.freedesktop.DBus.Properties;l
string "xyz.openbmc_project.GPIOStatus"
signal time=1728627740.524104 sender=:1.2907 -> destination=(null destination) serial=114 path=/xyz/openbmc_project/inventory/item/$SENSOR_NAME; interface=org.freedesktop.DBus.Properties; member=Propertid
string "xyz.openbmc_project.GPIOStatus"
array [
dict entry(
string "Present"
variant boolean true
)
]
array [
]
method call time=1728627745.695646 sender=:1.81 -> destination=xyz.openbmc_project.GPIOStatus serial=6805 path=/xyz/openbmc_project/inventory/item/$SENSOR_NAME; interface=org.freedesktop.DBus.Properties;l
string "xyz.openbmc_project.GPIOStatus"
[After this change]
Step 1. dbus-monitor path=/xyz/openbmc_project/inventory/item/$SENSOR_NAME interface=xyz.openbmc_project.gpiosensor --system
Step 2. systemctl restart xyz.openbmc_project.gpiosensor
Test result:
dbus-monitor path=/xyz/openbmc_project/inventory/item/$SENSOR_NAME interface=xyz.openbmc_project.gpiosensor --system
Failed to open connection to session bus: Using X11 for dbus-daemon autolaunch was disabled at compile time, set your DBUS_SESSION_BUS_ADDRESS instead
root@cig:~# dbus-monitor path=/xyz/openbmc_project/inventory/item/$SENSOR_NAME interface=xyz.openbmc_project.gpiosensor --system
signal time=1728626779.647020 sender=org.freedesktop.DBus -> destination=:1.7505 serial=4294967295 path=/org/freedesktop/DBus; interface=org.freedesktop.DBusd
string ":1.7505"
signal time=1728626779.647144 sender=org.freedesktop.DBus -> destination=:1.7505 serial=4294967295 path=/org/freedesktop/DBus; interface=org.freedesktop.DBust
string ":1.7505"
signal time=1728626812.774611 sender=:1.7544 -> destination=(null destination) serial=62 path=/xyz/openbmc_project/inventory/item/$SENSOR_NAME; interfaced
string "xyz.openbmc_project.GPIOStatus"
array [
dict entry(
string "Name"
variant string "$SENSOR_NAME"
)
]
array [
]
signal time=1728626812.775064 sender=:1.7544 -> destination=(null destination) serial=63 path=/xyz/openbmc_project/inventory/item/$SENSOR_NAME; interfaced
string "xyz.openbmc_project.GPIOStatus"
array [
dict entry(
string "Present"
variant boolean true
)
]
array [
]
method call time=1728626817.932756 sender=:1.136 -> destination=xyz.openbmc_project.GPIOStatus serial=6972 path=/xyz/openbmc_project/inventory/item/BP_12V_CAl
string "xyz.openbmc_project.GPIOStatus"
Fusion-Link:
platform11: https://fusion2.corp.google.com/20a5e907-03d3-3e65-94d0-3c33ec0dea0f
platform5: https://fusion2.corp.google.com/2e2f42cd-7eb8-3abd-8c47-8cb78e576d5d
platform15: https://fusion2.corp.google.com/124f9f34-065c-3311-8c1d-6432f3ecb99f
platform17: https://fusion2.corp.google.com/2fef2479-f9ec-3742-8468-56f69b907699
Platforms-Affected: All
Google-Bug-Id: 441433977
Change-Id: Ia3b6e50da077ac45115be1a6e9bdb94b371b08ab
Signed-off-by: Brian Chiang <chiang.brian@inventec.corp-partner.google.com>
(cherry picked from commit e1bac3c2109b9f79449616e3c5da0b06a6974932)
diff --git a/recipes-phosphor/sensors/dbus-sensors/0015-dbus-sensors-gpiosensor-Publish-interface-after-the-.patch b/recipes-phosphor/sensors/dbus-sensors/0015-dbus-sensors-gpiosensor-Publish-interface-after-the-.patch
new file mode 100644
index 0000000..02090fb
--- /dev/null
+++ b/recipes-phosphor/sensors/dbus-sensors/0015-dbus-sensors-gpiosensor-Publish-interface-after-the-.patch
@@ -0,0 +1,163 @@
+From 2bb8422abbe1cb5b49d4381410621f01d101f147 Mon Sep 17 00:00:00 2001
+From: Brian Chiang <chiang.brian@inventec.com>
+Date: Fri, 26 Sep 2025 10:08:15 +0800
+Subject: [PATCH] dbus-sensors: gpiosensor: Publish interface after the Present
+ property is set
+
+The existing code set the Present property false as default and then
+intialize the interface immediately. This causes the interface to be
+published with Present = false. If actual state of the sensor is
+asserted true, there will be a false negative happening between the time
+the interface is published and the time the property is updated to true.
+
+In order to avoid this false negative, move the interface publishing
+after the Present property is set to the actual state.
+
+Tested:
+[Before this change]
+Step 1. dbus-monitor path=/xyz/openbmc_project/inventory/item/$SENSOR_NAME interface=xyz.openbmc_project.gpiosensor --system
+Step 2. systemctl restart xyz.openbmc_project.gpiosensor
+
+Test result:
+signal time=1728627723.100853 sender=org.freedesktop.DBus -> destination=:1.2898 serial=4294967295 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameAcquired
+ string ":1.2898"
+signal time=1728627723.100961 sender=org.freedesktop.DBus -> destination=:1.2898 serial=4294967295 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameLost
+ string ":1.2898"
+signal time=1728627727.461779 sender=:1.2907 -> destination=(null destination) serial=17 path=/xyz/openbmc_project/inventory/item/$SENSOR_NAME; interface=org.freedesktop.DBus.Properties; member=Propertied
+ string "xyz.openbmc_project.GPIOStatus"
+ array [
+ dict entry(
+ string "Present"
+ variant boolean false
+ )
+ ]
+ array [
+ ]
+signal time=1728627727.461983 sender=:1.2907 -> destination=(null destination) serial=18 path=/xyz/openbmc_project/inventory/item/$SENSOR_NAME; interface=org.freedesktop.DBus.Properties; member=Propertied
+ string "xyz.openbmc_project.GPIOStatus"
+ array [
+ dict entry(
+ string "Name"
+ variant string "$SENSOR_NAME"
+ )
+ ]
+ array [
+ ]
+method call time=1728627732.623678 sender=:1.81 -> destination=xyz.openbmc_project.GPIOStatus serial=6246 path=/xyz/openbmc_project/inventory/item/$SENSOR_NAME; interface=org.freedesktop.DBus.Properties;l
+ string "xyz.openbmc_project.GPIOStatus"
+signal time=1728627740.524104 sender=:1.2907 -> destination=(null destination) serial=114 path=/xyz/openbmc_project/inventory/item/$SENSOR_NAME; interface=org.freedesktop.DBus.Properties; member=Propertid
+ string "xyz.openbmc_project.GPIOStatus"
+ array [
+ dict entry(
+ string "Present"
+ variant boolean true
+ )
+ ]
+ array [
+ ]
+method call time=1728627745.695646 sender=:1.81 -> destination=xyz.openbmc_project.GPIOStatus serial=6805 path=/xyz/openbmc_project/inventory/item/$SENSOR_NAME; interface=org.freedesktop.DBus.Properties;l
+ string "xyz.openbmc_project.GPIOStatus"
+
+[After this change]
+Step 1. dbus-monitor path=/xyz/openbmc_project/inventory/item/$SENSOR_NAME interface=xyz.openbmc_project.gpiosensor --system
+Step 2. systemctl restart xyz.openbmc_project.gpiosensor
+
+Test result:
+dbus-monitor path=/xyz/openbmc_project/inventory/item/$SENSOR_NAME interface=xyz.openbmc_project.gpiosensor --system
+Failed to open connection to session bus: Using X11 for dbus-daemon autolaunch was disabled at compile time, set your DBUS_SESSION_BUS_ADDRESS instead
+root@cig:~# dbus-monitor path=/xyz/openbmc_project/inventory/item/$SENSOR_NAME interface=xyz.openbmc_project.gpiosensor --system
+signal time=1728626779.647020 sender=org.freedesktop.DBus -> destination=:1.7505 serial=4294967295 path=/org/freedesktop/DBus; interface=org.freedesktop.DBusd
+ string ":1.7505"
+signal time=1728626779.647144 sender=org.freedesktop.DBus -> destination=:1.7505 serial=4294967295 path=/org/freedesktop/DBus; interface=org.freedesktop.DBust
+ string ":1.7505"
+signal time=1728626812.774611 sender=:1.7544 -> destination=(null destination) serial=62 path=/xyz/openbmc_project/inventory/item/$SENSOR_NAME; interfaced
+ string "xyz.openbmc_project.GPIOStatus"
+ array [
+ dict entry(
+ string "Name"
+ variant string "$SENSOR_NAME"
+ )
+ ]
+ array [
+ ]
+signal time=1728626812.775064 sender=:1.7544 -> destination=(null destination) serial=63 path=/xyz/openbmc_project/inventory/item/$SENSOR_NAME; interfaced
+ string "xyz.openbmc_project.GPIOStatus"
+ array [
+ dict entry(
+ string "Present"
+ variant boolean true
+ )
+ ]
+ array [
+ ]
+method call time=1728626817.932756 sender=:1.136 -> destination=xyz.openbmc_project.GPIOStatus serial=6972 path=/xyz/openbmc_project/inventory/item/BP_12V_CAl
+ string "xyz.openbmc_project.GPIOStatus"
+
+Google-Bug-Id: 441433977
+Signed-off-by: Brian Chiang <chiang.brian@inventec.corp-partner.google.com>
+---
+ include/GPIOPresenceSensor.hpp | 1 +
+ src/GPIOPresenceSensor.cpp | 16 ++++++++++++++--
+ src/GPIOPresenceSensorMain.cpp | 3 ---
+ 3 files changed, 15 insertions(+), 5 deletions(-)
+
+diff --git a/include/GPIOPresenceSensor.hpp b/include/GPIOPresenceSensor.hpp
+index 5b74adb..286b1c5 100644
+--- a/include/GPIOPresenceSensor.hpp
++++ b/include/GPIOPresenceSensor.hpp
+@@ -124,6 +124,7 @@ class GPIOPresence
+ std::unordered_map<std::string, ::gpiod::line> gpioLines;
+ // default polling rate.
+ int pollRate;
++ bool initialized = false;
+ };
+
+ } // namespace gpiopresencesensing
+diff --git a/src/GPIOPresenceSensor.cpp b/src/GPIOPresenceSensor.cpp
+index 3061590..82b08cf 100644
+--- a/src/GPIOPresenceSensor.cpp
++++ b/src/GPIOPresenceSensor.cpp
+@@ -108,11 +108,23 @@ void GPIOPresence::startUpdateLoop(bool forceUpdate)
+ std::cout << "Cable " << config.name << " change state to "
+ << (present ? "connected" : "disconnected")
+ << std::endl;
+- obj.second.statusIfc->set_property(
+- gpiopresencesensing::Properties::propertyPresent, present);
++ if(!initialized)
++ {
++ obj.second.statusIfc->register_property(
++ gpiopresencesensing::Properties::propertyPresent, present);
++ obj.second.statusIfc->initialize();
++ }
++ else
++ {
++ obj.second.statusIfc->set_property(
++ gpiopresencesensing::Properties::propertyPresent, present);
++ }
+ config.present = present;
+ }
+ }
++ // By this time the interface should already be created because of the
++ // forceUpdate = true from the main.
++ initialized = true;
+ startUpdateLoop(/*forceUpdate=*/false);
+ });
+ }
+diff --git a/src/GPIOPresenceSensorMain.cpp b/src/GPIOPresenceSensorMain.cpp
+index f3e81b2..a6741f8 100644
+--- a/src/GPIOPresenceSensorMain.cpp
++++ b/src/GPIOPresenceSensorMain.cpp
+@@ -265,10 +265,7 @@ int main()
+ objPath, gpiopresencesensing::interfaces::statusIfc);
+ std::cout << "Adding status interface: " << config.name
+ << " at path: " << objPath.str << std::endl;
+- statusIfc->register_property(
+- gpiopresencesensing::Properties::propertyPresent, false);
+ statusIfc->register_property("Name", config.name);
+- statusIfc->initialize();
+ // Add Inventory Association
+ if (config.generateAssociation)
+ {
+--
+2.43.0
+
diff --git a/recipes-phosphor/sensors/dbus-sensors_%.bbappend b/recipes-phosphor/sensors/dbus-sensors_%.bbappend
index 39cd80c..fcc37e4 100644
--- a/recipes-phosphor/sensors/dbus-sensors_%.bbappend
+++ b/recipes-phosphor/sensors/dbus-sensors_%.bbappend
@@ -20,6 +20,7 @@
file://0011-LTC2991-PSUSensor-support.patch \
file://0012-TDA38740-PSUSensor-support.patch \
file://0014-dbus-sensors-psusensor-Add-support-for-ADM1273.patch \
+ file://0015-dbus-sensors-gpiosensor-Publish-interface-after-the-.patch \
"
# TODO(linchuyuan@google.com): remove the following section once the upstream has the change