fix: avoid resetting method.hashUpdate#95
fix: avoid resetting method.hashUpdate#95mikolajlubiak wants to merge 2 commits intointel:developfrom
method.hashUpdate#95Conversation
This is done to avoid setting the variable twice, because in a multithreaded environment this destroys memory caches. Note that to make the code cleaner I used an early return in the special `sha256_ni_hashUpdate` case. Fixes intel/confidential-computing.sgx#1073 Signed-off-by: Mikołaj Lubiak <[email protected]>
|
To cite the issue:
|
|
Did a couple of benchmark runs, and the new code saves about 1,000,000,000 cache references, 10 CPU seconds (10% decrease), and halves the instruction count, in the specific benchmark case. Numbers hold roughly the same proportions in all runs. Without fix: Benchmark code: https://gist.github.com/mikolajlubiak/4d4c2f3286c03455f0aca256300aa3fe (from haxelion) |
|
Some other stats with the same benchmark: With fix: Without fix: |
|
@mikolajlubiak sorry I was AFK last week. It is unfortunate that the IPP CP API and the TCrypto API doesn't mesh well and forces us to call the I think that change can be broadly applied to all |
Yes, although this PR improves the performance a bit its still really poor.
You are right. I wanted to do that, but unfortunately had no free time. |
|
Thanks @mikolajlubiak and @haxelion for your valuable contribution and feedback. We'll check it internally and get back to you with an answer. |
|
Hello everyone, Summary of the fix: We've implemented a Recommendation: To ensure thread safety and optimal performance, we strongly recommend caching and reusing the returned pointer rather than making repeated function calls. We would appreciate your feedback on this approach. Please review the implementation and let us know if you have any concerns before we proceed with closing this PR. |
Hi @iMartyan, The fix looks good. Mine only got rid of cache invalidation while yours actually fixed the multithreading issue. I have a couple of questions though.
Thanks in advance, |
|
Hi @mikolajlubiak, Please find answers below:
Thanks again for looking into this matter, we really do appreciate it! Best regards, |
|
According to our CONTRIBUTING.md guide, I am closing the current PR as the changes has been introduced in the library. Thank you for your contribution! Please let us know if you have any more questions |
This is done to avoid setting the variable twice, because in a multithreaded environment this destroys memory caches. Note that to make the code cleaner I used an early return in the special
sha256_ni_hashUpdatecase.Compilation using the Intel® oneAPI DPC++/C++ compiler succeeded.
Code formatted according to the .clang-format rules.
Added a note in change log and incremented the version.
Fixes intel/confidential-computing.sgx#1073