Repository navigation
Fix shutdown with TRACY_NO_EXIT=1 on Android. - #134
Conversation
Nicely found.
There is no relationship to order here. It's just a status variable that indicates when threads should exit.
It doesn't work fine.
Maybe checking if stdout is still open in |
More precise questions:
Ah, thanks for explaining the rationale for I'm runnin Android 10 and (One of the Actually if I so it is passively waiting on a blocking Out of curiosity is this about the implementation of Would |
Complexity of code? :) Joking aside, you are probably right here. The C++ standard wording once again manages to be clear as mud.
It doesn't matter. Signalling the thread that it should exit and disabling tracing on the kernel side are two separate things that don't depend on each other.
I think you are skipping kernel time here. What I do is use Tracy to see what is happening at the scheduler level. For example, this is And Despite the same application name, these are two different workloads. The second one is utilizing an external SDK to capture video, which makes the system more busy, as can be seen by number of scheduled threads. Unfortunately, this is what I currently have available. You may reproduce these measurements using both methods with your application, to see if there's an observable difference on your device. There should be, as constant wakeups of In some cases using Evidently the OS tries to save power here, keeping just one core active, which results in constant preemption of the profiled application's thread, which in this example is actively trying to do something (not waiting). |
|
Thanks a lot for the explanation. Now I understand what Please review; this code works for me on Android 10 / Aarch64. I have tested that the I edited the
I also made another change: removed that Regarding C++ atomics: this is definitely a hairy topic, C++ standardization on it is still iterating on it, and the lead person on it has been giving advice like this: (see these slides, go to slide 34) "Weakly ordered atomics are hard! Avoid when possible!" |
It is contained in the elfkickers package, which seems to be not available in debian. You can get it from https://github.com/BR903/ELFkickers.
Probably something changed in how the binary is built by the compiler in the meantime. The original list of sections to remove was created by trying to remove all that was there and checking if the binary still runs.
Good point. I think redirecting to
There always is a performance reason :)
I don't think instruction reordering (be it by compiler or by CPU) has an impact here. My resasoning here is as follows: I fully expect a number of "incorrect" loop iterations until the memory controller finally catches up to the value stored by the other thread. This is not a problem, as this cost is only paid once (when the state is changing), and this approach reduces the 100 cycles per-read stall to just a normal memory read cost during normal operation, when the value is not changing.
I believe the default (seq_cst) to be always quite bad? If there was to be a change, I would expect to use release and acquire ordering. Generally speaking, I hear you there, but I'm not sure I want to act right now. There are other places in code where this pattern is used, for example: tracy/server/TracyFileRead.hpp Lines 371 to 376 in 0073fd7 To make things worse, the relaxed ordering is also used in an example at https://en.cppreference.com/w/cpp/atomic/atomic_flag: while (lock.test(std::memory_order_relaxed)) // test lock
; // spin |
|
Thanks for the review and answers. Now this is with I tried again with Regarding |





With
TRACY_NO_EXIT=1on Android, the profiled program was never terminating, not even after Tracy UI connected, finished getting data and terminated itself.Debugging this, I first found that the
breakhere is only breaking out of the inner loop, so we're back to the outerfor(;;)loop, so we need to alsobreakout of it. That's the first line in this commit.(Side note: I would be very interested in an explanation of why this code uses
std::memory_order_relaxed- what is providing the memory ordering relationships here? Anyway, I played with that too but that wasn't relevant to the observed issue.)Once I had fixed the above, it still wasn't terminating. Then I noticed that the
tracy_systraceprocess was still running on the device. Killing it allowed the profiled program to terminate. That also explained why we were getting errors as follows while trying to createtracy_systrace: we were failing to overwrite this binary as it was still running.According to
pson the device,tracy_systracewas sleeping:So this wasn't a matter of just
waitpidon it. I tried callingkill(2)on it withSIGKILLbut that didn't work; in hindsight that might be a permissions problem; i could retry with the usualsutechnique as elsewhere in this file, but...At this point I remembered that on recent Android devices we don't seem to need
tracy_systraceat all, ascat /sys/kernel/debug/tracing/trace_pipeseems to be working fine. So I changed theexec'd command to try that first, and fall back totracy_systraceotherwise (note - I needed to implement that in the shell command, whence the||shell operator, and not in C++, becauseexecnever returns unless in some basic error cases, and here it likely won't return even ifcat /sys/kernel/debug/tracing/trace_pipefails).Then I added the
waitpidto wait on this child, which works fine as long as we are taking thecat /sys/kernel/debug/tracing/trace_pipecode path.So we still have (I guess) the never-terminating issue in the
tracy_systracecode path, but that is now only a legacy fallback.