Skip to content

Commit 3cc1a6e

Browse files
Krishna Tcarlescufi
authored andcommitted
drivers: net: loopback: Optimize packet drop
If we are dropping packets, then drop then early without the clone, this improves zperf performance. Signed-off-by: Krishna T <[email protected]>
1 parent 3b2243d commit 3cc1a6e

File tree

1 file changed

+13
-18
lines changed

1 file changed

+13
-18
lines changed

drivers/net/loopback.c

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,19 @@ static int loopback_send(const struct device *dev, struct net_pkt *pkt)
8989

9090
ARG_UNUSED(dev);
9191

92+
#ifdef CONFIG_NET_LOOPBACK_SIMULATE_PACKET_DROP
93+
/* Drop packets based on the loopback_packet_drop_ratio
94+
* a ratio of 0.2 will drop one every 5 packets
95+
*/
96+
loopback_packet_drop_state += loopback_packet_drop_ratio;
97+
if (loopback_packet_drop_state >= 1.0f) {
98+
/* Administrate we dropped a packet */
99+
loopback_packet_drop_state -= 1.0f;
100+
loopback_packet_dropped_count++;
101+
return 0;
102+
}
103+
#endif
104+
92105
if (!pkt->frags) {
93106
LOG_ERR("No data to send");
94107
return -ENODATA;
@@ -125,24 +138,6 @@ static int loopback_send(const struct device *dev, struct net_pkt *pkt)
125138
goto out;
126139
}
127140

128-
#ifdef CONFIG_NET_LOOPBACK_SIMULATE_PACKET_DROP
129-
/* Drop packets based on the loopback_packet_drop_ratio
130-
* a ratio of 0.2 will drop one every 5 packets
131-
*/
132-
loopback_packet_drop_state += loopback_packet_drop_ratio;
133-
if (loopback_packet_drop_state >= 1.0f) {
134-
/* Administrate we dropped a packet */
135-
loopback_packet_drop_state -= 1.0f;
136-
loopback_packet_dropped_count++;
137-
138-
/* Clean up the packet */
139-
net_pkt_unref(cloned);
140-
/* Pretend everything was fine */
141-
res = 0;
142-
143-
goto out;
144-
}
145-
#endif
146141
res = net_recv_data(net_pkt_iface(cloned), cloned);
147142
if (res < 0) {
148143
LOG_ERR("Data receive failed.");

0 commit comments

Comments
 (0)