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
cmd/pprof: macOS 12.6.1 profile overcounts system calls (again) #57722
Comments
Testing on an Intel MacOS (MacOS 12.6.1) go version
go env
I'm a bit of a go noob (start during advent of code lol), so I wasn't able to set up the UI you used but my IDE's built in pprof output looks similar to yours. If you want the matching profiler UI and send me a how-to link I can set it up :) |
@cbedard thanks, this looks like Intel Macs have the same issue. The UI doesn't matter, this is fine :). |
@golang/runtime |
It would not surprise me if darwin has unfair SIGPROF delivery. e.g., if the system call return path updates the CPU timers, it may be more likely to trigger overflow and deliver SIGPROF to itself vs threads that do not make system calls. |
I think this could be tested with a simple C program. Two threads, one running a busy loop, the other with a busy loop that makes a system call. Do they both receive ~50% of SIGPROF signals? |
I haven't read the sample code. Just wonder, for the "interleaved" case, are the compression and I/O running concurrently on different goroutines/threads, or they are on the same thread but just interleaved? If the latter, do you know what frequency or time period the interleaving is, and is it faster than the profile sampling frequency (100 Hz)? Thanks. |
It's the latter. But I suspect that there could be concurrent/parallel read-ahead happening on the OS level.
According to the trace (shown below), the workload issues 53k syscalls in 3.7s, so at ~14kHz it's much faster than the profiling frequency.
What syscall would you use? It would have to be a non-blocking one to see 50%? But yeah, a small C reproducer could be useful for this. |
I'd start with getpid or something similar, though perhaps it needs to go through the scheduler, so a very briefly blocking system call may be needed. |
In triage now, since it seems like the next step is a C reproducer to confirm unfair SIGPROF delivery? Does that sound right? (The assignee is mostly just for tracking, there's no obligation; feel free to remove it.) |
What version of Go are you using (
go version
)?This is on macOS 12.6.1 with an M1 chip, but the problem seems to affect Intel as well.
Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Create a CPU profile of a CPU-bound workload that is interleaved with short system calls.
For example TestInterleavedIO is a reproducer that is compressing a 250MB file containing random data.
What did you expect to see?
A profile that is similar to the one shown below for linux. Most of time should be spent on gzip compression, and a little bit on syscalls.
What did you see instead?
On macOS the majority of time is attributed to read and write syscalls. The gzip compression is barely showing up at all.
Sanity Check
TestSequentialIO implements the same workload, but instead of interleaved I/O, it does one big read first, followed by gzip compression, followed by a big write.
As expected, Linux produces a profile dominated by gzip compression.
And macOS now shows the right profile too.
Conclusion
macOS
setitimer(2)
seems to bias towards syscalls. This issue was reported and fixed in the past, see #17406 (2016) and #6047 (2013). So this could be a macOS regression.I've uploaded all code, pprofs and screenshots to this google drive folder.
The text was updated successfully, but these errors were encountered: