-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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
[Console] fix: console deinit always deadlocks - adds ability to unblock linenoise (try 2) (IDFGH-9188) #10580
base: master
Are you sure you want to change the base?
Conversation
* | ||
* @param[in] xRingbuffer The ring buffer who's rx will be unblocked. | ||
*/ | ||
void vRingbufferUnblockRx(RingbufHandle_t xRingbuffer); |
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.
If usb_serial_jtag.c starts using something other than a ringbuffer internally (e.g. a StreamBuffer), we would have to add similar API for unblocking there; and given that StreamBuffer is upstream FreeRTOS code we would most likely want to avoid that.
^ From Ivan.
Can you re-evaluate your position on this? vRingbufferUnblockRx
seems like the ideal solution.
If we ever switched to StreamBuffer
we could come up with alternative solutions. For example:
- A) a counting semaphore + StreamBuffer. 'give' the semaphore on new data + then call StreamBuffer with a 0 timeout. We'll then check if there enough data. During deinit, we'd "give" the semaphore another time in order to unblock the read, then return
read()
with error. - B) Use a long timeout with StreamBuffer, perhaps 10 seconds, and poll an exit condition
- C) Make a Pull Request on FreeRTOS to add the necessary unblock feature to StreamBuffer
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.
Alternatively, ^^ solution (A), could be used to mitigate the need for vRingbufferUnblockRx
in this PR as well.
I think the solution would look like this:
- normal exclusive mutex. Not entirely necessary.
usb_serial_jtag_read_bytes
will grab this mutex first. This makes sure the counting semaphore only has a single thread using it at a time. i.e. so the first thread to callread()
will always be satisfied first. - counting semaphore.
usb_serial_jtag_isr_handler_default
increments this counting semaphore once each time it appends to the ringbuffer,usb_serial_jtag_read_bytes
will 'take' from the semaphore waiting until new bytes are ready (We could also useevent_groups
instead). - ring buffer,
usb_serial_jtag_read_bytes
calls the ringbuffer with a zero timeout, and will wait on the counting semaphore again until there is enough data.
Of course, I would consider the vRingbufferUnblockRx
solution already used in this PR better.
bc01e0c
to
29fd993
Compare
29fd993
to
419b136
Compare
419b136
to
02eb8d6
Compare
Hi @chipweinberger, I started looking into your PR. Can I ask you to rebase and fix the build issues and conflict with upstream? |
sure, one moment. |
0523e98
to
4a8c859
Compare
@SoucheSouche updated. |
55e025a
to
10bfe50
Compare
10bfe50
to
097d22a
Compare
components/esp_ringbuf/ringbuf.c
Outdated
configASSERT(pxRingbuffer); | ||
|
||
// is the semaphore taken? | ||
if (uxSemaphoreGetCount(rbGET_RX_SEM_HANDLE(pxRingbuffer)) == 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.
rbGET_RX_SEM_HANDLE
doesn't seem to be declared anywhere.
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 code must have changed. @SoucheSouche, I'm pretty behind and stressed about my own work at the moment. If you are able to update it that would be a great help.
edit: I updated the code to remove the semaphore. Threading needs more thought.
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.
sure no problem!
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 wonder if we should move this from the flags, and into its own variable. That way we are less likely to hit threading problems from multiple flags sharing the same memory location.
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'm not familiar enough with ringbuf to make this judgement call.
097d22a
to
f85938e
Compare
@SoucheSouche how are things going? |
@chipweinberger, there has been some changes in the ring buffer so I am now looking at your PR again since the semaphores for rx and tx were removed. But tomorrow is my last working day before my extended leaves so I will most likely not finish up before. Someone from my team will take over the console related PRs. |
I updated the PR and removed the semaphores. But as I was saying before I think we should move this bit: |
The other issue is that this comment is still valid and your current solution won't be accepted. I am implementing an alternative to your changes using |
@SoucheSouche , did you understand Ivans comment? "Thinking about this again, select on a pair of file descriptors (stdin and eventfd) is probably the cleanest solution." I'm not sure what that solution would look like. If you use |
@SoucheSouche another idea - we could send a "enter" key event to vfs buffers to force the thread to exit line noise. something like:
|
👋 Hello chipweinberger, we appreciate your contribution to this project! 📘 Please review the project's Contributions Guide for key guidelines on code, documentation, testing, and more. 🖊️ Please also make sure you have read and signed the Contributor License Agreement for this project. Click to see more instructions ...
Review and merge process you can expect ...
|
Hi @chipweinberger, |
Hi @chipweinberger, a little update on the PR. I experimented with
I kept |
seems like a reasonable solution! impressive :) fun :) |
I had to implement the select for the usb serial jtag driver so I will have to first merge this added feature before proceeding with the actual deadlock fix. |
related: #9964 ([USB Serial JTAG] calling select() & poll() crashes) |
Hi @chipweinberger, |
hi @chipweinberger, I will try to submit it before the end of the week, so I hope it will be merged before Christmas. |
Yes I can imagine it was a difficult fix. Congrats! My product is now shipping: jamcorder.com :) |
Congratulation to you! And I couldn't help but notice that you are missing the mouse hover on the FAQ section for the desktop version of the website. |
Previous PR: #9983
I am re-opening this PR to get more traction on it.
This solves: #9974
Motivation: