Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Attach a program to a raw perf event rather than a kernel or userspace function #338

Open
pittma opened this issue Jun 29, 2022 · 3 comments

Comments

@pittma
Copy link

pittma commented Jun 29, 2022

Hey all, I've been digging around the redbpf source today, trying to track down a way to use it to map an ebpf program to a regular old perf event (a hardware event in my case). In the Python BCC library, you can use attach_perf_event_raw and map a perf_event_attr to a function:

prog_text="""
int hw_event(struct bpf_perf_event_data *ctx) {
    // do stuff with `ctx`
}
"""

attr = Perf.perf_event_attr()
attr.type=PerfType.RAW

# hw_hexcode here is the perf event + mask
attr.config = int(hw_hexcode, 16)

b = BPF(text=prog_text)
b.attach_perf_event_raw(perf_event_attr=attr, fn_name=hw_event, pid=pid, cpu=cpu)

How might I do this with redbpf?

@GermanCoding
Copy link
Contributor

Hi,

as far as I know redBPF does not support raw tracepoints at this time. I had a look at the requirements and it does not look to be terribly different from what we already have, so likely doable, but it just isn't there at this time.

@AlexandruCihodaru
Copy link

Hello @GermanCoding I would like to contribute this. :D

@GermanCoding
Copy link
Contributor

I am not a maintainer of redBPF, but sure go ahead. From my experience the maintainers do review and merge code.

Revisiting the original question, I think I misread it. I thought about raw tracepoints, but it looks like the actual question was about BPF_PROG_TYPE_PERF_EVENT (perf event programs). I don't remember redBPF support for these either.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants