Skip to contentSkip to conversation

adapter: Fix discovery trigger for 0 second delay

PATCH Superseded Frédéric Danis 3 participants 5 messages Mar 12, 2021 – Mar 15, 2021 Bluetooth drivers

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 adapter: Fix discovery trigger for 0 second delay

When calling StartDiscovery the effective start can take around 10 ms or up to 700 ms.
g_timeout_add_seconds() call doesn't ensure the time for the first call of the timer if the delay is less or equal to 1 second.
---
v2: Fix issue founs by CI

 src/adapter.c | 7 +++++++
 1 file changed, 7 insertions(+)
src/adapter.c +7 -0
index cc0849f99..3078ce1a8 100644
@@ -1797,6 +1797,13 @@ static void trigger_start_discovery(struct btd_adapter *adapter, guint delay)
 	if (!btd_adapter_get_powered(adapter))
 		return;
 
+	if (!delay) {
+		adapter->discovery_idle_timeout = g_idle_add(
+						start_discovery_timeout,
+						adapter);
+		return;
+	}
+
 	adapter->discovery_idle_timeout = g_timeout_add_seconds(delay,
 					start_discovery_timeout, adapter);
 }
Signature · 1 line
2.18.0
#1 lore raw

Hi Frédéric,

Quoted 5 lines · Frédéric Danis

When calling StartDiscovery the effective start can take around 10 ms or up to 700 ms.
g_timeout_add_seconds() call doesn't ensure the time for the first call of the timer if the delay is less or equal to 1 second.

Interesting, I always thought that 0 would be handle just as idle and not round up to the next timeout.

Quoted 13 lines

---
v2: Fix issue founs by CI

 src/adapter.c | 7 +++++++
 1 file changed, 7 insertions(+)
src/adapter.c +0 -0
index cc0849f99..3078ce1a8 100644
@@ -1797,6 +1797,13 @@ static void trigger_start_discovery(struct btd_adapter *adapter, guint delay)
        if (!btd_adapter_get_powered(adapter))
                return;

src/adapter.c static void trigger_start_discovery(struct btd_adapter *adapter, guint delay) · line 1808

Quoted 10 lines
src/adapter.c +7 -0
 
+       if (!delay) {
+               adapter->discovery_idle_timeout = g_idle_add(
+                                               start_discovery_timeout,
+                                               adapter);
+               return;
+       }
+
        adapter->discovery_idle_timeout = g_timeout_add_seconds(delay,
                                        start_discovery_timeout, adapter);

Maybe we should have a wrapper function for g_timeout_add_seconds since I suspect there might be other instances of g_timeout_add_seconds with 0 delay.

Quoted 4 lines
src/adapter.c +0 -1
 }
--

2.18.0

Signature · 1 line
Luiz Augusto von Dentz
#2 lore raw

Hi Luiz,

Quoted 25 lines · Luiz Augusto von Dentz

Hi Frédéric,

Quoted 4 lines · Frédéric Danis

When calling StartDiscovery the effective start can take around 10 ms or up to 700 ms.
g_timeout_add_seconds() call doesn't ensure the time for the first call of the timer if the delay is less or equal to 1 second.

Interesting, I always thought that 0 would be handle just as idle and not round up to the next timeout.

Quoted 14 lines

---
v2: Fix issue founs by CI

  src/adapter.c | 7 +++++++
  1 file changed, 7 insertions(+)
src/adapter.c +0 -0
index cc0849f99..3078ce1a8 100644
@@ -1797,6 +1797,13 @@ static void trigger_start_discovery(struct btd_adapter *adapter, guint delay)
         if (!btd_adapter_get_powered(adapter))
                 return;
 
Quoted 12 lines

src/adapter.c static void trigger_start_discovery(struct btd_adapter *adapter, guint delay) · line 1808

Quoted 9 lines
src/adapter.c +7 -0
+       if (!delay) {
+               adapter->discovery_idle_timeout = g_idle_add(
+                                               start_discovery_timeout,
+                                               adapter);
+               return;
+       }
+
         adapter->discovery_idle_timeout = g_timeout_add_seconds(delay,
                                         start_discovery_timeout, adapter);

Maybe we should have a wrapper function for g_timeout_add_seconds since I suspect there might be other instances of g_timeout_add_seconds with 0 delay.

Ok
Is adding a timeout_add_seconds() function to src/shared/timeout.h the right place?

Fred

#3 lore raw

Hi Frédéric,

Quoted 42 lines · Frédéric Danis

Hi Luiz,

Quoted 25 lines · Luiz Augusto von Dentz

Hi Frédéric,

Quoted 4 lines · Frédéric Danis

When calling StartDiscovery the effective start can take around 10 ms or up to 700 ms.
g_timeout_add_seconds() call doesn't ensure the time for the first call of the timer if the delay is less or equal to 1 second.

Interesting, I always thought that 0 would be handle just as idle and not round up to the next timeout.

Quoted 14 lines

---
v2: Fix issue founs by CI

  src/adapter.c | 7 +++++++
  1 file changed, 7 insertions(+)
src/adapter.c +0 -0
index cc0849f99..3078ce1a8 100644
@@ -1797,6 +1797,13 @@ static void trigger_start_discovery(struct btd_adapter *adapter, guint delay)
         if (!btd_adapter_get_powered(adapter))
                 return;
 
Quoted 12 lines

src/adapter.c static void trigger_start_discovery(struct btd_adapter *adapter, guint delay) · line 1808

Quoted 9 lines
src/adapter.c +7 -0
+       if (!delay) {
+               adapter->discovery_idle_timeout = g_idle_add(
+                                               start_discovery_timeout,
+                                               adapter);
+               return;
+       }
+
         adapter->discovery_idle_timeout = g_timeout_add_seconds(delay,
                                         start_discovery_timeout, adapter);

Maybe we should have a wrapper function for g_timeout_add_seconds since I suspect there might be other instances of g_timeout_add_seconds with 0 delay.

Quoted 3 lines

Ok
Is adding a timeout_add_seconds() function to src/shared/timeout.h the right place?

Yep, that should be the right place.

Signature · 1 line
Luiz Augusto von Dentz
#4 lore raw
In reply to Frédéric Danis

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list. This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=447189

---Test result---

##############################
Test: CheckPatch - PASS

##############################
Test: CheckGitLint - PASS

##############################
Test: CheckBuild - PASS

##############################
Test: MakeCheck - PASS

---
Regards,
Linux Bluetooth