aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Petter Selasky <hselasky@FreeBSD.org>2020-06-18 10:31:21 +0000
committerHans Petter Selasky <hselasky@FreeBSD.org>2020-06-18 10:31:21 +0000
commite5fce44e5127a0f7454203b837487cf86986fc55 (patch)
tree28fa94402668c71e0d736f0d2f3c2885ae52fa56
parent73356f025754fa313d4aab17a2afc0acc41e9c0d (diff)
downloadsrc-e5fce44e5127a0f7454203b837487cf86986fc55.tar.gz
src-e5fce44e5127a0f7454203b837487cf86986fc55.zip
MFC r362044:
Extend use of unlikely() in the fast path, in mlx5en(4). Typically the TCP/IP headers fit within the first mbuf and should not trigger any of the error cases. Use unlikely() for these cases. No functional change. Sponsored by: Mellanox Technologies
Notes
Notes: svn path=/stable/10/; revision=362310
-rw-r--r--sys/dev/mlx5/mlx5_en/mlx5_en_tx.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/sys/dev/mlx5/mlx5_en/mlx5_en_tx.c b/sys/dev/mlx5/mlx5_en/mlx5_en_tx.c
index 92a5ad6968ce..7040e724a03a 100644
--- a/sys/dev/mlx5/mlx5_en/mlx5_en_tx.c
+++ b/sys/dev/mlx5/mlx5_en/mlx5_en_tx.c
@@ -196,21 +196,21 @@ mlx5e_get_header_size(const struct mbuf *mb)
int eth_hdr_len;
eh = mtod(mb, const struct ether_vlan_header *);
- if (mb->m_len < ETHER_HDR_LEN)
+ if (unlikely(mb->m_len < ETHER_HDR_LEN))
return (0);
if (eh->evl_encap_proto == htons(ETHERTYPE_VLAN)) {
+ if (unlikely(mb->m_len < (ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN)))
+ return (0);
eth_type = ntohs(eh->evl_proto);
eth_hdr_len = ETHER_HDR_LEN + ETHER_VLAN_ENCAP_LEN;
} else {
eth_type = ntohs(eh->evl_encap_proto);
eth_hdr_len = ETHER_HDR_LEN;
}
- if (mb->m_len < eth_hdr_len)
- return (0);
switch (eth_type) {
case ETHERTYPE_IP:
ip = (const struct ip *)(mb->m_data + eth_hdr_len);
- if (mb->m_len < eth_hdr_len + sizeof(*ip))
+ if (unlikely(mb->m_len < eth_hdr_len + sizeof(*ip)))
return (0);
if (ip->ip_p != IPPROTO_TCP)
return (0);
@@ -219,7 +219,7 @@ mlx5e_get_header_size(const struct mbuf *mb)
break;
case ETHERTYPE_IPV6:
ip6 = (const struct ip6_hdr *)(mb->m_data + eth_hdr_len);
- if (mb->m_len < eth_hdr_len + sizeof(*ip6))
+ if (unlikely(mb->m_len < eth_hdr_len + sizeof(*ip6)))
return (0);
if (ip6->ip6_nxt != IPPROTO_TCP)
return (0);
@@ -228,12 +228,17 @@ mlx5e_get_header_size(const struct mbuf *mb)
default:
return (0);
}
- if (mb->m_len < eth_hdr_len + sizeof(*th))
+ if (unlikely(mb->m_len < eth_hdr_len + sizeof(*th)))
return (0);
th = (const struct tcphdr *)(mb->m_data + eth_hdr_len);
tcp_hlen = th->th_off << 2;
eth_hdr_len += tcp_hlen;
- if (mb->m_len < eth_hdr_len)
+ /*
+ * m_copydata() will be used on the remaining header which
+ * does not need to reside within the first m_len bytes of
+ * data:
+ */
+ if (unlikely(mb->m_pkthdr.len < eth_hdr_len))
return (0);
return (eth_hdr_len);
}