From owner-svn-src-stable@freebsd.org Tue Apr 4 18:01:36 2017 Return-Path: Delivered-To: svn-src-stable@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 B0674D2EADB; Tue, 4 Apr 2017 18:01:36 +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 7547F2ED; Tue, 4 Apr 2017 18:01:36 +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 v34I1Zsx004306; Tue, 4 Apr 2017 18:01:35 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v34I1ZbT004303; Tue, 4 Apr 2017 18:01:35 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201704041801.v34I1ZbT004303@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Tue, 4 Apr 2017 18:01:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r316499 - in stable/10/sys: cam sys X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 04 Apr 2017 18:01:36 -0000 Author: mav Date: Tue Apr 4 18:01:35 2017 New Revision: 316499 URL: https://svnweb.freebsd.org/changeset/base/316499 Log: MFC r315673, r315674: Make CAM SIM lock optional. For three years now CAM does not use SIM lock, but still enforces SIM to use it. Remove this requirement, allowing SIMs to have any locking they prefer, if they pass no mutex to cam_sim_alloc(). Modified: stable/10/sys/cam/cam_sim.c stable/10/sys/cam/cam_xpt.c stable/10/sys/sys/param.h Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/cam/cam_sim.c ============================================================================== --- stable/10/sys/cam/cam_sim.c Tue Apr 4 17:59:10 2017 (r316498) +++ stable/10/sys/cam/cam_sim.c Tue Apr 4 18:01:35 2017 (r316499) @@ -46,6 +46,9 @@ __FBSDID("$FreeBSD$"); static MALLOC_DEFINE(M_CAMSIM, "CAM SIM", "CAM SIM buffers"); +static struct mtx cam_sim_free_mtx; +MTX_SYSINIT(cam_sim_free_init, &cam_sim_free_mtx, "CAM SIM free lock", MTX_DEF); + struct cam_devq * cam_simq_alloc(u_int32_t max_sim_transactions) { @@ -66,9 +69,6 @@ cam_sim_alloc(sim_action_func sim_action { struct cam_sim *sim; - if (mtx == NULL) - return (NULL); - sim = (struct cam_sim *)malloc(sizeof(struct cam_sim), M_CAMSIM, M_ZERO | M_NOWAIT); @@ -101,16 +101,23 @@ cam_sim_alloc(sim_action_func sim_action void cam_sim_free(struct cam_sim *sim, int free_devq) { + struct mtx *mtx = sim->mtx; int error; - mtx_assert(sim->mtx, MA_OWNED); + if (mtx) { + mtx_assert(mtx, MA_OWNED); + } else { + mtx = &cam_sim_free_mtx; + mtx_lock(mtx); + } sim->refcount--; if (sim->refcount > 0) { - error = msleep(sim, sim->mtx, PRIBIO, "simfree", 0); + error = msleep(sim, mtx, PRIBIO, "simfree", 0); KASSERT(error == 0, ("invalid error value for msleep(9)")); } - KASSERT(sim->refcount == 0, ("sim->refcount == 0")); + if (sim->mtx == NULL) + mtx_unlock(mtx); if (free_devq) cam_simq_free(sim->devq); @@ -120,31 +127,43 @@ cam_sim_free(struct cam_sim *sim, int fr void cam_sim_release(struct cam_sim *sim) { - int lock; + struct mtx *mtx = sim->mtx; - lock = (mtx_owned(sim->mtx) == 0); - if (lock) - CAM_SIM_LOCK(sim); + if (mtx) { + if (!mtx_owned(mtx)) + mtx_lock(mtx); + else + mtx = NULL; + } else { + mtx = &cam_sim_free_mtx; + mtx_lock(mtx); + } KASSERT(sim->refcount >= 1, ("sim->refcount >= 1")); sim->refcount--; if (sim->refcount == 0) wakeup(sim); - if (lock) - CAM_SIM_UNLOCK(sim); + if (mtx) + mtx_unlock(mtx); } void cam_sim_hold(struct cam_sim *sim) { - int lock; + struct mtx *mtx = sim->mtx; - lock = (mtx_owned(sim->mtx) == 0); - if (lock) - CAM_SIM_LOCK(sim); + if (mtx) { + if (!mtx_owned(mtx)) + mtx_lock(mtx); + else + mtx = NULL; + } else { + mtx = &cam_sim_free_mtx; + mtx_lock(mtx); + } KASSERT(sim->refcount >= 1, ("sim->refcount >= 1")); sim->refcount++; - if (lock) - CAM_SIM_UNLOCK(sim); + if (mtx) + mtx_unlock(mtx); } void Modified: stable/10/sys/cam/cam_xpt.c ============================================================================== --- stable/10/sys/cam/cam_xpt.c Tue Apr 4 17:59:10 2017 (r316498) +++ stable/10/sys/cam/cam_xpt.c Tue Apr 4 18:01:35 2017 (r316499) @@ -2483,7 +2483,7 @@ xpt_action_default(union ccb *start_ccb) { struct cam_path *path; struct cam_sim *sim; - int lock; + struct mtx *mtx; path = start_ccb->ccb_h.path; CAM_DEBUG(path, CAM_DEBUG_TRACE, ("xpt_action_default\n")); @@ -2637,12 +2637,14 @@ xpt_action_default(union ccb *start_ccb) case XPT_PATH_INQ: call_sim: sim = path->bus->sim; - lock = (mtx_owned(sim->mtx) == 0); - if (lock) - CAM_SIM_LOCK(sim); + mtx = sim->mtx; + if (mtx && !mtx_owned(mtx)) + mtx_lock(mtx); + else + mtx = NULL; (*(sim->sim_action))(sim, start_ccb); - if (lock) - CAM_SIM_UNLOCK(sim); + if (mtx) + mtx_unlock(mtx); break; case XPT_PATH_STATS: start_ccb->cpis.last_reset = path->bus->last_reset; @@ -2864,8 +2866,8 @@ call_sim: break; } cur_entry->event_enable = csa->event_enable; - cur_entry->event_lock = - mtx_owned(path->bus->sim->mtx) ? 1 : 0; + cur_entry->event_lock = (path->bus->sim->mtx && + mtx_owned(path->bus->sim->mtx)) ? 1 : 0; cur_entry->callback_arg = csa->callback_arg; cur_entry->callback = csa->callback; SLIST_INSERT_HEAD(async_head, cur_entry, links); @@ -3025,10 +3027,12 @@ xpt_polled_action(union ccb *start_ccb) struct cam_sim *sim; struct cam_devq *devq; struct cam_ed *dev; + struct mtx *mtx; timeout = start_ccb->ccb_h.timeout * 10; sim = start_ccb->ccb_h.path->bus->sim; devq = sim->devq; + mtx = sim->mtx; dev = start_ccb->ccb_h.path->device; mtx_unlock(&dev->device_mtx); @@ -3043,9 +3047,11 @@ xpt_polled_action(union ccb *start_ccb) (--timeout > 0)) { mtx_unlock(&devq->send_mtx); DELAY(100); - CAM_SIM_LOCK(sim); + if (mtx) + mtx_lock(mtx); (*(sim->sim_poll))(sim); - CAM_SIM_UNLOCK(sim); + if (mtx) + mtx_unlock(mtx); camisr_runqueue(); mtx_lock(&devq->send_mtx); } @@ -3055,9 +3061,11 @@ xpt_polled_action(union ccb *start_ccb) if (timeout != 0) { xpt_action(start_ccb); while(--timeout > 0) { - CAM_SIM_LOCK(sim); + if (mtx) + mtx_lock(mtx); (*(sim->sim_poll))(sim); - CAM_SIM_UNLOCK(sim); + if (mtx) + mtx_unlock(mtx); camisr_runqueue(); if ((start_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_INPROG) @@ -3215,7 +3223,7 @@ static void xpt_run_devq(struct cam_devq *devq) { char cdb_str[(SCSI_MAX_CDBLEN * 3) + 1]; - int lock; + struct mtx *mtx; CAM_DEBUG_PRINT(CAM_DEBUG_XPT, ("xpt_run_devq\n")); @@ -3317,12 +3325,14 @@ xpt_run_devq(struct cam_devq *devq) * queued device, rather than the one from the calling bus. */ sim = device->sim; - lock = (mtx_owned(sim->mtx) == 0); - if (lock) - CAM_SIM_LOCK(sim); + mtx = sim->mtx; + if (mtx && !mtx_owned(mtx)) + mtx_lock(mtx); + else + mtx = NULL; (*(sim->sim_action))(sim, work_ccb); - if (lock) - CAM_SIM_UNLOCK(sim); + if (mtx) + mtx_unlock(mtx); mtx_lock(&devq->send_mtx); } devq->send_queue.qfrozen_cnt--; @@ -3867,8 +3877,6 @@ xpt_bus_register(struct cam_sim *sim, de struct cam_path *path; cam_status status; - mtx_assert(sim->mtx, MA_OWNED); - sim->bus_id = bus; new_bus = (struct cam_eb *)malloc(sizeof(*new_bus), M_CAMXPT, M_NOWAIT|M_ZERO); @@ -4225,7 +4233,7 @@ xpt_async_bcast(struct async_list *async struct cam_path *path, void *async_arg) { struct async_node *cur_entry; - int lock; + struct mtx *mtx; cur_entry = SLIST_FIRST(async_head); while (cur_entry != NULL) { @@ -4237,14 +4245,15 @@ xpt_async_bcast(struct async_list *async */ next_entry = SLIST_NEXT(cur_entry, links); if ((cur_entry->event_enable & async_code) != 0) { - lock = cur_entry->event_lock; - if (lock) - CAM_SIM_LOCK(path->device->sim); + mtx = cur_entry->event_lock ? + path->device->sim->mtx : NULL; + if (mtx) + mtx_lock(mtx); cur_entry->callback(cur_entry->callback_arg, async_code, path, async_arg); - if (lock) - CAM_SIM_UNLOCK(path->device->sim); + if (mtx) + mtx_unlock(mtx); } cur_entry = next_entry; } Modified: stable/10/sys/sys/param.h ============================================================================== --- stable/10/sys/sys/param.h Tue Apr 4 17:59:10 2017 (r316498) +++ stable/10/sys/sys/param.h Tue Apr 4 18:01:35 2017 (r316499) @@ -58,7 +58,7 @@ * in the range 5 to 9. */ #undef __FreeBSD_version -#define __FreeBSD_version 1003512 /* Master, propagated to newvers */ +#define __FreeBSD_version 1003513 /* Master, propagated to newvers */ /* * __FreeBSD_kernel__ indicates that this system uses the kernel of FreeBSD,