-
Notifications
You must be signed in to change notification settings - Fork 3k
rand() and srand() are made sparse to not have same block. #9820
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
Conversation
Random number generation in case of IAR 8, requires TLS support. Thread local storage is not part of Mbed OS, test is updated to have random numbers sparse, but in future random number creation should be moved to main thread, or use some other logic for randomization instead of rand() call.
Started CI to test the fix |
Test run: SUCCESSSummary: 12 of 12 test jobs passed |
PR #9650 (delivered 2 weeks ago) fixed block overwrite by different threads. If the failure did not happen on the updated test then Pls see my remark to Martin's question at #9650, and let me know if its sufficient. AFAIK, seeding at +1 or +2 shouldn't make a difference, because a +1 difference in seed results in a "random" difference in the rand series (and this test doesn't really require a random series, only a set of 50 different numbers). |
Error was noted after #9650. I just tried different seed as +1 was not working with IAR8 but the proper solution I will leave it to storage team as stated in description. And +2 worked for all compilers so it will be stable for some time ‘Time’ should not be used for rand it will have its own issue and with time we will have sec precision. Generating a random number table for threads to use will be a good option. |
Simplest solution is to make sure the threads can never collide by interleaving their accesses:
(This might be too simplisitic if trying to stress test the actual storage device and its controller - the striped access pattern wouldn't fully exercise a cache - but for a general a test of our software and all the block device drivers should be fine). |
@deepikabhavnani - can you please supply logs for the failing in IAR8, probably requires a JIRA as well |
This one failed http://mbed-os-ci.s3-website-eu-west-1.amazonaws.com/?prefix=jenkins-ci/ARMmbed/mbed-os/mbed-os-ci/PR-9811/artifacts/9811/1/greentea-test/1239/FAIL/, test can be found #9811 (run twice to confirm the failures) |
@0xc0170 : The change suggested by @deepikabhavnani uses a different series of random numbers. It resolves the problem for IAR8 but might later on introduce more conflicts under a different setup. |
Closing this PR and will wait for @theamirocohen to add the fix. |
OK, but IAR8 feature branch is now ready and includes this fix. Let me verify this is OK with you to go ahead and fix on master asap. |
@deepikabhavnani @0xc0170 |
Description
Random number generation API's - rand() and srand() are made sparse to not have same block.
Failure was noted when 2 threads getting same random number were trying to write to same block and rechecking resulted in error (since block was over-written by another thread).
Random number generation in case of IAR 8, requires TLS support and without TLS it may result into same random number since same main thread space is used for all threads.
This may happen in other cases as well when rand() gives same values for for 2-threads.
Future solution recommendation will be:
Instead of checking the same random data written, checksum logic can be used in future. Threads are allowed to overwrite the data (block commands are not in mutex) in test, so instead of verifying the exact data some checksum of data should be checked to make sure data was not jumbled up 2-threads accessing it.
Pull request type
Reviewers
@ARMmbed/mbed-os-storage
@ARMmbed/mbed-os-maintainers - Commit in applied to #9818 PR to test with IAR 8 and here to test with IAR 7 as well.
Please consider merging this when approved.