Merge CAM locking changes from the projects/camlock branch to radically
authormav <mav@ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f>
Mon, 21 Oct 2013 12:00:26 +0000 (12:00 +0000)
committermav <mav@ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f>
Mon, 21 Oct 2013 12:00:26 +0000 (12:00 +0000)
commitfc59506f2dcc55caa02dbbac6135aa874386f5fa
tree2241bb08977b8fb8347e216b1dd8011b6627f617
parent864170ba4b6181ffb063e730ba1c869656cb4d05
Merge CAM locking changes from the projects/camlock branch to radically
reduce lock congestion and improve SMP scalability of the SCSI/ATA stack,
preparing the ground for the coming next GEOM direct dispatch support.

Replace big per-SIM locks with bunch of smaller ones:
 - per-LUN locks to protect device and peripheral drivers state;
 - per-target locks to protect list of LUNs on target;
 - per-bus locks to protect reference counting;
 - per-send queue locks to protect queue of CCBs to be sent;
 - per-done queue locks to protect queue of completed CCBs;
 - remaining per-SIM locks now protect only HBA driver internals.

While holding LUN lock it is allowed (while not recommended for performance
reasons) to take SIM lock.  The opposite acquisition order is forbidden.
All the other locks are leaf locks, that can be taken anywhere, but should
not be cascaded.  Many functions, such as: xpt_action(), xpt_done(),
xpt_async(), xpt_create_path(), etc. are no longer require (but allow) SIM
lock to be held.

To keep compatibility and solve cases where SIM lock can't be dropped, all
xpt_async() calls in addition to xpt_done() calls are queued to completion
threads for async processing in clean environment without SIM lock held.

Instead of single CAM SWI thread, used for commands completion processing
before, use multiple (depending on number of CPUs) threads.  Load balanced
between them using "hash" of the device B:T:L address.

HBA drivers that can drop SIM lock during completion processing and have
sufficient number of completion threads to efficiently scale to multiple
CPUs can use new function xpt_done_direct() to avoid extra context switch.
Make ahci(4) driver to use this mechanism depending on hardware setup.

Sponsored by: iXsystems, Inc.
MFC after: 2 months

git-svn-id: svn://svn.freebsd.org/base/head@256843 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f
36 files changed:
sys/cam/ata/ata_da.c
sys/cam/ata/ata_pmp.c
sys/cam/ata/ata_xpt.c
sys/cam/cam_ccb.h
sys/cam/cam_periph.c
sys/cam/cam_periph.h
sys/cam/cam_queue.c
sys/cam/cam_queue.h
sys/cam/cam_sim.c
sys/cam/cam_sim.h
sys/cam/cam_xpt.c
sys/cam/cam_xpt.h
sys/cam/cam_xpt_internal.h
sys/cam/cam_xpt_sim.h
sys/cam/ctl/ctl_frontend_cam_sim.c
sys/cam/ctl/scsi_ctl.c
sys/cam/scsi/scsi_cd.c
sys/cam/scsi/scsi_ch.c
sys/cam/scsi/scsi_da.c
sys/cam/scsi/scsi_enc.c
sys/cam/scsi/scsi_enc_internal.h
sys/cam/scsi/scsi_enc_safte.c
sys/cam/scsi/scsi_enc_ses.c
sys/cam/scsi/scsi_pass.c
sys/cam/scsi/scsi_pt.c
sys/cam/scsi/scsi_sa.c
sys/cam/scsi/scsi_sg.c
sys/cam/scsi/scsi_targ_bh.c
sys/cam/scsi/scsi_target.c
sys/cam/scsi/scsi_xpt.c
sys/dev/ahci/ahci.c
sys/dev/ahci/ahci.h
sys/dev/ata/ata-all.c
sys/dev/isp/isp_freebsd.c
sys/dev/mvs/mvs.c
sys/dev/siis/siis.c