Re: [PATCH 06/10] perf evlist: Allow growing pollfd on add method
From: Jiri Olsa
Date: Mon Aug 25 2014 - 05:48:09 EST
On Fri, Aug 22, 2014 at 05:59:46PM -0300, Arnaldo Carvalho de Melo wrote:
SNIP
>
> -static int perf_evlist__alloc_pollfd(struct perf_evlist *evlist)
> +static int perf_evlist__grow_pollfd(struct perf_evlist *evlist, int hint)
> +{
> + int nr_fds_alloc = evlist->nr_fds_alloc + hint;
> + size_t size = sizeof(struct pollfd) * nr_fds_alloc;
> + struct pollfd *pollfd = realloc(evlist->pollfd, size);
> +
> + if (pollfd == NULL)
> + return -ENOMEM;
> +
> + evlist->nr_fds_alloc = nr_fds_alloc;
> + evlist->pollfd = pollfd;
> + return 0;
> +}
> +
> +int perf_evlist__alloc_pollfd(struct perf_evlist *evlist)
> {
> int nr_cpus = cpu_map__nr(evlist->cpus);
> int nr_threads = thread_map__nr(evlist->threads);
> @@ -416,16 +430,28 @@ static int perf_evlist__alloc_pollfd(struct perf_evlist *evlist)
> nfds += nr_cpus * nr_threads;
> }
>
> - evlist->pollfd = malloc(sizeof(struct pollfd) * nfds);
> - return evlist->pollfd != NULL ? 0 : -ENOMEM;
> + if (evlist->nr_fds_alloc - evlist->nr_fds < nfds &&
> + perf_evlist__grow_pollfd(evlist, nfds) < 0)
> + return -ENOMEM;
hum, so do we still need perf_evlist__alloc_pollfd?
we grow any time we need inside perf_evlist__add_pollfd..
jirka
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/