You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2016/07/11 22:33:18 UTC

incubator-mynewt-core git commit: BLE Host - Limit to 2 consecutive OS events.

Repository: incubator-mynewt-core
Updated Branches:
  refs/heads/develop f258b0de4 -> 364bcc3ea


BLE Host - Limit to 2 consecutive OS events.

Prior to this change:

When the host had work to do, it would process its eventq until it was
empty.  This is the correct behavior for most tasks, since the OS will
interrupt the task when a higher priority task has work to do.  However,
this is wrong for the NimBLE host because the host doesn't have a task
of its own; it runs within a parent task.  This previous behavior caused
the following two problems:

1. When the host sets a timer, the timer is associated with the parent
task's eventq.  When the timer expires, it is the parent task which
executes the callout.  If the host is busy with an endless series of
events (e.g., during scanning, if the application logs every
advertisement), then the callout never gets processed because the host
event queue is never empty.  This is especially problematic in the case
of scanning, because it is a time which terminates the scan procedure!

2. The parent task could get starved when the host had too much work to
do (again, the example is when logging incoming advertisement reports).
This isn't as big of a problem, because the application could always
move functionality out of the parent task and into something with a
higher priority.

New behavior:

After the host processes two consecutive events, it relinquishes control
back to the parent task.  If the parent task has no work to do, control
is immediately given back to the host.


Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/commit/364bcc3e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/364bcc3e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/364bcc3e

Branch: refs/heads/develop
Commit: 364bcc3ea3db00ade4e0a8c6290ff8f8b2f1158c
Parents: f258b0d
Author: Christopher Collins <cc...@apache.org>
Authored: Mon Jul 11 15:22:20 2016 -0700
Committer: Christopher Collins <cc...@apache.org>
Committed: Mon Jul 11 15:22:20 2016 -0700

----------------------------------------------------------------------
 net/nimble/host/src/ble_hs.c | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/364bcc3e/net/nimble/host/src/ble_hs.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs.c b/net/nimble/host/src/ble_hs.c
index bd09217..37e4549 100644
--- a/net/nimble/host/src/ble_hs.c
+++ b/net/nimble/host/src/ble_hs.c
@@ -30,11 +30,11 @@
 #include "host/ble_hs_test.h"
 #endif
 
-#ifdef ARCH_sim
-#define BLE_HS_STACK_SIZE   (1024)
-#else
-#define BLE_HS_STACK_SIZE   (512)//(250)
-#endif
+/**
+ * The maximum number of events the host will process in a row before returning
+ * control to the parent task.
+ */
+#define BLE_HS_MAX_EVS_IN_A_ROW 2
 
 static struct log_handler ble_hs_log_console_handler;
 struct log ble_hs_log;
@@ -213,8 +213,20 @@ ble_hs_event_handle(void *unused)
     struct os_callout_func *cf;
     struct os_event *ev;
     os_sr_t sr;
+    int i;
 
+    i = 0;
     while (1) {
+        /* If the host has already processed several consecutive events, stop
+         * and return control to the parent task.  Put an event on the parent
+         * task's eventq so indicate that more host events are enqueued.
+         */
+        if (i >= BLE_HS_MAX_EVS_IN_A_ROW) {
+            os_eventq_put(ble_hs_parent_evq, &ble_hs_event_co.cf_c.c_ev);
+            break;
+        }
+        i++;
+
         OS_ENTER_CRITICAL(sr);
         ev = STAILQ_FIRST(&ble_hs_evq.evq_list);
         OS_EXIT_CRITICAL(sr);
@@ -232,7 +244,6 @@ ble_hs_event_handle(void *unused)
             break;
 
         case BLE_HOST_HCI_EVENT_CTLR_EVENT:
-            /* Process HCI event from controller */
             host_hci_os_event_proc(ev);
             break;