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

implement wifi event handling with data #2453

Merged
merged 14 commits into from
Nov 13, 2024
Merged

Conversation

Easyoakland
Copy link
Contributor

@Easyoakland Easyoakland commented Nov 3, 2024

Thank you for your contribution!

We appreciate the time and effort you've put into this pull request.
To help us review it efficiently, please ensure you've gone through the following checklist:

Submission Checklist 📝

  • I have updated existing examples or added new ones (if applicable).
  • I have used cargo xtask fmt-packages command to ensure that all changed code is formatted correctly.
  • My changes were added to the CHANGELOG.md in the proper section.
  • I have added necessary changes to user code to the Migration Guide.
  • My changes are in accordance to the esp-rs API guidelines

Extra:

Pull Request Details 📖

Description

Fixes: #2412

Implement event handling for apsta{,dis}connect and probe

I kind of guessed which events are associated with which data. Is there a better place for this?

Added to wifi_access_point example, I don't know it would be preferred to copy-paste it as a new example.

Currently requires Boxing and somewhat ugly update function. I'm going to work on this a bit more before undrafting the request, but would like feedback on:

If the approach should be modified completely instead of following the std::panic::hook apis. The implementation here doesn't support removing a single handler, but I'm not sure when that would be preferred over checking a flag in the handler itself.

Testing

Ran the modified example on esp32 and connected to it. Got printlns for the sta connected and disconnected events as expected. Didn't test probe event.

@Easyoakland
Copy link
Contributor Author

By the way, I get a linker error trying to build the example on the latest commit, even before changing anything, and had to fix it with:

- esp-wifi-sys = { version = "0.6.0", git = "https://github.com/esp-rs/esp-wifi-sys.git", rev = "a3e2ed64e9095f120bbcebe6287ddf62760774db"}
+ esp-wifi-sys = { version = "0.6.0" }

Error:

[...]/.cargo/target\xtensa-esp32-none-elf\release\build\esp-wifi-sys-5deb9f734c403436\out\libbtdm_app.a: file not recognized: file format not recognized 
          collect2.exe: error: ld returned 1 exit status

Comment on lines 5 to 7
mod sealed {
pub trait Sealed {}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Please move this to esp_wifi::private::Sealed. We're adding this trait there in a different PR and we don't need two.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was going to move the get_handler method into the Sealed trait so it can't be called by user-code and can be changed later. Should I still move the sealed trait?

esp-wifi/src/wifi/event.rs Outdated Show resolved Hide resolved
pub type Handler<T> = dyn FnMut(&T) + Sync + Send;
// fn default_handler<'a, T>(_: &'a T) {}
/// Data for a wifi event which can be handled by an event handler.
pub trait WifiEventData: sealed::Sealed + Sized + 'static {
Copy link
Contributor

Choose a reason for hiding this comment

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

This trait is completely unnecessary. You can, in your macro, define a newtype around the event types. That way we could avoid the extremely confusing "static method on C type" situation we have here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would still need the trait though? How else do you make a static per type? Are you suggesting making a newtype in rust for each c type and making that the public interface? I must not understand what you mean, could you clarify?

esp-wifi/src/wifi/os_adapter.rs Outdated Show resolved Hide resolved
esp-wifi/src/wifi/os_adapter.rs Outdated Show resolved Hide resolved
esp-wifi/src/wifi/os_adapter.rs Outdated Show resolved Hide resolved
@Easyoakland Easyoakland requested a review from bugadani November 4, 2024 06:04
@bugadani
Copy link
Contributor

bugadani commented Nov 4, 2024

This isn't going in a direction I'm comfortable with, but I'll wait for you to mark this as ready before passing judgement.

- match simpler api from `std::panic::update_hook`

- do not assume size_of in prelude

- make all events handleable

- box static instead of leak
@Easyoakland
Copy link
Contributor Author

  • I forgot that Box<ZST> doesn't allocate, so the whole thing I did was unnecessarily complicated. Changed to Box<dyn ...>
  • Why pass the critical section to the event handler?
  • I don't know how a newtype around event types fixes the need for a trait.

@Easyoakland Easyoakland marked this pull request as ready for review November 5, 2024 05:41
esp-wifi/src/wifi/event.rs Outdated Show resolved Hide resolved
@Easyoakland Easyoakland requested a review from bugadani November 5, 2024 08:47
esp-wifi/src/wifi/event.rs Outdated Show resolved Hide resolved
esp-wifi/src/wifi/event.rs Outdated Show resolved Hide resolved
- pass critical section to event handlers
- comment on perf of Box<ZST>
- don't pass `prev` in `update_handler`, instead call previous handler first unconditionally
@Easyoakland Easyoakland requested a review from bugadani November 5, 2024 19:56
Copy link
Contributor

@bugadani bugadani left a comment

Choose a reason for hiding this comment

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

Thanks for bearing with me on this one.

@bjoernQ
Copy link
Contributor

bjoernQ commented Nov 6, 2024

By the way, I get a linker error trying to build the example on the latest commit, even before changing anything, and had to fix it with:

- esp-wifi-sys = { version = "0.6.0", git = "https://github.com/esp-rs/esp-wifi-sys.git", rev = "a3e2ed64e9095f120bbcebe6287ddf62760774db"}
+ esp-wifi-sys = { version = "0.6.0" }

Error:

[...]/.cargo/target\xtensa-esp32-none-elf\release\build\esp-wifi-sys-5deb9f734c403436\out\libbtdm_app.a: file not recognized: file format not recognized 
          collect2.exe: error: ld returned 1 exit status

Maybe your local Cargo cache is damaged?

@bjoernQ
Copy link
Contributor

bjoernQ commented Nov 6, 2024

One concern I have is that currently we are burning cycles in the (most common) case when no one is interested in the events

INFO - EVENT: HomeChannelChange
INFO - took = 2042 cycles
INFO - EVENT: StaStart
INFO - took = 1393 cycles
INFO - EVENT: ScanDone
INFO - took = 1698 cycles
INFO - EVENT: HomeChannelChange
INFO - took = 2042 cycles
INFO - EVENT: StaConnected
INFO - took = 2042 cycles

(that's on C6 - I guess it's more expensive on multi-core chips)

It's not the end of the world given events are not emitted at a high frequency (not sure about things like FtmReport if enabled).

Probably the best thing to do would be to have a way to mask out events no one is interested in as early as possible (before doing anything with them) ... but that would be out of scope for this PR

@Easyoakland
Copy link
Contributor Author

One concern I have is that currently we are burning cycles in the (most common) case when no one is interested in the events

How did you measure the cycles? I'd be interested in trying this myself.

Is this a comparison of before/after the pr?

It would be strange to me that this be a significant performance drop with no registered handler.
dispatch_handler matches the enum, which should be fast, calls handle_raw which in release does nothing and calls handle, which acquires a critical section, checks the option is none and releases the critical section. The event_post method already acquires a critical section, so I don't know why this would be significantly slower.

@Easyoakland
Copy link
Contributor Author

Easyoakland commented Nov 6, 2024

I've changed the critical section to be passed in to dispatch_event_handler, so now the only new cost should be the match and one new borrow_ref_mut while still holding the critical section.

@bjoernQ
Copy link
Contributor

bjoernQ commented Nov 7, 2024

The numbers were just the measured cycles calling the dispatch function w/o any registered callbacks.

On our RISC-V chips the code to do that is

    unsafe {
        asm!(
            "
                csrrwi x0, 0x7e0, 1 #what to count, for cycles write 1 for instructions write 2
                csrrwi x0, 0x7e1, 0 #disable counter
                csrrwi x0, 0x7e2, 0 #reset counter
                csrrwi x0, 0x7e1, 1 #enable counter
        "
        );
    }

    // WHAT WE WANT TO MEASURE HERE!!!! e.g. calling `dispatch`

    let mut perf_counter: u32 = 0;
    unsafe {
        asm!(
            "
            csrr {x}, 0x7e2
            ",
            options(nostack),
            x = inout(reg) perf_counter,
        )
    };
    info!("took = {} cycles", perf_counter);

@Easyoakland
Copy link
Contributor Author

Numbers I got from testing on esp32:

  1. critical section
    let start = xtensa_lx_rt::xtensa_lx::timer::get_cycle_count();
    critical_section::with(|cs| {
        core::hint::black_box(cs);
    });
    let end = xtensa_lx_rt::xtensa_lx::timer::get_cycle_count();
    • 2902
    • 1946
    • 2902
    • 1945
    • 35
    • 1945
    • 35
    • 1945
    • 35
    • 1945
    • 35
  2. borrow_ref_mut
    let start = xtensa_lx_rt::xtensa_lx::timer::get_cycle_count();
    WIFI_EVENTS.borrow_ref_mut(cs).insert(event);
    let end = xtensa_lx_rt::xtensa_lx::timer::get_cycle_count();
    • 965
    • 964
    • 18
    • 964
    • 20
    • 965
    • 964
    • 20
  3. match statement itself
    let start = xtensa_lx_rt::xtensa_lx::timer::get_cycle_count();
    match event {
        ...
        WifiEvent::ApStadisconnected => {
            let end = xtensa_lx_rt::xtensa_lx::timer::get_cycle_count();
        }
    }
    • 1923
    • 1923
    • 1923
  4. handle_raw with nothing registered
    let start = xtensa_lx_rt::xtensa_lx::timer::get_cycle_count();
    handle_raw::<ApStadisconnected>(cs, event_data, event_data_size);
    let end = xtensa_lx_rt::xtensa_lx::timer::get_cycle_count();
    • 9
    • 9
    • 9
  5. It looks like the match statement might be slow? Checking the assembly, it looks like a jump-table and I'm not sure why it takes so long. I'm not sure how to check this.
no registered event handler dispatch asm
.section .text.dispatch_event_handler,"ax",@progbits
    .literal_position
    .literal .LCPI210_0, .LJTI210_0
    .literal .LCPI210_1, <esp_wifi::wifi::event::StaNeighborRep as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_2, .Lanon.6f9af055088f29a420e67a46e94ad374.129
    .literal .LCPI210_3, core::cell::panic_already_borrowed
    .literal .LCPI210_4, <esp_wifi::wifi::event::HomeChannelChange as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_5, <esp_wifi::wifi::event::NdpTerminated as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_6, <esp_wifi::wifi::event::NdpConfirm as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_7, <esp_wifi::wifi::event::NdpIndication as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_8, <esp_wifi::wifi::event::NanReceive as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_9, <esp_wifi::wifi::event::NanReplied as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_10, <esp_wifi::wifi::event::NanSvcMatch as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_11, <esp_wifi::wifi::event::NanStopped as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_12, <esp_wifi::wifi::event::NanStarted as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_13, <esp_wifi::wifi::event::BtwtTeardown as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_14, <esp_wifi::wifi::event::BtwtSetup as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_15, <esp_wifi::wifi::event::TwtWakeup as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_16, <esp_wifi::wifi::event::ItwtSuspend as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_17, <esp_wifi::wifi::event::ItwtProbe as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_18, <esp_wifi::wifi::event::ItwtTeardown as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_19, <esp_wifi::wifi::event::ItwtSetup as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_20, <esp_wifi::wifi::event::ApWpsRgPbcOverlap as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_21, <esp_wifi::wifi::event::ApWpsRgPin as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_22, <esp_wifi::wifi::event::ApWpsRgTimeout as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_23, <esp_wifi::wifi::event::ApWpsRgFailed as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_24, <esp_wifi::wifi::event::ApWpsRgSuccess as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_25, <esp_wifi::wifi::event::ConnectionlessModuleWakeIntervalStart as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_26, <esp_wifi::wifi::event::StaBeaconTimeout as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_27, <esp_wifi::wifi::event::RocDone as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_28, <esp_wifi::wifi::event::ActionTxStatus as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_29, <esp_wifi::wifi::event::StaBssRssiLow as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_30, <esp_wifi::wifi::event::FtmReport as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_31, <esp_wifi::wifi::event::ApProbereqrecved as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_32, <esp_wifi::wifi::event::ApStadisconnected as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_33, <esp_wifi::wifi::event::ApStaconnected as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_34, <esp_wifi::wifi::event::ApStop as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_35, <esp_wifi::wifi::event::ApStart as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_36, <esp_wifi::wifi::event::StaWpsErPbcOverlap as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_37, <esp_wifi::wifi::event::StaWpsErPin as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_38, <esp_wifi::wifi::event::StaWpsErTimeout as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_39, <esp_wifi::wifi::event::StaWpsErFailed as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_40, <esp_wifi::wifi::event::StaWpsErSuccess as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_41, <esp_wifi::wifi::event::StaAuthmodeChange as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_42, <esp_wifi::wifi::event::StaDisconnected as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_43, <esp_wifi::wifi::event::StaConnected as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_44, <esp_wifi::wifi::event::StaStop as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_45, <esp_wifi::wifi::event::StaStart as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_46, <esp_wifi::wifi::event::ScanDone as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .literal .LCPI210_47, <esp_wifi::wifi::event::WifiReady as esp_wifi::wifi::event::sealed::Event>::handler::HANDLE.0
    .global dispatch_event_handler
    .p2align        2
    .type   dispatch_event_handler,@function
dispatch_event_handler:

    entry a1, 32
    l32r a8, .LCPI210_0
    addx4 a8, a2, a8
    l32i.n a8, a8, 0
    jx a8

    l32r a8, .LCPI210_47
    j .LBB210_46

    l32r a8, .LCPI210_46
    j .LBB210_46

    l32r a8, .LCPI210_45
    j .LBB210_46

    l32r a8, .LCPI210_44
    j .LBB210_46

    l32r a8, .LCPI210_43
    j .LBB210_46

    l32r a8, .LCPI210_42
    j .LBB210_46

    l32r a8, .LCPI210_41
    j .LBB210_46

    l32r a8, .LCPI210_40
    j .LBB210_46

    l32r a8, .LCPI210_39
    j .LBB210_46

    l32r a8, .LCPI210_38
    j .LBB210_46

    l32r a8, .LCPI210_37
    j .LBB210_46

    l32r a8, .LCPI210_36
    j .LBB210_46

    l32r a8, .LCPI210_35
    j .LBB210_46

    l32r a8, .LCPI210_34
    j .LBB210_46

    l32r a8, .LCPI210_33
    j .LBB210_46

    l32r a8, .LCPI210_32
    j .LBB210_46

    l32r a8, .LCPI210_31
    j .LBB210_46

    l32r a8, .LCPI210_30
    j .LBB210_46

    l32r a8, .LCPI210_29
    j .LBB210_46

    l32r a8, .LCPI210_28
    j .LBB210_46

    l32r a8, .LCPI210_27
    j .LBB210_46

    l32r a8, .LCPI210_26
    j .LBB210_46

    l32r a8, .LCPI210_25
    j .LBB210_46

    l32r a8, .LCPI210_24
    j .LBB210_46

    l32r a8, .LCPI210_23
    j .LBB210_46

    l32r a8, .LCPI210_22
    j .LBB210_46

    l32r a8, .LCPI210_21
    j .LBB210_46

    l32r a8, .LCPI210_20
    j .LBB210_46

    l32r a8, .LCPI210_19
    j .LBB210_46

    l32r a8, .LCPI210_18
    j .LBB210_46

    l32r a8, .LCPI210_17
    j .LBB210_46

    l32r a8, .LCPI210_16
    j .LBB210_46

    l32r a8, .LCPI210_15
    j .LBB210_46

    l32r a8, .LCPI210_14
    j .LBB210_46

    l32r a8, .LCPI210_13
    j .LBB210_46

    l32r a8, .LCPI210_12
    j .LBB210_46

    l32r a8, .LCPI210_11
    j .LBB210_46

    l32r a8, .LCPI210_10
    j .LBB210_46

    l32r a8, .LCPI210_9
    j .LBB210_46

    l32r a8, .LCPI210_8
    j .LBB210_46

    l32r a8, .LCPI210_7
    j .LBB210_46

    l32r a8, .LCPI210_6
    j .LBB210_46

    l32r a8, .LCPI210_5
    j .LBB210_46

    l32r a8, .LCPI210_4
    j .LBB210_46

    l32r a8, .LCPI210_1

.LBB210_46:
    l8ui a9, a8, 0
    bnez a9, .LBB210_48

    movi.n a9, 0
    s8i a9, a8, 0
    retw.n

    l32r a10, .LCPI210_2
    l32r a8, .LCPI210_3
    callx8 a8
6. I tried dispatching multiple times per event and got strange results. Seems like the issue is something isn't cached and takes a bunch of cycles to load the first time? Is it possible the instructions for the match itself is what's taking a while to load?
dispatch same handler log
0: ApStaconnected - Dispatch took: 3870 cycles
1: ApStaconnected - Dispatch took: 26 cycles
2: ApStaconnected - Dispatch took: 26 cycles
3: ApStaconnected - Dispatch took: 26 cycles
4: ApStaconnected - Dispatch took: 26 cycles
5: ApStaconnected - Dispatch took: 26 cycles
6: ApStaconnected - Dispatch took: 26 cycles
7: ApStaconnected - Dispatch took: 26 cycles
8: ApStaconnected - Dispatch took: 26 cycles
9: ApStaconnected - Dispatch took: 26 cycles
critical-section-with took: 2906
ApStadisconnected - WIFI_EVENTS.borrow_ref_mut took: 967
0: ApStadisconnected - Dispatch took: 4836 cycles
1: ApStadisconnected - Dispatch took: 26 cycles
2: ApStadisconnected - Dispatch took: 26 cycles
3: ApStadisconnected - Dispatch took: 26 cycles
4: ApStadisconnected - Dispatch took: 26 cycles
5: ApStadisconnected - Dispatch took: 26 cycles
6: ApStadisconnected - Dispatch took: 26 cycles
7: ApStadisconnected - Dispatch took: 26 cycles
8: ApStadisconnected - Dispatch took: 26 cycles
9: ApStadisconnected - Dispatch took: 26 cycles
critical-section-with took: 2905
HomeChannelChange - WIFI_EVENTS.borrow_ref_mut took: 22
0: HomeChannelChange - Dispatch took: 972 cycles
1: HomeChannelChange - Dispatch took: 26 cycles
2: HomeChannelChange - Dispatch took: 26 cycles
3: HomeChannelChange - Dispatch took: 26 cycles
4: HomeChannelChange - Dispatch took: 26 cycles
5: HomeChannelChange - Dispatch took: 26 cycles
6: HomeChannelChange - Dispatch took: 26 cycles
7: HomeChannelChange - Dispatch took: 26 cycles
8: HomeChannelChange - Dispatch took: 26 cycles
9: HomeChannelChange - Dispatch took: 26 cycles
critical-section-with took: 40
HomeChannelChange - WIFI_EVENTS.borrow_ref_mut took: 22
0: HomeChannelChange - Dispatch took: 26 cycles
1: HomeChannelChange - Dispatch took: 26 cycles
2: HomeChannelChange - Dispatch took: 26 cycles
3: HomeChannelChange - Dispatch took: 26 cycles
4: HomeChannelChange - Dispatch took: 26 cycles
5: HomeChannelChange - Dispatch took: 26 cycles
6: HomeChannelChange - Dispatch took: 26 cycles
7: HomeChannelChange - Dispatch took: 26 cycles
8: HomeChannelChange - Dispatch took: 26 cycles
9: HomeChannelChange - Dispatch took: 26 cycles
critical-section-with took: 40
ApStaconnected - WIFI_EVENTS.borrow_ref_mut took: 967
0: ApStaconnected - Dispatch took: 1940 cycles
1: ApStaconnected - Dispatch took: 26 cycles
2: ApStaconnected - Dispatch took: 26 cycles
3: ApStaconnected - Dispatch took: 26 cycles
4: ApStaconnected - Dispatch took: 26 cycles
5: ApStaconnected - Dispatch took: 26 cycles
6: ApStaconnected - Dispatch took: 26 cycles
7: ApStaconnected - Dispatch took: 26 cycles
8: ApStaconnected - Dispatch took: 26 cycles
9: ApStaconnected - Dispatch took: 26 cycles
critical-section-with took: 40
ApStadisconnected - WIFI_EVENTS.borrow_ref_mut took: 967
0: ApStadisconnected - Dispatch took: 4836 cycles
1: ApStadisconnected - Dispatch took: 26 cycles
2: ApStadisconnected - Dispatch took: 26 cycles
3: ApStadisconnected - Dispatch took: 26 cycles
4: ApStadisconnected - Dispatch took: 26 cycles
5: ApStadisconnected - Dispatch took: 26 cycles
6: ApStadisconnected - Dispatch took: 26 cycles
7: ApStadisconnected - Dispatch took: 26 cycles
8: ApStadisconnected - Dispatch took: 26 cycles
9: ApStadisconnected - Dispatch took: 26 cycles
critical-section-with took: 2905
HomeChannelChange - WIFI_EVENTS.borrow_ref_mut took: 22
0: HomeChannelChange - Dispatch took: 972 cycles
1: HomeChannelChange - Dispatch took: 26 cycles
2: HomeChannelChange - Dispatch took: 26 cycles
3: HomeChannelChange - Dispatch took: 26 cycles
4: HomeChannelChange - Dispatch took: 26 cycles
5: HomeChannelChange - Dispatch took: 26 cycles
6: HomeChannelChange - Dispatch took: 26 cycles
7: HomeChannelChange - Dispatch took: 26 cycles
8: HomeChannelChange - Dispatch took: 26 cycles
9: HomeChannelChange - Dispatch took: 26 cycles
dispatch different handler log
HomeChannelChange - WIFI_EVENTS.borrow_ref_mut took: 967
0: HomeChannelChange - Dispatch took: 2898 cycles
1: NdpTerminated - Dispatch took: 28 cycles
2: NdpConfirm - Dispatch took: 973 cycles
3: NdpIndication - Dispatch took: 28 cycles
4: NanReceive - Dispatch took: 972 cycles
5: NanReplied - Dispatch took: 975 cycles
6: NanSvcMatch - Dispatch took: 27 cycles
7: NanStopped - Dispatch took: 974 cycles
8: NanStarted - Dispatch took: 27 cycles
9: BtwtTeardown - Dispatch took: 28 cycles
critical-section-with took: 3853
ApStart - WIFI_EVENTS.borrow_ref_mut took: 19
0: ApStart - Dispatch took: 3863 cycles
1: StaWpsErPbcOverlap - Dispatch took: 27 cycles
2: StaWpsErPin - Dispatch took: 28 cycles
3: StaWpsErTimeout - Dispatch took: 973 cycles
4: StaWpsErFailed - Dispatch took: 28 cycles
5: StaWpsErSuccess - Dispatch took: 972 cycles
6: StaAuthmodeChange - Dispatch took: 975 cycles
7: StaDisconnected - Dispatch took: 27 cycles
8: StaConnected - Dispatch took: 28 cycles
9: StaStop - Dispatch took: 27 cycles
critical-section-with took: 42
is wifi started: Ok(true)
Ok(EnumSet(AccessPoint))
Start busy loop on main. Connect to the AP `esp-wifi` and point your browser to http://192.168.2.1:8080/
Use a static IP in the range 192.168.2.2 .. 192.168.2.255, use gateway 192.168.2.1
ApStaconnected - WIFI_EVENTS.borrow_ref_mut took: 965
0: ApStaconnected - Dispatch took: 2898 cycles
1: ApStop - Dispatch took: 27 cycles
2: ApStart - Dispatch took: 28 cycles
3: StaWpsErPbcOverlap - Dispatch took: 27 cycles
4: StaWpsErPin - Dispatch took: 28 cycles
5: StaWpsErTimeout - Dispatch took: 27 cycles
6: StaWpsErFailed - Dispatch took: 28 cycles
7: StaWpsErSuccess - Dispatch took: 27 cycles
8: StaAuthmodeChange - Dispatch took: 28 cycles
9: StaDisconnected - Dispatch took: 27 cycles
critical-section-with took: 2908
ApStadisconnected - WIFI_EVENTS.borrow_ref_mut took: 965
0: ApStadisconnected - Dispatch took: 4830 cycles
1: ApStaconnected - Dispatch took: 1937 cycles
2: ApStop - Dispatch took: 27 cycles
3: ApStart - Dispatch took: 28 cycles
4: StaWpsErPbcOverlap - Dispatch took: 27 cycles
5: StaWpsErPin - Dispatch took: 28 cycles
6: StaWpsErTimeout - Dispatch took: 973 cycles
7: StaWpsErFailed - Dispatch took: 28 cycles
8: StaWpsErSuccess - Dispatch took: 972 cycles
9: StaAuthmodeChange - Dispatch took: 28 cycles
critical-section-with took: 3853
HomeChannelChange - WIFI_EVENTS.borrow_ref_mut took: 21
0: HomeChannelChange - Dispatch took: 974 cycles
1: NdpTerminated - Dispatch took: 28 cycles
2: NdpConfirm - Dispatch took: 973 cycles
3: NdpIndication - Dispatch took: 28 cycles
4: NanReceive - Dispatch took: 972 cycles
5: NanReplied - Dispatch took: 975 cycles
6: NanSvcMatch - Dispatch took: 27 cycles
7: NanStopped - Dispatch took: 974 cycles
8: NanStarted - Dispatch took: 27 cycles
9: BtwtTeardown - Dispatch took: 28 cycles
critical-section-with took: 42
7. Does this need to be resolved for the pr to be accepted?

@bjoernQ
Copy link
Contributor

bjoernQ commented Nov 8, 2024

Ok this definitely looks like cache misses - not really something that should be touched in this PR.

I'm personally not very convinced by the chained callbacks but I'm fine with it - will leave the last word to someone else in the team to decide (i.e. approve)

@Easyoakland
Copy link
Contributor Author

Easyoakland commented Nov 10, 2024

I'm personally not very convinced by the chained callbacks but I'm fine with it - will leave the last word to someone else in the team to decide (i.e. approve)

If it helps, using replace_handler with function items should be as efficient as only supporting a single fn callback, so there shouldn't be a runtime cost to doing it this way.

@Easyoakland
Copy link
Contributor Author

@bjoernQ Is there something I can do to move this along at this point? I'd like to avoid having to merge main to keep the branch up-to-date.

Copy link
Member

@jessebraham jessebraham left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM

@jessebraham jessebraham added this pull request to the merge queue Nov 13, 2024
Merged via the queue into esp-rs:main with commit 30276e1 Nov 13, 2024
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Accessing WifiEvent data
4 participants