public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
To: Alexei Fedorov <Alexei.Fedorov@arm.com>
Cc: Evan Lloyd <Evan.Lloyd@arm.com>,
	"edk2-devel@lists.01.org" <edk2-devel@lists.01.org>,
	 "leif.lindholm@linaro.org@arm.com"
	<"leif.lindholm@linaro.org"@arm.com>,
	 "nd@arm.com@arm.com" <"nd@arm.com"@arm.com>,
	 "ard.biesheuvel@linaro.org@arm.com"
	<"ard.biesheuvel@linaro.org"@arm.com>,
	 "Matteo.Carlini@arm.com@arm.com"
	<"Matteo.Carlini@arm.com"@arm.com>
Subject: Re: [PATCH 04/19] ArmPlatformPkg: LcdGraphicsOurputDxe: Add debug asserts
Date: Fri, 8 Dec 2017 21:39:43 +0000	[thread overview]
Message-ID: <CAKv+Gu9udgpyNDXUDO2sbhZNmTKKzw1mrEqxEjGXiXr7RNmt=Q@mail.gmail.com> (raw)
In-Reply-To: <DB5PR08MB10146236F42F95D024621A0A9A330@DB5PR08MB1014.eurprd08.prod.outlook.com>

On 7 December 2017 at 16:53, Alexei Fedorov <Alexei.Fedorov@arm.com> wrote:
> As expected with new ASSERT_EFI_ERROR () definition compiler generates 1
> conditional branch at the start:
>
>
> // r:\edk2\ArmPlatformPkg\Drivers\LcdGraphicsOutputDxe\HdLcd.c:79:
> ASSERT_EFI_ERROR (Status);
>     .loc 1 79 0
>     tbz    x0, #63, .L4    // Status,
>

Thanks for confirming!


>
> ________________________________
> From: Ard Biesheuvel <ard.biesheuvel@linaro.org>
> Sent: 07 December 2017 15:10:05
> To: Alexei Fedorov
> Cc: Evan Lloyd; edk2-devel@lists.01.org; leif.lindholm@linaro.org@arm.com;
> nd@arm.com@arm.com; ard.biesheuvel@linaro.org@arm.com;
> Matteo.Carlini@arm.com@arm.com
> Subject: Re: [PATCH 04/19] ArmPlatformPkg: LcdGraphicsOurputDxe: Add debug
> asserts
>
> On 7 December 2017 at 14:55, Alexei Fedorov <Alexei.Fedorov@arm.com> wrote:
>> Hi,
>>
>> I've compiled current HdLcd.c code with different optimisation levels for
>> DEBUG build using GCC 7.2.1, and the assembler code below was generated
>> for:
>>
>>   ASSERT_EFI_ERROR (Status);
>>   if (EFI_ERROR( Status )) {
>>     return EFI_DEVICE_ERROR;
>>   }
>>
>> -O0 (default DEBUG option for AARCH64 before Ard's patch):
>>
>>
>>     str    x0, [x29, 72]    //, Status
>>
>> // r:\edk2\ArmPlatformPkg\Drivers\LcdGraphicsOutputDxe\HdLcd.c:79:
>> ASSERT_EFI_ERROR (Status);
>>     .loc 1 79 0
>>     bl    DebugAssertEnabled    //
>>     and    w0, w0, 255    // _1, tmp150
>>     cmp    w0, 0    // _1,
>>     beq    .L4    //,
>>     ldr    x0, [x29, 72]    // Status.9_2, Status
>>     cmp    x0, 0    // Status.9_2,
>>     bge    .L4    //,
>>
>> 2.  -Os:
>>
>>      mov    x19, x0    // Status,
>> // r:\edk2\ArmPlatformPkg\Drivers\LcdGraphicsOutputDxe\HdLcd.c:79:
>> ASSERT_EFI_ERROR (Status);
>>     .loc 1 79 0
>>     bl    DebugAssertEnabled    //
>> .LVL15:
>>     tst    w0, 255    //
>>     beq    .L4    //,
>>     tbz    x19, #63, .L8    // Status,
>>
>> 3.  -O3:
>>
>>     mov    x19, x0    // Status,
>> .LVL14:
>> // r:\edk2\ArmPlatformPkg\Drivers\LcdGraphicsOutputDxe\HdLcd.c:79:
>> ASSERT_EFI_ERROR (Status);
>>     bl    DebugAssertEnabled    //
>> .LVL15:
>>     tst    w0, 255    //
>>     beq    .L5    //,
>>     tbnz    x19, #63, .L26    // Status,
>>
>> with DebugAssertEnabled() compiled as:
>>
>> DebugAssertEnabled:
>> .LFB4:
>>     .loc 1 203 0
>>     .cfi_startproc
>> // r:\edk2\MdePkg\Library\BaseDebugLibSerialPort\DebugLib.c:204:   return
>> (BOOLEAN) ((PcdGet8(PcdDebugPropertyMask) &
>> DEBUG_PROPERTY_DEBUG_ASSERT_ENABLED) != 0);
>>     .loc 1 204 0
>>     adrp    x0, _gPcd_FixedAtBuild_PcdDebugPropertyMask    // tmp80,
>>     add    x0, x0, :lo12:_gPcd_FixedAtBuild_PcdDebugPropertyMask    //
>> tmp79, tmp80,
>>     ldrb    w0, [x0]    // _gPcd_FixedAtBuild_PcdDebugPropertyMask.4_1,
>> _gPcd_FixedAtBuild_PcdDebugPropertyMask
>>     and    w0, w0, 1    // _3, _2,
>>     cmp    w0, 0    // _3,
>>     cset    w0, ne    // tmp82,
>>     and    w0, w0, 255    // _4, tmp81
>> // r:\edk2\MdePkg\Library\BaseDebugLibSerialPort\DebugLib.c:205: }
>>     .loc 1 205 0
>>     ret
>>
>> As you can see each "ASSERT_EFI_ERROR (Status)" macro requires
>> DebugAssertEnabled() call taking 8 instructions by itself + minimum 3
>> instructions (for -Os, -O3) for Status check, which will be performed by
>> "if
>> (EFI_ERROR( Status ))" anyway.
>> Please correct me if I'm wrong assuming that placing
>> ASSERT_EFI_ERROR (Status)
>> inside
>> if (EFI_ERROR( Status )) {
>> statement is an optimisation improvement.
>>
>
> Thanks for digging this up. This appears to be an oversight in the
> definition of the ASSERT_EFI_ERROR () macro, which is currently
> defined as
>
> #if !defined(MDEPKG_NDEBUG)
>   #define ASSERT_EFI_ERROR(StatusParameter)                              \
>     do {                                                                 \
>       if (DebugAssertEnabled ()) {                                       \
>         if (EFI_ERROR (StatusParameter)) {                               \
>
> which is obviously the wrong way around, given that the compiler can
> never optimize away the function call, due to its potential side
> effects (which it doesn't have)
>
> So I will propose to fix this, by swapping the two if () statements.
> Please let me know if the issue is still reproducible with that patch
> applied.
> IMPORTANT NOTICE: The contents of this email and any attachments are
> confidential and may also be privileged. If you are not the intended
> recipient, please notify the sender immediately and do not disclose the
> contents to any other person, use it for any purpose, or store or copy the
> information in any medium. Thank you.


  reply	other threads:[~2017-12-08 21:35 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-26 20:15 [PATCH 00/19] ArmPlatformPkg: Update GOP evan.lloyd
2017-09-26 20:15 ` [PATCH 01/19] ArmPlatformPkg: Tidy LcdGraphicsOutputDxe code: Coding standard evan.lloyd
2017-10-12 18:45   ` Leif Lindholm
2017-09-26 20:15 ` [PATCH 02/19] ArmPlatformPkg: Tidy LcdGraphicsOutputDxe code: Added comments evan.lloyd
2017-10-12 19:02   ` Leif Lindholm
2017-12-05 18:55     ` Evan Lloyd
2017-12-05 19:58       ` Leif Lindholm
2017-12-05 22:06         ` Evan Lloyd
2017-09-26 20:15 ` [PATCH 03/19] ArmPlatformPkg: PL111 and HDLCD: add const qualifier evan.lloyd
2017-10-12 19:07   ` Leif Lindholm
2017-10-12 19:47   ` Ard Biesheuvel
2017-12-01 16:17     ` Evan Lloyd
2017-12-01 17:31       ` Ard Biesheuvel
2017-12-05 20:35         ` Evan Lloyd
2017-12-05 20:54           ` Ard Biesheuvel
2017-09-26 20:15 ` [PATCH 04/19] ArmPlatformPkg: LcdGraphicsOurputDxe: Add debug asserts evan.lloyd
2017-10-12 19:32   ` Leif Lindholm
2017-10-13  7:33   ` Ard Biesheuvel
2017-12-01 16:33     ` Evan Lloyd
2017-12-01 17:34       ` Ard Biesheuvel
2017-12-01 17:58         ` Leif Lindholm
2017-12-05 20:46         ` Evan Lloyd
2017-12-07 14:55           ` Alexei Fedorov
2017-12-07 15:10             ` Ard Biesheuvel
2017-12-07 16:53               ` Alexei Fedorov
2017-12-08 21:39                 ` Ard Biesheuvel [this message]
2017-09-26 20:15 ` [PATCH 05/19] ArmPlatformPkg: PL111LcdArmVExpressLib: Minor code cleanup evan.lloyd
2017-10-12 19:33   ` Leif Lindholm
2017-09-26 20:15 ` [PATCH 06/19] ArmPlatformPkg: PL111Lcd: Replace magic number with macro evan.lloyd
2017-10-12 19:34   ` Leif Lindholm
2017-09-26 20:15 ` [PATCH 07/19] ArmPlatformPkg: PL111LcdArmVExpressLib: Use FixedPcdGet32 evan.lloyd
2017-10-12 19:35   ` Leif Lindholm
2017-09-26 20:15 ` [PATCH 08/19] ArmPlatformPkg: PL11LcdArmVExpressLib: Improvement conditional evan.lloyd
2017-10-12 19:36   ` Leif Lindholm
2017-09-26 20:15 ` [PATCH 09/19] ArmPlatformPkg: HdLcdArmVExpressLib: Use FixedPcdGet32 evan.lloyd
2017-10-12 19:38   ` Leif Lindholm
2017-09-26 20:15 ` [PATCH 10/19] ArmPlatformPkg: HdLcdArmVExpressLib: Remove status check EFI_TIMEOUT evan.lloyd
2017-10-12 19:40   ` Leif Lindholm
2017-09-26 20:15 ` [PATCH 11/19] ArmPlatformPkg: Implement LcdIdentify function for HDLCD GOP evan.lloyd
2017-10-12 19:43   ` Leif Lindholm
2017-09-26 20:15 ` [PATCH 12/19] ArmPlatformPkg: Redefine LcdPlatformGetTimings function evan.lloyd
2017-10-13  7:49   ` Leif Lindholm
2017-09-26 20:15 ` [PATCH 13/19] ArmPlatformPkg: HdLcd Remove redundant Bpp evan.lloyd
2017-10-13  7:53   ` Leif Lindholm
2017-10-17 14:32     ` Evan Lloyd
2017-10-17 15:40       ` Leif Lindholm
2017-09-26 20:15 ` [PATCH 14/19] ArmPlatformPkg: Add PCD to select pixel format evan.lloyd
2017-10-25 14:27   ` Leif Lindholm
2017-09-26 20:15 ` [PATCH 15/19] ArmPlatformPkg: PCD to swap red/blue format for HDLCD evan.lloyd
2017-10-25 14:33   ` Leif Lindholm
2017-09-26 20:15 ` [PATCH 16/19] ArmPlatformPkg: Reorganize Lcd Graphics Output evan.lloyd
2017-10-25 14:44   ` Leif Lindholm
2017-09-26 20:15 ` [PATCH 17/19] ArmPlatformPkg: Additional display modes evan.lloyd
2017-10-25 14:45   ` Leif Lindholm
2017-09-26 20:15 ` [PATCH 18/19] ArmPlatformPkg: Reserving framebuffer at build evan.lloyd
2017-10-25 14:51   ` Leif Lindholm
2017-10-25 18:10   ` Ard Biesheuvel
2017-12-01 16:56     ` Evan Lloyd
2017-12-01 17:38       ` Ard Biesheuvel
2017-09-26 20:15 ` [PATCH 19/19] ArmPlatformPkg: New DP500/DP550/DP650 GOP driver evan.lloyd
2017-10-25 15:31   ` Leif Lindholm
2017-11-28 18:17   ` Ard Biesheuvel
2017-12-01 13:12     ` Evan Lloyd
2017-12-01 17:18       ` Ard Biesheuvel
2017-12-05 20:03         ` Evan Lloyd
2017-12-05 21:27           ` Ard Biesheuvel
2017-12-07 20:21             ` Evan Lloyd
2017-12-07 21:10               ` Ard Biesheuvel
2017-12-01 17:29       ` Leif Lindholm

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+Gu9udgpyNDXUDO2sbhZNmTKKzw1mrEqxEjGXiXr7RNmt=Q@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