-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
usdt: Add support for kernel usdt semaphore activation #1567
Conversation
Dependent on iovisor/bcc#3135 . |
@@ -1268,7 +1268,18 @@ hi | |||
^C | |||
``` | |||
|
|||
bpftrace also supports USDT semaphores. You may activate semaphores by passing in `-p $PID` or | |||
bpftrace also supports USDT semaphores. If both your environment and bpftrace |
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.
Is this a (new) kernel feature or has it been in there for ages? Might be good to list the required version if this requires a modern kernel
It came out in 4.20 kernel which came out late 2018. I think it should be fine to leave out.
…On Wed, Oct 21, 2020, at 2:17 AM, bas smit wrote:
***@***.**** commented on this pull request.
In docs/reference_guide.md
<#1567 (comment)>:
> @@ -1268,7 +1268,18 @@ hi
^C
```
-bpftrace also supports USDT semaphores. You may activate semaphores by
passing in `-p $PID` or
+bpftrace also supports USDT semaphores. If both your environment and
bpftrace
Is this a (new) kernel feature or has it been in there for ages? Might
be good to list the required version if this requires a modern kernel
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#1567 (review)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAGJKJYDI4J42FBEVEYM5RDSL2RMNANCNFSM4SZEBKMQ>.
--
Daniel Xu
accounts@dxuuu.xyz
|
cc @dalehamel |
Thanks @javierhonduco i've been keeping an eye on this and iovisor/bcc#3135 |
bcc PR is merged, this is ready for review now |
Looks good :). @dalehamel do you have time for a review, im not that familiar with usdts |
@fbs i'll give this a closer look this week |
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.
Love it. I wonder if we can update github actions for CI so that we run on several versions of ubuntu, as I think that ubuntu 16.04 is still on 4.15 kernel that doesn't have this API, but 20.04 and 18.04 are on 5.4 kernels that do have it.
It would be great to be able to test both code paths (kernel has ref counter offset, kernel doesn't) in CI, but everything looks right to me.
@danobi needs a rebase |
Will be used in a later commit to see if we can use the kernel's usdt semaphore support.
The function was getting huge, with a bunch of #ifdef's sprinkled around. It was pretty hard to reason about, let alone add more #ifdef branches. This is (hopefully) a non-functional change.
If available, let the kernel manage the semaphore count for the usdt probe. This is better because the kernel can activate the semaphore on all processes that have the target mapped much faster than the current --usdt-file-activation implementation (which walks /proc/*/maps) and greps for strings. It's also better b/c if bpftrace crashes the kernel can reliable decrement the semaphore.
Now you can gate a runtime test on a feature NOT being present. eg: REQUIRES_FEATURE !btf
@dalehamel I'll file a separate issue for VM tests in CI |
Don't merge this yet -- I'm investigating the build failure. This is looking to be a really strange bug. Either in bcc or in the kernel. |
Ok, so it took an entire day of printf debugging the kernel, but I have a suspicion. I think embedded build's toolchain is having I'll update the tests to allow >1 semaphore count bump. |
The kernel can do it much faster and reliably. Note that the kernel may increment the semaphore by more than 1. This happens when the executable image is mapped to >1 VMAs. The runtime tests are updated to accept a semaphore value > 0.
If we run two usdt_semaphore_test binaries and both are running a busy loop full speed, then all the events generated by the first binary can overflow the perf buffer and starve out events from the second binary.
That's really bizarre if it depends on the toolchain... maybe it is the BCC version though? I think the embedded builds were still on 0.12 last I checked, but there is a build that does "latest" also, the "edge" build. Is that one also behaving oddly?
I think I've seen this exact issue before, but I forget what the conclusion was... I've found using |
I don't think so. I singled stepped the code using GDB and it really was the syscall (perf_event_open) incrementing by 2. I dumped the perf_event_open() args using strace and everything matched. I could also reproduce the issue with a native build of bpftrace against the embedded built test prog. So I really do think it's the test prog doing some funny stuff here.
I think I fixed that in 17588d2 . Lemme know if it's still buggy and I can take a look |
This PR adds support for the kernel's uprobe ref count API. If you
pass the kernel an offset to the usdt semaphore while attaching
a uprobe, the kernel will manage the lifetime of the semaphore.
This is better because:
--usdt-file-activation than we can in userspace (faster and less
racy)
This is nice because it makes usdt's with semaphore act like a regular
usdt. No need to pass the PID to activate the semaphore.
Checklist
docs/reference_guide.md
CHANGELOG.md