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

Try use new API to create [k,u]probe with perf_event_open #1518

Merged
merged 2 commits into from
Jan 10, 2018

Conversation

liu-song-6
Copy link
Contributor

New kernel API allows creating [k,u]probe with perf_event_open.
This patch tries to use the new API. If the new API doesn't work,
we fall back to old API.

The kernel part of this work is available for test at:
git:https://git.kernel.org/pub/scm/linux/kernel/git/peterz/queue.git perf/core

Thanks,
Song

@yonghong-song
Copy link
Collaborator

[buildbot, ok to test]

Copy link
Collaborator

@yonghong-song yonghong-song left a comment

Choose a reason for hiding this comment

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

Change looks good. Tested on a VM with the change (PeterD's queue git, perf/core branch).

src/cc/libbpf.c Outdated
char buf[64];

snprintf(buf, sizeof(buf), PMU_TYPE_FILE, event_type);

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you need to check the return value of snprintf? Is it possible that it may fail in the future?

src/cc/libbpf.c Outdated
int ret;
char buf[64];

snprintf(buf, sizeof(buf), PMU_RETPROBE_FILE, event_type);
Copy link
Collaborator

Choose a reason for hiding this comment

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

The same here, check snprintf return status?

src/cc/libbpf.c Outdated
struct perf_reader *reader, int pid,
int pfd)
{
int efd, cpu = 0;
ssize_t bytes;
char buf[256];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not related to your patch, but for long file path, the buffer size may not be enough. Could you help change it to PATH_MAX?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Teng just fixed it :)

goto error;
}
res = snprintf(event_alias, sizeof(event_alias), "%s_bcc_%d", ev_name, getpid());
if (res < 0 || res >= sizeof(event_alias)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure what these solid green block is? Is this due to using TAB? In bcc non-kernel code, we use spaces instead of TABs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is because we moved many lines into if (pfd < 0). Diff broke it into several sections, but it is just adding 2 more spaces for the whole chunk (

@yonghong-song
Copy link
Collaborator

Please rebase on top of trunk as there is a conflict for ready-to-merge.

The new [k,u]probe API allows creating [k,u]probe together with
perf_event_open. This patch adds functions to use the new API.

Note: these new functions are not used until next patch, so this patch
doesn't change the behavior. The change is splitted into two patches
for cleaner review.

Signed-off-by: Song Liu <[email protected]>
New kernel API allows creating [k,u]probe with perf_event_open.
This patch tries to use the new API. If the new API doesn't work,
we fall back to old API.

bpf_detach_probe() looks up the event being removed. If the event
is not found, we skip the clean up procedure.

Signed-off-by: Song Liu <[email protected]>
Copy link
Collaborator

@yonghong-song yonghong-song left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks!

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.

2 participants