From: David Lechner <dlechner@baylibre.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: "Michael Hennerich" <Michael.Hennerich@analog.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] iio: adc: ad7124: change setup reg allocation strategy
Date: Sat, 20 Sep 2025 09:53:28 -0500 [thread overview]
Message-ID: <3bcca945-b74e-42a0-bf42-24d01068d246@baylibre.com> (raw)
In-Reply-To: <20250920122404.76277a27@jic23-huawei>
On 9/20/25 6:24 AM, Jonathan Cameron wrote:
> On Wed, 17 Sep 2025 17:05:01 -0500
> David Lechner <dlechner@baylibre.com> wrote:
>
>> Change the allocation strategy of the 8 SETUP registers from a least-
>> recently-used (LRU) to a first-come-first-served basis.
>>
>> The AD7124 chips can have up to 16 channels enabled at a time in the
>> sequencer for buffered reads, but only have 8 SETUP configurations
>> (namely the OFFSET, GAIN, CONFIG and FILTER registers) that must be
>> shared among the 16 channels. This means some of the channels must use
>> the exact same configuration parameters so that they can share a single
>> SETUP group of registers. The previous LRU strategy did not keep track
>> of how many different configurations were requested at the same time,
>> so if there were more than 8 different configurations requested, some
>> channels would end up using the incorrect configuration because the slot
>> assigned to them would also be assigned to a different configuration
>> that wrote over it later.
>>
>> Adding such tracking to solve this would make an already complex
>> algorithm even more complex. Instead we can replace it with a simpler
>> first-come-first-serve strategy. This makes it easy to track how many
>> different configurations are being requested at the same time. This
>> comes at the expense of slightly longer setup times for buffered reads
>> since all setup registers must be written each time when a buffered read
>> is enabled. But this is generally not considered a hot path where
>> performance is critical, so should be acceptable.
>
> If I read this correctly, ever time we call postenable()
> this parses the channels enabled and first checks if an existing cfg
> is usable, if not assigns the first unused slot.
>
> If so, the algorithm is a little more complex than it needs to be because
> it is allowing for holes in the used cfg registers that I don't think
> can occur.
Yes, Nuno noticed this too and had a suggestion on how to simplify it.
>
> So if we add simple cfg_slots_used variable we can for example jump directly
> to the next unused slot if we don't find a match and we can use this
> as the loop limit to save on checking a bunch of zeros after that aren't
> in use.
There are only 8 available config slots, so I didn't consider such
optimization. But we could perhaps do this even without adding an
extra variable.
>
> Maybe I'm missing something?
>
> In general the approach you have here feels sensible.
>
> Jonathan
>
prev parent reply other threads:[~2025-09-20 14:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-17 22:05 David Lechner
2025-09-18 12:24 ` Nuno Sá
2025-09-18 13:16 ` David Lechner
2025-09-18 14:07 ` Nuno Sá
2025-09-20 11:24 ` Jonathan Cameron
2025-09-20 14:53 ` David Lechner [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3bcca945-b74e-42a0-bf42-24d01068d246@baylibre.com \
--to=dlechner@baylibre.com \
--cc=Michael.Hennerich@analog.com \
--cc=andy@kernel.org \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®