All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH Bluez v5 0/4] adapter: Fix discovery trigger for 0 second delay
@ 2021-03-16 17:18 Frédéric Danis
  2021-03-16 17:18 ` [PATCH Bluez v5 1/4] shared/timeout: Add timeout_add_seconds abstraction Frédéric Danis
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Frédéric Danis @ 2021-03-16 17:18 UTC (permalink / raw)
  To: linux-bluetooth

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 found by CI
v3: Add a wrapper function for g_timeout_add_seconds and replace calls to it in
    src/*, profiles/* and plugins/*
v4: Fix issue found by CI
v5: Fix issue found by CI

Frédéric Danis (4):
  shared/timeout: Add timeout_add_seconds abstraction
  src: Replace calls to g_timeout_add_seconds by timeout_add_seconds
  plugins: Replace calls to g_timeout_add_seconds by timeout_add_seconds
  profiles: Replace calls to g_timeout_add_seconds by
    timeout_add_seconds

 plugins/policy.c              | 91 ++++++++++++++++++-----------------
 profiles/audio/a2dp.c         | 17 ++++---
 profiles/audio/avctp.c        | 44 +++++++++--------
 profiles/audio/avdtp.c        | 61 ++++++++++++-----------
 profiles/audio/avrcp.c        | 13 ++---
 profiles/health/hdp.c         | 16 +++---
 profiles/health/mcap.c        | 21 ++++----
 profiles/input/device.c       | 33 +++++++------
 profiles/network/bnep.c       | 12 +++--
 profiles/sap/server.c         | 13 ++---
 src/adapter.c                 | 90 ++++++++++++++++++----------------
 src/adv_monitor.c             | 14 +++---
 src/advertising.c             | 28 ++++++-----
 src/device.c                  | 60 ++++++++++++-----------
 src/main.c                    |  7 +--
 src/sdp-client.c              | 13 ++---
 src/shared/tester.c           | 16 +++---
 src/shared/timeout-ell.c      |  6 +++
 src/shared/timeout-glib.c     | 27 +++++++++++
 src/shared/timeout-mainloop.c |  6 +++
 src/shared/timeout.h          |  3 ++
 21 files changed, 332 insertions(+), 259 deletions(-)

--
2.18.0

^ permalink raw reply	[flat|nested] 9+ messages in thread
* [PATCH Bluez v4 1/4] shared/timeout: Add timeout_add_seconds abstraction
@ 2021-03-16 16:39 Frédéric Danis
  2021-03-16 17:08 ` adapter: Fix discovery trigger for 0 second delay bluez.test.bot
  0 siblings, 1 reply; 9+ messages in thread
From: Frédéric Danis @ 2021-03-16 16:39 UTC (permalink / raw)
  To: linux-bluetooth

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.
In case of a 0 delay call g_idle_add() instead of g_timeout_add_seconds().
---
 src/shared/tester.c           | 16 +++++++++-------
 src/shared/timeout-ell.c      |  6 ++++++
 src/shared/timeout-glib.c     | 27 +++++++++++++++++++++++++++
 src/shared/timeout-mainloop.c |  6 ++++++
 src/shared/timeout.h          |  3 +++
 5 files changed, 51 insertions(+), 7 deletions(-)

diff --git a/src/shared/tester.c b/src/shared/tester.c
index af33a79cd..c07cbc11c 100644
--- a/src/shared/tester.c
+++ b/src/shared/tester.c
@@ -36,6 +36,7 @@
 #include "src/shared/util.h"
 #include "src/shared/tester.h"
 #include "src/shared/log.h"
+#include "src/shared/timeout.h"
 
 #define COLOR_OFF	"\x1B[0m"
 #define COLOR_BLACK	"\x1B[0;30m"
@@ -126,7 +127,7 @@ static void test_destroy(gpointer data)
 	struct test_case *test = data;
 
 	if (test->timeout_id > 0)
-		g_source_remove(test->timeout_id);
+		timeout_remove(test->timeout_id);
 
 	if (test->teardown_id > 0)
 		g_source_remove(test->teardown_id);
@@ -429,7 +430,7 @@ static gboolean teardown_callback(gpointer user_data)
 	return FALSE;
 }
 
-static gboolean test_timeout(gpointer user_data)
+static bool test_timeout(gpointer user_data)
 {
 	struct test_case *test = user_data;
 
@@ -470,8 +471,9 @@ static void next_test_case(void)
 	test->start_time = g_timer_elapsed(test_timer, NULL);
 
 	if (test->timeout > 0)
-		test->timeout_id = g_timeout_add_seconds(test->timeout,
-							test_timeout, test);
+		test->timeout_id = timeout_add_seconds(test->timeout,
+							test_timeout, test,
+							NULL);
 
 	test->stage = TEST_STAGE_PRE_SETUP;
 
@@ -542,7 +544,7 @@ void tester_pre_setup_failed(void)
 		return;
 
 	if (test->timeout_id > 0) {
-		g_source_remove(test->timeout_id);
+		timeout_remove(test->timeout_id);
 		test->timeout_id = 0;
 	}
 
@@ -583,7 +585,7 @@ void tester_setup_failed(void)
 	test->stage = TEST_STAGE_POST_TEARDOWN;
 
 	if (test->timeout_id > 0) {
-		g_source_remove(test->timeout_id);
+		timeout_remove(test->timeout_id);
 		test->timeout_id = 0;
 	}
 
@@ -606,7 +608,7 @@ static void test_result(enum test_result result)
 		return;
 
 	if (test->timeout_id > 0) {
-		g_source_remove(test->timeout_id);
+		timeout_remove(test->timeout_id);
 		test->timeout_id = 0;
 	}
 
diff --git a/src/shared/timeout-ell.c b/src/shared/timeout-ell.c
index 023364069..6416d8590 100644
--- a/src/shared/timeout-ell.c
+++ b/src/shared/timeout-ell.c
@@ -101,3 +101,9 @@ void timeout_remove(unsigned int id)
 	if (to)
 		l_timeout_remove(to);
 }
+
+unsigned int timeout_add_seconds(unsigned int timeout, timeout_func_t func,
+			void *user_data, timeout_destroy_func_t destroy)
+{
+	return timeout_add(timeout * 1000, func, user_data, destroy);
+}
diff --git a/src/shared/timeout-glib.c b/src/shared/timeout-glib.c
index 8bdb7a662..3268d480c 100644
--- a/src/shared/timeout-glib.c
+++ b/src/shared/timeout-glib.c
@@ -71,3 +71,30 @@ void timeout_remove(unsigned int id)
 	if (source)
 		g_source_destroy(source);
 }
+
+unsigned int timeout_add_seconds(unsigned int timeout, timeout_func_t func,
+			void *user_data, timeout_destroy_func_t destroy)
+{
+	struct timeout_data *data;
+	guint id;
+
+	data = g_try_new0(struct timeout_data, 1);
+	if (!data)
+		return 0;
+
+	data->func = func;
+	data->destroy = destroy;
+	data->user_data = user_data;
+
+	if (!timeout)
+		id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, timeout_callback,
+							data, timeout_destroy);
+	else
+		id = g_timeout_add_seconds_full(G_PRIORITY_DEFAULT, timeout,
+							timeout_callback, data,
+							timeout_destroy);
+	if (!id)
+		g_free(data);
+
+	return id;
+}
diff --git a/src/shared/timeout-mainloop.c b/src/shared/timeout-mainloop.c
index 5ffa65c2a..9be803cda 100644
--- a/src/shared/timeout-mainloop.c
+++ b/src/shared/timeout-mainloop.c
@@ -71,3 +71,9 @@ void timeout_remove(unsigned int id)
 
 	mainloop_remove_timeout((int) id);
 }
+
+unsigned int timeout_add_seconds(unsigned int timeout, timeout_func_t func,
+			void *user_data, timeout_destroy_func_t destroy)
+{
+	return timeout_add(timeout * 1000, func, user_data, destroy);
+}
diff --git a/src/shared/timeout.h b/src/shared/timeout.h
index 7e22345dd..0945c3318 100644
--- a/src/shared/timeout.h
+++ b/src/shared/timeout.h
@@ -16,3 +16,6 @@ typedef void (*timeout_destroy_func_t)(void *user_data);
 unsigned int timeout_add(unsigned int timeout, timeout_func_t func,
 			void *user_data, timeout_destroy_func_t destroy);
 void timeout_remove(unsigned int id);
+
+unsigned int timeout_add_seconds(unsigned int timeout, timeout_func_t func,
+			void *user_data, timeout_destroy_func_t destroy);
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread
* [PATCH Bluez v3 1/4] shared/timeout: Add timeout_add_seconds abstraction
@ 2021-03-16 14:26 Frédéric Danis
  2021-03-16 14:48 ` adapter: Fix discovery trigger for 0 second delay bluez.test.bot
  0 siblings, 1 reply; 9+ messages in thread
From: Frédéric Danis @ 2021-03-16 14:26 UTC (permalink / raw)
  To: linux-bluetooth

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.
In case of a 0 delay call g_idle_add() instead of g_timeout_add_seconds().
---
 src/shared/tester.c           | 16 +++++++++-------
 src/shared/timeout-ell.c      |  6 ++++++
 src/shared/timeout-glib.c     | 27 +++++++++++++++++++++++++++
 src/shared/timeout-mainloop.c |  6 ++++++
 src/shared/timeout.h          |  3 +++
 5 files changed, 51 insertions(+), 7 deletions(-)

diff --git a/src/shared/tester.c b/src/shared/tester.c
index af33a79cd..c07cbc11c 100644
--- a/src/shared/tester.c
+++ b/src/shared/tester.c
@@ -36,6 +36,7 @@
 #include "src/shared/util.h"
 #include "src/shared/tester.h"
 #include "src/shared/log.h"
+#include "src/shared/timeout.h"
 
 #define COLOR_OFF	"\x1B[0m"
 #define COLOR_BLACK	"\x1B[0;30m"
@@ -126,7 +127,7 @@ static void test_destroy(gpointer data)
 	struct test_case *test = data;
 
 	if (test->timeout_id > 0)
-		g_source_remove(test->timeout_id);
+		timeout_remove(test->timeout_id);
 
 	if (test->teardown_id > 0)
 		g_source_remove(test->teardown_id);
@@ -429,7 +430,7 @@ static gboolean teardown_callback(gpointer user_data)
 	return FALSE;
 }
 
-static gboolean test_timeout(gpointer user_data)
+static bool test_timeout(gpointer user_data)
 {
 	struct test_case *test = user_data;
 
@@ -470,8 +471,9 @@ static void next_test_case(void)
 	test->start_time = g_timer_elapsed(test_timer, NULL);
 
 	if (test->timeout > 0)
-		test->timeout_id = g_timeout_add_seconds(test->timeout,
-							test_timeout, test);
+		test->timeout_id = timeout_add_seconds(test->timeout,
+							test_timeout, test,
+							NULL);
 
 	test->stage = TEST_STAGE_PRE_SETUP;
 
@@ -542,7 +544,7 @@ void tester_pre_setup_failed(void)
 		return;
 
 	if (test->timeout_id > 0) {
-		g_source_remove(test->timeout_id);
+		timeout_remove(test->timeout_id);
 		test->timeout_id = 0;
 	}
 
@@ -583,7 +585,7 @@ void tester_setup_failed(void)
 	test->stage = TEST_STAGE_POST_TEARDOWN;
 
 	if (test->timeout_id > 0) {
-		g_source_remove(test->timeout_id);
+		timeout_remove(test->timeout_id);
 		test->timeout_id = 0;
 	}
 
@@ -606,7 +608,7 @@ static void test_result(enum test_result result)
 		return;
 
 	if (test->timeout_id > 0) {
-		g_source_remove(test->timeout_id);
+		timeout_remove(test->timeout_id);
 		test->timeout_id = 0;
 	}
 
diff --git a/src/shared/timeout-ell.c b/src/shared/timeout-ell.c
index 023364069..6416d8590 100644
--- a/src/shared/timeout-ell.c
+++ b/src/shared/timeout-ell.c
@@ -101,3 +101,9 @@ void timeout_remove(unsigned int id)
 	if (to)
 		l_timeout_remove(to);
 }
+
+unsigned int timeout_add_seconds(unsigned int timeout, timeout_func_t func,
+			void *user_data, timeout_destroy_func_t destroy)
+{
+	return timeout_add(timeout * 1000, func, user_data, destroy);
+}
diff --git a/src/shared/timeout-glib.c b/src/shared/timeout-glib.c
index 8bdb7a662..3268d480c 100644
--- a/src/shared/timeout-glib.c
+++ b/src/shared/timeout-glib.c
@@ -71,3 +71,30 @@ void timeout_remove(unsigned int id)
 	if (source)
 		g_source_destroy(source);
 }
+
+unsigned int timeout_add_seconds(unsigned int timeout, timeout_func_t func,
+			void *user_data, timeout_destroy_func_t destroy)
+{
+	struct timeout_data *data;
+	guint id;
+
+	data = g_try_new0(struct timeout_data, 1);
+	if (!data)
+		return 0;
+
+	data->func = func;
+	data->destroy = destroy;
+	data->user_data = user_data;
+
+	if (!timeout)
+		id = g_idle_add_full(G_PRIORITY_DEFAULT_IDLE, timeout_callback,
+							data, timeout_destroy);
+	else
+		id = g_timeout_add_seconds_full(G_PRIORITY_DEFAULT, timeout,
+							timeout_callback, data,
+							timeout_destroy);
+	if (!id)
+		g_free(data);
+
+	return id;
+}
diff --git a/src/shared/timeout-mainloop.c b/src/shared/timeout-mainloop.c
index 5ffa65c2a..9be803cda 100644
--- a/src/shared/timeout-mainloop.c
+++ b/src/shared/timeout-mainloop.c
@@ -71,3 +71,9 @@ void timeout_remove(unsigned int id)
 
 	mainloop_remove_timeout((int) id);
 }
+
+unsigned int timeout_add_seconds(unsigned int timeout, timeout_func_t func,
+			void *user_data, timeout_destroy_func_t destroy)
+{
+	return timeout_add(timeout * 1000, func, user_data, destroy);
+}
diff --git a/src/shared/timeout.h b/src/shared/timeout.h
index 7e22345dd..0945c3318 100644
--- a/src/shared/timeout.h
+++ b/src/shared/timeout.h
@@ -16,3 +16,6 @@ typedef void (*timeout_destroy_func_t)(void *user_data);
 unsigned int timeout_add(unsigned int timeout, timeout_func_t func,
 			void *user_data, timeout_destroy_func_t destroy);
 void timeout_remove(unsigned int id);
+
+unsigned int timeout_add_seconds(unsigned int timeout, timeout_func_t func,
+			void *user_data, timeout_destroy_func_t destroy);
-- 
2.18.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2021-03-16 18:11 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-03-16 17:18 [PATCH Bluez v5 0/4] adapter: Fix discovery trigger for 0 second delay Frédéric Danis
2021-03-16 17:18 ` [PATCH Bluez v5 1/4] shared/timeout: Add timeout_add_seconds abstraction Frédéric Danis
2021-03-16 17:51   ` adapter: Fix discovery trigger for 0 second delay bluez.test.bot
2021-03-16 18:08   ` [PATCH Bluez v5 1/4] shared/timeout: Add timeout_add_seconds abstraction Luiz Augusto von Dentz
2021-03-16 17:18 ` [PATCH Bluez v5 2/4] src: Replace calls to g_timeout_add_seconds by timeout_add_seconds Frédéric Danis
2021-03-16 17:18 ` [PATCH Bluez v5 3/4] plugins: " Frédéric Danis
2021-03-16 17:18 ` [PATCH Bluez v5 4/4] profiles: " Frédéric Danis
  -- strict thread matches above, loose matches on Subject: below --
2021-03-16 16:39 [PATCH Bluez v4 1/4] shared/timeout: Add timeout_add_seconds abstraction Frédéric Danis
2021-03-16 17:08 ` adapter: Fix discovery trigger for 0 second delay bluez.test.bot
2021-03-16 14:26 [PATCH Bluez v3 1/4] shared/timeout: Add timeout_add_seconds abstraction Frédéric Danis
2021-03-16 14:48 ` adapter: Fix discovery trigger for 0 second delay bluez.test.bot

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.