Skip to contentSkip to conversation

perf tools: Do not set O_NONBLOCK flag for perf event fd

PATCH In review Jiri Olsa 4 participants 11 messages Oct 1, 2014 – Oct 15, 2014 1 message not in the archive perf events

lore
Share & tools
lore

Jiri Olsa

author reviewer
#0 lore raw

PATCH 1/5 perf tools: Do not set O_NONBLOCK flag for perf event fd

We don't need O_NONBLOCK flag on perf event file descriptors.

Aside the fact that file descriptors in evlist::pollfd are never used in read syscall (write syscall is not supported), the kernel perf read syscall path could never block anyway.

Cc Adrian Hunter <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Corey Ashford <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Milian Wolff <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 tools/perf/util/evlist.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
tools/perf/util/evlist.c +1 -4
index 3cebc9a8d52e..0fbc5f082308 100644
@@ -434,12 +434,9 @@ static int __perf_evlist__add_pollfd(struct perf_evlist *evlist, int fd, int idx
 	 * Save the idx so that when we filter out fds POLLHUP'ed we can
 	 * close the associated evlist->mmap[] entry.
 	 */
-	if (pos >= 0) {
+	if (pos >= 0)
 		evlist->pollfd.priv[pos].idx = idx;
 
-		fcntl(fd, F_SETFL, O_NONBLOCK);
-	}
-
 	return pos;
 }
 
Signature · 1 line
1.9.3
author reviewer
#1 lore raw

PATCH 2/5 perf tools: Move callchain_param to util object in to fix python test

In following commit we changed the location of callchains data:
b016b5ba554b perf tools: Move callchain config from record_opts to callchain_param

Now all callchains stuff stays in callchain_param struct, which adds its dependency for evsel.c object and breaks python perf.so usage (unresolved callchain_param).

Moving callchain_param into callchain.c and adding it into python-ext-sources unleash just another dependency hell, so I ended up adding callchain_param into util.c for now.

Cc Adrian Hunter <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Corey Ashford <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Milian Wolff <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 tools/perf/util/hist.c | 7 -------
 tools/perf/util/util.c | 8 ++++++++
 2 files changed, 8 insertions(+), 7 deletions(-)
tools/perf/util/hist.c +0 -7
index 86569fa3651d..b47595697140 100644
@@ -14,13 +14,6 @@ static bool hists__filter_entry_by_thread(struct hists *hists,
 static bool hists__filter_entry_by_symbol(struct hists *hists,
 					  struct hist_entry *he);
 
-struct callchain_param	callchain_param = {
-	.mode	= CHAIN_GRAPH_REL,
-	.min_percent = 0.5,
-	.order  = ORDER_CALLEE,
-	.key	= CCKEY_FUNCTION
-};
-
 u16 hists__col_len(struct hists *hists, enum hist_column col)
 {
 	return hists->col_len[col];
tools/perf/util/util.c +8 -0
index 24e8d871b74e..d5eab3f3323f 100644
@@ -14,6 +14,14 @@
 #include <byteswap.h>
 #include <linux/kernel.h>
 #include <unistd.h>
+#include "callchain.h"
+
+struct callchain_param	callchain_param = {
+	.mode	= CHAIN_GRAPH_REL,
+	.min_percent = 0.5,
+	.order  = ORDER_CALLEE,
+	.key	= CCKEY_FUNCTION
+};
 
 /*
  * XXX We need to find a better place for these things...
Signature · 1 line
1.9.3

A message that is not in the archive (sent off-list or not yet received): [email protected]

#3 lore raw

Re: [PATCH 2/5] perf tools: Move callchain_param to util object in to fix python test

Quoted 8 lines · Arnaldo Carvalho de Melo

Em Wed, Oct 01, 2014 at 06:00:26PM +0200, Jiri Olsa escreveu:

Quoted 7 lines

In following commit we changed the location of callchains data:
b016b5ba554b perf tools: Move callchain config from record_opts to callchain_param

Now all callchains stuff stays in callchain_param struct, which adds its dependency for evsel.c object and breaks python perf.so usage (unresolved callchain_param).

Quoted 5 lines
Quoted 3 lines

Moving callchain_param into callchain.c and adding it into python-ext-sources unleash just another dependency hell, so I ended up adding callchain_param into util.c for now.

Against what branch is the patch? I am not finding b016b5ba554b in none

[jolsa@krava perf]$ git describe --contains b016b5ba554b
fatal: cannot describe 'b016b5ba554ba38c74241ef8739f8fde8878d3eb' [jolsa@krava perf]$ git show --oneline b016b5ba554b | head -1 b016b5ba554b perf tools: Move callchain config from record_opts to callchain_param [jolsa@krava perf]$ git show 72a128aa083a > /tmp/p
[jolsa@krava perf]$ git show b016b5ba554b > /tmp/p1
[jolsa@krava perf]$ diff -puw /tmp/p /tmp/p1

tmp/p1 2014-10-02 17:06:26.035946113 +0200 renamed from tmp/p 2014-10-02 17:06:20.072958720 +0200 +1 -1
@@ -1,4 +1,4 @@
-commit 72a128aa083a7f4cc4f800718aaae05d9c698e26
+commit b016b5ba554ba38c74241ef8739f8fde8878d3eb
 Author: Namhyung Kim <[email protected]>
 Date:   Tue Sep 23 10:01:41 2014 +0900
 

I guess I took some version before your rebase

Quoted 6 lines

of the branches in my linux git repo and the python 'perf test' entry works as expected:

[root@zoo ~]# perf test python
17: Try 'use perf' in python, checking link problems : Ok
[root@zoo ~]#

hum.. yours acme/perf/core is failing for me:

[jolsa@krava perf]$ ./perf test python
17: Try 'use perf' in python, checking link problems : FAILED!
[jolsa@krava perf]$ git show --oneline HEAD | head -1
281f92f233a5 perf record: Fix error message for --filter option not coming after tracepoint

maybe you need 'make clean && make' ?

jirka

Quoted 64 lines

- Arnaldo

Quoted 61 lines
Cc Adrian Hunter <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Corey Ashford <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Milian Wolff <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 tools/perf/util/hist.c | 7 -------
 tools/perf/util/util.c | 8 ++++++++
 2 files changed, 8 insertions(+), 7 deletions(-)
tools/perf/util/hist.c +0 -7
index 86569fa3651d..b47595697140 100644
@@ -14,13 +14,6 @@ static bool hists__filter_entry_by_thread(struct hists *hists,
 static bool hists__filter_entry_by_symbol(struct hists *hists,
 					  struct hist_entry *he);
 
-struct callchain_param	callchain_param = {
-	.mode	= CHAIN_GRAPH_REL,
-	.min_percent = 0.5,
-	.order  = ORDER_CALLEE,
-	.key	= CCKEY_FUNCTION
-};
-
 u16 hists__col_len(struct hists *hists, enum hist_column col)
 {
 	return hists->col_len[col];
tools/perf/util/util.c +8 -0
index 24e8d871b74e..d5eab3f3323f 100644
@@ -14,6 +14,14 @@
 #include <byteswap.h>
 #include <linux/kernel.h>
 #include <unistd.h>
+#include "callchain.h"
+
+struct callchain_param	callchain_param = {
+	.mode	= CHAIN_GRAPH_REL,
+	.min_percent = 0.5,
+	.order  = ORDER_CALLEE,
+	.key	= CCKEY_FUNCTION
+};
 
 /*
  * XXX We need to find a better place for these things...
Signature · 7 lines
1.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/
#4 lore raw

Re: [PATCH 2/5] perf tools: Move callchain_param to util object in to fix python test

Em Thu, Oct 02, 2014 at 05:08:27PM +0200, Jiri Olsa escreveu:

Quoted 40 lines · Arnaldo Carvalho de Melo
Quoted 8 lines

Em Wed, Oct 01, 2014 at 06:00:26PM +0200, Jiri Olsa escreveu:

Quoted 7 lines

In following commit we changed the location of callchains data:
b016b5ba554b perf tools: Move callchain config from record_opts to callchain_param

Now all callchains stuff stays in callchain_param struct, which adds its dependency for evsel.c object and breaks python perf.so usage (unresolved callchain_param).

Quoted 5 lines
Quoted 3 lines

Moving callchain_param into callchain.c and adding it into python-ext-sources unleash just another dependency hell, so I ended up adding callchain_param into util.c for now.

Against what branch is the patch? I am not finding b016b5ba554b in none

[jolsa@krava perf]$ git describe --contains b016b5ba554b
fatal: cannot describe 'b016b5ba554ba38c74241ef8739f8fde8878d3eb' [jolsa@krava perf]$ git show --oneline b016b5ba554b | head -1 b016b5ba554b perf tools: Move callchain config from record_opts to callchain_param [jolsa@krava perf]$ git show 72a128aa083a > /tmp/p
[jolsa@krava perf]$ git show b016b5ba554b > /tmp/p1
[jolsa@krava perf]$ diff -puw /tmp/p /tmp/p1

tmp/p1 2014-10-02 17:06:26.035946113 +0200 renamed from tmp/p 2014-10-02 17:06:20.072958720 +0200 +1 -1
@@ -1,4 +1,4 @@
-commit 72a128aa083a7f4cc4f800718aaae05d9c698e26
+commit b016b5ba554ba38c74241ef8739f8fde8878d3eb
 Author: Namhyung Kim <[email protected]>
 Date:   Tue Sep 23 10:01:41 2014 +0900
 

I guess I took some version before your rebase

Quoted 6 lines

of the branches in my linux git repo and the python 'perf test' entry works as expected:

[root@zoo ~]# perf test python
17: Try 'use perf' in python, checking link problems : Ok
[root@zoo ~]#

Quoted 8 lines

hum.. yours acme/perf/core is failing for me:

[jolsa@krava perf]$ ./perf test python
17: Try 'use perf' in python, checking link problems : FAILED!
[jolsa@krava perf]$ git show --oneline HEAD | head -1
281f92f233a5 perf record: Fix error message for --filter option not coming after tracepoint

maybe you need 'make clean && make' ?

Yeap, I somehow thought that I had that covered :-\

Reproduced, yeah, 72a128aa083a7f4cc4f800718aaae05d9c698e26 is in, and I'll take your patch, thanks.

Will update the comment to refer to the right cset.

- Arnaldo

#5 lore raw

[tip:perf/urgent] perf callchain: Move callchain_param to util object in to fix python test

In reply to Jiri Olsa
perf callchain: Move callchain_param to util object in to fix python test
Commit-ID:  23aadb1fcda27e79a134ec35a7fb68f243269bcb
Gitweb:     http://git.kernel.org/tip/23aadb1fcda27e79a134ec35a7fb68f243269bcb
Author:     Jiri Olsa <[email protected]>
AuthorDate: Wed, 1 Oct 2014 18:00:26 +0200
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 3 Oct 2014 09:39:48 -0300

perf callchain: Move callchain_param to util object in to fix python test

In following commit we changed the location of callchains data:

72a128aa083a7f4cc4f800718aaae05d9c698e26
perf tools: Move callchain config from record_opts to callchain_param

Now all callchains stuff stays in callchain_param struct, which adds its dependency for evsel.c object and breaks python perf.so usage (unresolved callchain_param).

Moving callchain_param into callchain.c and adding it into python-ext-sources unleash just another dependency hell, so I ended up adding callchain_param into util.c for now.

Cc Adrian Hunter <[email protected]>
Cc Corey Ashford <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Milian Wolff <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 tools/perf/util/hist.c | 7 -------
 tools/perf/util/util.c | 8 ++++++++
 2 files changed, 8 insertions(+), 7 deletions(-)
tools/perf/util/hist.c +0 -7
index 86569fa..b475956 100644
@@ -14,13 +14,6 @@ static bool hists__filter_entry_by_thread(struct hists *hists,
 static bool hists__filter_entry_by_symbol(struct hists *hists,
 					  struct hist_entry *he);
 
-struct callchain_param	callchain_param = {
-	.mode	= CHAIN_GRAPH_REL,
-	.min_percent = 0.5,
-	.order  = ORDER_CALLEE,
-	.key	= CCKEY_FUNCTION
-};
-
 u16 hists__col_len(struct hists *hists, enum hist_column col)
 {
 	return hists->col_len[col];
tools/perf/util/util.c +8 -0
index 24e8d87..d5eab3f 100644
@@ -14,6 +14,14 @@
 #include <byteswap.h>
 #include <linux/kernel.h>
 #include <unistd.h>
+#include "callchain.h"
+
+struct callchain_param	callchain_param = {
+	.mode	= CHAIN_GRAPH_REL,
+	.min_percent = 0.5,
+	.order  = ORDER_CALLEE,
+	.key	= CCKEY_FUNCTION
+};
 
 /*
  * XXX We need to find a better place for these things...
author reviewer
#6 lore raw

PATCH 3/5 perf kvm stat live: Fix perf_evlist__add_pollfd error handling

In reply to Jiri Olsa

With the interface changed in following commit:
2171a9256862 tools lib fd array: Allow associating an integer cookie with each entry
the perf_evlist__add_pollfd function now returns the fd
position in the pollfd array.

We need to change this function's error check condition.

Cc Adrian Hunter <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Corey Ashford <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Milian Wolff <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 tools/perf/builtin-kvm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/builtin-kvm.c +2 -2
index d8bf2271f4ea..663d6eda0822 100644
@@ -928,12 +928,12 @@ static int kvm_events_live_report(struct perf_kvm_stat *kvm)
 		goto out;
 	}
 
-	if (perf_evlist__add_pollfd(kvm->evlist, kvm->timerfd))
+	if (perf_evlist__add_pollfd(kvm->evlist, kvm->timerfd) < 0)
 		goto out;
 
 	nr_fds++;
 
-	if (perf_evlist__add_pollfd(kvm->evlist, fileno(stdin)))
+	if (perf_evlist__add_pollfd(kvm->evlist, fileno(stdin)) < 0)
 		goto out;
 
 	nr_stdin = nr_fds;
Signature · 1 line
1.9.3
#7 lore raw

[tip:perf/urgent] perf kvm stat live: Fix perf_evlist__add_pollfd error handling

perf kvm stat live: Fix perf_evlist__add_pollfd error handling
Commit-ID:  fe636adda6caff6022e61b37202495dbf68e1410
Gitweb:     http://git.kernel.org/tip/fe636adda6caff6022e61b37202495dbf68e1410
Author:     Jiri Olsa <[email protected]>
AuthorDate: Wed, 1 Oct 2014 18:00:27 +0200
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 3 Oct 2014 09:39:47 -0300

perf kvm stat live: Fix perf_evlist__add_pollfd error handling

With the interface changed in following commit:

2171a9256862 tools lib fd array: Allow associating an integer cookie with each entry

the perf_evlist__add_pollfd function now returns the fd position in the pollfd array.

We need to change this function's error check condition.

Cc Adrian Hunter <[email protected]>
Cc Corey Ashford <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Milian Wolff <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 tools/perf/builtin-kvm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/builtin-kvm.c +2 -2
index d8bf227..663d6ed 100644
@@ -928,12 +928,12 @@ static int kvm_events_live_report(struct perf_kvm_stat *kvm)
 		goto out;
 	}
 
-	if (perf_evlist__add_pollfd(kvm->evlist, kvm->timerfd))
+	if (perf_evlist__add_pollfd(kvm->evlist, kvm->timerfd) < 0)
 		goto out;
 
 	nr_fds++;
 
-	if (perf_evlist__add_pollfd(kvm->evlist, fileno(stdin)))
+	if (perf_evlist__add_pollfd(kvm->evlist, fileno(stdin)) < 0)
 		goto out;
 
 	nr_stdin = nr_fds;
author reviewer
#8 lore raw

PATCH 4/5 perf kvm stat live: Use perf_evlist__add_pollfd return fd position

In reply to Jiri Olsa

With the interface changed in following commit:
2171a9256862 tools lib fd array: Allow associating an integer cookie with each entry
the perf_evlist__add_pollfd function now returns the
fd position in the pollfd array.

Hence we no longer need to count the fd position, because we get it as the return value.

Cc Adrian Hunter <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Corey Ashford <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Milian Wolff <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 tools/perf/builtin-kvm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/builtin-kvm.c +2 -2
index 663d6eda0822..dc7d704735bd 100644
@@ -933,10 +933,10 @@ static int kvm_events_live_report(struct perf_kvm_stat *kvm)
 
 	nr_fds++;
 
-	if (perf_evlist__add_pollfd(kvm->evlist, fileno(stdin)) < 0)
+	nr_stdin = perf_evlist__add_pollfd(kvm->evlist, fileno(stdin));
+	if (nr_stdin < 0)
 		goto out;
 
-	nr_stdin = nr_fds;
 	nr_fds++;
 	if (fd_set_nonblock(fileno(stdin)) != 0)
 		goto out;
Signature · 1 line
1.9.3
#9 lore raw

[tip:perf/urgent] perf kvm stat live: Use perf_evlist__add_pollfd return fd position

perf kvm stat live: Use perf_evlist__add_pollfd return fd position
Commit-ID:  0cae013cf4450ea0ecb62241a2f3e7565db09f93
Gitweb:     http://git.kernel.org/tip/0cae013cf4450ea0ecb62241a2f3e7565db09f93
Author:     Jiri Olsa <[email protected]>
AuthorDate: Wed, 1 Oct 2014 18:00:28 +0200
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 3 Oct 2014 09:39:48 -0300

perf kvm stat live: Use perf_evlist__add_pollfd return fd position

With the interface changed in following commit:

2171a9256862 tools lib fd array: Allow associating an integer cookie with each entry

the perf_evlist__add_pollfd function now returns the fd position in the pollfd array.

Hence we no longer need to count the fd position, because we get it as the return value.

Cc Adrian Hunter <[email protected]>
Cc Corey Ashford <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Milian Wolff <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 tools/perf/builtin-kvm.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
tools/perf/builtin-kvm.c +2 -2
index 663d6ed..dc7d704 100644
@@ -933,10 +933,10 @@ static int kvm_events_live_report(struct perf_kvm_stat *kvm)
 
 	nr_fds++;
 
-	if (perf_evlist__add_pollfd(kvm->evlist, fileno(stdin)) < 0)
+	nr_stdin = perf_evlist__add_pollfd(kvm->evlist, fileno(stdin));
+	if (nr_stdin < 0)
 		goto out;
 
-	nr_stdin = nr_fds;
 	nr_fds++;
 	if (fd_set_nonblock(fileno(stdin)) != 0)
 		goto out;
author reviewer
#10 lore raw

PATCH 5/5 perf kvm stat live: Use fdarray object instead pollfd

In reply to Jiri Olsa

The reason is that we don't need to count the number of file descriptors because it's already handled in fdarray object.

Cc Adrian Hunter <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
Cc Corey Ashford <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Milian Wolff <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 tools/perf/builtin-kvm.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
tools/perf/builtin-kvm.c +4 -12
index dc7d704735bd..460a4ce9c044 100644
@@ -896,8 +896,7 @@ static int perf_kvm__handle_stdin(void)
 
 static int kvm_events_live_report(struct perf_kvm_stat *kvm)
 {
-	struct pollfd *pollfds = NULL;
-	int nr_fds, nr_stdin, ret, err = -EINVAL;
+	int nr_stdin, ret, err = -EINVAL;
 	struct termios save;
 
 	/* live flag must be set first */
@@ -919,9 +918,6 @@ static int kvm_events_live_report(struct perf_kvm_stat *kvm)
 	signal(SIGINT, sig_handler);
 	signal(SIGTERM, sig_handler);
 
-	/* use pollfds -- need to add timerfd and stdin */
-	nr_fds = kvm->evlist->pollfd.nr;
-
 	/* add timer fd */
 	if (perf_kvm__timerfd_create(kvm) < 0) {
 		err = -1;
@@ -931,22 +927,18 @@ static int kvm_events_live_report(struct perf_kvm_stat *kvm)
 	if (perf_evlist__add_pollfd(kvm->evlist, kvm->timerfd) < 0)
 		goto out;
 
-	nr_fds++;
-
 	nr_stdin = perf_evlist__add_pollfd(kvm->evlist, fileno(stdin));
 	if (nr_stdin < 0)
 		goto out;
 
-	nr_fds++;
 	if (fd_set_nonblock(fileno(stdin)) != 0)
 		goto out;
 
-	pollfds	 = kvm->evlist->pollfd.entries;
-
 	/* everything is good - enable the events and process */
 	perf_evlist__enable(kvm->evlist);
 
 	while (!done) {
+		struct fdarray *fda = &kvm->evlist->pollfd;
 		int rc;
 
 		rc = perf_kvm__mmap_read(kvm);
@@ -957,11 +949,11 @@ static int kvm_events_live_report(struct perf_kvm_stat *kvm)
 		if (err)
 			goto out;
 
-		if (pollfds[nr_stdin].revents & POLLIN)
+		if (fda->entries[nr_stdin].revents & POLLIN)
 			done = perf_kvm__handle_stdin();
 
 		if (!rc && !done)
-			err = poll(pollfds, nr_fds, 100);
+			err = fdarray__poll(fda, 100);
 	}
 
 	perf_evlist__disable(kvm->evlist);
Signature · 1 line
1.9.3
#11 lore raw

[tip:perf/urgent] perf kvm stat live: Use fdarray object instead of pollfd

perf kvm stat live: Use fdarray object instead of pollfd
Commit-ID:  1ca72260e471a8b03f03fe9a6547deb088710042
Gitweb:     http://git.kernel.org/tip/1ca72260e471a8b03f03fe9a6547deb088710042
Author:     Jiri Olsa <[email protected]>
AuthorDate: Wed, 1 Oct 2014 18:00:29 +0200
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 3 Oct 2014 09:39:48 -0300

perf kvm stat live: Use fdarray object instead of pollfd

The reason is that we don't need to count the number of file descriptors because it's already handled in fdarray object.

Cc Adrian Hunter <[email protected]>
Cc Corey Ashford <[email protected]>
Cc David Ahern <[email protected]>
Cc Frederic Weisbecker <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Milian Wolff <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Paul Mackerras <[email protected]>
Cc Peter Zijlstra <[email protected]>
---
 tools/perf/builtin-kvm.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
tools/perf/builtin-kvm.c +4 -12
index dc7d704..460a4ce 100644
@@ -896,8 +896,7 @@ static int perf_kvm__handle_stdin(void)
 
 static int kvm_events_live_report(struct perf_kvm_stat *kvm)
 {
-	struct pollfd *pollfds = NULL;
-	int nr_fds, nr_stdin, ret, err = -EINVAL;
+	int nr_stdin, ret, err = -EINVAL;
 	struct termios save;
 
 	/* live flag must be set first */
@@ -919,9 +918,6 @@ static int kvm_events_live_report(struct perf_kvm_stat *kvm)
 	signal(SIGINT, sig_handler);
 	signal(SIGTERM, sig_handler);
 
-	/* use pollfds -- need to add timerfd and stdin */
-	nr_fds = kvm->evlist->pollfd.nr;
-
 	/* add timer fd */
 	if (perf_kvm__timerfd_create(kvm) < 0) {
 		err = -1;
@@ -931,22 +927,18 @@ static int kvm_events_live_report(struct perf_kvm_stat *kvm)
 	if (perf_evlist__add_pollfd(kvm->evlist, kvm->timerfd) < 0)
 		goto out;
 
-	nr_fds++;
-
 	nr_stdin = perf_evlist__add_pollfd(kvm->evlist, fileno(stdin));
 	if (nr_stdin < 0)
 		goto out;
 
-	nr_fds++;
 	if (fd_set_nonblock(fileno(stdin)) != 0)
 		goto out;
 
-	pollfds	 = kvm->evlist->pollfd.entries;
-
 	/* everything is good - enable the events and process */
 	perf_evlist__enable(kvm->evlist);
 
 	while (!done) {
+		struct fdarray *fda = &kvm->evlist->pollfd;
 		int rc;
 
 		rc = perf_kvm__mmap_read(kvm);
@@ -957,11 +949,11 @@ static int kvm_events_live_report(struct perf_kvm_stat *kvm)
 		if (err)
 			goto out;
 
-		if (pollfds[nr_stdin].revents & POLLIN)
+		if (fda->entries[nr_stdin].revents & POLLIN)
 			done = perf_kvm__handle_stdin();
 
 		if (!rc && !done)
-			err = poll(pollfds, nr_fds, 100);
+			err = fdarray__poll(fda, 100);
 	}
 
 	perf_evlist__disable(kvm->evlist);