Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: AdvancedLoggerHdwPortLib should not check PCD for header versions greater than 2 #309

Closed
1 task done
spbrogan opened this issue Sep 6, 2023 · 3 comments · Fixed by #311
Closed
1 task done
Assignees
Labels
state:needs-triage Needs to triaged to determine next steps type:bug Something isn't working urgency:medium Important with a moderate impact

Comments

@spbrogan
Copy link
Member

spbrogan commented Sep 6, 2023

Is there an existing issue for this?

  • I have searched existing issues

Current Behavior

wasted execution time on a hot path comparing the debug level against the PCD at both levels.

if (DebugLevel & PcdGet32 (PcdAdvancedLoggerHdwPortDebugPrintErrorLevel)) {

Why does calling code just mask the bits rather than avoid the function call?

DebugLevel = (DebugLevel & LoggerInfo->HwPrintLevel);

Expected Behavior

Expected to be as efficient as possible and require minimal code in lower layers.

Steps To Reproduce

Look at code

Build Environment

NA

Version Information

a3d53ef6296bc0b1309cf2654017eb394a726dd4

all versions.

Urgency

Medium

Are you going to fix this?

Someone else needs to fix it

Do you need maintainer feedback?

No maintainer feedback needed

Anything else?

May have impact on downstream/out-of-tree projects and their implementations.

@spbrogan spbrogan added type:bug Something isn't working state:needs-triage Needs to triaged to determine next steps labels Sep 6, 2023
@spbrogan spbrogan assigned spbrogan and unassigned spbrogan Sep 6, 2023
@github-actions github-actions bot added state:needs-owner Needs an issue owner to be assigned urgency:medium Important with a moderate impact and removed state:needs-owner Needs an issue owner to be assigned labels Sep 6, 2023
@os-d
Copy link
Contributor

os-d commented Sep 7, 2023

There is a case here where we could not have LoggerInfo, in the SEC instance:

#ifdef ADVANCED_LOGGER_SEC
// If LoggerInfo == NULL, assume there is a HdwPort and it has not been disabled. This
// does occur in SEC
if ((LoggerInfo == NULL) || (!LoggerInfo->HdwPortDisabled)) {
#else
if ((LoggerInfo != NULL) && (!LoggerInfo->HdwPortDisabled)) {
if (LoggerInfo->Version >= ADVANCED_LOGGER_HW_LVL_VER) {
DebugLevel = (DebugLevel & LoggerInfo->HwPrintLevel);
}
#endif
AdvancedLoggerHdwPortWrite (DebugLevel, (UINT8 *)Buffer, NumberOfBytes);
}
.

So, either we need the HdwPortLib to check the PCD and the upper lib not to, or the SEC instance needs to be reworked or have a separate code path. The smaller delta here is having the HdwPortLib check the PCD and being unconditionally called, so I'll put up a PR for that and we can discuss if a different approach is better.

The other consideration here, though, is who will be implementing HdwPortLib. If this is intended to only use the mu_plus version, great, we can drop the upper layer's checking of the PCD. If a platform may implement HdwPortLib, then the core relies on the platform to check the PCD to only log what fields are set, which is a platform level decision, but may or may not be the intention of the AdvLogger flow.

@os-d
Copy link
Contributor

os-d commented Sep 11, 2023

Looking again, if we unconditionally log in SEC, which seems reasonable, we can drop this double checking.

@kuqin12
Copy link
Contributor

kuqin12 commented Sep 18, 2023

There were different use cases for the bitmask vs. PCD. The bitmask was added for inheriting the level set by its loader (i.e. PEI core, when DXE is loaded, etc.). But the PCD was left alone to keep the functionality where the print level for each module can be changed on demand.

kuqin12 added a commit that referenced this issue Oct 10, 2023
## Description

The DebugLevel is checked twice in the hot path on serial path writes
and the HdwPortWrite call is made even if the upper layer knows that the
message being logged does not meet the DebugLevel criteria.

Closes #309.

In order to maintain backwards compatibility, if the LoggerInfo block is
found to have a version less than the hardware logging level version,
the PCD is checked to decide whether to call HdwPortWrite or not.

In SEC, because we may not have the LoggerInfo structure, we check the
PCD to see if the message should be logged at this DebugLevel.

For each item, place an "x" in between `[` and `]` if true. Example:
`[x]`.
_(you can also check items in the GitHub UI)_

- [x] Impacts functionality?
- **Functionality** - Does the change ultimately impact how firmware
functions?
- Examples: Add a new library, publish a new PPI, update an algorithm,
...
- [ ] Impacts security?
- **Security** - Does the change have a direct security impact on an
application,
    flow, or firmware?
  - Examples: Crypto algorithm change, buffer overflow fix, parameter
    validation improvement, ...
- [ ] Breaking change?
- **Breaking change** - Will anyone consuming this change experience a
break
    in build or boot behavior?
- Examples: Add a new library class, move a module to a different repo,
call
    a function in a new library class in a pre-existing module, ...
- [ ] Includes tests?
  - **Tests** - Does the change include any explicit test code?
  - Examples: Unit tests, integration tests, robot tests, ...
- [ ] Includes documentation?
- **Documentation** - Does the change contain explicit documentation
additions
    outside direct code modifications (and comments)?
- Examples: Update readme file, add feature readme file, link to
documentation
    on an a separate Web page, ...

## How This Was Tested

Build tested.

## Integration Instructions

If a bespoke AdvLoggerHdwPortLib is used, AdvLoggerHdwPortWrite should
not check DebugLevel, but simply write the message to the hardware port.

Co-authored-by: kuqin12 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state:needs-triage Needs to triaged to determine next steps type:bug Something isn't working urgency:medium Important with a moderate impact
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants