From owner-svn-src-all@freebsd.org Thu Aug 18 09:22:12 2016 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 493FEBBC7CD; Thu, 18 Aug 2016 09:22:12 +0000 (UTC) (envelope-from mav@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 mx1.freebsd.org (Postfix) with ESMTPS id 20CE115A5; Thu, 18 Aug 2016 09:22:12 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u7I9MBwQ092942; Thu, 18 Aug 2016 09:22:11 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u7I9MBVC092941; Thu, 18 Aug 2016 09:22:11 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201608180922.u7I9MBVC092941@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Thu, 18 Aug 2016 09:22:11 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r304352 - stable/11/sys/dev/ntb/ntb_hw X-SVN-Group: stable-11 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.22 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: Thu, 18 Aug 2016 09:22:12 -0000 Author: mav Date: Thu Aug 18 09:22:11 2016 New Revision: 304352 URL: https://svnweb.freebsd.org/changeset/base/304352 Log: MFC r302491: Switch ctx_lock from mutex to rmlock. It is odd idea to serialize different MSI-X vectors. Use of rmlocks here allows them to execute in parallel, but still protects ctx. If upper layers require any additional serialization -- they can do it by themselves. Modified: stable/11/sys/dev/ntb/ntb_hw/ntb_hw.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/dev/ntb/ntb_hw/ntb_hw.c ============================================================================== --- stable/11/sys/dev/ntb/ntb_hw/ntb_hw.c Thu Aug 18 09:21:36 2016 (r304351) +++ stable/11/sys/dev/ntb/ntb_hw/ntb_hw.c Thu Aug 18 09:22:11 2016 (r304352) @@ -50,6 +50,7 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include #include #include #include @@ -220,10 +221,7 @@ struct ntb_softc { void *ntb_ctx; const struct ntb_ctx_ops *ctx_ops; struct ntb_vec *msix_vec; -#define CTX_LOCK(sc) mtx_lock(&(sc)->ctx_lock) -#define CTX_UNLOCK(sc) mtx_unlock(&(sc)->ctx_lock) -#define CTX_ASSERT(sc,f) mtx_assert(&(sc)->ctx_lock, (f)) - struct mtx ctx_lock; + struct rmlock ctx_lock; uint32_t ppd; enum ntb_conn_type conn_type; @@ -657,7 +655,7 @@ ntb_attach(device_t device) callout_init(&ntb->lr_timer, 1); callout_init(&ntb->peer_msix_work, 1); mtx_init(&ntb->db_mask_lock, "ntb hw bits", NULL, MTX_SPIN); - mtx_init(&ntb->ctx_lock, "ntb ctx", NULL, MTX_DEF); + rm_init(&ntb->ctx_lock, "ntb ctx"); if (ntb->type == NTB_ATOM) error = ntb_detect_atom(ntb); @@ -720,7 +718,7 @@ ntb_detach(device_t device) ntb_teardown_interrupts(ntb); mtx_destroy(&ntb->db_mask_lock); - mtx_destroy(&ntb->ctx_lock); + rm_destroy(&ntb->ctx_lock); ntb_unmap_pci_bar(ntb); @@ -2012,17 +2010,15 @@ ntb_set_ctx(device_t dev, void *ctx, con if (ctx == NULL || ops == NULL) return (EINVAL); - if (ntb->ctx_ops != NULL) - return (EINVAL); - CTX_LOCK(ntb); + rm_wlock(&ntb->ctx_lock); if (ntb->ctx_ops != NULL) { - CTX_UNLOCK(ntb); + rm_wunlock(&ntb->ctx_lock); return (EINVAL); } ntb->ntb_ctx = ctx; ntb->ctx_ops = ops; - CTX_UNLOCK(ntb); + rm_wunlock(&ntb->ctx_lock); return (0); } @@ -2047,10 +2043,10 @@ ntb_clear_ctx(device_t dev) { struct ntb_softc *ntb = device_get_softc(dev); - CTX_LOCK(ntb); + rm_wlock(&ntb->ctx_lock); ntb->ntb_ctx = NULL; ntb->ctx_ops = NULL; - CTX_UNLOCK(ntb); + rm_wunlock(&ntb->ctx_lock); } /* @@ -2064,11 +2060,12 @@ static void ntb_link_event(device_t dev) { struct ntb_softc *ntb = device_get_softc(dev); + struct rm_priotracker ctx_tracker; - CTX_LOCK(ntb); + rm_rlock(&ntb->ctx_lock, &ctx_tracker); if (ntb->ctx_ops != NULL && ntb->ctx_ops->link_event != NULL) ntb->ctx_ops->link_event(ntb->ntb_ctx); - CTX_UNLOCK(ntb); + rm_runlock(&ntb->ctx_lock, &ctx_tracker); } /* @@ -2088,11 +2085,12 @@ static void ntb_db_event(device_t dev, uint32_t vec) { struct ntb_softc *ntb = device_get_softc(dev); + struct rm_priotracker ctx_tracker; - CTX_LOCK(ntb); + rm_rlock(&ntb->ctx_lock, &ctx_tracker); if (ntb->ctx_ops != NULL && ntb->ctx_ops->db_event != NULL) ntb->ctx_ops->db_event(ntb->ntb_ctx, vec); - CTX_UNLOCK(ntb); + rm_runlock(&ntb->ctx_lock, &ctx_tracker); } static int