mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Victor Chernyakin <chernyakin.victor.j@outlook.com>
Cc: andy@kernel.org, dlechner@baylibre.com, jic23@kernel.org,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	nuno.sa@analog.com
Subject: Re: [PATCH v8 4/4] iio: cdc: add Texas Instruments FDC1004 driver
Date: Wed, 11 Nov 2026 16:50:40 +0200	[thread overview]
Message-ID: <avSAwLDgDAOM-9Gu@ashevche-desk.local> (raw)
In-Reply-To: <MW2PR12MB2523036E2E017B5952015D9AA5712@MW2PR12MB2523.namprd12.prod.outlook.com>

On Wed, Nov 11, 2026 at 08:10:49AM -0600, Victor Chernyakin wrote:

...

> > > > > +static const int fdc1004_calibbias_decomposed[] = {
> > > > > +	lower_32_bits(fdc1004_calibbias[0]), upper_32_bits(fdc1004_calibbias[0]),
> > > > > +	lower_32_bits(fdc1004_calibbias[1]), upper_32_bits(fdc1004_calibbias[1]),
> > > > > +	lower_32_bits(fdc1004_calibbias[2]), upper_32_bits(fdc1004_calibbias[2]),
> > > > > +};
> > > > > +
> > > > > +static const int fdc1004_calibscale_decomposed[] = {
> > > > > +	lower_32_bits(fdc1004_calibscale[0]), upper_32_bits(fdc1004_calibscale[0]),
> > > > > +	lower_32_bits(fdc1004_calibscale[1]), upper_32_bits(fdc1004_calibscale[1]),
> > > > > +	lower_32_bits(fdc1004_calibscale[2]), upper_32_bits(fdc1004_calibscale[2]),
> > > > > +};

> > > > Can we prepare them dynamically at runtime? Use global variables and a macro
> > > > from once.h to make the populate function a singleton, so we don't have as many
> > > > copies as devices on the system that are driven by this code. We can probably
> > > > do this later, though.
> > > 
> > > Are you sure there's a separate copy for each device? In my understanding,
> > > these static variables are loaded along with the module, and the module
> > > is loaded only once and shared between all devices.
> > 
> > I started my paragraph with "Can we prepare them dynamically at runtime?"
> > which assumes that the rest of the paragraph is elaborating that idea.
> 
> Oh, I see how I misread that, sorry.
> 
> Here's the implementation I tried:
> 
> static int fdc1004_calibbias_decomposed[6];
> static int fdc1004_calibscale_decomposed[6];
> 
> static void fdc1004_init_decomposed_arrays(void)
> {
> 	for (int i = 0; i < ARRAY_SIZE(fdc1004_calibbias); i++) {

This is not fully correct.

> 		iio_val_s64_decompose(fdc1004_calibbias[i], &fdc1004_calibbias_decomposed[2 * i],
> 							    &fdc1004_calibbias_decomposed[2 * i + 1]);
> 		iio_val_s64_decompose(fdc1004_calibscale[i], &fdc1004_calibscale_decomposed[2 * i],
> 							     &fdc1004_calibscale_decomposed[2 * i + 1]);
> 	}
> }

This can be reduced to supply the pointers to the arrays along with the size
to some helper and call it twice (three functions), but that might be not
better either by size.

> static int fdc1004_read_avail(...)
> {
> 	DO_ONCE(fdc1004_init_decomposed_arrays);
> 	....
> }
> 
> Running bloat-o-meter, the code got quite a bit bigger unfortunately:
> 
> Function                                     old     new   delta
> fdc1004_read_avail                           141     369    +228
> ____versions                                1408    1536    +128
> ____version_ext_names                        406     437     +31
> ___once_key                                    -      16     +16
> ____version_ext_crcs                          88      96      +8
> ___done                                        -       1      +1
> Total: Before=8750, After=9162, chg +4.71%
> 
> (This was compiling with KCFLAGS="-Os". I also tried KCFLAGS="-O2" and
> the result is very similar)

However, this is not about the size of the binary, it's about robustness of
the code and having one point of data. As I already mentioned, this is just
an idea how to solve it, maybe Jonathan and others have a better one...

-- 
With Best Regards,
Andy Shevchenko



      reply	other threads:[~2026-11-11 14:50 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10 20:24 [PATCH v8 0/4] " Victor Chernyakin
2026-11-10 20:24 ` [PATCH v8 1/4] iio: prepare iio_format_value to handle higher-precision IIO_VAL_DECIMAL64_* formats Victor Chernyakin
2026-11-10 20:24 ` [PATCH v8 2/4] iio: add IIO_VAL_DECIMAL64_{ATTO,ZEPTO,YOCTO} formats Victor Chernyakin
2026-11-10 20:24 ` [PATCH v8 3/4] dt-bindings: iio: cdc: add Texas Instruments FDC1004 Victor Chernyakin
2026-11-10 20:24 ` [PATCH v8 4/4] iio: cdc: add Texas Instruments FDC1004 driver Victor Chernyakin
2026-11-10 21:18   ` Andy Shevchenko
2026-11-11  0:18     ` Victor Chernyakin
2026-11-11  8:41       ` Andy Shevchenko
2026-11-11 14:10         ` Victor Chernyakin
2026-11-11 14:50           ` Andy Shevchenko [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=avSAwLDgDAOM-9Gu@ashevche-desk.local \
    --to=andriy.shevchenko@intel.com \
    --cc=andy@kernel.org \
    --cc=chernyakin.victor.j@outlook.com \
    --cc=dlechner@baylibre.com \
    --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®