From owner-svn-src-all@freebsd.org Tue Sep 3 14:08:17 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 98829DDA39; Tue, 3 Sep 2019 14:07:24 +0000 (UTC) (envelope-from yuripv@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [96.47.72.132]) (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 "freefall.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46N80W3XQLz4QYL; Tue, 3 Sep 2019 14:07:23 +0000 (UTC) (envelope-from yuripv@freebsd.org) Received: by freefall.freebsd.org (Postfix, from userid 1452) id B867C1B553; Tue, 3 Sep 2019 14:06:37 +0000 (UTC) X-Original-To: yuripv@localmail.freebsd.org Delivered-To: yuripv@localmail.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mx1.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by freefall.freebsd.org (Postfix) with ESMTPS id CF632153DE; Mon, 22 Apr 2019 19:24:26 +0000 (UTC) (envelope-from owner-src-committers@freebsd.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2610:1c1:1:6074::16:84]) (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 "freefall.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4E49372C3C; Mon, 22 Apr 2019 19:24:26 +0000 (UTC) (envelope-from owner-src-committers@freebsd.org) Received: by freefall.freebsd.org (Postfix, from userid 538) id 25316153A5; Mon, 22 Apr 2019 19:24:26 +0000 (UTC) Delivered-To: src-committers@localmail.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [96.47.72.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client CN "mx1.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by freefall.freebsd.org (Postfix) with ESMTPS id 676D8153A3 for ; Mon, 22 Apr 2019 19:24:23 +0000 (UTC) (envelope-from gallatin@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 1D08272C37; Mon, 22 Apr 2019 19:24:23 +0000 (UTC) (envelope-from gallatin@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 E1C5119724; Mon, 22 Apr 2019 19:24:22 +0000 (UTC) (envelope-from gallatin@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x3MJOMqP000973; Mon, 22 Apr 2019 19:24:22 GMT (envelope-from gallatin@FreeBSD.org) Received: (from gallatin@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x3MJOLOA000964; Mon, 22 Apr 2019 19:24:21 GMT (envelope-from gallatin@FreeBSD.org) Message-Id: <201904221924.x3MJOLOA000964@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: gallatin set sender to gallatin@FreeBSD.org using -f From: Andrew Gallatin To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r346579 - in head: share/man/man9 sys/dev/cxgbe sys/dev/mlx5/mlx5_en sys/net X-SVN-Group: head X-SVN-Commit-Author: gallatin X-SVN-Commit-Paths: in head: share/man/man9 sys/dev/cxgbe sys/dev/mlx5/mlx5_en sys/net X-SVN-Commit-Revision: 346579 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk X-Loop: FreeBSD.org Sender: owner-src-committers@freebsd.org X-Rspamd-Queue-Id: 4E49372C3C X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.96 / 15.00]; local_wl_from(0.00)[freebsd.org]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; NEURAL_HAM_SHORT(-0.96)[-0.965,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] Status: O X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 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: , Date: Tue, 03 Sep 2019 14:08:17 -0000 X-Original-Date: Mon, 22 Apr 2019 19:24:21 +0000 (UTC) X-List-Received-Date: Tue, 03 Sep 2019 14:08:17 -0000 Author: gallatin Date: Mon Apr 22 19:24:21 2019 New Revision: 346579 URL: https://svnweb.freebsd.org/changeset/base/346579 Log: Track device's NUMA domain in ifnet & alloc ifnet from NUMA local memory This commit adds new if_alloc_domain() and if_alloc_dev() methods to allocate ifnets. When called with a domain on a NUMA machine, ifalloc_domain() will record the NUMA domain in the ifnet, and it will allocate the ifnet struct from memory which is local to that NUMA node. Similarly, if_alloc_dev() is a wrapper for if_alloc_domain which uses a driver supplied device_t to call ifalloc_domain() with the appropriate domain. Note that the new if_numa_domain field fits in an alignment pad in struct ifnet, and so does not alter the size of the structure. Reviewed by: glebius, kib, markj Sponsored by: Netflix Differential Revision: https://reviews.freebsd.org/D19930 Modified: head/share/man/man9/Makefile head/share/man/man9/ifnet.9 head/sys/dev/cxgbe/t4_main.c head/sys/dev/mlx5/mlx5_en/mlx5_en_main.c head/sys/net/if.c head/sys/net/if_var.h Modified: head/share/man/man9/Makefile ============================================================================== --- head/share/man/man9/Makefile Mon Apr 22 19:21:35 2019 (r346578) +++ head/share/man/man9/Makefile Mon Apr 22 19:24:21 2019 (r346579) @@ -1175,6 +1175,8 @@ MLINKS+=iflibtxrx.9 isc_rxd_available.9 \ iflibtxrx.9 isc_txd_flush.9 MLINKS+=ifnet.9 if_addmulti.9 \ ifnet.9 if_alloc.9 \ + ifnet.9 if_alloc_dev.9 \ + ifnet.9 if_alloc_domain.9 \ ifnet.9 if_allmulti.9 \ ifnet.9 if_attach.9 \ ifnet.9 if_data.9 \ Modified: head/share/man/man9/ifnet.9 ============================================================================== --- head/share/man/man9/ifnet.9 Mon Apr 22 19:21:35 2019 (r346578) +++ head/share/man/man9/ifnet.9 Mon Apr 22 19:24:21 2019 (r346579) @@ -48,6 +48,10 @@ .Ss "Interface Manipulation Functions" .Ft "struct ifnet *" .Fn if_alloc "u_char type" +.Ft "struct ifnet *" +.Fn if_alloc_dev "u_char type" "device_t dev" +.Ft "struct ifnet *" +.Fn if_alloc_domain "u_char type" "int numa_domain" .Ft void .Fn if_attach "struct ifnet *ifp" .Ft void @@ -440,6 +444,15 @@ It is used to cache the type passed to but unlike .Va if_type , it would not be changed by drivers. +.It Va if_numa_domain +.Pq Vt uint8_t +The NUMA domain of the hardware device associated with the interface. +This is filled in with a wildcard value unless the kernel is NUMA +aware, the system is a NUMA system, and the ifnet is allocated +using +.Fn if_alloc_dev +or +.Fn if_alloc_domain . .El .Pp References to @@ -1151,6 +1164,24 @@ include the allocation of a .Fa type specific structure in .Va if_l2com . +.It Fn if_alloc_dev +Allocate and initialize +.Vt "struct ifnet" +as +.Fn if_alloc +does, with the addition that the ifnet can be tagged with the +appropriate NUMA domain derived from the +.Fa dev +argument passed by the caller. +.It Fn if_alloc_domain +Allocate and initialize +.Vt "struct ifnet" +as +.Fn if_alloc +does, with the addition that the ifnet will be tagged with the NUMA +domain via the +.Fa numa_domain +argument passed by the caller. .It Fn if_attach Link the specified interface .Fa ifp @@ -1168,7 +1199,10 @@ function.) The .Fa ifp must have been allocated by -.Fn if_alloc . +.Fn if_alloc , +.Fn if_alloc_dev +or +.Fn if_alloc_domain . .It Fn if_detach Shut down and unlink the specified .Fa ifp Modified: head/sys/dev/cxgbe/t4_main.c ============================================================================== --- head/sys/dev/cxgbe/t4_main.c Mon Apr 22 19:21:35 2019 (r346578) +++ head/sys/dev/cxgbe/t4_main.c Mon Apr 22 19:24:21 2019 (r346579) @@ -1636,7 +1636,7 @@ cxgbe_vi_attach(device_t dev, struct vi_info *vi) callout_init(&vi->tick, 1); /* Allocate an ifnet and set it up */ - ifp = if_alloc(IFT_ETHER); + ifp = if_alloc_dev(IFT_ETHER, dev); if (ifp == NULL) { device_printf(dev, "Cannot allocate ifnet\n"); return (ENOMEM); Modified: head/sys/dev/mlx5/mlx5_en/mlx5_en_main.c ============================================================================== --- head/sys/dev/mlx5/mlx5_en/mlx5_en_main.c Mon Apr 22 19:21:35 2019 (r346578) +++ head/sys/dev/mlx5/mlx5_en/mlx5_en_main.c Mon Apr 22 19:24:21 2019 (r346579) @@ -3682,7 +3682,7 @@ mlx5e_create_ifp(struct mlx5_core_dev *mdev) M_MLX5EN, M_WAITOK | M_ZERO); mlx5e_priv_mtx_init(priv); - ifp = priv->ifp = if_alloc(IFT_ETHER); + ifp = priv->ifp = if_alloc_dev(IFT_ETHER, mdev->pdev->dev.bsddev); if (ifp == NULL) { mlx5_core_err(mdev, "if_alloc() failed\n"); goto err_free_priv; Modified: head/sys/net/if.c ============================================================================== --- head/sys/net/if.c Mon Apr 22 19:21:35 2019 (r346578) +++ head/sys/net/if.c Mon Apr 22 19:24:21 2019 (r346579) @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -526,13 +527,19 @@ if_grow(void) * registered for the passed type. */ struct ifnet * -if_alloc(u_char type) +if_alloc_domain(u_char type, int numa_domain) { struct ifnet *ifp; u_short idx; void *old; - ifp = malloc(sizeof(struct ifnet), M_IFNET, M_WAITOK|M_ZERO); + KASSERT(numa_domain <= IF_NODOM, ("numa_domain too large")); + if (numa_domain == IF_NODOM) + ifp = malloc(sizeof(struct ifnet), M_IFNET, + M_WAITOK | M_ZERO); + else + ifp = malloc_domainset(sizeof(struct ifnet), M_IFNET, + DOMAINSET_PREF(numa_domain), M_WAITOK | M_ZERO); restart: IFNET_WLOCK(); idx = ifindex_alloc(&old); @@ -547,6 +554,7 @@ if_alloc(u_char type) ifp->if_index = idx; ifp->if_type = type; ifp->if_alloctype = type; + ifp->if_numa_domain = numa_domain; #ifdef VIMAGE ifp->if_vnet = curvnet; #endif @@ -580,6 +588,22 @@ if_alloc(u_char type) return (ifp); } +struct ifnet * +if_alloc_dev(u_char type, device_t dev) +{ + int numa_domain; + + if (dev == NULL || bus_get_domain(dev, &numa_domain) != 0) + return (if_alloc_domain(type, IF_NODOM)); + return (if_alloc_domain(type, numa_domain)); +} + +struct ifnet * +if_alloc(u_char type) +{ + + return (if_alloc_domain(type, IF_NODOM)); +} /* * Do the actual work of freeing a struct ifnet, and layer 2 common * structure. This call is made when the last reference to an @@ -608,7 +632,10 @@ if_free_internal(struct ifnet *ifp) free(ifp->if_description, M_IFDESCR); free(ifp->if_hw_addr, M_IFADDR); - free(ifp, M_IFNET); + if (ifp->if_numa_domain == IF_NODOM) + free(ifp, M_IFNET); + else + free_domain(ifp, M_IFNET); } static void Modified: head/sys/net/if_var.h ============================================================================== --- head/sys/net/if_var.h Mon Apr 22 19:21:35 2019 (r346578) +++ head/sys/net/if_var.h Mon Apr 22 19:24:21 2019 (r346579) @@ -244,7 +244,7 @@ struct ifnet { CK_STAILQ_HEAD(, ifg_list) if_groups; /* linked list of groups per if (CK_) */ /* protected by if_addr_lock */ u_char if_alloctype; /* if_type at time of allocation */ - + uint8_t if_numa_domain; /* NUMA domain of device */ /* Driver and protocol specific information that remains stable. */ void *if_softc; /* pointer to driver state */ void *if_llsoftc; /* link layer softc */ @@ -394,6 +394,7 @@ struct ifnet { /* for compatibility with other BSDs */ #define if_name(ifp) ((ifp)->if_xname) +#define IF_NODOM 255 /* * Locks for address lists on the network interface. */ @@ -622,6 +623,8 @@ int if_delgroup(struct ifnet *, const char *); int if_addmulti(struct ifnet *, struct sockaddr *, struct ifmultiaddr **); int if_allmulti(struct ifnet *, int); struct ifnet* if_alloc(u_char); +struct ifnet* if_alloc_dev(u_char, device_t dev); +struct ifnet* if_alloc_domain(u_char, int numa_domain); void if_attach(struct ifnet *); void if_dead(struct ifnet *); int if_delmulti(struct ifnet *, struct sockaddr *);