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/02/05 23:30:09 UTC
[2/2] incubator-mynewt-larva git commit: Switch nimble host from
private mbuf poool to msys
Switch nimble host from private mbuf poool to msys
Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/commit/336fa55f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/tree/336fa55f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/diff/336fa55f
Branch: refs/heads/master
Commit: 336fa55feb68c9dd6e9111c9a4877d3277e0b6b0
Parents: 1f9b22b
Author: Christopher Collins <cc...@gmail.com>
Authored: Fri Feb 5 14:29:26 2016 -0800
Committer: Christopher Collins <cc...@gmail.com>
Committed: Fri Feb 5 14:29:26 2016 -0800
----------------------------------------------------------------------
net/nimble/host/src/ble_att.c | 21 ----------------
net/nimble/host/src/ble_att_clt.c | 2 +-
net/nimble/host/src/ble_att_priv.h | 1 -
net/nimble/host/src/ble_att_svr.c | 24 +++++++++---------
net/nimble/host/src/ble_hs.c | 25 -------------------
net/nimble/host/src/ble_hs_misc.c | 21 ++++++++++++++++
net/nimble/host/src/ble_hs_priv.h | 2 ++
net/nimble/host/src/ble_l2cap_sig_cmd.c | 6 ++---
net/nimble/host/src/test/ble_hs_test_util.c | 31 +++++++++++++++++++++++-
net/nimble/host/src/test/ble_l2cap_test.c | 10 ++++----
10 files changed, 74 insertions(+), 69 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/336fa55f/net/nimble/host/src/ble_att.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att.c b/net/nimble/host/src/ble_att.c
index 753df4a..7acaeb1 100644
--- a/net/nimble/host/src/ble_att.c
+++ b/net/nimble/host/src/ble_att.c
@@ -226,27 +226,6 @@ ble_att_create_chan(void)
}
/**
- * Allocates an mbuf for use as an ATT request or response.
- *
- * Lock restrictions: None.
- */
-struct os_mbuf *
-ble_att_get_pkthdr(void)
-{
- struct os_mbuf *om;
-
- om = os_mbuf_get_pkthdr(&ble_hs_mbuf_pool, 0);
- if (om == NULL) {
- return NULL;
- }
-
- /* Make room in the buffer for various headers. XXX Check this number. */
- om->om_data += 8;
-
- return om;
-}
-
-/**
* Lock restrictions: None.
*/
void
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/336fa55f/net/nimble/host/src/ble_att_clt.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_clt.c b/net/nimble/host/src/ble_att_clt.c
index b9de412..63a440a 100644
--- a/net/nimble/host/src/ble_att_clt.c
+++ b/net/nimble/host/src/ble_att_clt.c
@@ -47,7 +47,7 @@ ble_att_clt_init_req(struct ble_hs_conn *conn, struct ble_l2cap_chan **chan,
goto err;
}
- *txom = ble_att_get_pkthdr();
+ *txom = ble_hs_misc_pkthdr();
if (*txom == NULL) {
rc = BLE_HS_ENOMEM;
goto err;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/336fa55f/net/nimble/host/src/ble_att_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_priv.h b/net/nimble/host/src/ble_att_priv.h
index 1f091f0..b4b1a1b 100644
--- a/net/nimble/host/src/ble_att_priv.h
+++ b/net/nimble/host/src/ble_att_priv.h
@@ -93,7 +93,6 @@ int ble_att_conn_chan_find(uint16_t conn_handle, struct ble_hs_conn **out_conn,
struct ble_l2cap_chan **out_chan);
uint16_t ble_att_mtu(uint16_t conn_handle);
void ble_att_set_peer_mtu(struct ble_l2cap_chan *chan, uint16_t peer_mtu);
-struct os_mbuf *ble_att_get_pkthdr(void);
void ble_att_init(void);
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/336fa55f/net/nimble/host/src/ble_att_svr.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_att_svr.c b/net/nimble/host/src/ble_att_svr.c
index fb2ddec..d71a055 100644
--- a/net/nimble/host/src/ble_att_svr.c
+++ b/net/nimble/host/src/ble_att_svr.c
@@ -467,7 +467,7 @@ ble_att_svr_tx_error_rsp(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
void *dst;
int rc;
- txom = ble_att_get_pkthdr();
+ txom = ble_hs_misc_pkthdr();
if (txom == NULL) {
rc = BLE_HS_ENOMEM;
goto err;
@@ -576,7 +576,7 @@ ble_att_svr_tx_mtu_rsp(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
assert(op == BLE_ATT_OP_MTU_REQ || op == BLE_ATT_OP_MTU_RSP);
assert(mtu >= BLE_ATT_MTU_DFLT);
- txom = ble_att_get_pkthdr();
+ txom = ble_hs_misc_pkthdr();
if (txom == NULL) {
*att_err = BLE_ATT_ERR_INSUFFICIENT_RES;
rc = BLE_HS_ENOMEM;
@@ -792,7 +792,7 @@ ble_att_svr_build_find_info_rsp(uint16_t conn_handle,
goto done;
}
- txom = ble_att_get_pkthdr();
+ txom = ble_hs_misc_pkthdr();
if (txom == NULL) {
*att_err = BLE_ATT_ERR_INSUFFICIENT_RES;
rc = BLE_HS_ENOMEM;
@@ -1122,7 +1122,7 @@ ble_att_svr_build_find_type_value_rsp(uint16_t conn_handle,
uint8_t *buf;
int rc;
- txom = ble_att_get_pkthdr();
+ txom = ble_hs_misc_pkthdr();
if (txom == NULL) {
*out_att_err = BLE_ATT_ERR_INSUFFICIENT_RES;
rc = BLE_HS_ENOMEM;
@@ -1249,7 +1249,7 @@ ble_att_svr_build_read_type_rsp(uint16_t conn_handle,
return BLE_HS_ENOTCONN;
}
- txom = ble_att_get_pkthdr();
+ txom = ble_hs_misc_pkthdr();
if (txom == NULL) {
*att_err = BLE_ATT_ERR_INSUFFICIENT_RES;
*err_handle = 0;
@@ -1443,7 +1443,7 @@ ble_att_svr_build_read_rsp(uint16_t conn_handle, void *attr_data, int attr_len,
goto done;
}
- txom = ble_att_get_pkthdr();
+ txom = ble_hs_misc_pkthdr();
if (txom == NULL) {
*att_err = BLE_ATT_ERR_INSUFFICIENT_RES;
rc = BLE_HS_ENOMEM;
@@ -1550,7 +1550,7 @@ ble_att_svr_build_read_blob_rsp(void *attr_data, int attr_len, uint16_t mtu,
uint8_t op;
int rc;
- txom = ble_att_get_pkthdr();
+ txom = ble_hs_misc_pkthdr();
if (txom == NULL) {
*att_err = BLE_ATT_ERR_INSUFFICIENT_RES;
rc = BLE_HS_ENOMEM;
@@ -1684,7 +1684,7 @@ ble_att_svr_build_read_mult_rsp(uint16_t conn_handle,
goto done;
}
- txom = ble_att_get_pkthdr();
+ txom = ble_hs_misc_pkthdr();
if (txom == NULL) {
*att_err = BLE_ATT_ERR_INSUFFICIENT_RES;
*err_handle = 0;
@@ -1918,7 +1918,7 @@ ble_att_svr_build_read_group_type_rsp(uint16_t conn_handle,
goto done;
}
- txom = ble_att_get_pkthdr();
+ txom = ble_hs_misc_pkthdr();
if (txom == NULL) {
*att_err = BLE_ATT_ERR_INSUFFICIENT_RES;
rc = BLE_HS_ENOMEM;
@@ -2146,7 +2146,7 @@ ble_att_svr_build_write_rsp(struct os_mbuf **out_txom, uint8_t *att_err)
uint8_t *dst;
int rc;
- txom = ble_att_get_pkthdr();
+ txom = ble_hs_misc_pkthdr();
if (txom == NULL) {
*att_err = BLE_ATT_ERR_INSUFFICIENT_RES;
rc = BLE_HS_ENOMEM;
@@ -2608,7 +2608,7 @@ ble_att_svr_build_exec_write_rsp(struct os_mbuf **out_txom, uint8_t *att_err)
uint8_t *dst;
int rc;
- txom = ble_att_get_pkthdr();
+ txom = ble_hs_misc_pkthdr();
if (txom == NULL) {
*att_err = BLE_ATT_ERR_INSUFFICIENT_RES;
rc = BLE_HS_ENOMEM;
@@ -2750,7 +2750,7 @@ ble_att_svr_build_indicate_rsp(struct os_mbuf **out_txom)
uint8_t *dst;
int rc;
- txom = ble_att_get_pkthdr();
+ txom = ble_hs_misc_pkthdr();
if (txom == NULL) {
rc = BLE_HS_ENOMEM;
goto done;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/336fa55f/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 d20cae2..094e992 100644
--- a/net/nimble/host/src/ble_hs.c
+++ b/net/nimble/host/src/ble_hs.c
@@ -52,24 +52,11 @@ static os_membuf_t g_hci_cmd_buf[OS_MEMPOOL_SIZE(HCI_CMD_BUFS,
#define HCI_NUM_OS_EVENTS (32)
#define HCI_OS_EVENT_BUF_SIZE (sizeof(struct os_event))
-#define BLE_HS_NUM_MBUFS (8)
-#define BLE_HS_MBUF_BUF_SIZE (256)
-#define BLE_HS_MBUF_MEMBLOCK_SIZE \
- (BLE_HS_MBUF_BUF_SIZE + sizeof(struct os_mbuf) + \
- sizeof(struct os_mbuf_pkthdr))
-
-#define BLE_HS_MBUF_MEMPOOL_SIZE \
- OS_MEMPOOL_SIZE(BLE_HS_NUM_MBUFS, BLE_HS_MBUF_MEMBLOCK_SIZE)
-
struct os_mempool g_hci_os_event_pool;
static os_membuf_t
g_hci_os_event_buf[OS_MEMPOOL_SIZE(HCI_NUM_OS_EVENTS,
HCI_OS_EVENT_BUF_SIZE)] bssnz_t;
-static os_membuf_t ble_hs_mbuf_mem[BLE_HS_MBUF_MEMPOOL_SIZE];
-static struct os_mempool ble_hs_mbuf_mempool;
-struct os_mbuf_pool ble_hs_mbuf_pool;
-
/* Host HCI Task Events */
struct os_eventq ble_hs_evq;
static struct os_event ble_hs_kick_hci_ev;
@@ -245,18 +232,6 @@ ble_hs_init(uint8_t prio)
host_hci_init();
- rc = os_mempool_init(&ble_hs_mbuf_mempool, BLE_HS_NUM_MBUFS,
- BLE_HS_MBUF_MEMBLOCK_SIZE,
- ble_hs_mbuf_mem, "ble_hs_mbuf_pool");
- if (rc != 0) {
- return BLE_HS_EOS;
- }
- rc = os_mbuf_pool_init(&ble_hs_mbuf_pool, &ble_hs_mbuf_mempool,
- BLE_HS_MBUF_MEMBLOCK_SIZE, BLE_HS_NUM_MBUFS);
- if (rc != 0) {
- return BLE_HS_EOS;
- }
-
rc = ble_hs_conn_init();
if (rc != 0) {
return rc;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/336fa55f/net/nimble/host/src/ble_hs_misc.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_misc.c b/net/nimble/host/src/ble_hs_misc.c
index b21bdc5..97a3495 100644
--- a/net/nimble/host/src/ble_hs_misc.c
+++ b/net/nimble/host/src/ble_hs_misc.c
@@ -74,3 +74,24 @@ ble_hs_misc_assert_no_locks(void)
assert(!ble_gattc_locked_by_cur_task());
assert(!ble_gap_locked_by_cur_task());
}
+
+/**
+ * Allocates an mbuf for use by the nimble host.
+ *
+ * Lock restrictions: None.
+ */
+struct os_mbuf *
+ble_hs_misc_pkthdr(void)
+{
+ struct os_mbuf *om;
+
+ om = os_msys_get_pkthdr(0, 0);
+ if (om == NULL) {
+ return NULL;
+ }
+
+ /* Make room in the buffer for various headers. XXX Check this number. */
+ om->om_data += 8;
+
+ return om;
+}
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/336fa55f/net/nimble/host/src/ble_hs_priv.h
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_hs_priv.h b/net/nimble/host/src/ble_hs_priv.h
index c6e29d6..0aae2c9 100644
--- a/net/nimble/host/src/ble_hs_priv.h
+++ b/net/nimble/host/src/ble_hs_priv.h
@@ -46,4 +46,6 @@ void ble_hs_cfg_init(void);
void ble_hs_misc_assert_no_locks(void);
+struct os_mbuf *ble_hs_misc_pkthdr(void);
+
#endif
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/336fa55f/net/nimble/host/src/ble_l2cap_sig_cmd.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/ble_l2cap_sig_cmd.c b/net/nimble/host/src/ble_l2cap_sig_cmd.c
index cdc604c..9b1e7c7 100644
--- a/net/nimble/host/src/ble_l2cap_sig_cmd.c
+++ b/net/nimble/host/src/ble_l2cap_sig_cmd.c
@@ -94,7 +94,7 @@ ble_l2cap_sig_reject_tx(struct ble_hs_conn *conn, struct ble_l2cap_chan *chan,
void *v;
int rc;
- txom = ble_att_get_pkthdr();
+ txom = ble_hs_misc_pkthdr();
if (txom == NULL) {
return BLE_HS_ENOMEM;
}
@@ -222,7 +222,7 @@ ble_l2cap_sig_update_req_tx(struct ble_hs_conn *conn,
void *v;
int rc;
- txom = ble_att_get_pkthdr();
+ txom = ble_hs_misc_pkthdr();
if (txom == NULL) {
rc = BLE_HS_ENOMEM;
goto done;
@@ -262,7 +262,7 @@ ble_l2cap_sig_update_rsp_tx(struct ble_hs_conn *conn,
void *v;
int rc;
- txom = ble_att_get_pkthdr();
+ txom = ble_hs_misc_pkthdr();
if (txom == NULL) {
rc = BLE_HS_ENOMEM;
goto err;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/336fa55f/net/nimble/host/src/test/ble_hs_test_util.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_hs_test_util.c b/net/nimble/host/src/test/ble_hs_test_util.c
index d8c8f07..25068c2 100644
--- a/net/nimble/host/src/test/ble_hs_test_util.c
+++ b/net/nimble/host/src/test/ble_hs_test_util.c
@@ -30,6 +30,17 @@
#include "ble_att_cmd.h"
#include "ble_hs_test_util.h"
+#define BLE_HS_TEST_UTIL_NUM_MBUFS (10)
+#define BLE_HS_TEST_UTIL_BUF_SIZE OS_ALIGN(BLE_MBUF_PAYLOAD_SIZE, 4)
+#define BLE_HS_TEST_UTIL_MEMBLOCK_SIZE \
+ (BLE_HS_TEST_UTIL_BUF_SIZE + BLE_MBUF_MEMBLOCK_OVERHEAD)
+#define BLE_HS_TEST_UTIL_MEMPOOL_SIZE \
+ OS_MEMPOOL_SIZE(BLE_HS_TEST_UTIL_NUM_MBUFS, BLE_HS_TEST_UTIL_MEMBLOCK_SIZE)
+
+os_membuf_t ble_hs_test_util_mbuf_mpool_data[BLE_HS_TEST_UTIL_MEMPOOL_SIZE];
+struct os_mbuf_pool ble_hs_test_util_mbuf_pool;
+struct os_mempool ble_hs_test_util_mbuf_mpool;
+
struct os_mbuf *ble_hs_test_util_prev_tx;
uint8_t *ble_hs_test_util_prev_hci_tx;
@@ -187,7 +198,7 @@ ble_hs_test_util_l2cap_rx_payload_flat(struct ble_hs_conn *conn,
struct os_mbuf *om;
int rc;
- om = os_mbuf_get_pkthdr(&ble_hs_mbuf_pool, 0);
+ om = ble_hs_misc_pkthdr();
TEST_ASSERT_FATAL(om != NULL);
om->om_data += BLE_L2CAP_HDR_SZ;
@@ -393,9 +404,27 @@ ble_hs_test_util_init(void)
{
int rc;
+ os_msys_reset();
+
rc = ble_hs_init(10);
TEST_ASSERT_FATAL(rc == 0);
+ rc = os_mempool_init(&ble_hs_test_util_mbuf_mpool,
+ BLE_HS_TEST_UTIL_NUM_MBUFS,
+ BLE_HS_TEST_UTIL_MEMBLOCK_SIZE,
+ ble_hs_test_util_mbuf_mpool_data,
+ "ble_hs_test_util_mbuf_data");
+ assert(rc == 0);
+
+ rc = os_mbuf_pool_init(&ble_hs_test_util_mbuf_pool,
+ &ble_hs_test_util_mbuf_mpool,
+ BLE_HS_TEST_UTIL_MEMBLOCK_SIZE,
+ BLE_HS_TEST_UTIL_NUM_MBUFS);
+ assert(rc == 0);
+
+ rc = os_msys_register(&ble_hs_test_util_mbuf_pool);
+ assert(rc == 0);
+
/* Don't limit a connection's ability to transmit; simplify tests. */
ble_hs_cfg.max_outstanding_pkts_per_conn = 0;
http://git-wip-us.apache.org/repos/asf/incubator-mynewt-larva/blob/336fa55f/net/nimble/host/src/test/ble_l2cap_test.c
----------------------------------------------------------------------
diff --git a/net/nimble/host/src/test/ble_l2cap_test.c b/net/nimble/host/src/test/ble_l2cap_test.c
index 50a22db..a35abad 100644
--- a/net/nimble/host/src/test/ble_l2cap_test.c
+++ b/net/nimble/host/src/test/ble_l2cap_test.c
@@ -66,7 +66,7 @@ ble_l2cap_test_util_rx_update_req(struct ble_hs_conn *conn, uint8_t id,
2, BLE_HCI_PB_FIRST_FLUSH,
BLE_L2CAP_HDR_SZ + BLE_L2CAP_SIG_HDR_SZ + BLE_L2CAP_SIG_UPDATE_REQ_SZ);
- om = ble_att_get_pkthdr();
+ om = ble_hs_misc_pkthdr();
TEST_ASSERT_FATAL(om != NULL);
om = ble_l2cap_prepend_hdr(om, BLE_L2CAP_CID_SIG,
@@ -108,7 +108,7 @@ ble_l2cap_test_util_rx_update_rsp(struct ble_hs_conn *conn,
2, BLE_HCI_PB_FIRST_FLUSH,
BLE_L2CAP_HDR_SZ + BLE_L2CAP_SIG_HDR_SZ + BLE_L2CAP_SIG_UPDATE_RSP_SZ);
- om = ble_att_get_pkthdr();
+ om = ble_hs_misc_pkthdr();
TEST_ASSERT_FATAL(om != NULL);
om = ble_l2cap_prepend_hdr(om, BLE_L2CAP_CID_SIG,
@@ -253,7 +253,7 @@ ble_l2cap_test_util_rx_first_frag(struct ble_hs_conn *conn,
void *v;
int rc;
- om = ble_att_get_pkthdr();
+ om = ble_hs_misc_pkthdr();
TEST_ASSERT_FATAL(om != NULL);
v = os_mbuf_extend(om, l2cap_frag_len);
@@ -277,7 +277,7 @@ ble_l2cap_test_util_rx_next_frag(struct ble_hs_conn *conn, uint16_t hci_len)
void *v;
int rc;
- om = ble_att_get_pkthdr();
+ om = ble_hs_misc_pkthdr();
TEST_ASSERT_FATAL(om != NULL);
v = os_mbuf_extend(om, hci_len);
@@ -363,7 +363,7 @@ TEST_CASE(ble_l2cap_test_case_frag_single)
/*** HCI header specifies middle fragment without start. */
hci_hdr = BLE_L2CAP_TEST_UTIL_HCI_HDR(2, BLE_HCI_PB_MIDDLE, 10);
- om = ble_att_get_pkthdr();
+ om = ble_hs_misc_pkthdr();
TEST_ASSERT_FATAL(om != NULL);
om = ble_l2cap_prepend_hdr(om, 0, 5);