Date: Thu, 3 May 2018 17:02:31 +0000 (UTC) From: Stephen Hurd <shurd@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r333218 - head/sys/net Message-ID: <201805031702.w43H2VkE090781@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
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 <mmacy@mattmacy.io> 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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201805031702.w43H2VkE090781>