More sleep fixes #3079
No reviewers
Labels
No labels
bazel
bluetooth
board settings
boot_stage2
bug
build
c++
can't reproduce
clang
clib-interface
cmsis
code cleanliness
code size
compiler version issues
cyw43_driver
debug
discussion
documentation
duplicate
dynamic_clock
elf2uf2
enhancement
errata
filesystem
flash layout
floating point
FreeRTOS
hardware_adc
hardware_claim
hardware_clocks
hardware_dma
hardware_exception
hardware_flash
hardware_gpio
hardware_i2c
hardware_irq
hardware_pio
hardware_pwm
hardware_rcp
hardware_rtc
hardware_spi
hardware_sync
hardware_uart
hardware_vreg
hardware_watchdog
hardware_xosc
help wanted
host
IAR
installation
invalid
linker scripts
lto
lwip
mbedtls
missing API
needs reporter detail
networking
newlib
newlib-multicore
non-c
non-cmake
non-gcc
openocd
orphan PR
OS integration
pico_async_context
pico_base
pico_binary_info
pico_flash
picolibc
pico_lwip
pico_malloc
pico_multicore
pico_printf
pico_runtime
pico_stdio
pico_stdio_usb
pico_sync
pico_time
pico_util
pioasm
port
question
review
review2
rtos interop
runtime init
static library
svd
test
tinyusb
vscode
wifi integration
wontfix
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-raspberrypi/pico-sdk!3079
Loading…
Reference in a new issue
No description provided.
Delete branch "another-sleep-fix"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
fixes #3078
@ -28,42 +33,45 @@ int64_t notify_lock_with_flag(__unused alarm_id_t id, void *user_data) {return 0;}I don't claim to understand what this code is doing, but does the callback function now always need to do a
__sev(), or is that just an "implementation detail" of this particular test?If the
__sev()isn't required, maybe it's worth adding a separate test that uses a different callback function (which doesn't use__sev()), just to rule out any "side effect" behaviour? 🤷@ -3,10 +3,22 @@ if (NOT PICO_TIME_NO_ALARM_SUPPORT)set_target_properties(pico_time_test PROPERTIES PICO_TEST_TIMEOUT "20")It looks like you've got a
if (PICO_RP2040)inside aif (NOT PICO_RP2040), so presumably this code will never be reached?@ -0,0 +2,4 @@add_executable(short_sleep_test short_sleep_test.c)set_target_properties(short_sleep_test PROPERTIES PICO_TEST_TIMEOUT "20")target_compile_definitions(short_sleep_test PRIVATEPICO_TIME_SLEEP_OVERHEAD_ADJUST_US=0It looks like you need to add this define to
test/short_sleep_test/BUILD.bazeltoo? (Because the Bazel builds are currently failing CI)@ -28,42 +33,45 @@ int64_t notify_lock_with_flag(__unused alarm_id_t id, void *user_data) {return 0;}Thanks Graham 😃
@ -3,10 +3,22 @@ if (NOT PICO_TIME_NO_ALARM_SUPPORT)set_target_properties(pico_time_test PROPERTIES PICO_TEST_TIMEOUT "20")ahha
Summary of changes:
sleep_until()adds a timer callback, to notify itself to wake up. This was using aspin_lock/spin_unlock_with_wait, with the callback doing aspin_lock/spin_unlock_with_notify. This was, if I recall, done (vs just WFE and SEV) because these primitives are what are overridden by FreeRTOS, and the additional overhead of the spinlock is minimal. The problem on RP2350 with software spinlocks, is that the spin_lock/spin_unlock_with_wait wakes up immediately. The fix here is to use WFE/SEV unless the macros are overriddenalarm_pool_irq_handlerand using a function callback marker constant instead of changing the timeout, so that the timeout value was not lostrepeating_timer_markeranddeleted_timer_markerwere changed to be small immediate even values, to reduce code size, and so attempting to call them will trap)best_effort_wfe_or_timeoutfor last_added == timeout_timestamp meant we always did a WFE in that case, which is wrong if best_effotrt_wfe_or_timeout is called repeatedly for the same timestamp that has now passed. A check is added for the WFE for this case@ -13,6 +13,27 @@const absolute_time_t ABSOLUTE_TIME_INITIALIZED_VAR(nil_time, 0);I'm, guessing that this was supposed to be
?
Additional changes:
5. Fixed a claude detected race conditoin
6. Added PICO_PLATFORM_NAME so tests that want to print something meaningful don't have to #Ifdef
7. Added newer even more improved claude co-written test which is also designed to test (the almost certainly broken) FreeRTOS - interop.. tests currently pass on
rp2040,rp2350-arm-s,rrp2350-riscvwith hardware/software spinlocks on RP2350Reviewed the deletion race fixes -- look correct to me. Not digested the other changes.
@ -13,6 +13,27 @@const absolute_time_t ABSOLUTE_TIME_INITIALIZED_VAR(nil_time, 0);const absolute_time_t ABSOLUTE_TIME_INITIALIZED_VAR(at_the_end_of_time, INT64_MAX);// Whether sleep_until() waits on a lock_core rather than on a bare __wfe().If you're going to generate code, please at least write the comments yourself. This is obvious slop and I'd rather not read it every time I look in this file.
Single-copy atomicity of aligned loads and stores is a RISC-V guarantee, not a Hazard3 one.
I don't think the use of LLMs here is a good direction. This code is already incredibly demanding to understand, which is why I left it unreviewed for so long. I think it's made worse by these changes.
yeah i plan to redact a lot of the comments which is why i haven't merged this yet
i disagree on whether LLM is helpful here - it has been; the upshot though is actually that a fix I'd made in June fixed A and introduced B. A separate fix i myself made as part of this PR fixed C (and unknown to me was actually a fix for A). Fixing B in this PR actually broke D. so the actual correct fix was just my change that fixed C. The tests added by this PR have been invaluable. The net code changes themselves are small, but I will actually split them out into separate commits because half of them are not even related to fixing the particular known bugs and can be applied individually to fix E & F etc
closed in favor of tidied up version #3127
Pull request closed