pespin has submitted this change. ( 
https://gerrit.osmocom.org/c/osmo-bts/+/41658?usp=email )

Change subject: bts-trx: get rid of static variables in trx_if_send_burst()
......................................................................

bts-trx: get rid of static variables in trx_if_send_burst()

Change-Id: I431964d6fe02e53771cc0514ac930348f0a86aa1
Related: OS#1579
---
M src/osmo-bts-trx/l1_if.h
M src/osmo-bts-trx/trx_if.c
2 files changed, 28 insertions(+), 22 deletions(-)

Approvals:
  laforge: Looks good to me, but someone else must approve
  pespin: Looks good to me, approved
  osmith: Looks good to me, but someone else must approve
  Jenkins Builder: Verified




diff --git a/src/osmo-bts-trx/l1_if.h b/src/osmo-bts-trx/l1_if.h
index 7cc82ad..0180499 100644
--- a/src/osmo-bts-trx/l1_if.h
+++ b/src/osmo-bts-trx/l1_if.h
@@ -126,6 +126,13 @@
        /* Whether the l1h->trx_ctrl_list was flushed by the callback handling 
a received message */
        bool                    flushed_while_in_trx_ctrl_read_cb;

+       struct {
+               /* the Tx buffer used by trx_if_send_burst() */
+               struct msgb     *sndbuf;
+               /* number of PDUs in the Tx buffer */
+               unsigned int    sndbuf_num_pdus;
+       } data;
+
        //struct gsm_bts_trx    *trx;
        struct phy_instance     *phy_inst;

diff --git a/src/osmo-bts-trx/trx_if.c b/src/osmo-bts-trx/trx_if.c
index 8b57aba..5f32360 100644
--- a/src/osmo-bts-trx/trx_if.c
+++ b/src/osmo-bts-trx/trx_if.c
@@ -1120,9 +1120,8 @@
 int trx_if_send_burst(struct trx_l1h *l1h, const struct trx_dl_burst_req *br)
 {
        uint8_t pdu_ver = l1h->config.trxd_pdu_ver_use;
-       static struct msgb *trx_data_last_msg = NULL;
-       static unsigned int pdu_num = 0;
-       uint8_t *buf;
+       struct msgb *sndbuf = NULL;
+       uint8_t *buf = NULL;
        int rc;

        /* Make sure that the PHY is powered on */
@@ -1132,33 +1131,33 @@
                return -ENODEV;
        }

-       if (!trx_data_last_msg) {
-               trx_data_last_msg = msgb_alloc(TRXD_MSG_BUF_SIZE, "tx_trxd");
-               OSMO_ASSERT(trx_data_last_msg);
-               buf = msgb_data(trx_data_last_msg);
+       if (l1h->data.sndbuf == NULL) {
+               l1h->data.sndbuf = msgb_alloc_c(l1h, TRXD_MSG_BUF_SIZE, 
"tx_trxd");
+               OSMO_ASSERT(l1h->data.sndbuf);
        }
+       sndbuf = l1h->data.sndbuf;

        /* Burst batching breaker */
        if (br == NULL) {
-               if (pdu_num > 0)
+               if (l1h->data.sndbuf_num_pdus > 0)
                        goto sendall;
                return -ENOMSG;
        }

-       /* l2h holds Pointer to the last encoded PDU */
-       trx_data_last_msg->l2h = trx_data_last_msg->tail;
+       /* l2h points to the last encoded PDU */
+       sndbuf->l2h = sndbuf->tail;

        switch (pdu_ver) {
        /* Both versions have the same PDU format */
        case 0: /* TRXDv0 */
        case 1: /* TRXDv1 */
-               buf = (uint8_t *)msgb_put(trx_data_last_msg, 6);
+               buf = (uint8_t *)msgb_put(sndbuf, 6);
                buf[0] = ((pdu_ver & 0x0f) << 4) | br->tn;
                osmo_store32be(br->fn, buf + 1);
                buf[5] = br->att;
                break;
        case 2: /* TRXDv2 */
-               buf = (uint8_t *)msgb_put(trx_data_last_msg, 8);
+               buf = (uint8_t *)msgb_put(sndbuf, 8);
                buf[0] = br->tn;
                /* BATCH.ind will be unset in the last PDU */
                buf[1] = (br->trx_num & 0x3f) | (1 << 7);
@@ -1169,9 +1168,9 @@
                buf[4] = (uint8_t) br->scpir;
                buf[5] = buf[6] = buf[7] = 0x00; /* Spare */
                /* Some fields are not present in batched PDUs */
-               if (pdu_num == 0) {
+               if (l1h->data.sndbuf_num_pdus == 0) {
                        buf[0] |= (pdu_ver & 0x0f) << 4;
-                       msgb_put_u32(trx_data_last_msg, br->fn);
+                       msgb_put_u32(sndbuf, br->fn);
                }
                break;
        default:
@@ -1180,10 +1179,10 @@
        }

        /* copy ubits {0,1} */
-       memcpy(msgb_put(trx_data_last_msg, br->burst_len), br->burst, 
br->burst_len);
+       memcpy(msgb_put(sndbuf, br->burst_len), br->burst, br->burst_len);

        /* One more PDU in the buffer */
-       pdu_num++;
+       l1h->data.sndbuf_num_pdus++;

        /* TRXDv2: wait for the batching breaker */
        if (pdu_ver >= 2)
@@ -1192,23 +1191,23 @@
 sendall:
        LOGPPHI(l1h->phy_inst, DTRX, LOGL_DEBUG,
                "Tx TRXDv%u datagram with %u PDU(s)\n",
-               pdu_ver, pdu_num);
+               pdu_ver, l1h->data.sndbuf_num_pdus);

        /* TRXDv2: unset BATCH.ind in the last PDU */
        if (pdu_ver >= 2)
-               trx_data_last_msg->l2h[1] &= ~(1 << 7);
+               sndbuf->l2h[1] &= ~(1 << 7);

-       rc = osmo_iofd_write_msgb(l1h->trx_data_iofd, trx_data_last_msg);
+       rc = osmo_iofd_write_msgb(l1h->trx_data_iofd, sndbuf);
        if (OSMO_UNLIKELY(rc < 0)) {
                char errbuf[256];
                strerror_r(errno, errbuf, sizeof(errbuf));
                LOGPPHI(l1h->phy_inst, DTRX, LOGL_ERROR,
                        "osmo_iofd_write_msgb() failed on TRXD with rc=%d 
(%s)\n",
                        rc, errbuf);
-               msgb_free(trx_data_last_msg);
+               msgb_free(sndbuf);
        }
-       trx_data_last_msg = NULL;
-       pdu_num = 0;
+       l1h->data.sndbuf = NULL;
+       l1h->data.sndbuf_num_pdus = 0;

        return 0;
 }

--
To view, visit https://gerrit.osmocom.org/c/osmo-bts/+/41658?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.osmocom.org/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Change-Id: I431964d6fe02e53771cc0514ac930348f0a86aa1
Gerrit-Change-Number: 41658
Gerrit-PatchSet: 5
Gerrit-Owner: fixeria <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <[email protected]>
Gerrit-Reviewer: osmith <[email protected]>
Gerrit-Reviewer: pespin <[email protected]>

Reply via email to