Skip to content

Commit eeae945

Browse files
andreasmuellerrettichschnidi
authored andcommitted
[sg noup] net: ppp: delay PPP thread after receiving a packet
This is a simple way to create back-pressure towards Linux. A better approach might be to have a separate network queue for PPP and delay while there is already a packet in the queue. This is currently not supported by the Zephyr network queue API (there is no method to check how many packets are currently in the queue), and would also require a bit of cleanup in the lb_radio driver (correctly handle getting a new packet from PPP while receiving or starting to receive a packet via Lemonbeat). Note regarding the defaults: - 100 ms fixed delay is meant to accommodate for sending ACKs & general overhead such as sending the preamble (2x 17.6 ms for packet & ACK, another 2x 17.6 ms if a reply is sent). - The 400 μs variable delay is meant to allow for transmission of the data over UART (around 70 μs per byte at 115200 bps), over the air using Lemonbeat (80 μs per byte at 100 kbps), and sending an equally large packet back. Although a value of 300 μs should be sufficient, experiments show that when testing with large packets and short intervals (1450 bytes, 100 ms interval), only 1-2 out of 3 pings get through; with a per byte delay of 400 μs, all 3 pings get through. Issue: SG-21138 (cherry picked from commit e49c0f5)
1 parent c23af30 commit eeae945

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

drivers/net/Kconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,20 @@ config NET_PPP_RX_PRIORITY
6969
help
7070
Sets the priority of the RX workqueue thread.
7171

72+
config NET_PPP_RX_DELAY_FIXED_MS
73+
int "Fixed PPP RX thread delay in ms"
74+
default 100
75+
help
76+
Fixed delay before reading next byte in PPP RX thread after sucessfully receiving a
77+
packet.
78+
79+
config NET_PPP_RX_DELAY_PER_BYTE_US
80+
int "Per-byte PPP RX thread delay in μs"
81+
default 400
82+
help
83+
Per-byte delay before reading next byte in PPP RX thread after sucessfully receiving a
84+
packet.
85+
7286
config NET_PPP_VERIFY_FCS
7387
bool "Verify that received FCS is valid"
7488
default y

drivers/net/ppp.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ BUILD_ASSERT(UART_YIELD_INTERVAL_BYTES * 8 * 1000 /
5353

5454
#define RX_RINGBUF_MIN_SPACE CONFIG_NET_PPP_RINGBUF_MIN_SPACE
5555

56+
/* delay after successfully receiving a packet via PPP (to give lb_radio time to send it) */
57+
#define NET_RECV_DELAY_FIXED_MS CONFIG_NET_PPP_RX_DELAY_FIXED_MS
58+
#define NET_RECV_DELAY_PER_BYTE_US CONFIG_NET_PPP_RX_DELAY_PER_BYTE_US
59+
5660
enum ppp_driver_state {
5761
STATE_HDLC_FRAME_START,
5862
STATE_HDLC_FRAME_ADDRESS,
@@ -666,8 +670,17 @@ static void ppp_process_msg(struct ppp_driver_context *ppp)
666670
net_pkt_cursor_init(ppp->pkt);
667671
net_pkt_set_overwrite(ppp->pkt, true);
668672

673+
size_t size = net_pkt_get_len(ppp->pkt);
674+
uint32_t delay_ms =
675+
NET_RECV_DELAY_FIXED_MS + size * NET_RECV_DELAY_PER_BYTE_US / 1000;
669676
if (net_recv_data(ppp->iface, ppp->pkt) < 0) {
670677
net_pkt_unref(ppp->pkt);
678+
} else {
679+
if (delay_ms > 0) {
680+
LOG_DBG("PPP received pkt (%d bytes); sleeping for %d ms",
681+
size, delay_ms);
682+
k_msleep(delay_ms);
683+
}
671684
}
672685
}
673686
}

0 commit comments

Comments
 (0)