From patchwork Mon Feb 19 22:33:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13563144 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D9212C48BC3 for ; Mon, 19 Feb 2024 22:35:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=OhH0tGNPXK1yrMCxFNFH7mugvcbAVAhQRr0wLA7w2vM=; b=SeOd+fbYOM9v3b TB5/UGvSE8NkH8GxMTqiNxht7OYRCIQEZVrG+9Dl22AxylFagrS5fQ9M8BMvlflgOCndDotxAMRWl 01m23bkPcFnSVZ97kthOCZ66Ip9QuibDja2AZTDZkYPISH54cX/NmHPC14VZbzuAkKsKi2+6Fhik7 wPxdXbVxacM506lGrXJcznhEA+gb8ZHzFkSDQrw7tkH69mnHc4ewZUox/fBIKTO+UIJpSS5/OTcoA t2vXt6R2IHY+eiQupKRC5BpIyW5YQc6+ZwO4EBgeqUutKCHzFcdFVMekUir+gu2+Zrw+k7J56hJPF j0Kw2xOOAY/ek9k9Vc6g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rcCE3-0000000COsy-1EW0; Mon, 19 Feb 2024 22:35:03 +0000 Received: from mail-ot1-x32e.google.com ([2607:f8b0:4864:20::32e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rcCDz-0000000COo2-2KFB for linux-arm-kernel@lists.infradead.org; Mon, 19 Feb 2024 22:35:01 +0000 Received: by mail-ot1-x32e.google.com with SMTP id 46e09a7af769-6e44a309b6fso692922a34.1 for ; Mon, 19 Feb 2024 14:34:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1708382096; x=1708986896; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=gpwEAehth1tWZQpA0TjLevm8DWTiiteNXTP4U1INUoM=; b=vqS0kPpXTZDcfuuZ9L7xKtTxo47vh3hSWnHRHv+mHoVvn56UiT8y27Rbsvrr+M9tBq KuujkPBd8ZX4mCwoL6XOrUfFcoVPlmX2m8kKNE/zrmSXEibtlSLMeEwjpjrbmXhSLyqL Kyh5+lmZpE6U/fYDZim9R8j77k6EmkHRHS09ixxtpaVUHXiEx/SPgz/pyF61tICbkBZk G6motkjbHRjaYaxQDhYTPatHpIwQZxoaevtxiJ+xfZ4cetC0KNX4OnKajvG8FBD5ugbA HcUJywHLFHnwLM1NodlSk54d9RteSxg5Iio+8REjMSfkxK4VxBsLbImyD8E4zjsvR0GO RJmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708382096; x=1708986896; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=gpwEAehth1tWZQpA0TjLevm8DWTiiteNXTP4U1INUoM=; b=P6hf0J0ya1zUOQ8Kv0SS9ApFhB42F2Ln3829X6CMa96Rwcg48P9qH01YuAHlNINFLY R8rit3dhXP+S55ixhkYvL3LEglVuTdnOhl6tk0BhMsmt+kcABn0wDbwgV9EzKzuTJomP dCnf9iUVnMtP32k5tPFr8TXkDEn/HzCZ9HNFhO8XnQXXUNfRDZky7E1i4SqqBOIMIXKx aeXsVIIX/6VZFJiwWnphS1P68NhyW+BsaH29hpas4KAZVVQkTNnBaHFVlTdKlmeaM9Lm wiIaov0t9ROlEme80IKGA09T4isXkG+yClqOuUY743iqmOBv5wkaGF7G9h3CMmAwc8wf VkJQ== X-Forwarded-Encrypted: i=1; AJvYcCVVoG+8piOtrBy/O4y+GdXsnhp0+b2Bnj1V8AjYFjXGTD40o7m4TxcJ1LfbeLoSTAPlSVHuN76TEznmWDhv1DmkcdsO+bC51+bhBS/NfngbOrjzOks= X-Gm-Message-State: AOJu0YwdCZl66Q9auoUZrmfGWtkOvjRbEq0+MmIAoeH3f+zv4Vfc9sko ojoFmL3s9KXhjhAcM9YtY/CDdgG7XYMsEjGft1BTnHGcYkqmqHRDI6XNWT3CAP0= X-Google-Smtp-Source: AGHT+IE2e9IPdvZzRdmlGUC/m+SCrl+vlfAO1vOVWnmmv6s7Y3hILnYtoJnl9bqMN42qD9thWqnGRA== X-Received: by 2002:a05:6830:4cb:b0:6e4:3cef:5e0b with SMTP id s11-20020a05683004cb00b006e43cef5e0bmr8226071otd.13.1708382096244; Mon, 19 Feb 2024 14:34:56 -0800 (PST) Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id h25-20020a9d6419000000b006e45a5f0a70sm171776otl.49.2024.02.19.14.34.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 14:34:55 -0800 (PST) From: David Lechner To: Mark Brown Cc: David Lechner , Martin Sperl , David Jander , Jonathan Cameron , Michael Hennerich , =?utf-8?q?Nuno_S=C3=A1?= , Alain Volmat , Maxime Coquelin , Alexandre Torgue , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-iio@vger.kernel.org, Julien Stephan , Jonathan Cameron Subject: [PATCH v2 0/5] spi: add support for pre-cooking messages Date: Mon, 19 Feb 2024 16:33:17 -0600 Message-ID: <20240219-mainline-spi-precook-message-v2-0-4a762c6701b9@baylibre.com> X-Mailer: git-send-email 2.43.2 MIME-Version: 1.0 X-Mailer: b4 0.12.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240219_143459_641952_DC94D9E6 X-CRM114-Status: GOOD ( 17.40 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This is a follow-up to [1] where it was suggested to break down the proposed SPI offload support into smaller series. This takes on the first suggested task of introducing an API to "pre-cook" SPI messages. This idea was first discussed extensively in 2013 [2][3] and revisited more briefly 2022 [4]. The goal here is to be able to improve performance (higher throughput, and reduced CPU usage) by allowing peripheral drivers that use the same struct spi_message repeatedly to "pre-cook" the message once to avoid repeating the same validation, and possibly other operations each time the message is sent. This series includes __spi_validate() and the automatic splitting of xfers in the optimizations. Another frequently suggested optimization is doing DMA mapping only once. This is not included in this series, but can be added later (preferably by someone with a real use case for it). To show how this all works and get some real-world measurements, this series includes the core changes, optimization of a SPI controller driver, and optimization of an ADC driver. This test case was only able to take advantage of the single validation optimization, since it didn't require splitting transfers. With these changes, CPU usage of the threaded interrupt handler, which calls spi_sync(), was reduced from 83% to 73% while at the same time the sample rate (frequency of SPI xfers) was increased from 20kHz to 25kHz. [1]: https://lore.kernel.org/linux-spi/20240109-axi-spi-engine-series-3-v1-1-e42c6a986580@baylibre.com/T/ [2]: https://lore.kernel.org/linux-spi/E81F4810-48DD-41EE-B110-D0D848B8A510@martin.sperl.org/T/ [3]: https://lore.kernel.org/linux-spi/39DEC004-10A1-47EF-9D77-276188D2580C@martin.sperl.org/T/ [4]: https://lore.kernel.org/linux-spi/20220525163946.48ea40c9@erd992/T/ --- Changes in v2: - Removed pre_optimized parameter from __spi_optimize_message() - Added comment explaining purpose of pre_optimized flag - Fixed missing doc comment for @pre_optimized - Removed kernel doc inclusion (/** -> /*) from static members - Removed unrelated comment about calling spi_finalize_current_message() - Reworked IIO driver patch - Link to v1: https://lore.kernel.org/r/20240212-mainline-spi-precook-message-v1-0-a2373cd72d36@baylibre.com --- David Lechner (5): spi: add spi_optimize_message() APIs spi: move splitting transfers to spi_optimize_message() spi: stm32: move splitting transfers to optimize_message spi: axi-spi-engine: move message compile to optimize_message iio: adc: ad7380: use spi_optimize_message() drivers/iio/adc/ad7380.c | 36 +++++- drivers/spi/spi-axi-spi-engine.c | 40 +++--- drivers/spi/spi-stm32.c | 28 +++-- drivers/spi/spi.c | 259 ++++++++++++++++++++++++++++++++------- include/linux/spi/spi.h | 20 +++ 5 files changed, 297 insertions(+), 86 deletions(-) --- base-commit: 55072343f1df834879b8bae9e419cd5cbb5f3259 prerequisite-patch-id: 844c06b6caf25a2724e130dfa7999dc90dd26fde change-id: 20240208-mainline-spi-precook-message-189b2f08ba7f