Skip to content
This repository was archived by the owner on Mar 7, 2026. It is now read-only.

crc32: Buffer up log output to avoid prefix-chunking, fix func - #1998

Merged
dragonmux merged 1 commit into
blackmagic-debug:mainfrom
ALTracer:fix/crc32-snprintf
Jul 27, 2025
Merged

crc32: Buffer up log output to avoid prefix-chunking, fix func#1998
dragonmux merged 1 commit into
blackmagic-debug:mainfrom
ALTracer:fix/crc32-snprintf

Conversation

@ALTracer

Copy link
Copy Markdown
Contributor

Detailed description

  • This is a fix to one of my edited/contributed features regarding compare-sections via qCRC.
  • There are three existing problems, which are not critical to upstream BMD here.
  • This PR updates crc32 dispatch code to deal with them.
  1. Because of Fix: Replace attribute alias in CRC32 #1713 and requirements to support Windows and MacOS (cross-platform portable software), the __func__ portion of log became identical as collateral damage. This change restores the behaviour intended in Fix: qCRC performance uplift #1708, so that we can tell apart speed reports from BMF+ENABLE_DEBUG and BMDA.
  2. On out-of-tree platforms like Farpatch which use BMD as a git submodule directly, custom logger implementations format every DEBUG_INFO() call etc. by prepending loglevel and timestamp, so the 2-3 piece logmessage gets broken and mixed. This change buffers the optional output pieces into a zeroed stack buffer via snprintf() to avoid that.
  3. Xtensa Farpatch crashes on every divide-by-zero, which can happen here when <1 milliseconds are reported elapsed by corresponding platform timing code. BMF on Cortex-M3 does not trap integer divide-by-zero into UsageFault, so it was never affected. BMDA usually gets more than 1ms due to USB FS delays and all the layer overheads. This change skips the speed report by checking for both length and time to be big enough.

Your checklist for this pull request

Closing issues

Fixes some issues in Farpatch.

Comment thread src/crc32.c Outdated
@xobs

xobs commented Nov 11, 2024

Copy link
Copy Markdown
Contributor

I like this change! It improves readability when doing checksum benchmarking.

@dragonmux dragonmux added this to the v2.1 release milestone Jul 26, 2025
@dragonmux dragonmux added the Enhancement General project improvement label Jul 26, 2025
@dragonmux

Copy link
Copy Markdown
Member

Please could you rebase this on main and we'll look at getting this reviewed as soon as we can.

@ALTracer
ALTracer force-pushed the fix/crc32-snprintf branch from ef1c2ab to 7f93994 Compare July 26, 2025 15:42

@dragonmux dragonmux left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of notes in doing a review - but with them fixed, this looks basically ready to merge. Good job!

Comment thread src/crc32.c Outdated
Comment thread src/crc32.c Outdated
Comment thread src/crc32.c Outdated
Comment thread src/crc32.c Outdated
@ALTracer
ALTracer force-pushed the fix/crc32-snprintf branch 2 times, most recently from f48b77d to 5424dc1 Compare July 26, 2025 18:48

@dragonmux dragonmux left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM, merging. Thank you for the contribution!

While there's a known issue with 64-bit targets here, we're not going to have this block merging this as that's a separate issue that'll take a pile more work to fix and so should be a separate PR.

* Format the optional output pieces into a stack buffer, then do a single DEBUG_INFO() call
* Restore the name of compiled function implementation in the log output
* Avoid dividing by 0 milliseconds elapsed
@ALTracer
ALTracer force-pushed the fix/crc32-snprintf branch from 5424dc1 to 0ac0c23 Compare July 27, 2025 14:17
@dragonmux
dragonmux merged commit 0ac0c23 into blackmagic-debug:main Jul 27, 2025
35 of 36 checks passed
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Enhancement General project improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants