-
Notifications
You must be signed in to change notification settings - Fork 199
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
Pin Monitor 100% CPU #22
Comments
Thanks for the bug report! I'd also like to document this in the wiki. What hardware specifically do you have that shows this behaviour? |
It's the g_serial driver for a USB virtual serialport (/dev/ttyACM0) interfacing with a TI CC2531. |
Investigated the issue. The proper solution is to propogate the error to |
I think that it's a fair bet for EINVAL, perhaps restrict it to just that error code for now (unless a case of a different code comes up). For our information if this functionality is (Pin Monitoring) is disabled, what effect does it have on functionality? Might be good to document too. |
I'll continue the loop for only EAGAIN or EWOULDBLOCK as a signal may occur at any time. All others I'll treat as fatal. When the monitoring thread stops, a user will no longer get notification of pin state changes CTS, DTR, DCD and RI. I had an old phone that also provided a /dev/ttyACM0 interface, unfortunately, I can't test with that (the ioctl works). I've tested by changing code in such a way that the error occurs and I get the result I expect (no 100% CPU, the thread stops and the program continues as expected). |
Could I make a suggestion? A better failure mode for devices that don't support waiting (and those who fail at it) would be to update pin changes using a thread with a fixed wait time (i.e 10ms) IMHO. We don't use that functionality currently, so it's not an issue for us. Just saying. |
And I'm happy to test any changes you make on Monday on the hardware, no issue. |
For some serial devices, such as ttyACM* USB devices, the ioctl(TIOCMIWAIT) returns an error. Now if an error occurs, we propogate it to the .NET implementation which already correctly ends the monitoring thread. Previously, the error was ignored in a loop resulting in 100% CPU utilization. Issue: DOTNET-85, #22
I've made a first draft in github with the branch "bugfix/modem". There are a few other fixes present when I reviewed the code. I'll look over your suggestion and see what I can do. |
Hu, wondering if you had the chance to test before I merge to the main branch. |
Sorry I haven't my hardware got feature frozen for a demos. Unfortunately that's the only one I have built at the moment. Another one will be getting built very soon, probably early next week, |
Would you be able to review the code? I'd like to be ready to merge on the weekend. Thanks for your help. |
looks fine to me |
Just did a review of my own after a few days. I've found a few bugs, so I'll have to clean them up first. |
For some serial devices, such as ttyACM* USB devices, the ioctl(TIOCMIWAIT) returns an error. Now if an error occurs, we propogate it to the .NET implementation which already correctly ends the monitoring thread. Previously, the error was ignored in a loop resulting in 100% CPU utilization. Issue: DOTNET-85, #22
Bugs fixed and now pushed to v2.x |
@jcurl I tested your newest version today. The issue is back. strace shows:
|
The problem appears to be that the pthread continues to get recreated after a failure. |
Just a sanity question, did you update and use the newer libnserial package? Did you compile from source or install the debian package? |
yes using the latest libnserial compiled from git, and the latest .net side from NuGet. I forgot to mention that that strace is above is grep'ed with ioctl. I did some debugging and found that although the pthread is exited on failure, it gets restarted when requested again. |
hi, i have the same problem in raspberry pi 3 b+ |
i found that,i am use 2.1.2 version the cpu not 100% and the 2.1.4 when i use it (serialportstream object singleton) read while 7 or 8 hours my raspberry cpu will cpu 100% all time.and that 2.1.2 will not |
I'm open for patches to review if you can provide a generic solution without regressions for standard hardware. |
i have catch crash info |
i found that 2.1.2 always will let cpu 100% |
The TIOCMIWAIT ioctl returns EINVAL on some drivers/hardware. This results in 100% CPU usage for the thread as instead of blocking the function call immediately returns.
Perhaps it would be better to just introduce a delay (sleep) in cases like this since you can't wait on pin changes on this hardware.
The text was updated successfully, but these errors were encountered: