boards/arm/rp2040: allow flash write operation on rp2040 in SMP mode#17224
Conversation
d335498 to
64e7090
Compare
Thank you for the detailed test information! It's always appreciated a lot. Just to wrap my head around this, did d8cb775 break the RP2040 code for SMP flash writing entirely? As in, it worked before this commit and then began to fail after that commit (I assume you found this with
I think that's not a bad idea if it's generally applicable. I think it would be fine to merge this fix first since it solves (presumably) a regression, and then afterward you could see about re-factoring the solution to use your more general implementation?
Yes, there are some people working on Espressif boards and can probably run your changes against their internal CI to catch anything. I would like to note that it's very appreciated that you mention this, since there are a lot of PRs which only test one board and assume the changes apply just as well elsewhere.
What I'm wondering is, do the
Can't really help with any of this, sorry. I'm not familiar enough with much of the scheduling logic to say anything of value.
Maybe you could raise an issue for it and post to the mailing list to get more eyes on this?
Ditto, not informed enough to help with this either. |
|
Thanks for your comments!
It was a compile-time breakage. The referenced function was simply missing. See #16203. No other file contained a reference to that function. Probably it is a rare use-case (for now) to write to the internal flash storage.
This is not really my area of expertise, but I guess, d8cb775 wanted to replace a dirty implementation (which was used in too many places) with a clean implementation. But that is just guessing. I cannot really understand that commit message, but this is probably based on my lack of understanding for NuttX's scheduling infrastructure. |
Previously the function "up_cpu_pause" was used for preventing all other CPUs from executing code from flash. The above function was removed in d8cb775. Now flash operations work on rp2040 in SMP mode by blocking all but the current CPU for the duration of the critical function (write or erase). Closes: apache#16203 Signed-off-by: Lars Kruse <devel@sumpfralle.de>
64e7090 to
256a649
Compare
Yikes, that's worse. CI should have caught it. Might have to add another RP2040 config which includes SmartFS for flash writing so it can be caught.
I think it shouldn't be. My team has done this several times already for rocketry applications and it's a good feature. If it breaks, that's quite bad. Thank you for your fix! |
|
Any comments regarding my proposal for fixing the flash write issue on rp2040? |
acassis
left a comment
There was a problem hiding this comment.
LGTM, please remove Draft and let other to comment
Summary
Previously the function
up_cpu_pausewas used during flash write operations for preventing all other CPUs from executing code from flash.The above function was removed in d8cb775.
Thus, writing to flash on
rp2040was only possible in non-SMP mode.This PR allows write operations to the flash on rp2040 even in SMP mode. It blocks all but the current CPU for the duration of the critical function (write or erase).
The implementation is based on the previous implementation (see d8cb775).
It is slightly enhanced by supporting more than two CPUs and it avoids global variables.
Closes: #16203
BEWARE: this is just a draft. Please take a look at the "discussion" at the end.
Impact
It is possible to write to flash on rp2040 even in SMP mode.
Testing
CONFIG_PIPESandCONFIG_RP2040_FLASH_FILE_SYSTEMrp2040_flash_mtd_initialize();in your startup codenetcat -l 10000 | dd of=/dev/mtd bs=1k seek=512nc -N "$nuttx_host" 10000 <filenameddprocess in the NuttX shell to finish after the connection ofnetcatwas closedWithout the patch, this process would hang (after commenting out the removed
up_cpu_pausecalls).Running the
smpapp (CONFIG_TESTING_SMP) during the above write operation does not cause issues.Details to be discussed?
esp32_spiram.candesp32s3_spiram.cuse a similar implementation for guarding their flash accesses (seeg_cpu_pause).rp2350will surely need this, too, when flash write support is added.*_smp_isolation) somewhere else (e.g. belowsched/sched/)? Which name would be appropriate? (*_smp_isolationis just my silly choice)sched_note_cpu_pause? Currently it is probably unused.boolflags). I picked this for readability. Is this a burden? Should I useboolinstead?enter_critical_sectionwas called beforeup_cpu_pause. Now it is called afterwards.enter_smp_isolationandleave_smp_isolationcallsched_lock/sched_unlock. This may feel a bit excessive, but I think, it is necessary:nxsched_smp_call_asynctries to run the "pause handler" directly on the current CPU, ifthis_cpu()is part of the given cpuset (see source). This would starve our current task and prevent the execution of "leave_smp_isolation". This behavior of "nxsched_smp_call_async" is probably a bug.CONFIG_SMPis used everywhere as the indicator for "multiple processes running in parallel". This is not true during the "smp isolation" context created by these functions.