Conversation
|
The hf search issue will have no connection to the lf search hang. (Connected to the hitag/cotag/em4x05 detection) |
|
So you're saying that at present, this code hangs on Windows when doing |
|
micolous:revert-450 |
|
i have finally had a little time to test this pull myself and have found no evidence of lingering issues (caused or exposed) from this PR on windows. hf search works fine on 14a, mifare + compatibles + magic, ntag, 15693, 14b, and when no tag is on the antenna. i therefore cannot explain #449. user error? |
|
Yes i have tested it. Works great with my cards (14a, mifare + magic, 15693, legic prime). |
| printf("uart_receiver: get lock\n"); | ||
| #endif | ||
| // Lock up receives, in case they try to take it away from us. | ||
| pthread_mutex_lock(&conn->recv_lock); |
There was a problem hiding this comment.
Why do we need this lock? There is only only one thread calling this function.
There was a problem hiding this comment.
It's also called in flash.c in CloseProxmark -- this ensures that when we do a serial port dance in enter_bootloader, that the receive thread can be stalled while we get a new serial port connection in place.
| // We aren't normally trying to transmit in the flasher when the port would | ||
| // be reset, so we can just keep going at this point. | ||
| pthread_mutex_lock(&txcmd_lock); | ||
| if (txcmd_pending) { |
There was a problem hiding this comment.
Can't we eliminate txcmd_pending? It is kind of a self made signal.
There was a problem hiding this comment.
Not entirely. I'll replace it with an if statement instead, because that makes a bit more sense.
The reason is the execution flow is as follows:
SendCommandcalled on main thread.SendCommandwaits fortxcmd_lock.SendCommandchecks to see if there is an existing command in the buffer, if not, then stuffs the command in the buffer then returns.SendCommandgets another command, gets a lock.SendCommandsees there's already a command in the buffer, callspthread_cond_waitto wait for thetxcmdto be sent, and releases the lock in the interim (and blocks the main thread)uart_receiveracquires thetxcmd_lockuart_receiversees a command in the buffer and sends it.uart_receiverclearstxcmd_pending, and signals totxcmd_sigthat it is ready for more datauart_receiverunlockstxcmd_lockSendCommandunblocks, lockstxcmd_lockand stuffs a new command into the buffer.SendCommandunlockstxcmd_lock, and then returns.uart_receiverpicks up the new buffered command on the next loop.
It could be replaced also if txcmd was a pointer instead, but many operations modify an existing UsbCommand immediately after sending it, only to send it again. This could lead to a race between the main and uart_receiver threads, leading to the command possibly being corrupted in flight.
The goal is to make SendCommand slightly asynchronous -- it'll only block if there's another command still to be sent out, or if it's a flasher command (in which case it is being sent immediately).
"special case" sounds like an ugly workaround. Why do other commands break? Makes me shiver... Is there a reason for the
Correct. |
I agree. But I'm trying to not rock the boat... The existing PM3 In most circumstances I don't think this is a big deal, but the specific complaint raised in the last PR was that flashing was quite a lot slower. The While I didn't run a profiler to find this out, when I pulled it into the main thread everything worked with equivalent wall-clock performance. This appears to be introduced in f0ba634, but as this was pre-GitHub (2012-12), I think you'll find that the context of that change is buried somewhere in the Proxmark Forum archives. Going back further I see that
I tried tweaking the sleeps as well (they also make me lose sleep), and didn't see a significant improvement until I pulled the flashing command back into the main thread. I think running a profiler over the flasher (and other components) would be good to do, but that would also require writing some isolated tests. I haven't done much C profiling though, and I haven't yet been motivated to spend the time here. |
|
@pwpiwi I think I've addressed the issues you've outlined already, can we merge this? |
|
Some conflicts need to be fixed, then decision on merge. |
|
I didn't even test yet. There is one issue mentioned by @micolous which rings my warning bells:
If there is a special case handling required for a command to make it run faster and others break when treated the same, this indicates a race condition, hand shake problem or timing issue to me. |
|
When @pwpiwi is satisfied I'll rebase this against
I agree there's an issue with multi-threaded access in PM3, but it has been a problem even before this patch. I addressed that issue with mutexes.
We shouldn't be in a position where moving some methods around causes all the code to break (especially on single platforms).
Lines 43 to 50 in a37725f In light the performance complaints, |
|
@micolous: thanks for the explanation. Makes sense and mutes the warning bell 😃 Let's start testing after rebase. |
|
@pwpiwi I rebased it against I tested this on Ubuntu 17.10 and OSX 10.13. |
|
Status on this one? @pwpiwi @marshmellow42 |
|
I've made several line comments. Do those not notify? There are some minor find and replace errors, and a potential infinite loop. |
|
Hold that thought, I may be confusing this PR for another .. |
|
I belive this one should compensate for the slowdown of pm3, (booting from 6sec -> 12sec) |
|
I believe the main purpose if this PR was to prepare for @micolous Android library. And some refactoring to concentrate all UART related code pieces. And some additional mutexes to prevent race conditions (but I am wondering how these could occur with the current "send command - wait for response" client) |
|
Slowness of PM3 booting is not something that I've touched on this PR. That is a firmware issue. The purpose of this PR is where I've minimised the changes needed to get PM3 running as a library, and I can throw in a compatible This change would also allow some more robust tests to be run on the client as well. I have ported the |
|
Also tested with Windows now (using ProxSpace), seems to be happy. |
client/comms.c
Outdated
| if (msclock() - start_time > 2000 && show_warning) { | ||
| // 2 seconds elapsed (but this doesn't mean the timeout was exceeded) | ||
| PrintAndLog("Waiting for a response from the proxmark..."); | ||
| PrintAndLog("Don't forget to cancel its operation first by pressing on the button"); |
There was a problem hiding this comment.
This wording was changed in a recent PR. As it is now it can be confusing as it sounds like the user is supposed to press the button regardless.
| while (!WaitForResponse(CMD_ANY, &resp)) { | ||
| // Keep waiting for a response | ||
| msleep(100); | ||
| } |
There was a problem hiding this comment.
What happens if there is no response?
There was a problem hiding this comment.
Exactly what ReceiveCommand did before... it would wait forever. The only difference here is that msleep makes this less of a tight loop.
|
@marshmellow42, @iceman1001: Did you test this successfully? Which platforms? Any Mac-Users here? |
|
Tested as described by doing as I did before repeatedly running I am not sure how to tell, but I know when I did the earlier tests I know I ran through the setup instructions on the wiki, so I would be using GNU Readline. I'm using a non-GUI . TLDR I was not able to reproduce my crash in these circumstances. `$ time ./flasher /dev/tty.usbmodem881 ../armsrc/obj/fullimage.elf Waiting for Proxmark to appear on /dev/tty.usbmodem881. Found. Flashing... Resetting hardware... Have a nice day! real 0m6.510s `$ time ./flasher /dev/tty.usbmodem881 ../armsrc/obj/fullimage.elf Waiting for Proxmark to appear on /dev/tty.usbmodem881. Found. Flashing... Resetting hardware... Have a nice day! real 0m6.333s Attached is the compile from the micolous code base I did have a repeating warning when compiling that was not present in the main Proxmark code. |
|
Thanks @tuxthemadpenguin. I think in the absence of further crashes on a clean build environment, we can assert that the crashes that you saw were unrelated to the changes in this PR. As for telling which readline was linked, you should be able to do it with For example, following the wiki instructions, you'll get a build using This build is linked against As for the build warning, that @pwpiwi I'll rebase this on #585 (which has a better documented fix for libedit/readline issues than what is here). Please let me know if there are any other blockers. |
|
The rl_initialize call in this PR makes the client crash after a few times on ubuntu1704. I posted in another thread about the error message. |
…oxmark#371)"" This reverts commit 289d25a.
…note on race condition ugliness.
- Remove unused rarg parameter. - Make uart_receiver non-static, and add force_align_arg_pointer to header.
|
Removed
|
|
In order to make progress, I have prepared PR #587 which just moves code around between files, some minor changes (like replacing |
|
See PR #595 for a second part of this PR. |
* make uart_receiver() static in comms.c * move receiver thread creation and respective mutexes to comms.c * use comms.c for flasher as well
* make uart_communication() static in comms.c * move receiver thread creation and respective mutexes to comms.c * add mutex and signal for tx buffer * use comms.c for flasher as well * remove comm functions from client/proxmark3.h * this completes isolating all USB communication related functions in comms.c
* make uart_communication(), storeCommand() and getCommand() static in comms.c * move receiver thread creation and respective mutexes to comms.c * add mutex and signal for tx buffer * use comms.c for flasher as well * remove comm functions from client/proxmark3.h * this completes isolating all USB communication related functions in comms.c * don't assume a port to be defined by a name. Change parameter in OpenProxmark() to void* * comms.c: set sp and serial_port_name to NULL when offline
This reverts #450, which reverted #371. As before, this is blocking other work that I'm doing on Android support. To address the issues raised post-merge in #450:
After this commit, the Flasher uses the same code as the rest of proxmark3, which executes
SendCommandon the Receiver thread (which is otherwise unmodified), and spins. Previously, the customSendCommandin flasher would execute on the main thread entirely.Flashing for me took 18.5 sec vs. 12.2 sec without the patch, so yep, performance regression.
I've since added another commit (c7376c3) which adds a special case for handling
CMD_FINISH_WRITEon the main thread, such that the flash speed is 12.3 sec. Other commands break when running in this fashion, so I haven't applied this workaround to other commands.I get the same speeds reported in the client with and without this patch. The speed is determined by the firmware, and there aren't firmware modifications in this commit.
I don't see the same issue (on Linux, on OSX...)
I also tried
lf search, no change observed without a card on patches, though without a card both would require pressing the PM-button in order to continue any operation. This may be the root cause if you have a dual-frequency antenna setup.ping @Fl0-0 @pwpiwi @cjbrigato