Skip to content
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

BTF support for tracepoints defined in modules #2479

Merged
merged 2 commits into from Apr 11, 2023

Conversation

viktormalik
Copy link
Contributor

@viktormalik viktormalik commented Jan 20, 2023

For tracepoints defined in vmlinux, we support usage of BTF for type parsing which can automatically resolve types from tracepoint defs. Thanks to this feature, users do not have to include headers with necessary types manually.

This PR enables the same for tracepoints defined in kernel modules. Since parsing of BTF for modules is already supported for kfuncs (#2315) , this change is as simple as adding the subsystem name to the list of modules whose BTF is parsed.

At the moment, this is not supported for tracepoints using wildcarded subsystems. The reason is that tracepoints require dumping of C definitions from BTF which is not possible for multiple modules at once (as it could introduce type redefinitions) so this feature is limited to single-subsystem tracepoints only.

Check #2094 to see where this is useful.

Checklist
  • Language changes are updated in man/adoc/bpftrace.adoc and if needed in docs/reference_guide.md
  • User-visible and non-trivial changes updated in CHANGELOG.md
  • The new behaviour is covered by tests

std::unordered_set<std::string> to_dump(set);
if (btf_objects.size() == 2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like if bpf_objects.size() > 2, then only vmlinux btf is dumped. And user will get an ambiguous error about incomplete/missing definitions. Do we want to have a more explicit error check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. It'll happen only if probes from multiple modules are used at once, but adding the error message should be relatively easy.

Dumping C definitions from multiple kernel modules at once can introduce
type redefinitions, hence it is not supported for now. On the other
hand, we can support dumping from a single module since there should be
no conflicts and it could help for some situations.

This will enable BTF support for tracepoints defined in modules as
tracepoints always need to dump C structs from BTF for ClangParser.
For tracepoints defined in vmlinux, we support usage of BTF for type
parsing which can automatically resolve types from tracepoint defs.
Thanks to this feature, users do not have to include headers with
necessary types manually.

This commit enables the same for tracepoints defined in kernel modules.
Since parsing BTF for modules is already supported for kfuncs, it is
sufficient to add the tracepoint subsystem name to the list of modules.
If the name of the subsystem does not correspond to a loaded module, it
will be ignored.

Note that this is only supported for single-subsystem tracepoints at the
moment. The reason is that tracepoints require dumping of C definitions
from BTF which is not possible for multiple modules at once (as it could
introduce type redefinitions).
@danobi danobi merged commit 74a5604 into bpftrace:master Apr 11, 2023
20 checks passed
@viktormalik viktormalik deleted the tracepoint-modules-btf branch June 5, 2023 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants