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: 771195 Received: from mail-oi1-f169.google.com (mail-oi1-f169.google.com [209.85.167.169]) (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 620D97F7D0 for ; Wed, 7 Feb 2024 14:51:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707317497; cv=none; b=SMBm+bPbhf4b9DfLSj/coJXR9OzzAKik3PdwTXiwrl58wOFis1iyzsbq+w8RgRNibNEfUumg4UNNzPNgL+NfcR1Eo0qdR5R3nIxrXhS2NhRmVYnnt3TbE0wv4KRoYkV70tblj86SRe99eRbiU/eBIQRyuubXv2Db2zqdZ9MhOdA= 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.169 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 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: by mail-oi1-f169.google.com with SMTP id 5614622812f47-3bbc649c275so426528b6e.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=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=P+Iulq7uYt6o8OyNzqzlDbDNrgMeS2mHVFfhzOTOR7o6p5nSjFhyyLmCRqM/m5qwY2 9ZTmtKlo7r5sQLstJo0qOuzwIBgD75XufvjM11V1lo6OsdMUKaUDjkpIWBvPNJKLNanT jikW/zYVE/7ycF9m4TCeO4vtUNxZUq9wsWe8s3PzGDZXq6LXaAvhAJ8zNHhc8AtxmapY y9d9Iy437glR5LnFLdIKBx6kpgVPsMAig1pg020BNr2yHrHOW1YrcEKMzANINyuiyVg0 vM3YEgJZLJzIjuTrAXgBG7bChfh8vrP3/2xvguHxDy7onDbMN3eSPUA4hW/hKjAmC/dI XlMw== X-Gm-Message-State: AOJu0Yx729Mtl3y7T3KKkn2VWwUxaiJ3QWzqyByqUybXadCXrturcrWE StIs5S3rdA69qBAp0/84BrafcwbHE88/lmhITaXlYKGNcwuS5PBvp0vvYd1oq4tNEzavkT+3jUW s X-Google-Smtp-Source: AGHT+IF49KbxP1ujx11aBVx51qbYUQPqkJU32gXuwc8srgoc4C/ywi4+Fifz6S7CAXtkLARc4Reliw== 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-spi@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Mailer: b4 0.12.4 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;