This is an automated email from the ASF dual-hosted git repository.

andk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git

commit 1f2fa515402d65991f9cad1c206cd79443be09a6
Author: Andrzej Kaczmarek <andrzej.kaczma...@codecoup.pl>
AuthorDate: Tue Oct 10 15:28:25 2023 +0200

    nimble/ll: Add counter for queued SDUs
    
    This avoid looping through queue to find number of SDUs in event.
---
 .../controller/include/controller/ble_ll_isoal.h   |  1 +
 nimble/controller/src/ble_ll_isoal.c               | 23 ++++++++++------------
 2 files changed, 11 insertions(+), 13 deletions(-)

diff --git a/nimble/controller/include/controller/ble_ll_isoal.h 
b/nimble/controller/include/controller/ble_ll_isoal.h
index 5104ea97..73ceaf76 100644
--- a/nimble/controller/include/controller/ble_ll_isoal.h
+++ b/nimble/controller/include/controller/ble_ll_isoal.h
@@ -39,6 +39,7 @@ struct ble_ll_isoal_mux {
     uint8_t sdu_in_event;
 
     STAILQ_HEAD(, os_mbuf_pkthdr) sdu_q;
+    uint16_t sdu_q_len;
 
     struct os_mbuf *frag;
 
diff --git a/nimble/controller/src/ble_ll_isoal.c 
b/nimble/controller/src/ble_ll_isoal.c
index b0288443..3ccf986d 100644
--- a/nimble/controller/src/ble_ll_isoal.c
+++ b/nimble/controller/src/ble_ll_isoal.c
@@ -46,6 +46,7 @@ ble_ll_isoal_mux_init(struct ble_ll_isoal_mux *mux, uint8_t 
max_pdu,
     mux->sdu_per_event = (1 + pte) * mux->sdu_per_interval;
 
     STAILQ_INIT(&mux->sdu_q);
+    mux->sdu_q_len = 0;
 }
 
 void
@@ -117,23 +118,14 @@ ble_ll_isoal_mux_tx_pkt_in(struct ble_ll_isoal_mux *mux, 
struct os_mbuf *om,
     OS_ENTER_CRITICAL(sr);
     pkthdr = OS_MBUF_PKTHDR(om);
     STAILQ_INSERT_TAIL(&mux->sdu_q, pkthdr, omp_next);
+    mux->sdu_q_len++;
     OS_EXIT_CRITICAL(sr);
 }
 
 int
 ble_ll_isoal_mux_event_start(struct ble_ll_isoal_mux *mux, uint32_t timestamp)
 {
-    struct os_mbuf_pkthdr *pkthdr;
-    uint8_t num_sdu;
-
-    num_sdu = mux->sdu_per_event;
-
-    pkthdr = STAILQ_FIRST(&mux->sdu_q);
-    while (pkthdr && num_sdu--) {
-        pkthdr = STAILQ_NEXT(pkthdr, omp_next);
-    }
-
-    mux->sdu_in_event = mux->sdu_per_event - num_sdu;
+    mux->sdu_in_event = min(mux->sdu_q_len, mux->sdu_per_event);
     mux->event_tx_timestamp = timestamp;
 
     return mux->sdu_in_event;
@@ -148,6 +140,7 @@ ble_ll_isoal_mux_event_done(struct ble_ll_isoal_mux *mux)
     struct os_mbuf *om_next;
     uint8_t num_sdu;
     int pkt_freed = 0;
+    os_sr_t sr;
 
     num_sdu = min(mux->sdu_in_event, mux->sdu_per_interval);
 
@@ -160,8 +153,13 @@ ble_ll_isoal_mux_event_done(struct ble_ll_isoal_mux *mux)
     }
 
     while (pkthdr && num_sdu--) {
-        om = OS_MBUF_PKTHDR_TO_MBUF(pkthdr);
+        OS_ENTER_CRITICAL(sr);
+        STAILQ_REMOVE_HEAD(&mux->sdu_q, omp_next);
+        BLE_LL_ASSERT(mux->sdu_q_len > 0);
+        mux->sdu_q_len--;
+        OS_EXIT_CRITICAL(sr);
 
+        om = OS_MBUF_PKTHDR_TO_MBUF(pkthdr);
         while (om) {
             om_next = SLIST_NEXT(om, om_next);
             os_mbuf_free(om);
@@ -169,7 +167,6 @@ ble_ll_isoal_mux_event_done(struct ble_ll_isoal_mux *mux)
             om = om_next;
         }
 
-        STAILQ_REMOVE_HEAD(&mux->sdu_q, omp_next);
         pkthdr = STAILQ_FIRST(&mux->sdu_q);
     }
 

Reply via email to