Change in osmo-bts[master]: osmo-bts-trx: enlarge and share TRXD message buffer

fixeria gerrit-no-reply at lists.osmocom.org
Thu Apr 22 15:25:33 UTC 2021


fixeria has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-bts/+/23865 )


Change subject: osmo-bts-trx: enlarge and share TRXD message buffer
......................................................................

osmo-bts-trx: enlarge and share TRXD message buffer

Starting from TRXDv2, several PDUs may be batched together and sent in
all together a single datagram.  This requires us to increase the buffer
size that we use for sending and receiving TRXD messages.  Let's use
65536 matching the default MTU value for 'lo' interface on Linux.

Given that 65536 is quite a big number, let's allocate a shared Rx/Tx
buffer statically to avoid [potential] stack overflow.

Change-Id: I729451c8ecdc7ff2631beb423f15523db16b3ee3
Related: SYS#4895, OS#4941, OS#4006
---
M src/osmo-bts-trx/trx_if.c
M src/osmo-bts-trx/trx_if.h
2 files changed, 23 insertions(+), 18 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/65/23865/1

diff --git a/src/osmo-bts-trx/trx_if.c b/src/osmo-bts-trx/trx_if.c
index 8169f8f..30c74dd 100644
--- a/src/osmo-bts-trx/trx_if.c
+++ b/src/osmo-bts-trx/trx_if.c
@@ -902,20 +902,24 @@
 	return buf;
 }
 
+/* TRXD buffer used by Rx/Tx handlers */
+static uint8_t trx_data_buf[TRXD_MSG_BUF_SIZE];
+
 /* Parse TRXD message from transceiver, compose an UL burst indication. */
 static int trx_data_read_cb(struct osmo_fd *ofd, unsigned int what)
 {
+	const uint8_t *ptr = &trx_data_buf[0];
 	struct trx_l1h *l1h = ofd->data;
-	uint8_t buf[TRXD_MSG_BUF_SIZE];
 	struct trx_ul_burst_ind bi;
 	ssize_t hdr_len, buf_len;
 	uint8_t pdu_ver;
 
-	buf_len = recv(ofd->fd, buf, sizeof(buf), 0);
+	buf_len = recv(ofd->fd, trx_data_buf, sizeof(trx_data_buf), 0);
 	if (buf_len <= 0) {
-		strerror_r(errno, (char *)buf, sizeof(buf));
+		strerror_r(errno, (char *) trx_data_buf, sizeof(trx_data_buf));
 		LOGPPHI(l1h->phy_inst, DTRX, LOGL_ERROR,
-			"recv() failed on TRXD with rc=%zd (%s)\n", buf_len, buf);
+			"recv() failed on TRXD with rc=%zd (%s)\n",
+			buf_len, trx_data_buf);
 		return buf_len;
 	}
 
@@ -923,7 +927,7 @@
 	bi.flags = 0x00;
 
 	/* Parse PDU version first */
-	pdu_ver = buf[0] >> 4;
+	pdu_ver = ptr[0] >> 4;
 
 	/* Make sure that PDU version matches our expectations */
 	if (pdu_ver != l1h->config.trxd_pdu_ver_use) {
@@ -944,10 +948,10 @@
 	/* Parse header depending on the PDU version */
 	switch (pdu_ver) {
 	case 0: /* TRXDv0 */
-		hdr_len = trx_data_handle_hdr_v0(l1h->phy_inst, &bi, buf, buf_len);
+		hdr_len = trx_data_handle_hdr_v0(l1h->phy_inst, &bi, ptr, buf_len);
 		break;
 	case 1: /* TRXDv1 */
-		hdr_len = trx_data_handle_hdr_v1(l1h->phy_inst, &bi, buf, buf_len);
+		hdr_len = trx_data_handle_hdr_v1(l1h->phy_inst, &bi, ptr, buf_len);
 		break;
 	default:
 		/* Shall not happen */
@@ -969,7 +973,7 @@
 	buf_len -= hdr_len;
 
 	/* Calculate burst length and parse it (if present) */
-	if (trx_data_handle_burst(&bi, buf + hdr_len, buf_len) != 0) {
+	if (trx_data_handle_burst(&bi, ptr + hdr_len, buf_len) != 0) {
 		LOGPPHI(l1h->phy_inst, DTRX, LOGL_ERROR,
 			"Rx malformed TRXDv%u PDU: odd burst length=%zd\n",
 			pdu_ver, buf_len);
@@ -995,7 +999,7 @@
 {
 	ssize_t snd_len;
 	uint8_t pdu_ver = l1h->config.trxd_pdu_ver_use;
-	uint8_t buf[TRXD_MSG_BUF_SIZE];
+	uint8_t *ptr = &trx_data_buf[0];
 
 	if ((br->burst_len != GSM_BURST_LEN) && (br->burst_len != EGPRS_BURST_LEN)) {
 		LOGPPHI(l1h->phy_inst, DTRX, LOGL_ERROR, "Tx burst length %zu invalid\n",
@@ -1019,20 +1023,21 @@
 		return -ENOTSUP;
 	}
 
-	buf[0] = ((pdu_ver & 0x0f) << 4) | br->tn;
-	osmo_store32be(br->fn, buf + 1);
-	buf[5] = br->att;
+	ptr[0] = ((pdu_ver & 0x0f) << 4) | br->tn;
+	osmo_store32be(br->fn, ptr + 1);
+	ptr[5] = br->att;
 
 	/* copy ubits {0,1} */
-	memcpy(buf + 6, br->burst, br->burst_len);
+	memcpy(ptr + 6, br->burst, br->burst_len);
 
 	/* we must be sure that TRX is on */
 	if (trx_if_powered(l1h)) {
-		snd_len = send(l1h->trx_ofd_data.fd, buf, br->burst_len + 6, 0);
+		snd_len = send(l1h->trx_ofd_data.fd, trx_data_buf, br->burst_len + 6, 0);
 		if (snd_len <= 0) {
-			strerror_r(errno, (char *)buf, sizeof(buf));
+			strerror_r(errno, (char *) trx_data_buf, sizeof(trx_data_buf));
 			LOGPPHI(l1h->phy_inst, DTRX, LOGL_ERROR,
-				"send() failed on TRXD with rc=%zd (%s)\n", snd_len, buf);
+				"send() failed on TRXD with rc=%zd (%s)\n",
+				snd_len, trx_data_buf);
 			return -2;
 		}
 	} else
diff --git a/src/osmo-bts-trx/trx_if.h b/src/osmo-bts-trx/trx_if.h
index ca3d51b..f40dbb5 100644
--- a/src/osmo-bts-trx/trx_if.h
+++ b/src/osmo-bts-trx/trx_if.h
@@ -2,8 +2,8 @@
 
 /* TRXC read/send buffer size */
 #define TRXC_MSG_BUF_SIZE	1500
-/* TRXD read/send buffer size */
-#define TRXD_MSG_BUF_SIZE	512
+/* TRXD read/send buffer size (max. lo MTU) */
+#define TRXD_MSG_BUF_SIZE	65536
 
 struct trx_dl_burst_req;
 struct trx_l1h;

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

Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Change-Id: I729451c8ecdc7ff2631beb423f15523db16b3ee3
Gerrit-Change-Number: 23865
Gerrit-PatchSet: 1
Gerrit-Owner: fixeria <vyanitskiy at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210422/c6e9664b/attachment.htm>


More information about the gerrit-log mailing list