aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/iscsi_tcp.c
diff options
context:
space:
mode:
authorShlomo Pongratz <shlomop@mellanox.com>2014-02-07 01:41:38 -0500
committerJames Bottomley <JBottomley@Parallels.com>2014-03-15 13:19:18 -0400
commit659743b02c411075b26601725947b21df0bb29c8 (patch)
tree5c0350e508cdc32c97bf8d86da0ecfa5c15915f5 /drivers/scsi/iscsi_tcp.c
parent5d0fddd0a72d3023bb0fa97e546f687aa6222be3 (diff)
[SCSI] libiscsi: Reduce locking contention in fast path
Replace the session lock with two locks, a forward lock and a backwards lock named frwd_lock and back_lock respectively. The forward lock protects resources that change while sending a request to the target, such as cmdsn, queued_cmdsn, and allocating task from the commands' pool with kfifo_out. The backward lock protects resources that change while processing a response or in error path, such as cmdsn_exp, cmdsn_max, and returning tasks to the commands' pool with kfifo_in. Under a steady state fast-path situation, that is when one or more processes/threads submit IO to an iscsi device and a single kernel upcall (e.g softirq) is dealing with processing of responses without errors, this patch eliminates the contention between the queuecommand()/request response/scsi_done() flows associated with iscsi sessions. Between the forward and the backward locks exists a strict locking hierarchy. The mutual exclusion zone protected by the forward lock can enclose the mutual exclusion zone protected by the backward lock but not vice versa. For example, in iscsi_conn_teardown or in iscsi_xmit_data when there is a failure and __iscsi_put_task is called, the backward lock is taken while the forward lock is still taken. On the other hand, if in the RX path a nop is to be sent, for example in iscsi_handle_reject or __iscsi_complete_pdu than the forward lock is released and the backward lock is taken for the duration of iscsi_send_nopout, later the backward lock is released and the forward lock is retaken. libiscsi_tcp uses two kernel fifos the r2t pool and the r2t queue. The insertion and deletion from these queues didn't corespond to the assumption taken by the new forward/backwards session locking paradigm. That is, in iscsi_tcp_clenup_task which belongs to the RX (backwards) path, r2t is taken out from r2t queue and inserted to the r2t pool. In iscsi_tcp_get_curr_r2t which belong to the TX (forward) path, r2t is also inserted to the r2t pool and another r2t is pulled from r2t queue. Only in iscsi_tcp_r2t_rsp which is called in the RX path but can requeue to the TX path, r2t is taken from the r2t pool and inserted to the r2t queue. In order to cope with this situation, two spin locks were added, pool2queue and queue2pool. The former protects extracting from the r2t pool and inserting to the r2t queue, and the later protects the extracing from the r2t queue and inserting to the r2t pool. Signed-off-by: Shlomo Pongratz <shlomop@mellanox.com> Signed-off-by: Or Gerlitz <ogerlitz@mellanox.com> [minor fix up to apply cleanly and compile fix] Signed-off-by: Mike Christie <michaelc@cs.wisc.edu> Signed-off-by: James Bottomley <JBottomley@Parallels.com>
Diffstat (limited to 'drivers/scsi/iscsi_tcp.c')
-rw-r--r--drivers/scsi/iscsi_tcp.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
index add6d1566ec8..12b351213c59 100644
--- a/drivers/scsi/iscsi_tcp.c
+++ b/drivers/scsi/iscsi_tcp.c
@@ -593,9 +593,9 @@ static void iscsi_sw_tcp_release_conn(struct iscsi_conn *conn)
593 iscsi_sw_tcp_conn_restore_callbacks(conn); 593 iscsi_sw_tcp_conn_restore_callbacks(conn);
594 sock_put(sock->sk); 594 sock_put(sock->sk);
595 595
596 spin_lock_bh(&session->lock); 596 spin_lock_bh(&session->frwd_lock);
597 tcp_sw_conn->sock = NULL; 597 tcp_sw_conn->sock = NULL;
598 spin_unlock_bh(&session->lock); 598 spin_unlock_bh(&session->frwd_lock);
599 sockfd_put(sock); 599 sockfd_put(sock);
600} 600}
601 601
@@ -663,10 +663,10 @@ iscsi_sw_tcp_conn_bind(struct iscsi_cls_session *cls_session,
663 if (err) 663 if (err)
664 goto free_socket; 664 goto free_socket;
665 665
666 spin_lock_bh(&session->lock); 666 spin_lock_bh(&session->frwd_lock);
667 /* bind iSCSI connection and socket */ 667 /* bind iSCSI connection and socket */
668 tcp_sw_conn->sock = sock; 668 tcp_sw_conn->sock = sock;
669 spin_unlock_bh(&session->lock); 669 spin_unlock_bh(&session->frwd_lock);
670 670
671 /* setup Socket parameters */ 671 /* setup Socket parameters */
672 sk = sock->sk; 672 sk = sock->sk;
@@ -726,14 +726,14 @@ static int iscsi_sw_tcp_conn_get_param(struct iscsi_cls_conn *cls_conn,
726 switch(param) { 726 switch(param) {
727 case ISCSI_PARAM_CONN_PORT: 727 case ISCSI_PARAM_CONN_PORT:
728 case ISCSI_PARAM_CONN_ADDRESS: 728 case ISCSI_PARAM_CONN_ADDRESS:
729 spin_lock_bh(&conn->session->lock); 729 spin_lock_bh(&conn->session->frwd_lock);
730 if (!tcp_sw_conn || !tcp_sw_conn->sock) { 730 if (!tcp_sw_conn || !tcp_sw_conn->sock) {
731 spin_unlock_bh(&conn->session->lock); 731 spin_unlock_bh(&conn->session->frwd_lock);
732 return -ENOTCONN; 732 return -ENOTCONN;
733 } 733 }
734 rc = kernel_getpeername(tcp_sw_conn->sock, 734 rc = kernel_getpeername(tcp_sw_conn->sock,
735 (struct sockaddr *)&addr, &len); 735 (struct sockaddr *)&addr, &len);
736 spin_unlock_bh(&conn->session->lock); 736 spin_unlock_bh(&conn->session->frwd_lock);
737 if (rc) 737 if (rc)
738 return rc; 738 return rc;
739 739
@@ -759,23 +759,23 @@ static int iscsi_sw_tcp_host_get_param(struct Scsi_Host *shost,
759 759
760 switch (param) { 760 switch (param) {
761 case ISCSI_HOST_PARAM_IPADDRESS: 761 case ISCSI_HOST_PARAM_IPADDRESS:
762 spin_lock_bh(&session->lock); 762 spin_lock_bh(&session->frwd_lock);
763 conn = session->leadconn; 763 conn = session->leadconn;
764 if (!conn) { 764 if (!conn) {
765 spin_unlock_bh(&session->lock); 765 spin_unlock_bh(&session->frwd_lock);
766 return -ENOTCONN; 766 return -ENOTCONN;
767 } 767 }
768 tcp_conn = conn->dd_data; 768 tcp_conn = conn->dd_data;
769 769
770 tcp_sw_conn = tcp_conn->dd_data; 770 tcp_sw_conn = tcp_conn->dd_data;
771 if (!tcp_sw_conn->sock) { 771 if (!tcp_sw_conn->sock) {
772 spin_unlock_bh(&session->lock); 772 spin_unlock_bh(&session->frwd_lock);
773 return -ENOTCONN; 773 return -ENOTCONN;
774 } 774 }
775 775
776 rc = kernel_getsockname(tcp_sw_conn->sock, 776 rc = kernel_getsockname(tcp_sw_conn->sock,
777 (struct sockaddr *)&addr, &len); 777 (struct sockaddr *)&addr, &len);
778 spin_unlock_bh(&session->lock); 778 spin_unlock_bh(&session->frwd_lock);
779 if (rc) 779 if (rc)
780 return rc; 780 return rc;
781 781