Skip to content

LittleFS: correct CRC calculation #11896

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

Closed
wants to merge 2 commits into from
Closed

Conversation

kjbracey
Copy link
Contributor

@kjbracey kjbracey commented Nov 19, 2019

Description (required)

When using MbedCRC, init value must be non-reversed, regardless of reflect_data or reflect_out settings. This means we need to reflect the intermediate output before using it as the next init value.

(In GCC this ends up putting in two RBIT instructions back-to-back, because it's implemented as assembler, so it doesn't know how to optimise. In ARMC6, __RBIT is implemented as an intrinsic, so adding this reflection cancels the existing reflection and makes the code smaller).

Summary of change (What the change is for and why)

Fixes #11879

Documentation (Details of any document updates required)

n/a


Pull request type (required)

[X] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Fixes issue caused by #11559, so depends on that.


Test results (required)

[] No Tests required for this change (E.g docs only update)
[X] Covered by existing mbed-os tests (Greentea or Unittest)
[] Tests / results supplied as part of this PR

Is covered by existing tests, but they're not being run?

@ciarmcom ciarmcom requested review from a team November 19, 2019 14:00
@ciarmcom
Copy link
Member

@kjbracey-arm, thank you for your changes.
@ARMmbed/mbed-os-storage @ARMmbed/mbed-os-maintainers please review.

@VeijoPesonen
Copy link
Contributor

@kjbracey-arm Should this fix and your previous commit be upstreamed? littlefs

@kjbracey
Copy link
Contributor Author

@kjbracey-arm Should this fix and your previous commit be upstreamed? littlefs

The code I'm touching isn't actually in that upstream version - the "use Mbed CRC" code is in our version only.

@kjbracey
Copy link
Contributor Author

There's nothing actually wrong with LFS's own software CRC code - it's a tight and pretty-optimal reflected CRC32. I'd not have bothered trying to hook it up to MbedCRC in the first place, but I guess hooking it up allows code+table reuse in theory.

It doesn't allow hardware acceleration though, because LFS doesn't have "start/stop" as part of its API, and often does it 1 byte at a time, which doesn't mesh well with HW acceleration.

When using MbedCRC, init value must be non-reversed, regardless of
`reflect_data` or `reflect_out` settings. This means we need to reflect
the intermediate output before passing using it as the next init value.

(In GCC this ends up putting in two `RBIT` instructions back-to-back,
because it's implemented as assembler, so it doesn't know how to
optimise. In ARMC6, `__RBIT` is implemented as an intrinsic, so adding
this reflection cancels the existing reflection and makes the code
smaller).
@0xc0170
Copy link
Contributor

0xc0170 commented Nov 21, 2019

CI started meanwhile

@mbed-ci
Copy link

mbed-ci commented Nov 21, 2019

Test run: FAILED

Summary: 1 of 4 test jobs failed
Build number : 1
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_build-ARM

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 21, 2019

CI restarted (internal error)

@mbed-ci
Copy link

mbed-ci commented Nov 21, 2019

Test run: SUCCESS

Summary: 11 of 11 test jobs passed
Build number : 2
Build artifacts

@0xc0170 0xc0170 added release-version: 6.0.0-alpha-1 First pre-release version of 6.0.0 and removed release-version: 5.15.0-rc1 labels Nov 21, 2019
Copy link
Contributor

@teetak01 teetak01 left a comment

Choose a reason for hiding this comment

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

Verified to also fix the client-issue.

KVStore external is using LittleFS so this fixes also all client targets that use that configuration.

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 21, 2019

Preceding PR (5.15rc1 needs to be created first - soon). Otherwise this is ready.

Copy link
Contributor

@jamesbeyond jamesbeyond left a comment

Choose a reason for hiding this comment

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

LittleFS test passed manual testing

@geky
Copy link
Contributor

geky commented Nov 22, 2019

Looks good to me 👍

It doesn't allow hardware acceleration though, because LFS doesn't have "start/stop" as part of its API, and often does it 1 byte at a time, which doesn't mesh well with HW acceleration.

I agree, in practice I doubt we really get much benefit from HW acceleration here.

It's theoretically possible to refactor LFS to better batch together CRC of operations (lfs_cache_crc?), but I don't think there's much interest in this as most CRC operations are heavily overshadowed by waiting for storage transactions.

@kjbracey
Copy link
Contributor Author

kjbracey commented Nov 25, 2019

I don't think there's much interest in this

And indeed there's a danger - we've just got a giant mutex on the singleton CRC hardware, so if the storage or some other bulk thing were to start using it, anything low-latency like a radio would find itself shut out.

We already have the equivalent problem with storage vs radio and SPI mutex locks, but that's been pushed aside simply by using one mutex per SPI bus. We've no solution for thread-switching singleton hardware like crypto.

I can see various solutions to address that problem, but none are straightforward. Not inclined to tackle it at this time.

@bulislaw
Copy link
Member

Why 6 and not 5.15?

@kjbracey
Copy link
Contributor Author

kjbracey commented Nov 25, 2019

Why 6 and not 5.15?

Cos this is fixing a bug in #11559, which is filed for 6 because there are breaking changes (change to way 7-bit CRCs are handled, removal of special POLY_32BIT_REV_ANSI case, and a table correction that changes results).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

filesystem-littlefs Greentea test failed after CRC revision #11559 merged
10 participants