From owner-svn-src-head@freebsd.org Thu May 3 17:02:32 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A7474FB20A8; Thu, 3 May 2018 17:02:32 +0000 (UTC) (envelope-from shurd@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 2D0B57249C; Thu, 3 May 2018 17:02:32 +0000 (UTC) (envelope-from shurd@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 27FD022A5A; Thu, 3 May 2018 17:02:32 +0000 (UTC) (envelope-from shurd@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w43H2WV9090783; Thu, 3 May 2018 17:02:32 GMT (envelope-from shurd@FreeBSD.org) Received: (from shurd@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w43H2VkE090781; Thu, 3 May 2018 17:02:31 GMT (envelope-from shurd@FreeBSD.org) Message-Id: <201805031702.w43H2VkE090781@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: shurd set sender to shurd@FreeBSD.org using -f From: Stephen Hurd Date: Thu, 3 May 2018 17:02:31 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r333218 - head/sys/net X-SVN-Group: head X-SVN-Commit-Author: shurd X-SVN-Commit-Paths: head/sys/net X-SVN-Commit-Revision: 333218 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 03 May 2018 17:02:32 -0000 Author: shurd Date: Thu May 3 17:02:31 2018 New Revision: 333218 URL: https://svnweb.freebsd.org/changeset/base/333218 Log: Allow iflib NIC drivers to sleep rather than busy wait Since the move to SMP NIC driver locking has had to go through serious contortions using mtx around long running hardware operations. This moves iflib past that. Individual drivers may now sleep when appropriate. Submitted by: Matthew Macy Reviewed by: shurd Sponsored by: Limelight Networks Differential Revision: https://reviews.freebsd.org/D14983 Modified: head/sys/net/iflib.c head/sys/net/iflib.h Modified: head/sys/net/iflib.c ============================================================================== --- head/sys/net/iflib.c Thu May 3 16:19:47 2018 (r333217) +++ head/sys/net/iflib.c Thu May 3 17:02:31 2018 (r333218) @@ -163,7 +163,7 @@ struct iflib_ctx { if_shared_ctx_t ifc_sctx; struct if_softc_ctx ifc_softc_ctx; - struct mtx ifc_ctx_mtx; + struct sx ifc_ctx_sx; struct mtx ifc_state_mtx; uint16_t ifc_nhwtxqs; @@ -537,10 +537,10 @@ rxd_info_zero(if_rxd_info_t ri) #define CTX_ACTIVE(ctx) ((if_getdrvflags((ctx)->ifc_ifp) & IFF_DRV_RUNNING)) -#define CTX_LOCK_INIT(_sc, _name) mtx_init(&(_sc)->ifc_ctx_mtx, _name, "iflib ctx lock", MTX_DEF) -#define CTX_LOCK(ctx) mtx_lock(&(ctx)->ifc_ctx_mtx) -#define CTX_UNLOCK(ctx) mtx_unlock(&(ctx)->ifc_ctx_mtx) -#define CTX_LOCK_DESTROY(ctx) mtx_destroy(&(ctx)->ifc_ctx_mtx) +#define CTX_LOCK_INIT(_sc) sx_init(&(_sc)->ifc_ctx_sx, "iflib ctx lock") +#define CTX_LOCK(ctx) sx_xlock(&(ctx)->ifc_ctx_sx) +#define CTX_UNLOCK(ctx) sx_xunlock(&(ctx)->ifc_ctx_sx) +#define CTX_LOCK_DESTROY(ctx) sx_destroy(&(ctx)->ifc_ctx_sx) #define STATE_LOCK_INIT(_sc, _name) mtx_init(&(_sc)->ifc_state_mtx, _name, "iflib state lock", MTX_DEF) @@ -4277,7 +4277,9 @@ iflib_device_register(device_t dev, void *sc, if_share } } + CTX_LOCK(ctx); if ((err = IFDI_ATTACH_PRE(ctx)) != 0) { + CTX_UNLOCK(ctx); device_printf(dev, "IFDI_ATTACH_PRE failed %d\n", err); return (err); } @@ -4435,6 +4437,7 @@ iflib_device_register(device_t dev, void *sc, if_share if_setgetcounterfn(ctx->ifc_ifp, iflib_if_get_counter); iflib_add_device_sysctl_post(ctx); ctx->ifc_flags |= IFC_INIT_DONE; + CTX_UNLOCK(ctx); return (0); fail_detach: ether_ifdetach(ctx->ifc_ifp); @@ -4445,6 +4448,7 @@ fail_queues: /* XXX free queues */ fail: IFDI_DETACH(ctx); + CTX_UNLOCK(ctx); return (err); } @@ -4711,8 +4715,7 @@ iflib_register(if_ctx_t ctx) _iflib_assert(sctx); - CTX_LOCK_INIT(ctx, device_get_nameunit(ctx->ifc_dev)); - + CTX_LOCK_INIT(ctx); STATE_LOCK_INIT(ctx, device_get_nameunit(ctx->ifc_dev)); ifp = ctx->ifc_ifp = if_gethandle(IFT_ETHER); if (ifp == NULL) { @@ -5457,8 +5460,8 @@ iflib_io_tqg_attach(struct grouptask *gt, void *uniq, } void -iflib_config_gtask_init(if_ctx_t ctx, struct grouptask *gtask, gtask_fn_t *fn, - char *name) +iflib_config_gtask_init(void *ctx, struct grouptask *gtask, gtask_fn_t *fn, + const char *name) { GROUPTASK_INIT(gtask, 0, fn, ctx); @@ -5538,11 +5541,11 @@ iflib_add_int_delay_sysctl(if_ctx_t ctx, const char *n info, 0, iflib_sysctl_int_delay, "I", description); } -struct mtx * +struct sx * iflib_ctx_lock_get(if_ctx_t ctx) { - return (&ctx->ifc_ctx_mtx); + return (&ctx->ifc_ctx_sx); } static int Modified: head/sys/net/iflib.h ============================================================================== --- head/sys/net/iflib.h Thu May 3 16:19:47 2018 (r333217) +++ head/sys/net/iflib.h Thu May 3 17:02:31 2018 (r333218) @@ -373,8 +373,8 @@ void iflib_irq_free(if_ctx_t ctx, if_irq_t irq); void iflib_io_tqg_attach(struct grouptask *gt, void *uniq, int cpu, char *name); -void iflib_config_gtask_init(if_ctx_t ctx, struct grouptask *gtask, - gtask_fn_t *fn, char *name); +void iflib_config_gtask_init(void *ctx, struct grouptask *gtask, + gtask_fn_t *fn, const char *name); void iflib_config_gtask_deinit(struct grouptask *gtask); @@ -396,7 +396,7 @@ int iflib_dma_alloc_multi(if_ctx_t ctx, int *sizes, if void iflib_dma_free_multi(iflib_dma_info_t *dmalist, int count); -struct mtx *iflib_ctx_lock_get(if_ctx_t); +struct sx *iflib_ctx_lock_get(if_ctx_t); struct mtx *iflib_qset_lock_get(if_ctx_t, uint16_t); void iflib_led_create(if_ctx_t ctx);