Skip to content
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

Add priority-limited locks #2684

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Add priority-limited locks #2684

wants to merge 3 commits into from

Conversation

bugadani
Copy link
Contributor

@bugadani bugadani commented Dec 4, 2024

However, when it does, we can use it in embassy-executor to lock certain resources without affecting higher priority levels. This will come in handy once we manage our own timer queue, which is only ever accessed from the executor's priority level, and the alarm's level (which we'll be able to reduce to executor+1). Priority-limiting access to the queue will result in less jitter in higher priority executors. Hopefully :)

skip-changelog is purposeful. sync is a hidden module, which needs to be public because embassy/wifi build on it, but this new addition is pretty experimental - API, documentation or functionality may still change I think.

@bugadani bugadani added the skip-changelog No changelog modification needed label Dec 4, 2024
@bugadani bugadani force-pushed the prio branch 2 times, most recently from 4989831 to 8f2075a Compare December 4, 2024 22:42
@Dominaezzz
Copy link
Collaborator

I haven't taken the time to see if it matters for this yet but just in case you figure it out before I do:

Given priorities are being treated more granular-ly than just a binary on/off thing now, it might a good time to improve the priority restoration instruction here.

unsafe { core::arch::asm!("waiti 0") };

That should be restoring back to the original level rather than just zero.

@bugadani
Copy link
Contributor Author

bugadani commented Dec 4, 2024

Oops I accidentally reverted that change... It's actually needed otherwise that restoration can release a lock by accident.

@bugadani bugadani force-pushed the prio branch 6 times, most recently from 9a373b5 to ed34f6c Compare December 5, 2024 09:11
@bugadani bugadani marked this pull request as ready for review December 5, 2024 09:40
@bugadani bugadani marked this pull request as draft December 6, 2024 16:30
@bugadani

This comment was marked as resolved.

@bugadani bugadani force-pushed the prio branch 5 times, most recently from 269d71a to bae305e Compare December 6, 2024 17:38
@bugadani bugadani marked this pull request as ready for review December 6, 2024 19:02
esp-hal/src/sync.rs Outdated Show resolved Hide resolved
@bjoernQ
Copy link
Contributor

bjoernQ commented Dec 10, 2024

Running cargo xtask run-example examples esp32s3 wifi_embassy_dhcp on this branch gets me

I (296) boot: Disabling RNG early entropy source...
INFO - esp-wifi configuration EspWifiConfig { rx_queue_size: 5, tx_queue_size: 3, static_rx_buf_num: 10, dynamic_rx_buf_num: 32, static_tx_buf_num: 0, dynamic_tx_buf_num: 32, csi_enable: true, ampdu_rx_enable: true, ampdu_tx_enable: true, amsdu_tx_enable: false, rx_ba_win: 6, max_burst_size: 1, country_code: "CN", country_code_operating_class: 0, mtu: 1492, tick_rate_hz: 100, listen_interval: 3, beacon_timeout: 6, ap_beacon_timeout: 300, failure_retry_cnt: 1, scan_method: 0 }
WARN - esp_wifi_internal_tx 12290
start connection task
Device capabilities: Ok(EnumSet(Client))
Starting wifi
Wifi started!
About to connect...
Wifi connected!
Waiting to get IP address...
Got IP: 192.168.178.65/24


====================== PANIC ======================
panicked at C:\Users\bq\.cargo\registry\src\index.crates.io-6f17d22bba15001f\smoltcp-0.11.0\src\iface\interface\mod.rs:882:14:
called `Option::unwrap()` on a `None` value

Backtrace:

0x420184c5
0x420184c5 - core::option::unwrap_failed
    at C:\Users\bq\.rustup\toolchains\esp\lib\rustlib\src\rust\library\core\src\option.rs:2015
0x4203630d
0x4203630d - core::option::Option<T>::unwrap
    at C:\Users\bq\.rustup\toolchains\esp\lib\rustlib\src\rust\library\core\src\option.rs:965
0x42034d7e
0x42034d7e - smoltcp::iface::interface::ipv6::<impl smoltcp::iface::interface::InterfaceInner>::icmpv6_reply
    at C:\Users\bq\.cargo\registry\src\index.crates.io-6f17d22bba15001f\smoltcp-0.11.0\src\iface\interface\ipv6.rs:336
0x42032e15
0x42032e15 - smoltcp::iface::interface::InterfaceInner::process_udp
    at C:\Users\bq\.cargo\registry\src\index.crates.io-6f17d22bba15001f\smoltcp-0.11.0\src\iface\interface\mod.rs:1174
0x4202ac49
0x4202ac49 - smoltcp::iface::interface::ipv6::<impl smoltcp::iface::interface::InterfaceInner>::process_nxt_hdr
    at C:\Users\bq\.cargo\registry\src\index.crates.io-6f17d22bba15001f\smoltcp-0.11.0\src\iface\interface\ipv6.rs:155
0x4200978e
0x4200978e - smoltcp::iface::interface::Interface::socket_ingress::{{closure}}
    at C:\Users\bq\.cargo\registry\src\index.crates.io-6f17d22bba15001f\smoltcp-0.11.0\src\iface\interface\mod.rs:539
0x4200327c
0x4200327c - embassy_executor::raw::SyncExecutor::poll::{{closure}}
    at C:\Users\bq\.cargo\registry\src\index.crates.io-6f17d22bba15001f\embassy-executor-0.6.3\src\raw\mod.rs:405
0x420172f7
0x420172f7 - wifi_embassy_dhcp::__xtensa_lx_rt_main
    at d:\projects\review\bugadani\esp-hal\examples\src\bin\wifi_embassy_dhcp.rs:50
0x4203e2e2
0x4203e2e2 - Reset
    at D:\projects\review\bugadani\esp-hal\xtensa-lx-rt\src\lib.rs:82
0x40378dde
0x40378dde - ESP32Reset
    at D:\projects\review\bugadani\esp-hal\esp-hal\src\soc\esp32s3\mod.rs:164

@bugadani
Copy link
Contributor Author

I see a similar enough crash on main, I don't think this is the PR's fault:

Failed to connect to wifi: Disconnected
About to connect...
Wifi connected!


====================== PANIC ======================
panicked at C:\Users\bugad\.cargo\registry\src\index.crates.io-6f17d22bba15001f\smoltcp-0.11.0\src\socket\dns.rs:170:49:
called `Result::unwrap()` on an `Err` value: ()

@bjoernQ
Copy link
Contributor

bjoernQ commented Dec 10, 2024

I see a similar enough crash on main, I don't think this is the PR's fault:

interesting - I haven't seen crashes on main but after a clean build it seems it's fine on this branch - so might be a red herring

Copy link
Contributor

@bjoernQ bjoernQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Collaborator

@Dominaezzz Dominaezzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Xtensa side LGTM. (I don't really know the RISCV aspects of this)

Comment on lines +17 to +18
unsafe fn enter(&self) -> critical_section::RawRestoreState;
unsafe fn exit(&self, token: critical_section::RawRestoreState);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At some point critical_section should be treated like embedded_hal, where it's a convenient add-on, rather that part of the inherent APIs of the hal.

Copy link
Contributor Author

@bugadani bugadani Dec 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment about the use of critical_section::RawRestoreState as a return value?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip-changelog No changelog modification needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants