Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp697607pxj; Wed, 2 Jun 2021 09:10:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyq44HHICvAbT5Q8etVN7FbTFZaUGnjvjO3lPq3OhiuSVoHE9T7TYOMvEDTcwst3HQEn72c X-Received: by 2002:a17:906:f84:: with SMTP id q4mr36371381ejj.442.1622650229661; Wed, 02 Jun 2021 09:10:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622650229; cv=none; d=google.com; s=arc-20160816; b=WrLUgzK1ojrdIpIxnyIAjVDpR7zHwIEHa9PJXoGXrimbevpc6XLzFGCxSm4l9QlhZl G4xIRxXK2Tvaek98ol3vKyjTFhV/J7o031rjifWCT5Mxkzy2kFKRn4DRRtR+1nQCLtPQ mmwi5ujTWXQw+9/dZo/UCH0zaFjzDqQGtUWijeuTbe9+V+lCfCK2ypEcuhihyNHr7mnQ JE5pxlmor0pUAUVP7rQqFGgosUlQ09Ftk3K1WfnDHLFJ7RVTTs3MF0XDiyM05uf8aNpn TES0UGqbKofCRARu7fwtWgaq9kfe/e/kF/sNeiybzCNOoBLOg5PET33LXm+vl+WS/Cu6 MpDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:ironport-sdr:dkim-signature; bh=iRk/CaFPWAqzdUH/ceI3at5mugoNy40RJwXXz7aSUYU=; b=KWP3Hl/Uysfk6VnexZIer+RfxLA1ubBMdYeg/YFuILykpeFtsRge7CuVCFbufCHYgs OLpQGrVQplL2RNtdh8rUIlup5QUzv1v+KZvJSknbc6lTZ8o1tu2NSEZCAXV02F2Bjeiu gpHqd4PggrQm3VZN1UcfDE0i4i/+0DOmmsP9Tzug3kXOO8LCnGlk69FZ+QiQ+WLGAYyV qmfwSsYtfNCbaUjAvxktYBFnUM8b/JchZalDqpZN3M/GzgILobd1ygsjj1ZAFuChcK6Q WDYrxsJGE959wUass3gyv6XoviQ2EhGO878kdBREV8e00iY7LR4GCONjb2vmku/y/ch/ BMtQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@microchip.com header.s=mchp header.b=HiH2upfN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v7si292478edj.318.2021.06.02.09.10.06; Wed, 02 Jun 2021 09:10:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=fail header.i=@microchip.com header.s=mchp header.b=HiH2upfN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=microchip.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229980AbhFBQKW (ORCPT + 99 others); Wed, 2 Jun 2021 12:10:22 -0400 Received: from esa.microchip.iphmx.com ([68.232.153.233]:16512 "EHLO esa.microchip.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229817AbhFBQKU (ORCPT ); Wed, 2 Jun 2021 12:10:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1622650118; x=1654186118; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=xM1Z4XPCdE5QfVSLjvhJSs57E9XcJ2Y6MAuOiSOnj9U=; b=HiH2upfNOCpBPWXzXNPyx8w1HjM3qqbJvoTgT1T9e+ZWrqpaXlRrfa+D 52id4VbV29ZXKYfpTzCizlsGDGuDekPDuwU0iU89yJnpN7a/YVA80bZWF kV3KlCWiUbcFwSveJv8MDL72YwrqXr+j2YQ+mWRBUS9SEeid87MmLQFvG V4alnpVEYxfufvonv8H3V9BLiDuc8B/CCdscd78X2HJCgYhgEY0HxIig/ NTnH1UjDOKp5gmBbSuyeUIvbO3PWfrpBmy8QZMbyq+Va9W4g9OQM/mxzP aghmAVmDqxoeYDewioq9/tkBRRIelBCHqpWUMQXpuKG8M/TVz/hvS/+3i Q==; IronPort-SDR: lnKl10SvjnU5CCbCAzOVyTkuRemZZf9aV2vQmLZBkqnlh0mZGVM7+AR2oOaQl5SPwwu4Eyv2SW innJFxDpjploJtbMbDkiv4amsqHM/ZbsF0Xju/QU3JW/7Nr10UpUc/NH881V7rCJnbq4qwcSQ7 MIu86H9RTV5R9U1uP3YBb7XUxOAHYgF82GTPGvyuyK3PfeUBoDDN1/rKhuYku0DvkAhZXpJ3RH 09P9gNKxiFzkmvRsycUQCE+mJctnHOhjDIprSXhRYe0t+K2ZzohTt91TA6xF1tPw6cWRHRLeGP fyQ= X-IronPort-AV: E=Sophos;i="5.83,242,1616482800"; d="scan'208";a="123275443" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa5.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 02 Jun 2021 09:08:38 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Wed, 2 Jun 2021 09:08:36 -0700 Received: from dan-linux.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2176.2 via Frontend Transport; Wed, 2 Jun 2021 09:08:36 -0700 From: Dan Sneddon To: , , CC: Dan Sneddon , Tudor Ambarus , Mark Brown , Nicolas Ferre , Alexandre Belloni , Ludovic Desroches Subject: [PATCH 2/2] spi: atmel: Reduce spin lock usage Date: Wed, 2 Jun 2021 09:08:15 -0700 Message-ID: <20210602160816.4890-2-dan.sneddon@microchip.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210602160816.4890-1-dan.sneddon@microchip.com> References: <20210602160816.4890-1-dan.sneddon@microchip.com> MIME-Version: 1.0 Content-Type: text/plain Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The current implementation of the driver holds a spin lock for the duration of the transfer, releasing it only to enable interrupts for short periods of time. As this would prevent any interrupt from happening, this could cause system performance issues every time a SPI message is sent. Since the spi core now handles message syncronization we can reduce the amount of time the spin-lock is held to the regions where both the calling thread and the interrupt might interract. Signed-off-by: Dan Sneddon --- drivers/spi/spi-atmel.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c index 0e693e72c922..2ef74885ffa2 100644 --- a/drivers/spi/spi-atmel.c +++ b/drivers/spi/spi-atmel.c @@ -700,7 +700,6 @@ static void atmel_spi_next_xfer_pio(struct spi_master *master, static int atmel_spi_next_xfer_dma_submit(struct spi_master *master, struct spi_transfer *xfer, u32 *plen) - __must_hold(&as->lock) { struct atmel_spi *as = spi_master_get_devdata(master); struct dma_chan *rxchan = master->dma_rx; @@ -716,8 +715,6 @@ static int atmel_spi_next_xfer_dma_submit(struct spi_master *master, if (!rxchan || !txchan) return -ENODEV; - /* release lock for DMA operations */ - atmel_spi_unlock(as); *plen = xfer->len; @@ -786,15 +783,12 @@ static int atmel_spi_next_xfer_dma_submit(struct spi_master *master, rxchan->device->device_issue_pending(rxchan); txchan->device->device_issue_pending(txchan); - /* take back lock */ - atmel_spi_lock(as); return 0; err_dma: spi_writel(as, IDR, SPI_BIT(OVRES)); atmel_spi_stop_dma(master); err_exit: - atmel_spi_lock(as); return -ENOMEM; } @@ -1053,8 +1047,6 @@ atmel_spi_pump_pio_data(struct atmel_spi *as, struct spi_transfer *xfer) /* Interrupt * - * No need for locking in this Interrupt handler: done_status is the - * only information modified. */ static irqreturn_t atmel_spi_pio_interrupt(int irq, void *dev_id) @@ -1302,8 +1294,6 @@ static int atmel_spi_one_transfer(struct spi_master *master, unsigned long dma_timeout; as = spi_master_get_devdata(master); - /* This lock was orignally taken in atmel_spi_trasfer_one_message */ - atmel_spi_lock(as); asd = spi->controller_state; bits = (asd->csr >> 4) & 0xf; @@ -1332,7 +1322,9 @@ static int atmel_spi_one_transfer(struct spi_master *master, reinit_completion(&as->xfer_completion); if (as->use_pdc) { + atmel_spi_lock(as); atmel_spi_pdc_next_xfer(master, xfer); + atmel_spi_unlock(as); } else if (atmel_spi_use_dma(as, xfer)) { len = as->current_remaining_bytes; ret = atmel_spi_next_xfer_dma_submit(master, @@ -1348,14 +1340,13 @@ static int atmel_spi_one_transfer(struct spi_master *master, as->current_remaining_bytes = 0; } } else { + atmel_spi_lock(as); atmel_spi_next_xfer_pio(master, xfer); + atmel_spi_unlock(as); } - /* interrupts are disabled, so free the lock for schedule */ - atmel_spi_unlock(as); dma_timeout = wait_for_completion_timeout(&as->xfer_completion, SPI_DMA_TIMEOUT); - atmel_spi_lock(as); if (WARN_ON(dma_timeout == 0)) { dev_err(&spi->dev, "spi transfer timeout\n"); as->done_status = -EIO; @@ -1403,8 +1394,6 @@ static int atmel_spi_one_transfer(struct spi_master *master, if (as->use_pdc) atmel_spi_disable_pdc_transfer(as); - atmel_spi_unlock(as); - return as->done_status; } -- 2.17.1