aboutsummaryrefslogtreecommitdiff
path: root/sys/net/if.c
diff options
context:
space:
mode:
authorHans Petter Selasky <hselasky@FreeBSD.org>2019-10-15 12:08:09 +0000
committerHans Petter Selasky <hselasky@FreeBSD.org>2019-10-15 12:08:09 +0000
commit270b83b9d1f0b390705999d0da9940ab6fbabcf7 (patch)
tree75048b21a5ff4cc0e03112feede02212869333ee /sys/net/if.c
parent93cfeb0ed9d94bc3a86381ef9917cff7a64dda54 (diff)
downloadsrc-270b83b9d1f0b390705999d0da9940ab6fbabcf7.tar.gz
src-270b83b9d1f0b390705999d0da9940ab6fbabcf7.zip
The two functions ifnet_byindex() and ifnet_byindex_locked() are exactly the
same after the network stack was epochified. Merge the two into one function and cleanup all uses of ifnet_byindex_locked(). While at it: - Add branch prediction macros. - Make sure the ifnet pointer is only deferred once, also when code optimisation is disabled. Sponsored by: Mellanox Technologies
Notes
Notes: svn path=/head/; revision=353550
Diffstat (limited to 'sys/net/if.c')
-rw-r--r--sys/net/if.c24
1 files changed, 8 insertions, 16 deletions
diff --git a/sys/net/if.c b/sys/net/if.c
index 88c759fb4643..7f261633c012 100644
--- a/sys/net/if.c
+++ b/sys/net/if.c
@@ -329,23 +329,15 @@ MALLOC_DEFINE(M_IFADDR, "ifaddr", "interface address");
MALLOC_DEFINE(M_IFMADDR, "ether_multi", "link-level multicast address");
struct ifnet *
-ifnet_byindex_locked(u_short idx)
-{
-
- if (idx > V_if_index)
- return (NULL);
- if (V_ifindex_table[idx] == IFNET_HOLD)
- return (NULL);
- return (V_ifindex_table[idx]);
-}
-
-struct ifnet *
ifnet_byindex(u_short idx)
{
struct ifnet *ifp;
- ifp = ifnet_byindex_locked(idx);
- return (ifp);
+ if (__predict_false(idx > V_if_index))
+ return (NULL);
+
+ ifp = *(struct ifnet * const volatile *)(V_ifindex_table + idx);
+ return (__predict_false(ifp == IFNET_HOLD) ? NULL : ifp);
}
struct ifnet *
@@ -355,7 +347,7 @@ ifnet_byindex_ref(u_short idx)
NET_EPOCH_ASSERT();
- ifp = ifnet_byindex_locked(idx);
+ ifp = ifnet_byindex(idx);
if (ifp == NULL || (ifp->if_flags & IFF_DYING))
return (NULL);
if_ref(ifp);
@@ -427,7 +419,7 @@ ifaddr_byindex(u_short idx)
NET_EPOCH_ASSERT();
- ifp = ifnet_byindex_locked(idx);
+ ifp = ifnet_byindex(idx);
if (ifp != NULL && (ifa = ifp->if_addr) != NULL)
ifa_ref(ifa);
return (ifa);
@@ -653,7 +645,7 @@ if_free(struct ifnet *ifp)
CURVNET_SET_QUIET(ifp->if_vnet);
IFNET_WLOCK();
- KASSERT(ifp == ifnet_byindex_locked(ifp->if_index),
+ KASSERT(ifp == ifnet_byindex(ifp->if_index),
("%s: freeing unallocated ifnet", ifp->if_xname));
ifindex_free_locked(ifp->if_index);