From owner-svn-src-all@freebsd.org Tue Oct 15 12:08:10 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 92C5115D150; Tue, 15 Oct 2019 12:08:10 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46svMZ3Pvwz46xF; Tue, 15 Oct 2019 12:08:10 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 587761E495; Tue, 15 Oct 2019 12:08:10 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x9FC8AYR023093; Tue, 15 Oct 2019 12:08:10 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x9FC89b8023090; Tue, 15 Oct 2019 12:08:09 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201910151208.x9FC89b8023090@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Tue, 15 Oct 2019 12:08:09 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r353550 - head/sys/net X-SVN-Group: head X-SVN-Commit-Author: hselasky X-SVN-Commit-Paths: head/sys/net X-SVN-Commit-Revision: 353550 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Oct 2019 12:08:10 -0000 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