aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-kvm.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2014-08-18 16:12:30 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2014-09-25 15:46:54 -0400
commit0a04c9e0b2181aff8348b5e80d9d96ec8df1ffb3 (patch)
tree285bce0f10494c9a081f5bf16995968e89fc4242 /tools/perf/builtin-kvm.c
parent9ae28035b8677b82e1d71cea4f793cb5504ec104 (diff)
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>
Diffstat (limited to 'tools/perf/builtin-kvm.c')
-rw-r--r--tools/perf/builtin-kvm.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index f5d3ae483110..a440219b0be0 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -919,15 +919,8 @@ static int kvm_events_live_report(struct perf_kvm_stat *kvm)
919 signal(SIGINT, sig_handler); 919 signal(SIGINT, sig_handler);
920 signal(SIGTERM, sig_handler); 920 signal(SIGTERM, sig_handler);
921 921
922 /* copy pollfds -- need to add timerfd and stdin */ 922 /* use pollfds -- need to add timerfd and stdin */
923 nr_fds = kvm->evlist->nr_fds; 923 nr_fds = kvm->evlist->nr_fds;
924 pollfds = zalloc(sizeof(struct pollfd) * (nr_fds + 2));
925 if (!pollfds) {
926 err = -ENOMEM;
927 goto out;
928 }
929 memcpy(pollfds, kvm->evlist->pollfd,
930 sizeof(struct pollfd) * kvm->evlist->nr_fds);
931 924
932 /* add timer fd */ 925 /* add timer fd */
933 if (perf_kvm__timerfd_create(kvm) < 0) { 926 if (perf_kvm__timerfd_create(kvm) < 0) {
@@ -935,17 +928,21 @@ static int kvm_events_live_report(struct perf_kvm_stat *kvm)
935 goto out; 928 goto out;
936 } 929 }
937 930
938 pollfds[nr_fds].fd = kvm->timerfd; 931 if (perf_evlist__add_pollfd(kvm->evlist, kvm->timerfd))
939 pollfds[nr_fds].events = POLLIN; 932 goto out;
933
940 nr_fds++; 934 nr_fds++;
941 935
942 pollfds[nr_fds].fd = fileno(stdin); 936 if (perf_evlist__add_pollfd(kvm->evlist, fileno(stdin)))
943 pollfds[nr_fds].events = POLLIN; 937 goto out;
938
944 nr_stdin = nr_fds; 939 nr_stdin = nr_fds;
945 nr_fds++; 940 nr_fds++;
946 if (fd_set_nonblock(fileno(stdin)) != 0) 941 if (fd_set_nonblock(fileno(stdin)) != 0)
947 goto out; 942 goto out;
948 943
944 pollfds = kvm->evlist->pollfd;
945
949 /* everything is good - enable the events and process */ 946 /* everything is good - enable the events and process */
950 perf_evlist__enable(kvm->evlist); 947 perf_evlist__enable(kvm->evlist);
951 948
@@ -979,7 +976,6 @@ out:
979 close(kvm->timerfd); 976 close(kvm->timerfd);
980 977
981 tcsetattr(0, TCSAFLUSH, &save); 978 tcsetattr(0, TCSAFLUSH, &save);
982 free(pollfds);
983 return err; 979 return err;
984} 980}
985 981