public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Leif Lindholm <leif.lindholm@linaro.org>
To: Evan Lloyd <Evan.Lloyd@arm.com>
Cc: "edk2-devel@lists.01.org" <edk2-devel@lists.01.org>,
	Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	Matteo Carlini <Matteo.Carlini@arm.com>, nd <nd@arm.com>
Subject: Re: [PATCH 1/5] ArmPkg: Tidy GIC code before changes.
Date: Thu, 21 Sep 2017 18:43:16 +0100	[thread overview]
Message-ID: <20170921174316.wn75y3x77z472rc4@bivouac.eciton.net> (raw)
In-Reply-To: <AM4PR0801MB14441B892C184C1402F872DA8B660@AM4PR0801MB1444.eurprd08.prod.outlook.com>

On Thu, Sep 21, 2017 at 03:34:07PM +0000, Evan Lloyd wrote:
> Hi Leif.
> I agree/accept all the comments, except:
> 
> > -----Original Message-----
> > From: Leif Lindholm [mailto:leif.lindholm@linaro.org]
> > Sent: 14 September 2017 17:41
> > To: Evan Lloyd <Evan.Lloyd@arm.com>
> > Cc: edk2-devel@lists.01.org; Ard Biesheuvel <ard.biesheuvel@linaro.org>;
> > Matteo Carlini <Matteo.Carlini@arm.com>; nd <nd@arm.com>
> > Subject: Re: [PATCH 1/5] ArmPkg: Tidy GIC code before changes.
> > 
> > On Mon, Sep 11, 2017 at 04:23:31PM +0100, evan.lloyd@arm.com wrote:
> > > From: Evan Lloyd <evan.lloyd@arm.com>
> > >
> ...
> > 
> > >    // whereas Affinity3 is defined at [32:39] in MPIDR
> > > -  CpuAffinity = (MpId & (ARM_CORE_AFF0 | ARM_CORE_AFF1 |
> > > ARM_CORE_AFF2)) | ((MpId & ARM_CORE_AFF3) >> 8);
> > > +  CpuAffinity = (MpId & (ARM_CORE_AFF0 | ARM_CORE_AFF1 |
> > ARM_CORE_AFF2))
> > > +                | ((MpId & ARM_CORE_AFF3) >> 8);
> > 
> > I can't find an explicit rule on this, but my preference aligns with what
> > examples I can see in the Coding Style: moving that lone '|' to the end of the
> > preceding line:
> > 
> >   CpuAffinity = (MpId & (ARM_CORE_AFF0 | ARM_CORE_AFF1 |
> > ARM_CORE_AFF2)) |
> >                 ((MpId & ARM_CORE_AFF3) >> 8);
> 
> [[Evan Lloyd]] 5.2.1.6 and 5.7.2.4 have multiple examples of prefix style, 
>   with 5.2.2.11 and 5.7.2.3 providing only 2 instances of a line suffix operator.

The example of 5.2.1.6 already violates the rule of 5.2.2.11.
But the whole problem is that there is no explicit rule about
prefix/suffix, which leads to...

>   I can change it if you insist, but it will be a clear instance of a 
>   maintainer's personal prejudice overriding the coding standard.

If you can point me to a rule I have missed, then yes, you would be
absolutely correct. But I can only find uses, of both variants, in
examples explaining other rules.

If not, I am doing exactly what I am meant to be doing.

Since the maintainer is the one who a) has to review patches without
prior understanding of what the author was thinking and b) the one who
needs to review future modifications to that code, it would be highly
irresponsible to not ask for the code to be presented in the form most
clear to them, where this does not conflict with the coding style.

>   I strongly believe prefix format is much clearer, especially for
>   compound conditions with nesting.

Then why this prefix format not uniformly used in the patch?

Further down, there is
---
-    CpuTarget = MpId & (ARM_CORE_AFF0 | ARM_CORE_AFF1 | ARM_CORE_AFF2 | ARM_CORE_AFF3);
+    CpuTarget = MpId &
+                (ARM_CORE_AFF0 | ARM_CORE_AFF1 | ARM_CORE_AFF2 | ARM_CORE_AFF3);
---

Now, a) I think that's very clear and b) any other way pushes the
length of the second line over 80 characters. But it does mean you are
not adhering to the rules you are arguing for.

> > 
> > >    if (Revision == ARM_GIC_ARCH_REVISION_3) {
> ...
> > >      // Write set-enable register
> > > -    MmioWrite32 (GicCpuRedistributorBase +
> > ARM_GICR_CTLR_FRAME_SIZE + ARM_GICR_ISENABLER + (4 * RegOffset), 1
> > << RegShift);
> > > +    MmioWrite32 (
> > > +      (GicCpuRedistributorBase
> > > +        + ARM_GICR_CTLR_FRAME_SIZE
> > > +        + ARM_GICR_ISENABLER
> > > +        + (4 * RegOffset)),
> > > +      1 << RegShift
> > > +      );
> > 
> > Maybe rewrite as
> > 
> > #define SET_ENABLE_ADDRESS(base,offset) ((base) +
> > ARM_GICR_CTLR_FRAME_SIZE + \
> >                                          ARM_GICR_ISENABLER + (4 * offset))
> > 
> > (further up)
> > 
> > then
> > 
> >     MmioWrite32 (
> >       SET_ENABLE_ADDRESS (GicCpuRedistributorBase, RegOffset),
> >       1 << RegShift
> >       );
> > 
> > ?
> 
> [[Evan Lloyd]] Agree, but I called the macros ISENABLER_ADDRESS and ISENABLER_ADDRESS
> (using the register names) because SET_ seemed to imply writing something in this context.

Yes, this is much better.

Another reason why I keep banging on about macros - they let you
add descriptive semantics that makes the code easier to understand for
someone unfamiliar with it.

Regards,

Leif


  reply	other threads:[~2017-09-21 17:40 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-11 15:23 [PATCH 0/5] Add HardwareInterrupt2 for ARM evan.lloyd
2017-09-11 15:23 ` [PATCH 1/5] ArmPkg: Tidy GIC code before changes evan.lloyd
2017-09-14 16:41   ` Leif Lindholm
2017-09-21 15:34     ` Evan Lloyd
2017-09-21 17:43       ` Leif Lindholm [this message]
2017-09-11 15:23 ` [PATCH 2/5] EmbeddedPkg: Introduce HardwareInterrupt2 protocol evan.lloyd
2017-09-14 16:42   ` Leif Lindholm
2017-09-15  9:21     ` Alexei Fedorov
2017-09-11 15:23 ` [PATCH 3/5] ArmPkg/ArmGicDxe: Expose " evan.lloyd
2017-09-14 17:00   ` Leif Lindholm
2017-09-11 15:23 ` [PATCH 4/5] ArmPkg/GenericWatchdogDxe: Set Watchdog interrupt type evan.lloyd
2017-09-14 17:06   ` Leif Lindholm
2017-09-11 15:23 ` [PATCH 5/5] ArmPkg: Tidy up GenericWatchdogDxe.c evan.lloyd
2017-09-14 17:10   ` Leif Lindholm
  -- strict thread matches above, loose matches on Subject: below --
2017-02-16 22:14 [PATCH 0/5] HardwareInterrupt2 protocol evan.lloyd
2017-02-16 22:14 ` [PATCH 1/5] ArmPkg: Tidy GIC code before changes evan.lloyd

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=20170921174316.wn75y3x77z472rc4@bivouac.eciton.net \
    --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