Received: by 2002:a05:7412:2a91:b0:fc:a2b0:25d7 with SMTP id u17csp15087rdh; Tue, 13 Feb 2024 08:06:24 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVfFvNOGitedD1JyXvAJGP1xoZruUnRwVkUevzXAyTIDkeKcD5XGjbKyP4GxPjOhV0nFRz3ThywJI4xI/Mk8VvWPOsPR0V+nW4mfQ2i8A== X-Google-Smtp-Source: AGHT+IHXvJi2ps8gNGaWbUsmoneLEv0j9iR8fK98yWBJ9asB+KGyrFkrVuLgLqFqmQE4YxTbkTWI X-Received: by 2002:a17:903:40d0:b0:1d9:e182:2bf8 with SMTP id t16-20020a17090340d000b001d9e1822bf8mr13801863pld.6.1707840384545; Tue, 13 Feb 2024 08:06:24 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707840384; cv=pass; d=google.com; s=arc-20160816; b=OB1tzOawMAnSTn4b3Tj4KJrltY+nDmiCsgR0cevSeuOWy9TWS0pxpKDLzuZ+Fw0Nab SMwIBSdfE7OrRJEa4uiAdJ2wxhoataNo8PUcYdpXKs0k0NwpMxk2nCZzcZSvAhBWt+ob cJQp6U3JefIynAfDAm8RvDHvsEVmsAgjerkbdgLZeeBud3U2/JVsNTPSucNc4ZgmjlG7 hQ55BXrogZ0BY8zSXrVO3FMcOj0jZFVjcV/r2H4kFJAsGtLAqAvWui8lnoz2j09TKTX7 j3g8Gnnf5nzbY+n4pnJKS1l5FU7kW6RQ3UgI9L2LY+y7nTPPbyy1njdshPPJrm7B0lR0 clXw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :user-agent:content-transfer-encoding:references:in-reply-to:date:cc :to:from:subject:message-id:dkim-signature; bh=rM3rrsxmVIGD8Xdy2RSGGo3eRi8719tCkmvzDLLsESI=; fh=qEFP6YnX+5Xv/rZQPPszFHbZMlJUHxaI69a5PY3E+2M=; b=0JKVoE35/KQnEogGoiKc3h0GN5BScx6/MYVqqSl295/G2yWjTuHj3WH4MXPUKzQ6Ax Y/huUUlLa1jCtQV6dZuNu9XSb5THOZhLqJNnr2q4f8J5nellhV0gKgJB1IM1sT+c+Ipw /drg9kKbBR+rgCM8hc36FBbYn2jnn3ze2ByZJ53Df7SDnLZ6KP9dGvr+qG5zf17OvFG4 ecdAoNE2zuhA1b0aTsrlwx4BjFKbCfx3K1ZA0ZGltz3PFZVcnE8FsTbWtVibrjU3wGAK 6SprZUyFCCnkjUqxEJr6v6d7Guc1QHtmjAqYMnY2Ut0dVgUQbT5F9ATIwJH0pzkJCSS8 ZbJQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=LB0hW0F+; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-63855-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63855-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com X-Forwarded-Encrypted: i=2; AJvYcCWQcGrgF7IW0M/X8szIHOH56pMkvvkJja22SeDDnmhL6Ka19R1JJ1gN0scY8hBiTWKBdhwMlTD3LCPVoul6HBExh0b3tdrgpY9BZJdySQ== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id f12-20020a170902684c00b001da1efbd32asi1371126pln.443.2024.02.13.08.06.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 08:06:24 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-63855-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=LB0hW0F+; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-63855-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-63855-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 938262890BE for ; Tue, 13 Feb 2024 16:05:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EFEF45F56B; Tue, 13 Feb 2024 16:05:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="LB0hW0F+" Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) (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 3847D5EE87; Tue, 13 Feb 2024 16:05:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.45 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707840305; cv=none; b=ReeA1d9UOv9E6Koq8RdwkthL5h24qMNzqIp7YIbasdfdS+LPFIB9ut5ZNAB68djuGVoItK8RuR7KrrYSNHu2aGpFAt9tIR7x4BdHYBJo6kw9Vsie8gX/54qM7XcUBtdilWk61ZKNHkjXsBEznP5ArsRt3NxJb09mWzy871wkRBE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707840305; c=relaxed/simple; bh=rM3rrsxmVIGD8Xdy2RSGGo3eRi8719tCkmvzDLLsESI=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=W2XWnha/8IAcS7cTni5vVofOWtAS3Nak9zDrJTh8lw6XNDWruylMLFtJSI3VMUqKMX4gJzQhUMr/AKhU1eDqsSSjasDF5vLTidmz0CxvxWO8TXMlbEL6MnFV5bRk8NGI0uWA/0+yp3Ejl5fbe5C2x7F9ahhJAhCVZIgqMSF0WNU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=LB0hW0F+; arc=none smtp.client-ip=209.85.218.45 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ej1-f45.google.com with SMTP id a640c23a62f3a-a3cb228b90bso228537666b.3; Tue, 13 Feb 2024 08:05:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707840301; x=1708445101; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=rM3rrsxmVIGD8Xdy2RSGGo3eRi8719tCkmvzDLLsESI=; b=LB0hW0F+OUgI0/Gf09U3uTDEdYMPMKeLV2+q9Wd7i1YE6wMqk8aoVuuY51wWU5Ag2e Q60o0nn2ZtjuJ1m04Gped8KYpouB80LWrBKX8A82XbMY1fVmpJw7tZHSLoT3AnLBaMsQ 7k767bYn5N4MtxrGim13m/bPeRX+Rzh3DCep8dBE4haYS4+b9Xx4kPI84s6mm+Q8SHYD k0iA8NhNSapo5XlMC1W8ny5xejrrNPd2Zv68LP4qW5KJ2HgUWmcYprApT0SDwsIQn4c6 dlGCmju52SLJa8McINWRqaEEbLX5FNuH8Cj8QUcfncVDpoxFgPMg16cb6KgT7S9h5KoL Vbfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707840301; x=1708445101; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=rM3rrsxmVIGD8Xdy2RSGGo3eRi8719tCkmvzDLLsESI=; b=ULNXLOTdmgpeeGS7P37xpxEzDrhgPeFpZvTn210OIXlVd9dCVjM0hoyLD5ZJu69Y+G m38V9tt5MokL1AXWeRX7E8wRleulXU3IUrnxuoGwxa5BbO5mij9acXcnOVi0Wx7itgvO 8Fo8vz/qIPDusNiWAutRHKdcldiIwiDr6WZ5dAMRdiMphenenUq0krZ4P27eH7WBN8L3 WnVLNCK/jM12W6aptJl9i0Agc6AdIp1QBf6CRtLC0ZmpOun7aqjQ1lxgDjxIwHcSg2TW JvLH5ZOu3e9a81TXAkgKhqaYRVEPksbdgnLS7ueRArvDvFr/BopKFjh7rGAUFBOQj5cc u3SA== X-Forwarded-Encrypted: i=1; AJvYcCV6ayfa7sATYkj7JGnDbds5oJXi/37To3lvOFKSN5+JRTrM1EHs8x/TVbdqfaTEHTm3NBOnKfMkPbp89/h6xTrMuzfcZNaHA1C1b/NeFq3e49jZaco0fwsQKmbWgaUMo9uYNmyg2jF3umG0k3zeFisle3StwOyyTPVrP8ep/eNz2Np7 X-Gm-Message-State: AOJu0Yw93S1Y+Z03A/j7b9aj48WEOSA2fPIg3xmTzIo/a1Gcdqmukr7I eC1pzL8UgiuAucrHIJfxhpx4IPraaM2Xz3I/WpNGMulp9SvaqCIz X-Received: by 2002:a17:906:80b:b0:a3c:771:a97a with SMTP id e11-20020a170906080b00b00a3c0771a97amr7821530ejd.73.1707840301135; Tue, 13 Feb 2024 08:05:01 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUtLWfPHGLeQOMOCOpurgmOWvVQm0yGHwp2Gp+OpYptWmZush47c4TmCLi5f3fjS7IMNTsyCLXIyD0n9yv8oaWKCMUgXq6MC5CFdl1gPwHyZl7hzAuQG+zUKzQ+yq0jaT4a/012vwpBVcQZq8Z3zGDax35nhIXppxJQv9ed19HY1EdiTr1k0GQCOpxvsAqf1rSoffKNhTXO3VD5NnqAb3ebLPR55bOoYDICJwPMhap9drcriuLaRbX3VqYyZmVIIfLJHX3gmYAmhRWo5pDx5OU7GjCWlAF1+cpgW4Ae25p1arZ7fvXBmr2KFAyp4x+QZkfcxbFWGp8UdM3FexW4FQrhak67rFjsOlfXgJRcXydt6S4b9+0frLP4FptO2Kt40lsHcnnZhVq65PgPmyd+Lsjr6xLkmMZFux5ZH6I53JF0c8fm16Px/d/j9OUDoAqfkWhUrwREwWBEl44ZK+fi+OOKR6PRKs1Z1Dr1WfwZGwRXS8mRWN5LNcvv2QoCTn/galthSzaHJzSkvf0g32eKFSHaz/Ro4wI= Received: from ?IPv6:2003:f6:ef1b:2000:944c:cbc7:1e1c:2c47? (p200300f6ef1b2000944ccbc71e1c2c47.dip0.t-ipconnect.de. [2003:f6:ef1b:2000:944c:cbc7:1e1c:2c47]) by smtp.gmail.com with ESMTPSA id ps8-20020a170906bf4800b00a3ca744438csm1407182ejb.213.2024.02.13.08.05.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 08:05:00 -0800 (PST) Message-ID: Subject: Re: [PATCH 5/5] iio: adc: ad7380: use spi_optimize_message() From: Nuno =?ISO-8859-1?Q?S=E1?= To: David Lechner Cc: Mark Brown , Martin Sperl , David Jander , Jonathan Cameron , Michael Hennerich , Nuno =?ISO-8859-1?Q?S=E1?= , 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 Date: Tue, 13 Feb 2024 17:08:19 +0100 In-Reply-To: References: <20240212-mainline-spi-precook-message-v1-0-a2373cd72d36@baylibre.com> <20240212-mainline-spi-precook-message-v1-5-a2373cd72d36@baylibre.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.50.3 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Tue, 2024-02-13 at 09:27 -0600, David Lechner wrote: > On Tue, Feb 13, 2024 at 3:47=E2=80=AFAM Nuno S=C3=A1 wrote: > >=20 > > On Mon, 2024-02-12 at 17:26 -0600, David Lechner wrote: > > > This modifies the ad7380 ADC driver to use spi_optimize_message() to > > > optimize the SPI message for the buffered read operation. Since buffe= red > > > reads reuse the same SPI message for each read, this can improve > > > performance by reducing the overhead of setting up some parts the SPI > > > message in each spi_sync() call. > > >=20 > > > Signed-off-by: David Lechner > > > --- > > > =C2=A0drivers/iio/adc/ad7380.c | 52 +++++++++++++++++++++++++++++++++= ++++++++-- > > > ---- > > > - > > > =C2=A01 file changed, 45 insertions(+), 7 deletions(-) > > >=20 > > > diff --git a/drivers/iio/adc/ad7380.c b/drivers/iio/adc/ad7380.c > > > index abd746aef868..5c5d2642a474 100644 > > > --- a/drivers/iio/adc/ad7380.c > > > +++ b/drivers/iio/adc/ad7380.c > > > @@ -133,6 +133,7 @@ struct ad7380_state { > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 struct spi_device *spi; > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 struct regulator *vref; > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 struct regmap *regmap; > > > +=C2=A0=C2=A0=C2=A0=C2=A0 struct spi_message *msg; > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 /* > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * DMA (thus cache coherency main= tenance) requires the > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 * transfer buffers to live in th= eir own cache lines. > > > @@ -231,19 +232,55 @@ static int ad7380_debugfs_reg_access(struct iio= _dev > > > *indio_dev, u32 reg, > > > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 return ret; > > > =C2=A0} > > >=20 > > > +static int ad7380_buffer_preenable(struct iio_dev *indio_dev) > > > +{ > > > +=C2=A0=C2=A0=C2=A0=C2=A0 struct ad7380_state *st =3D iio_priv(indio_= dev); > > > +=C2=A0=C2=A0=C2=A0=C2=A0 struct spi_transfer *xfer; > > > +=C2=A0=C2=A0=C2=A0=C2=A0 int ret; > > > + > > > +=C2=A0=C2=A0=C2=A0=C2=A0 st->msg =3D spi_message_alloc(1, GFP_KERNEL= ); > > > +=C2=A0=C2=A0=C2=A0=C2=A0 if (!st->msg) > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 return -ENOMEM; > > > + > > > +=C2=A0=C2=A0=C2=A0=C2=A0 xfer =3D list_first_entry(&st->msg->transfe= rs, struct spi_transfer, > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0 transfer_list); > > > + > > > +=C2=A0=C2=A0=C2=A0=C2=A0 xfer->bits_per_word =3D st->chip_info->chan= nels[0].scan_type.realbits; > > > +=C2=A0=C2=A0=C2=A0=C2=A0 xfer->len =3D 4; > > > +=C2=A0=C2=A0=C2=A0=C2=A0 xfer->rx_buf =3D st->scan_data.raw; > > > + > > > +=C2=A0=C2=A0=C2=A0=C2=A0 ret =3D spi_optimize_message(st->spi, st->m= sg); > > > +=C2=A0=C2=A0=C2=A0=C2=A0 if (ret) { > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 spi_message_free(st->msg); > > > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 return ret; > > > +=C2=A0=C2=A0=C2=A0=C2=A0 } > > > + > > > +=C2=A0=C2=A0=C2=A0=C2=A0 return 0; > > > +} > > > + > > > +static int ad7380_buffer_postdisable(struct iio_dev *indio_dev) > > > +{ > > > +=C2=A0=C2=A0=C2=A0=C2=A0 struct ad7380_state *st =3D iio_priv(indio_= dev); > > > + > > > +=C2=A0=C2=A0=C2=A0=C2=A0 spi_unoptimize_message(st->msg); > > > +=C2=A0=C2=A0=C2=A0=C2=A0 spi_message_free(st->msg); > > > + > > > +=C2=A0=C2=A0=C2=A0=C2=A0 return 0; > > > +} > > > + > >=20 > > Not such a big deal but unless I'm missing something we could have the > > spi_message (+ the transfer) statically allocated in struct ad7380_stat= e and > > do > > the optimize only once at probe (naturally with proper devm action for > > unoptimize). Then we would not need to this for every buffer enable + > > disable. I > > know in terms of performance it won't matter but it would be less code = I > > guess. > >=20 > > Am I missing something? >=20 > No, your understanding is correct for the current state of everything > in this series. So, we could do as you suggest, but I have a feeling > that future additions to this driver might require that it gets > changed back this way eventually. Hmm, not really sure about that as chip_info stuff is always our friend :).= And I'm anyways of the opinion of keeping things simpler and start to evolve wh= en really needed (because often we never really need to evolve). But bah, as I said... this is really not a big deal. - Nuno S=C3=A1