-
Notifications
You must be signed in to change notification settings - Fork 210
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
Esp wifi/more dynamic allocations #2396
Esp wifi/more dynamic allocations #2396
Conversation
7649f37
to
27741c3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is certainly better than before, but I'm hoping we can get rid of the huge amount of malloc
s eventually.
my thinking was that at least for the things indirectly allocated from the driver via t.b.h. I'm not sure if that would cause problems or not but if it's causing problems those things might be hard to debug For things only allocated by our code I was fine using the global allocator (since I think these shouldn't cause problems) |
This would be a perfect use-case for allocator-api2, that way we could define an InternalAllocator and use that instead of mallocing. |
7bfbea8
to
d62c430
Compare
item_size, | ||
current_read: 0, | ||
current_write: 0, | ||
storage, | ||
} | ||
} | ||
|
||
fn free_storage(&mut self) { | ||
unsafe fn release_storage(&mut self) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I appreciate this function not causing a use-after-free, but I'd appreciate at least a note that this must be called before/during dropping the queue and that the struct should probably not be used after.
Can we move this into a Drop implementation and use ptr::drop_in_place
instead of calling this manually?
I agree, I also saw some (de)allocations happening here within critical-sections, theoretically these should ideally happen through a bounded-time allocator instead of the global allocator (if the global allocator is not bounded time). Have you considered also using a lock-free queue instead? |
I'm not sure if I should change |
Back to draft after observing this: #2274 (comment) |
False alarm caused by unintendedly enabling ps-max-modem |
0bd27f4
to
928b637
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I stopped after about half of the changeset. I have two pain points of different severity:
core::assert
will include more strings than needed- there are a few
addr_of!
uses that look incorrect and I'd like you to double check them. Maybe it's just github reviews being clunky, but I have low confidence in them.
esp-wifi/src/ble/npl.rs
Outdated
if (*callout).dummy == 0 { | ||
panic!("Trying to stop an uninitialzed callout"); | ||
} | ||
core::assert!((*callout).dummy != 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason these aren't the assert from fmt.rs
? I'd prefer using defmt if it's enabled.
|
||
let queue = (*queue).dummy as *mut ConcurrentQueue; | ||
let mut event = event as usize; | ||
(*queue).enqueue(addr_of_mut!(event).cast()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks wrong, this passes the address of the parameter (i.e. points to the stack), not the event pointer itself. Same for remove
, unless I'm missing something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see
enqueue
and remove
take a pointer to some data of length item_size
and copy from that location into the queue.
The NPL stuff however wants us to enqueue and dequeue a pointer
(Hope that explanation makes sense - not sure how to phrase it differently)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ehm okay I don't like this pattern but I guess it's OK because RawQueue copies out of the pointer. I'd prefer if we revisited this later and turned the queue into something typed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes - RawQueue was initially done to satisfy what the WiFi driver expects from a queue - in an upcoming PR we should use something other than RawQueue here for NPL (and looking back I should have split things into separate more granular PRs)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is getting a bit hard to review, so I suggest we don't add more to the PR.
Overall this a nice improvement, and I'm glad we're not storing things like the timer and rng in statics, this will allow me to do some nice things in #2301.
Co-authored-by: Dániel Buga <bugadani@gmail.com>
c9c42e4
to
43c6151
Compare
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 📝
cargo xtask fmt-packages
command to ensure that all changed code is formatted correctly.CHANGELOG.md
in the proper section.Extra:
Pull Request Details 📖
Description
Prefer dynamic allocations over static allocations internally.
Testing
All examples still work