Index: mpath.c =================================================================== RCS file: /cvs/src/sys/scsi/mpath.c,v retrieving revision 1.37 diff -u -p -r1.37 mpath.c --- mpath.c 14 Sep 2014 14:17:26 -0000 1.37 +++ mpath.c 24 Sep 2014 23:49:56 -0000 @@ -340,7 +340,7 @@ mpath_done(struct scsi_xfer *mxs) void mpath_failover(struct mpath_dev *d) { - if (!scsi_pending_start(&d->d_mtx, &d->d_failover)) + if (!scsi_pending_start(&d->d_failover)) return; mpath_failover_start(d); @@ -389,7 +389,7 @@ mpath_path_status(struct mpath_path *p, if (status == MPATH_S_ACTIVE) { scsi_xsh_add(&p->p_xsh); - if (!scsi_pending_finish(&d->d_mtx, &d->d_failover)) + if (!scsi_pending_finish(&d->d_failover)) mpath_failover_start(d); } else mpath_failover_check(d); Index: scsi_base.c =================================================================== RCS file: /cvs/src/sys/scsi/scsi_base.c,v retrieving revision 1.217 diff -u -p -r1.217 scsi_base.c --- scsi_base.c 20 Sep 2014 16:18:23 -0000 1.217 +++ scsi_base.c 24 Sep 2014 23:49:56 -0000 @@ -45,6 +45,7 @@ #include #include #include +#include #include #include @@ -201,33 +202,20 @@ scsi_plug_detach(void *xp, void *null) } int -scsi_pending_start(struct mutex *mtx, u_int *running) +scsi_pending_start(u_int *running) { - int rv = 1; - - mtx_enter(mtx); - (*running)++; - if ((*running) > 1) - rv = 0; - mtx_leave(mtx); - - return (rv); + return (atomic_inc_int_nv(running) == 1); } int -scsi_pending_finish(struct mutex *mtx, u_int *running) +scsi_pending_finish(u_int *running) { - int rv = 1; + if (atomic_cas_uint(running, 1, 0) == 1) + return (1); - mtx_enter(mtx); - (*running)--; - if ((*running) > 0) { - (*running) = 1; - rv = 0; - } - mtx_leave(mtx); + *running = 1; - return (rv); + return (0); } void @@ -409,7 +397,7 @@ scsi_iopool_run(struct scsi_iopool *iopl struct scsi_iohandler *ioh; void *io; - if (!scsi_pending_start(&iopl->mtx, &iopl->running)) + if (!scsi_pending_start(&iopl->running)) return; do { while (scsi_ioh_pending(iopl)) { @@ -425,7 +413,7 @@ scsi_iopool_run(struct scsi_iopool *iopl ioh->handler(ioh->cookie, io); } - } while (!scsi_pending_finish(&iopl->mtx, &iopl->running)); + } while (!scsi_pending_finish(&iopl->running)); } /* @@ -568,7 +556,7 @@ scsi_xsh_runqueue(struct scsi_link *link struct scsi_iohandler *ioh; int runq; - if (!scsi_pending_start(&link->pool->mtx, &link->running)) + if (!scsi_pending_start(&link->running)) return; do { runq = 0; @@ -589,7 +577,7 @@ scsi_xsh_runqueue(struct scsi_link *link if (runq) scsi_iopool_run(link->pool); - } while (!scsi_pending_finish(&link->pool->mtx, &link->running)); + } while (!scsi_pending_finish(&link->running)); } void Index: scsiconf.h =================================================================== RCS file: /cvs/src/sys/scsi/scsiconf.h,v retrieving revision 1.162 diff -u -p -r1.162 scsiconf.h --- scsiconf.h 9 Sep 2014 20:30:08 -0000 1.162 +++ scsiconf.h 24 Sep 2014 23:49:56 -0000 @@ -570,8 +570,8 @@ int scsi_xsh_del(struct scsi_xshandler * /* * utility functions */ -int scsi_pending_start(struct mutex *, u_int *); -int scsi_pending_finish(struct mutex *, u_int *); +int scsi_pending_start(u_int *); +int scsi_pending_finish(u_int *); /* * Utility functions for SCSI HBA emulation.