public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Tom Rini <trini@konsulko.com>
To: Simon Glass <sjg@chromium.org>
Cc: "Pali Rohár" <pali@kernel.org>,
	"U-Boot Mailing List" <u-boot@lists.denx.de>
Subject: Re: [PATCH v2 2/6] console: Implement flush() function
Date: Wed, 31 Aug 2022 09:55:16 -0400	[thread overview]
Message-ID: <20220831135516.GD7942@bill-the-cat> (raw)
In-Reply-To: <CAPnjgZ0gsyts_10zTxs=19VCkrp9HLJY7gganJ9gPK72fsHa+A@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 5231 bytes --]

On Wed, Aug 31, 2022 at 07:46:58AM -0600, Simon Glass wrote:
> Hi Pali,
> 
> On Wed, 31 Aug 2022 at 03:13, Pali Rohár <pali@kernel.org> wrote:
> >
> > On Thursday 25 August 2022 09:08:18 Simon Glass wrote:
> > > Hi Pali,
> > >
> > > On Thu, 25 Aug 2022 at 08:20, Pali Rohár <pali@kernel.org> wrote:
> > > >
> > > > On Friday 12 August 2022 20:21:00 Simon Glass wrote:
> > > > > Hi Pali,
> > > > >
> > > > > On Fri, 12 Aug 2022 at 09:17, Pali Rohár <pali@kernel.org> wrote:
> > > > > >
> > > > > > On Friday 12 August 2022 09:11:10 Simon Glass wrote:
> > > > > > > Hi Pali,
> > > > > > >
> > > > > > > On Fri, 12 Aug 2022 at 03:01, Pali Rohár <pali@kernel.org> wrote:
> > > > > > > >
> > > > > > > > On Thursday 11 August 2022 18:08:46 Simon Glass wrote:
> > > > > > > > > Hi Pali,
> > > > > > > > >
> > > > > > > > > On Thu, 11 Aug 2022 at 08:50, Pali Rohár <pali@kernel.org> wrote:
> > > > > > > > > >
> > > > > > > > > > On Thursday 11 August 2022 08:47:50 Simon Glass wrote:
> > > > > > > > > > > > diff --git a/include/stdio_dev.h b/include/stdio_dev.h
> > > > > > > > > > > > index 270fa2729fb2..06278366ae88 100644
> > > > > > > > > > > > --- a/include/stdio_dev.h
> > > > > > > > > > > > +++ b/include/stdio_dev.h
> > > > > > > > > > > > @@ -37,6 +37,10 @@ struct stdio_dev {
> > > > > > > > > > > >         void (*putc)(struct stdio_dev *dev, const char c);
> > > > > > > > > > > >         /* To put a string (accelerator) */
> > > > > > > > > > > >         void (*puts)(struct stdio_dev *dev, const char *s);
> > > > > > > > > > > > +#ifdef CONFIG_CONSOLE_FLUSH_SUPPORT
> > > > > > > > > > >
> > > > > > > > > > > I'd argue it isn't worth the #ifdef and we might as well have this
> > > > > > > > > > > member here always. Then you can drop some #ifdefs from your code.
> > > > > > > > > >
> > > > > > > > > > But then it will increase binary code size.
> > > > > > > > >
> > > > > > > > > Using the member will increase code size. But I think the only place
> > > > > > > > > you need an #ifdef for that is when you include it in the driver
> > > > > > > > > struct. You can use __maybe_unused in the other place.
> > > > > > > > >
> > > > > > > > > Having the member will only increase memory usage, not code size.
> > > > > > > >
> > > > > > > > But static memory structures are part of the u-boot.bin binary and also
> > > > > > > > their usage increase code size (required copy, etc...), so at the end it
> > > > > > > > increase code size.
> > > > > > >
> > > > > > > From what I understand stdio_dev is allocated at runtime in BSS:
> > > > > > >
> > > > > > > struct stdio_dev *stdio_devices[] = { NULL, NULL, NULL };
> > > > > > >
> > > > > > > (the NULL stuff should not be there, but does nothing, I believe)
> > > > > > >
> > > > > > > So long as no code accesses your new member, then it should only
> > > > > > > affect the BSS size.
> > > > > >
> > > > > > Code of course has to access new member. How otherwise would be able to
> > > > > > call that new callbacks? E.g. all new code in patch 2/6 or 3/6.
> > > > >
> > > > > Yes, see below. Also, do check whether it actually adds code or not.
> > > > >
> > > > > >
> > > > > > > If you are very worried about it, you could use the technique in
> > > > > > > asm-generic/global_data.h to avoid #ifdefs in the C code:
> > > > > > >
> > > > > > > #ifdef CONFIG_GENERATE_ACPI_TABLE
> > > > > > > #define gd_acpi_start() gd->acpi_start
> > > > > > > #define gd_set_acpi_start(addr) gd->acpi_start = addr
> > > > > > > #else
> > > > > > > #define gd_acpi_start() 0UL
> > > > > > > #define gd_set_acpi_start(addr)
> > > > > > > #endif
> > > > > > >
> > > > > > > Regards,
> > > > > > > Simon
> > > > >
> > > > > Regards,
> > > > > Simon
> > > >
> > > > But in this case, it is needed to introduce a new special macro and hide
> > > > assigning code into it. In my opinion such macro with side effect and
> > > > worse than writing it explicitly - open coded to show what the code is
> > > > doing.
> > >
> > > You can use an inline function if you prefer.
> >
> > But it has still same issue, hiding conditional logic indirectly to
> > additional file. Some members would be assigned directly via = operator
> > and some via macro/inlinefunction is inconsistent.
> 
> I've said everything I can say about this. If Tom has some thoughts
> I'll leave it to him.
> 
> >
> > > My main objection is to adding #ifdefs to C files. They are OK (for
> > > now) in driver struct declarations, where some members are optional.
> > > But I think it is worth going to some lengths to avoid them elsewhere.
> > >
> > > +Tom Rini for thoughts on this
> > >
> > > Regards,
> > > SImon
> >
> > Any comments on this?

Given the plethora of tools to demonstrate that approach X results in
size change Y, I'm not sure why we're pondering if something will or
won't result in increases? I would like to see this series result in the
smallest increase in binary size on platforms that don't enable the
feature. An #ifdef isn't more or less readable than using some macro
instead, and decorators like __maybe_unused have their own impact on
code readability.

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

  reply	other threads:[~2022-08-31 13:55 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-11 12:39 [PATCH v2 0/6] console: Implement flush() function Pali Rohár
2022-08-11 12:39 ` [PATCH v2 1/6] sandbox: Add function os_flush() Pali Rohár
2022-08-11 14:47   ` Simon Glass
2022-08-11 12:39 ` [PATCH v2 2/6] console: Implement flush() function Pali Rohár
2022-08-11 14:47   ` Simon Glass
2022-08-11 14:49     ` Pali Rohár
2022-08-12  0:08       ` Simon Glass
2022-08-12  9:01         ` Pali Rohár
2022-08-12 15:11           ` Simon Glass
2022-08-12 15:17             ` Pali Rohár
2022-08-13  2:21               ` Simon Glass
2022-08-25 14:20                 ` Pali Rohár
2022-08-25 15:08                   ` Simon Glass
2022-08-31  9:13                     ` Pali Rohár
2022-08-31 13:46                       ` Simon Glass
2022-08-31 13:55                         ` Tom Rini [this message]
2022-08-11 12:39 ` [PATCH v2 3/6] serial: Implement flush callback Pali Rohár
2022-08-11 14:47   ` Simon Glass
2022-08-11 12:39 ` [PATCH v2 4/6] serial: Implement serial_flush() function for console flush() fallback Pali Rohár
2022-08-11 14:47   ` Simon Glass
2022-08-11 12:39 ` [PATCH v2 5/6] serial: Call flush() before changing baudrate Pali Rohár
2022-08-11 14:47   ` Simon Glass
2022-08-11 14:51     ` Pali Rohár
2022-08-12  0:08       ` Simon Glass
2022-08-12  9:00         ` Pali Rohár
2022-08-11 12:39 ` [PATCH v2 6/6] boot: Call flush() before booting Pali Rohár
2022-08-11 14:47   ` Simon Glass

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=20220831135516.GD7942@bill-the-cat \
    --to=trini@konsulko.com \
    --cc=pali@kernel.org \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /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