From owner-svn-src-head@FreeBSD.ORG Sat Nov 22 09:05:54 2014 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id EB0E43D3; Sat, 22 Nov 2014 09:05:54 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::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 CC1DC7D0; Sat, 22 Nov 2014 09:05:54 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id sAM95sBt036724; Sat, 22 Nov 2014 09:05:54 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id sAM95ser036723; Sat, 22 Nov 2014 09:05:54 GMT (envelope-from mav@FreeBSD.org) Message-Id: <201411220905.sAM95ser036723@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Sat, 22 Nov 2014 09:05:54 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r274843 - head/sys/dev/iscsi X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 22 Nov 2014 09:05:55 -0000 Author: mav Date: Sat Nov 22 09:05:54 2014 New Revision: 274843 URL: https://svnweb.freebsd.org/changeset/base/274843 Log: Move icl_pdu_get_data() and xpt_done() out of initiator's session lock. During heavy reads data copying in icl_pdu_get_data() may consume large percent of CPU time. Moving it out of the lock significantly reduces lock hold time and respectively lock congestion on read operations. MFC after: 2 weeks Modified: head/sys/dev/iscsi/iscsi.c Modified: head/sys/dev/iscsi/iscsi.c ============================================================================== --- head/sys/dev/iscsi/iscsi.c Sat Nov 22 08:47:04 2014 (r274842) +++ head/sys/dev/iscsi/iscsi.c Sat Nov 22 09:05:54 2014 (r274843) @@ -139,6 +139,7 @@ static uma_zone_t iscsi_outstanding_zone #define ISCSI_SESSION_LOCK(X) mtx_lock(&X->is_lock) #define ISCSI_SESSION_UNLOCK(X) mtx_unlock(&X->is_lock) #define ISCSI_SESSION_LOCK_ASSERT(X) mtx_assert(&X->is_lock, MA_OWNED) +#define ISCSI_SESSION_LOCK_ASSERT_NOT(X) mtx_assert(&X->is_lock, MA_NOTOWNED) static int iscsi_ioctl(struct cdev *dev, u_long cmd, caddr_t arg, int mode, struct thread *td); @@ -709,37 +710,46 @@ iscsi_receive_callback(struct icl_pdu *r switch (response->ip_bhs->bhs_opcode) { case ISCSI_BHS_OPCODE_NOP_IN: iscsi_pdu_handle_nop_in(response); + ISCSI_SESSION_UNLOCK(is); break; case ISCSI_BHS_OPCODE_SCSI_RESPONSE: iscsi_pdu_handle_scsi_response(response); + /* Session lock dropped inside. */ + ISCSI_SESSION_LOCK_ASSERT_NOT(is); break; case ISCSI_BHS_OPCODE_TASK_RESPONSE: iscsi_pdu_handle_task_response(response); + ISCSI_SESSION_UNLOCK(is); break; case ISCSI_BHS_OPCODE_SCSI_DATA_IN: iscsi_pdu_handle_data_in(response); + /* Session lock dropped inside. */ + ISCSI_SESSION_LOCK_ASSERT_NOT(is); break; case ISCSI_BHS_OPCODE_LOGOUT_RESPONSE: iscsi_pdu_handle_logout_response(response); + ISCSI_SESSION_UNLOCK(is); break; case ISCSI_BHS_OPCODE_R2T: iscsi_pdu_handle_r2t(response); + ISCSI_SESSION_UNLOCK(is); break; case ISCSI_BHS_OPCODE_ASYNC_MESSAGE: iscsi_pdu_handle_async_message(response); + ISCSI_SESSION_UNLOCK(is); break; case ISCSI_BHS_OPCODE_REJECT: iscsi_pdu_handle_reject(response); + ISCSI_SESSION_UNLOCK(is); break; default: ISCSI_SESSION_WARN(is, "received PDU with unsupported " "opcode 0x%x; reconnecting", response->ip_bhs->bhs_opcode); iscsi_session_reconnect(is); + ISCSI_SESSION_UNLOCK(is); icl_pdu_free(response); } - - ISCSI_SESSION_UNLOCK(is); } static void @@ -840,9 +850,13 @@ iscsi_pdu_handle_scsi_response(struct ic ISCSI_SESSION_WARN(is, "bad itt 0x%x", bhssr->bhssr_initiator_task_tag); icl_pdu_free(response); iscsi_session_reconnect(is); + ISCSI_SESSION_UNLOCK(is); return; } + iscsi_outstanding_remove(is, io); + ISCSI_SESSION_UNLOCK(is); + if (bhssr->bhssr_response != BHSSR_RESPONSE_COMMAND_COMPLETED) { ISCSI_SESSION_WARN(is, "service response 0x%x", bhssr->bhssr_response); if ((io->io_ccb->ccb_h.status & CAM_DEV_QFRZN) == 0) { @@ -861,15 +875,7 @@ iscsi_pdu_handle_scsi_response(struct ic io->io_ccb->csio.scsi_status = bhssr->bhssr_status; } - if (bhssr->bhssr_flags & BHSSR_FLAGS_RESIDUAL_OVERFLOW) { - ISCSI_SESSION_WARN(is, "target indicated residual overflow"); - icl_pdu_free(response); - iscsi_session_reconnect(is); - return; - } - csio = &io->io_ccb->csio; - data_segment_len = icl_pdu_data_segment_length(response); if (data_segment_len > 0) { if (data_segment_len < sizeof(sense_len)) { @@ -931,7 +937,6 @@ out: } xpt_done(io->io_ccb); - iscsi_outstanding_remove(is, io); icl_pdu_free(response); } @@ -974,7 +979,7 @@ iscsi_pdu_handle_data_in(struct icl_pdu struct iscsi_outstanding *io; struct iscsi_session *is; struct ccb_scsiio *csio; - size_t data_segment_len; + size_t data_segment_len, received; is = PDU_SESSION(response); bhsdi = (struct iscsi_bhs_data_in *)response->ip_bhs; @@ -983,6 +988,7 @@ iscsi_pdu_handle_data_in(struct icl_pdu ISCSI_SESSION_WARN(is, "bad itt 0x%x", bhsdi->bhsdi_initiator_task_tag); icl_pdu_free(response); iscsi_session_reconnect(is); + ISCSI_SESSION_UNLOCK(is); return; } @@ -993,6 +999,7 @@ iscsi_pdu_handle_data_in(struct icl_pdu * but initiators and targets MUST be able to properly receive * 0 length data segments." */ + ISCSI_SESSION_UNLOCK(is); icl_pdu_free(response); return; } @@ -1007,6 +1014,7 @@ iscsi_pdu_handle_data_in(struct icl_pdu io->io_received, (size_t)ntohl(bhsdi->bhsdi_buffer_offset)); icl_pdu_free(response); iscsi_session_reconnect(is); + ISCSI_SESSION_UNLOCK(is); return; } @@ -1018,11 +1026,17 @@ iscsi_pdu_handle_data_in(struct icl_pdu data_segment_len, io->io_received, csio->dxfer_len); icl_pdu_free(response); iscsi_session_reconnect(is); + ISCSI_SESSION_UNLOCK(is); return; } - icl_pdu_get_data(response, 0, csio->data_ptr + io->io_received, data_segment_len); + received = io->io_received; io->io_received += data_segment_len; + if ((bhsdi->bhsdi_flags & BHSDI_FLAGS_S) != 0) + iscsi_outstanding_remove(is, io); + ISCSI_SESSION_UNLOCK(is); + + icl_pdu_get_data(response, 0, csio->data_ptr + received, data_segment_len); /* * XXX: Check DataSN. @@ -1064,7 +1078,6 @@ iscsi_pdu_handle_data_in(struct icl_pdu } xpt_done(io->io_ccb); - iscsi_outstanding_remove(is, io); icl_pdu_free(response); }