[DTrace-devel] [PATCH 1/1] tools/dtrace: initial implementation of DTrace

Peter Zijlstra peterz at infradead.org
Thu Jul 4 06:05:09 PDT 2019


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;
> +}



More information about the DTrace-devel mailing list