From patchwork Mon Feb 12 23:26:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Lechner X-Patchwork-Id: 13554144 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 2F6F3C4829E for ; Mon, 12 Feb 2024 23:28:10 +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=FmRWiqQzfz4OQ5IVcferq7J9GbTw9JhBHmgzSX2/OII=; b=bcT3re6Atll+X1 3csJsAuXzJIFn1mVFL7RKLsDulFuYDJcPHTG7n0NNK9jA8UTBkATKljnk18hl4T66Fc1xsxBVcq+d WOVU73kkfU57ggi2dco95gn2z5zu0CrjZ+cTZ57+swrzxGVZTFKiVyEArgtP5J8qFul5f5SCT3TQ4 5VSxCRaoqLre10OdoD0bqz+cRSbaaugXzHJ4TEEecVwBw2qymaE3NC4kxb+A9M8wSYtxDKQz7aikA vDRK5BQ8CG8/wGEawN9GkcCF7xJ/qt7QUIAjVKDc3df+aZ+LErXnHJ8xflkug/JvhUyYKUmlHi4Zj WQfnUS950JJIBLWBC5Zw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZfiS-00000007Grf-29Pr; Mon, 12 Feb 2024 23:28:00 +0000 Received: from mail-ot1-x330.google.com ([2607:f8b0:4864:20::330]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZfiN-00000007Gok-33No for linux-arm-kernel@lists.infradead.org; Mon, 12 Feb 2024 23:27:58 +0000 Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-6e2dfa17547so1047645a34.2 for ; Mon, 12 Feb 2024 15:27:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1707780474; x=1708385274; 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=3+egtMFSB5wP/JnRwyX/FLjZ4VS6y7AaGO4xFQVkuUk=; b=UzgyjdOedN9pae3Px6uCDZNVtNVwEssZYjtH91HwEgpJtf8zxCwft/t4MyI3rYlckd MFjG8i74CcxwKCOTjek5SsVAjBYDzNFvjVC9LZJXJY6ZzmmAVqj6SaBeulaRe4X77qto iyIXvhksquKa0SHrnpSyyjfkMeX/O2G+eotXeIfEoG0Kd0XKo9KpxNJ9KfZSxBMzNHgB i1oPAiBWzs2yeOIQy9CLr0tC1oh728rLdJM+Nbf9xES//wmcChbi3jQQtBGUOsMPIDXk tJSvIndc37IAk6Okk7MY5P1V6a+KSn5n8NiKRqlWD3OL3Df58jL9TEu7ORbdm7524hxu Qn5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707780474; x=1708385274; 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=3+egtMFSB5wP/JnRwyX/FLjZ4VS6y7AaGO4xFQVkuUk=; b=bBa5fpU2Ch6mLONBNkFWvz39udlujYwN/vkJ0HHO6wwOCpDQb0433Lw7SK+Isqr/Tq Heo6Id2PL2ZlX84WmhChd2UF7ocqXAlEIy0H9BrggjJ832ej+JEnS/k14VnewT4txlb8 MmKBITmb/YomXbFz3DcG5PcX/+rPg7lFY9/Zs7biseidAXnIhOeds58VXN4jbzJBSDmp 565iipJiLNA3jZDgep8DVmmztLpEO1hKq+cWidnc9FvF0cl1ns8QTMMMoPuDwqaV9b0G j8QGl0z11GjdywvqNcrHL0zmmgAU1TEipXGqbtB/TtcY2cFAVDL5M+0hrolJWdqk0H+E 39Mg== X-Forwarded-Encrypted: i=1; AJvYcCXHVxy1qD2LMEF0XJ6WAA5PFJ1GOJ/Feo02kpYGx6nDvgmjeSU07RuX/IvKxDzYd0n9HPcTg2LMj0PiqJsOOech0qBK6QBBRS1dtr/vsguB4U9bANo= X-Gm-Message-State: AOJu0YxPh/2FS0u3cQ8iLRMTLaHD8YVrcpZf8+lXLIGUWiYjFcLKVHpj B17iN/yM+icooUCzP6mAZVyU00JrnrRgQ8jpVn7EUmvnj8unGvPTmdqlmXx5vBQ= X-Google-Smtp-Source: AGHT+IEnqNuLs+L+SkljOkSHhq48382/YhpcidnWFKrPiXnIR0zV1wGkfWPgAvmmTXxR3uMFQYBdTw== X-Received: by 2002:a05:6871:80f:b0:218:55c9:bb20 with SMTP id q15-20020a056871080f00b0021855c9bb20mr9748766oap.21.1707780473886; Mon, 12 Feb 2024 15:27:53 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVBCLWzInzImFpjlEde3du9xxWbJtlsO+FIOwVJCqeIGb3XUsPpgQL9MqOSJhqdb/VUAjFuoxvugBtbTKi0LRU+DEKsVET+S1y2BKftd8n6uHN7eeWchHaIuejP1qVpCOCqRjZ3rAXp+AA2CHyMY/eGgTU4nz9PpqD+iqlOeB3kH1N1kKZ7mEr1PH+lJ7gWJDxlmsPqZZHS0DxgHZpOfGcmKawoi/MFfiLH+0ce4Kbn6Y+/gewTIz+E2ZdUOnbXW1TGZMKrbwASINXfQwv80bKsZ5NIf94Sw9NEVO3RBB/IIoXmP0ie0xeGEHT8UiIrqoS8kPntNLX8W8Hcdi3VobfLuV7GLDGv12WG9ityJo9cjFG26LHR7rP6t7f1S7xMAubULcG9BWN44pTpMGAE0FbXXrXzpPbX/+lBsk/NXOlX9/U2dLT7WeQc4mc9RSWZikiWe/v1k16bK24UkDKgHCLfm156oNu0rmFechfXGHcU4GPpxjnzd2n/gMlEIuV8Ejo2/TY2z3/Ue/fUm1amIh69Ij5EeMw= Received: from freyr.lechnology.com (ip98-183-112-25.ok.ok.cox.net. [98.183.112.25]) by smtp.gmail.com with ESMTPSA id pk17-20020a0568704c1100b0021a7a45e0b1sm330141oab.35.2024.02.12.15.27.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 15:27:53 -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 Subject: [PATCH 0/5] spi: add support for pre-cooking messages Date: Mon, 12 Feb 2024 17:26:40 -0600 Message-ID: <20240212-mainline-spi-precook-message-v1-0-a2373cd72d36@baylibre.com> X-Mailer: git-send-email 2.43.0 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-20240212_152756_009232_C4A50390 X-CRM114-Status: GOOD ( 18.91 ) 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. Finally, there has been quite a bit of discussion on the naming of the API already. The most natural suggestion of spi_message_[un]prepare() conflicts with the existing prepare_message controller callback which does something a bit different. I've so far stuck with [un]optimize() from [3], but am not partial to it. Maybe [un]cook() would makes more sense to people? Or maybe we could rename the existing prepare_message callback to free up the name? [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/ --- 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 | 52 ++++++-- drivers/spi/spi-axi-spi-engine.c | 40 +++---- drivers/spi/spi-stm32.c | 28 +++-- drivers/spi/spi.c | 253 ++++++++++++++++++++++++++++++++------- include/linux/spi/spi.h | 19 +++ 5 files changed, 305 insertions(+), 87 deletions(-) --- base-commit: 5111fd347aee731964993fc021e428f8cf46a076 prerequisite-patch-id: 844c06b6caf25a2724e130dfa7999dc90dd26fde change-id: 20240208-mainline-spi-precook-message-189b2f08ba7f