perf kvm stat live: Use perf_evlist__add_pollfd() instead of local equivalent
Since we can add file descriptors to the evlist pollfd and it will autogrow, no need to copy all events to a local pollfd array, just add the timer and stdin file descriptors. Reviewed-by: David Ahern <dsahern@gmail.com> Acked-by: Jiri Olsa <jolsa@kernel.org> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Corey Ashford <cjashfor@linux.vnet.ibm.com> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <fweisbec@gmail.com> Cc: Ingo Molnar <mingo@kernel.org> Cc: Jean Pihet <jean.pihet@linaro.org> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Paul Mackerras <paulus@samba.org> Cc: Peter Zijlstra <a.p.zijlstra@chello.nl> Link: http://lkml.kernel.org/n/tip-2hvp9iromiheh6rl4oaa08x5@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
9ae28035b8
commit
0a04c9e0b2
1 changed files with 9 additions and 13 deletions
|
@ -919,15 +919,8 @@ static int kvm_events_live_report(struct perf_kvm_stat *kvm)
|
||||||
signal(SIGINT, sig_handler);
|
signal(SIGINT, sig_handler);
|
||||||
signal(SIGTERM, sig_handler);
|
signal(SIGTERM, sig_handler);
|
||||||
|
|
||||||
/* copy pollfds -- need to add timerfd and stdin */
|
/* use pollfds -- need to add timerfd and stdin */
|
||||||
nr_fds = kvm->evlist->nr_fds;
|
nr_fds = kvm->evlist->nr_fds;
|
||||||
pollfds = zalloc(sizeof(struct pollfd) * (nr_fds + 2));
|
|
||||||
if (!pollfds) {
|
|
||||||
err = -ENOMEM;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
memcpy(pollfds, kvm->evlist->pollfd,
|
|
||||||
sizeof(struct pollfd) * kvm->evlist->nr_fds);
|
|
||||||
|
|
||||||
/* add timer fd */
|
/* add timer fd */
|
||||||
if (perf_kvm__timerfd_create(kvm) < 0) {
|
if (perf_kvm__timerfd_create(kvm) < 0) {
|
||||||
|
@ -935,17 +928,21 @@ static int kvm_events_live_report(struct perf_kvm_stat *kvm)
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
pollfds[nr_fds].fd = kvm->timerfd;
|
if (perf_evlist__add_pollfd(kvm->evlist, kvm->timerfd))
|
||||||
pollfds[nr_fds].events = POLLIN;
|
goto out;
|
||||||
|
|
||||||
nr_fds++;
|
nr_fds++;
|
||||||
|
|
||||||
pollfds[nr_fds].fd = fileno(stdin);
|
if (perf_evlist__add_pollfd(kvm->evlist, fileno(stdin)))
|
||||||
pollfds[nr_fds].events = POLLIN;
|
goto out;
|
||||||
|
|
||||||
nr_stdin = nr_fds;
|
nr_stdin = nr_fds;
|
||||||
nr_fds++;
|
nr_fds++;
|
||||||
if (fd_set_nonblock(fileno(stdin)) != 0)
|
if (fd_set_nonblock(fileno(stdin)) != 0)
|
||||||
goto out;
|
goto out;
|
||||||
|
|
||||||
|
pollfds = kvm->evlist->pollfd;
|
||||||
|
|
||||||
/* everything is good - enable the events and process */
|
/* everything is good - enable the events and process */
|
||||||
perf_evlist__enable(kvm->evlist);
|
perf_evlist__enable(kvm->evlist);
|
||||||
|
|
||||||
|
@ -979,7 +976,6 @@ static int kvm_events_live_report(struct perf_kvm_stat *kvm)
|
||||||
close(kvm->timerfd);
|
close(kvm->timerfd);
|
||||||
|
|
||||||
tcsetattr(0, TCSAFLUSH, &save);
|
tcsetattr(0, TCSAFLUSH, &save);
|
||||||
free(pollfds);
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue