You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by we...@apache.org on 2016/08/11 21:27:35 UTC

[35/50] [abbrv] incubator-mynewt-core git commit: BLE RAM trans: evt buf sz 260-->45; ct 3-->14

BLE RAM trans: evt buf sz 260-->45; ct 3-->14

For the combined host-controller (RAM HCI transport), the default HCI
event buffer size was much larger than necessary.  The largest event the
NimBLE controller will send is 45 bytes, but the default buffer size was
260.

This change:

* reduces the default event buffer size from 260 to 45
* increases the default lo-prio event count from 2 to 12
* increases the default hi-prio event count from 1 to 2


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/74c3c9be
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/tree/74c3c9be
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/diff/74c3c9be

Branch: refs/heads/phyrx_no_mbuf
Commit: 74c3c9bee638a425d7f2be65ce1d8637eee75c9c
Parents: 202e5c3
Author: Christopher Collins <cc...@apache.org>
Authored: Tue Aug 9 17:53:46 2016 -0700
Committer: William San Filippo <wi...@runtime.io>
Committed: Thu Aug 11 14:26:26 2016 -0700

----------------------------------------------------------------------
 .../controller/include/controller/ble_ll_hci.h  |  3 ++
 net/nimble/controller/src/ble_ll_conn_hci.c     | 32 ++++++++++----------
 net/nimble/controller/src/ble_ll_hci.c          |  2 ++
 net/nimble/host/include/host/ble_hs.h           | 18 ++---------
 net/nimble/host/src/ble_hs_cfg.c                |  2 +-
 net/nimble/transport/ram/src/ble_hci_ram.c      |  8 +++--
 6 files changed, 29 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/74c3c9be/net/nimble/controller/include/controller/ble_ll_hci.h
----------------------------------------------------------------------
diff --git a/net/nimble/controller/include/controller/ble_ll_hci.h b/net/nimble/controller/include/controller/ble_ll_hci.h
index 47daa76..43b98fc 100644
--- a/net/nimble/controller/include/controller/ble_ll_hci.h
+++ b/net/nimble/controller/include/controller/ble_ll_hci.h
@@ -24,6 +24,9 @@
 #define BLE_LL_SUPP_CMD_LEN (36)
 extern const uint8_t g_ble_ll_supp_cmds[BLE_LL_SUPP_CMD_LEN];
 
+/* The largest event the controller will send. */
+#define BLE_LL_MAX_EVT_LEN  (45)
+
 /*
  * This determines the number of outstanding commands allowed from the
  * host to the controller.

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/74c3c9be/net/nimble/controller/src/ble_ll_conn_hci.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_conn_hci.c b/net/nimble/controller/src/ble_ll_conn_hci.c
index f653ca6..d7001f8 100644
--- a/net/nimble/controller/src/ble_ll_conn_hci.c
+++ b/net/nimble/controller/src/ble_ll_conn_hci.c
@@ -203,22 +203,25 @@ ble_ll_conn_comp_event_send(struct ble_ll_conn_sm *connsm, uint8_t status)
     }
 }
 
+
 /**
  * Called to create and send the number of completed packets event to the
  * host.
  *
- * Because of the ridiculous spec, all the connection handles are contiguous and
- * then all the completed packets are contiguous. In order to avoid multiple
- * passes through the connection list or allocating a large stack variable or
- * malloc, I just use the event buffer and place the completed packets after
- * the last possible handle. I then copy the completed packets to make it
- * contiguous with the handles.
- *
- * @param connsm
+ * Because of the ridiculous spec, all the connection handles are contiguous
+ * and then all the completed packets are contiguous. In order to avoid
+ * multiple passes through the connection list or allocating a large stack
+ * variable or malloc, I just use the event buffer and place the completed
+ * packets after the last possible handle. I then copy the completed packets
+ * to make it contiguous with the handles.
  */
 void
 ble_ll_conn_num_comp_pkts_event_send(void)
 {
+    /** The maximum number of handles that will fit in an event buffer. */
+    static const int max_handles =
+        (BLE_LL_MAX_EVT_LEN - BLE_HCI_EVENT_HDR_LEN - 1) / 4;
+
     int event_sent;
     uint8_t *evbuf;
     uint8_t *handle_ptr;
@@ -253,7 +256,7 @@ ble_ll_conn_num_comp_pkts_event_send(void)
                 }
                 handles = 0;
                 handle_ptr = evbuf + 3;
-                comp_pkt_ptr = handle_ptr + (sizeof(uint16_t) * 60);
+                comp_pkt_ptr = handle_ptr + (sizeof(uint16_t) * max_handles);
             }
 
             /* Add handle and complete packets */
@@ -264,11 +267,8 @@ ble_ll_conn_num_comp_pkts_event_send(void)
             comp_pkt_ptr += sizeof(uint16_t);
             ++handles;
 
-            /*
-             * The event buffer should fit at least 255 bytes so this means we
-             * can fit up to 60 handles per event (a little more but who cares).
-             */
-            if (handles == 60) {
+            /* Send now if the buffer is full. */
+            if (handles == max_handles) {
                 evbuf[0] = BLE_HCI_EVCODE_NUM_COMP_PKTS;
                 evbuf[1] = (handles * 2 * sizeof(uint16_t)) + 1;
                 evbuf[2] = handles;
@@ -285,9 +285,9 @@ ble_ll_conn_num_comp_pkts_event_send(void)
         evbuf[0] = BLE_HCI_EVCODE_NUM_COMP_PKTS;
         evbuf[1] = (handles * 2 * sizeof(uint16_t)) + 1;
         evbuf[2] = handles;
-        if (handles < 60) {
+        if (handles < max_handles) {
             /* Make the pkt counts contiguous with handles */
-            memmove(handle_ptr, evbuf + 3 + (60 * 2), handles * 2);
+            memmove(handle_ptr, evbuf + 3 + (max_handles * 2), handles * 2);
         }
         ble_ll_hci_event_send(evbuf);
         event_sent = 1;

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/74c3c9be/net/nimble/controller/src/ble_ll_hci.c
----------------------------------------------------------------------
diff --git a/net/nimble/controller/src/ble_ll_hci.c b/net/nimble/controller/src/ble_ll_hci.c
index 352dda2..758568b 100644
--- a/net/nimble/controller/src/ble_ll_hci.c
+++ b/net/nimble/controller/src/ble_ll_hci.c
@@ -64,6 +64,8 @@ ble_ll_hci_event_send(uint8_t *evbuf)
 {
     int rc;
 
+    assert(BLE_HCI_EVENT_HDR_LEN + evbuf[1] <= BLE_LL_MAX_EVT_LEN);
+
     /* Count number of events sent */
     STATS_INC(ble_ll_stats, hci_events_sent);
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/74c3c9be/net/nimble/host/include/host/ble_hs.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/include/host/ble_hs.h b/net/nimble/host/include/host/ble_hs.h
index 954d278..8d85009 100644
--- a/net/nimble/host/include/host/ble_hs.h
+++ b/net/nimble/host/include/host/ble_hs.h
@@ -95,26 +95,12 @@ typedef void ble_hs_sync_fn(void);
 
 struct ble_hs_cfg {
     /**
-     * An HCI buffer is a "flat" 260-byte buffer.  HCI buffers are used by the
-     * controller to send unsolicited events to the host.
-     *
-     * HCI buffers can get tied up when the controller sends lots of
-     * asynchronous / unsolicited events (i.e., non-acks).  When the controller
-     * needs to send one of these events, it allocates an HCI buffer, fills it
-     * with the event payload, and puts it on a host queue.  If the controller
-     * sends a quick burst of these events, the buffer pool may be exhausted,
-     * preventing the host from sending an HCI command to the controller.
-     *
      * Every time the controller sends a non-ack HCI event to the host, it also
      * allocates an OS event (it is unfortunate that these are both called
      * "events").  The OS event is put on the host-parent-task's event queue;
      * it is what wakes up the host-parent-task and indicates that an HCI event
-     * needs to be processsed.  The pool of OS events is allocated with the
-     * same number of elements as the HCI buffer pool.
-     */
-    /* XXX: This should either be renamed to indicate it is only used for OS
-     * events, or it should go away entirely (copy the number from the
-     * transport's config).
+     * needs to be processsed.  This setting should be equal to the total
+     * number of HCI event buffers that the transport is configured to use.
      */
     uint8_t max_hci_bufs;
 

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/74c3c9be/net/nimble/host/src/ble_hs_cfg.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_cfg.c b/net/nimble/host/src/ble_hs_cfg.c
index fb5fb45..eca8407 100644
--- a/net/nimble/host/src/ble_hs_cfg.c
+++ b/net/nimble/host/src/ble_hs_cfg.c
@@ -27,7 +27,7 @@
 
 const struct ble_hs_cfg ble_hs_cfg_dflt = {
     /** HCI settings. */
-    .max_hci_bufs = 3,
+    .max_hci_bufs = 14,
 
     /** Connection settings. */
     .max_connections = BLE_HS_CFG_MAX_CONNECTIONS,

http://git-wip-us.apache.org/repos/asf/incubator-mynewt-core/blob/74c3c9be/net/nimble/transport/ram/src/ble_hci_ram.c
----------------------------------------------------------------------
diff --git a/net/nimble/transport/ram/src/ble_hci_ram.c b/net/nimble/transport/ram/src/ble_hci_ram.c
index 2ce5fd6..ef46309 100644
--- a/net/nimble/transport/ram/src/ble_hci_ram.c
+++ b/net/nimble/transport/ram/src/ble_hci_ram.c
@@ -9,9 +9,11 @@
 
 /** Default configuration. */
 const struct ble_hci_ram_cfg ble_hci_ram_cfg_dflt = {
-    .num_evt_hi_bufs = 1,
-    .num_evt_lo_bufs = 2,
-    .evt_buf_sz = BLE_HCI_TRANS_CMD_SZ,
+    .num_evt_hi_bufs = 2,
+    .num_evt_lo_bufs = 12,
+
+    /* The largest event the nimble controller will send is 45 bytes. */
+    .evt_buf_sz = 45,
 };
 
 static ble_hci_trans_rx_cmd_fn *ble_hci_ram_rx_cmd_hs_cb;