Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2742771rdb; Mon, 12 Feb 2024 15:28:05 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWL7x8Bo5nyv9UjQ0PS58pOl0bS5veZIOav9QX3WCRHnAsfK86tMxDGba74Rf6UDoYygDGTi07jI7uinyAYFSZfC9T8m4YOO+HsoYZUNA== X-Google-Smtp-Source: AGHT+IEXi8PHqZBar0nkDpU8EKxJe6QMk4LnuumeGpIfcFlFHd9WRRdS8NwDE7j/jsPkuEgFg2v6 X-Received: by 2002:a05:6808:1803:b0:3bd:c805:b7b1 with SMTP id bh3-20020a056808180300b003bdc805b7b1mr7688625oib.59.1707780485505; Mon, 12 Feb 2024 15:28:05 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707780485; cv=pass; d=google.com; s=arc-20160816; b=l1okvixjGzBStTOyqi/Tv+q6n2KC7L1p67egOFscG+EDOLZ+LLAVky54rMMw7X9NsG ryMeMAH0WIXsHsj/cJOgtQioIns2lzLp9FKpCIBEn3hUcZmzpcy+bLPfo/IPZ6TzQTwP 0yDS5lUk2Uvkp/O091kS6yF2hwY2qiKW2sK0YkhveS4av+GTbtyJzUzPJvmA0dy/3+VD 9W8aRzy89MPbRSEtNkSc9muY9L6AnhTpSSmjo0+u6RhK+wv8piM2GoVKHEnHa8kC9DSR 6PuX8hqinqzT8TOutyansVRBPyPEeSrTd6AhO8XOZ/zqUzX0IqceIPil+6Ethz1ldQqm plRw== 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:message-id:date:subject:cc:to :from:dkim-signature; bh=3+egtMFSB5wP/JnRwyX/FLjZ4VS6y7AaGO4xFQVkuUk=; fh=WV7HqmROcU/Qylou8HG+ORZA4INQWy/xTQw4obAlLlM=; b=MTk5sKx+UpQB3oc+33SBDu2yjOam6Wfj4c7n/cWMS7ezQotGlkKZmv2vkGLO4P9UGC wq/ApIGaPSJq7xxep1DYjePgoX1Zdct3pgt6dDhSl/UjNQayIl085+0HT1cR8sEf+5VE o4dErBX8piGVghs/3X91TxjF40yw+d8BfIu8aos1B95rZ2y+dITWQbEe046Tdu5AicBR SkjCAnW0s0/m9a880V2znpYd3TP7qxy6WYcbvEereLXsyNHTkLX6zF2e1Jz6aHENOTi1 kBmTmmIyYhrO4dt8jVlXMeIn4MVCNxB1O1mPKc9AAICKt9p0NFKe21fGc+iJdxNLbKhu TEpQ==; 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=MzkgzzL3; 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-62532-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62532-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCU9K0Zh7bqX9D10x/kvKeo6NiWVAEYLRmn4F7o8VW++m40sUCuzslwzfNKmWGl5qhIp0ex8psTq+92EEyzATjCPArIq8u8mKohcaBivNQ== Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 12-20020ac8590c000000b0042d7adcdc22si1803414qty.651.2024.02.12.15.28.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Feb 2024 15:28:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-62532-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20230601.gappssmtp.com header.s=20230601 header.b=MzkgzzL3; 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-62532-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-62532-linux.lists.archive=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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 334181C22140 for ; Mon, 12 Feb 2024 23:28:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 6285C4F8B9; Mon, 12 Feb 2024 23:27:58 +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="MzkgzzL3" Received: from mail-ot1-f52.google.com (mail-ot1-f52.google.com [209.85.210.52]) (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 16ACE4F5FE for ; Mon, 12 Feb 2024 23:27:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707780477; cv=none; b=Pm/VEwQMZBGledi24Ytb632HLEj20VUa3hIgHuTuxp2ewgOnpc6Cx/aY43azldeIueIQp8S6CJGWUUcJpr5O2p42Az2h4UTKbyiRhxoC/n4PLQnTa6Gus1lKlhUaMSyTJGvbddPvmm3Ky7GSc81rtbdvnEMw0aHn/Ij+E4xudnc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707780477; c=relaxed/simple; bh=wQOLAzpAqdTMxbzgxQagsub1MlQcJ776NbBb/5ZmX74=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version:Content-Type; b=R5fPwsatL7kJx533NlTXb6oOgJzYLkZXLwHxCqpbP49sc895/VlzRR8F+xcvQc+NfjB9f+lHR5/hhQ6FDYmBOG8sjcGvJb8KTKJX6BNtvZrXvUFb/6hw3/U91sZsgjRmfttVJaJpTzRBSFSoBLRthiG1Fhrlrzlszp9JHWRsn2E= 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=MzkgzzL3; arc=none smtp.client-ip=209.85.210.52 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-ot1-f52.google.com with SMTP id 46e09a7af769-6e2de202d9aso1146719a34.0 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=vger.kernel.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=MzkgzzL35sh2Hd+HStux+3lGfZoFx7BkilNaOUALWkvWugwmOYoS+6P5/MfIdtzwLr ehKLKlttNTDbLLxsqJMJt4c4fuJKu3RayyfQgcocUWMvtTjSN/i9xXGldsBtTBFEa8UY 3Sp8WFg7OhoUlZ0dppHfWFLshzgxwsJU7rqfRyF7uR+7J1oSHBIChuiMXaPqCtH6b2ni FTPmicM8416vHwfK6s0L2b7ru3nF0eOtA5TemYDxy2Yj3/1VT2jrX7m7H2g8p+ITL+ie 873w6fL2sG6YOZ5odZn17r2CGHxBZOSlO5Zlsjs24qKoRBqH0wn6SMlp00w0jdjfkqUf 85Bw== 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=jwkgB1oGso5xC4kp83gX9tKJlJK5V2TDerubLAwBkwptpQaxDxbiTpRMG2MESnW4RS i9hmXNjQgH6H2eJq7DxYB0vlQjNgBf4dtgKfp/yMKjurgsWgDWFQPdki4ojq2hsvpAr3 JWbji9j8f9HedhLXuAvZxciLHNVzY3N3ZfQesZkRXupAiQKULs3mAy1lNxXv2cy9O0tA K+l+jk2eT523NggpGW2uCBOZ5W52CaFco8DppTVBEouzWpq7rhADM9c8Ubp4oFQeHgD0 Lm6p8gnf9IB7aUJ+HnNCyPgNJW9uwr0UqWuSoQ7Faowvw8wjYPwAdIbJB6s/1n8qbRaU qmvw== X-Forwarded-Encrypted: i=1; AJvYcCXUIQRP9s5OMB2o+nwDkMmBjY095kyw2KX919XppxmkSUPGbgopR/3hk5MLMapR8v9z+tVxzAuv7GQlTr/KbCfTlP2YxbxRBydAlpj0 X-Gm-Message-State: AOJu0YxVuEbRd/RDQt4lCC0ugZyqzJOqrqqA5r/Iv032px6Mh0ZiDkbi Mhw4vw97F6iep0FtUK0JrIZrThGoeNV0nXCadXuWByhsz2zkeVSvXYMQr78fWdM= 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" X-Mailer: b4 0.12.4 Content-Transfer-Encoding: 8bit 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