Conversation
labbott
marked this pull request as draft
August 28, 2026 19:20
The hash driver was originally written for isolation. Other tasks would call into hash driver as necessary. It turns out the only use case we've found for accelerated hashing on the SP is hashing the host flash QSPI. There's a non-trivial overhead associated with having the hash block as a separate task which makes it almost as slow as doing software only hashing. Move the hash block directly into the host task. This change also removes the hiffy interfaces for hashing. While this is technically a breaking change we've never really made use of the hash interface except for testing and profiling. Before: laura@cadbury ~ $ time pfexec humility -t c71 hiffy -c HostFlash.hash -aaddress=0,len=33554432 --timeout 1000000 humility: attached to 0483:3754:001100184741500820383733 via ST-Link V3 HostFlash.hash() => [ 0x9c, 0x41, 0xaf, 0x46, 0x10, 0xb8, 0x55, 0x1f, 0x28, 0x5a, 0xf6, 0xbe, 0xd7, 0x84, 0x2c, 0xab, 0xc6, 0xa4, 0x2a, 0xf4, 0x90, 0x93, 0x88, 0x8a, 0xc9, 0x61, 0x39, 0xf3, 0xde, 0xee, 0x86, 0x1d ] real 0m10.115s user 0m3.457s sys 0m0.663s After: laura@cadbury ~ $ time pfexec humility -t c71 -a ~/build-gimlet-c-lab-image-default.zip hiffy -c HostFlash.hash -aaddress=0,len=33554432 --timeout 1000000 humility: WARNING: archive on command-line overriding archive in environment file humility: attached to 0483:3754:001100184741500820383733 via ST-Link V3 HostFlash.hash() => [ 0x9c, 0x41, 0xaf, 0x46, 0x10, 0xb8, 0x55, 0x1f, 0x28, 0x5a, 0xf6, 0xbe, 0xd7, 0x84, 0x2c, 0xab, 0xc6, 0xa4, 0x2a, 0xf4, 0x90, 0x93, 0x88, 0x8a, 0xc9, 0x61, 0x39, 0xf3, 0xde, 0xee, 0x86, 0x1d ] real 0m7.355s user 0m3.319s sys 0m0.560s
The hash library keeps an internal buffer of bytes to always write a full hash block (16*4 bytes). This was designed to accomodate making multiple `update` calls with data less than a block of data. This is good for correctness and flexibility but the extra copy ends up being expensive. Introduce the `update_exact` API which avoids the extra copy if the data is a multiple of a hash block.
The QPSI hardware has an internal FIFO with a configurable threshold to generate an interrupt. We currently have it set to 16 (50%). This results in many context switches because we wait for an interrupt when it drops below that threshold. Turning it down improves performance at the cost of blocking for longer periods of time. Baseline laura@cadbury ~ $ time pfexec humility -t c71 -a ~/build-gimlet-c-lab-image-default.zip hiffy -c HostFlash.hash -aaddress=0,len=33554432 --timeout 1000000 humility: WARNING: archive on command-line overriding archive in environment file humility: attached to 0483:3754:001100184741500820383733 via ST-Link V3 HostFlash.hash() => [ 0x9c, 0x41, 0xaf, 0x46, 0x10, 0xb8, 0x55, 0x1f, 0x28, 0x5a, 0xf6, 0xbe, 0xd7, 0x84, 0x2c, 0xab, 0xc6, 0xa4, 0x2a, 0xf4, 0x90, 0x93, 0x88, 0x8a, 0xc9, 0x61, 0x39, 0xf3, 0xde, 0xee, 0x86, 0x1d ] real 0m7.480s user 0m3.315s sys 0m0.562s FIFO_THRESH 8 laura@cadbury ~ $ time pfexec humility -t c71 -a ~/build-gimlet-c-lab-image-default.zip hiffy -c HostFlash.hash -aaddress=0,len=33554432 --timeout 1000000 humility: WARNING: archive on command-line overriding archive in environment file humility: attached to 0483:3754:001100184741500820383733 via ST-Link V3 HostFlash.hash() => [ 0x9c, 0x41, 0xaf, 0x46, 0x10, 0xb8, 0x55, 0x1f, 0x28, 0x5a, 0xf6, 0xbe, 0xd7, 0x84, 0x2c, 0xab, 0xc6, 0xa4, 0x2a, 0xf4, 0x90, 0x93, 0x88, 0x8a, 0xc9, 0x61, 0x39, 0xf3, 0xde, 0xee, 0x86, 0x1d ] real 0m6.504s user 0m3.235s sys 0m0.498s FIFO_THRESH 4 laura@cadbury ~ $ time pfexec humility -t c71 -a ~/build-gimlet-c-lab-image-default.zip hiffy -c HostFlash.hash -aaddress=0,len=33554432 --timeout 1000000 humility: WARNING: archive on command-line overriding archive in environment file humility: attached to 0483:3754:001100184741500820383733 via ST-Link V3 HostFlash.hash() => [ 0x9c, 0x41, 0xaf, 0x46, 0x10, 0xb8, 0x55, 0x1f, 0x28, 0x5a, 0xf6, 0xbe, 0xd7, 0x84, 0x2c, 0xab, 0xc6, 0xa4, 0x2a, 0xf4, 0x90, 0x93, 0x88, 0x8a, 0xc9, 0x61, 0x39, 0xf3, 0xde, 0xee, 0x86, 0x1d ] real 0m6.480s user 0m3.242s sys 0m0.495s laura@cadbury ~ $ time pfexec humility -t c71 -a ~/build-gimlet-c-lab-image-default.zip hiffy -c HostFlash.hash -aaddress=0,len=33554432 --timeout 1000000 humility: WARNING: archive on command-line overriding archive in environment file humility: attached to 0483:3754:001100184741500820383733 via ST-Link V3 HostFlash.hash() => [ 0x9c, 0x41, 0xaf, 0x46, 0x10, 0xb8, 0x55, 0x1f, 0x28, 0x5a, 0xf6, 0xbe, 0xd7, 0x84, 0x2c, 0xab, 0xc6, 0xa4, 0x2a, 0xf4, 0x90, 0x93, 0x88, 0x8a, 0xc9, 0x61, 0x39, 0xf3, 0xde, 0xee, 0x86, 0x1d ] real 0m6.196s user 0m3.210s sys 0m0.485s
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.