From patchwork Wed Feb 7 14:51:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 197969 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2288058dyb; Wed, 7 Feb 2024 07:03:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IErRtJ+jT+qd3/Dc2XXQfCNsLWVr+tcR/0so+lc6qxX+9Q7wyxUNEhbG3/ib/gMiJUS5XZ8 X-Received: by 2002:a17:906:3689:b0:a35:2f7a:385b with SMTP id a9-20020a170906368900b00a352f7a385bmr4299082ejc.23.1707318180689; Wed, 07 Feb 2024 07:03:00 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707318180; cv=pass; d=google.com; s=arc-20160816; b=Nyahfr1kCRIjULOporXwxSeFvVzJDniFabXj1KmQLZLbs7Wg9qlRgWSGtCPBC3x0cC VeQQI0Bxvi0tZU8b7lksMchlPfC+R4QiPrI2DuVcZ9f8OdgaiKPAimLgiJLg6TXhDqvA apTwSzo5iPPVWlEjrv5XfpJ4Imjx9Tok0OfxVLIAmGVHVzXTJG+Gb6LCBp/V78AL5Df9 QOZn7YF1A7HqwNqJYTvRK+2svOemCPl+ippk382d1rHsh4RLZlPetR/TUVftm3/pHq8J g56GT7nSp68Ok8Cb1/mjyQjsg2uPx17LKmaH8AyHeMF7DzHC55S7b09kTDsmifonjg9/ Zt4w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ux87ry6fY2cpssDKidx5KVtl6ifmP1x/qZ3f7bi/zmc=; fh=7zOQnmZUSdm9N2/gskT2qoZWVaVjhGanpYJKuLRMa5k=; b=xuqhlXWqBkixT0pZ5S9a7FekMLe0RL2qzdr4ryWKFKlz82UMsCXz7T3D+GX/bltkzg 6SSth+W4D3X1AJwiPA1oMmfHhzz7wISxPm4dvzeUidBpGcvK295jxuvCVIUtGiIoEkgQ +fbjo8+ky+P0CUnwLmgh1pQhvCT/g9yC0bYukXa9xZAixEWB2vSkUKzAbH59OTkmWdzQ WzZvndVM+9SK5hnZhIspiAcnB5ZoAA0oVr59NU/DGsBA0ASFT12Gt6IKtSfGGkXdpl1F xd5QHw7JY6tjNNtZoX2X1DiY+pknWBsVI1S3ueox0FQONP9IKE15aHoxHuMNDwrl66wT wvNw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=qN4fqeWi; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-56656-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56656-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCXzfbJ54AJHxgAM5t+YLFULgPRkuT5qTUiR/FnugBNw51t3Tz3go6utMkEXk0uZlXe5M4HuaXPr7sTaiHYtuoTprFiPBQ== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id qt28-20020a170906ecfc00b00a37de46d73dsi1011944ejb.195.2024.02.07.07.03.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 07:03:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56656-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=qN4fqeWi; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-56656-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56656-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 54E771F28D72 for ; Wed, 7 Feb 2024 14:52:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F31BD7FBAB; Wed, 7 Feb 2024 14:51:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="qN4fqeWi" Received: from mail-oi1-f176.google.com (mail-oi1-f176.google.com [209.85.167.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5D01A7F7CE for ; Wed, 7 Feb 2024 14:51:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707317497; cv=none; b=iXprocRx8F3SRySSHE/9bbrR11QdLd9KdyQBJR5eFT/BaOb2UMBsZFRHK7iEnHH2OzvuLj0gCq2csaY10j57KXr9Ib2//mV7XYU/zFo/Vnlr4I/uSC9EpRPU19weH4aGr8GnuW2EihZdHcnA7U65w97qBjvTKi3Je3BfR9bZfRE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707317497; c=relaxed/simple; bh=/KvjVNAVg8fzd2VfLqRcK/ChfH3ulQlvhCLvZrUm28c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Fyuw2DkjGbv8k8sdgLEXMOzg/aJP3meZXxw6dEGS7iijdyIgj+VBaqLY3Ineo/UPFs2oaiCAF3EnxAFs3GHlbtpw9GFAPs3fxizrWDn604wqaozWb75NL4BKFn9htfdVOD2NPu9OOwPomgD5fMkX35E8Wo37oyouTOmwTY6D2pA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=qN4fqeWi; arc=none smtp.client-ip=209.85.167.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Received: by mail-oi1-f176.google.com with SMTP id 5614622812f47-3bfdd9fa13eso396746b6e.1 for ; Wed, 07 Feb 2024 06:51:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1707317494; x=1707922294; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ux87ry6fY2cpssDKidx5KVtl6ifmP1x/qZ3f7bi/zmc=; b=qN4fqeWiDjzqu4ATPiruymN8hwI3s3lv1Cteb3D4Y2fkng7Wfc5YQ9egRRxnFp4Hun KYEm9jqOnweHsnFk/Qrwnt/P2eGXP3PHiSjh2XjbB2+Hyp3Ef/JH51gX9yVfmW/ZKdv2 TysUh+WcpaXjUGIIvsYviFtXHidY6PateqZZhm91v13iCrV/TI6DJQEmI8KVjoZ+5x/k k3aA19RGafIKxr8VmK+DxElWQkUQxuiHnrJCpfuZtV+m+E0uadW90B9H+E2LfLFlV58D e8xd/aIfTs0BnOaerubWZhc58WhT8mbT6Dwyg1k3m52B/J+34fah/RztAGfwe4fZ8/yG sKNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707317494; x=1707922294; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ux87ry6fY2cpssDKidx5KVtl6ifmP1x/qZ3f7bi/zmc=; b=RbZqni84BRNrk2yWz4eBhqXR/gDEERhTMZlpDGK6kYg25AEj0RsPHDFoJqan1Jz7Qg 8YDy63ty43hlqtDHinLtH0K0v1b9bTMGpDAJP6aPFz1FoUkrpaJsKkrmsf/ONM12MDi4 zOBe8iyEiIAfLedAGLGtVgR1YjX9OdR8xtvyTCcAchLzbCxchF2b2WjA+IKdxM180gUv rd7czP+0uZiLOltbXWIeISmx+OwnFYIjtD1SuJhBT3Rc2HxENaEO27ZaIYnLVVi7lLG2 db7gloZ3NGwntE08YhISEHlKez5pYs7AtgESu+5sPTkXplI8bau6mnqxv3iQfwfxspas R77A== X-Gm-Message-State: AOJu0YzYsaHQaxj58c3nnFLNfhif8/r8pI8zSQgz15OuY01U9ub+AubN 6nNIwBYO5y7lC0UoLNczGCYfneydIHgffugjaHj4vJDqxilJhcpe6Jo7VfhAELg= X-Received: by 2002:a05:6808:3a18:b0:3bf:e5c0:78ff with SMTP id gr24-20020a0568083a1800b003bfe5c078ffmr5809178oib.11.1707317494328; Wed, 07 Feb 2024 06:51:34 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWqvDAiqH+R2x35IJZes3f5w+JgRftkTo/8x70ZulV3Y6q731h2IqDbBbHdyFVWY6YffUKEm+QkuhZZ1Z+/8JcewULwC1pVfUzUJ+afis/0pt0kv4pB/vcTtJfb+e5eFElWqotzWxpg5r7/O2k5hbDYzzJ1Ax6ThUYSD6zgOZeNrqTBxyDbuaOAw7qZsakk3REmKg== Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id k26-20020a05680808da00b003bfe05691f3sm205856oij.9.2024.02.07.06.51.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 06:51:34 -0800 (PST) From: David Lechner To: linux-spi@vger.kernel.org Cc: David Lechner , Mark Brown , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] spi: axi-spi-engine: remove use of ida for sync id Date: Wed, 7 Feb 2024 08:51:24 -0600 Message-ID: <20240207-axi-spi-engine-round-2-1-v2-1-40c0b4e85352@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240207-axi-spi-engine-round-2-1-v2-0-40c0b4e85352@baylibre.com> References: <20240207-axi-spi-engine-round-2-1-v2-0-40c0b4e85352@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.12.4 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790252868326222729 X-GMAIL-MSGID: 1790252868326222729 Profiling has shown that ida_alloc_range() accounts for about 10% of the time spent in spi_sync() when using the AXI SPI Engine controller. This call is used to create a unique id for each SPI message to match to an IRQ when the message is complete. Since the core SPI code serializes messages in a message queue, we can only have one message in flight at a time, namely host->cur_msg. This means that we can use a fixed value instead of a unique id for each message since there can never be more than one message pending at a time. This patch removes the use of ida for the sync id and replaces it with a constant value. This simplifies the driver and improves performance. Reviewed-by: Nuno Sa Signed-off-by: David Lechner --- drivers/spi/spi-axi-spi-engine.c | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c index 6b0c72bf3395..606389566129 100644 --- a/drivers/spi/spi-axi-spi-engine.c +++ b/drivers/spi/spi-axi-spi-engine.c @@ -7,7 +7,6 @@ #include #include -#include #include #include #include @@ -57,6 +56,9 @@ #define SPI_ENGINE_TRANSFER_WRITE 0x1 #define SPI_ENGINE_TRANSFER_READ 0x2 +/* Arbitrary sync ID for use by host->cur_msg */ +#define AXI_SPI_ENGINE_CUR_MSG_SYNC_ID 0x1 + #define SPI_ENGINE_CMD(inst, arg1, arg2) \ (((inst) << 12) | ((arg1) << 8) | (arg2)) @@ -98,8 +100,6 @@ struct spi_engine_message_state { unsigned int rx_length; /** @rx_buf: Bytes not yet written to the RX FIFO. */ uint8_t *rx_buf; - /** @sync_id: ID to correlate SYNC interrupts with this message. */ - u8 sync_id; }; struct spi_engine { @@ -109,7 +109,6 @@ struct spi_engine { spinlock_t lock; void __iomem *base; - struct ida sync_ida; struct timer_list watchdog_timer; struct spi_controller *controller; @@ -483,9 +482,7 @@ static irqreturn_t spi_engine_irq(int irq, void *devid) } if (pending & SPI_ENGINE_INT_SYNC && msg) { - struct spi_engine_message_state *st = msg->state; - - if (completed_id == st->sync_id) { + if (completed_id == AXI_SPI_ENGINE_CUR_MSG_SYNC_ID) { if (timer_delete_sync(&spi_engine->watchdog_timer)) { msg->status = 0; msg->actual_length = msg->frame_length; @@ -510,10 +507,8 @@ static int spi_engine_prepare_message(struct spi_controller *host, struct spi_message *msg) { struct spi_engine_program p_dry, *p; - struct spi_engine *spi_engine = spi_controller_get_devdata(host); struct spi_engine_message_state *st; size_t size; - int ret; st = kzalloc(sizeof(*st), GFP_KERNEL); if (!st) @@ -531,18 +526,10 @@ static int spi_engine_prepare_message(struct spi_controller *host, return -ENOMEM; } - ret = ida_alloc_range(&spi_engine->sync_ida, 0, U8_MAX, GFP_KERNEL); - if (ret < 0) { - kfree(p); - kfree(st); - return ret; - } - - st->sync_id = ret; - spi_engine_compile_message(msg, false, p); - spi_engine_program_add_cmd(p, false, SPI_ENGINE_CMD_SYNC(st->sync_id)); + spi_engine_program_add_cmd(p, false, SPI_ENGINE_CMD_SYNC( + AXI_SPI_ENGINE_CUR_MSG_SYNC_ID)); st->p = p; st->cmd_buf = p->instructions; @@ -555,10 +542,8 @@ static int spi_engine_prepare_message(struct spi_controller *host, static int spi_engine_unprepare_message(struct spi_controller *host, struct spi_message *msg) { - struct spi_engine *spi_engine = spi_controller_get_devdata(host); struct spi_engine_message_state *st = msg->state; - ida_free(&spi_engine->sync_ida, st->sync_id); kfree(st->p); kfree(st); @@ -640,7 +625,6 @@ static int spi_engine_probe(struct platform_device *pdev) spi_engine = spi_controller_get_devdata(host); spin_lock_init(&spi_engine->lock); - ida_init(&spi_engine->sync_ida); timer_setup(&spi_engine->watchdog_timer, spi_engine_timeout, TIMER_IRQSAFE); spi_engine->controller = host; From patchwork Wed Feb 7 14:51:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 197970 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:168b:b0:106:860b:bbdd with SMTP id ma11csp2288299dyb; Wed, 7 Feb 2024 07:03:13 -0800 (PST) X-Google-Smtp-Source: AGHT+IEHnCz9vF/MfIF5mEZPUsFrJko4h13C9fLI+tF4zDC8HdX92M6ill7nrJ2CbN9wztY2jRkm X-Received: by 2002:a17:907:778e:b0:a37:d286:8c98 with SMTP id ky14-20020a170907778e00b00a37d2868c98mr4478057ejc.14.1707318193422; Wed, 07 Feb 2024 07:03:13 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707318193; cv=pass; d=google.com; s=arc-20160816; b=yZvRtvk/k5EtTFx5DdtFCDNzwewIKOoouvBbJ0D6K0wlExHuToh4wcPy6OXael0+ie 9SUq1uNL2q71ejpJoyt4TcVT4Bk6013bQn622TSMJNIIF+0+dx2reFSyVclqCpcTBLUK aU53F+MSIBbBYqjOt2Sbh2clc6Q4dgRADZaBrUCO0M55qayGaRokegawdRlfd14mF0UR VBo49jZd3Sga8FauUI8JSvDznFrc5ajqDkzFubPEBoZHqAKHlJYPPC3XL24rlAlSF5Zk tHUZ5HGI2pTRRcUzTSMzTJJqwygHa91/nBHLj64NltD7sIuV7xBCB/4MYsDCHG57NqKS z4cA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Ao4b426B+NqhtR2ZLveczs7D6jYQ4PDxIiN9DLi59UM=; fh=vn0tb3lHU3UaRI1V5kGu78+OKYgx/PsE0wiqvXHj358=; b=cTTZbELYadF7+F1lsDrFH4ZD/5RtSwb9EEvqIk5fuvhxrWT2CnUmtFa6hspmBmgb8c /pQf6cY/ZqtLtMbrOVROsYcMpL/JV+Nnc+M8LybTSV9lzy5Ny4uIz/EtBWJNoPBfu++I Lor8JrIFOtg3fx5uM879St+K5GWzq8d81xDCTYYZvgnvIqOoDTOcaNap7GFBYtp241al Xj8mZLK9RYRm/Jlq9TXxJm8AeCuBiHj2ZTzIVzVrLcLmFD15zhaIx8JeeuX5Rnr/5Pii UF9wHD3LzVbD1dP6relYeI3fvfeZPHdC1iYM8IPtBBoxTLzxZnFsrSCaHufqcZHoHwab nPJQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=SfKO0Saj; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-56658-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56658-ouuuleilei=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCX0w7bxcnvKwQyX/+eAaMS7OspszV2OUgOmzMhbbhX5cNXFvtGVLQNjpzi4fpmODmrxIr/YB0Y4rFJCEaeEIPbelAlfEA== Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id o24-20020a1709061d5800b00a38390723cesi916755ejh.688.2024.02.07.07.03.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 07:03:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-56658-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=SfKO0Saj; arc=pass (i=1 spf=pass spfdomain=baylibre.com dkim=pass dkdomain=baylibre-com.20230601.gappssmtp.com); spf=pass (google.com: domain of linux-kernel+bounces-56658-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-56658-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id CAECA1F28F97 for ; Wed, 7 Feb 2024 14:52:29 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C86217FBCC; Wed, 7 Feb 2024 14:51:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b="SfKO0Saj" Received: from mail-oi1-f172.google.com (mail-oi1-f172.google.com [209.85.167.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 22A307F7D4 for ; Wed, 7 Feb 2024 14:51:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707317499; cv=none; b=RaXuL0AtjB/FIUiG19fKAbquTS+OhOGq+Al4wACbsEYSsog/UK69Zf8s6KvREcK8+Mup/cCiZhTMp1cwLqoBOCDBCJAmb9KtiBj3FdE27M6Cky6gODd/uLXczIimcSvo/+aX2Nyp32cvJF5I6g3zTBbmK+A3VG10SeQDafUle6U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707317499; c=relaxed/simple; bh=0+mHBIiTkYE/oE5w4LgHz44U2EyulKRFEiitlg4y6SA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=fqy+YPfq6e6jYnGFbm/tSm7NfpKjn8Ym4jJJIlUeyToXdAt9vp46kocoMruozZRsJ1OjPL50Uis0MoLwEIWpLZRuEcnxSFqIEBn6Fj6ImHleKASy3/Czyv0LQ4m8O4+DIJlSDVsUjAOFzdemer+UFo/QcA7n98v0M2daaEWWuyw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com; spf=pass smtp.mailfrom=baylibre.com; dkim=pass (2048-bit key) header.d=baylibre-com.20230601.gappssmtp.com header.i=@baylibre-com.20230601.gappssmtp.com header.b=SfKO0Saj; arc=none smtp.client-ip=209.85.167.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=baylibre.com Received: by mail-oi1-f172.google.com with SMTP id 5614622812f47-3bfedaaeeacso313377b6e.0 for ; Wed, 07 Feb 2024 06:51:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1707317495; x=1707922295; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ao4b426B+NqhtR2ZLveczs7D6jYQ4PDxIiN9DLi59UM=; b=SfKO0SajEh8wkzzi49/Z/jenlkww/rCxmmE0xjtno9GLLTnCUCmA5XptA/2tmbA6eN gMVNo9QXwVC6OR9y3EmO0DmeRzk4ID6aTCZ7lqZ360u+dNYBXVZMI5jXMZThfafszlka VU1fbsIREk6RC8Ht/l0AburR3t6t33KWxfoXS1nk1WSqjyxgSqZfBQPWa0S95DU3sGNq OZt2m/6LdKzIKKdcSUPjlrPRM14tRNtRSf7wt7As7LMYlMXUQkJIWh4TuvamovKR+2wL tlQBBE2o2kbmzO4iMvJQv4qfo2e991FvPF35WlVv2qtdSucwi8HHDZxaHVrxOWUUe+0+ FiBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707317495; x=1707922295; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ao4b426B+NqhtR2ZLveczs7D6jYQ4PDxIiN9DLi59UM=; b=n9rcwJueTvmj2paawB/92/Ix710pTH6iuj7HSHi7MgeFb2EzIRSlkCCxYTmu98t3O8 PCsfp77Qg3mIm3hxBsxsnGOaSRGglAZcMhkioWIQS+gZvXQhi41GVs3LcqskscY1e37A qdR4x0BgV6FCxw5nNSiV/YV18Nvj1YiawiVntfwHb8ALvqYtk3//3U6l9aJLMd1Myvh4 9K36ACEUEheV5dPJPaAecAJZL06+myD+f0DVJW07XETDtvNhZ4hOavQ3mIqvHrm1Hcn1 N89hPEk5UEM3aSOKnkjuAuRj4f4A9q2b+vg/r1/bJfPuJc9TE6EwHZjm+HeqInIcKqdC RhHw== X-Gm-Message-State: AOJu0Yx5W6M5X5ktiPcIW8/BDFPgIjb9bXjf76BF+f7rIkxEEx3f2A5K V9nvfEhDg6OlPTP6As3pA/b4aLimo4jV2iCP5fOTG3jJFQ8RPlRlCSvb5QdUB4Q= X-Received: by 2002:a05:6808:148f:b0:3bf:c0bf:dcbe with SMTP id e15-20020a056808148f00b003bfc0bfdcbemr6905308oiw.6.1707317495045; Wed, 07 Feb 2024 06:51:35 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXLWnHSxUKQJVXie5Ik3MB+TQiaqcz1HhlWz0ZIolbZ8d5MjZsPMBjdjuBlEyvYEV9hmcUYI3A6WhLhJ3UB18tVhk5dSUuVcXISc7uHgUsnj9p5SjOQHUt7ezv0Idw9AcZPD7YQQctoYLmOIvUrrjPIbVOWG+FYPD3F6TAZranWfoBRgWYpH73seilUG3MVCcpGDg== Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id k26-20020a05680808da00b003bfe05691f3sm205856oij.9.2024.02.07.06.51.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 07 Feb 2024 06:51:34 -0800 (PST) From: David Lechner To: linux-spi@vger.kernel.org Cc: David Lechner , Mark Brown , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , linux-kernel@vger.kernel.org Subject: [PATCH v2 2/2] spi: axi-spi-engine: move msg finalization out of irq handler Date: Wed, 7 Feb 2024 08:51:25 -0600 Message-ID: <20240207-axi-spi-engine-round-2-1-v2-2-40c0b4e85352@baylibre.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240207-axi-spi-engine-round-2-1-v2-0-40c0b4e85352@baylibre.com> References: <20240207-axi-spi-engine-round-2-1-v2-0-40c0b4e85352@baylibre.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.12.4 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790252881705707730 X-GMAIL-MSGID: 1790252881705707730 As a general principal, it is best to do as little as possible in an interrupt handler. This patch reworks the AXI SPI Engine driver to move timer_delete_sync() and spi_finalize_current_message() out of the interrupt handler. Instead, spi_finalize_current_message() is moved to the transfer_one_message function (similar to nearly all other SPI controllers). A completion is now used to wait for the sync interrupt that indicates that the message is complete. The watchdog timer is no longer needed since we can use the wait_for_completion_timeout() function to wait for the message to complete with the same effect. As a bonus, these changes also improve throughput of the SPI controller. For example, this was tested on a ZynqMP with a 80MHz SCLK reading 4 byte samples from an ADC. The max measured throughput increased from 26k to 28k samples per second. Reviewed-by: Nuno Sa Signed-off-by: David Lechner --- drivers/spi/spi-axi-spi-engine.c | 40 +++++++++++++++------------------------- 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/drivers/spi/spi-axi-spi-engine.c b/drivers/spi/spi-axi-spi-engine.c index 606389566129..ca66d202f0e2 100644 --- a/drivers/spi/spi-axi-spi-engine.c +++ b/drivers/spi/spi-axi-spi-engine.c @@ -6,6 +6,7 @@ */ #include +#include #include #include #include @@ -13,7 +14,6 @@ #include #include #include -#include #define SPI_ENGINE_REG_RESET 0x40 @@ -109,9 +109,7 @@ struct spi_engine { spinlock_t lock; void __iomem *base; - struct timer_list watchdog_timer; - struct spi_controller *controller; - + struct completion msg_complete; unsigned int int_enable; }; @@ -483,11 +481,9 @@ static irqreturn_t spi_engine_irq(int irq, void *devid) if (pending & SPI_ENGINE_INT_SYNC && msg) { if (completed_id == AXI_SPI_ENGINE_CUR_MSG_SYNC_ID) { - if (timer_delete_sync(&spi_engine->watchdog_timer)) { - msg->status = 0; - msg->actual_length = msg->frame_length; - spi_finalize_current_message(host); - } + msg->status = 0; + msg->actual_length = msg->frame_length; + complete(&spi_engine->msg_complete); disable_int |= SPI_ENGINE_INT_SYNC; } } @@ -558,7 +554,7 @@ static int spi_engine_transfer_one_message(struct spi_controller *host, unsigned int int_enable = 0; unsigned long flags; - mod_timer(&spi_engine->watchdog_timer, jiffies + msecs_to_jiffies(5000)); + reinit_completion(&spi_engine->msg_complete); spin_lock_irqsave(&spi_engine->lock, flags); @@ -580,21 +576,16 @@ static int spi_engine_transfer_one_message(struct spi_controller *host, spi_engine->int_enable = int_enable; spin_unlock_irqrestore(&spi_engine->lock, flags); - return 0; -} - -static void spi_engine_timeout(struct timer_list *timer) -{ - struct spi_engine *spi_engine = from_timer(spi_engine, timer, watchdog_timer); - struct spi_controller *host = spi_engine->controller; - - if (WARN_ON(!host->cur_msg)) - return; + if (!wait_for_completion_timeout(&spi_engine->msg_complete, + msecs_to_jiffies(5000))) { + dev_err(&host->dev, + "Timeout occurred while waiting for transfer to complete. Hardware is probably broken.\n"); + msg->status = -ETIMEDOUT; + } - dev_err(&host->dev, - "Timeout occurred while waiting for transfer to complete. Hardware is probably broken.\n"); - host->cur_msg->status = -ETIMEDOUT; spi_finalize_current_message(host); + + return msg->status; } static void spi_engine_release_hw(void *p) @@ -625,8 +616,7 @@ static int spi_engine_probe(struct platform_device *pdev) spi_engine = spi_controller_get_devdata(host); spin_lock_init(&spi_engine->lock); - timer_setup(&spi_engine->watchdog_timer, spi_engine_timeout, TIMER_IRQSAFE); - spi_engine->controller = host; + init_completion(&spi_engine->msg_complete); spi_engine->clk = devm_clk_get_enabled(&pdev->dev, "s_axi_aclk"); if (IS_ERR(spi_engine->clk))