Re: [PATCH v2 01/18] trace-cmd: Add initial perf interface in trace-cmd library

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, 22 Mar 2021 11:59:28 +0200
"Tzvetomir Stoyanov (VMware)" <tz.stoyanov@xxxxxxxxx> wrote:

> +void trace_perf_close(struct trace_perf *perf)
> +{
> +	if (perf->fd >= 0)
> +		close(perf->fd);
> +	perf->fd = -1;
> +	if (perf->mmap)

The above should be:

	if (perf->mmap && perf->mmap != MAP_FAILED)

-- Steve

> +		munmap(perf->mmap, (perf->pages + 1) * getpagesize());
> +	perf->mmap = NULL;
> +}
> +
> +/**
> + * trace_perf_open - Open perf session
> + *
> + * @perf: structure, representing perf context that will be opened. It must be
> + *	  initialized with trace_perf_init().
> + *
> + * Returns 0 on success, or -1 in case of an error. In case of success, the
> + * session must be closed with trace_perf_close()
> + */
> +int trace_perf_open(struct trace_perf *perf)
> +{
> +	perf->fd = syscall(__NR_perf_event_open, &perf->pe, perf->pid, perf->cpu, -1, 0);
> +	if (perf->fd < 0)
> +		return -1;
> +	fcntl(perf->fd, F_SETFL, O_NONBLOCK);
> +
> +	perf->mmap = mmap(NULL, (perf->pages + 1) * getpagesize(),
> +			  PROT_READ | PROT_WRITE, MAP_SHARED, perf->fd, 0);
> +	if (perf->mmap == MAP_FAILED)
> +		goto error;
> +
> +	return 0;
> +
> +error:
> +	trace_perf_close(perf);
> +	return -1;
> +}




[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux