svn commit: r353550 - head/sys/net
Hans Petter Selasky
hselasky at FreeBSD.org
Tue Oct 15 12:08:10 UTC 2019
Author: hselasky
Date: Tue Oct 15 12:08:09 2019
New Revision: 353550
URL: https://svnweb.freebsd.org/changeset/base/353550
Log:
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
Modified:
head/sys/net/if.c
head/sys/net/if_var.h
head/sys/net/route.c
Modified: head/sys/net/if.c
==============================================================================
--- head/sys/net/if.c Tue Oct 15 11:20:16 2019 (r353549)
+++ head/sys/net/if.c Tue Oct 15 12:08:09 2019 (r353550)
@@ -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);
Modified: head/sys/net/if_var.h
==============================================================================
--- head/sys/net/if_var.h Tue Oct 15 11:20:16 2019 (r353549)
+++ head/sys/net/if_var.h Tue Oct 15 12:08:09 2019 (r353550)
@@ -629,7 +629,6 @@ extern struct sx ifnet_sxlock;
* to call ifnet_byindex() instead of ifnet_byindex_ref().
*/
struct ifnet *ifnet_byindex(u_short idx);
-struct ifnet *ifnet_byindex_locked(u_short idx);
struct ifnet *ifnet_byindex_ref(u_short idx);
/*
Modified: head/sys/net/route.c
==============================================================================
--- head/sys/net/route.c Tue Oct 15 11:20:16 2019 (r353549)
+++ head/sys/net/route.c Tue Oct 15 12:08:09 2019 (r353550)
@@ -1293,7 +1293,7 @@ rt_getifa_fib(struct rt_addrinfo *info, u_int fibnum)
ifpaddr->sa_family == AF_LINK) {
const struct sockaddr_dl *sdl = (const struct sockaddr_dl *)ifpaddr;
if (sdl->sdl_index != 0)
- info->rti_ifp = ifnet_byindex_locked(sdl->sdl_index);
+ info->rti_ifp = ifnet_byindex(sdl->sdl_index);
}
/*
* If we have source address specified, try to find it
More information about the svn-src-all
mailing list