From patchwork Fri Mar 11 06:30:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nicholas A. Bellinger" X-Patchwork-Id: 8562411 Return-Path: X-Original-To: patchwork-linux-scsi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id AA2179F6E4 for ; Fri, 11 Mar 2016 06:35:12 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 89AEA2026D for ; Fri, 11 Mar 2016 06:35:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5F2952034F for ; Fri, 11 Mar 2016 06:35:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934180AbcCKGfG (ORCPT ); Fri, 11 Mar 2016 01:35:06 -0500 Received: from mail-oi0-f42.google.com ([209.85.218.42]:35254 "EHLO mail-oi0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934061AbcCKGe5 (ORCPT ); Fri, 11 Mar 2016 01:34:57 -0500 Received: by mail-oi0-f42.google.com with SMTP id c203so78908277oia.2 for ; Thu, 10 Mar 2016 22:34:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=daterainc-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OvN2P3iQOSElHCmSaiMBuoLBpCxxdd15PSpXqo1rP4o=; b=11ZKgeLDJvzONAa9UMLDtIA5gpozWukKX+VEFAiSLLDi6RIcXTFTBRfe09EtF1mYdn T6Riu+W2oJ9+ZcpVMW9jwmHNuTsdq5gSLrO54BKQbdFCeM+J05U0yxyMS+wL8uurEj+t xJJzhzcHO3lta+n2j79N56H+OPha6KFNZxpCRIHPuOgH6PVlO6UvjxtcApdM1ODSM+If WHKpS9A3QtJFMwhB6lA1TvjN+fEtLNj9VXH/O/nZraEGrDZf/gi2SxPcJF6EHuasKYuO 3pb10NjrtTxcTSF+UMOcSYvoOPFVMQH7P4XgQtFhUuun6QQj7MR+991Z4j7LLYrp31N9 LwZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OvN2P3iQOSElHCmSaiMBuoLBpCxxdd15PSpXqo1rP4o=; b=NB7SbXQctAhiy/NY5j8N7iMGJhds3r+Kv4Kd+Aq9I4ZJaGO/hpvh5TJNNMo1iuF/w9 Afuxq07KBUuYD30WNgiHQI9tMczWSb45+7aus1w4BwZqZEv4LU/Szhs4svC7M36DSrp2 La42cozzKlF/3fjbvJo/vucM0nc+m4j/27lDA8MKV3lgz/EXMbX7Yv6JgZsTXOxZ+oAm 3DNJbBb6FuG3xSzZiyNGtOBaOn5Wr+RhBZjVKBGQpl7DFhjAaM17bAFpymOEDY2oO60b T0GV+j1UOfPo+62Q2XEZisTCK2aDocXEkGEp2jTLre/pvJfmNZryfh6cCuKOjantjF5T B6+g== X-Gm-Message-State: AD7BkJKbBjXq8s239GIficSCjau/U7hTJJSbRHe34Jl4oLvoUt9bavW+mFxZDhPlTsh4fw== X-Received: by 10.202.77.81 with SMTP id a78mr4330845oib.71.1457678095744; Thu, 10 Mar 2016 22:34:55 -0800 (PST) Received: from localhost.localdomain (mail.linux-iscsi.org. [67.23.28.174]) by smtp.gmail.com with ESMTPSA id s81sm3540631oif.0.2016.03.10.22.34.55 (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 10 Mar 2016 22:34:55 -0800 (PST) From: "Nicholas A. Bellinger" To: target-devel Cc: linux-scsi , Christoph Hellwig , Hannes Reinecke , Mike Christie , Sagi Grimberg , Andy Grover , Sebastian Andrzej Siewior , Juergen Gross , Andrzej Pietrasiewicz , Chris Boot , Felipe Balbi , Nicholas Bellinger , Vu Pham , Bart Van Assche Subject: [PATCH-v4 14/14] ib_srpt: Convert to percpu_ida tag allocation Date: Fri, 11 Mar 2016 06:30:10 +0000 Message-Id: <1457677810-2478-15-git-send-email-nab@daterainc.com> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1457677810-2478-1-git-send-email-nab@daterainc.com> References: <1457677810-2478-1-git-send-email-nab@daterainc.com> Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Nicholas Bellinger This patch converts ib_srpt to use existing percpu_ida tag pre-allocation for struct srpt_send_ioctx. This allows ib_srpt to drop it's internal pre-allocation mechanisms with the extra spin_lock_irqsave, and use percpu_ida common code for doing this. Cc: Vu Pham Cc: Sagi Grimberg Cc: Bart Van Assche Signed-off-by: Nicholas Bellinger --- drivers/infiniband/ulp/srpt/ib_srpt.c | 55 +++++++++++------------------------ drivers/infiniband/ulp/srpt/ib_srpt.h | 2 -- 2 files changed, 17 insertions(+), 40 deletions(-) diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.c b/drivers/infiniband/ulp/srpt/ib_srpt.c index 72a671e..b0707a7 100644 --- a/drivers/infiniband/ulp/srpt/ib_srpt.c +++ b/drivers/infiniband/ulp/srpt/ib_srpt.c @@ -1261,40 +1261,26 @@ free_mem: */ static struct srpt_send_ioctx *srpt_get_send_ioctx(struct srpt_rdma_ch *ch) { + struct se_session *se_sess; struct srpt_send_ioctx *ioctx; - unsigned long flags; + int tag; BUG_ON(!ch); + se_sess = ch->sess; - ioctx = NULL; - spin_lock_irqsave(&ch->spinlock, flags); - if (!list_empty(&ch->free_list)) { - ioctx = list_first_entry(&ch->free_list, - struct srpt_send_ioctx, free_list); - list_del(&ioctx->free_list); + tag = percpu_ida_alloc(&se_sess->sess_tag_pool, TASK_RUNNING); + if (tag < 0) { + pr_err("Unable to obtain tag for srpt_send_ioctx\n"); + return NULL; } - spin_unlock_irqrestore(&ch->spinlock, flags); - - if (!ioctx) - return ioctx; - - BUG_ON(ioctx->ch != ch); + ioctx = &((struct srpt_send_ioctx *)se_sess->sess_cmd_map)[tag]; + memset(ioctx, 0, sizeof(struct srpt_send_ioctx)); + ioctx->ch = ch; spin_lock_init(&ioctx->spinlock); ioctx->state = SRPT_STATE_NEW; - ioctx->n_rbuf = 0; - ioctx->rbufs = NULL; - ioctx->n_rdma = 0; - ioctx->n_rdma_wrs = 0; - ioctx->rdma_wrs = NULL; - ioctx->mapped_sg_count = 0; init_completion(&ioctx->tx_done); - ioctx->queue_status_only = false; - /* - * transport_init_se_cmd() does not initialize all fields, so do it - * here. - */ - memset(&ioctx->cmd, 0, sizeof(ioctx->cmd)); - memset(&ioctx->sense_data, 0, sizeof(ioctx->sense_data)); + + ioctx->cmd.map_tag = tag; return ioctx; } @@ -2241,7 +2227,7 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id, struct ib_cm_rep_param *rep_param; struct srpt_rdma_ch *ch, *tmp_ch; u32 it_iu_len; - int i, ret = 0; + int ret = 0; unsigned char *p; WARN_ON_ONCE(irqs_disabled()); @@ -2370,12 +2356,6 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id, if (!ch->ioctx_ring) goto free_ch; - INIT_LIST_HEAD(&ch->free_list); - for (i = 0; i < ch->rq_size; i++) { - ch->ioctx_ring[i]->ch = ch; - list_add_tail(&ch->ioctx_ring[i]->free_list, &ch->free_list); - } - ret = srpt_create_ch_ib(ch); if (ret) { rej->reason = cpu_to_be32( @@ -2406,7 +2386,8 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id, p = &ch->sess_name[0]; try_again: - ch->sess = target_alloc_session(&sport->port_tpg_1, 0, 0, + ch->sess = target_alloc_session(&sport->port_tpg_1, ch->rq_size, + sizeof(struct srpt_send_ioctx), TARGET_PROT_NORMAL, p, ch, NULL); if (IS_ERR(ch->sess)) { pr_info("Rejected login because no ACL has been" @@ -3194,7 +3175,7 @@ static void srpt_release_cmd(struct se_cmd *se_cmd) struct srpt_send_ioctx *ioctx = container_of(se_cmd, struct srpt_send_ioctx, cmd); struct srpt_rdma_ch *ch = ioctx->ch; - unsigned long flags; + struct se_session *se_sess = ch->sess; WARN_ON(ioctx->state != SRPT_STATE_DONE); WARN_ON(ioctx->mapped_sg_count != 0); @@ -3205,9 +3186,7 @@ static void srpt_release_cmd(struct se_cmd *se_cmd) ioctx->n_rbuf = 0; } - spin_lock_irqsave(&ch->spinlock, flags); - list_add(&ioctx->free_list, &ch->free_list); - spin_unlock_irqrestore(&ch->spinlock, flags); + percpu_ida_free(&se_sess->sess_tag_pool, se_cmd->map_tag); } /** diff --git a/drivers/infiniband/ulp/srpt/ib_srpt.h b/drivers/infiniband/ulp/srpt/ib_srpt.h index 09037f2..6fbb6e7 100644 --- a/drivers/infiniband/ulp/srpt/ib_srpt.h +++ b/drivers/infiniband/ulp/srpt/ib_srpt.h @@ -179,7 +179,6 @@ struct srpt_recv_ioctx { * struct srpt_send_ioctx - SRPT send I/O context. * @ioctx: See above. * @ch: Channel pointer. - * @free_list: Node in srpt_rdma_ch.free_list. * @n_rbuf: Number of data buffers in the received SRP command. * @rbufs: Pointer to SRP data buffer array. * @single_rbuf: SRP data buffer if the command has only a single buffer. @@ -202,7 +201,6 @@ struct srpt_send_ioctx { struct srp_direct_buf *rbufs; struct srp_direct_buf single_rbuf; struct scatterlist *sg; - struct list_head free_list; spinlock_t spinlock; enum srpt_command_state state; struct se_cmd cmd;