On Wed, Jul 03, 2019 at 08:14:30PM -0700, Kris Van Hees wrote:
> +int dt_bpf_attach(int event_id, int bpf_fd)
> +{
> +     int                     event_fd;
> +     int                     rc;
> +     struct perf_event_attr  attr = {};
> +
> +     attr.type = PERF_TYPE_TRACEPOINT;
> +     attr.sample_type = PERF_SAMPLE_RAW;
> +     attr.sample_period = 1;
> +     attr.wakeup_events = 1;
> +     attr.config = event_id;
> +
> +     /* Register the event (based on its id), and obtain a fd. */
> +     event_fd = perf_event_open(&attr, -1, 0, -1, 0);
> +     if (event_fd < 0) {
> +             perror("sys_perf_event_open");
> +             return -1;
> +     }
> +
> +     /* Enable the probe. */
> +     rc = ioctl(event_fd, PERF_EVENT_IOC_ENABLE, 0);

AFAICT you didn't use attr.disabled = 1, so this IOC_ENABLE is
completely superfluous.

> +     if (rc < 0) {
> +             perror("PERF_EVENT_IOC_ENABLE");
> +             return -1;
> +     }
> +
> +     /* Associate the BPF program with the event. */
> +     rc = ioctl(event_fd, PERF_EVENT_IOC_SET_BPF, bpf_fd);
> +     if (rc < 0) {
> +             perror("PERF_EVENT_IOC_SET_BPF");
> +             return -1;
> +     }
> +
> +     return 0;
> +}

Reply via email to