From patchwork Wed Apr 12 19:13:20 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uma Krishnan X-Patchwork-Id: 9678239 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 0A06760382 for ; Wed, 12 Apr 2017 19:13:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E9CEF28633 for ; Wed, 12 Apr 2017 19:13:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DD5C528637; Wed, 12 Apr 2017 19:13:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3582328633 for ; Wed, 12 Apr 2017 19:13:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752870AbdDLTNk (ORCPT ); Wed, 12 Apr 2017 15:13:40 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:39005 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752304AbdDLTNk (ORCPT ); Wed, 12 Apr 2017 15:13:40 -0400 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v3CJ9FMN089359 for ; Wed, 12 Apr 2017 15:13:39 -0400 Received: from e31.co.us.ibm.com (e31.co.us.ibm.com [32.97.110.149]) by mx0a-001b2d01.pphosted.com with ESMTP id 29ssdkaaq7-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 12 Apr 2017 15:13:39 -0400 Received: from localhost by e31.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 12 Apr 2017 13:13:38 -0600 Received: from b03cxnp07028.gho.boulder.ibm.com (9.17.130.15) by e31.co.us.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 12 Apr 2017 13:13:36 -0600 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v3CJDRwb17367298; Wed, 12 Apr 2017 12:13:27 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id EBE3B78043; Wed, 12 Apr 2017 13:13:26 -0600 (MDT) Received: from p8tul1-build.aus.stglabs.ibm.com (unknown [9.3.141.206]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP id 3E8C978038; Wed, 12 Apr 2017 13:13:26 -0600 (MDT) From: Uma Krishnan To: linux-scsi@vger.kernel.org, James Bottomley , "Martin K. Petersen" , "Matthew R. Ochs" , "Manoj N. Kumar" Cc: linuxppc-dev@lists.ozlabs.org, Ian Munsie , Andrew Donnellan , Frederic Barrat , Christophe Lombard Subject: [PATCH 03/17] cxlflash: Implement IRQ polling for RRQ processing Date: Wed, 12 Apr 2017 14:13:20 -0500 X-Mailer: git-send-email 2.1.0 In-Reply-To: <1492024215-55579-1-git-send-email-ukrishn@linux.vnet.ibm.com> References: <1492024215-55579-1-git-send-email-ukrishn@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17041219-8235-0000-0000-00000B4D41FE X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006924; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000208; SDB=6.00846634; UDB=6.00417626; IPR=6.00625072; BA=6.00005286; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00015025; XFM=3.00000013; UTC=2017-04-12 19:13:37 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17041219-8236-0000-0000-00003B172617 Message-Id: <1492024400-55734-1-git-send-email-ukrishn@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-04-12_15:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1702020001 definitions=main-1704120157 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: "Matthew R. Ochs" Currently, RRQ processing takes place on hardware interrupt context. This can be a heavy burden in some environments due to the overhead encountered while completing RRQ entries. In an effort to improve system performance, use the IRQ polling API to schedule this processing on softirq context. This function will be disabled by default until starting values can be established for the hardware supported by this driver. Signed-off-by: Matthew R. Ochs Signed-off-by: Uma Krishnan --- drivers/scsi/cxlflash/common.h | 8 +++ drivers/scsi/cxlflash/main.c | 123 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 127 insertions(+), 4 deletions(-) diff --git a/drivers/scsi/cxlflash/common.h b/drivers/scsi/cxlflash/common.h index 9d56b8c..3ff05f1 100644 --- a/drivers/scsi/cxlflash/common.h +++ b/drivers/scsi/cxlflash/common.h @@ -15,6 +15,7 @@ #ifndef _CXLFLASH_COMMON_H #define _CXLFLASH_COMMON_H +#include #include #include #include @@ -196,10 +197,17 @@ struct afu { char version[16]; u64 interface_version; + u32 irqpoll_weight; + struct irq_poll irqpoll; struct cxlflash_cfg *parent; /* Pointer back to parent cxlflash_cfg */ }; +static inline bool afu_is_irqpoll_enabled(struct afu *afu) +{ + return !!afu->irqpoll_weight; +} + static inline bool afu_is_cmd_mode(struct afu *afu, u64 cmd_mode) { u64 afu_cap = afu->interface_version >> SISL_INTVER_CAP_SHIFT; diff --git a/drivers/scsi/cxlflash/main.c b/drivers/scsi/cxlflash/main.c index 8c207ba..30d68af 100644 --- a/drivers/scsi/cxlflash/main.c +++ b/drivers/scsi/cxlflash/main.c @@ -554,7 +554,7 @@ static void free_mem(struct cxlflash_cfg *cfg) * Safe to call with AFU in a partially allocated/initialized state. * * Cancels scheduled worker threads, waits for any active internal AFU - * commands to timeout and then unmaps the MMIO space. + * commands to timeout, disables IRQ polling and then unmaps the MMIO space. */ static void stop_afu(struct cxlflash_cfg *cfg) { @@ -565,6 +565,8 @@ static void stop_afu(struct cxlflash_cfg *cfg) if (likely(afu)) { while (atomic_read(&afu->cmds_active)) ssleep(1); + if (afu_is_irqpoll_enabled(afu)) + irq_poll_disable(&afu->irqpoll); if (likely(afu->afu_map)) { cxl_psa_unmap((void __iomem *)afu->afu_map); afu->afu_map = NULL; @@ -1158,12 +1160,13 @@ static irqreturn_t cxlflash_sync_err_irq(int irq, void *data) * process_hrrq() - process the read-response queue * @afu: AFU associated with the host. * @doneq: Queue of commands harvested from the RRQ. + * @budget: Threshold of RRQ entries to process. * * This routine must be called holding the disabled RRQ spin lock. * * Return: The number of entries processed. */ -static int process_hrrq(struct afu *afu, struct list_head *doneq) +static int process_hrrq(struct afu *afu, struct list_head *doneq, int budget) { struct afu_cmd *cmd; struct sisl_ioasa *ioasa; @@ -1175,7 +1178,7 @@ static int process_hrrq(struct afu *afu, struct list_head *doneq) *hrrq_end = afu->hrrq_end, *hrrq_curr = afu->hrrq_curr; - /* Process however many RRQ entries that are ready */ + /* Process ready RRQ entries up to the specified budget (if any) */ while (true) { entry = *hrrq_curr; @@ -1204,6 +1207,9 @@ static int process_hrrq(struct afu *afu, struct list_head *doneq) atomic_inc(&afu->hsq_credits); num_hrrq++; + + if (budget > 0 && num_hrrq >= budget) + break; } afu->hrrq_curr = hrrq_curr; @@ -1229,6 +1235,32 @@ static void process_cmd_doneq(struct list_head *doneq) } /** + * cxlflash_irqpoll() - process a queue of harvested RRQ commands + * @irqpoll: IRQ poll structure associated with queue to poll. + * @budget: Threshold of RRQ entries to process per poll. + * + * Return: The number of entries processed. + */ +static int cxlflash_irqpoll(struct irq_poll *irqpoll, int budget) +{ + struct afu *afu = container_of(irqpoll, struct afu, irqpoll); + unsigned long hrrq_flags; + LIST_HEAD(doneq); + int num_entries = 0; + + spin_lock_irqsave(&afu->hrrq_slock, hrrq_flags); + + num_entries = process_hrrq(afu, &doneq, budget); + if (num_entries < budget) + irq_poll_complete(irqpoll); + + spin_unlock_irqrestore(&afu->hrrq_slock, hrrq_flags); + + process_cmd_doneq(&doneq); + return num_entries; +} + +/** * cxlflash_rrq_irq() - interrupt handler for read-response queue (normal path) * @irq: Interrupt number. * @data: Private data provided at interrupt registration, the AFU. @@ -1243,7 +1275,14 @@ static irqreturn_t cxlflash_rrq_irq(int irq, void *data) int num_entries = 0; spin_lock_irqsave(&afu->hrrq_slock, hrrq_flags); - num_entries = process_hrrq(afu, &doneq); + + if (afu_is_irqpoll_enabled(afu)) { + irq_poll_sched(&afu->irqpoll); + spin_unlock_irqrestore(&afu->hrrq_slock, hrrq_flags); + return IRQ_HANDLED; + } + + num_entries = process_hrrq(afu, &doneq, -1); spin_unlock_irqrestore(&afu->hrrq_slock, hrrq_flags); if (num_entries == 0) @@ -1588,6 +1627,11 @@ static int start_afu(struct cxlflash_cfg *cfg) atomic_set(&afu->hsq_credits, NUM_SQ_ENTRY - 1); } + /* Initialize IRQ poll */ + if (afu_is_irqpoll_enabled(afu)) + irq_poll_init(&afu->irqpoll, afu->irqpoll_weight, + cxlflash_irqpoll); + rc = init_global(cfg); dev_dbg(dev, "%s: returning rc=%d\n", __func__, rc); @@ -2225,6 +2269,75 @@ static ssize_t port1_lun_table_show(struct device *dev, } /** + * irqpoll_weight_show() - presents the current IRQ poll weight for the host + * @dev: Generic device associated with the host. + * @attr: Device attribute representing the IRQ poll weight. + * @buf: Buffer of length PAGE_SIZE to report back the current IRQ poll + * weight in ASCII. + * + * An IRQ poll weight of 0 indicates polling is disabled. + * + * Return: The size of the ASCII string returned in @buf. + */ +static ssize_t irqpoll_weight_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct cxlflash_cfg *cfg = shost_priv(class_to_shost(dev)); + struct afu *afu = cfg->afu; + + return scnprintf(buf, PAGE_SIZE, "%u\n", afu->irqpoll_weight); +} + +/** + * irqpoll_weight_store() - sets the current IRQ poll weight for the host + * @dev: Generic device associated with the host. + * @attr: Device attribute representing the IRQ poll weight. + * @buf: Buffer of length PAGE_SIZE containing the desired IRQ poll + * weight in ASCII. + * @count: Length of data resizing in @buf. + * + * An IRQ poll weight of 0 indicates polling is disabled. + * + * Return: The size of the ASCII string returned in @buf. + */ +static ssize_t irqpoll_weight_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct cxlflash_cfg *cfg = shost_priv(class_to_shost(dev)); + struct device *cfgdev = &cfg->dev->dev; + struct afu *afu = cfg->afu; + u32 weight; + int rc; + + rc = kstrtouint(buf, 10, &weight); + if (rc) + return -EINVAL; + + if (weight > 256) { + dev_info(cfgdev, + "Invalid IRQ poll weight. It must be 256 or less.\n"); + return -EINVAL; + } + + if (weight == afu->irqpoll_weight) { + dev_info(cfgdev, + "Current IRQ poll weight has the same weight.\n"); + return -EINVAL; + } + + if (afu_is_irqpoll_enabled(afu)) + irq_poll_disable(&afu->irqpoll); + + afu->irqpoll_weight = weight; + + if (weight > 0) + irq_poll_init(&afu->irqpoll, weight, cxlflash_irqpoll); + + return count; +} + +/** * mode_show() - presents the current mode of the device * @dev: Generic device associated with the device. * @attr: Device attribute representing the device mode. @@ -2250,6 +2363,7 @@ static DEVICE_ATTR_RW(lun_mode); static DEVICE_ATTR_RO(ioctl_version); static DEVICE_ATTR_RO(port0_lun_table); static DEVICE_ATTR_RO(port1_lun_table); +static DEVICE_ATTR_RW(irqpoll_weight); static struct device_attribute *cxlflash_host_attrs[] = { &dev_attr_port0, @@ -2258,6 +2372,7 @@ static struct device_attribute *cxlflash_host_attrs[] = { &dev_attr_ioctl_version, &dev_attr_port0_lun_table, &dev_attr_port1_lun_table, + &dev_attr_irqpoll_weight, NULL };