public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Ard Biesheuvel" <ard.biesheuvel@linaro.org>
To: "Kinney, Michael D" <michael.d.kinney@intel.com>
Cc: "devel@edk2.groups.io" <devel@edk2.groups.io>,
	"Gao, Zhichao" <zhichao.gao@intel.com>,
	 Laszlo Ersek <lersek@redhat.com>,
	"Gao, Liming" <liming.gao@intel.com>,
	 "Bi, Dandan" <dandan.bi@intel.com>
Subject: Re: [edk2-devel] [PATCH V2 3/8] MdePkg/UefiDebugLibStdErr: Decrease the name collisions
Date: Wed, 24 Apr 2019 19:51:35 +0200	[thread overview]
Message-ID: <CAKv+Gu_U4NXjZ+S9zaYitPQvA_J8GB7FytUX7M+UhB8TeOA_=A@mail.gmail.com> (raw)
In-Reply-To: <E92EE9817A31E24EB0585FDF735412F5B9C9DA8C@ORSMSX113.amr.corp.intel.com>

On Wed, 24 Apr 2019 at 19:31, Kinney, Michael D
<michael.d.kinney@intel.com> wrote:
>
> Hi Ard,
>
> I see no issues with using 'static' on more symbols.
>
> I am not sure how to enforce it, so it would be a good
> recommendation for code style and a good recommendation
> for a code reviews.
>

In Linux, it is one of the things enforced by the sparse tool: if no
declaration exists anywhere in a .h file, it warns about it, since it
means only the defining translation unit can refer to it.

> Can you provide an example where code generation is
> improved when 'static' is used.  That would be good to
> include with the recommendations and would help encourage
> developers to follow the recommendation.
>

Something like

STATIC UINT32 mVar = FixedPcdGet32 (FooCount);

VOID Func (VOID)
{
      UINT32 Index;

   for (Index = 0; Index < mVar; Index++) {
     ...
   }
}

If the compiler notices that there are no other assignments of mVar
(or can prove they are unreachable), it simply treats mVar as an
immediate constant, and removes the whole loop if mVar == 0. This is
only possible when using STATIC (or when using LTO, and so the lack of
STATIC may be one of the reasons LTO is so effective on our codebase)

The compiler will even track value ranges, i.e., if the only other
reachable assignment sets mVar to 1, it can take that into account in
the code generation as well.

As soon as the mVar symbol gets exported, the compiler must assume
that it can hold any value representable by the type, which defeats
many of these optimizations.


>
> > -----Original Message-----
> > From: devel@edk2.groups.io [mailto:devel@edk2.groups.io]
> > On Behalf Of Ard Biesheuvel
> > Sent: Wednesday, April 24, 2019 10:10 AM
> > To: Kinney, Michael D <michael.d.kinney@intel.com>
> > Cc: devel@edk2.groups.io; Gao, Zhichao
> > <zhichao.gao@intel.com>; Laszlo Ersek
> > <lersek@redhat.com>; Gao, Liming <liming.gao@intel.com>;
> > Bi, Dandan <dandan.bi@intel.com>
> > Subject: Re: [edk2-devel] [PATCH V2 3/8]
> > MdePkg/UefiDebugLibStdErr: Decrease the name collisions
> >
> > On Wed, 24 Apr 2019 at 18:59, Kinney, Michael D
> > <michael.d.kinney@intel.com> wrote:
> > >
> > > Hi Ard,
> > >
> > > I see a mix of use of 'static' and 'STATIC' in the
> > sources.
> > >
> > > The reason to use STATIC is if it needs to be replaced
> > with
> > > something other than 'static' for a specific compiler
> > or
> > > debug scenario.
> > >
> > > Long ago, there were some source level debug issue with
> > > 'static' symbols, so using the macro STATIC was
> > preferred
> > > so it could be mapped to nothing for a debug scenario.
> > That
> > > issue no long exists.
> > >
> > > Do you know of a reason today to map 'STATIC' to
> > anything
> > > Other than 'static'?
> > >
> > > I also looked at the EDK II C Coding Standard.  It is
> > also
> > > inconsistent and had references to both 'static' and
> > 'STATIC'.
> > > We should enter a few BZs to update that doc once we
> > have
> > > clear guidance from this discussion.
> > >
> >
> > I wasn't aware that lower case static is also in use, so
> > I was simply
> > extrapolating from personal experience.
> >
> > i think there should be no reason to use the preprocessor
> > to change
> > 'static' into something else, and so I'm happy to settle
> > on lowercase
> > static, as long as we are consistent. But more
> > importantly, now that
> > this has come up, what I would like to do is make
> > 'static' mandatory
> > unless the code requires otherwise: this results in much
> > better code
> > generation (given that the compiler can infer constness
> > for non-const
> > static variables but not for ones with external linkage)
> > and generally
> > improves programmer hygiene when it comes to linking to
> > arbitrary
> > symbols that are really internal to a library.
> >
> >
> > > > -----Original Message-----
> > > > From: devel@edk2.groups.io
> > [mailto:devel@edk2.groups.io]
> > > > On Behalf Of Ard Biesheuvel
> > > > Sent: Wednesday, April 24, 2019 1:07 AM
> > > > To: edk2-devel-groups-io <devel@edk2.groups.io>; Gao,
> > > > Zhichao <zhichao.gao@intel.com>
> > > > Cc: Laszlo Ersek <lersek@redhat.com>; Kinney, Michael
> > D
> > > > <michael.d.kinney@intel.com>; Gao, Liming
> > > > <liming.gao@intel.com>; Bi, Dandan
> > <dandan.bi@intel.com>
> > > > Subject: Re: [edk2-devel] [PATCH V2 3/8]
> > > > MdePkg/UefiDebugLibStdErr: Decrease the name
> > collisions
> > > >
> > > > On Wed, 24 Apr 2019 at 06:59, Gao, Zhichao
> > > > <zhichao.gao@intel.com> wrote:
> > > > >
> > > > > REF:
> > > > https://bugzilla.tianocore.org/show_bug.cgi?id=1740
> > > > >
> > > > > Add a 'static' descriptor to the global variables
> > that
> > > > only
> > > > > used in a single file to minimize the name
> > collisions.
> > > > > This is only for the varable named
> > > > 'mExitBootServicesEvent'.
> > > > >
> > > > > Cc: Laszlo Ersek <lersek@redhat.com>
> > > > > Cc: Michael D Kinney <michael.d.kinney@intel.com>
> > > > > Cc: Liming Gao <liming.gao@intel.com>
> > > > > Cc: Dandan Bi <dandan.bi@intel.com>
> > > > > Signed-off-by: Zhichao Gao <zhichao.gao@intel.com>
> > > > > ---
> > > > >
> > > >
> > MdePkg/Library/UefiDebugLibStdErr/DebugLibConstructor.c |
> > > > 4 ++--
> > > > >  1 file changed, 2 insertions(+), 2 deletions(-)
> > > > >
> > > > > diff --git
> > > >
> > a/MdePkg/Library/UefiDebugLibStdErr/DebugLibConstructor.c
> > > >
> > b/MdePkg/Library/UefiDebugLibStdErr/DebugLibConstructor.c
> > > > > index d4fdfbab55..bb7b144569 100644
> > > > > ---
> > > >
> > a/MdePkg/Library/UefiDebugLibStdErr/DebugLibConstructor.c
> > > > > +++
> > > >
> > b/MdePkg/Library/UefiDebugLibStdErr/DebugLibConstructor.c
> > > > > @@ -15,9 +15,9 @@
> > > > >  //
> > > > >  // BOOLEAN value to indicate if it is at the post
> > > > ExitBootServices pahse
> > > > >  //
> > > > > -BOOLEAN     mPostEBS = FALSE;
> > > > > +BOOLEAN               mPostEBS = FALSE;
> > > > >
> > > > > -EFI_EVENT   mExitBootServicesEvent;
> > > > > +static EFI_EVENT      mExitBootServicesEvent;
> > > > >
> > > >
> > > > Please use STATIC not static.
> > > >
> > > >
> > > > >  //
> > > > >  // Pointer to SystemTable
> > > > > --
> > > > > 2.21.0.windows.1
> > > > >
> > > > >
> > > > >
> > > > >
> > > >
> > > >
> > >
> >
> > 
>

  reply	other threads:[~2019-04-24 17:51 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-24  4:58 [PATCH V2 0/8] Decrease the name collisions Gao, Zhichao
2019-04-24  4:58 ` [PATCH V2 1/8] MdePkg/UefiDebugLibConOut: " Gao, Zhichao
2019-04-24  4:58 ` [PATCH V2 2/8] MdePkg/UefiDebugLibDebugPortProtocol: " Gao, Zhichao
2019-04-24  4:58 ` [PATCH V2 3/8] MdePkg/UefiDebugLibStdErr: " Gao, Zhichao
2019-04-24  8:07   ` [edk2-devel] " Ard Biesheuvel
2019-04-24 16:59     ` Michael D Kinney
2019-04-24 17:09       ` Ard Biesheuvel
2019-04-24 17:31         ` Michael D Kinney
2019-04-24 17:51           ` Ard Biesheuvel [this message]
2019-10-15 11:20           ` Leif Lindholm
2019-04-26 16:49         ` Laszlo Ersek
2019-04-29 16:40           ` Michael D Kinney
2019-04-30  9:43             ` Laszlo Ersek
2019-04-24  4:58 ` [PATCH V2 4/8] IntelFrameworkModulePkg: " Gao, Zhichao
2019-04-24  4:58 ` [PATCH V2 5/8] MdeModulePkg/FirmwarePerformanceDxe: " Gao, Zhichao
2019-04-24  4:58 ` [PATCH V2 6/8] IntelFsp2WrapperPkg/FspWrapperNotifyDxe: " Gao, Zhichao
2019-04-24  5:19   ` Chiu, Chasel
2019-04-24  5:27   ` Nate DeSimone
2019-04-24  4:58 ` [PATCH V2 7/8] IntelFrameworkModulePkg: " Gao, Zhichao
2019-04-24  4:58 ` [PATCH V2 8/8] MdeModulePkg/StatusCodeHandlerRuntimeDxe: " Gao, Zhichao
2019-04-24 11:16 ` [PATCH V2 0/8] " Laszlo Ersek
2019-04-25  7:00   ` Gao, Zhichao

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-list 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='CAKv+Gu_U4NXjZ+S9zaYitPQvA_J8GB7FytUX7M+UhB8TeOA_=A@mail.gmail.com' \
    --to=devel@edk2.groups.io \
    /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