[tip:perf/urgent] perf bench numa: Fix cpu0 binding

2019-08-08 Thread tip-bot for Jiri Olsa
Commit-ID:  6bbfe4e602691b90ac866712bd4c43c51e546a60
Gitweb: https://git.kernel.org/tip/6bbfe4e602691b90ac866712bd4c43c51e546a60
Author: Jiri Olsa 
AuthorDate: Thu, 1 Aug 2019 16:26:42 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Thu, 1 Aug 2019 11:34:13 -0300

perf bench numa: Fix cpu0 binding

Michael reported an issue with perf bench numa failing with binding to
cpu0 with '-0' option.

  # perf bench numa mem -p 3 -t 1 -P 512 -s 100 -zZcm0 --thp 1 -M 1 -ddd
  # Running 'numa/mem' benchmark:

   # Running main, "perf bench numa numa-mem -p 3 -t 1 -P 512 -s 100 -zZcm0 
--thp 1 -M 1 -ddd"
  binding to node 0, mask: 0001 => -1
  perf: bench/numa.c:356: bind_to_memnode: Assertion `!(ret)' failed.
  Aborted (core dumped)

This happens when the cpu0 is not part of node0, which is the benchmark
assumption and we can see that's not the case for some powerpc servers.

Using correct node for cpu0 binding.

Reported-by: Michael Petlan 
Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Andi Kleen 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Satheesh Rajendran 
Link: http://lkml.kernel.org/r/20190801142642.28004-1-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/bench/numa.c | 6 --
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/perf/bench/numa.c b/tools/perf/bench/numa.c
index a640ca7aaada..513cb2f2fa32 100644
--- a/tools/perf/bench/numa.c
+++ b/tools/perf/bench/numa.c
@@ -379,8 +379,10 @@ static u8 *alloc_data(ssize_t bytes0, int map_flags,
 
/* Allocate and initialize all memory on CPU#0: */
if (init_cpu0) {
-   orig_mask = bind_to_node(0);
-   bind_to_memnode(0);
+   int node = numa_node_of_cpu(0);
+
+   orig_mask = bind_to_node(node);
+   bind_to_memnode(node);
}
 
bytes = bytes0 + HPSIZE;


[tip:perf/core] libperf: Initial documentation

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  f4f48e9c1adb49f732ac0abc4b2513f2b62a10cb
Gitweb: https://git.kernel.org/tip/f4f48e9c1adb49f732ac0abc4b2513f2b62a10cb
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:25:06 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:47 -0300

libperf: Initial documentation

Add initial drafts of documentation files, hugely unfinished.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-80-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/Documentation/Makefile  |   7 ++
 tools/perf/lib/Documentation/man/libperf.rst   | 100 +
 tools/perf/lib/Documentation/tutorial/tutorial.rst | 123 +
 3 files changed, 230 insertions(+)

diff --git a/tools/perf/lib/Documentation/Makefile 
b/tools/perf/lib/Documentation/Makefile
new file mode 100644
index ..586425a88795
--- /dev/null
+++ b/tools/perf/lib/Documentation/Makefile
@@ -0,0 +1,7 @@
+all:
+   rst2man man/libperf.rst > man/libperf.7
+   rst2pdf tutorial/tutorial.rst
+
+clean:
+   rm -f man/libperf.7
+   rm -f tutorial/tutorial.pdf
diff --git a/tools/perf/lib/Documentation/man/libperf.rst 
b/tools/perf/lib/Documentation/man/libperf.rst
new file mode 100644
index ..09a270fccb9c
--- /dev/null
+++ b/tools/perf/lib/Documentation/man/libperf.rst
@@ -0,0 +1,100 @@
+.. SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
+
+libperf
+
+The libperf library provides an API to access the linux kernel perf
+events subsystem. It provides the following high level objects:
+
+  - struct perf_cpu_map
+  - struct perf_thread_map
+  - struct perf_evlist
+  - struct perf_evsel
+
+reference
+=
+Function reference by header files:
+
+perf/core.h
+---
+.. code-block:: c
+
+  typedef int (\*libperf_print_fn_t)(enum libperf_print_level level,
+ const char \*, va_list ap);
+
+  void libperf_set_print(libperf_print_fn_t fn);
+
+perf/cpumap.h
+-
+.. code-block:: c
+
+  struct perf_cpu_map \*perf_cpu_map__dummy_new(void);
+  struct perf_cpu_map \*perf_cpu_map__new(const char \*cpu_list);
+  struct perf_cpu_map \*perf_cpu_map__read(FILE \*file);
+  struct perf_cpu_map \*perf_cpu_map__get(struct perf_cpu_map \*map);
+  void perf_cpu_map__put(struct perf_cpu_map \*map);
+  int perf_cpu_map__cpu(const struct perf_cpu_map \*cpus, int idx);
+  int perf_cpu_map__nr(const struct perf_cpu_map \*cpus);
+  perf_cpu_map__for_each_cpu(cpu, idx, cpus)
+
+perf/threadmap.h
+
+.. code-block:: c
+
+  struct perf_thread_map \*perf_thread_map__new_dummy(void);
+  void perf_thread_map__set_pid(struct perf_thread_map \*map, int thread, 
pid_t pid);
+  char \*perf_thread_map__comm(struct perf_thread_map \*map, int thread);
+  struct perf_thread_map \*perf_thread_map__get(struct perf_thread_map \*map);
+  void perf_thread_map__put(struct perf_thread_map \*map);
+
+perf/evlist.h
+-
+.. code-block::
+
+  void perf_evlist__init(struct perf_evlist \*evlist);
+  void perf_evlist__add(struct perf_evlist \*evlist,
+  struct perf_evsel \*evsel);
+  void perf_evlist__remove(struct perf_evlist \*evlist,
+ struct perf_evsel \*evsel);
+  struct perf_evlist \*perf_evlist__new(void);
+  void perf_evlist__delete(struct perf_evlist \*evlist);
+  struct perf_evsel\* perf_evlist__next(struct perf_evlist \*evlist,
+ struct perf_evsel \*evsel);
+  int perf_evlist__open(struct perf_evlist \*evlist);
+  void perf_evlist__close(struct perf_evlist \*evlist);
+  void perf_evlist__enable(struct perf_evlist \*evlist);
+  void perf_evlist__disable(struct perf_evlist \*evlist);
+  perf_evlist__for_each_evsel(evlist, pos)
+  void perf_evlist__set_maps(struct perf_evlist \*evlist,
+   struct perf_cpu_map \*cpus,
+   struct perf_thread_map \*threads);
+
+perf/evsel.h
+
+.. code-block:: c
+
+  struct perf_counts_values {
+union {
+struct {
+uint64_t val;
+uint64_t ena;
+uint64_t run;
+};
+uint64_t values[3];
+};
+  };
+
+  void perf_evsel__init(struct perf_evsel \*evsel,
+  struct perf_event_attr \*attr);
+  struct perf_evsel \*perf_evsel__new(struct perf_event_attr \*attr);
+  void perf_evsel__delete(struct perf_evsel \*evsel);
+  int perf_evsel__open(struct perf_evsel \*evsel, struct perf_cpu_map \*cpus,
+ struct perf_thread_map \*threads);
+  void perf_evsel__close(struct perf_evsel \*evsel);
+  int perf_evsel__read(struct perf_evsel \*evsel, int cpu, int thread,
+ struct perf_counts_values \*count);
+  int 

[tip:perf/core] libperf: Add perf_evsel__enable/disable test

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  02266a2d9cf7e04bf3d4b4457654839dc253f605
Gitweb: https://git.kernel.org/tip/02266a2d9cf7e04bf3d4b4457654839dc253f605
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:25:05 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:47 -0300

libperf: Add perf_evsel__enable/disable test

Add simple perf_evsel enable/disable test together with evsel counter
reading interface.

Committer testing:

  # make -C tools/perf/lib tests
  make: Entering directory '/home/acme/git/perf/tools/perf/lib'
LINK test-cpumap-a
LINK test-threadmap-a
LINK test-evlist-a
LINK test-evsel-a
LINK test-cpumap-so
LINK test-threadmap-so
LINK test-evlist-so
LINK test-evsel-so
  running static:
  - running test-cpumap.c...OK
  - running test-threadmap.c...OK
  - running test-evlist.c...OK
  - running test-evsel.c...OK
  running dynamic:
  - running test-cpumap.c...OK
  - running test-threadmap.c...OK
  - running test-evlist.c...OK
  - running test-evsel.c...OK
  make: Leaving directory '/home/acme/git/perf/tools/perf/lib'
  #

Signed-off-by: Jiri Olsa 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-79-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/tests/test-evsel.c | 43 +++
 1 file changed, 43 insertions(+)

diff --git a/tools/perf/lib/tests/test-evsel.c 
b/tools/perf/lib/tests/test-evsel.c
index 268712292f60..2c648fe5617e 100644
--- a/tools/perf/lib/tests/test-evsel.c
+++ b/tools/perf/lib/tests/test-evsel.c
@@ -70,12 +70,55 @@ static int test_stat_thread(void)
return 0;
 }
 
+static int test_stat_thread_enable(void)
+{
+   struct perf_counts_values counts = { .val = 0 };
+   struct perf_thread_map *threads;
+   struct perf_evsel *evsel;
+   struct perf_event_attr attr = {
+   .type = PERF_TYPE_SOFTWARE,
+   .config   = PERF_COUNT_SW_TASK_CLOCK,
+   .disabled = 1,
+   };
+   int err;
+
+   threads = perf_thread_map__new_dummy();
+   __T("failed to create threads", threads);
+
+   perf_thread_map__set_pid(threads, 0, 0);
+
+   evsel = perf_evsel__new();
+   __T("failed to create evsel", evsel);
+
+   err = perf_evsel__open(evsel, NULL, threads);
+   __T("failed to open evsel", err == 0);
+
+   perf_evsel__read(evsel, 0, 0, );
+   __T("failed to read value for evsel", counts.val == 0);
+
+   err = perf_evsel__enable(evsel);
+   __T("failed to enable evsel", err == 0);
+
+   perf_evsel__read(evsel, 0, 0, );
+   __T("failed to read value for evsel", counts.val != 0);
+
+   err = perf_evsel__disable(evsel);
+   __T("failed to enable evsel", err == 0);
+
+   perf_evsel__close(evsel);
+   perf_evsel__delete(evsel);
+
+   perf_thread_map__put(threads);
+   return 0;
+}
+
 int main(int argc, char **argv)
 {
__T_START;
 
test_stat_cpu();
test_stat_thread();
+   test_stat_thread_enable();
 
__T_OK;
return 0;


[tip:perf/core] libperf: Add perf_evlist__enable/disable test

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  6bda376ff416cf713773d38b743953a1a9bc0603
Gitweb: https://git.kernel.org/tip/6bda376ff416cf713773d38b743953a1a9bc0603
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:25:04 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:47 -0300

libperf: Add perf_evlist__enable/disable test

Add simple perf_evlist enable/disable test together with evlist counter
reading interface.

Committer testing:

  # make -C tools/perf/lib tests
  make: Entering directory '/home/acme/git/perf/tools/perf/lib'
LINK test-cpumap-a
LINK test-threadmap-a
LINK test-evlist-a
LINK test-evsel-a
LINK test-cpumap-so
LINK test-threadmap-so
LINK test-evlist-so
LINK test-evsel-so
  running static:
  - running test-cpumap.c...OK
  - running test-threadmap.c...OK
  - running test-evlist.c...OK
  - running test-evsel.c...OK
  running dynamic:
  - running test-cpumap.c...OK
  - running test-threadmap.c...OK
  - running test-evlist.c...OK
  - running test-evsel.c...OK
  make: Leaving directory '/home/acme/git/perf/tools/perf/lib'
  #

Signed-off-by: Jiri Olsa 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-78-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/tests/test-evlist.c | 63 ++
 1 file changed, 63 insertions(+)

diff --git a/tools/perf/lib/tests/test-evlist.c 
b/tools/perf/lib/tests/test-evlist.c
index f24c531afcb6..4e1407f20ffd 100644
--- a/tools/perf/lib/tests/test-evlist.c
+++ b/tools/perf/lib/tests/test-evlist.c
@@ -111,12 +111,75 @@ static int test_stat_thread(void)
return 0;
 }
 
+static int test_stat_thread_enable(void)
+{
+   struct perf_counts_values counts = { .val = 0 };
+   struct perf_thread_map *threads;
+   struct perf_evlist *evlist;
+   struct perf_evsel *evsel;
+   struct perf_event_attr attr1 = {
+   .type = PERF_TYPE_SOFTWARE,
+   .config   = PERF_COUNT_SW_CPU_CLOCK,
+   .disabled = 1,
+   };
+   struct perf_event_attr attr2 = {
+   .type = PERF_TYPE_SOFTWARE,
+   .config   = PERF_COUNT_SW_TASK_CLOCK,
+   .disabled = 1,
+   };
+   int err;
+
+   threads = perf_thread_map__new_dummy();
+   __T("failed to create threads", threads);
+
+   perf_thread_map__set_pid(threads, 0, 0);
+
+   evlist = perf_evlist__new();
+   __T("failed to create evlist", evlist);
+
+   evsel = perf_evsel__new();
+   __T("failed to create evsel1", evsel);
+
+   perf_evlist__add(evlist, evsel);
+
+   evsel = perf_evsel__new();
+   __T("failed to create evsel2", evsel);
+
+   perf_evlist__add(evlist, evsel);
+
+   perf_evlist__set_maps(evlist, NULL, threads);
+
+   err = perf_evlist__open(evlist);
+   __T("failed to open evsel", err == 0);
+
+   perf_evlist__for_each_evsel(evlist, evsel) {
+   perf_evsel__read(evsel, 0, 0, );
+   __T("failed to read value for evsel", counts.val == 0);
+   }
+
+   perf_evlist__enable(evlist);
+
+   perf_evlist__for_each_evsel(evlist, evsel) {
+   perf_evsel__read(evsel, 0, 0, );
+   __T("failed to read value for evsel", counts.val != 0);
+   }
+
+   perf_evlist__disable(evlist);
+
+   perf_evlist__close(evlist);
+   perf_evlist__delete(evlist);
+
+   perf_thread_map__put(threads);
+   return 0;
+}
+
 int main(int argc, char **argv)
 {
__T_START;
 
test_stat_cpu();
test_stat_thread();
+   test_stat_thread_enable();
 
__T_OK;
return 0;


[tip:perf/core] libperf: Add perf_evsel tests

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  bb5133ae4d404a8a08d8a94dfdea1c477c93e842
Gitweb: https://git.kernel.org/tip/bb5133ae4d404a8a08d8a94dfdea1c477c93e842
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:25:03 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:47 -0300

libperf: Add perf_evsel tests

Add 2 simple perf_evsel tests to test counters reading interface through
the struct evsel object.

Committer testing:

  # make -C tools/perf/lib tests
  make: Entering directory '/home/acme/git/perf/tools/perf/lib'
LINK test-cpumap-a
LINK test-threadmap-a
LINK test-evlist-a
LINK test-evsel-a
LINK test-cpumap-so
LINK test-threadmap-so
LINK test-evlist-so
LINK test-evsel-so
  running static:
  - running test-cpumap.c...OK
  - running test-threadmap.c...OK
  - running test-evlist.c...OK
  - running test-evsel.c...OK
  running dynamic:
  - running test-cpumap.c...OK
  - running test-threadmap.c...OK
  - running test-evlist.c...OK
  - running test-evsel.c...OK
  make: Leaving directory '/home/acme/git/perf/tools/perf/lib'
  #

Signed-off-by: Jiri Olsa 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-77-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/tests/Makefile |  2 +-
 tools/perf/lib/tests/test-evsel.c | 82 +++
 2 files changed, 83 insertions(+), 1 deletion(-)

diff --git a/tools/perf/lib/tests/Makefile b/tools/perf/lib/tests/Makefile
index e66ed090f08e..1ee4e9ba848b 100644
--- a/tools/perf/lib/tests/Makefile
+++ b/tools/perf/lib/tests/Makefile
@@ -1,6 +1,6 @@
 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
 
-TESTS = test-cpumap test-threadmap test-evlist
+TESTS = test-cpumap test-threadmap test-evlist test-evsel
 
 TESTS_SO := $(addsuffix -so,$(TESTS))
 TESTS_A  := $(addsuffix -a,$(TESTS))
diff --git a/tools/perf/lib/tests/test-evsel.c 
b/tools/perf/lib/tests/test-evsel.c
new file mode 100644
index ..268712292f60
--- /dev/null
+++ b/tools/perf/lib/tests/test-evsel.c
@@ -0,0 +1,82 @@
+// SPDX-License-Identifier: GPL-2.0
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int test_stat_cpu(void)
+{
+   struct perf_cpu_map *cpus;
+   struct perf_evsel *evsel;
+   struct perf_event_attr attr = {
+   .type   = PERF_TYPE_SOFTWARE,
+   .config = PERF_COUNT_SW_CPU_CLOCK,
+   };
+   int err, cpu, tmp;
+
+   cpus = perf_cpu_map__new(NULL);
+   __T("failed to create cpus", cpus);
+
+   evsel = perf_evsel__new();
+   __T("failed to create evsel", evsel);
+
+   err = perf_evsel__open(evsel, cpus, NULL);
+   __T("failed to open evsel", err == 0);
+
+   perf_cpu_map__for_each_cpu(cpu, tmp, cpus) {
+   struct perf_counts_values counts = { .val = 0 };
+
+   perf_evsel__read(evsel, cpu, 0, );
+   __T("failed to read value for evsel", counts.val != 0);
+   }
+
+   perf_evsel__close(evsel);
+   perf_evsel__delete(evsel);
+
+   perf_cpu_map__put(cpus);
+   return 0;
+}
+
+static int test_stat_thread(void)
+{
+   struct perf_counts_values counts = { .val = 0 };
+   struct perf_thread_map *threads;
+   struct perf_evsel *evsel;
+   struct perf_event_attr attr = {
+   .type   = PERF_TYPE_SOFTWARE,
+   .config = PERF_COUNT_SW_TASK_CLOCK,
+   };
+   int err;
+
+   threads = perf_thread_map__new_dummy();
+   __T("failed to create threads", threads);
+
+   perf_thread_map__set_pid(threads, 0, 0);
+
+   evsel = perf_evsel__new();
+   __T("failed to create evsel", evsel);
+
+   err = perf_evsel__open(evsel, NULL, threads);
+   __T("failed to open evsel", err == 0);
+
+   perf_evsel__read(evsel, 0, 0, );
+   __T("failed to read value for evsel", counts.val != 0);
+
+   perf_evsel__close(evsel);
+   perf_evsel__delete(evsel);
+
+   perf_thread_map__put(threads);
+   return 0;
+}
+
+int main(int argc, char **argv)
+{
+   __T_START;
+
+   test_stat_cpu();
+   test_stat_thread();
+
+   __T_OK;
+   return 0;
+}


[tip:perf/core] libperf: Add perf_evlist test

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  8ded5425fa71e2f7f60eb59d64ecdba80582b641
Gitweb: https://git.kernel.org/tip/8ded5425fa71e2f7f60eb59d64ecdba80582b641
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:25:02 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:47 -0300

libperf: Add perf_evlist test

Add 2 simple perf_evlist tests to test counters reading interface
through the struct evlist object.

Committer testing:

  # make -C tools/perf/lib tests
  make: Entering directory '/home/acme/git/perf/tools/perf/lib'
LINK test-cpumap-a
LINK test-threadmap-a
LINK test-evlist-a
LINK test-cpumap-so
LINK test-threadmap-so
LINK test-evlist-so
  running static:
  - running test-cpumap.c...OK
  - running test-threadmap.c...OK
  - running test-evlist.c...OK
  running dynamic:
  - running test-cpumap.c...OK
  - running test-threadmap.c...OK
  - running test-evlist.c...OK
  make: Leaving directory '/home/acme/git/perf/tools/perf/lib'
  #

Signed-off-by: Jiri Olsa 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-76-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/tests/Makefile  |   2 +-
 tools/perf/lib/tests/test-evlist.c | 123 +
 2 files changed, 124 insertions(+), 1 deletion(-)

diff --git a/tools/perf/lib/tests/Makefile b/tools/perf/lib/tests/Makefile
index 5dc84003e3a7..e66ed090f08e 100644
--- a/tools/perf/lib/tests/Makefile
+++ b/tools/perf/lib/tests/Makefile
@@ -1,6 +1,6 @@
 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
 
-TESTS = test-cpumap test-threadmap
+TESTS = test-cpumap test-threadmap test-evlist
 
 TESTS_SO := $(addsuffix -so,$(TESTS))
 TESTS_A  := $(addsuffix -a,$(TESTS))
diff --git a/tools/perf/lib/tests/test-evlist.c 
b/tools/perf/lib/tests/test-evlist.c
new file mode 100644
index ..f24c531afcb6
--- /dev/null
+++ b/tools/perf/lib/tests/test-evlist.c
@@ -0,0 +1,123 @@
+// SPDX-License-Identifier: GPL-2.0
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static int test_stat_cpu(void)
+{
+   struct perf_cpu_map *cpus;
+   struct perf_evlist *evlist;
+   struct perf_evsel *evsel;
+   struct perf_event_attr attr1 = {
+   .type   = PERF_TYPE_SOFTWARE,
+   .config = PERF_COUNT_SW_CPU_CLOCK,
+   };
+   struct perf_event_attr attr2 = {
+   .type   = PERF_TYPE_SOFTWARE,
+   .config = PERF_COUNT_SW_TASK_CLOCK,
+   };
+   int err, cpu, tmp;
+
+   cpus = perf_cpu_map__new(NULL);
+   __T("failed to create cpus", cpus);
+
+   evlist = perf_evlist__new();
+   __T("failed to create evlist", evlist);
+
+   evsel = perf_evsel__new();
+   __T("failed to create evsel1", evsel);
+
+   perf_evlist__add(evlist, evsel);
+
+   evsel = perf_evsel__new();
+   __T("failed to create evsel2", evsel);
+
+   perf_evlist__add(evlist, evsel);
+
+   perf_evlist__set_maps(evlist, cpus, NULL);
+
+   err = perf_evlist__open(evlist);
+   __T("failed to open evsel", err == 0);
+
+   perf_evlist__for_each_evsel(evlist, evsel) {
+   cpus = perf_evsel__cpus(evsel);
+
+   perf_cpu_map__for_each_cpu(cpu, tmp, cpus) {
+   struct perf_counts_values counts = { .val = 0 };
+
+   perf_evsel__read(evsel, cpu, 0, );
+   __T("failed to read value for evsel", counts.val != 0);
+   }
+   }
+
+   perf_evlist__close(evlist);
+   perf_evlist__delete(evlist);
+
+   perf_cpu_map__put(cpus);
+   return 0;
+}
+
+static int test_stat_thread(void)
+{
+   struct perf_counts_values counts = { .val = 0 };
+   struct perf_thread_map *threads;
+   struct perf_evlist *evlist;
+   struct perf_evsel *evsel;
+   struct perf_event_attr attr1 = {
+   .type   = PERF_TYPE_SOFTWARE,
+   .config = PERF_COUNT_SW_CPU_CLOCK,
+   };
+   struct perf_event_attr attr2 = {
+   .type   = PERF_TYPE_SOFTWARE,
+   .config = PERF_COUNT_SW_TASK_CLOCK,
+   };
+   int err;
+
+   threads = perf_thread_map__new_dummy();
+   __T("failed to create threads", threads);
+
+   perf_thread_map__set_pid(threads, 0, 0);
+
+   evlist = perf_evlist__new();
+   __T("failed to create evlist", evlist);
+
+   evsel = perf_evsel__new();
+   __T("failed to create evsel1", evsel);
+
+   perf_evlist__add(evlist, evsel);
+
+   evsel = perf_evsel__new();
+   __T("failed to create evsel2", evsel);
+
+   perf_evlist__add(evlist, evsel);
+
+   perf_evlist__set_maps(evlist, NULL, threads);
+
+   err = perf_evlist__open(evlist);
+   __T("failed to open evsel", err == 0);
+
+   

[tip:perf/core] libperf: Add perf_thread_map test

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  43d6976365d5f90de487e8f9f49ab21775ae84f4
Gitweb: https://git.kernel.org/tip/43d6976365d5f90de487e8f9f49ab21775ae84f4
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:25:01 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:46 -0300

libperf: Add perf_thread_map test

Add simple perf_thread_map tests.

Committer testing:

  $ make O=/tmp/build/perf -C tools/perf/lib tests
  make: Entering directory '/home/acme/git/perf/tools/perf/lib'
LINK test-cpumap-a
LINK test-threadmap-a
LINK test-cpumap-so
LINK test-threadmap-so
  running static:
  - running test-cpumap.c...OK
  - running test-threadmap.c...OK
  running dynamic:
  - running test-cpumap.c...OK
  - running test-threadmap.c...OK
  make: Leaving directory '/home/acme/git/perf/tools/perf/lib'
  $

Signed-off-by: Jiri Olsa 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-75-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/tests/Makefile |  2 +-
 tools/perf/lib/tests/test-threadmap.c | 21 +
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/tools/perf/lib/tests/Makefile b/tools/perf/lib/tests/Makefile
index b72c8c47df61..5dc84003e3a7 100644
--- a/tools/perf/lib/tests/Makefile
+++ b/tools/perf/lib/tests/Makefile
@@ -1,6 +1,6 @@
 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
 
-TESTS = test-cpumap
+TESTS = test-cpumap test-threadmap
 
 TESTS_SO := $(addsuffix -so,$(TESTS))
 TESTS_A  := $(addsuffix -a,$(TESTS))
diff --git a/tools/perf/lib/tests/test-threadmap.c 
b/tools/perf/lib/tests/test-threadmap.c
new file mode 100644
index ..10a4f4cbbdd5
--- /dev/null
+++ b/tools/perf/lib/tests/test-threadmap.c
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0
+#include 
+#include 
+
+int main(int argc, char **argv)
+{
+   struct perf_thread_map *threads;
+
+   __T_START;
+
+   threads = perf_thread_map__new_dummy();
+   if (!threads)
+   return -1;
+
+   perf_thread_map__get(threads);
+   perf_thread_map__put(threads);
+   perf_thread_map__put(threads);
+
+   __T_OK;
+   return 0;
+}


[tip:perf/core] libperf: Add perf_cpu_map test

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  c0e730456ae8a864701f5ca4f6c2e23010e4b04a
Gitweb: https://git.kernel.org/tip/c0e730456ae8a864701f5ca4f6c2e23010e4b04a
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:25:00 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:46 -0300

libperf: Add perf_cpu_map test

Add simple perf_cpu_map tests.

Committer testing:

One has to build it in the source tree, a limitation that should be
fixed in followup patches:

  $ make O=/tmp/build/perf -C tools/perf/lib
  make: Entering directory '/home/acme/git/perf/tools/perf/lib'
LINK /tmp/build/perf/libperf.so.0.0.1
GEN  /tmp/build/perf/libperf.pc
  make: Leaving directory '/home/acme/git/perf/tools/perf/lib'
  $ make O=/tmp/build/perf -C tools/perf/lib  tests
  make: Entering directory '/home/acme/git/perf/tools/perf/lib'
LINK test-cpumap-a
  gcc: error: ../libperf.a: No such file or directory
  make[1]: *** [Makefile:22: test-cpumap-a] Error 1
  make: *** [Makefile:115: tests] Error 2
  make: Leaving directory '/home/acme/git/perf/tools/perf/lib'
  [acme@quaco perf]$ make -C tools/perf/lib
  make: Entering directory '/home/acme/git/perf/tools/perf/lib'
HOSTCC   fixdep.o
HOSTLD   fixdep-in.o
LINK fixdep
CC   core.o
CC   cpumap.o
CC   threadmap.o
CC   evsel.o
CC   evlist.o
CC   zalloc.o
CC   xyarray.o
CC   lib.o
LD   libperf-in.o
AR   libperf.a
LINK libperf.so.0.0.1
GEN  libperf.pc
  make: Leaving directory '/home/acme/git/perf/tools/perf/lib'
  $ make O=/tmp/build/perf -C tools/perf/lib  tests
  make: Entering directory '/home/acme/git/perf/tools/perf/lib'
LINK test-cpumap-a
LINK test-cpumap-so
  running static:
  - running test-cpumap.c...OK
  running dynamic:
  - running test-cpumap.c...OK
  make: Leaving directory '/home/acme/git/perf/tools/perf/lib'
  $

Signed-off-by: Jiri Olsa 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-74-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/tests/Makefile  |  2 +-
 tools/perf/lib/tests/test-cpumap.c | 21 +
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/tools/perf/lib/tests/Makefile b/tools/perf/lib/tests/Makefile
index de951ae38dea..b72c8c47df61 100644
--- a/tools/perf/lib/tests/Makefile
+++ b/tools/perf/lib/tests/Makefile
@@ -1,6 +1,6 @@
 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
 
-TESTS =
+TESTS = test-cpumap
 
 TESTS_SO := $(addsuffix -so,$(TESTS))
 TESTS_A  := $(addsuffix -a,$(TESTS))
diff --git a/tools/perf/lib/tests/test-cpumap.c 
b/tools/perf/lib/tests/test-cpumap.c
new file mode 100644
index ..76a43cfb83a1
--- /dev/null
+++ b/tools/perf/lib/tests/test-cpumap.c
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0
+#include 
+#include 
+
+int main(int argc, char **argv)
+{
+   struct perf_cpu_map *cpus;
+
+   __T_START;
+
+   cpus = perf_cpu_map__dummy_new();
+   if (!cpus)
+   return -1;
+
+   perf_cpu_map__get(cpus);
+   perf_cpu_map__put(cpus);
+   perf_cpu_map__put(cpus);
+
+   __T_OK;
+   return 0;
+}


[tip:perf/core] libperf: Add tests support

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  6a94b52a71b7d3ca3ec47c194f7916b306cb26ef
Gitweb: https://git.kernel.org/tip/6a94b52a71b7d3ca3ec47c194f7916b306cb26ef
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:59 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:46 -0300

libperf: Add tests support

Adding simple test framework, now empty.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-73-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/Makefile |  7 +-
 tools/perf/lib/include/internal/tests.h | 19 +
 tools/perf/lib/tests/Makefile   | 38 +
 3 files changed, 63 insertions(+), 1 deletion(-)

diff --git a/tools/perf/lib/Makefile b/tools/perf/lib/Makefile
index f1b3d4c6d5f0..8a9ae50818e4 100644
--- a/tools/perf/lib/Makefile
+++ b/tools/perf/lib/Makefile
@@ -109,6 +109,11 @@ all: fixdep
 clean:
$(call QUIET_CLEAN, libperf) $(RM) $(LIBPERF_A) \
 *.o *~ *.a *.so *.so.$(VERSION) *.so.$(LIBPERF_VERSION) .*.d 
.*.cmd LIBPERF-CFLAGS $(LIBPERF_PC)
+   $(Q)$(MAKE) -C tests clean
+
+tests:
+   $(Q)$(MAKE) -C tests
+   $(Q)$(MAKE) -C tests run
 
 $(LIBPERF_PC):
$(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \
@@ -150,4 +155,4 @@ install: install_lib install_headers install_pkgconfig
 
 FORCE:
 
-.PHONY: all install clean FORCE
+.PHONY: all install clean tests FORCE
diff --git a/tools/perf/lib/include/internal/tests.h 
b/tools/perf/lib/include/internal/tests.h
new file mode 100644
index ..b7a20cd24ee1
--- /dev/null
+++ b/tools/perf/lib/include/internal/tests.h
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __LIBPERF_INTERNAL_TESTS_H
+#define __LIBPERF_INTERNAL_TESTS_H
+
+#include 
+
+#define __T_START fprintf(stdout, "- running %s...", __FILE__)
+#define __T_OKfprintf(stdout, "OK\n")
+#define __T_FAIL  fprintf(stdout, "FAIL\n")
+
+#define __T(text, cond)
  \
+do {   
  \
+   if (!(cond)) {  
 \
+   fprintf(stderr, "FAILED %s:%d %s\n", __FILE__, __LINE__, text); 
 \
+   return -1;  
 \
+   }   
 \
+} while (0)
+
+#endif /* __LIBPERF_INTERNAL_TESTS_H */
diff --git a/tools/perf/lib/tests/Makefile b/tools/perf/lib/tests/Makefile
new file mode 100644
index ..de951ae38dea
--- /dev/null
+++ b/tools/perf/lib/tests/Makefile
@@ -0,0 +1,38 @@
+# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
+
+TESTS =
+
+TESTS_SO := $(addsuffix -so,$(TESTS))
+TESTS_A  := $(addsuffix -a,$(TESTS))
+
+# Set compile option CFLAGS
+ifdef EXTRA_CFLAGS
+  CFLAGS := $(EXTRA_CFLAGS)
+else
+  CFLAGS := -g -Wall
+endif
+
+all:
+
+include $(srctree)/tools/scripts/Makefile.include
+
+INCLUDE = -I$(srctree)/tools/perf/lib/include -I$(srctree)/tools/include
+
+$(TESTS_A): FORCE
+   $(QUIET_LINK)$(CC) $(INCLUDE) $(CFLAGS) -o $@ $(subst -a,.c,$@) 
../libperf.a
+
+$(TESTS_SO): FORCE
+   $(QUIET_LINK)$(CC) $(INCLUDE) $(CFLAGS) -L.. -o $@ $(subst -so,.c,$@) 
-lperf
+
+all: $(TESTS_A) $(TESTS_SO)
+
+run:
+   @echo "running static:"
+   @for i in $(TESTS_A); do ./$$i; done
+   @echo "running dynamic:"
+   @for i in $(TESTS_SO); do LD_LIBRARY_PATH=../ ./$$i; done
+
+clean:
+   $(call QUIET_CLEAN, tests)$(RM) $(TESTS_A) $(TESTS_SO)
+
+.PHONY: all clean FORCE


[tip:perf/core] libperf: Add install targets

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  0a64d7091efde161a7d0fa385ed5c3bdb72ecdf9
Gitweb: https://git.kernel.org/tip/0a64d7091efde161a7d0fa385ed5c3bdb72ecdf9
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:58 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:46 -0300

libperf: Add install targets

Add install targets (mostly copied from tools/lib/bpf), it's now
possible to install libperf with:

  $ make DESTDIR=/tmp/krava  install
INSTALL  libperf.a
INSTALL  libperf.so
INSTALL  libperf.so.0
INSTALL  libperf.so.0.0.1
INSTALL  headers
INSTALL  libperf.pc

  $ find /tmp/krava/
  /tmp/krava/
  /tmp/krava/include
  /tmp/krava/include/perf
  /tmp/krava/include/perf/evsel.h
  /tmp/krava/include/perf/evlist.h
  /tmp/krava/include/perf/threadmap.h
  /tmp/krava/include/perf/cpumap.h
  /tmp/krava/include/perf/core.h
  /tmp/krava/lib64
  /tmp/krava/lib64/pkgconfig
  /tmp/krava/lib64/pkgconfig/libperf.pc
  /tmp/krava/lib64/libperf.so.0.0.1
  /tmp/krava/lib64/libperf.so.0
  /tmp/krava/lib64/libperf.so
  /tmp/krava/lib64/libperf.a

Signed-off-by: Jiri Olsa 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-72-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/Makefile| 69 +-
 .../lib/libperf.pc.template}   |  7 +--
 2 files changed, 70 insertions(+), 6 deletions(-)

diff --git a/tools/perf/lib/Makefile b/tools/perf/lib/Makefile
index cd571ec648ad..f1b3d4c6d5f0 100644
--- a/tools/perf/lib/Makefile
+++ b/tools/perf/lib/Makefile
@@ -14,9 +14,31 @@ srctree := $(patsubst %/,%,$(dir $(srctree)))
 #$(info Determined 'srctree' to be $(srctree))
 endif
 
+INSTALL = install
+
+# Use DESTDIR for installing into a different root directory.
+# This is useful for building a package. The program will be
+# installed in this directory as if it was the root directory.
+# Then the build tool can move it later.
+DESTDIR ?=
+DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
+
 include $(srctree)/tools/scripts/Makefile.include
 include $(srctree)/tools/scripts/Makefile.arch
 
+ifeq ($(LP64), 1)
+  libdir_relative = lib64
+else
+  libdir_relative = lib
+endif
+
+prefix ?=
+libdir = $(prefix)/$(libdir_relative)
+
+# Shell quotes
+libdir_SQ = $(subst ','\'',$(libdir))
+libdir_relative_SQ = $(subst ','\'',$(libdir_relative))
+
 ifeq ("$(origin V)", "command line")
   VERBOSE = $(V)
 endif
@@ -49,6 +71,8 @@ override CFLAGS += -fvisibility=hidden
 all:
 
 export srctree OUTPUT CC LD CFLAGS V
+export DESTDIR DESTDIR_SQ
+
 include $(srctree)/tools/build/Makefile.include
 
 VERSION_SCRIPT := libperf.map
@@ -60,6 +84,9 @@ VERSION   = 
$(LIBPERF_VERSION).$(LIBPERF_PATCHLEVEL).$(LIBPERF_EXTRAVERSION)
 LIBPERF_SO := $(OUTPUT)libperf.so.$(VERSION)
 LIBPERF_A  := $(OUTPUT)libperf.a
 LIBPERF_IN := $(OUTPUT)libperf-in.o
+LIBPERF_PC := $(OUTPUT)libperf.pc
+
+LIBPERF_ALL := $(LIBPERF_A) $(OUTPUT)libperf.so*
 
 $(LIBPERF_IN): FORCE
$(Q)$(MAKE) $(build)=libperf
@@ -74,14 +101,52 @@ $(LIBPERF_SO): $(LIBPERF_IN)
@ln -sf $(@F) $(OUTPUT)libperf.so.$(LIBPERF_VERSION)
 
 
-libs: $(LIBPERF_A) $(LIBPERF_SO)
+libs: $(LIBPERF_A) $(LIBPERF_SO) $(LIBPERF_PC)
 
 all: fixdep
$(Q)$(MAKE) libs
 
 clean:
$(call QUIET_CLEAN, libperf) $(RM) $(LIBPERF_A) \
-*.o *~ *.a *.so *.so.$(VERSION) *.so.$(LIBPERF_VERSION) .*.d 
.*.cmd LIBPERF-CFLAGS
+*.o *~ *.a *.so *.so.$(VERSION) *.so.$(LIBPERF_VERSION) .*.d 
.*.cmd LIBPERF-CFLAGS $(LIBPERF_PC)
+
+$(LIBPERF_PC):
+   $(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \
+   -e "s|@LIBDIR@|$(libdir_SQ)|" \
+   -e "s|@VERSION@|$(VERSION)|" \
+   < libperf.pc.template > $@
+
+define do_install_mkdir
+   if [ ! -d '$(DESTDIR_SQ)$1' ]; then \
+   $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
+   fi
+endef
+
+define do_install
+   if [ ! -d '$(DESTDIR_SQ)$2' ]; then \
+   $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
+   fi; \
+   $(INSTALL) $1 $(if $3,-m $3,) '$(DESTDIR_SQ)$2'
+endef
+
+install_lib: libs
+   $(call QUIET_INSTALL, $(LIBPERF_ALL)) \
+   $(call do_install_mkdir,$(libdir_SQ)); \
+   cp -fpR $(LIBPERF_ALL) $(DESTDIR)$(libdir_SQ)
+
+install_headers:
+   $(call QUIET_INSTALL, headers) \
+   $(call 
do_install,include/perf/core.h,$(prefix)/include/perf,644); \
+   $(call 
do_install,include/perf/cpumap.h,$(prefix)/include/perf,644); \
+   $(call 
do_install,include/perf/threadmap.h,$(prefix)/include/perf,644); \
+   $(call 
do_install,include/perf/evlist.h,$(prefix)/include/perf,644); \
+   $(call 
do_install,include/perf/evsel.h,$(prefix)/include/perf,644);
+

[tip:perf/core] libperf: Add perf_evsel__attr() function

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  384c4ad192a01fe235c7ac9e9fd8605d12a807e8
Gitweb: https://git.kernel.org/tip/384c4ad192a01fe235c7ac9e9fd8605d12a807e8
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:57 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:46 -0300

libperf: Add perf_evsel__attr() function

Add a perf_evsel__attr() function to get attr pointer from a perf_evsel
instance.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-71-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/evsel.c  | 5 +
 tools/perf/lib/include/perf/evsel.h | 1 +
 tools/perf/lib/libperf.map  | 1 +
 3 files changed, 7 insertions(+)

diff --git a/tools/perf/lib/evsel.c b/tools/perf/lib/evsel.c
index 8dbe0e841b8f..24abc80dd767 100644
--- a/tools/perf/lib/evsel.c
+++ b/tools/perf/lib/evsel.c
@@ -225,3 +225,8 @@ struct perf_thread_map *perf_evsel__threads(struct 
perf_evsel *evsel)
 {
return evsel->threads;
 }
+
+struct perf_event_attr *perf_evsel__attr(struct perf_evsel *evsel)
+{
+   return >attr;
+}
diff --git a/tools/perf/lib/include/perf/evsel.h 
b/tools/perf/lib/include/perf/evsel.h
index ae9f7eeb53a2..4388667f265c 100644
--- a/tools/perf/lib/include/perf/evsel.h
+++ b/tools/perf/lib/include/perf/evsel.h
@@ -34,5 +34,6 @@ LIBPERF_API int perf_evsel__enable(struct perf_evsel *evsel);
 LIBPERF_API int perf_evsel__disable(struct perf_evsel *evsel);
 LIBPERF_API struct perf_cpu_map *perf_evsel__cpus(struct perf_evsel *evsel);
 LIBPERF_API struct perf_thread_map *perf_evsel__threads(struct perf_evsel 
*evsel);
+LIBPERF_API struct perf_event_attr *perf_evsel__attr(struct perf_evsel *evsel);
 
 #endif /* __LIBPERF_EVSEL_H */
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index 2068e3d52227..e24d3cec01c1 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -23,6 +23,7 @@ LIBPERF_0.0.1 {
perf_evsel__read;
perf_evsel__cpus;
perf_evsel__threads;
+   perf_evsel__attr;
perf_evlist__new;
perf_evlist__delete;
perf_evlist__open;


[tip:perf/core] libperf: Adopt perf_evlist__enable()/disable() functions from perf

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  fcc97c3e7a9d6fd3fda7674f52fb005f4e8453e7
Gitweb: https://git.kernel.org/tip/fcc97c3e7a9d6fd3fda7674f52fb005f4e8453e7
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:56 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:46 -0300

libperf: Adopt perf_evlist__enable()/disable() functions from perf

Adopt the following functions from tools/perf:

  perf_evlist__enable()
  perf_evlist__disable()

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-70-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/evlist.c  | 16 
 tools/perf/lib/include/perf/evlist.h |  2 ++
 tools/perf/lib/libperf.map   |  2 ++
 3 files changed, 20 insertions(+)

diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index 5dda96b1d4da..f4dc9a208332 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -141,3 +141,19 @@ void perf_evlist__close(struct perf_evlist *evlist)
perf_evlist__for_each_entry_reverse(evlist, evsel)
perf_evsel__close(evsel);
 }
+
+void perf_evlist__enable(struct perf_evlist *evlist)
+{
+   struct perf_evsel *evsel;
+
+   perf_evlist__for_each_entry(evlist, evsel)
+   perf_evsel__enable(evsel);
+}
+
+void perf_evlist__disable(struct perf_evlist *evlist)
+{
+   struct perf_evsel *evsel;
+
+   perf_evlist__for_each_entry(evlist, evsel)
+   perf_evsel__disable(evsel);
+}
diff --git a/tools/perf/lib/include/perf/evlist.h 
b/tools/perf/lib/include/perf/evlist.h
index 6d3dda743541..38365f8f3fba 100644
--- a/tools/perf/lib/include/perf/evlist.h
+++ b/tools/perf/lib/include/perf/evlist.h
@@ -20,6 +20,8 @@ LIBPERF_API struct perf_evsel* perf_evlist__next(struct 
perf_evlist *evlist,
 struct perf_evsel *evsel);
 LIBPERF_API int perf_evlist__open(struct perf_evlist *evlist);
 LIBPERF_API void perf_evlist__close(struct perf_evlist *evlist);
+LIBPERF_API void perf_evlist__enable(struct perf_evlist *evlist);
+LIBPERF_API void perf_evlist__disable(struct perf_evlist *evlist);
 
 #define perf_evlist__for_each_evsel(evlist, pos)   \
for ((pos) = perf_evlist__next((evlist), NULL); \
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index 4f966ddd5e53..2068e3d52227 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -27,6 +27,8 @@ LIBPERF_0.0.1 {
perf_evlist__delete;
perf_evlist__open;
perf_evlist__close;
+   perf_evlist__enable;
+   perf_evlist__disable;
perf_evlist__init;
perf_evlist__add;
perf_evlist__remove;


[tip:perf/core] libperf: Adopt simplified perf_evlist__open()/close() functions from tools/perf

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  80dc2b3e257cbd62e1cd5b18a6581f231c828c81
Gitweb: https://git.kernel.org/tip/80dc2b3e257cbd62e1cd5b18a6581f231c828c81
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:55 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:46 -0300

libperf: Adopt simplified perf_evlist__open()/close() functions from tools/perf

Add the following functions:

  perf_evlist__open()
  perf_evlist__close()

It's a simplified version of perf's evlist__open() without the sampling
id index calculations. We can try to merge it in the future when we need
it in some new libperf user.

Also adopt some helper evlist traversing macros. In the future we can
remove them from util/evlist.h, but that requires also some other
changes.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-69-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/evlist.c  | 27 +
 tools/perf/lib/include/internal/evlist.h | 34 
 tools/perf/lib/include/perf/evlist.h |  2 ++
 tools/perf/lib/libperf.map   |  2 ++
 4 files changed, 65 insertions(+)

diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index 6a2308ef9868..5dda96b1d4da 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -114,3 +115,29 @@ void perf_evlist__set_maps(struct perf_evlist *evlist,
 
perf_evlist__propagate_maps(evlist);
 }
+
+int perf_evlist__open(struct perf_evlist *evlist)
+{
+   struct perf_evsel *evsel;
+   int err;
+
+   perf_evlist__for_each_entry(evlist, evsel) {
+   err = perf_evsel__open(evsel, evsel->cpus, evsel->threads);
+   if (err < 0)
+   goto out_err;
+   }
+
+   return 0;
+
+out_err:
+   perf_evlist__close(evlist);
+   return err;
+}
+
+void perf_evlist__close(struct perf_evlist *evlist)
+{
+   struct perf_evsel *evsel;
+
+   perf_evlist__for_each_entry_reverse(evlist, evsel)
+   perf_evsel__close(evsel);
+}
diff --git a/tools/perf/lib/include/internal/evlist.h 
b/tools/perf/lib/include/internal/evlist.h
index b7b43dbc9b82..448891f06e3e 100644
--- a/tools/perf/lib/include/internal/evlist.h
+++ b/tools/perf/lib/include/internal/evlist.h
@@ -2,6 +2,8 @@
 #ifndef __LIBPERF_INTERNAL_EVLIST_H
 #define __LIBPERF_INTERNAL_EVLIST_H
 
+#include 
+
 struct perf_cpu_map;
 struct perf_thread_map;
 
@@ -13,4 +15,36 @@ struct perf_evlist {
struct perf_thread_map  *threads;
 };
 
+/**
+ * __perf_evlist__for_each_entry - iterate thru all the evsels
+ * @list: list_head instance to iterate
+ * @evsel: struct perf_evsel iterator
+ */
+#define __perf_evlist__for_each_entry(list, evsel) \
+   list_for_each_entry(evsel, list, node)
+
+/**
+ * evlist__for_each_entry - iterate thru all the evsels
+ * @evlist: perf_evlist instance to iterate
+ * @evsel: struct perf_evsel iterator
+ */
+#define perf_evlist__for_each_entry(evlist, evsel) \
+   __perf_evlist__for_each_entry(&(evlist)->entries, evsel)
+
+/**
+ * __perf_evlist__for_each_entry_reverse - iterate thru all the evsels in 
reverse order
+ * @list: list_head instance to iterate
+ * @evsel: struct evsel iterator
+ */
+#define __perf_evlist__for_each_entry_reverse(list, evsel) \
+   list_for_each_entry_reverse(evsel, list, node)
+
+/**
+ * perf_evlist__for_each_entry_reverse - iterate thru all the evsels in 
reverse order
+ * @evlist: evlist instance to iterate
+ * @evsel: struct evsel iterator
+ */
+#define perf_evlist__for_each_entry_reverse(evlist, evsel) \
+   __perf_evlist__for_each_entry_reverse(&(evlist)->entries, evsel)
+
 #endif /* __LIBPERF_INTERNAL_EVLIST_H */
diff --git a/tools/perf/lib/include/perf/evlist.h 
b/tools/perf/lib/include/perf/evlist.h
index b1d8dee018d6..6d3dda743541 100644
--- a/tools/perf/lib/include/perf/evlist.h
+++ b/tools/perf/lib/include/perf/evlist.h
@@ -18,6 +18,8 @@ LIBPERF_API struct perf_evlist *perf_evlist__new(void);
 LIBPERF_API void perf_evlist__delete(struct perf_evlist *evlist);
 LIBPERF_API struct perf_evsel* perf_evlist__next(struct perf_evlist *evlist,
 struct perf_evsel *evsel);
+LIBPERF_API int perf_evlist__open(struct perf_evlist *evlist);
+LIBPERF_API void perf_evlist__close(struct perf_evlist *evlist);
 
 #define perf_evlist__for_each_evsel(evlist, pos)   \
for ((pos) = perf_evlist__next((evlist), NULL); \
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index 9f43b5cda031..4f966ddd5e53 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -25,6 +25,8 @@ LIBPERF_0.0.1 {
perf_evsel__threads;

[tip:perf/core] libperf: Add perf_evsel__cpus()/threads() functions

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  0ff1a0fdf52cffa998eee4303e02780d39b2b09c
Gitweb: https://git.kernel.org/tip/0ff1a0fdf52cffa998eee4303e02780d39b2b09c
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:54 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:46 -0300

libperf: Add perf_evsel__cpus()/threads() functions

Add the following functions:

  perf_evsel__cpus()
  perf_evsel__threads()

to access the evsel's cpus and threads objects.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-68-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/evsel.c  | 10 ++
 tools/perf/lib/include/perf/evsel.h |  2 ++
 tools/perf/lib/libperf.map  |  2 ++
 tools/perf/util/evsel.h |  2 +-
 4 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/tools/perf/lib/evsel.c b/tools/perf/lib/evsel.c
index c3f3722e9f91..8dbe0e841b8f 100644
--- a/tools/perf/lib/evsel.c
+++ b/tools/perf/lib/evsel.c
@@ -215,3 +215,13 @@ int perf_evsel__apply_filter(struct perf_evsel *evsel, 
const char *filter)
 PERF_EVENT_IOC_SET_FILTER,
 (void *)filter);
 }
+
+struct perf_cpu_map *perf_evsel__cpus(struct perf_evsel *evsel)
+{
+   return evsel->cpus;
+}
+
+struct perf_thread_map *perf_evsel__threads(struct perf_evsel *evsel)
+{
+   return evsel->threads;
+}
diff --git a/tools/perf/lib/include/perf/evsel.h 
b/tools/perf/lib/include/perf/evsel.h
index 0db18dfabdb8..ae9f7eeb53a2 100644
--- a/tools/perf/lib/include/perf/evsel.h
+++ b/tools/perf/lib/include/perf/evsel.h
@@ -32,5 +32,7 @@ LIBPERF_API int perf_evsel__read(struct perf_evsel *evsel, 
int cpu, int thread,
 struct perf_counts_values *count);
 LIBPERF_API int perf_evsel__enable(struct perf_evsel *evsel);
 LIBPERF_API int perf_evsel__disable(struct perf_evsel *evsel);
+LIBPERF_API struct perf_cpu_map *perf_evsel__cpus(struct perf_evsel *evsel);
+LIBPERF_API struct perf_thread_map *perf_evsel__threads(struct perf_evsel 
*evsel);
 
 #endif /* __LIBPERF_EVSEL_H */
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index d4d34bea0b40..9f43b5cda031 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -21,6 +21,8 @@ LIBPERF_0.0.1 {
perf_evsel__open;
perf_evsel__close;
perf_evsel__read;
+   perf_evsel__cpus;
+   perf_evsel__threads;
perf_evlist__new;
perf_evlist__delete;
perf_evlist__init;
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 0989fb2eb1ec..3cf35aa782b9 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -193,7 +193,7 @@ struct record_opts;
 
 static inline struct perf_cpu_map *evsel__cpus(struct evsel *evsel)
 {
-   return evsel->core.cpus;
+   return perf_evsel__cpus(>core);
 }
 
 static inline int perf_evsel__nr_cpus(struct evsel *evsel)


[tip:perf/core] libperf: Add perf_cpu_map__for_each_cpu() macro

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  09145d26b608e886415396e9277ae08f0617d21b
Gitweb: https://git.kernel.org/tip/09145d26b608e886415396e9277ae08f0617d21b
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:53 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:46 -0300

libperf: Add perf_cpu_map__for_each_cpu() macro

Add the following macro to libperf:

  perf_cpu_map__for_each_cpu()

And its related functions:

  perf_cpu_map__cpu()
  perf_cpu_map__nr()

That will allow hiding how it is implemented.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-67-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/cpumap.c  | 13 +
 tools/perf/lib/include/perf/cpumap.h |  7 +++
 tools/perf/lib/libperf.map   |  2 ++
 3 files changed, 22 insertions(+)

diff --git a/tools/perf/lib/cpumap.c b/tools/perf/lib/cpumap.c
index a5d4f7ff7174..1ddb69e796e5 100644
--- a/tools/perf/lib/cpumap.c
+++ b/tools/perf/lib/cpumap.c
@@ -224,3 +224,16 @@ invalid:
 out:
return cpus;
 }
+
+int perf_cpu_map__cpu(const struct perf_cpu_map *cpus, int idx)
+{
+   if (idx < cpus->nr)
+   return cpus->map[idx];
+
+   return -1;
+}
+
+int perf_cpu_map__nr(const struct perf_cpu_map *cpus)
+{
+   return cpus ? cpus->nr : 1;
+}
diff --git a/tools/perf/lib/include/perf/cpumap.h 
b/tools/perf/lib/include/perf/cpumap.h
index b4a9283a5dfa..1b6e7db3fa2b 100644
--- a/tools/perf/lib/include/perf/cpumap.h
+++ b/tools/perf/lib/include/perf/cpumap.h
@@ -12,5 +12,12 @@ LIBPERF_API struct perf_cpu_map *perf_cpu_map__new(const 
char *cpu_list);
 LIBPERF_API struct perf_cpu_map *perf_cpu_map__read(FILE *file);
 LIBPERF_API struct perf_cpu_map *perf_cpu_map__get(struct perf_cpu_map *map);
 LIBPERF_API void perf_cpu_map__put(struct perf_cpu_map *map);
+LIBPERF_API int perf_cpu_map__cpu(const struct perf_cpu_map *cpus, int idx);
+LIBPERF_API int perf_cpu_map__nr(const struct perf_cpu_map *cpus);
+
+#define perf_cpu_map__for_each_cpu(cpu, idx, cpus) \
+   for ((idx) = 0, (cpu) = perf_cpu_map__cpu(cpus, idx);   \
+(idx) < perf_cpu_map__nr(cpus);\
+(idx)++, (cpu) = perf_cpu_map__cpu(cpus, idx))
 
 #endif /* __LIBPERF_CPUMAP_H */
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index 5bd491ac1762..d4d34bea0b40 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -6,6 +6,8 @@ LIBPERF_0.0.1 {
perf_cpu_map__put;
perf_cpu_map__new;
perf_cpu_map__read;
+   perf_cpu_map__nr;
+   perf_cpu_map__cpu;
perf_thread_map__new_dummy;
perf_thread_map__set_pid;
perf_thread_map__comm;


[tip:perf/core] libperf: Adopt simplified perf_evsel__close() function from tools/perf

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  88761fa1f1e3fb2df86727ac99f88abf2ac7e00b
Gitweb: https://git.kernel.org/tip/88761fa1f1e3fb2df86727ac99f88abf2ac7e00b
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:50 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:46 -0300

libperf: Adopt simplified perf_evsel__close() function from tools/perf

Add perf_evsel__close() function to libperf while keeping a tools/perf
specific evsel__close() to free ids.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-64-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-trace.c |  2 +-
 tools/perf/lib/evsel.c | 26 ++
 tools/perf/lib/include/internal/evsel.h|  2 ++
 tools/perf/lib/include/perf/evsel.h|  1 +
 tools/perf/lib/libperf.map |  1 +
 tools/perf/tests/openat-syscall-all-cpus.c |  2 +-
 tools/perf/tests/openat-syscall.c  |  2 +-
 tools/perf/util/evlist.c   |  5 +++--
 tools/perf/util/evsel.c| 27 +++
 tools/perf/util/evsel.h|  3 +--
 10 files changed, 40 insertions(+), 31 deletions(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 35f3684f5327..75eb3811e942 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -2401,7 +2401,7 @@ static int trace__event_handler(struct trace *trace, 
struct evsel *evsel,
 
if (evsel->max_events != ULONG_MAX && 
++evsel->nr_events_printed == evsel->max_events) {
evsel__disable(evsel);
-   perf_evsel__close(evsel);
+   evsel__close(evsel);
}
}
}
diff --git a/tools/perf/lib/evsel.c b/tools/perf/lib/evsel.c
index 7027dacb50f6..50f09e939229 100644
--- a/tools/perf/lib/evsel.c
+++ b/tools/perf/lib/evsel.c
@@ -111,3 +111,29 @@ int perf_evsel__open(struct perf_evsel *evsel, struct 
perf_cpu_map *cpus,
 
return err;
 }
+
+void perf_evsel__close_fd(struct perf_evsel *evsel)
+{
+   int cpu, thread;
+
+   for (cpu = 0; cpu < xyarray__max_x(evsel->fd); cpu++)
+   for (thread = 0; thread < xyarray__max_y(evsel->fd); ++thread) {
+   close(FD(evsel, cpu, thread));
+   FD(evsel, cpu, thread) = -1;
+   }
+}
+
+void perf_evsel__free_fd(struct perf_evsel *evsel)
+{
+   xyarray__delete(evsel->fd);
+   evsel->fd = NULL;
+}
+
+void perf_evsel__close(struct perf_evsel *evsel)
+{
+   if (evsel->fd == NULL)
+   return;
+
+   perf_evsel__close_fd(evsel);
+   perf_evsel__free_fd(evsel);
+}
diff --git a/tools/perf/lib/include/internal/evsel.h 
b/tools/perf/lib/include/internal/evsel.h
index 3cb9a0f5f32e..878e2cf41ffc 100644
--- a/tools/perf/lib/include/internal/evsel.h
+++ b/tools/perf/lib/include/internal/evsel.h
@@ -21,5 +21,7 @@ struct perf_evsel {
 };
 
 int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
+void perf_evsel__close_fd(struct perf_evsel *evsel);
+void perf_evsel__free_fd(struct perf_evsel *evsel);
 
 #endif /* __LIBPERF_INTERNAL_EVSEL_H */
diff --git a/tools/perf/lib/include/perf/evsel.h 
b/tools/perf/lib/include/perf/evsel.h
index e9fbaa8fb51a..aa5c48f822d2 100644
--- a/tools/perf/lib/include/perf/evsel.h
+++ b/tools/perf/lib/include/perf/evsel.h
@@ -15,5 +15,6 @@ LIBPERF_API struct perf_evsel *perf_evsel__new(struct 
perf_event_attr *attr);
 LIBPERF_API void perf_evsel__delete(struct perf_evsel *evsel);
 LIBPERF_API int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map 
*cpus,
 struct perf_thread_map *threads);
+LIBPERF_API void perf_evsel__close(struct perf_evsel *evsel);
 
 #endif /* __LIBPERF_EVSEL_H */
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index 7594d3d89c5f..0b90999dcdcb 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -15,6 +15,7 @@ LIBPERF_0.0.1 {
perf_evsel__delete;
perf_evsel__init;
perf_evsel__open;
+   perf_evsel__close;
perf_evlist__new;
perf_evlist__delete;
perf_evlist__init;
diff --git a/tools/perf/tests/openat-syscall-all-cpus.c 
b/tools/perf/tests/openat-syscall-all-cpus.c
index d161b1a78703..8322b6aa4047 100644
--- a/tools/perf/tests/openat-syscall-all-cpus.c
+++ b/tools/perf/tests/openat-syscall-all-cpus.c
@@ -116,7 +116,7 @@ int test__openat_syscall_event_on_all_cpus(struct test 
*test __maybe_unused, int
 
perf_evsel__free_counts(evsel);
 out_close_fd:
-   perf_evsel__close_fd(evsel);
+   perf_evsel__close_fd(>core);
 out_evsel_delete:

[tip:perf/core] libperf: Adopt perf_evsel__read() function from tools/perf

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  5c30af92f2b1e9d844e1ae3243e4adcd7753d4c1
Gitweb: https://git.kernel.org/tip/5c30af92f2b1e9d844e1ae3243e4adcd7753d4c1
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:51 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:46 -0300

libperf: Adopt perf_evsel__read() function from tools/perf

Move the perf_evsel__read() function to libperf as a public interface
together with struct perf_counts_values for returning counter values.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-65-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/evsel.c  | 42 ++
 tools/perf/lib/include/internal/evsel.h |  1 +
 tools/perf/lib/include/perf/evsel.h | 14 ++
 tools/perf/lib/libperf.map  |  1 +
 tools/perf/tests/event-times.c  |  2 +-
 tools/perf/util/counts.h| 12 +
 tools/perf/util/evsel.c | 45 ++---
 tools/perf/util/evsel.h |  3 ---
 8 files changed, 62 insertions(+), 58 deletions(-)

diff --git a/tools/perf/lib/evsel.c b/tools/perf/lib/evsel.c
index 50f09e939229..390fcf9107c1 100644
--- a/tools/perf/lib/evsel.c
+++ b/tools/perf/lib/evsel.c
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *attr)
@@ -137,3 +138,44 @@ void perf_evsel__close(struct perf_evsel *evsel)
perf_evsel__close_fd(evsel);
perf_evsel__free_fd(evsel);
 }
+
+int perf_evsel__read_size(struct perf_evsel *evsel)
+{
+   u64 read_format = evsel->attr.read_format;
+   int entry = sizeof(u64); /* value */
+   int size = 0;
+   int nr = 1;
+
+   if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED)
+   size += sizeof(u64);
+
+   if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING)
+   size += sizeof(u64);
+
+   if (read_format & PERF_FORMAT_ID)
+   entry += sizeof(u64);
+
+   if (read_format & PERF_FORMAT_GROUP) {
+   nr = evsel->nr_members;
+   size += sizeof(u64);
+   }
+
+   size += entry * nr;
+   return size;
+}
+
+int perf_evsel__read(struct perf_evsel *evsel, int cpu, int thread,
+struct perf_counts_values *count)
+{
+   size_t size = perf_evsel__read_size(evsel);
+
+   memset(count, 0, sizeof(*count));
+
+   if (FD(evsel, cpu, thread) < 0)
+   return -EINVAL;
+
+   if (readn(FD(evsel, cpu, thread), count->values, size) <= 0)
+   return -errno;
+
+   return 0;
+}
diff --git a/tools/perf/lib/include/internal/evsel.h 
b/tools/perf/lib/include/internal/evsel.h
index 878e2cf41ffc..89bae3720d67 100644
--- a/tools/perf/lib/include/internal/evsel.h
+++ b/tools/perf/lib/include/internal/evsel.h
@@ -23,5 +23,6 @@ struct perf_evsel {
 int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
 void perf_evsel__close_fd(struct perf_evsel *evsel);
 void perf_evsel__free_fd(struct perf_evsel *evsel);
+int perf_evsel__read_size(struct perf_evsel *evsel);
 
 #endif /* __LIBPERF_INTERNAL_EVSEL_H */
diff --git a/tools/perf/lib/include/perf/evsel.h 
b/tools/perf/lib/include/perf/evsel.h
index aa5c48f822d2..16ae3f873280 100644
--- a/tools/perf/lib/include/perf/evsel.h
+++ b/tools/perf/lib/include/perf/evsel.h
@@ -2,6 +2,7 @@
 #ifndef __LIBPERF_EVSEL_H
 #define __LIBPERF_EVSEL_H
 
+#include 
 #include 
 
 struct perf_evsel;
@@ -9,6 +10,17 @@ struct perf_event_attr;
 struct perf_cpu_map;
 struct perf_thread_map;
 
+struct perf_counts_values {
+   union {
+   struct {
+   uint64_t val;
+   uint64_t ena;
+   uint64_t run;
+   };
+   uint64_t values[3];
+   };
+};
+
 LIBPERF_API void perf_evsel__init(struct perf_evsel *evsel,
  struct perf_event_attr *attr);
 LIBPERF_API struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr);
@@ -16,5 +28,7 @@ LIBPERF_API void perf_evsel__delete(struct perf_evsel *evsel);
 LIBPERF_API int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map 
*cpus,
 struct perf_thread_map *threads);
 LIBPERF_API void perf_evsel__close(struct perf_evsel *evsel);
+LIBPERF_API int perf_evsel__read(struct perf_evsel *evsel, int cpu, int thread,
+struct perf_counts_values *count);
 
 #endif /* __LIBPERF_EVSEL_H */
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index 0b90999dcdcb..2e23cf420cce 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -16,6 +16,7 @@ LIBPERF_0.0.1 {
perf_evsel__init;
perf_evsel__open;
   

[tip:perf/core] libperf: Adopt perf_evsel__enable()/disable()/apply_filter() functions

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  a00571fda6091b5268d05e87d0797efe2db1920a
Gitweb: https://git.kernel.org/tip/a00571fda6091b5268d05e87d0797efe2db1920a
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:52 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:46 -0300

libperf: Adopt perf_evsel__enable()/disable()/apply_filter() functions

Move the following functions:

  evsel__enable()
  evsel__disable()
  evsel__apply_filter()

to libperf with the following names:

  perf_evsel__enable()
  perf_evsel__disable()
  perf_evsel__apply_filter()

Export only perf_evsel__enable()/disable(), keeping the
perf_evsel__apply_filter() one private for the moment.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-66-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/evsel.c  | 36 +
 tools/perf/lib/include/internal/evsel.h |  1 +
 tools/perf/lib/include/perf/evsel.h |  2 ++
 tools/perf/lib/libperf.map  |  2 ++
 tools/perf/util/evlist.c|  2 +-
 tools/perf/util/evsel.c | 29 ++
 tools/perf/util/evsel.h |  1 -
 7 files changed, 44 insertions(+), 29 deletions(-)

diff --git a/tools/perf/lib/evsel.c b/tools/perf/lib/evsel.c
index 390fcf9107c1..c3f3722e9f91 100644
--- a/tools/perf/lib/evsel.c
+++ b/tools/perf/lib/evsel.c
@@ -14,6 +14,7 @@
 #include 
 #include 
 #include 
+#include 
 
 void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *attr)
 {
@@ -179,3 +180,38 @@ int perf_evsel__read(struct perf_evsel *evsel, int cpu, 
int thread,
 
return 0;
 }
+
+static int perf_evsel__run_ioctl(struct perf_evsel *evsel,
+int ioc,  void *arg)
+{
+   int cpu, thread;
+
+   for (cpu = 0; cpu < xyarray__max_x(evsel->fd); cpu++) {
+   for (thread = 0; thread < xyarray__max_y(evsel->fd); thread++) {
+   int fd = FD(evsel, cpu, thread),
+   err = ioctl(fd, ioc, arg);
+
+   if (err)
+   return err;
+   }
+   }
+
+   return 0;
+}
+
+int perf_evsel__enable(struct perf_evsel *evsel)
+{
+   return perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_ENABLE, 0);
+}
+
+int perf_evsel__disable(struct perf_evsel *evsel)
+{
+   return perf_evsel__run_ioctl(evsel, PERF_EVENT_IOC_DISABLE, 0);
+}
+
+int perf_evsel__apply_filter(struct perf_evsel *evsel, const char *filter)
+{
+   return perf_evsel__run_ioctl(evsel,
+PERF_EVENT_IOC_SET_FILTER,
+(void *)filter);
+}
diff --git a/tools/perf/lib/include/internal/evsel.h 
b/tools/perf/lib/include/internal/evsel.h
index 89bae3720d67..8b854d1c9b45 100644
--- a/tools/perf/lib/include/internal/evsel.h
+++ b/tools/perf/lib/include/internal/evsel.h
@@ -24,5 +24,6 @@ int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, 
int nthreads);
 void perf_evsel__close_fd(struct perf_evsel *evsel);
 void perf_evsel__free_fd(struct perf_evsel *evsel);
 int perf_evsel__read_size(struct perf_evsel *evsel);
+int perf_evsel__apply_filter(struct perf_evsel *evsel, const char *filter);
 
 #endif /* __LIBPERF_INTERNAL_EVSEL_H */
diff --git a/tools/perf/lib/include/perf/evsel.h 
b/tools/perf/lib/include/perf/evsel.h
index 16ae3f873280..0db18dfabdb8 100644
--- a/tools/perf/lib/include/perf/evsel.h
+++ b/tools/perf/lib/include/perf/evsel.h
@@ -30,5 +30,7 @@ LIBPERF_API int perf_evsel__open(struct perf_evsel *evsel, 
struct perf_cpu_map *
 LIBPERF_API void perf_evsel__close(struct perf_evsel *evsel);
 LIBPERF_API int perf_evsel__read(struct perf_evsel *evsel, int cpu, int thread,
 struct perf_counts_values *count);
+LIBPERF_API int perf_evsel__enable(struct perf_evsel *evsel);
+LIBPERF_API int perf_evsel__disable(struct perf_evsel *evsel);
 
 #endif /* __LIBPERF_EVSEL_H */
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index 2e23cf420cce..5bd491ac1762 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -13,6 +13,8 @@ LIBPERF_0.0.1 {
perf_thread_map__put;
perf_evsel__new;
perf_evsel__delete;
+   perf_evsel__enable;
+   perf_evsel__disable;
perf_evsel__init;
perf_evsel__open;
perf_evsel__close;
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index c6b4883b2d49..c4489a1ad6bc 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -1109,7 +1109,7 @@ int perf_evlist__apply_filters(struct evlist *evlist, 
struct evsel **err_evsel)
 * filters only work for tracepoint event, which doesn't have 
cpu limit.
  

[tip:perf/core] libperf: Adopt simplified perf_evsel__open() function from tools/perf

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  50a4e6fa450c4e5b688814a7ec8236d0de6e38bf
Gitweb: https://git.kernel.org/tip/50a4e6fa450c4e5b688814a7ec8236d0de6e38bf
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:49 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:46 -0300

libperf: Adopt simplified perf_evsel__open() function from tools/perf

Add a perf_evsel__open() function to libperf.

It's a simplified version of evsel__open() without the fallback
mechanism.

We can try to merge it in the future to libperf, but it has many
details, lets start simple, requiring the latest kernel, perf should
continue using its evsel__open() version, continuing to support running
on older kernels when possible.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-63-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/evsel.c  | 65 +
 tools/perf/lib/include/perf/evsel.h |  4 +++
 tools/perf/lib/libperf.map  |  1 +
 3 files changed, 70 insertions(+)

diff --git a/tools/perf/lib/evsel.c b/tools/perf/lib/evsel.c
index 027f1edb4e8e..7027dacb50f6 100644
--- a/tools/perf/lib/evsel.c
+++ b/tools/perf/lib/evsel.c
@@ -1,11 +1,17 @@
 // SPDX-License-Identifier: GPL-2.0
 #include 
+#include 
+#include 
 #include 
+#include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
+#include 
 #include 
 
 void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *attr)
@@ -46,3 +52,62 @@ int perf_evsel__alloc_fd(struct perf_evsel *evsel, int 
ncpus, int nthreads)
 
return evsel->fd != NULL ? 0 : -ENOMEM;
 }
+
+static int
+sys_perf_event_open(struct perf_event_attr *attr,
+   pid_t pid, int cpu, int group_fd,
+   unsigned long flags)
+{
+   return syscall(__NR_perf_event_open, attr, pid, cpu, group_fd, flags);
+}
+
+int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map *cpus,
+struct perf_thread_map *threads)
+{
+   int cpu, thread, err = 0;
+
+   if (cpus == NULL) {
+   static struct perf_cpu_map *empty_cpu_map;
+
+   if (empty_cpu_map == NULL) {
+   empty_cpu_map = perf_cpu_map__dummy_new();
+   if (empty_cpu_map == NULL)
+   return -ENOMEM;
+   }
+
+   cpus = empty_cpu_map;
+   }
+
+   if (threads == NULL) {
+   static struct perf_thread_map *empty_thread_map;
+
+   if (empty_thread_map == NULL) {
+   empty_thread_map = perf_thread_map__new_dummy();
+   if (empty_thread_map == NULL)
+   return -ENOMEM;
+   }
+
+   threads = empty_thread_map;
+   }
+
+   if (evsel->fd == NULL &&
+   perf_evsel__alloc_fd(evsel, cpus->nr, threads->nr) < 0)
+   return -ENOMEM;
+
+   for (cpu = 0; cpu < cpus->nr; cpu++) {
+   for (thread = 0; thread < threads->nr; thread++) {
+   int fd;
+
+   fd = sys_perf_event_open(>attr,
+threads->map[thread].pid,
+cpus->map[cpu], -1, 0);
+
+   if (fd < 0)
+   return -errno;
+
+   FD(evsel, cpu, thread) = fd;
+   }
+   }
+
+   return err;
+}
diff --git a/tools/perf/lib/include/perf/evsel.h 
b/tools/perf/lib/include/perf/evsel.h
index a57efc0f5c8b..e9fbaa8fb51a 100644
--- a/tools/perf/lib/include/perf/evsel.h
+++ b/tools/perf/lib/include/perf/evsel.h
@@ -6,10 +6,14 @@
 
 struct perf_evsel;
 struct perf_event_attr;
+struct perf_cpu_map;
+struct perf_thread_map;
 
 LIBPERF_API void perf_evsel__init(struct perf_evsel *evsel,
  struct perf_event_attr *attr);
 LIBPERF_API struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr);
 LIBPERF_API void perf_evsel__delete(struct perf_evsel *evsel);
+LIBPERF_API int perf_evsel__open(struct perf_evsel *evsel, struct perf_cpu_map 
*cpus,
+struct perf_thread_map *threads);
 
 #endif /* __LIBPERF_EVSEL_H */
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index 9b6e8f165014..7594d3d89c5f 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -14,6 +14,7 @@ LIBPERF_0.0.1 {
perf_evsel__new;
perf_evsel__delete;
perf_evsel__init;
+   perf_evsel__open;
perf_evlist__new;
perf_evlist__delete;
perf_evlist__init;


[tip:perf/core] libperf: Adopt perf_evsel__alloc_fd() function from tools/perf

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  b8eca4d761c57fcf691a8063cd562f205645d11f
Gitweb: https://git.kernel.org/tip/b8eca4d761c57fcf691a8063cd562f205645d11f
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:48 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:46 -0300

libperf: Adopt perf_evsel__alloc_fd() function from tools/perf

Move the perf_evsel__alloc_fd() function from perf to libperf.

It's not exported.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-62-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/evsel.c  | 21 +
 tools/perf/lib/include/internal/evsel.h |  2 ++
 tools/perf/util/evsel.c | 18 +-
 3 files changed, 24 insertions(+), 17 deletions(-)

diff --git a/tools/perf/lib/evsel.c b/tools/perf/lib/evsel.c
index ddc3ad447bfb..027f1edb4e8e 100644
--- a/tools/perf/lib/evsel.c
+++ b/tools/perf/lib/evsel.c
@@ -1,9 +1,12 @@
 // SPDX-License-Identifier: GPL-2.0
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
+#include 
 
 void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *attr)
 {
@@ -25,3 +28,21 @@ void perf_evsel__delete(struct perf_evsel *evsel)
 {
free(evsel);
 }
+
+#define FD(e, x, y) (*(int *) xyarray__entry(e->fd, x, y))
+
+int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads)
+{
+   evsel->fd = xyarray__new(ncpus, nthreads, sizeof(int));
+
+   if (evsel->fd) {
+   int cpu, thread;
+   for (cpu = 0; cpu < ncpus; cpu++) {
+   for (thread = 0; thread < nthreads; thread++) {
+   FD(evsel, cpu, thread) = -1;
+   }
+   }
+   }
+
+   return evsel->fd != NULL ? 0 : -ENOMEM;
+}
diff --git a/tools/perf/lib/include/internal/evsel.h 
b/tools/perf/lib/include/internal/evsel.h
index 29eca9576546..3cb9a0f5f32e 100644
--- a/tools/perf/lib/include/internal/evsel.h
+++ b/tools/perf/lib/include/internal/evsel.h
@@ -20,4 +20,6 @@ struct perf_evsel {
int  nr_members;
 };
 
+int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int nthreads);
+
 #endif /* __LIBPERF_INTERNAL_EVSEL_H */
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 8b9a00598677..d3c8488f7069 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1153,22 +1153,6 @@ void perf_evsel__config(struct evsel *evsel, struct 
record_opts *opts,
perf_evsel__reset_sample_bit(evsel, BRANCH_STACK);
 }
 
-static int perf_evsel__alloc_fd(struct evsel *evsel, int ncpus, int nthreads)
-{
-   evsel->core.fd = xyarray__new(ncpus, nthreads, sizeof(int));
-
-   if (evsel->core.fd) {
-   int cpu, thread;
-   for (cpu = 0; cpu < ncpus; cpu++) {
-   for (thread = 0; thread < nthreads; thread++) {
-   FD(evsel, cpu, thread) = -1;
-   }
-   }
-   }
-
-   return evsel->core.fd != NULL ? 0 : -ENOMEM;
-}
-
 static int perf_evsel__run_ioctl(struct evsel *evsel,
  int ioc,  void *arg)
 {
@@ -1866,7 +1850,7 @@ int evsel__open(struct evsel *evsel, struct perf_cpu_map 
*cpus,
nthreads = threads->nr;
 
if (evsel->core.fd == NULL &&
-   perf_evsel__alloc_fd(evsel, cpus->nr, nthreads) < 0)
+   perf_evsel__alloc_fd(>core, cpus->nr, nthreads) < 0)
return -ENOMEM;
 
if (evsel->cgrp) {


[tip:perf/core] libperf: Adopt the readn()/writen() functions from tools/perf

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  c03538b1f1a7e0e996a8d6feb20cf001d4b14939
Gitweb: https://git.kernel.org/tip/c03538b1f1a7e0e996a8d6feb20cf001d4b14939
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:47 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:46 -0300

libperf: Adopt the readn()/writen() functions from tools/perf

Move the readn()/writen() functions into libperf.

Keep those non-namespaced names because they will be shared only between
perf and libperf.

Again, these are not exported functions.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-61-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/Build  |  1 +
 tools/perf/lib/include/internal/lib.h | 10 
 tools/perf/lib/lib.c  | 46 +++
 tools/perf/util/util.c| 40 --
 tools/perf/util/util.h|  4 +--
 5 files changed, 58 insertions(+), 43 deletions(-)

diff --git a/tools/perf/lib/Build b/tools/perf/lib/Build
index 4f78ec0b4e10..c31f1c111f8f 100644
--- a/tools/perf/lib/Build
+++ b/tools/perf/lib/Build
@@ -5,6 +5,7 @@ libperf-y += evsel.o
 libperf-y += evlist.o
 libperf-y += zalloc.o
 libperf-y += xyarray.o
+libperf-y += lib.o
 
 $(OUTPUT)zalloc.o: ../../lib/zalloc.c FORCE
$(call rule_mkdir)
diff --git a/tools/perf/lib/include/internal/lib.h 
b/tools/perf/lib/include/internal/lib.h
new file mode 100644
index ..0b56f1201dc9
--- /dev/null
+++ b/tools/perf/lib/include/internal/lib.h
@@ -0,0 +1,10 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __LIBPERF_INTERNAL_LIB_H
+#define __LIBPERF_INTERNAL_LIB_H
+
+#include 
+
+ssize_t readn(int fd, void *buf, size_t n);
+ssize_t writen(int fd, const void *buf, size_t n);
+
+#endif /* __LIBPERF_INTERNAL_CPUMAP_H */
diff --git a/tools/perf/lib/lib.c b/tools/perf/lib/lib.c
new file mode 100644
index ..2a81819c3b8c
--- /dev/null
+++ b/tools/perf/lib/lib.c
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: GPL-2.0
+#include 
+#include 
+#include 
+#include 
+#include 
+
+static ssize_t ion(bool is_read, int fd, void *buf, size_t n)
+{
+   void *buf_start = buf;
+   size_t left = n;
+
+   while (left) {
+   /* buf must be treated as const if !is_read. */
+   ssize_t ret = is_read ? read(fd, buf, left) :
+   write(fd, buf, left);
+
+   if (ret < 0 && errno == EINTR)
+   continue;
+   if (ret <= 0)
+   return ret;
+
+   left -= ret;
+   buf  += ret;
+   }
+
+   BUG_ON((size_t)(buf - buf_start) != n);
+   return n;
+}
+
+/*
+ * Read exactly 'n' bytes or return an error.
+ */
+ssize_t readn(int fd, void *buf, size_t n)
+{
+   return ion(true, fd, buf, n);
+}
+
+/*
+ * Write exactly 'n' bytes or return an error.
+ */
+ssize_t writen(int fd, const void *buf, size_t n)
+{
+   /* ion does not modify buf. */
+   return ion(false, fd, (void *)buf, n);
+}
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index a61535cf1bca..9c3c97697387 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -384,46 +384,6 @@ int copyfile(const char *from, const char *to)
return copyfile_mode(from, to, 0755);
 }
 
-static ssize_t ion(bool is_read, int fd, void *buf, size_t n)
-{
-   void *buf_start = buf;
-   size_t left = n;
-
-   while (left) {
-   /* buf must be treated as const if !is_read. */
-   ssize_t ret = is_read ? read(fd, buf, left) :
-   write(fd, buf, left);
-
-   if (ret < 0 && errno == EINTR)
-   continue;
-   if (ret <= 0)
-   return ret;
-
-   left -= ret;
-   buf  += ret;
-   }
-
-   BUG_ON((size_t)(buf - buf_start) != n);
-   return n;
-}
-
-/*
- * Read exactly 'n' bytes or return an error.
- */
-ssize_t readn(int fd, void *buf, size_t n)
-{
-   return ion(true, fd, buf, n);
-}
-
-/*
- * Write exactly 'n' bytes or return an error.
- */
-ssize_t writen(int fd, const void *buf, size_t n)
-{
-   /* ion does not modify buf. */
-   return ion(false, fd, (void *)buf, n);
-}
-
 size_t hex_width(u64 v)
 {
size_t n = 1;
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index dc7a469921e9..0dab140c6517 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -11,6 +11,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /* General helper functions */
 void usage(const char *err) __noreturn;
@@ -30,9 +31,6 @@ int copyfile_mode(const char *from, const char *to, mode_t 
mode);
 int copyfile_ns(const char *from, const char *to, struct nsinfo *nsi);
 int 

[tip:perf/core] libperf: Move nr_members from perf's evsel to libperf's perf_evsel

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  5643b1a59e581ac3f66d36caba8124313cc446c0
Gitweb: https://git.kernel.org/tip/5643b1a59e581ac3f66d36caba8124313cc446c0
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:46 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:46 -0300

libperf: Move nr_members from perf's evsel to libperf's perf_evsel

Move the nr_members member from perf's evsel to libperf's perf_evsel.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-60-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-report.c |  2 +-
 tools/perf/builtin-script.c |  2 +-
 tools/perf/builtin-stat.c   |  2 +-
 tools/perf/lib/include/internal/evsel.h |  3 +++
 tools/perf/tests/parse-events.c | 22 +++---
 tools/perf/ui/gtk/annotate.c|  2 +-
 tools/perf/ui/gtk/hists.c   |  2 +-
 tools/perf/ui/hist.c|  6 +++---
 tools/perf/util/annotate.c  |  8 
 tools/perf/util/evlist.c|  6 +++---
 tools/perf/util/evsel.c |  6 +++---
 tools/perf/util/evsel.h |  3 +--
 tools/perf/util/evsel_fprintf.c |  4 ++--
 tools/perf/util/header.c| 12 ++--
 tools/perf/util/hist.c  |  2 +-
 tools/perf/util/parse-events.c  |  2 +-
 tools/perf/util/stat-display.c  |  2 +-
 tools/perf/util/stat.c  |  2 +-
 18 files changed, 45 insertions(+), 43 deletions(-)

diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c
index e258e988c55b..d4288dcce156 100644
--- a/tools/perf/builtin-report.c
+++ b/tools/perf/builtin-report.c
@@ -436,7 +436,7 @@ static size_t hists__fprintf_nr_sample_events(struct hists 
*hists, struct report
ret = fprintf(fp, "# Samples: %lu%c", nr_samples, unit);
if (evname != NULL) {
ret += fprintf(fp, " of event%s '%s'",
-  evsel->nr_members > 1 ? "s" : "", evname);
+  evsel->core.nr_members > 1 ? "s" : "", evname);
}
 
if (rep->time_str)
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 46fadbbe1c3e..31a529ec139f 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1734,7 +1734,7 @@ static void perf_sample__fprint_metric(struct perf_script 
*script,
   sample->cpu,
   _stat);
evsel_script(evsel)->val = val;
-   if (evsel_script(evsel->leader)->gnum == evsel->leader->nr_members) {
+   if (evsel_script(evsel->leader)->gnum == 
evsel->leader->core.nr_members) {
for_each_group_member (ev2, evsel->leader) {
perf_stat__print_shadow_stats(_config, ev2,
  evsel_script(ev2)->val,
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 14e4c970d16a..b19df67e 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -479,7 +479,7 @@ try_again:
counter->supported = false;
 
if ((counter->leader != counter) ||
-   !(counter->leader->nr_members > 1))
+   !(counter->leader->core.nr_members > 1))
continue;
} else if (perf_evsel__fallback(counter, errno, msg, 
sizeof(msg))) {
 if (verbose > 0)
diff --git a/tools/perf/lib/include/internal/evsel.h 
b/tools/perf/lib/include/internal/evsel.h
index df4078194e9a..29eca9576546 100644
--- a/tools/perf/lib/include/internal/evsel.h
+++ b/tools/perf/lib/include/internal/evsel.h
@@ -15,6 +15,9 @@ struct perf_evsel {
struct perf_cpu_map *own_cpus;
struct perf_thread_map  *threads;
struct xyarray  *fd;
+
+   /* parse modifier helper */
+   int  nr_members;
 };
 
 #endif /* __LIBPERF_INTERNAL_EVSEL_H */
diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c
index 5b4a5a3dac50..49f52e4de41b 100644
--- a/tools/perf/tests/parse-events.c
+++ b/tools/perf/tests/parse-events.c
@@ -653,7 +653,7 @@ static int test__group1(struct evlist *evlist)
TEST_ASSERT_VAL("wrong exclude host", !evsel->core.attr.exclude_host);
TEST_ASSERT_VAL("wrong precise_ip", !evsel->core.attr.precise_ip);
TEST_ASSERT_VAL("wrong leader", perf_evsel__is_group_leader(evsel));
-   TEST_ASSERT_VAL("wrong nr_members", evsel->nr_members == 2);
+   TEST_ASSERT_VAL("wrong core.nr_members", evsel->core.nr_members == 2);
TEST_ASSERT_VAL("wrong group_idx", perf_evsel__group_idx(evsel) == 0);

[tip:perf/core] libperf: Move fd array from perf's evsel to lobperf's perf_evsel class

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  9dfcb7599084382884fec6d0fd9ca33945fa7578
Gitweb: https://git.kernel.org/tip/9dfcb7599084382884fec6d0fd9ca33945fa7578
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:45 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:46 -0300

libperf: Move fd array from perf's evsel to lobperf's perf_evsel class

Move the fd array from perf's evsel to libperf's perf_evsel class.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-59-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/include/internal/evsel.h |  1 +
 tools/perf/util/bpf-loader.c|  2 +-
 tools/perf/util/evlist.c| 10 +-
 tools/perf/util/evsel.c | 30 +++---
 tools/perf/util/evsel.h |  1 -
 5 files changed, 22 insertions(+), 22 deletions(-)

diff --git a/tools/perf/lib/include/internal/evsel.h 
b/tools/perf/lib/include/internal/evsel.h
index 8340fd883a3d..df4078194e9a 100644
--- a/tools/perf/lib/include/internal/evsel.h
+++ b/tools/perf/lib/include/internal/evsel.h
@@ -14,6 +14,7 @@ struct perf_evsel {
struct perf_cpu_map *cpus;
struct perf_cpu_map *own_cpus;
struct perf_thread_map  *threads;
+   struct xyarray  *fd;
 };
 
 #endif /* __LIBPERF_INTERNAL_EVSEL_H */
diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
index 4df8bdea14ac..9c219d413e57 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -1403,7 +1403,7 @@ static int
 apply_config_evsel_for_key(const char *name, int map_fd, void *pkey,
   struct evsel *evsel)
 {
-   struct xyarray *xy = evsel->fd;
+   struct xyarray *xy = evsel->core.fd;
struct perf_event_attr *attr;
unsigned int key, events;
bool check_pass = false;
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 4433b656cfb7..e4b1a9914ea4 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -40,7 +40,7 @@
 int sigqueue(pid_t pid, int sig, const union sigval value);
 #endif
 
-#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
+#define FD(e, x, y) (*(int *)xyarray__entry(e->core.fd, x, y))
 #define SID(e, x, y) xyarray__entry(e->sample_id, x, y)
 
 void evlist__init(struct evlist *evlist, struct perf_cpu_map *cpus,
@@ -321,7 +321,7 @@ void evlist__disable(struct evlist *evlist)
struct evsel *pos;
 
evlist__for_each_entry(evlist, pos) {
-   if (pos->disabled || !perf_evsel__is_group_leader(pos) || 
!pos->fd)
+   if (pos->disabled || !perf_evsel__is_group_leader(pos) || 
!pos->core.fd)
continue;
evsel__disable(pos);
}
@@ -334,7 +334,7 @@ void evlist__enable(struct evlist *evlist)
struct evsel *pos;
 
evlist__for_each_entry(evlist, pos) {
-   if (!perf_evsel__is_group_leader(pos) || !pos->fd)
+   if (!perf_evsel__is_group_leader(pos) || !pos->core.fd)
continue;
evsel__enable(pos);
}
@@ -353,7 +353,7 @@ static int perf_evlist__enable_event_cpu(struct evlist 
*evlist,
int thread;
int nr_threads = perf_evlist__nr_threads(evlist, evsel);
 
-   if (!evsel->fd)
+   if (!evsel->core.fd)
return -EINVAL;
 
for (thread = 0; thread < nr_threads; thread++) {
@@ -371,7 +371,7 @@ static int perf_evlist__enable_event_thread(struct evlist 
*evlist,
int cpu;
int nr_cpus = cpu_map__nr(evlist->core.cpus);
 
-   if (!evsel->fd)
+   if (!evsel->core.fd)
return -EINVAL;
 
for (cpu = 0; cpu < nr_cpus; cpu++) {
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index f7758ce0dd5c..8d087d0e55f1 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -90,7 +90,7 @@ set_methods:
return 0;
 }
 
-#define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
+#define FD(e, x, y) (*(int *)xyarray__entry(e->core.fd, x, y))
 
 int __perf_evsel__sample_size(u64 sample_type)
 {
@@ -1155,9 +1155,9 @@ void perf_evsel__config(struct evsel *evsel, struct 
record_opts *opts,
 
 static int perf_evsel__alloc_fd(struct evsel *evsel, int ncpus, int nthreads)
 {
-   evsel->fd = xyarray__new(ncpus, nthreads, sizeof(int));
+   evsel->core.fd = xyarray__new(ncpus, nthreads, sizeof(int));
 
-   if (evsel->fd) {
+   if (evsel->core.fd) {
int cpu, thread;
for (cpu = 0; cpu < ncpus; cpu++) {
for (thread = 0; thread < nthreads; thread++) {
@@ -1166,7 +1166,7 @@ static int perf_evsel__alloc_fd(struct evsel *evsel, int 
ncpus, int nthreads)
}
}
 
-   return evsel->fd != NULL ? 0 : -ENOMEM;
+   

[tip:perf/core] libperf: Add perf_evlist__set_maps() function

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  453fa03090a64c0e0a561f10dfd5e8747796949c
Gitweb: https://git.kernel.org/tip/453fa03090a64c0e0a561f10dfd5e8747796949c
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:43 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:45 -0300

libperf: Add perf_evlist__set_maps() function

Move the evlist__set_maps() function from tools/perf to libperf.

Committer notes:

Fix up reject due to earlier inversion in calling perf_evlist__init().

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-57-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/arch/x86/tests/perf-time-to-tsc.c |  3 +-
 tools/perf/builtin-script.c  |  3 +-
 tools/perf/builtin-stat.c|  3 +-
 tools/perf/lib/evlist.c  | 54 ++
 tools/perf/lib/include/perf/evlist.h |  6 +++
 tools/perf/lib/libperf.map   |  1 +
 tools/perf/tests/code-reading.c  |  5 ++-
 tools/perf/tests/keep-tracking.c |  3 +-
 tools/perf/tests/mmap-basic.c|  3 +-
 tools/perf/tests/sw-clock.c  |  3 +-
 tools/perf/tests/switch-tracking.c   |  3 +-
 tools/perf/tests/task-exit.c |  3 +-
 tools/perf/util/evlist.c | 58 ++--
 tools/perf/util/evlist.h |  2 -
 14 files changed, 83 insertions(+), 67 deletions(-)

diff --git a/tools/perf/arch/x86/tests/perf-time-to-tsc.c 
b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
index 261bdd680651..582182d98a7f 100644
--- a/tools/perf/arch/x86/tests/perf-time-to-tsc.c
+++ b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
@@ -6,6 +6,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "parse-events.h"
 #include "evlist.h"
@@ -72,7 +73,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, 
int subtest __maybe
evlist = evlist__new();
CHECK_NOT_NULL__(evlist);
 
-   perf_evlist__set_maps(evlist, cpus, threads);
+   perf_evlist__set_maps(>core, cpus, threads);
 
CHECK__(parse_events(evlist, "cycles:u", NULL));
 
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index a787c5cb1331..46fadbbe1c3e 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -48,6 +48,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -3264,7 +3265,7 @@ static int set_maps(struct perf_script *script)
if (WARN_ONCE(script->allocated, "stats double allocation\n"))
return -EINVAL;
 
-   perf_evlist__set_maps(evlist, script->cpus, script->threads);
+   perf_evlist__set_maps(>core, script->cpus, script->threads);
 
if (perf_evlist__alloc_stats(evlist, true))
return -ENOMEM;
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 4a94ca131d56..14e4c970d16a 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -83,6 +83,7 @@
 #include 
 
 #include 
+#include 
 
 #define DEFAULT_SEPARATOR  " "
 #define FREEZE_ON_SMI_PATH "devices/cpu/freeze_on_smi"
@@ -1517,7 +1518,7 @@ static int set_maps(struct perf_stat *st)
if (WARN_ONCE(st->maps_allocated, "stats double allocation\n"))
return -EINVAL;
 
-   perf_evlist__set_maps(evsel_list, st->cpus, st->threads);
+   perf_evlist__set_maps(_list->core, st->cpus, st->threads);
 
if (perf_evlist__alloc_stats(evsel_list, true))
return -ENOMEM;
diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index 087ef76ea8fd..6a2308ef9868 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -5,6 +5,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 void perf_evlist__init(struct perf_evlist *evlist)
 {
@@ -12,11 +14,39 @@ void perf_evlist__init(struct perf_evlist *evlist)
evlist->nr_entries = 0;
 }
 
+static void __perf_evlist__propagate_maps(struct perf_evlist *evlist,
+ struct perf_evsel *evsel)
+{
+   /*
+* We already have cpus for evsel (via PMU sysfs) so
+* keep it, if there's no target cpu list defined.
+*/
+   if (!evsel->own_cpus || evlist->has_user_cpus) {
+   perf_cpu_map__put(evsel->cpus);
+   evsel->cpus = perf_cpu_map__get(evlist->cpus);
+   } else if (evsel->cpus != evsel->own_cpus) {
+   perf_cpu_map__put(evsel->cpus);
+   evsel->cpus = perf_cpu_map__get(evsel->own_cpus);
+   }
+
+   perf_thread_map__put(evsel->threads);
+   evsel->threads = perf_thread_map__get(evlist->threads);
+}
+
+static void perf_evlist__propagate_maps(struct perf_evlist *evlist)
+{
+   struct perf_evsel *evsel;
+
+   perf_evlist__for_each_evsel(evlist, evsel)
+   

[tip:perf/core] libperf: Adopt xyarray class from perf

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  4b247fa7314ce48282f3da400a9ffb7f3fd3f863
Gitweb: https://git.kernel.org/tip/4b247fa7314ce48282f3da400a9ffb7f3fd3f863
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:44 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:45 -0300

libperf: Adopt xyarray class from perf

Move the xyarray class from perf to libperf, because it's going to be
used in both.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-58-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-top.c| 1 -
 tools/perf/lib/Build| 1 +
 tools/perf/{util => lib/include/internal}/xyarray.h | 6 +++---
 tools/perf/{util => lib}/xyarray.c  | 4 ++--
 tools/perf/util/Build   | 1 -
 tools/perf/util/counts.h| 2 +-
 tools/perf/util/evsel.h | 2 +-
 tools/perf/util/python-ext-sources  | 1 -
 tools/perf/util/stat.h  | 1 -
 9 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index c69ddc67c672..1a4615a5f6c9 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -38,7 +38,6 @@
 #include 
 #include "util/parse-events.h"
 #include "util/cpumap.h"
-#include "util/xyarray.h"
 #include "util/sort.h"
 #include "util/string2.h"
 #include "util/term.h"
diff --git a/tools/perf/lib/Build b/tools/perf/lib/Build
index faf64db13e37..4f78ec0b4e10 100644
--- a/tools/perf/lib/Build
+++ b/tools/perf/lib/Build
@@ -4,6 +4,7 @@ libperf-y += threadmap.o
 libperf-y += evsel.o
 libperf-y += evlist.o
 libperf-y += zalloc.o
+libperf-y += xyarray.o
 
 $(OUTPUT)zalloc.o: ../../lib/zalloc.c FORCE
$(call rule_mkdir)
diff --git a/tools/perf/util/xyarray.h 
b/tools/perf/lib/include/internal/xyarray.h
similarity index 84%
rename from tools/perf/util/xyarray.h
rename to tools/perf/lib/include/internal/xyarray.h
index 7ffe562e7ae7..3bf70e4d474c 100644
--- a/tools/perf/util/xyarray.h
+++ b/tools/perf/lib/include/internal/xyarray.h
@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0 */
-#ifndef _PERF_XYARRAY_H_
-#define _PERF_XYARRAY_H_ 1
+#ifndef __LIBPERF_INTERNAL_XYARRAY_H
+#define __LIBPERF_INTERNAL_XYARRAY_H
 
 #include 
 
@@ -32,4 +32,4 @@ static inline int xyarray__max_x(struct xyarray *xy)
return xy->max_x;
 }
 
-#endif /* _PERF_XYARRAY_H_ */
+#endif /* __LIBPERF_INTERNAL_XYARRAY_H */
diff --git a/tools/perf/util/xyarray.c b/tools/perf/lib/xyarray.c
similarity index 95%
copy from tools/perf/util/xyarray.c
copy to tools/perf/lib/xyarray.c
index 86889ebc3514..dcd901d154bb 100644
--- a/tools/perf/util/xyarray.c
+++ b/tools/perf/lib/xyarray.c
@@ -1,8 +1,8 @@
 // SPDX-License-Identifier: GPL-2.0
-#include "xyarray.h"
+#include 
+#include 
 #include 
 #include 
-#include 
 
 struct xyarray *xyarray__new(int xlen, int ylen, size_t entry_size)
 {
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 08f670d21615..7abf05131889 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -69,7 +69,6 @@ perf-y += svghelper.o
 perf-y += sort.o
 perf-y += hist.o
 perf-y += util.o
-perf-y += xyarray.o
 perf-y += cpumap.o
 perf-y += cputopo.o
 perf-y += cgroup.o
diff --git a/tools/perf/util/counts.h b/tools/perf/util/counts.h
index 0f0cb2d8f70d..bbfac9ecf642 100644
--- a/tools/perf/util/counts.h
+++ b/tools/perf/util/counts.h
@@ -2,7 +2,7 @@
 #ifndef __PERF_COUNTS_H
 #define __PERF_COUNTS_H
 
-#include "xyarray.h"
+#include 
 
 struct perf_counts_values {
union {
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 57b5523b480c..1f9f66fe43f4 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -8,7 +8,7 @@
 #include 
 #include 
 #include 
-#include "xyarray.h"
+#include 
 #include "symbol_conf.h"
 #include "cpumap.h"
 #include "counts.h"
diff --git a/tools/perf/util/python-ext-sources 
b/tools/perf/util/python-ext-sources
index 2237bac9fadb..235bd9803390 100644
--- a/tools/perf/util/python-ext-sources
+++ b/tools/perf/util/python-ext-sources
@@ -20,7 +20,6 @@ util/namespaces.c
 ../lib/vsprintf.c
 util/thread_map.c
 util/util.c
-util/xyarray.c
 util/cgroup.c
 util/parse-branch-options.c
 util/rblist.c
diff --git a/tools/perf/util/stat.h b/tools/perf/util/stat.h
index 95b4de7a9d51..bcb376e1b3a7 100644
--- a/tools/perf/util/stat.h
+++ b/tools/perf/util/stat.h
@@ -8,7 +8,6 @@
 #include 
 #include 
 #include 
-#include "xyarray.h"
 #include "rblist.h"
 #include "perf.h"
 #include "event.h"


[tip:perf/core] libperf: Add threads to struct perf_evlist

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  03617c22e31f32cbf0e4797e216db898fb898d90
Gitweb: https://git.kernel.org/tip/03617c22e31f32cbf0e4797e216db898fb898d90
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:42 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:45 -0300

libperf: Add threads to struct perf_evlist

Move threads from tools/perf's evlist to libperf's perf_evlist struct.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-56-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-ftrace.c |  4 ++--
 tools/perf/builtin-kvm.c|  2 +-
 tools/perf/builtin-record.c |  4 ++--
 tools/perf/builtin-stat.c   | 18 +++
 tools/perf/builtin-top.c|  4 ++--
 tools/perf/builtin-trace.c  |  8 +++
 tools/perf/lib/include/internal/evlist.h|  2 ++
 tools/perf/tests/openat-syscall-tp-fields.c |  2 +-
 tools/perf/util/auxtrace.c  |  6 ++---
 tools/perf/util/evlist.c| 36 ++---
 tools/perf/util/evlist.h|  1 -
 tools/perf/util/stat.c  |  2 +-
 12 files changed, 45 insertions(+), 44 deletions(-)

diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index f481a870e728..ae1466aa3b26 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -156,9 +156,9 @@ static int set_tracing_pid(struct perf_ftrace *ftrace)
if (target__has_cpu(>target))
return 0;
 
-   for (i = 0; i < thread_map__nr(ftrace->evlist->threads); i++) {
+   for (i = 0; i < thread_map__nr(ftrace->evlist->core.threads); i++) {
scnprintf(buf, sizeof(buf), "%d",
- ftrace->evlist->threads->map[i]);
+ ftrace->evlist->core.threads->map[i]);
if (append_tracing_file("set_ftrace_pid", buf) < 0)
return -1;
}
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index b9c58a5c1ba6..69d16ac852c3 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -1450,7 +1450,7 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
perf_session__set_id_hdr_size(kvm->session);
ordered_events__set_copy_on_queue(>session->ordered_events, true);
machine__synthesize_threads(>session->machines.host, 
>opts.target,
-   kvm->evlist->threads, false, 1);
+   kvm->evlist->core.threads, false, 1);
err = kvm_live_open_events(kvm);
if (err)
goto out;
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index d4f0430c2f49..d31d7a5a1be3 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1275,7 +1275,7 @@ static int record__synthesize(struct record *rec, bool 
tail)
if (err)
goto out;
 
-   err = perf_event__synthesize_thread_map2(>tool, 
rec->evlist->threads,
+   err = perf_event__synthesize_thread_map2(>tool, 
rec->evlist->core.threads,
 process_synthesized_event,
NULL);
if (err < 0) {
@@ -1295,7 +1295,7 @@ static int record__synthesize(struct record *rec, bool 
tail)
if (err < 0)
pr_warning("Couldn't synthesize bpf events.\n");
 
-   err = __machine__synthesize_threads(machine, tool, >target, 
rec->evlist->threads,
+   err = __machine__synthesize_threads(machine, tool, >target, 
rec->evlist->core.threads,
process_synthesized_event, 
opts->sample_address,
1);
 out:
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index d81b0b1ef514..4a94ca131d56 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -263,7 +263,7 @@ static int read_single_counter(struct evsel *counter, int 
cpu,
  */
 static int read_counter(struct evsel *counter, struct timespec *rs)
 {
-   int nthreads = thread_map__nr(evsel_list->threads);
+   int nthreads = thread_map__nr(evsel_list->core.threads);
int ncpus, cpu, thread;
 
if (target__has_cpu() && !target__has_per_thread())
@@ -485,15 +485,15 @@ try_again:
 ui__warning("%s\n", msg);
 goto try_again;
} else if (target__has_per_thread() &&
-  evsel_list->threads &&
-  evsel_list->threads->err_thread != -1) {
+  evsel_list->core.threads &&
+  evsel_list->core.threads->err_thread 

[tip:perf/core] libperf: Add cpus to struct perf_evlist

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  f72f901d90b00aaf2a6c1335b41311687b3f2dec
Gitweb: https://git.kernel.org/tip/f72f901d90b00aaf2a6c1335b41311687b3f2dec
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:41 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:45 -0300

libperf: Add cpus to struct perf_evlist

Move cpus from tools/perf's evlist to libperf's perf_evlist struct.

Committer notes:

Fixed up this one:

  tools/perf/arch/arm/util/cs-etm.c

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-55-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/arch/arm/util/cs-etm.c|  8 +++
 tools/perf/arch/x86/util/intel-bts.c |  2 +-
 tools/perf/arch/x86/util/intel-pt.c  |  4 ++--
 tools/perf/builtin-ftrace.c  |  2 +-
 tools/perf/builtin-record.c  |  2 +-
 tools/perf/builtin-stat.c| 16 +++---
 tools/perf/builtin-top.c |  2 +-
 tools/perf/lib/include/internal/evlist.h |  9 +---
 tools/perf/util/auxtrace.c   |  2 +-
 tools/perf/util/evlist.c | 36 
 tools/perf/util/evlist.h |  1 -
 tools/perf/util/record.c |  6 +++---
 tools/perf/util/stat-display.c   |  6 +++---
 tools/perf/util/stat.c   |  2 +-
 tools/perf/util/top.c|  6 +++---
 15 files changed, 53 insertions(+), 51 deletions(-)

diff --git a/tools/perf/arch/arm/util/cs-etm.c 
b/tools/perf/arch/arm/util/cs-etm.c
index c25bc1528b96..5cb07e8cb296 100644
--- a/tools/perf/arch/arm/util/cs-etm.c
+++ b/tools/perf/arch/arm/util/cs-etm.c
@@ -155,7 +155,7 @@ static int cs_etm_set_option(struct auxtrace_record *itr,
 struct evsel *evsel, u32 option)
 {
int i, err = -EINVAL;
-   struct perf_cpu_map *event_cpus = evsel->evlist->cpus;
+   struct perf_cpu_map *event_cpus = evsel->evlist->core.cpus;
struct perf_cpu_map *online_cpus = perf_cpu_map__new(NULL);
 
/* Set option of each CPU we have */
@@ -253,7 +253,7 @@ static int cs_etm_recording_options(struct auxtrace_record 
*itr,
container_of(itr, struct cs_etm_recording, itr);
struct perf_pmu *cs_etm_pmu = ptr->cs_etm_pmu;
struct evsel *evsel, *cs_etm_evsel = NULL;
-   struct perf_cpu_map *cpus = evlist->cpus;
+   struct perf_cpu_map *cpus = evlist->core.cpus;
bool privileged = (geteuid() == 0 || perf_event_paranoid() < 0);
int err = 0;
 
@@ -489,7 +489,7 @@ cs_etm_info_priv_size(struct auxtrace_record *itr 
__maybe_unused,
 {
int i;
int etmv3 = 0, etmv4 = 0;
-   struct perf_cpu_map *event_cpus = evlist->cpus;
+   struct perf_cpu_map *event_cpus = evlist->core.cpus;
struct perf_cpu_map *online_cpus = perf_cpu_map__new(NULL);
 
/* cpu map is not empty, we have specific CPUs to work with */
@@ -636,7 +636,7 @@ static int cs_etm_info_fill(struct auxtrace_record *itr,
u32 offset;
u64 nr_cpu, type;
struct perf_cpu_map *cpu_map;
-   struct perf_cpu_map *event_cpus = session->evlist->cpus;
+   struct perf_cpu_map *event_cpus = session->evlist->core.cpus;
struct perf_cpu_map *online_cpus = perf_cpu_map__new(NULL);
struct cs_etm_recording *ptr =
container_of(itr, struct cs_etm_recording, itr);
diff --git a/tools/perf/arch/x86/util/intel-bts.c 
b/tools/perf/arch/x86/util/intel-bts.c
index d8a091266185..7b23318ebd7b 100644
--- a/tools/perf/arch/x86/util/intel-bts.c
+++ b/tools/perf/arch/x86/util/intel-bts.c
@@ -106,7 +106,7 @@ static int intel_bts_recording_options(struct 
auxtrace_record *itr,
container_of(itr, struct intel_bts_recording, itr);
struct perf_pmu *intel_bts_pmu = btsr->intel_bts_pmu;
struct evsel *evsel, *intel_bts_evsel = NULL;
-   const struct perf_cpu_map *cpus = evlist->cpus;
+   const struct perf_cpu_map *cpus = evlist->core.cpus;
bool privileged = geteuid() == 0 || perf_event_paranoid() < 0;
 
btsr->evlist = evlist;
diff --git a/tools/perf/arch/x86/util/intel-pt.c 
b/tools/perf/arch/x86/util/intel-pt.c
index aada6a2c456a..218a4e694618 100644
--- a/tools/perf/arch/x86/util/intel-pt.c
+++ b/tools/perf/arch/x86/util/intel-pt.c
@@ -365,7 +365,7 @@ static int intel_pt_info_fill(struct auxtrace_record *itr,
ui__warning("Intel Processor Trace: TSC not 
available\n");
}
 
-   per_cpu_mmaps = !cpu_map__empty(session->evlist->cpus);
+   per_cpu_mmaps = !cpu_map__empty(session->evlist->core.cpus);
 
auxtrace_info->type = PERF_AUXTRACE_INTEL_PT;
auxtrace_info->priv[INTEL_PT_PMU_TYPE] = intel_pt_pmu->type;
@@ -557,7 +557,7 @@ static int intel_pt_recording_options(struct 

[tip:perf/core] libperf: Add has_user_cpus to struct perf_evlist

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  ec903f264f0184a0aba62b42d7717c61f1893450
Gitweb: https://git.kernel.org/tip/ec903f264f0184a0aba62b42d7717c61f1893450
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:40 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:45 -0300

libperf: Add has_user_cpus to struct perf_evlist

Move has_user_cpus from tools/perf's evlist to libbperf's perf_evlist struct.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-54-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/include/internal/evlist.h | 1 +
 tools/perf/util/evlist.c | 4 ++--
 tools/perf/util/evlist.h | 1 -
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/perf/lib/include/internal/evlist.h 
b/tools/perf/lib/include/internal/evlist.h
index a12c712a9197..9964e4a9456e 100644
--- a/tools/perf/lib/include/internal/evlist.h
+++ b/tools/perf/lib/include/internal/evlist.h
@@ -5,6 +5,7 @@
 struct perf_evlist {
struct list_headentries;
int nr_entries;
+   boolhas_user_cpus;
 };
 
 #endif /* __LIBPERF_INTERNAL_EVLIST_H */
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 5ce8fc730453..23a8ead4512f 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -159,7 +159,7 @@ static void __perf_evlist__propagate_maps(struct evlist 
*evlist,
 * We already have cpus for evsel (via PMU sysfs) so
 * keep it, if there's no target cpu list defined.
 */
-   if (!evsel->core.own_cpus || evlist->has_user_cpus) {
+   if (!evsel->core.own_cpus || evlist->core.has_user_cpus) {
perf_cpu_map__put(evsel->core.cpus);
evsel->core.cpus = perf_cpu_map__get(evlist->cpus);
} else if (evsel->core.cpus != evsel->core.own_cpus) {
@@ -1095,7 +1095,7 @@ int perf_evlist__create_maps(struct evlist *evlist, 
struct target *target)
if (!cpus)
goto out_delete_threads;
 
-   evlist->has_user_cpus = !!target->cpu_list;
+   evlist->core.has_user_cpus = !!target->cpu_list;
 
perf_evlist__set_maps(evlist, cpus, threads);
 
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 17dd83021a79..35cca0242631 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -31,7 +31,6 @@ struct evlist {
int  nr_groups;
int  nr_mmaps;
bool enabled;
-   bool has_user_cpus;
size_t   mmap_len;
int  id_pos;
int  is_pos;


[tip:perf/core] libperf: Add own_cpus to struct perf_evsel

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  fe1f61b37ffada9fc7ec2c9d4ca5376b5a797dbc
Gitweb: https://git.kernel.org/tip/fe1f61b37ffada9fc7ec2c9d4ca5376b5a797dbc
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:38 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:45 -0300

libperf: Add own_cpus to struct perf_evsel

Move own_cpus from tools/perf's evsel to libbpf's perf_evsel.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-52-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/include/internal/evsel.h |  1 +
 tools/perf/tests/event_update.c |  4 ++--
 tools/perf/util/evlist.c|  6 +++---
 tools/perf/util/evsel.c |  4 ++--
 tools/perf/util/evsel.h |  1 -
 tools/perf/util/header.c| 10 +-
 tools/perf/util/parse-events.c  |  2 +-
 7 files changed, 14 insertions(+), 14 deletions(-)

diff --git a/tools/perf/lib/include/internal/evsel.h 
b/tools/perf/lib/include/internal/evsel.h
index b2c76e1a6244..d15d8ccfa3dc 100644
--- a/tools/perf/lib/include/internal/evsel.h
+++ b/tools/perf/lib/include/internal/evsel.h
@@ -11,6 +11,7 @@ struct perf_evsel {
struct list_head node;
struct perf_event_attr   attr;
struct perf_cpu_map *cpus;
+   struct perf_cpu_map *own_cpus;
 };
 
 #endif /* __LIBPERF_INTERNAL_EVSEL_H */
diff --git a/tools/perf/tests/event_update.c b/tools/perf/tests/event_update.c
index 2bc5145284c0..c37ff49c07c7 100644
--- a/tools/perf/tests/event_update.c
+++ b/tools/perf/tests/event_update.c
@@ -109,11 +109,11 @@ int test__event_update(struct test *test __maybe_unused, 
int subtest __maybe_unu
TEST_ASSERT_VAL("failed to synthesize attr update name",
!perf_event__synthesize_event_update_name(, 
evsel, process_event_name));
 
-   evsel->own_cpus = perf_cpu_map__new("1,2,3");
+   evsel->core.own_cpus = perf_cpu_map__new("1,2,3");
 
TEST_ASSERT_VAL("failed to synthesize attr update cpus",
!perf_event__synthesize_event_update_cpus(, 
evsel, process_event_cpus));
 
-   perf_cpu_map__put(evsel->own_cpus);
+   perf_cpu_map__put(evsel->core.own_cpus);
return 0;
 }
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 713968130d1d..d203305ac187 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -159,12 +159,12 @@ static void __perf_evlist__propagate_maps(struct evlist 
*evlist,
 * We already have cpus for evsel (via PMU sysfs) so
 * keep it, if there's no target cpu list defined.
 */
-   if (!evsel->own_cpus || evlist->has_user_cpus) {
+   if (!evsel->core.own_cpus || evlist->has_user_cpus) {
perf_cpu_map__put(evsel->core.cpus);
evsel->core.cpus = perf_cpu_map__get(evlist->cpus);
-   } else if (evsel->core.cpus != evsel->own_cpus) {
+   } else if (evsel->core.cpus != evsel->core.own_cpus) {
perf_cpu_map__put(evsel->core.cpus);
-   evsel->core.cpus = perf_cpu_map__get(evsel->own_cpus);
+   evsel->core.cpus = perf_cpu_map__get(evsel->core.own_cpus);
}
 
perf_thread_map__put(evsel->threads);
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 651f66ee902e..c5f6ee6d5f3b 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1125,7 +1125,7 @@ void perf_evsel__config(struct evsel *evsel, struct 
record_opts *opts,
attr->exclude_user   = 1;
}
 
-   if (evsel->own_cpus || evsel->unit)
+   if (evsel->core.own_cpus || evsel->unit)
evsel->core.attr.read_format |= PERF_FORMAT_ID;
 
/*
@@ -1326,7 +1326,7 @@ void perf_evsel__exit(struct evsel *evsel)
perf_evsel__free_config_terms(evsel);
cgroup__put(evsel->cgrp);
perf_cpu_map__put(evsel->core.cpus);
-   perf_cpu_map__put(evsel->own_cpus);
+   perf_cpu_map__put(evsel->core.own_cpus);
perf_thread_map__put(evsel->threads);
zfree(>group_name);
zfree(>name);
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 8ece5edf65ac..2eff837f10bd 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -123,7 +123,6 @@ struct evsel {
u64 db_id;
struct cgroup   *cgrp;
void*handler;
-   struct perf_cpu_map *own_cpus;
struct perf_thread_map *threads;
unsigned intsample_size;
int id_pos;
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index fa914ba8cd56..f97df418d661 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -3861,10 +3861,10 @@ perf_event__synthesize_event_update_cpus(struct 
perf_tool 

[tip:perf/core] libperf: Add threads to struct perf_evsel

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  af663bd01beaff8d9514199fcc1b239902a77de5
Gitweb: https://git.kernel.org/tip/af663bd01beaff8d9514199fcc1b239902a77de5
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:39 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:45 -0300

libperf: Add threads to struct perf_evsel

Move 'threads' from tools/perf's evsel to libperf's perf_evsel struct.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-53-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-record.c| 2 +-
 tools/perf/builtin-script.c| 4 ++--
 tools/perf/lib/include/internal/evsel.h| 2 ++
 tools/perf/util/evlist.c   | 6 +++---
 tools/perf/util/evsel.c| 4 ++--
 tools/perf/util/evsel.h| 1 -
 tools/perf/util/scripting-engines/trace-event-python.c | 2 +-
 tools/perf/util/stat-display.c | 6 +++---
 tools/perf/util/stat.c | 6 +++---
 9 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 090aaa2cf4b3..27ff899bed88 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -739,7 +739,7 @@ static int record__open(struct record *rec)
 
evlist__for_each_entry(evlist, pos) {
 try_again:
-   if (evsel__open(pos, pos->core.cpus, pos->threads) < 0) {
+   if (evsel__open(pos, pos->core.cpus, pos->core.threads) < 0) {
if (perf_evsel__fallback(pos, errno, msg, sizeof(msg))) 
{
if (verbose > 0)
ui__warning("%s\n", msg);
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 35f07dde5ad4..a787c5cb1331 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1899,7 +1899,7 @@ static struct scripting_ops   *scripting_ops;
 
 static void __process_stat(struct evsel *counter, u64 tstamp)
 {
-   int nthreads = thread_map__nr(counter->threads);
+   int nthreads = thread_map__nr(counter->core.threads);
int ncpus = perf_evsel__nr_cpus(counter);
int cpu, thread;
static int header_printed;
@@ -1921,7 +1921,7 @@ static void __process_stat(struct evsel *counter, u64 
tstamp)
 
printf("%3d %8d %15" PRIu64 " %15" PRIu64 " %15" PRIu64 
" %15" PRIu64 " %s\n",
counter->core.cpus->map[cpu],
-   thread_map__pid(counter->threads, thread),
+   thread_map__pid(counter->core.threads, thread),
counts->val,
counts->ena,
counts->run,
diff --git a/tools/perf/lib/include/internal/evsel.h 
b/tools/perf/lib/include/internal/evsel.h
index d15d8ccfa3dc..8340fd883a3d 100644
--- a/tools/perf/lib/include/internal/evsel.h
+++ b/tools/perf/lib/include/internal/evsel.h
@@ -6,12 +6,14 @@
 #include 
 
 struct perf_cpu_map;
+struct perf_thread_map;
 
 struct perf_evsel {
struct list_head node;
struct perf_event_attr   attr;
struct perf_cpu_map *cpus;
struct perf_cpu_map *own_cpus;
+   struct perf_thread_map  *threads;
 };
 
 #endif /* __LIBPERF_INTERNAL_EVSEL_H */
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index d203305ac187..5ce8fc730453 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -167,8 +167,8 @@ static void __perf_evlist__propagate_maps(struct evlist 
*evlist,
evsel->core.cpus = perf_cpu_map__get(evsel->core.own_cpus);
}
 
-   perf_thread_map__put(evsel->threads);
-   evsel->threads = perf_thread_map__get(evlist->threads);
+   perf_thread_map__put(evsel->core.threads);
+   evsel->core.threads = perf_thread_map__get(evlist->threads);
 }
 
 static void perf_evlist__propagate_maps(struct evlist *evlist)
@@ -1407,7 +1407,7 @@ int evlist__open(struct evlist *evlist)
perf_evlist__update_id_pos(evlist);
 
evlist__for_each_entry(evlist, evsel) {
-   err = evsel__open(evsel, evsel->core.cpus, evsel->threads);
+   err = evsel__open(evsel, evsel->core.cpus, evsel->core.threads);
if (err < 0)
goto out_err;
}
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index c5f6ee6d5f3b..f7758ce0dd5c 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1327,7 +1327,7 @@ void perf_evsel__exit(struct evsel *evsel)
cgroup__put(evsel->cgrp);
perf_cpu_map__put(evsel->core.cpus);

[tip:perf/core] libperf: Add cpus to struct perf_evsel

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  d400bd3abf2cc68df2df32047d3533faf690f404
Gitweb: https://git.kernel.org/tip/d400bd3abf2cc68df2df32047d3533faf690f404
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:37 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:45 -0300

libperf: Add cpus to struct perf_evsel

Mov the 'cpus' field from tools/perf's evsel to libperf's perf_evsel.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-51-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-record.c|  2 +-
 tools/perf/builtin-script.c|  2 +-
 tools/perf/lib/include/internal/evsel.h|  7 +--
 tools/perf/util/evlist.c   | 14 +++---
 tools/perf/util/evsel.c|  4 ++--
 tools/perf/util/evsel.h|  3 +--
 tools/perf/util/parse-events.c |  2 +-
 tools/perf/util/scripting-engines/trace-event-python.c |  2 +-
 tools/perf/util/stat-display.c |  2 +-
 9 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index b7d2c27c4164..090aaa2cf4b3 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -739,7 +739,7 @@ static int record__open(struct record *rec)
 
evlist__for_each_entry(evlist, pos) {
 try_again:
-   if (evsel__open(pos, pos->cpus, pos->threads) < 0) {
+   if (evsel__open(pos, pos->core.cpus, pos->threads) < 0) {
if (perf_evsel__fallback(pos, errno, msg, sizeof(msg))) 
{
if (verbose > 0)
ui__warning("%s\n", msg);
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 69133b35bbc1..35f07dde5ad4 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1920,7 +1920,7 @@ static void __process_stat(struct evsel *counter, u64 
tstamp)
counts = perf_counts(counter->counts, cpu, thread);
 
printf("%3d %8d %15" PRIu64 " %15" PRIu64 " %15" PRIu64 
" %15" PRIu64 " %s\n",
-   counter->cpus->map[cpu],
+   counter->core.cpus->map[cpu],
thread_map__pid(counter->threads, thread),
counts->val,
counts->ena,
diff --git a/tools/perf/lib/include/internal/evsel.h 
b/tools/perf/lib/include/internal/evsel.h
index c2e0bd104c94..b2c76e1a6244 100644
--- a/tools/perf/lib/include/internal/evsel.h
+++ b/tools/perf/lib/include/internal/evsel.h
@@ -5,9 +5,12 @@
 #include 
 #include 
 
+struct perf_cpu_map;
+
 struct perf_evsel {
-   struct list_headnode;
-   struct perf_event_attr  attr;
+   struct list_head node;
+   struct perf_event_attr   attr;
+   struct perf_cpu_map *cpus;
 };
 
 #endif /* __LIBPERF_INTERNAL_EVSEL_H */
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 67c67e9a38cd..713968130d1d 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -160,11 +160,11 @@ static void __perf_evlist__propagate_maps(struct evlist 
*evlist,
 * keep it, if there's no target cpu list defined.
 */
if (!evsel->own_cpus || evlist->has_user_cpus) {
-   perf_cpu_map__put(evsel->cpus);
-   evsel->cpus = perf_cpu_map__get(evlist->cpus);
-   } else if (evsel->cpus != evsel->own_cpus) {
-   perf_cpu_map__put(evsel->cpus);
-   evsel->cpus = perf_cpu_map__get(evsel->own_cpus);
+   perf_cpu_map__put(evsel->core.cpus);
+   evsel->core.cpus = perf_cpu_map__get(evlist->cpus);
+   } else if (evsel->core.cpus != evsel->own_cpus) {
+   perf_cpu_map__put(evsel->core.cpus);
+   evsel->core.cpus = perf_cpu_map__get(evsel->own_cpus);
}
 
perf_thread_map__put(evsel->threads);
@@ -786,7 +786,7 @@ static int perf_evlist__mmap_per_evsel(struct evlist 
*evlist, int idx,
if (evsel->system_wide && thread)
continue;
 
-   cpu = cpu_map__idx(evsel->cpus, evlist_cpu);
+   cpu = cpu_map__idx(evsel->core.cpus, evlist_cpu);
if (cpu == -1)
continue;
 
@@ -1407,7 +1407,7 @@ int evlist__open(struct evlist *evlist)
perf_evlist__update_id_pos(evlist);
 
evlist__for_each_entry(evlist, evsel) {
-   err = evsel__open(evsel, evsel->cpus, evsel->threads);
+   err = evsel__open(evsel, evsel->core.cpus, evsel->threads);
if (err < 0)
goto out_err;
  

[tip:perf/core] libperf: Add perf_evsel__delete() function

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  b9358ee95ec65fe7e2c4dc12e4d3da4aeee0d8fc
Gitweb: https://git.kernel.org/tip/b9358ee95ec65fe7e2c4dc12e4d3da4aeee0d8fc
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:36 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:45 -0300

libperf: Add perf_evsel__delete() function

Add the perf_evsel__delete() function to delete a perf_evsel instance.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-50-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/evsel.c  | 6 ++
 tools/perf/lib/include/perf/evsel.h | 1 +
 tools/perf/lib/libperf.map  | 1 +
 3 files changed, 8 insertions(+)

diff --git a/tools/perf/lib/evsel.c b/tools/perf/lib/evsel.c
index 8e91738c5c38..ddc3ad447bfb 100644
--- a/tools/perf/lib/evsel.c
+++ b/tools/perf/lib/evsel.c
@@ -3,6 +3,7 @@
 #include 
 #include 
 #include 
+#include 
 
 void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *attr)
 {
@@ -19,3 +20,8 @@ struct perf_evsel *perf_evsel__new(struct perf_event_attr 
*attr)
 
return evsel;
 }
+
+void perf_evsel__delete(struct perf_evsel *evsel)
+{
+   free(evsel);
+}
diff --git a/tools/perf/lib/include/perf/evsel.h 
b/tools/perf/lib/include/perf/evsel.h
index 21b66fc1937f..a57efc0f5c8b 100644
--- a/tools/perf/lib/include/perf/evsel.h
+++ b/tools/perf/lib/include/perf/evsel.h
@@ -10,5 +10,6 @@ struct perf_event_attr;
 LIBPERF_API void perf_evsel__init(struct perf_evsel *evsel,
  struct perf_event_attr *attr);
 LIBPERF_API struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr);
+LIBPERF_API void perf_evsel__delete(struct perf_evsel *evsel);
 
 #endif /* __LIBPERF_EVSEL_H */
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index 153e77cd6739..28ed04cbd223 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -12,6 +12,7 @@ LIBPERF_0.0.1 {
perf_thread_map__get;
perf_thread_map__put;
perf_evsel__new;
+   perf_evsel__delete;
perf_evsel__init;
perf_evlist__new;
perf_evlist__delete;


[tip:perf/core] libperf: Add perf_evlist__delete() function

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  57f0c3b6e13ae822ba02dd37563c8e6956a47141
Gitweb: https://git.kernel.org/tip/57f0c3b6e13ae822ba02dd37563c8e6956a47141
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:35 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:45 -0300

libperf: Add perf_evlist__delete() function

Add the perf_evlist__delete() function to delete a perf_evlist instance.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-49-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/evlist.c  | 6 ++
 tools/perf/lib/include/perf/evlist.h | 1 +
 tools/perf/lib/libperf.map   | 1 +
 3 files changed, 8 insertions(+)

diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index 979ee423490f..087ef76ea8fd 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -4,6 +4,7 @@
 #include 
 #include 
 #include 
+#include 
 
 void perf_evlist__init(struct perf_evlist *evlist)
 {
@@ -54,3 +55,8 @@ perf_evlist__next(struct perf_evlist *evlist, struct 
perf_evsel *prev)
 
return next;
 }
+
+void perf_evlist__delete(struct perf_evlist *evlist)
+{
+   free(evlist);
+}
diff --git a/tools/perf/lib/include/perf/evlist.h 
b/tools/perf/lib/include/perf/evlist.h
index 5092b622935b..9a126fd0773c 100644
--- a/tools/perf/lib/include/perf/evlist.h
+++ b/tools/perf/lib/include/perf/evlist.h
@@ -13,6 +13,7 @@ LIBPERF_API void perf_evlist__add(struct perf_evlist *evlist,
 LIBPERF_API void perf_evlist__remove(struct perf_evlist *evlist,
 struct perf_evsel *evsel);
 LIBPERF_API struct perf_evlist *perf_evlist__new(void);
+LIBPERF_API void perf_evlist__delete(struct perf_evlist *evlist);
 LIBPERF_API struct perf_evsel* perf_evlist__next(struct perf_evlist *evlist,
 struct perf_evsel *evsel);
 
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index c0968226f7b6..153e77cd6739 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -14,6 +14,7 @@ LIBPERF_0.0.1 {
perf_evsel__new;
perf_evsel__init;
perf_evlist__new;
+   perf_evlist__delete;
perf_evlist__init;
perf_evlist__add;
perf_evlist__remove;


[tip:perf/core] libperf: Add perf_evlist__for_each_evsel() iterator

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  651bf38ce10a65ef8efb901fc33187127c023e97
Gitweb: https://git.kernel.org/tip/651bf38ce10a65ef8efb901fc33187127c023e97
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:34 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:45 -0300

libperf: Add perf_evlist__for_each_evsel() iterator

Add a perf_evlist__for_each_evsel() macro to iterate perf_evsel objects
in evlist.

Introduce the perf_evlist__next() function to do that without exposing
'struct perf_evlist' internals.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-48-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/evlist.c  | 20 
 tools/perf/lib/include/perf/evlist.h |  7 +++
 tools/perf/lib/libperf.map   |  1 +
 3 files changed, 28 insertions(+)

diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index 0517deb4cb1c..979ee423490f 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -34,3 +34,23 @@ struct perf_evlist *perf_evlist__new(void)
 
return evlist;
 }
+
+struct perf_evsel *
+perf_evlist__next(struct perf_evlist *evlist, struct perf_evsel *prev)
+{
+   struct perf_evsel *next;
+
+   if (!prev) {
+   next = list_first_entry(>entries,
+   struct perf_evsel,
+   node);
+   } else {
+   next = list_next_entry(prev, node);
+   }
+
+   /* Empty list is noticed here so don't need checking on entry. */
+   if (>node == >entries)
+   return NULL;
+
+   return next;
+}
diff --git a/tools/perf/lib/include/perf/evlist.h 
b/tools/perf/lib/include/perf/evlist.h
index 7255a60869a1..5092b622935b 100644
--- a/tools/perf/lib/include/perf/evlist.h
+++ b/tools/perf/lib/include/perf/evlist.h
@@ -13,5 +13,12 @@ LIBPERF_API void perf_evlist__add(struct perf_evlist *evlist,
 LIBPERF_API void perf_evlist__remove(struct perf_evlist *evlist,
 struct perf_evsel *evsel);
 LIBPERF_API struct perf_evlist *perf_evlist__new(void);
+LIBPERF_API struct perf_evsel* perf_evlist__next(struct perf_evlist *evlist,
+struct perf_evsel *evsel);
+
+#define perf_evlist__for_each_evsel(evlist, pos)   \
+   for ((pos) = perf_evlist__next((evlist), NULL); \
+(pos) != NULL; \
+(pos) = perf_evlist__next((evlist), (pos)))
 
 #endif /* __LIBPERF_EVLIST_H */
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index e3eac9b60726..c0968226f7b6 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -17,6 +17,7 @@ LIBPERF_0.0.1 {
perf_evlist__init;
perf_evlist__add;
perf_evlist__remove;
+   perf_evlist__next;
local:
*;
 };


[tip:perf/core] libperf: Add perf_evsel__new() function

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  63bd5dfa69658c459d08a6ee6bfebbd4a91cf24d
Gitweb: https://git.kernel.org/tip/63bd5dfa69658c459d08a6ee6bfebbd4a91cf24d
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:33 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:45 -0300

libperf: Add perf_evsel__new() function

Add a perf_evsel__new() function to create and init a perf_evsel struct
dynamicaly.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-47-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/evsel.c  | 11 +++
 tools/perf/lib/include/perf/evsel.h |  1 +
 tools/perf/lib/libperf.map  |  1 +
 3 files changed, 13 insertions(+)

diff --git a/tools/perf/lib/evsel.c b/tools/perf/lib/evsel.c
index 17cba35becc7..8e91738c5c38 100644
--- a/tools/perf/lib/evsel.c
+++ b/tools/perf/lib/evsel.c
@@ -2,9 +2,20 @@
 #include 
 #include 
 #include 
+#include 
 
 void perf_evsel__init(struct perf_evsel *evsel, struct perf_event_attr *attr)
 {
INIT_LIST_HEAD(>node);
evsel->attr = *attr;
 }
+
+struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr)
+{
+   struct perf_evsel *evsel = zalloc(sizeof(*evsel));
+
+   if (evsel != NULL)
+   perf_evsel__init(evsel, attr);
+
+   return evsel;
+}
diff --git a/tools/perf/lib/include/perf/evsel.h 
b/tools/perf/lib/include/perf/evsel.h
index 295583b89f46..21b66fc1937f 100644
--- a/tools/perf/lib/include/perf/evsel.h
+++ b/tools/perf/lib/include/perf/evsel.h
@@ -9,5 +9,6 @@ struct perf_event_attr;
 
 LIBPERF_API void perf_evsel__init(struct perf_evsel *evsel,
  struct perf_event_attr *attr);
+LIBPERF_API struct perf_evsel *perf_evsel__new(struct perf_event_attr *attr);
 
 #endif /* __LIBPERF_EVSEL_H */
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index 5e685d6c7a95..e3eac9b60726 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -11,6 +11,7 @@ LIBPERF_0.0.1 {
perf_thread_map__comm;
perf_thread_map__get;
perf_thread_map__put;
+   perf_evsel__new;
perf_evsel__init;
perf_evlist__new;
perf_evlist__init;


[tip:perf/core] libperf: Add perf_evlist__new() function

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  634912d61ccc6bfeebb87716c276fbea20f63bdc
Gitweb: https://git.kernel.org/tip/634912d61ccc6bfeebb87716c276fbea20f63bdc
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:32 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:45 -0300

libperf: Add perf_evlist__new() function

Add perf_evlist__new() function to create and init a perf_evlist struct
dynamicaly.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-46-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/evlist.c  | 11 +++
 tools/perf/lib/include/perf/evlist.h |  1 +
 tools/perf/lib/libperf.map   |  1 +
 3 files changed, 13 insertions(+)

diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index 1b27fd2de9b9..0517deb4cb1c 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -3,6 +3,7 @@
 #include 
 #include 
 #include 
+#include 
 
 void perf_evlist__init(struct perf_evlist *evlist)
 {
@@ -23,3 +24,13 @@ void perf_evlist__remove(struct perf_evlist *evlist,
list_del_init(>node);
evlist->nr_entries -= 1;
 }
+
+struct perf_evlist *perf_evlist__new(void)
+{
+   struct perf_evlist *evlist = zalloc(sizeof(*evlist));
+
+   if (evlist != NULL)
+   perf_evlist__init(evlist);
+
+   return evlist;
+}
diff --git a/tools/perf/lib/include/perf/evlist.h 
b/tools/perf/lib/include/perf/evlist.h
index e0c87995c6ff..7255a60869a1 100644
--- a/tools/perf/lib/include/perf/evlist.h
+++ b/tools/perf/lib/include/perf/evlist.h
@@ -12,5 +12,6 @@ LIBPERF_API void perf_evlist__add(struct perf_evlist *evlist,
  struct perf_evsel *evsel);
 LIBPERF_API void perf_evlist__remove(struct perf_evlist *evlist,
 struct perf_evsel *evsel);
+LIBPERF_API struct perf_evlist *perf_evlist__new(void);
 
 #endif /* __LIBPERF_EVLIST_H */
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index e38473a8f32f..5e685d6c7a95 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -12,6 +12,7 @@ LIBPERF_0.0.1 {
perf_thread_map__get;
perf_thread_map__put;
perf_evsel__init;
+   perf_evlist__new;
perf_evlist__init;
perf_evlist__add;
perf_evlist__remove;


[tip:perf/core] libperf: Move zalloc.o into libperf

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  93bce7e5bfcd570e9250c974b5c2c91d6b8332ef
Gitweb: https://git.kernel.org/tip/93bce7e5bfcd570e9250c974b5c2c91d6b8332ef
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:31 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:45 -0300

libperf: Move zalloc.o into libperf

We need it in both perf and libperf, thus moving it to libperf.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-45-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/Build   | 5 +
 tools/perf/util/Build  | 5 -
 tools/perf/util/python-ext-sources | 1 -
 3 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/tools/perf/lib/Build b/tools/perf/lib/Build
index b27c1543b046..faf64db13e37 100644
--- a/tools/perf/lib/Build
+++ b/tools/perf/lib/Build
@@ -3,3 +3,8 @@ libperf-y += cpumap.o
 libperf-y += threadmap.o
 libperf-y += evsel.o
 libperf-y += evlist.o
+libperf-y += zalloc.o
+
+$(OUTPUT)zalloc.o: ../../lib/zalloc.c FORCE
+   $(call rule_mkdir)
+   $(call if_changed_dep,cc_o_c)
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index 14f812bb07a7..08f670d21615 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -26,7 +26,6 @@ perf-y += rbtree.o
 perf-y += libstring.o
 perf-y += bitmap.o
 perf-y += hweight.o
-perf-y += zalloc.o
 perf-y += smt.o
 perf-y += strbuf.o
 perf-y += string.o
@@ -243,7 +242,3 @@ $(OUTPUT)util/hweight.o: ../lib/hweight.c FORCE
 $(OUTPUT)util/vsprintf.o: ../lib/vsprintf.c FORCE
$(call rule_mkdir)
$(call if_changed_dep,cc_o_c)
-
-$(OUTPUT)util/zalloc.o: ../lib/zalloc.c FORCE
-   $(call rule_mkdir)
-   $(call if_changed_dep,cc_o_c)
diff --git a/tools/perf/util/python-ext-sources 
b/tools/perf/util/python-ext-sources
index ceb8afdf9a89..2237bac9fadb 100644
--- a/tools/perf/util/python-ext-sources
+++ b/tools/perf/util/python-ext-sources
@@ -18,7 +18,6 @@ util/namespaces.c
 ../lib/hweight.c
 ../lib/string.c
 ../lib/vsprintf.c
-../lib/zalloc.c
 util/thread_map.c
 util/util.c
 util/xyarray.c


[tip:perf/core] libperf: Add perf_cpu_map__new()/perf_cpu_map__read() functions

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  9c3516d1b850ea938b074df33e4c86d721c77720
Gitweb: https://git.kernel.org/tip/9c3516d1b850ea938b074df33e4c86d721c77720
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:30 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:45 -0300

libperf: Add perf_cpu_map__new()/perf_cpu_map__read() functions

Moving the following functions from tools/perf:

  cpu_map__new()
  cpu_map__read()

to libperf with the following names:

  perf_cpu_map__new()
  perf_cpu_map__read()

Committer notes:

Fixed up this one:

  tools/perf/arch/arm/util/cs-etm.c

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-44-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/arch/arm/util/cs-etm.c|   6 +-
 tools/perf/arch/x86/tests/perf-time-to-tsc.c |   3 +-
 tools/perf/bench/epoll-ctl.c |   3 +-
 tools/perf/bench/epoll-wait.c|   3 +-
 tools/perf/bench/futex-hash.c|   3 +-
 tools/perf/bench/futex-lock-pi.c |   3 +-
 tools/perf/bench/futex-requeue.c |   3 +-
 tools/perf/bench/futex-wake-parallel.c   |   2 +-
 tools/perf/bench/futex-wake.c|   3 +-
 tools/perf/builtin-ftrace.c  |   2 +-
 tools/perf/builtin-sched.c   |   4 +-
 tools/perf/lib/cpumap.c  | 184 +++
 tools/perf/lib/include/internal/cpumap.h |   4 +
 tools/perf/lib/include/perf/cpumap.h |   3 +
 tools/perf/lib/libperf.map   |   2 +
 tools/perf/tests/bitmap.c|   3 +-
 tools/perf/tests/code-reading.c  |   5 +-
 tools/perf/tests/cpumap.c|   7 +-
 tools/perf/tests/event-times.c   |   9 +-
 tools/perf/tests/event_update.c  |   3 +-
 tools/perf/tests/keep-tracking.c |   3 +-
 tools/perf/tests/mem2node.c  |   3 +-
 tools/perf/tests/mmap-basic.c|   3 +-
 tools/perf/tests/openat-syscall-all-cpus.c   |   2 +-
 tools/perf/tests/switch-tracking.c   |   5 +-
 tools/perf/tests/topology.c  |   3 +-
 tools/perf/util/cpumap.c | 181 +-
 tools/perf/util/cpumap.h |   2 -
 tools/perf/util/cputopo.c|   5 +-
 tools/perf/util/evlist.c |   5 +-
 tools/perf/util/header.c |   3 +-
 tools/perf/util/parse-events.c   |   3 +-
 tools/perf/util/pmu.c|   3 +-
 tools/perf/util/python.c |   3 +-
 tools/perf/util/record.c |   7 +-
 tools/perf/util/session.c|   3 +-
 tools/perf/util/svghelper.c  |   3 +-
 37 files changed, 265 insertions(+), 227 deletions(-)

diff --git a/tools/perf/arch/arm/util/cs-etm.c 
b/tools/perf/arch/arm/util/cs-etm.c
index f5aafdec7f50..c25bc1528b96 100644
--- a/tools/perf/arch/arm/util/cs-etm.c
+++ b/tools/perf/arch/arm/util/cs-etm.c
@@ -156,7 +156,7 @@ static int cs_etm_set_option(struct auxtrace_record *itr,
 {
int i, err = -EINVAL;
struct perf_cpu_map *event_cpus = evsel->evlist->cpus;
-   struct perf_cpu_map *online_cpus = cpu_map__new(NULL);
+   struct perf_cpu_map *online_cpus = perf_cpu_map__new(NULL);
 
/* Set option of each CPU we have */
for (i = 0; i < cpu__max_cpu(); i++) {
@@ -490,7 +490,7 @@ cs_etm_info_priv_size(struct auxtrace_record *itr 
__maybe_unused,
int i;
int etmv3 = 0, etmv4 = 0;
struct perf_cpu_map *event_cpus = evlist->cpus;
-   struct perf_cpu_map *online_cpus = cpu_map__new(NULL);
+   struct perf_cpu_map *online_cpus = perf_cpu_map__new(NULL);
 
/* cpu map is not empty, we have specific CPUs to work with */
if (!cpu_map__empty(event_cpus)) {
@@ -637,7 +637,7 @@ static int cs_etm_info_fill(struct auxtrace_record *itr,
u64 nr_cpu, type;
struct perf_cpu_map *cpu_map;
struct perf_cpu_map *event_cpus = session->evlist->cpus;
-   struct perf_cpu_map *online_cpus = cpu_map__new(NULL);
+   struct perf_cpu_map *online_cpus = perf_cpu_map__new(NULL);
struct cs_etm_recording *ptr =
container_of(itr, struct cs_etm_recording, itr);
struct perf_pmu *cs_etm_pmu = ptr->cs_etm_pmu;
diff --git a/tools/perf/arch/x86/tests/perf-time-to-tsc.c 
b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
index 07129e007eb0..261bdd680651 100644
--- a/tools/perf/arch/x86/tests/perf-time-to-tsc.c
+++ b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
@@ -5,6 +5,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "parse-events.h"
 #include "evlist.h"
@@ -65,7 +66,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, 
int subtest __maybe
 

[tip:perf/core] libperf: Add nr_entries to struct perf_evlist

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  6484d2f9dc3ecbf13f07100f7f771d1d779eda04
Gitweb: https://git.kernel.org/tip/6484d2f9dc3ecbf13f07100f7f771d1d779eda04
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:28 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:45 -0300

libperf: Add nr_entries to struct perf_evlist

Move nr_entries count from 'struct perf' to into perf_evlist struct.

Committer notes:

Fix tools/perf/arch/s390/util/auxtrace.c case. And also the comment in
tools/perf/util/annotate.h.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-42-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/arch/s390/util/auxtrace.c |  2 +-
 tools/perf/builtin-record.c  |  4 +-
 tools/perf/builtin-stat.c|  4 +-
 tools/perf/builtin-top.c | 12 ++---
 tools/perf/builtin-trace.c   |  4 +-
 tools/perf/lib/evlist.c  |  3 ++
 tools/perf/lib/include/internal/evlist.h |  1 +
 tools/perf/tests/parse-events.c  | 76 
 tools/perf/ui/browsers/annotate.c|  2 +-
 tools/perf/ui/browsers/hists.c   |  2 +-
 tools/perf/util/annotate.c   |  2 +-
 tools/perf/util/annotate.h   |  2 +-
 tools/perf/util/evlist.c | 26 +--
 tools/perf/util/evlist.h |  1 -
 tools/perf/util/header.c |  4 +-
 tools/perf/util/parse-events.c   |  4 +-
 tools/perf/util/python.c |  8 ++--
 tools/perf/util/record.c |  2 +-
 tools/perf/util/sort.c   |  2 +-
 tools/perf/util/top.c|  2 +-
 20 files changed, 83 insertions(+), 80 deletions(-)

diff --git a/tools/perf/arch/s390/util/auxtrace.c 
b/tools/perf/arch/s390/util/auxtrace.c
index 833f60fa9c5a..480ada281bdb 100644
--- a/tools/perf/arch/s390/util/auxtrace.c
+++ b/tools/perf/arch/s390/util/auxtrace.c
@@ -90,7 +90,7 @@ struct auxtrace_record *auxtrace_record__init(struct evlist 
*evlist,
int diagnose = 0;
 
*err = 0;
-   if (evlist->nr_entries == 0)
+   if (evlist->core.nr_entries == 0)
return NULL;
 
evlist__for_each_entry(evlist, pos) {
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 17bb0a536da3..778e46417f6b 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1375,7 +1375,7 @@ static int __cmd_record(struct record *rec, int argc, 
const char **argv)
 * because we synthesize event name through the pipe
 * and need the id for that.
 */
-   if (data->is_pipe && rec->evlist->nr_entries == 1)
+   if (data->is_pipe && rec->evlist->core.nr_entries == 1)
rec->opts.sample_id = true;
 
if (record__open(rec) != 0) {
@@ -2386,7 +2386,7 @@ int cmd_record(int argc, const char **argv)
if (record.opts.overwrite)
record.opts.tail_synthesize = true;
 
-   if (rec->evlist->nr_entries == 0 &&
+   if (rec->evlist->core.nr_entries == 0 &&
__perf_evlist__add_default(rec->evlist, !record.opts.no_samples) < 
0) {
pr_err("Not enough memory for event selector list\n");
goto out;
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 39bd73d0e06e..3ba184f2e64f 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -1366,7 +1366,7 @@ static int add_default_attributes(void)
free(str);
}
 
-   if (!evsel_list->nr_entries) {
+   if (!evsel_list->core.nr_entries) {
if (target__has_cpu())
default_attrs0[0].config = PERF_COUNT_SW_CPU_CLOCK;
 
@@ -1683,7 +1683,7 @@ static void setup_system_wide(int forks)
return;
}
 
-   if (evsel_list->nr_entries)
+   if (evsel_list->core.nr_entries)
target.system_wide = true;
}
 }
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index b103f1ba01cb..3291eff13e28 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -129,7 +129,7 @@ static int perf_top__parse_source(struct perf_top *top, 
struct hist_entry *he)
notes = symbol__annotation(sym);
pthread_mutex_lock(>lock);
 
-   if (!symbol__hists(sym, top->evlist->nr_entries)) {
+   if (!symbol__hists(sym, top->evlist->core.nr_entries)) {
pthread_mutex_unlock(>lock);
pr_err("Not enough memory for annotating '%s' symbol!\n",
   sym->name);
@@ -404,7 +404,7 @@ static void perf_top__print_mapped_keys(struct perf_top 
*top)
fprintf(stdout, "\t[d] display refresh delay. 
\t(%d)\n", top->delay_secs);
fprintf(stdout, "\t[e] 

[tip:perf/core] libperf: Add perf_evlist__remove() function

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  52e22fb8af779e1a26b1cbde1db2f82f78b3ae68
Gitweb: https://git.kernel.org/tip/52e22fb8af779e1a26b1cbde1db2f82f78b3ae68
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:27 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:44 -0300

libperf: Add perf_evlist__remove() function

Adding perf_evlist__remove() function to remove a perf_evsel from
a perf_evlist struct.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-41-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/evlist.c  | 6 ++
 tools/perf/lib/include/perf/evlist.h | 2 ++
 tools/perf/lib/libperf.map   | 1 +
 tools/perf/util/evlist.c | 2 +-
 4 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index e5f187fa4e57..023fe4b44131 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -14,3 +14,9 @@ void perf_evlist__add(struct perf_evlist *evlist,
 {
list_add_tail(>node, >entries);
 }
+
+void perf_evlist__remove(struct perf_evlist *evlist,
+struct perf_evsel *evsel)
+{
+   list_del_init(>node);
+}
diff --git a/tools/perf/lib/include/perf/evlist.h 
b/tools/perf/lib/include/perf/evlist.h
index 6992568b14a0..e0c87995c6ff 100644
--- a/tools/perf/lib/include/perf/evlist.h
+++ b/tools/perf/lib/include/perf/evlist.h
@@ -10,5 +10,7 @@ struct perf_evsel;
 LIBPERF_API void perf_evlist__init(struct perf_evlist *evlist);
 LIBPERF_API void perf_evlist__add(struct perf_evlist *evlist,
  struct perf_evsel *evsel);
+LIBPERF_API void perf_evlist__remove(struct perf_evlist *evlist,
+struct perf_evsel *evsel);
 
 #endif /* __LIBPERF_EVLIST_H */
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index 06ccf31eb24d..168339f89a2e 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -12,6 +12,7 @@ LIBPERF_0.0.1 {
perf_evsel__init;
perf_evlist__init;
perf_evlist__add;
+   perf_evlist__remove;
local:
*;
 };
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index f2b86f49ab8d..9b0108c23010 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -194,7 +194,7 @@ void evlist__add(struct evlist *evlist, struct evsel *entry)
 void evlist__remove(struct evlist *evlist, struct evsel *evsel)
 {
evsel->evlist = NULL;
-   list_del_init(>core.node);
+   perf_evlist__remove(>core, >core);
evlist->nr_entries -= 1;
 }
 


[tip:perf/core] libperf: Add perf_evlist__add() function

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  9a5edde6d3a6fb26101406534f7a5d09a9fcd362
Gitweb: https://git.kernel.org/tip/9a5edde6d3a6fb26101406534f7a5d09a9fcd362
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:26 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:44 -0300

libperf: Add perf_evlist__add() function

Add the perf_evlist__add() function to add a perf_evsel in a perf_evlist
struct.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-40-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/evlist.c  | 7 +++
 tools/perf/lib/include/perf/evlist.h | 3 +++
 tools/perf/lib/libperf.map   | 1 +
 tools/perf/util/evlist.c | 2 +-
 4 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index fdc8c1894b37..e5f187fa4e57 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -2,8 +2,15 @@
 #include 
 #include 
 #include 
+#include 
 
 void perf_evlist__init(struct perf_evlist *evlist)
 {
INIT_LIST_HEAD(>entries);
 }
+
+void perf_evlist__add(struct perf_evlist *evlist,
+ struct perf_evsel *evsel)
+{
+   list_add_tail(>node, >entries);
+}
diff --git a/tools/perf/lib/include/perf/evlist.h 
b/tools/perf/lib/include/perf/evlist.h
index 1ddfcca0bd01..6992568b14a0 100644
--- a/tools/perf/lib/include/perf/evlist.h
+++ b/tools/perf/lib/include/perf/evlist.h
@@ -5,7 +5,10 @@
 #include 
 
 struct perf_evlist;
+struct perf_evsel;
 
 LIBPERF_API void perf_evlist__init(struct perf_evlist *evlist);
+LIBPERF_API void perf_evlist__add(struct perf_evlist *evlist,
+ struct perf_evsel *evsel);
 
 #endif /* __LIBPERF_EVLIST_H */
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index 5ca6ff6fcdfa..06ccf31eb24d 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -11,6 +11,7 @@ LIBPERF_0.0.1 {
perf_thread_map__put;
perf_evsel__init;
perf_evlist__init;
+   perf_evlist__add;
local:
*;
 };
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index f4aa6cf80559..f2b86f49ab8d 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -180,8 +180,8 @@ static void perf_evlist__propagate_maps(struct evlist 
*evlist)
 
 void evlist__add(struct evlist *evlist, struct evsel *entry)
 {
+   perf_evlist__add(>core, >core);
entry->evlist = evlist;
-   list_add_tail(>core.node, >core.entries);
entry->idx = evlist->nr_entries;
entry->tracking = !entry->idx;
 


[tip:perf/core] libperf: Add perf_evlist__init() function

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  4562a7393996bb28bf629277903a561bfefea177
Gitweb: https://git.kernel.org/tip/4562a7393996bb28bf629277903a561bfefea177
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:25 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:44 -0300

libperf: Add perf_evlist__init() function

Add the perf_evlist__init() function to initialize a perf_evlist struct.

Committer testing:

Fix a change in init ordering that was causing this backtrace:

  (gdb) run stat sleep 1
  Starting program: /root/bin/perf stat sleep 1
  Program received signal SIGSEGV, Segmentation fault.
  0x004f6b55 in __perf_evlist__propagate_maps (evlist=0xbb34c0, 
evsel=0x0) at util/evlist.c:161
  161   if (!evsel->own_cpus || evlist->has_user_cpus) {
  Missing separate debuginfos, use: dnf debuginfo-install 
bzip2-libs-1.0.6-29.fc30.x86_64 elfutils-libelf-0.176-3.fc30.x86_64 
elfutils-libs-0.176-3.fc30.x86_64 glib2-2.60.4-1.fc30.x86_64 
libbabeltrace-1.5.6-2.fc30.x86_64 libgcc-9.1.1-1.fc30.x86_64 
libunwind-1.3.1-2.fc30.x86_64 libuuid-2.33.2-1.fc30.x86_64 
libxcrypt-4.4.6-2.fc30.x86_64 libzstd-1.4.0-1.fc30.x86_64 
numactl-libs-2.0.12-2.fc30.x86_64 pcre-8.43-2.fc30.x86_64 
perl-libs-5.28.2-436.fc30.x86_64 popt-1.16-17.fc30.x86_64 
python2-libs-2.7.16-2.fc30.x86_64 slang-2.3.2-5.fc30.x86_64 
xz-libs-5.2.4-5.fc30.x86_64 zlib-1.2.11-15.fc30.x86_64
  (gdb) bt
  #0  0x004f6b55 in __perf_evlist__propagate_maps (evlist=0xbb34c0, 
evsel=0x0) at util/evlist.c:161
  #1  0x004f6c7a in perf_evlist__propagate_maps (evlist=0xbb34c0) at 
util/evlist.c:178
  #2  0x004f955e in perf_evlist__set_maps (evlist=0xbb34c0, cpus=0x0, 
threads=0x0) at util/evlist.c:1128
  #3  0x004f66f8 in evlist__init (evlist=0xbb34c0, cpus=0x0, 
threads=0x0) at util/evlist.c:52
  #4  0x004f6790 in evlist__new () at util/evlist.c:64
  #5  0x00456071 in cmd_stat (argc=3, argv=0x7fffd670) at 
builtin-stat.c:1705
  #6  0x004dd0fa in run_builtin (p=0xa21e00 , argc=3, 
argv=0x7fffd670) at perf.c:304
  #7  0x004dd367 in handle_internal_command (argc=3, 
argv=0x7fffd670) at perf.c:356
  #8  0x004dd4ae in run_argv (argcp=0x7fffd4cc, 
argv=0x7fffd4c0) at perf.c:400
  #9  0x004dd81a in main (argc=3, argv=0x7fffd670) at perf.c:522
  (gdb) bt

So move the initialization of the core evlist (calling
perf_evlist__init()) to before perf_evlist__set_maps() in
evlist__init().

Signed-off-by: Jiri Olsa 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-39-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/evlist.c  | 5 +
 tools/perf/lib/include/perf/evlist.h | 4 
 tools/perf/lib/libperf.map   | 1 +
 tools/perf/util/evlist.c | 3 ++-
 4 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
index 646bdd518793..fdc8c1894b37 100644
--- a/tools/perf/lib/evlist.c
+++ b/tools/perf/lib/evlist.c
@@ -2,3 +2,8 @@
 #include 
 #include 
 #include 
+
+void perf_evlist__init(struct perf_evlist *evlist)
+{
+   INIT_LIST_HEAD(>entries);
+}
diff --git a/tools/perf/lib/include/perf/evlist.h 
b/tools/perf/lib/include/perf/evlist.h
index 92b0eb39caec..1ddfcca0bd01 100644
--- a/tools/perf/lib/include/perf/evlist.h
+++ b/tools/perf/lib/include/perf/evlist.h
@@ -2,6 +2,10 @@
 #ifndef __LIBPERF_EVLIST_H
 #define __LIBPERF_EVLIST_H
 
+#include 
+
 struct perf_evlist;
 
+LIBPERF_API void perf_evlist__init(struct perf_evlist *evlist);
+
 #endif /* __LIBPERF_EVLIST_H */
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index 54f8503c6d82..5ca6ff6fcdfa 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -10,6 +10,7 @@ LIBPERF_0.0.1 {
perf_thread_map__get;
perf_thread_map__put;
perf_evsel__init;
+   perf_evlist__init;
local:
*;
 };
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index faf3ffd81d4c..f4aa6cf80559 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -33,6 +33,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #ifdef LACKS_SIGQUEUE_PROTOTYPE
 int sigqueue(pid_t pid, int sig, const union sigval value);
@@ -48,7 +49,7 @@ void evlist__init(struct evlist *evlist, struct perf_cpu_map 
*cpus,
 
for (i = 0; i < PERF_EVLIST__HLIST_SIZE; ++i)
INIT_HLIST_HEAD(>heads[i]);
-   INIT_LIST_HEAD(>core.entries);
+   perf_evlist__init(>core);
perf_evlist__set_maps(evlist, cpus, threads);
fdarray__init(>pollfd, 64);
evlist->workload.pid = -1;


[tip:perf/core] libperf: Add perf_evsel__init function

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  b04c597af761ccfd32f40ee3629843b6f3674fce
Gitweb: https://git.kernel.org/tip/b04c597af761ccfd32f40ee3629843b6f3674fce
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:24 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:44 -0300

libperf: Add perf_evsel__init function

Add the perf_evsel__init() function to initialize perf_evsel struct.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-38-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/evsel.c  | 5 +
 tools/perf/lib/include/perf/evsel.h | 4 
 tools/perf/lib/libperf.map  | 1 +
 tools/perf/util/evsel.c | 3 ++-
 4 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/tools/perf/lib/evsel.c b/tools/perf/lib/evsel.c
index 12e86de1994b..9a87e867a7ec 100644
--- a/tools/perf/lib/evsel.c
+++ b/tools/perf/lib/evsel.c
@@ -2,3 +2,8 @@
 #include 
 #include 
 #include 
+
+void perf_evsel__init(struct perf_evsel *evsel)
+{
+   INIT_LIST_HEAD(>node);
+}
diff --git a/tools/perf/lib/include/perf/evsel.h 
b/tools/perf/lib/include/perf/evsel.h
index 162bffd43409..b4d074a3684b 100644
--- a/tools/perf/lib/include/perf/evsel.h
+++ b/tools/perf/lib/include/perf/evsel.h
@@ -2,6 +2,10 @@
 #ifndef __LIBPERF_EVSEL_H
 #define __LIBPERF_EVSEL_H
 
+#include 
+
 struct perf_evsel;
 
+LIBPERF_API void perf_evsel__init(struct perf_evsel *evsel);
+
 #endif /* __LIBPERF_EVSEL_H */
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index c4f611010ccc..54f8503c6d82 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -9,6 +9,7 @@ LIBPERF_0.0.1 {
perf_thread_map__comm;
perf_thread_map__get;
perf_thread_map__put;
+   perf_evsel__init;
local:
*;
 };
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 8fed22d889a4..172bcc2e198f 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -22,6 +22,7 @@
 #include 
 #include 
 #include 
+#include 
 #include "asm/bug.h"
 #include "callchain.h"
 #include "cgroup.h"
@@ -226,6 +227,7 @@ bool perf_evsel__is_function_event(struct evsel *evsel)
 void evsel__init(struct evsel *evsel,
 struct perf_event_attr *attr, int idx)
 {
+   perf_evsel__init(>core);
evsel->idx = idx;
evsel->tracking= !idx;
evsel->attr= *attr;
@@ -236,7 +238,6 @@ void evsel__init(struct evsel *evsel,
evsel->evlist  = NULL;
evsel->bpf_obj = NULL;
evsel->bpf_fd  = -1;
-   INIT_LIST_HEAD(>core.node);
INIT_LIST_HEAD(>config_terms);
perf_evsel__object.init(evsel);
evsel->sample_size = __perf_evsel__sample_size(attr->sample_type);


[tip:perf/core] libperf: Include perf_evlist in evlist object

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  ce9036a6e3bdfac6c7ccf8221aec9bcf9c2d355e
Gitweb: https://git.kernel.org/tip/ce9036a6e3bdfac6c7ccf8221aec9bcf9c2d355e
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:23 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:44 -0300

libperf: Include perf_evlist in evlist object

Include perf_evlist in the evlist object, will continue to move other
generic things into libperf's perf_evlist.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-37-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-record.c|  4 ++--
 tools/perf/builtin-sched.c |  2 +-
 tools/perf/builtin-trace.c |  2 +-
 tools/perf/ui/browsers/hists.c |  6 +++---
 tools/perf/util/cgroup.c   |  2 +-
 tools/perf/util/evlist.c   |  8 
 tools/perf/util/evlist.h   | 17 +
 tools/perf/util/header.c   |  4 ++--
 tools/perf/util/parse-events.c |  2 +-
 tools/perf/util/stat-display.c |  4 ++--
 10 files changed, 26 insertions(+), 25 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 03fbe4600ca0..17bb0a536da3 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1002,7 +1002,7 @@ static void record__init_features(struct record *rec)
if (rec->no_buildid)
perf_header__clear_feat(>header, HEADER_BUILD_ID);
 
-   if (!have_tracepoints(>evlist->entries))
+   if (!have_tracepoints(>evlist->core.entries))
perf_header__clear_feat(>header, HEADER_TRACING_DATA);
 
if (!rec->opts.branch_stack)
@@ -1218,7 +1218,7 @@ static int record__synthesize(struct record *rec, bool 
tail)
return err;
}
 
-   if (have_tracepoints(>evlist->entries)) {
+   if (have_tracepoints(>evlist->core.entries)) {
/*
 * FIXME err <= 0 here actually means that
 * there were no tracepoints so its not really
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 70247f1b23da..897d11c8ca2e 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -2929,7 +2929,7 @@ static int timehist_check_attr(struct perf_sched *sched,
struct evsel *evsel;
struct evsel_runtime *er;
 
-   list_for_each_entry(evsel, >entries, core.node) {
+   list_for_each_entry(evsel, >core.entries, core.node) {
er = perf_evsel__get_runtime(evsel);
if (er == NULL) {
pr_err("Failed to allocate memory for evsel runtime 
data\n");
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 29dbf99f6081..bcd033e91de4 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -3980,7 +3980,7 @@ static int trace__parse_cgroups(const struct option *opt, 
const char *str, int u
 {
struct trace *trace = opt->value;
 
-   if (!list_empty(>evlist->entries))
+   if (!list_empty(>evlist->core.entries))
return parse_cgroups(opt, str, unset);
 
trace->cgroup = evlist__findnew_cgroup(trace->evlist, str);
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index 280347499c50..ed5406ff9fe4 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -3309,13 +3309,13 @@ browse_hists:
ui_browser__show_title(>b, title);
switch (key) {
case K_TAB:
-   if (pos->core.node.next == >entries)
+   if (pos->core.node.next == 
>core.entries)
pos = perf_evlist__first(evlist);
else
pos = perf_evsel__next(pos);
goto browse_hists;
case K_UNTAB:
-   if (pos->core.node.prev == >entries)
+   if (pos->core.node.prev == 
>core.entries)
pos = perf_evlist__last(evlist);
else
pos = perf_evsel__prev(pos);
@@ -3370,7 +3370,7 @@ static int __perf_evlist__tui_browse_hists(struct evlist 
*evlist,
struct evsel *pos;
struct evsel_menu menu = {
.b = {
-   .entries= >entries,
+   .entries= >core.entries,
.refresh= ui_browser__list_head_refresh,
.seek   = ui_browser__list_head_seek,
.write  = perf_evsel_menu__write,
diff --git a/tools/perf/util/cgroup.c b/tools/perf/util/cgroup.c
index 

[tip:perf/core] libperf: Include perf_evsel in evsel object

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  b27c4ece725a7f2225f76ad05dc6f3f5463fe893
Gitweb: https://git.kernel.org/tip/b27c4ece725a7f2225f76ad05dc6f3f5463fe893
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:22 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:44 -0300

libperf: Include perf_evsel in evsel object

Including perf_evsel in evsel object, will continue to move other
generic things into libperf's perf_evsel struct.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-36-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-sched.c |  2 +-
 tools/perf/builtin-trace.c |  2 +-
 tools/perf/ui/browsers/hists.c |  8 
 tools/perf/util/evlist.c   | 16 
 tools/perf/util/evlist.h   | 12 ++--
 tools/perf/util/evsel.c|  4 ++--
 tools/perf/util/evsel.h| 16 
 tools/perf/util/parse-events.c | 20 ++--
 tools/perf/util/stat-display.c |  4 ++--
 tools/perf/util/trace-event-info.c |  4 ++--
 10 files changed, 44 insertions(+), 44 deletions(-)

diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index c02ecb295f23..70247f1b23da 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -2929,7 +2929,7 @@ static int timehist_check_attr(struct perf_sched *sched,
struct evsel *evsel;
struct evsel_runtime *er;
 
-   list_for_each_entry(evsel, >entries, node) {
+   list_for_each_entry(evsel, >entries, core.node) {
er = perf_evsel__get_runtime(evsel);
if (er == NULL) {
pr_err("Failed to allocate memory for evsel runtime 
data\n");
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 51d142594a12..29dbf99f6081 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -2636,7 +2636,7 @@ static bool evlist__add_vfs_getname(struct evlist *evlist)
continue;
}
 
-   list_del_init(>node);
+   list_del_init(>core.node);
evsel->evlist = NULL;
evsel__delete(evsel);
}
diff --git a/tools/perf/ui/browsers/hists.c b/tools/perf/ui/browsers/hists.c
index b83258bece05..280347499c50 100644
--- a/tools/perf/ui/browsers/hists.c
+++ b/tools/perf/ui/browsers/hists.c
@@ -3212,7 +3212,7 @@ static void perf_evsel_menu__write(struct ui_browser 
*browser,
 {
struct evsel_menu *menu = container_of(browser,
struct evsel_menu, b);
-   struct evsel *evsel = list_entry(entry, struct evsel, node);
+   struct evsel *evsel = list_entry(entry, struct evsel, core.node);
struct hists *hists = evsel__hists(evsel);
bool current_entry = ui_browser__is_current_entry(browser, row);
unsigned long nr_events = hists->stats.nr_events[PERF_RECORD_SAMPLE];
@@ -3309,13 +3309,13 @@ browse_hists:
ui_browser__show_title(>b, title);
switch (key) {
case K_TAB:
-   if (pos->node.next == >entries)
+   if (pos->core.node.next == >entries)
pos = perf_evlist__first(evlist);
else
pos = perf_evsel__next(pos);
goto browse_hists;
case K_UNTAB:
-   if (pos->node.prev == >entries)
+   if (pos->core.node.prev == >entries)
pos = perf_evlist__last(evlist);
else
pos = perf_evsel__prev(pos);
@@ -3351,7 +3351,7 @@ out:
 static bool filter_group_entries(struct ui_browser *browser __maybe_unused,
 void *entry)
 {
-   struct evsel *evsel = list_entry(entry, struct evsel, node);
+   struct evsel *evsel = list_entry(entry, struct evsel, core.node);
 
if (symbol_conf.event_group && !perf_evsel__is_group_leader(evsel))
return true;
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 38a3c6d16b4b..227576bf16c0 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -119,7 +119,7 @@ static void perf_evlist__purge(struct evlist *evlist)
struct evsel *pos, *n;
 
evlist__for_each_entry_safe(evlist, n, pos) {
-   list_del_init(>node);
+   list_del_init(>core.node);
pos->evlist = NULL;
evsel__delete(pos);
}
@@ -180,7 +180,7 @@ static void perf_evlist__propagate_maps(struct evlist 
*evlist)
 void evlist__add(struct 

[tip:perf/core] libperf: Add perf_evlist and perf_evsel structs

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  285a30c36d1e18e7e2afa24dae50ba5596be45e7
Gitweb: https://git.kernel.org/tip/285a30c36d1e18e7e2afa24dae50ba5596be45e7
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:21 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:44 -0300

libperf: Add perf_evlist and perf_evsel structs

Add the perf_evlist and perf_evsel structs to libperf.

It's added as a declarations into:

  include/perf/evlist.h
  include/perf/evsel.h

which will be included by users.

The definitions are added into:

  include/internal/evlist.h
  include/internal/evsel.h

which is not to be included by users, but shared
within perf and libperf.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-35-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/Build | 2 ++
 tools/perf/lib/evlist.c  | 4 
 tools/perf/lib/evsel.c   | 4 
 tools/perf/lib/include/internal/evlist.h | 9 +
 tools/perf/lib/include/internal/evsel.h  | 9 +
 tools/perf/lib/include/perf/evlist.h | 7 +++
 tools/perf/lib/include/perf/evsel.h  | 7 +++
 7 files changed, 42 insertions(+)

diff --git a/tools/perf/lib/Build b/tools/perf/lib/Build
index 9beadfc81a71..b27c1543b046 100644
--- a/tools/perf/lib/Build
+++ b/tools/perf/lib/Build
@@ -1,3 +1,5 @@
 libperf-y += core.o
 libperf-y += cpumap.o
 libperf-y += threadmap.o
+libperf-y += evsel.o
+libperf-y += evlist.o
diff --git a/tools/perf/lib/evlist.c b/tools/perf/lib/evlist.c
new file mode 100644
index ..646bdd518793
--- /dev/null
+++ b/tools/perf/lib/evlist.c
@@ -0,0 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0
+#include 
+#include 
+#include 
diff --git a/tools/perf/lib/evsel.c b/tools/perf/lib/evsel.c
new file mode 100644
index ..12e86de1994b
--- /dev/null
+++ b/tools/perf/lib/evsel.c
@@ -0,0 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0
+#include 
+#include 
+#include 
diff --git a/tools/perf/lib/include/internal/evlist.h 
b/tools/perf/lib/include/internal/evlist.h
new file mode 100644
index ..7fbfe5716652
--- /dev/null
+++ b/tools/perf/lib/include/internal/evlist.h
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __LIBPERF_INTERNAL_EVLIST_H
+#define __LIBPERF_INTERNAL_EVLIST_H
+
+struct perf_evlist {
+   struct list_headentries;
+};
+
+#endif /* __LIBPERF_INTERNAL_EVLIST_H */
diff --git a/tools/perf/lib/include/internal/evsel.h 
b/tools/perf/lib/include/internal/evsel.h
new file mode 100644
index ..690943d0408a
--- /dev/null
+++ b/tools/perf/lib/include/internal/evsel.h
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __LIBPERF_INTERNAL_EVSEL_H
+#define __LIBPERF_INTERNAL_EVSEL_H
+
+struct perf_evsel {
+   struct list_headnode;
+};
+
+#endif /* __LIBPERF_INTERNAL_EVSEL_H */
diff --git a/tools/perf/lib/include/perf/evlist.h 
b/tools/perf/lib/include/perf/evlist.h
new file mode 100644
index ..92b0eb39caec
--- /dev/null
+++ b/tools/perf/lib/include/perf/evlist.h
@@ -0,0 +1,7 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __LIBPERF_EVLIST_H
+#define __LIBPERF_EVLIST_H
+
+struct perf_evlist;
+
+#endif /* __LIBPERF_EVLIST_H */
diff --git a/tools/perf/lib/include/perf/evsel.h 
b/tools/perf/lib/include/perf/evsel.h
new file mode 100644
index ..162bffd43409
--- /dev/null
+++ b/tools/perf/lib/include/perf/evsel.h
@@ -0,0 +1,7 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __LIBPERF_EVSEL_H
+#define __LIBPERF_EVSEL_H
+
+struct perf_evsel;
+
+#endif /* __LIBPERF_EVSEL_H */


[tip:perf/core] libperf: Add perf_thread_map__new_dummy() function

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  4b49cce25e719587e934b745fe9bbb5bc8c4ba29
Gitweb: https://git.kernel.org/tip/4b49cce25e719587e934b745fe9bbb5bc8c4ba29
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:19 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:44 -0300

libperf: Add perf_thread_map__new_dummy() function

Moving the following functions:

  thread_map__new_dummy()
  thread_map__realloc()
  thread_map__set_pid()

to libperf with the following names:

  perf_thread_map__new_dummy()
  perf_thread_map__realloc()
  perf_thread_map__set_pid()

the other 2 functions are dependencies of the
perf_thread_map__new_dummy() function.

The perf_thread_map__realloc() function is not exported.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-33-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/include/internal/threadmap.h |  2 +
 tools/perf/lib/include/perf/threadmap.h |  7 
 tools/perf/lib/libperf.map  |  2 +
 tools/perf/lib/threadmap.c  | 43 +
 tools/perf/tests/openat-syscall-tp-fields.c |  2 +-
 tools/perf/tests/thread-map.c   |  2 +-
 tools/perf/util/evlist.c|  4 +-
 tools/perf/util/thread_map.c| 59 ++---
 tools/perf/util/thread_map.h|  7 +---
 9 files changed, 71 insertions(+), 57 deletions(-)

diff --git a/tools/perf/lib/include/internal/threadmap.h 
b/tools/perf/lib/include/internal/threadmap.h
index c8088005a9ab..df748baf9eda 100644
--- a/tools/perf/lib/include/internal/threadmap.h
+++ b/tools/perf/lib/include/internal/threadmap.h
@@ -18,4 +18,6 @@ struct perf_thread_map {
struct thread_map_data map[];
 };
 
+struct perf_thread_map *perf_thread_map__realloc(struct perf_thread_map *map, 
int nr);
+
 #endif /* __LIBPERF_INTERNAL_THREADMAP_H */
diff --git a/tools/perf/lib/include/perf/threadmap.h 
b/tools/perf/lib/include/perf/threadmap.h
index dc3a3837b56f..34ed7f587101 100644
--- a/tools/perf/lib/include/perf/threadmap.h
+++ b/tools/perf/lib/include/perf/threadmap.h
@@ -2,6 +2,13 @@
 #ifndef __LIBPERF_THREADMAP_H
 #define __LIBPERF_THREADMAP_H
 
+#include 
+#include 
+
 struct perf_thread_map;
 
+LIBPERF_API struct perf_thread_map *perf_thread_map__new_dummy(void);
+
+LIBPERF_API void perf_thread_map__set_pid(struct perf_thread_map *map, int 
thread, pid_t pid);
+
 #endif /* __LIBPERF_THREADMAP_H */
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index 76ce3bc59dd8..6b4ec1c4d3f3 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -4,6 +4,8 @@ LIBPERF_0.0.1 {
perf_cpu_map__dummy_new;
perf_cpu_map__get;
perf_cpu_map__put;
+   perf_thread_map__new_dummy;
+   perf_thread_map__set_pid;
local:
*;
 };
diff --git a/tools/perf/lib/threadmap.c b/tools/perf/lib/threadmap.c
index 163dc609b909..23e628a1437a 100644
--- a/tools/perf/lib/threadmap.c
+++ b/tools/perf/lib/threadmap.c
@@ -3,3 +3,46 @@
 #include 
 #include 
 #include 
+#include 
+
+static void perf_thread_map__reset(struct perf_thread_map *map, int start, int 
nr)
+{
+   size_t size = (nr - start) * sizeof(map->map[0]);
+
+   memset(>map[start], 0, size);
+   map->err_thread = -1;
+}
+
+struct perf_thread_map *perf_thread_map__realloc(struct perf_thread_map *map, 
int nr)
+{
+   size_t size = sizeof(*map) + sizeof(map->map[0]) * nr;
+   int start = map ? map->nr : 0;
+
+   map = realloc(map, size);
+   /*
+* We only realloc to add more items, let's reset new items.
+*/
+   if (map)
+   perf_thread_map__reset(map, start, nr);
+
+   return map;
+}
+
+#define thread_map__alloc(__nr) perf_thread_map__realloc(NULL, __nr)
+
+void perf_thread_map__set_pid(struct perf_thread_map *map, int thread, pid_t 
pid)
+{
+   map->map[thread].pid = pid;
+}
+
+struct perf_thread_map *perf_thread_map__new_dummy(void)
+{
+   struct perf_thread_map *threads = thread_map__alloc(1);
+
+   if (threads != NULL) {
+   perf_thread_map__set_pid(threads, 0, -1);
+   threads->nr = 1;
+   refcount_set(>refcnt, 1);
+   }
+   return threads;
+}
diff --git a/tools/perf/tests/openat-syscall-tp-fields.c 
b/tools/perf/tests/openat-syscall-tp-fields.c
index c7182b7840e5..1de79208e690 100644
--- a/tools/perf/tests/openat-syscall-tp-fields.c
+++ b/tools/perf/tests/openat-syscall-tp-fields.c
@@ -58,7 +58,7 @@ int test__syscall_openat_tp_fields(struct test *test 
__maybe_unused, int subtest
 
perf_evsel__config(evsel, , NULL);
 
-   thread_map__set_pid(evlist->threads, 0, getpid());
+   perf_thread_map__set_pid(evlist->threads, 0, getpid());
 
err = evlist__open(evlist);
   

[tip:perf/core] libperf: Add perf_thread_map__get()/perf_thread_map__put()

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  7836e52e518b5e3fd695850f1d4081f756f58406
Gitweb: https://git.kernel.org/tip/7836e52e518b5e3fd695850f1d4081f756f58406
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:20 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:44 -0300

libperf: Add perf_thread_map__get()/perf_thread_map__put()

Move the following functions:

  thread_map__get()
  thread_map__put()
  thread_map__comm()

to libperf with the following names:

  perf_thread_map__get()
  perf_thread_map__put()
  perf_thread_map__comm()

Add the perf_thread_map__comm() function for it to work/compile.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-34-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-record.c|  2 +-
 tools/perf/lib/include/perf/threadmap.h|  4 
 tools/perf/lib/libperf.map |  3 +++
 tools/perf/lib/threadmap.c | 33 ++
 tools/perf/tests/code-reading.c|  4 ++--
 tools/perf/tests/event-times.c |  4 ++--
 tools/perf/tests/keep-tracking.c   |  2 +-
 tools/perf/tests/mmap-basic.c  |  2 +-
 tools/perf/tests/mmap-thread-lookup.c  |  2 +-
 tools/perf/tests/openat-syscall-all-cpus.c |  2 +-
 tools/perf/tests/openat-syscall.c  |  2 +-
 tools/perf/tests/sw-clock.c|  2 +-
 tools/perf/tests/switch-tracking.c |  2 +-
 tools/perf/tests/task-exit.c   |  2 +-
 tools/perf/tests/thread-map.c  | 18 
 tools/perf/util/event.c|  4 ++--
 tools/perf/util/evlist.c   | 12 +--
 tools/perf/util/evsel.c|  2 +-
 tools/perf/util/parse-events.c |  2 +-
 tools/perf/util/python.c   |  2 +-
 tools/perf/util/stat-display.c |  2 +-
 tools/perf/util/thread_map.c   | 26 ---
 tools/perf/util/thread_map.h   |  8 
 23 files changed, 74 insertions(+), 68 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index c0962ddfad04..03fbe4600ca0 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1060,7 +1060,7 @@ static int record__synthesize_workload(struct record 
*rec, bool tail)
 process_synthesized_event,
 >session->machines.host,
 rec->opts.sample_address);
-   thread_map__put(thread_map);
+   perf_thread_map__put(thread_map);
return err;
 }
 
diff --git a/tools/perf/lib/include/perf/threadmap.h 
b/tools/perf/lib/include/perf/threadmap.h
index 34ed7f587101..456295273daa 100644
--- a/tools/perf/lib/include/perf/threadmap.h
+++ b/tools/perf/lib/include/perf/threadmap.h
@@ -10,5 +10,9 @@ struct perf_thread_map;
 LIBPERF_API struct perf_thread_map *perf_thread_map__new_dummy(void);
 
 LIBPERF_API void perf_thread_map__set_pid(struct perf_thread_map *map, int 
thread, pid_t pid);
+LIBPERF_API char *perf_thread_map__comm(struct perf_thread_map *map, int 
thread);
+
+LIBPERF_API struct perf_thread_map *perf_thread_map__get(struct 
perf_thread_map *map);
+LIBPERF_API void perf_thread_map__put(struct perf_thread_map *map);
 
 #endif /* __LIBPERF_THREADMAP_H */
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index 6b4ec1c4d3f3..c4f611010ccc 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -6,6 +6,9 @@ LIBPERF_0.0.1 {
perf_cpu_map__put;
perf_thread_map__new_dummy;
perf_thread_map__set_pid;
+   perf_thread_map__comm;
+   perf_thread_map__get;
+   perf_thread_map__put;
local:
*;
 };
diff --git a/tools/perf/lib/threadmap.c b/tools/perf/lib/threadmap.c
index 23e628a1437a..4865b73e2586 100644
--- a/tools/perf/lib/threadmap.c
+++ b/tools/perf/lib/threadmap.c
@@ -4,6 +4,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 static void perf_thread_map__reset(struct perf_thread_map *map, int start, int 
nr)
 {
@@ -35,6 +37,11 @@ void perf_thread_map__set_pid(struct perf_thread_map *map, 
int thread, pid_t pid
map->map[thread].pid = pid;
 }
 
+char *perf_thread_map__comm(struct perf_thread_map *map, int thread)
+{
+   return map->map[thread].comm;
+}
+
 struct perf_thread_map *perf_thread_map__new_dummy(void)
 {
struct perf_thread_map *threads = thread_map__alloc(1);
@@ -46,3 +53,29 @@ struct perf_thread_map *perf_thread_map__new_dummy(void)
}
return threads;
 }
+
+static void perf_thread_map__delete(struct perf_thread_map *threads)
+{
+   if (threads) {
+   int i;
+
+   

[tip:perf/core] libperf: Add perf_thread_map struct

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  07acd22677ac6bb2db404d1d258e8c7d06ca7706
Gitweb: https://git.kernel.org/tip/07acd22677ac6bb2db404d1d258e8c7d06ca7706
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:18 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:44 -0300

libperf: Add perf_thread_map struct

Add perf_thread_map struct to libperf.

It's added as a declaration into into:

  include/perf/threadmap.h

which will be included by users.

The perf_thread_map struct definition is added into:

  include/internal/threadmap.h

which is not to be included by users, but shared within perf and
libperf.

We tried the total separation of the perf_thread_map struct in libperf,
but it lead to complications and much bigger changes in perf code, so we
decided to share the declaration.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-32-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/Build|  1 +
 tools/perf/lib/include/internal/threadmap.h | 21 +
 tools/perf/lib/include/perf/threadmap.h |  7 +++
 tools/perf/lib/threadmap.c  |  5 +
 tools/perf/util/thread_map.h| 13 +
 5 files changed, 35 insertions(+), 12 deletions(-)

diff --git a/tools/perf/lib/Build b/tools/perf/lib/Build
index 195b274db49a..9beadfc81a71 100644
--- a/tools/perf/lib/Build
+++ b/tools/perf/lib/Build
@@ -1,2 +1,3 @@
 libperf-y += core.o
 libperf-y += cpumap.o
+libperf-y += threadmap.o
diff --git a/tools/perf/lib/include/internal/threadmap.h 
b/tools/perf/lib/include/internal/threadmap.h
new file mode 100644
index ..c8088005a9ab
--- /dev/null
+++ b/tools/perf/lib/include/internal/threadmap.h
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __LIBPERF_INTERNAL_THREADMAP_H
+#define __LIBPERF_INTERNAL_THREADMAP_H
+
+#include 
+#include 
+#include 
+
+struct thread_map_data {
+   pid_tpid;
+   char*comm;
+};
+
+struct perf_thread_map {
+   refcount_t  refcnt;
+   int nr;
+   int err_thread;
+   struct thread_map_data map[];
+};
+
+#endif /* __LIBPERF_INTERNAL_THREADMAP_H */
diff --git a/tools/perf/lib/include/perf/threadmap.h 
b/tools/perf/lib/include/perf/threadmap.h
new file mode 100644
index ..dc3a3837b56f
--- /dev/null
+++ b/tools/perf/lib/include/perf/threadmap.h
@@ -0,0 +1,7 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __LIBPERF_THREADMAP_H
+#define __LIBPERF_THREADMAP_H
+
+struct perf_thread_map;
+
+#endif /* __LIBPERF_THREADMAP_H */
diff --git a/tools/perf/lib/threadmap.c b/tools/perf/lib/threadmap.c
new file mode 100644
index ..163dc609b909
--- /dev/null
+++ b/tools/perf/lib/threadmap.c
@@ -0,0 +1,5 @@
+// SPDX-License-Identifier: GPL-2.0
+#include 
+#include 
+#include 
+#include 
diff --git a/tools/perf/util/thread_map.h b/tools/perf/util/thread_map.h
index 9358b1b6e657..5a7be6f8934f 100644
--- a/tools/perf/util/thread_map.h
+++ b/tools/perf/util/thread_map.h
@@ -5,18 +5,7 @@
 #include 
 #include 
 #include 
-
-struct thread_map_data {
-   pid_tpid;
-   char*comm;
-};
-
-struct perf_thread_map {
-   refcount_t refcnt;
-   int nr;
-   int err_thread;
-   struct thread_map_data map[];
-};
+#include 
 
 struct thread_map_event;
 


[tip:perf/core] libperf: Add perf_cpu_map__get()/perf_cpu_map__put()

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  38f01d8da1d8d28678ea16a0a484f4d3eded34b2
Gitweb: https://git.kernel.org/tip/38f01d8da1d8d28678ea16a0a484f4d3eded34b2
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:17 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:44 -0300

libperf: Add perf_cpu_map__get()/perf_cpu_map__put()

Moving the following functions:

  cpu_map__get()
  cpu_map__put()

to libperf with following names:

  perf_cpu_map__get()
  perf_cpu_map__put()

Committer notes:

Added fixes for arm/arm64

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-31-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/arch/arm/util/cs-etm.c  |  6 +++---
 tools/perf/arch/arm64/util/header.c|  4 ++--
 tools/perf/builtin-ftrace.c|  2 +-
 tools/perf/builtin-stat.c  |  4 ++--
 tools/perf/lib/cpumap.c| 24 
 tools/perf/lib/include/perf/cpumap.h   |  2 ++
 tools/perf/lib/libperf.map |  2 ++
 tools/perf/tests/bitmap.c  |  2 +-
 tools/perf/tests/code-reading.c|  4 ++--
 tools/perf/tests/cpumap.c  |  8 
 tools/perf/tests/event-times.c |  4 ++--
 tools/perf/tests/event_update.c|  4 ++--
 tools/perf/tests/keep-tracking.c   |  2 +-
 tools/perf/tests/mem2node.c|  2 +-
 tools/perf/tests/mmap-basic.c  |  2 +-
 tools/perf/tests/openat-syscall-all-cpus.c |  2 +-
 tools/perf/tests/sw-clock.c|  2 +-
 tools/perf/tests/switch-tracking.c |  2 +-
 tools/perf/tests/task-exit.c   |  2 +-
 tools/perf/tests/topology.c|  2 +-
 tools/perf/util/cpumap.c   | 22 --
 tools/perf/util/cpumap.h   |  3 ---
 tools/perf/util/cputopo.c  |  4 ++--
 tools/perf/util/env.c  |  2 +-
 tools/perf/util/event.c|  2 +-
 tools/perf/util/evlist.c   | 16 
 tools/perf/util/evsel.c|  4 ++--
 tools/perf/util/parse-events.c |  4 ++--
 tools/perf/util/pmu.c  |  2 +-
 tools/perf/util/python.c   |  2 +-
 tools/perf/util/record.c   |  6 +++---
 tools/perf/util/session.c  |  2 +-
 tools/perf/util/svghelper.c|  2 +-
 33 files changed, 78 insertions(+), 75 deletions(-)

diff --git a/tools/perf/arch/arm/util/cs-etm.c 
b/tools/perf/arch/arm/util/cs-etm.c
index 268fcb31cd53..3a78b38e43ca 100644
--- a/tools/perf/arch/arm/util/cs-etm.c
+++ b/tools/perf/arch/arm/util/cs-etm.c
@@ -181,7 +181,7 @@ static int cs_etm_set_option(struct auxtrace_record *itr,
 
err = 0;
 out:
-   cpu_map__put(online_cpus);
+   perf_cpu_map__put(online_cpus);
return err;
 }
 
@@ -517,7 +517,7 @@ cs_etm_info_priv_size(struct auxtrace_record *itr 
__maybe_unused,
}
}
 
-   cpu_map__put(online_cpus);
+   perf_cpu_map__put(online_cpus);
 
return (CS_ETM_HEADER_SIZE +
   (etmv4 * CS_ETMV4_PRIV_SIZE) +
@@ -679,7 +679,7 @@ static int cs_etm_info_fill(struct auxtrace_record *itr,
if (cpu_map__has(cpu_map, i))
cs_etm_get_metadata(i, , itr, info);
 
-   cpu_map__put(online_cpus);
+   perf_cpu_map__put(online_cpus);
 
return 0;
 }
diff --git a/tools/perf/arch/arm64/util/header.c 
b/tools/perf/arch/arm64/util/header.c
index b3e73a413f5a..602caf550e7f 100644
--- a/tools/perf/arch/arm64/util/header.c
+++ b/tools/perf/arch/arm64/util/header.c
@@ -27,7 +27,7 @@ char *get_cpuid_str(struct perf_pmu *pmu)
return NULL;
 
/* read midr from list of cpus mapped to this pmu */
-   cpus = cpu_map__get(pmu->cpus);
+   cpus = perf_cpu_map__get(pmu->cpus);
for (cpu = 0; cpu < cpus->nr; cpu++) {
scnprintf(path, PATH_MAX, "%s/devices/system/cpu/cpu%d"MIDR,
sysfs, cpus->map[cpu]);
@@ -60,6 +60,6 @@ char *get_cpuid_str(struct perf_pmu *pmu)
buf = NULL;
}
 
-   cpu_map__put(cpus);
+   perf_cpu_map__put(cpus);
return buf;
 }
diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index 105ef2a17a9c..6943352b8d94 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -206,7 +206,7 @@ static int reset_tracing_cpu(void)
int ret;
 
ret = set_tracing_cpumask(cpumap);
-   cpu_map__put(cpumap);
+   perf_cpu_map__put(cpumap);
return ret;
 }
 
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 36e66a4f3c57..39bd73d0e06e 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -933,8 

[tip:perf/core] libperf: Add perf_cpu_map__dummy_new() function

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  397721e06e52d017cfdd403f63284ed0995d4caf
Gitweb: https://git.kernel.org/tip/397721e06e52d017cfdd403f63284ed0995d4caf
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:16 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:44 -0300

libperf: Add perf_cpu_map__dummy_new() function

Move cpu_map__dummy_new() to libperf as perf_cpu_map__dummy_new() function.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-30-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/cpumap.c  | 13 +
 tools/perf/lib/include/perf/cpumap.h |  4 
 tools/perf/lib/libperf.map   |  1 +
 tools/perf/tests/sw-clock.c  |  2 +-
 tools/perf/tests/task-exit.c |  2 +-
 tools/perf/util/cpumap.c | 15 +--
 tools/perf/util/cpumap.h |  2 +-
 tools/perf/util/evlist.c |  2 +-
 tools/perf/util/evsel.c  |  2 +-
 9 files changed, 24 insertions(+), 19 deletions(-)

diff --git a/tools/perf/lib/cpumap.c b/tools/perf/lib/cpumap.c
index 86a199c26f20..80d587ab95aa 100644
--- a/tools/perf/lib/cpumap.c
+++ b/tools/perf/lib/cpumap.c
@@ -3,3 +3,16 @@
 #include 
 #include 
 #include 
+
+struct perf_cpu_map *perf_cpu_map__dummy_new(void)
+{
+   struct perf_cpu_map *cpus = malloc(sizeof(*cpus) + sizeof(int));
+
+   if (cpus != NULL) {
+   cpus->nr = 1;
+   cpus->map[0] = -1;
+   refcount_set(>refcnt, 1);
+   }
+
+   return cpus;
+}
diff --git a/tools/perf/lib/include/perf/cpumap.h 
b/tools/perf/lib/include/perf/cpumap.h
index 8355d3ce7d0c..fa1e5aa9d662 100644
--- a/tools/perf/lib/include/perf/cpumap.h
+++ b/tools/perf/lib/include/perf/cpumap.h
@@ -2,6 +2,10 @@
 #ifndef __LIBPERF_CPUMAP_H
 #define __LIBPERF_CPUMAP_H
 
+#include 
+
 struct perf_cpu_map;
 
+LIBPERF_API struct perf_cpu_map *perf_cpu_map__dummy_new(void);
+
 #endif /* __LIBPERF_CPUMAP_H */
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index 3536242c545c..65201c6cbe7e 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -1,6 +1,7 @@
 LIBPERF_0.0.1 {
global:
libperf_set_print;
+   perf_cpu_map__dummy_new;
local:
*;
 };
diff --git a/tools/perf/tests/sw-clock.c b/tools/perf/tests/sw-clock.c
index ba033a6e6c0f..c6d3f4488b73 100644
--- a/tools/perf/tests/sw-clock.c
+++ b/tools/perf/tests/sw-clock.c
@@ -56,7 +56,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)
}
evlist__add(evlist, evsel);
 
-   cpus = cpu_map__dummy_new();
+   cpus = perf_cpu_map__dummy_new();
threads = thread_map__new_by_tid(getpid());
if (!cpus || !threads) {
err = -ENOMEM;
diff --git a/tools/perf/tests/task-exit.c b/tools/perf/tests/task-exit.c
index d17effdd55c8..c094fb8cc877 100644
--- a/tools/perf/tests/task-exit.c
+++ b/tools/perf/tests/task-exit.c
@@ -63,7 +63,7 @@ int test__task_exit(struct test *test __maybe_unused, int 
subtest __maybe_unused
 * perf_evlist__prepare_workload we'll fill in the only thread
 * we're monitoring, the one forked there.
 */
-   cpus = cpu_map__dummy_new();
+   cpus = perf_cpu_map__dummy_new();
threads = thread_map__new_by_tid(-1);
if (!cpus || !threads) {
err = -ENOMEM;
diff --git a/tools/perf/util/cpumap.c b/tools/perf/util/cpumap.c
index 5eb4e1fbb877..acda9bfb4002 100644
--- a/tools/perf/util/cpumap.c
+++ b/tools/perf/util/cpumap.c
@@ -189,7 +189,7 @@ struct perf_cpu_map *cpu_map__new(const char *cpu_list)
else if (*cpu_list != '\0')
cpus = cpu_map__default_new();
else
-   cpus = cpu_map__dummy_new();
+   cpus = perf_cpu_map__dummy_new();
 invalid:
free(tmp_cpus);
 out:
@@ -256,19 +256,6 @@ size_t cpu_map__fprintf(struct perf_cpu_map *map, FILE *fp)
 #undef BUFSIZE
 }
 
-struct perf_cpu_map *cpu_map__dummy_new(void)
-{
-   struct perf_cpu_map *cpus = malloc(sizeof(*cpus) + sizeof(int));
-
-   if (cpus != NULL) {
-   cpus->nr = 1;
-   cpus->map[0] = -1;
-   refcount_set(>refcnt, 1);
-   }
-
-   return cpus;
-}
-
 struct perf_cpu_map *cpu_map__empty_new(int nr)
 {
struct perf_cpu_map *cpus = malloc(sizeof(*cpus) + sizeof(int) * nr);
diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h
index c2ba9ae195f7..0ce3f6bd9449 100644
--- a/tools/perf/util/cpumap.h
+++ b/tools/perf/util/cpumap.h
@@ -6,13 +6,13 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "perf.h"
 #include "util/debug.h"
 
 struct perf_cpu_map *cpu_map__new(const char *cpu_list);
 struct perf_cpu_map *cpu_map__empty_new(int nr);
-struct perf_cpu_map *cpu_map__dummy_new(void);
 struct 

[tip:perf/core] libperf: Add debug output support

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  a1556f8479ed58b8d5a33aef54578bad0165c7e7
Gitweb: https://git.kernel.org/tip/a1556f8479ed58b8d5a33aef54578bad0165c7e7
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:14 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:44 -0300

libperf: Add debug output support

Add the perf_set_print() function to allow setting an output function
for warn/info/debug messages.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-28-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/core.c  | 34 ++
 tools/perf/lib/include/perf/core.h | 13 +
 tools/perf/lib/internal.h  | 18 ++
 tools/perf/lib/libperf.map |  2 ++
 4 files changed, 67 insertions(+)

diff --git a/tools/perf/lib/core.c b/tools/perf/lib/core.c
index e69de29bb2d1..29d5e3348718 100644
--- a/tools/perf/lib/core.c
+++ b/tools/perf/lib/core.c
@@ -0,0 +1,34 @@
+// SPDX-License-Identifier: GPL-2.0-only
+
+#define __printf(a, b)  __attribute__((format(printf, a, b)))
+
+#include 
+#include 
+#include 
+#include "internal.h"
+
+static int __base_pr(enum libperf_print_level level, const char *format,
+va_list args)
+{
+   return vfprintf(stderr, format, args);
+}
+
+static libperf_print_fn_t __libperf_pr = __base_pr;
+
+void libperf_set_print(libperf_print_fn_t fn)
+{
+   __libperf_pr = fn;
+}
+
+__printf(2, 3)
+void libperf_print(enum libperf_print_level level, const char *format, ...)
+{
+   va_list args;
+
+   if (!__libperf_pr)
+   return;
+
+   va_start(args, format);
+   __libperf_pr(level, format, args);
+   va_end(args);
+}
diff --git a/tools/perf/lib/include/perf/core.h 
b/tools/perf/lib/include/perf/core.h
index e2e4b43c9131..c341a7b2c874 100644
--- a/tools/perf/lib/include/perf/core.h
+++ b/tools/perf/lib/include/perf/core.h
@@ -2,8 +2,21 @@
 #ifndef __LIBPERF_CORE_H
 #define __LIBPERF_CORE_H
 
+#include 
+
 #ifndef LIBPERF_API
 #define LIBPERF_API __attribute__((visibility("default")))
 #endif
 
+enum libperf_print_level {
+   LIBPERF_WARN,
+   LIBPERF_INFO,
+   LIBPERF_DEBUG,
+};
+
+typedef int (*libperf_print_fn_t)(enum libperf_print_level level,
+ const char *, va_list ap);
+
+LIBPERF_API void libperf_set_print(libperf_print_fn_t fn);
+
 #endif /* __LIBPERF_CORE_H */
diff --git a/tools/perf/lib/internal.h b/tools/perf/lib/internal.h
new file mode 100644
index ..dc92f241732e
--- /dev/null
+++ b/tools/perf/lib/internal.h
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __LIBPERF_INTERNAL_H
+#define __LIBPERF_INTERNAL_H
+
+void libperf_print(enum libperf_print_level level,
+  const char *format, ...)
+   __attribute__((format(printf, 2, 3)));
+
+#define __pr(level, fmt, ...)   \
+do {\
+   libperf_print(level, "libperf: " fmt, ##__VA_ARGS__); \
+} while (0)
+
+#define pr_warning(fmt, ...)__pr(LIBPERF_WARN, fmt, ##__VA_ARGS__)
+#define pr_info(fmt, ...)   __pr(LIBPERF_INFO, fmt, ##__VA_ARGS__)
+#define pr_debug(fmt, ...)  __pr(LIBPERF_DEBUG, fmt, ##__VA_ARGS__)
+
+#endif /* __LIBPERF_INTERNAL_H */
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
index a8e913988edf..3536242c545c 100644
--- a/tools/perf/lib/libperf.map
+++ b/tools/perf/lib/libperf.map
@@ -1,4 +1,6 @@
 LIBPERF_0.0.1 {
+   global:
+   libperf_set_print;
local:
*;
 };


[tip:perf/core] libperf: Add perf_cpu_map struct

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  959b83c769389b24d64759f60e64c4c62620ff02
Gitweb: https://git.kernel.org/tip/959b83c769389b24d64759f60e64c4c62620ff02
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:15 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:44 -0300

libperf: Add perf_cpu_map struct

Add perf_cpu_map struct to libperf.

It's added as a declaration into:

  include/perf/cpumap.h

which will be included by users.

The perf_cpu_map struct definition is added into:

  include/internal/cpumap.h

which is not to be included by users, but shared within perf and
libperf.

We tried the total separation of the perf_cpu_map struct in libperf, but
it lead to complications and much bigger changes in perf code, so we
decided to share the declaration.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-29-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/Build |  1 +
 tools/perf/lib/cpumap.c  |  5 +
 tools/perf/lib/include/internal/cpumap.h | 13 +
 tools/perf/lib/include/perf/cpumap.h |  7 +++
 tools/perf/util/cpumap.h |  7 +--
 5 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/tools/perf/lib/Build b/tools/perf/lib/Build
index 5196958cec01..195b274db49a 100644
--- a/tools/perf/lib/Build
+++ b/tools/perf/lib/Build
@@ -1 +1,2 @@
 libperf-y += core.o
+libperf-y += cpumap.o
diff --git a/tools/perf/lib/cpumap.c b/tools/perf/lib/cpumap.c
new file mode 100644
index ..86a199c26f20
--- /dev/null
+++ b/tools/perf/lib/cpumap.c
@@ -0,0 +1,5 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include 
+#include 
+#include 
+#include 
diff --git a/tools/perf/lib/include/internal/cpumap.h 
b/tools/perf/lib/include/internal/cpumap.h
new file mode 100644
index ..53ce95374b05
--- /dev/null
+++ b/tools/perf/lib/include/internal/cpumap.h
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __LIBPERF_INTERNAL_CPUMAP_H
+#define __LIBPERF_INTERNAL_CPUMAP_H
+
+#include 
+
+struct perf_cpu_map {
+   refcount_t  refcnt;
+   int nr;
+   int map[];
+};
+
+#endif /* __LIBPERF_INTERNAL_CPUMAP_H */
diff --git a/tools/perf/lib/include/perf/cpumap.h 
b/tools/perf/lib/include/perf/cpumap.h
new file mode 100644
index ..8355d3ce7d0c
--- /dev/null
+++ b/tools/perf/lib/include/perf/cpumap.h
@@ -0,0 +1,7 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __LIBPERF_CPUMAP_H
+#define __LIBPERF_CPUMAP_H
+
+struct perf_cpu_map;
+
+#endif /* __LIBPERF_CPUMAP_H */
diff --git a/tools/perf/util/cpumap.h b/tools/perf/util/cpumap.h
index 22729beae959..c2ba9ae195f7 100644
--- a/tools/perf/util/cpumap.h
+++ b/tools/perf/util/cpumap.h
@@ -5,16 +5,11 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "perf.h"
 #include "util/debug.h"
 
-struct perf_cpu_map {
-   refcount_t refcnt;
-   int nr;
-   int map[];
-};
-
 struct perf_cpu_map *cpu_map__new(const char *cpu_list);
 struct perf_cpu_map *cpu_map__empty_new(int nr);
 struct perf_cpu_map *cpu_map__dummy_new(void);


[tip:perf/core] libperf: Add libperf to the python.so build

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  a429dcb8feb60b8500fed81e2275c1944e3091fc
Gitweb: https://git.kernel.org/tip/a429dcb8feb60b8500fed81e2275c1944e3091fc
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:12 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:44 -0300

libperf: Add libperf to the python.so build

Link libperf.a with python.so.

Committer testing:

Continues to work:

  # perf test python
  18: 'import perf' in python   : Ok
  #

Signed-off-by: Jiri Olsa 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-26-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Makefile.perf | 1 +
 tools/perf/util/setup.py | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 6e7e7d44ffac..67512a12276b 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -307,6 +307,7 @@ LIBBPF = $(BPF_PATH)libbpf.a
 LIBSUBCMD = $(SUBCMD_PATH)libsubcmd.a
 
 LIBPERF = $(LIBPERF_PATH)libperf.a
+export LIBPERF
 
 # python extension build directories
 PYTHON_EXTBUILD := $(OUTPUT)python_ext_build/
diff --git a/tools/perf/util/setup.py b/tools/perf/util/setup.py
index a1a68a2fa917..d48f9cd58964 100644
--- a/tools/perf/util/setup.py
+++ b/tools/perf/util/setup.py
@@ -48,6 +48,7 @@ build_lib = getenv('PYTHON_EXTBUILD_LIB')
 build_tmp = getenv('PYTHON_EXTBUILD_TMP')
 libtraceevent = getenv('LIBTRACEEVENT')
 libapikfs = getenv('LIBAPI')
+libperf = getenv('LIBPERF')
 
 ext_sources = [f.strip() for f in open('util/python-ext-sources')
if len(f.strip()) > 0 and f[0] != '#']
@@ -64,7 +65,7 @@ perf = Extension('perf',
  include_dirs = ['util/include'],
  libraries = extra_libraries,
  extra_compile_args = cflags,
- extra_objects = [libtraceevent, libapikfs],
+ extra_objects = [libtraceevent, libapikfs, libperf],
  )
 
 setup(name='perf',


[tip:perf/core] libperf: Add perf/core.h header

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  5b7f445d684fc287a2101e29d42d1fee19ae14ff
Gitweb: https://git.kernel.org/tip/5b7f445d684fc287a2101e29d42d1fee19ae14ff
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:13 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:44 -0300

libperf: Add perf/core.h header

Add perf/core.h header to be used in header files coming in the
following patches.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-27-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/include/perf/core.h | 9 +
 1 file changed, 9 insertions(+)

diff --git a/tools/perf/lib/include/perf/core.h 
b/tools/perf/lib/include/perf/core.h
new file mode 100644
index ..e2e4b43c9131
--- /dev/null
+++ b/tools/perf/lib/include/perf/core.h
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __LIBPERF_CORE_H
+#define __LIBPERF_CORE_H
+
+#ifndef LIBPERF_API
+#define LIBPERF_API __attribute__((visibility("default")))
+#endif
+
+#endif /* __LIBPERF_CORE_H */


[tip:perf/core] libperf: Add build version support

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  47f9bccc79cb067103ad5e9790e0d01c94839429
Gitweb: https://git.kernel.org/tip/47f9bccc79cb067103ad5e9790e0d01c94839429
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:11 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:43 -0300

libperf: Add build version support

Add a shared library version, generating the following files:

  $ ll tools/perf/lib/libperf.so*
  libperf.so -> libperf.so.0.0.1
  libperf.so.0 -> libperf.so.0.0.1
  libperf.so.0.0.1

Committer testing:

One has to build just libbperf to get this, building perf so far doesn't
trigger this, i.e. I tried:

  $ make O=/tmp/build/perf -C tools/perf

And the files above were not created, so one has to do:

  $ make O=/tmp/build/perf -C tools/perf/lib/
  make: Entering directory '/home/acme/git/perf/tools/perf/lib'
LINK /tmp/build/perf/libperf.so.0.0.1
  make: Leaving directory '/home/acme/git/perf/tools/perf/lib'
  $ ls -la /tmp/build/perf/*.so.*
  lrwxrwxrwx. 1 acme acme16 Jul 22 15:37 /tmp/build/perf/libperf.so.0 -> 
libperf.so.0.0.1
  -rwxrwxr-x. 1 acme acme 16368 Jul 22 15:37 /tmp/build/perf/libperf.so.0.0.1
  $

Signed-off-by: Jiri Olsa 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-25-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/lib/Makefile| 20 +---
 tools/perf/lib/libperf.map |  4 
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/tools/perf/lib/Makefile b/tools/perf/lib/Makefile
index 33046e7c6a2a..cd571ec648ad 100644
--- a/tools/perf/lib/Makefile
+++ b/tools/perf/lib/Makefile
@@ -1,6 +1,10 @@
 # SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
 # Most of this file is copied from tools/lib/bpf/Makefile
 
+LIBPERF_VERSION = 0
+LIBPERF_PATCHLEVEL = 0
+LIBPERF_EXTRAVERSION = 1
+
 MAKEFLAGS += --no-print-directory
 
 ifeq ($(srctree),)
@@ -47,7 +51,13 @@ all:
 export srctree OUTPUT CC LD CFLAGS V
 include $(srctree)/tools/build/Makefile.include
 
-LIBPERF_SO := $(OUTPUT)libperf.so
+VERSION_SCRIPT := libperf.map
+
+PATCHLEVEL= $(LIBPERF_PATCHLEVEL)
+EXTRAVERSION  = $(LIBPERF_EXTRAVERSION)
+VERSION   = 
$(LIBPERF_VERSION).$(LIBPERF_PATCHLEVEL).$(LIBPERF_EXTRAVERSION)
+
+LIBPERF_SO := $(OUTPUT)libperf.so.$(VERSION)
 LIBPERF_A  := $(OUTPUT)libperf.a
 LIBPERF_IN := $(OUTPUT)libperf-in.o
 
@@ -58,7 +68,11 @@ $(LIBPERF_A): $(LIBPERF_IN)
$(QUIET_AR)$(RM) $@ && $(AR) rcs $@ $(LIBPERF_IN)
 
 $(LIBPERF_SO): $(LIBPERF_IN)
-   $(QUIET_LINK)$(CC) --shared -Wl,-soname,libperf.so $^ -o $@
+   $(QUIET_LINK)$(CC) --shared -Wl,-soname,libperf.so \
+-Wl,--version-script=$(VERSION_SCRIPT) $^ 
-o $@
+   @ln -sf $(@F) $(OUTPUT)libperf.so
+   @ln -sf $(@F) $(OUTPUT)libperf.so.$(LIBPERF_VERSION)
+
 
 libs: $(LIBPERF_A) $(LIBPERF_SO)
 
@@ -67,7 +81,7 @@ all: fixdep
 
 clean:
$(call QUIET_CLEAN, libperf) $(RM) $(LIBPERF_A) \
-*.o *~ *.a *.so .*.d .*.cmd LIBPERF-CFLAGS
+*.o *~ *.a *.so *.so.$(VERSION) *.so.$(LIBPERF_VERSION) .*.d 
.*.cmd LIBPERF-CFLAGS
 
 FORCE:
 
diff --git a/tools/perf/lib/libperf.map b/tools/perf/lib/libperf.map
new file mode 100644
index ..a8e913988edf
--- /dev/null
+++ b/tools/perf/lib/libperf.map
@@ -0,0 +1,4 @@
+LIBPERF_0.0.1 {
+   local:
+   *;
+};


[tip:perf/core] perf evlist: Rename perf_evlist__enable() to evlist__enable()

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  1c87f1654cc315fbeae0238a8dbf5bf3c498f3af
Gitweb: https://git.kernel.org/tip/1c87f1654cc315fbeae0238a8dbf5bf3c498f3af
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:08 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:43 -0300

perf evlist: Rename perf_evlist__enable() to evlist__enable()

Rename perf_evlist__enable() to evlist__enable(), so we don't have a
name clash when we add perf_evlist__enable() in libperf.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-22-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/arch/x86/tests/perf-time-to-tsc.c | 2 +-
 tools/perf/builtin-kvm.c | 2 +-
 tools/perf/builtin-record.c  | 4 ++--
 tools/perf/builtin-stat.c| 2 +-
 tools/perf/builtin-top.c | 2 +-
 tools/perf/builtin-trace.c   | 4 ++--
 tools/perf/tests/backward-ring-buffer.c  | 2 +-
 tools/perf/tests/bpf.c   | 2 +-
 tools/perf/tests/code-reading.c  | 2 +-
 tools/perf/tests/keep-tracking.c | 4 ++--
 tools/perf/tests/openat-syscall-tp-fields.c  | 2 +-
 tools/perf/tests/perf-record.c   | 2 +-
 tools/perf/tests/sw-clock.c  | 2 +-
 tools/perf/tests/switch-tracking.c   | 2 +-
 tools/perf/util/evlist.c | 4 ++--
 tools/perf/util/evlist.h | 2 +-
 16 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/tools/perf/arch/x86/tests/perf-time-to-tsc.c 
b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
index ea4cf1d367a6..aa5a5c972ce5 100644
--- a/tools/perf/arch/x86/tests/perf-time-to-tsc.c
+++ b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
@@ -97,7 +97,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, 
int subtest __maybe
goto out_err;
}
 
-   perf_evlist__enable(evlist);
+   evlist__enable(evlist);
 
comm1 = "Test COMM 1";
CHECK__(prctl(PR_SET_NAME, (unsigned long)comm1, 0, 0, 0));
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 6a0573a9c16b..9207bd49583e 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -972,7 +972,7 @@ static int kvm_events_live_report(struct perf_kvm_stat *kvm)
goto out;
 
/* everything is good - enable the events and process */
-   perf_evlist__enable(kvm->evlist);
+   evlist__enable(kvm->evlist);
 
while (!done) {
struct fdarray *fda = >evlist->pollfd;
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 7f933997b6d0..8e20ead0ddbe 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1453,7 +1453,7 @@ static int __cmd_record(struct record *rec, int argc, 
const char **argv)
 * so don't spoil it by prematurely enabling them.
 */
if (!target__none(>target) && !opts->initial_delay)
-   perf_evlist__enable(rec->evlist);
+   evlist__enable(rec->evlist);
 
/*
 * Let the child rip
@@ -1506,7 +1506,7 @@ static int __cmd_record(struct record *rec, int argc, 
const char **argv)
 
if (opts->initial_delay) {
usleep(opts->initial_delay * USEC_PER_MSEC);
-   perf_evlist__enable(rec->evlist);
+   evlist__enable(rec->evlist);
}
 
trigger_ready(_snapshot_trigger);
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index bdfe138f7aed..c0e9d94b6dd5 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -362,7 +362,7 @@ static void enable_counters(void)
 * - we have initial delay configured
 */
if (!target__none() || stat_config.initial_delay)
-   perf_evlist__enable(evsel_list);
+   evlist__enable(evsel_list);
 }
 
 static void disable_counters(void)
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 5886389f6a40..b103f1ba01cb 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -1255,7 +1255,7 @@ static int __cmd_top(struct perf_top *top)
 * so leave the check here.
 */
 if (!target__none(>target))
-perf_evlist__enable(top->evlist);
+   evlist__enable(top->evlist);
 
ret = -1;
if (pthread_create(_process, NULL, process_thread, top)) {
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index e508fdb77099..46fab1ff92dc 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -3402,14 +3402,14 @@ static int trace__run(struct trace *trace, int argc, 
const char **argv)
goto out_error_mmap;
 
if (!target__none(>opts.target) && !trace->opts.initial_delay)
-   perf_evlist__enable(evlist);
+

[tip:perf/core] libperf: Make libperf.a part of the perf build

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  3143504918105156d03e8f927e127f7b9ea260d2
Gitweb: https://git.kernel.org/tip/3143504918105156d03e8f927e127f7b9ea260d2
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:10 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:43 -0300

libperf: Make libperf.a part of the perf build

Add an empty libperf.a under tools/perf/lib and link it with perf.

It can also be built separately with:

  $ cd tools/perf/lib && make
CC   core.o
LD   libperf-in.o
AR   libperf.a
LINK libperf.so

Committer testing:

  $ make O=/tmp/build/perf -C tools/perf/lib/
  make: Entering directory '/home/acme/git/perf/tools/perf/lib'
LINK /tmp/build/perf/libperf.so
  make: Leaving directory '/home/acme/git/perf/tools/perf/lib'
  $ ls -la /tmp/build/perf/libperf.so
  -rwxrwxr-x. 1 acme acme 16232 Jul 22 15:30 /tmp/build/perf/libperf.so
  $ file /tmp/build/perf/libperf.so
  /tmp/build/perf/libperf.so: ELF 64-bit LSB shared object, x86-64, version 1 
(SYSV), dynamically linked, 
BuildID[sha1]=7a51d227d871b381ddb686dcf94145c4dd908221, not stripped
  $ git status tools/perf
  On branch perf/core
  nothing to commit, working tree clean
  $
  $ ls -lart tools/perf/lib/
  total 16
  drwxrwxr-x. 16 acme acme 4096 Jul 22 15:29 ..
  -rw-rw-r--.  1 acme acme 1633 Jul 22 15:29 Makefile
  -rw-rw-r--.  1 acme acme0 Jul 22 15:29 core.c
  -rw-rw-r--.  1 acme acme   20 Jul 22 15:29 Build
  drwxrwxr-x.  2 acme acme 4096 Jul 22 15:29 .
  $

Committer notes:

Need to add -I$(srctree)/tools/arch/$(ARCH)/include/uapi
-I$(srctree)/tools/include/uapi to tools/perf/lib/Makefile's INCLUDE
variable to pick up the latest versions of kernel headers, even in older
systems, this is in line with what is in tools/lib/bpf/Makefile.

Signed-off-by: Jiri Olsa 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-24-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/Makefile.config |  1 +
 tools/perf/Makefile.perf   | 30 +
 tools/perf/lib/Build   |  1 +
 tools/perf/lib/Makefile| 74 ++
 .../Makefile.boot => tools/perf/lib/core.c |  0
 5 files changed, 92 insertions(+), 14 deletions(-)

diff --git a/tools/perf/Makefile.config b/tools/perf/Makefile.config
index 89ac5a1f1550..e4988f49ea79 100644
--- a/tools/perf/Makefile.config
+++ b/tools/perf/Makefile.config
@@ -277,6 +277,7 @@ ifeq ($(DEBUG),0)
   endif
 endif
 
+INC_FLAGS += -I$(src-perf)/lib/include
 INC_FLAGS += -I$(src-perf)/util/include
 INC_FLAGS += -I$(src-perf)/arch/$(SRCARCH)/include
 INC_FLAGS += -I$(srctree)/tools/include/uapi
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index 0fffd2bb6cd9..6e7e7d44ffac 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -224,6 +224,7 @@ LIB_DIR = $(srctree)/tools/lib/api/
 TRACE_EVENT_DIR = $(srctree)/tools/lib/traceevent/
 BPF_DIR = $(srctree)/tools/lib/bpf/
 SUBCMD_DIR  = $(srctree)/tools/lib/subcmd/
+LIBPERF_DIR = $(srctree)/tools/perf/lib/
 
 # Set FEATURE_TESTS to 'all' so all possible feature checkers are executed.
 # Without this setting the output feature dump file misses some features, for
@@ -272,6 +273,7 @@ ifneq ($(OUTPUT),)
   TE_PATH=$(OUTPUT)
   BPF_PATH=$(OUTPUT)
   SUBCMD_PATH=$(OUTPUT)
+  LIBPERF_PATH=$(OUTPUT)
 ifneq ($(subdir),)
   API_PATH=$(OUTPUT)/../lib/api/
 else
@@ -282,6 +284,7 @@ else
   API_PATH=$(LIB_DIR)
   BPF_PATH=$(BPF_DIR)
   SUBCMD_PATH=$(SUBCMD_DIR)
+  LIBPERF_PATH=$(LIBPERF_DIR)
 endif
 
 LIBTRACEEVENT = $(TE_PATH)libtraceevent.a
@@ -303,6 +306,8 @@ LIBBPF = $(BPF_PATH)libbpf.a
 
 LIBSUBCMD = $(SUBCMD_PATH)libsubcmd.a
 
+LIBPERF = $(LIBPERF_PATH)libperf.a
+
 # python extension build directories
 PYTHON_EXTBUILD := $(OUTPUT)python_ext_build/
 PYTHON_EXTBUILD_LIB := $(PYTHON_EXTBUILD)lib/
@@ -348,9 +353,7 @@ endif
 
 export PERL_PATH
 
-LIBPERF_A=$(OUTPUT)libperf.a
-
-PERFLIBS = $(LIBAPI) $(LIBTRACEEVENT) $(LIBSUBCMD)
+PERFLIBS = $(LIBAPI) $(LIBTRACEEVENT) $(LIBSUBCMD) $(LIBPERF)
 ifndef NO_LIBBPF
   PERFLIBS += $(LIBBPF)
 endif
@@ -583,8 +586,6 @@ JEVENTS_IN:= $(OUTPUT)pmu-events/jevents-in.o
 
 PMU_EVENTS_IN := $(OUTPUT)pmu-events/pmu-events-in.o
 
-LIBPERF_IN := $(OUTPUT)libperf-in.o
-
 export JEVENTS
 
 build := -f $(srctree)/tools/build/Makefile.build dir=. obj
@@ -601,12 +602,9 @@ $(JEVENTS): $(JEVENTS_IN)
 $(PMU_EVENTS_IN): $(JEVENTS) FORCE
$(Q)$(MAKE) -f $(srctree)/tools/build/Makefile.build dir=pmu-events 
obj=pmu-events
 
-$(LIBPERF_IN): prepare FORCE
-   $(Q)$(MAKE) $(build)=libperf
-
-$(OUTPUT)perf: $(PERFLIBS) $(PERF_IN) $(PMU_EVENTS_IN) $(LIBPERF_IN) 
$(LIBTRACEEVENT_DYNAMIC_LIST)
+$(OUTPUT)perf: $(PERFLIBS) $(PERF_IN) $(PMU_EVENTS_IN) 

[tip:perf/core] perf evlist: Rename perf_evlist__disable() to evlist__disable()

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  e74676debaae7dcce20a34817ef145478887ba95
Gitweb: https://git.kernel.org/tip/e74676debaae7dcce20a34817ef145478887ba95
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:09 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:43 -0300

perf evlist: Rename perf_evlist__disable() to evlist__disable()

Rename perf_evlist__disable() to evlist__disable(), so we don't have a
name clash when we add perf_evlist__disable() in libperf.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-23-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/arch/x86/tests/perf-time-to-tsc.c | 2 +-
 tools/perf/builtin-kvm.c | 2 +-
 tools/perf/builtin-record.c  | 2 +-
 tools/perf/builtin-stat.c| 2 +-
 tools/perf/builtin-trace.c   | 4 ++--
 tools/perf/tests/backward-ring-buffer.c  | 2 +-
 tools/perf/tests/bpf.c   | 2 +-
 tools/perf/tests/code-reading.c  | 2 +-
 tools/perf/tests/keep-tracking.c | 6 +++---
 tools/perf/tests/sw-clock.c  | 2 +-
 tools/perf/tests/switch-tracking.c   | 4 ++--
 tools/perf/util/evlist.c | 4 ++--
 tools/perf/util/evlist.h | 2 +-
 13 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/tools/perf/arch/x86/tests/perf-time-to-tsc.c 
b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
index aa5a5c972ce5..8b70e9ee341a 100644
--- a/tools/perf/arch/x86/tests/perf-time-to-tsc.c
+++ b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
@@ -107,7 +107,7 @@ int test__perf_time_to_tsc(struct test *test 
__maybe_unused, int subtest __maybe
comm2 = "Test COMM 2";
CHECK__(prctl(PR_SET_NAME, (unsigned long)comm2, 0, 0, 0));
 
-   perf_evlist__disable(evlist);
+   evlist__disable(evlist);
 
for (i = 0; i < evlist->nr_mmaps; i++) {
md = >mmap[i];
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 9207bd49583e..3370eba0d3f3 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -993,7 +993,7 @@ static int kvm_events_live_report(struct perf_kvm_stat *kvm)
err = fdarray__poll(fda, 100);
}
 
-   perf_evlist__disable(kvm->evlist);
+   evlist__disable(kvm->evlist);
 
if (err == 0) {
sort_result(kvm);
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 8e20ead0ddbe..c0962ddfad04 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1605,7 +1605,7 @@ static int __cmd_record(struct record *rec, int argc, 
const char **argv)
 */
if (done && !disabled && !target__none(>target)) {
trigger_off(_snapshot_trigger);
-   perf_evlist__disable(rec->evlist);
+   evlist__disable(rec->evlist);
disabled = true;
}
}
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index c0e9d94b6dd5..36e66a4f3c57 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -373,7 +373,7 @@ static void disable_counters(void)
 * from counting before reading their constituent counters.
 */
if (!target__none())
-   perf_evlist__disable(evsel_list);
+   evlist__disable(evsel_list);
 }
 
 static volatile int workload_exec_errno;
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 46fab1ff92dc..51d142594a12 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -3451,7 +3451,7 @@ again:
goto out_disable;
 
if (done && !draining) {
-   perf_evlist__disable(evlist);
+   evlist__disable(evlist);
draining = true;
}
}
@@ -3477,7 +3477,7 @@ again:
 out_disable:
thread__zput(trace->current);
 
-   perf_evlist__disable(evlist);
+   evlist__disable(evlist);
 
if (trace->sort_events)
ordered_events__flush(>oe.data, OE_FLUSH__FINAL);
diff --git a/tools/perf/tests/backward-ring-buffer.c 
b/tools/perf/tests/backward-ring-buffer.c
index f4b45702821d..9bdf66139099 100644
--- a/tools/perf/tests/backward-ring-buffer.c
+++ b/tools/perf/tests/backward-ring-buffer.c
@@ -70,7 +70,7 @@ static int do_test(struct evlist *evlist, int mmap_pages,
 
evlist__enable(evlist);
testcase();
-   perf_evlist__disable(evlist);
+   evlist__disable(evlist);
 
err = count_samples(evlist, sample_count, comm_count);
perf_evlist__munmap(evlist);
diff --git a/tools/perf/tests/bpf.c b/tools/perf/tests/bpf.c
index 

[tip:perf/core] perf evlist: Rename perf_evlist__open() to evlist__open()

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  474ddc4c46025a615d0ea791d37ce9038fa20229
Gitweb: https://git.kernel.org/tip/474ddc4c46025a615d0ea791d37ce9038fa20229
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:06 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:43 -0300

perf evlist: Rename perf_evlist__open() to evlist__open()

Rename perf_evlist__open() to evlist__open(), so we don't have a name
clash when we add perf_evlist__open() in libperf.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-20-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/arch/x86/tests/perf-time-to-tsc.c | 2 +-
 tools/perf/builtin-kvm.c | 2 +-
 tools/perf/builtin-trace.c   | 2 +-
 tools/perf/tests/backward-ring-buffer.c  | 2 +-
 tools/perf/tests/bpf.c   | 2 +-
 tools/perf/tests/code-reading.c  | 2 +-
 tools/perf/tests/event-times.c   | 2 +-
 tools/perf/tests/keep-tracking.c | 2 +-
 tools/perf/tests/openat-syscall-tp-fields.c  | 2 +-
 tools/perf/tests/perf-record.c   | 2 +-
 tools/perf/tests/sw-clock.c  | 2 +-
 tools/perf/tests/switch-tracking.c   | 2 +-
 tools/perf/tests/task-exit.c | 2 +-
 tools/perf/util/evlist.c | 2 +-
 tools/perf/util/evlist.h | 2 +-
 tools/perf/util/python.c | 2 +-
 16 files changed, 16 insertions(+), 16 deletions(-)

diff --git a/tools/perf/arch/x86/tests/perf-time-to-tsc.c 
b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
index 09b6cef76f5b..ea4cf1d367a6 100644
--- a/tools/perf/arch/x86/tests/perf-time-to-tsc.c
+++ b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
@@ -83,7 +83,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, 
int subtest __maybe
evsel->attr.disabled = 1;
evsel->attr.enable_on_exec = 0;
 
-   CHECK__(perf_evlist__open(evlist));
+   CHECK__(evlist__open(evlist));
 
CHECK__(perf_evlist__mmap(evlist, UINT_MAX));
 
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 8f54bdfb5743..85604d117558 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -1048,7 +1048,7 @@ static int kvm_live_open_events(struct perf_kvm_stat *kvm)
attr->disabled = 1;
}
 
-   err = perf_evlist__open(evlist);
+   err = evlist__open(evlist);
if (err < 0) {
printf("Couldn't create the events: %s\n",
   str_error_r(errno, sbuf, sizeof(sbuf)));
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 95ecefa9ff7e..e508fdb77099 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -3342,7 +3342,7 @@ static int trace__run(struct trace *trace, int argc, 
const char **argv)
}
}
 
-   err = perf_evlist__open(evlist);
+   err = evlist__open(evlist);
if (err < 0)
goto out_error_open;
 
diff --git a/tools/perf/tests/backward-ring-buffer.c 
b/tools/perf/tests/backward-ring-buffer.c
index ef3c6db2fae4..8de2d6ad93ce 100644
--- a/tools/perf/tests/backward-ring-buffer.c
+++ b/tools/perf/tests/backward-ring-buffer.c
@@ -125,7 +125,7 @@ int test__backward_ring_buffer(struct test *test 
__maybe_unused, int subtest __m
 
perf_evlist__config(evlist, , NULL);
 
-   err = perf_evlist__open(evlist);
+   err = evlist__open(evlist);
if (err < 0) {
pr_debug("perf_evlist__open: %s\n",
 str_error_r(errno, sbuf, sizeof(sbuf)));
diff --git a/tools/perf/tests/bpf.c b/tools/perf/tests/bpf.c
index 313ff1aadd9c..b41c41482283 100644
--- a/tools/perf/tests/bpf.c
+++ b/tools/perf/tests/bpf.c
@@ -157,7 +157,7 @@ static int do_test(struct bpf_object *obj, int 
(*func)(void),
 
perf_evlist__config(evlist, , NULL);
 
-   err = perf_evlist__open(evlist);
+   err = evlist__open(evlist);
if (err < 0) {
pr_debug("perf_evlist__open: %s\n",
 str_error_r(errno, sbuf, sizeof(sbuf)));
diff --git a/tools/perf/tests/code-reading.c b/tools/perf/tests/code-reading.c
index 1c7f092a7388..23abc775a69c 100644
--- a/tools/perf/tests/code-reading.c
+++ b/tools/perf/tests/code-reading.c
@@ -646,7 +646,7 @@ static int do_test_code_reading(bool try_kcore)
evsel->attr.disabled = 1;
evsel->attr.enable_on_exec = 0;
 
-   ret = perf_evlist__open(evlist);
+   ret = evlist__open(evlist);
if (ret < 0) {
if (!excl_kernel) {
excl_kernel = true;
diff --git a/tools/perf/tests/event-times.c b/tools/perf/tests/event-times.c
index 6f9995df2c27..bf00d3d792fb 100644
--- a/tools/perf/tests/event-times.c
+++ 

[tip:perf/core] perf evlist: Rename perf_evlist__close() to evlist__close()

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  750b4edeb0527414fb17b0ee2a76d2dbbd9a199d
Gitweb: https://git.kernel.org/tip/750b4edeb0527414fb17b0ee2a76d2dbbd9a199d
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:07 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:43 -0300

perf evlist: Rename perf_evlist__close() to evlist__close()

Rename perf_evlist__close() to evlist__close(), so we don't have a name
clash when we add perf_evlist__close() in libperf.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-21-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-kvm.c  | 2 +-
 tools/perf/builtin-stat.c | 4 ++--
 tools/perf/util/evlist.c  | 6 +++---
 tools/perf/util/evlist.h  | 2 +-
 4 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 85604d117558..6a0573a9c16b 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -1058,7 +1058,7 @@ static int kvm_live_open_events(struct perf_kvm_stat *kvm)
if (perf_evlist__mmap(evlist, kvm->opts.mmap_pages) < 0) {
ui__error("Failed to mmap the events: %s\n",
  str_error_r(errno, sbuf, sizeof(sbuf)));
-   perf_evlist__close(evlist);
+   evlist__close(evlist);
goto out;
}
 
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index d28d4d71d9b7..bdfe138f7aed 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -613,7 +613,7 @@ try_again:
 * later the evsel_list will be closed after.
 */
if (!STAT_RECORD)
-   perf_evlist__close(evsel_list);
+   evlist__close(evsel_list);
 
return WEXITSTATUS(status);
 }
@@ -2003,7 +2003,7 @@ int cmd_stat(int argc, const char **argv)
perf_session__write_header(perf_stat.session, 
evsel_list, fd, true);
}
 
-   perf_evlist__close(evsel_list);
+   evlist__close(evsel_list);
perf_session__delete(perf_stat.session);
}
 
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 7d44e05dfaa4..67c288f467f6 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -140,7 +140,7 @@ void evlist__delete(struct evlist *evlist)
return;
 
perf_evlist__munmap(evlist);
-   perf_evlist__close(evlist);
+   evlist__close(evlist);
cpu_map__put(evlist->cpus);
thread_map__put(evlist->threads);
evlist->cpus = NULL;
@@ -1348,7 +1348,7 @@ void perf_evlist__set_selected(struct evlist *evlist,
evlist->selected = evsel;
 }
 
-void perf_evlist__close(struct evlist *evlist)
+void evlist__close(struct evlist *evlist)
 {
struct evsel *evsel;
 
@@ -1412,7 +1412,7 @@ int evlist__open(struct evlist *evlist)
 
return 0;
 out_err:
-   perf_evlist__close(evlist);
+   evlist__close(evlist);
errno = -err;
return err;
 }
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index f4b3152c879e..47e9d26b6774 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -147,7 +147,7 @@ void perf_evlist__toggle_bkw_mmap(struct evlist *evlist, 
enum bkw_mmap_state sta
 void perf_evlist__mmap_consume(struct evlist *evlist, int idx);
 
 int evlist__open(struct evlist *evlist);
-void perf_evlist__close(struct evlist *evlist);
+void evlist__close(struct evlist *evlist);
 
 struct callchain_param;
 


[tip:perf/core] perf evsel: Rename perf_evsel__cpus() to evsel__cpus()

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  b49aca3e9ce60d00e5bf0694b2ff4c2cd40809e5
Gitweb: https://git.kernel.org/tip/b49aca3e9ce60d00e5bf0694b2ff4c2cd40809e5
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:05 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:43 -0300

perf evsel: Rename perf_evsel__cpus() to evsel__cpus()

Rename perf_evsel__cpus() to evsel__cpus(), so we don't have a name
clash when we add perf_evsel__cpus() in libperf.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-19-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/evsel.h| 4 ++--
 tools/perf/util/stat-display.c | 6 +++---
 tools/perf/util/stat.c | 4 ++--
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 35f7e7ff3c5e..5fec1ca64f58 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -197,14 +197,14 @@ struct target;
 struct thread_map;
 struct record_opts;
 
-static inline struct perf_cpu_map *perf_evsel__cpus(struct evsel *evsel)
+static inline struct perf_cpu_map *evsel__cpus(struct evsel *evsel)
 {
return evsel->cpus;
 }
 
 static inline int perf_evsel__nr_cpus(struct evsel *evsel)
 {
-   return perf_evsel__cpus(evsel)->nr;
+   return evsel__cpus(evsel)->nr;
 }
 
 void perf_counts_values__scale(struct perf_counts_values *count,
diff --git a/tools/perf/util/stat-display.c b/tools/perf/util/stat-display.c
index cdfceb5b4d72..f7666d2e6e0c 100644
--- a/tools/perf/util/stat-display.c
+++ b/tools/perf/util/stat-display.c
@@ -109,7 +109,7 @@ static void aggr_printout(struct perf_stat_config *config,
} else {
fprintf(config->output, "CPU%*d%s ",
config->csv_output ? 0 : -5,
-   perf_evsel__cpus(evsel)->map[id],
+   evsel__cpus(evsel)->map[id],
config->csv_sep);
}
break;
@@ -325,7 +325,7 @@ static int first_shadow_cpu(struct perf_stat_config *config,
return 0;
 
for (i = 0; i < perf_evsel__nr_cpus(evsel); i++) {
-   int cpu2 = perf_evsel__cpus(evsel)->map[i];
+   int cpu2 = evsel__cpus(evsel)->map[i];
 
if (config->aggr_get_id(config, evlist->cpus, cpu2) == id)
return cpu2;
@@ -593,7 +593,7 @@ static void aggr_cb(struct perf_stat_config *config,
for (cpu = 0; cpu < perf_evsel__nr_cpus(counter); cpu++) {
struct perf_counts_values *counts;
 
-   s2 = config->aggr_get_id(config, perf_evsel__cpus(counter), 
cpu);
+   s2 = config->aggr_get_id(config, evsel__cpus(counter), cpu);
if (s2 != ad->id)
continue;
if (first)
diff --git a/tools/perf/util/stat.c b/tools/perf/util/stat.c
index efd934ec02c3..63f7815ceb4f 100644
--- a/tools/perf/util/stat.c
+++ b/tools/perf/util/stat.c
@@ -215,7 +215,7 @@ static int check_per_pkg(struct evsel *counter,
 struct perf_counts_values *vals, int cpu, bool *skip)
 {
unsigned long *mask = counter->per_pkg_mask;
-   struct perf_cpu_map *cpus = perf_evsel__cpus(counter);
+   struct perf_cpu_map *cpus = evsel__cpus(counter);
int s;
 
*skip = false;
@@ -483,7 +483,7 @@ int create_perf_stat_counter(struct evsel *evsel,
}
 
if (target__has_cpu(target) && !target__has_per_thread(target))
-   return perf_evsel__open_per_cpu(evsel, perf_evsel__cpus(evsel));
+   return perf_evsel__open_per_cpu(evsel, evsel__cpus(evsel));
 
return perf_evsel__open_per_thread(evsel, evsel->threads);
 }


[tip:perf/core] perf evsel: Rename perf_evsel__apply_filter() to evsel__apply_filter()

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  24e376b24582648d363df4e0a6bcc2ffcecd211e
Gitweb: https://git.kernel.org/tip/24e376b24582648d363df4e0a6bcc2ffcecd211e
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:04 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:43 -0300

perf evsel: Rename perf_evsel__apply_filter() to evsel__apply_filter()

Rename perf_evsel__apply_filter() to evsel__apply_filter(), so we don't
have a name clash when we add perf_evsel__apply_filter() in libperf.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-18-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/evlist.c | 2 +-
 tools/perf/util/evsel.c  | 2 +-
 tools/perf/util/evsel.h  | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 9461583c53d9..e71c3cc93924 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -1158,7 +1158,7 @@ int perf_evlist__apply_filters(struct evlist *evlist, 
struct evsel **err_evsel)
 * filters only work for tracepoint event, which doesn't have 
cpu limit.
 * So evlist and evsel should always be same.
 */
-   err = perf_evsel__apply_filter(evsel, evsel->filter);
+   err = evsel__apply_filter(evsel, evsel->filter);
if (err) {
*err_evsel = evsel;
break;
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 855d286298eb..5aeb7260c8e1 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1187,7 +1187,7 @@ static int perf_evsel__run_ioctl(struct evsel *evsel,
return 0;
 }
 
-int perf_evsel__apply_filter(struct evsel *evsel, const char *filter)
+int evsel__apply_filter(struct evsel *evsel, const char *filter)
 {
return perf_evsel__run_ioctl(evsel,
 PERF_EVENT_IOC_SET_FILTER,
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index c338ce14e8aa..35f7e7ff3c5e 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -294,7 +294,7 @@ int perf_evsel__set_filter(struct evsel *evsel, const char 
*filter);
 int perf_evsel__append_tp_filter(struct evsel *evsel, const char *filter);
 int perf_evsel__append_addr_filter(struct evsel *evsel,
   const char *filter);
-int perf_evsel__apply_filter(struct evsel *evsel, const char *filter);
+int evsel__apply_filter(struct evsel *evsel, const char *filter);
 int evsel__enable(struct evsel *evsel);
 int evsel__disable(struct evsel *evsel);
 


[tip:perf/core] perf evsel: Rename perf_evsel__disable() to evsel__disable()

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  9a10bb22897ae9c2aa0ac9c2071f539f406ef942
Gitweb: https://git.kernel.org/tip/9a10bb22897ae9c2aa0ac9c2071f539f406ef942
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:03 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:43 -0300

perf evsel: Rename perf_evsel__disable() to evsel__disable()

Renaming perf_evsel__disable() to evsel__disable(), so we don't have a
name clash when we add perf_evsel__disable() in libperf.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-17-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/arch/arm/util/cs-etm.c| 2 +-
 tools/perf/arch/x86/util/intel-bts.c | 2 +-
 tools/perf/arch/x86/util/intel-pt.c  | 2 +-
 tools/perf/builtin-trace.c   | 2 +-
 tools/perf/tests/keep-tracking.c | 2 +-
 tools/perf/tests/switch-tracking.c   | 4 ++--
 tools/perf/util/evlist.c | 2 +-
 tools/perf/util/evsel.c  | 2 +-
 tools/perf/util/evsel.h  | 2 +-
 9 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/tools/perf/arch/arm/util/cs-etm.c 
b/tools/perf/arch/arm/util/cs-etm.c
index 4b70b9504603..268fcb31cd53 100644
--- a/tools/perf/arch/arm/util/cs-etm.c
+++ b/tools/perf/arch/arm/util/cs-etm.c
@@ -821,7 +821,7 @@ static int cs_etm_snapshot_start(struct auxtrace_record 
*itr)
 
evlist__for_each_entry(ptr->evlist, evsel) {
if (evsel->attr.type == ptr->cs_etm_pmu->type)
-   return perf_evsel__disable(evsel);
+   return evsel__disable(evsel);
}
return -EINVAL;
 }
diff --git a/tools/perf/arch/x86/util/intel-bts.c 
b/tools/perf/arch/x86/util/intel-bts.c
index d27832fcb34c..8b0a53d748c9 100644
--- a/tools/perf/arch/x86/util/intel-bts.c
+++ b/tools/perf/arch/x86/util/intel-bts.c
@@ -317,7 +317,7 @@ static int intel_bts_snapshot_start(struct auxtrace_record 
*itr)
 
evlist__for_each_entry(btsr->evlist, evsel) {
if (evsel->attr.type == btsr->intel_bts_pmu->type)
-   return perf_evsel__disable(evsel);
+   return evsel__disable(evsel);
}
return -EINVAL;
 }
diff --git a/tools/perf/arch/x86/util/intel-pt.c 
b/tools/perf/arch/x86/util/intel-pt.c
index e3dacb2bf01b..4ce157a4e5e2 100644
--- a/tools/perf/arch/x86/util/intel-pt.c
+++ b/tools/perf/arch/x86/util/intel-pt.c
@@ -788,7 +788,7 @@ static int intel_pt_snapshot_start(struct auxtrace_record 
*itr)
 
evlist__for_each_entry(ptr->evlist, evsel) {
if (evsel->attr.type == ptr->intel_pt_pmu->type)
-   return perf_evsel__disable(evsel);
+   return evsel__disable(evsel);
}
return -EINVAL;
 }
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 89ae4737ef74..95ecefa9ff7e 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -2400,7 +2400,7 @@ static int trace__event_handler(struct trace *trace, 
struct evsel *evsel,
++trace->nr_events_printed;
 
if (evsel->max_events != ULONG_MAX && 
++evsel->nr_events_printed == evsel->max_events) {
-   perf_evsel__disable(evsel);
+   evsel__disable(evsel);
perf_evsel__close(evsel);
}
}
diff --git a/tools/perf/tests/keep-tracking.c b/tools/perf/tests/keep-tracking.c
index cdc19bcc7523..1976ccb3c812 100644
--- a/tools/perf/tests/keep-tracking.c
+++ b/tools/perf/tests/keep-tracking.c
@@ -129,7 +129,7 @@ int test__keep_tracking(struct test *test __maybe_unused, 
int subtest __maybe_un
 
evsel = perf_evlist__last(evlist);
 
-   CHECK__(perf_evsel__disable(evsel));
+   CHECK__(evsel__disable(evsel));
 
comm = "Test COMM 2";
CHECK__(prctl(PR_SET_NAME, (unsigned long)comm, 0, 0, 0));
diff --git a/tools/perf/tests/switch-tracking.c 
b/tools/perf/tests/switch-tracking.c
index acc4b5ff0cea..5662dc1c6bd3 100644
--- a/tools/perf/tests/switch-tracking.c
+++ b/tools/perf/tests/switch-tracking.c
@@ -464,7 +464,7 @@ int test__switch_tracking(struct test *test __maybe_unused, 
int subtest __maybe_
 
perf_evlist__enable(evlist);
 
-   err = perf_evsel__disable(cpu_clocks_evsel);
+   err = evsel__disable(cpu_clocks_evsel);
if (err) {
pr_debug("perf_evlist__disable_event failed!\n");
goto out_err;
@@ -483,7 +483,7 @@ int test__switch_tracking(struct test *test __maybe_unused, 
int subtest __maybe_
goto out_err;
}
 
-   err = perf_evsel__disable(cycles_evsel);
+   err = evsel__disable(cycles_evsel);
if (err) {
pr_debug("perf_evlist__disable_event failed!\n");
goto 

[tip:perf/core] perf evsel: Rename perf_evsel__enable() to evsel__enable()

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  ec7f24ef44fc5a4eb5cb71658c33db538ed66003
Gitweb: https://git.kernel.org/tip/ec7f24ef44fc5a4eb5cb71658c33db538ed66003
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:02 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:43 -0300

perf evsel: Rename perf_evsel__enable() to evsel__enable()

Rename perf_evsel__enable() to evsel__enable(), so we don't have a name
clash when we add perf_evsel__enable() in libperf.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-16-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/arch/arm/util/cs-etm.c| 2 +-
 tools/perf/arch/x86/util/intel-bts.c | 2 +-
 tools/perf/arch/x86/util/intel-pt.c  | 2 +-
 tools/perf/tests/event-times.c   | 6 +++---
 tools/perf/tests/switch-tracking.c   | 2 +-
 tools/perf/util/evlist.c | 4 ++--
 tools/perf/util/evsel.c  | 2 +-
 tools/perf/util/evsel.h  | 2 +-
 8 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/tools/perf/arch/arm/util/cs-etm.c 
b/tools/perf/arch/arm/util/cs-etm.c
index 91c64daa4487..4b70b9504603 100644
--- a/tools/perf/arch/arm/util/cs-etm.c
+++ b/tools/perf/arch/arm/util/cs-etm.c
@@ -834,7 +834,7 @@ static int cs_etm_snapshot_finish(struct auxtrace_record 
*itr)
 
evlist__for_each_entry(ptr->evlist, evsel) {
if (evsel->attr.type == ptr->cs_etm_pmu->type)
-   return perf_evsel__enable(evsel);
+   return evsel__enable(evsel);
}
return -EINVAL;
 }
diff --git a/tools/perf/arch/x86/util/intel-bts.c 
b/tools/perf/arch/x86/util/intel-bts.c
index c845531d383a..d27832fcb34c 100644
--- a/tools/perf/arch/x86/util/intel-bts.c
+++ b/tools/perf/arch/x86/util/intel-bts.c
@@ -330,7 +330,7 @@ static int intel_bts_snapshot_finish(struct auxtrace_record 
*itr)
 
evlist__for_each_entry(btsr->evlist, evsel) {
if (evsel->attr.type == btsr->intel_bts_pmu->type)
-   return perf_evsel__enable(evsel);
+   return evsel__enable(evsel);
}
return -EINVAL;
 }
diff --git a/tools/perf/arch/x86/util/intel-pt.c 
b/tools/perf/arch/x86/util/intel-pt.c
index e4dfe8c3d5c3..e3dacb2bf01b 100644
--- a/tools/perf/arch/x86/util/intel-pt.c
+++ b/tools/perf/arch/x86/util/intel-pt.c
@@ -801,7 +801,7 @@ static int intel_pt_snapshot_finish(struct auxtrace_record 
*itr)
 
evlist__for_each_entry(ptr->evlist, evsel) {
if (evsel->attr.type == ptr->intel_pt_pmu->type)
-   return perf_evsel__enable(evsel);
+   return evsel__enable(evsel);
}
return -EINVAL;
 }
diff --git a/tools/perf/tests/event-times.c b/tools/perf/tests/event-times.c
index 0f74ca103c41..6f9995df2c27 100644
--- a/tools/perf/tests/event-times.c
+++ b/tools/perf/tests/event-times.c
@@ -77,7 +77,7 @@ static int attach__current_disabled(struct evlist *evlist)
}
 
thread_map__put(threads);
-   return perf_evsel__enable(evsel) == 0 ? TEST_OK : TEST_FAIL;
+   return evsel__enable(evsel) == 0 ? TEST_OK : TEST_FAIL;
 }
 
 static int attach__current_enabled(struct evlist *evlist)
@@ -104,7 +104,7 @@ static int detach__disable(struct evlist *evlist)
 {
struct evsel *evsel = perf_evlist__last(evlist);
 
-   return perf_evsel__enable(evsel);
+   return evsel__enable(evsel);
 }
 
 static int attach__cpu_disabled(struct evlist *evlist)
@@ -133,7 +133,7 @@ static int attach__cpu_disabled(struct evlist *evlist)
}
 
cpu_map__put(cpus);
-   return perf_evsel__enable(evsel);
+   return evsel__enable(evsel);
 }
 
 static int attach__cpu_enabled(struct evlist *evlist)
diff --git a/tools/perf/tests/switch-tracking.c 
b/tools/perf/tests/switch-tracking.c
index ac5da4fd222f..acc4b5ff0cea 100644
--- a/tools/perf/tests/switch-tracking.c
+++ b/tools/perf/tests/switch-tracking.c
@@ -509,7 +509,7 @@ int test__switch_tracking(struct test *test __maybe_unused, 
int subtest __maybe_
goto out_err;
}
 
-   err = perf_evsel__enable(cycles_evsel);
+   err = evsel__enable(cycles_evsel);
if (err) {
pr_debug("perf_evlist__disable_event failed!\n");
goto out_err;
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 4627cc47de3e..e87c43e339d0 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -363,7 +363,7 @@ void perf_evlist__enable(struct evlist *evlist)
evlist__for_each_entry(evlist, pos) {
if (!perf_evsel__is_group_leader(pos) || !pos->fd)
continue;
-   perf_evsel__enable(pos);
+   evsel__enable(pos);
}
 
evlist->enabled = true;
@@ -1927,7 +1927,7 @@ int 

[tip:perf/core] perf evlist: Rename perf_evlist__remove() to evlist__remove()

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  1625102764a578b11fb407b8194cb0521129d919
Gitweb: https://git.kernel.org/tip/1625102764a578b11fb407b8194cb0521129d919
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:00 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:43 -0300

perf evlist: Rename perf_evlist__remove() to evlist__remove()

Rename perf_evlist__remove() to evlist__remove(), so we don't have a
name clash when we add perf_evlist__remove() in libperf.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-14-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-inject.c | 4 ++--
 tools/perf/util/evlist.c| 2 +-
 tools/perf/util/evlist.h| 2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index 917c8fb4baa5..4e56e399bbc8 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -622,7 +622,7 @@ static void strip_fini(struct perf_inject *inject)
if (evsel->handler == drop_sample &&
ok_to_remove(evlist, evsel)) {
pr_debug("Deleting %s\n", perf_evsel__name(evsel));
-   perf_evlist__remove(evlist, evsel);
+   evlist__remove(evlist, evsel);
evsel__delete(evsel);
}
}
@@ -724,7 +724,7 @@ static int __cmd_inject(struct perf_inject *inject)
if (evsel) {
pr_debug("Deleting %s\n",
 perf_evsel__name(evsel));
-   perf_evlist__remove(session->evlist, evsel);
+   evlist__remove(session->evlist, evsel);
evsel__delete(evsel);
}
if (inject->strip)
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 7741e12bdcb0..47516db62424 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -190,7 +190,7 @@ void evlist__add(struct evlist *evlist, struct evsel *entry)
__perf_evlist__propagate_maps(evlist, entry);
 }
 
-void perf_evlist__remove(struct evlist *evlist, struct evsel *evsel)
+void evlist__remove(struct evlist *evlist, struct evsel *evsel)
 {
evsel->evlist = NULL;
list_del_init(>node);
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index d52b29a1d852..b3a44e2eed08 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -74,7 +74,7 @@ void perf_evlist__exit(struct evlist *evlist);
 void evlist__delete(struct evlist *evlist);
 
 void evlist__add(struct evlist *evlist, struct evsel *entry);
-void perf_evlist__remove(struct evlist *evlist, struct evsel *evsel);
+void evlist__remove(struct evlist *evlist, struct evsel *evsel);
 
 int __perf_evlist__add_default(struct evlist *evlist, bool precise);
 


[tip:perf/core] perf evsel: Rename perf_evsel__open() to evsel__open()

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  5972d1e07bd95c7458e2d7f484391d69008affc7
Gitweb: https://git.kernel.org/tip/5972d1e07bd95c7458e2d7f484391d69008affc7
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:24:01 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:43 -0300

perf evsel: Rename perf_evsel__open() to evsel__open()

Rename perf_evsel__open() to evsel__open(), so we don't have a name
clash when we add perf_evsel__open() in libperf.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-15-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-record.c| 2 +-
 tools/perf/builtin-top.c   | 2 +-
 tools/perf/tests/mmap-basic.c  | 2 +-
 tools/perf/tests/openat-syscall-all-cpus.c | 2 +-
 tools/perf/util/evlist.c   | 4 ++--
 tools/perf/util/evsel.c| 8 
 tools/perf/util/evsel.h| 4 ++--
 tools/perf/util/parse-events.c | 4 ++--
 tools/perf/util/python.c   | 2 +-
 9 files changed, 15 insertions(+), 15 deletions(-)

diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 06966a2c2cdd..7f933997b6d0 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -739,7 +739,7 @@ static int record__open(struct record *rec)
 
evlist__for_each_entry(evlist, pos) {
 try_again:
-   if (perf_evsel__open(pos, pos->cpus, pos->threads) < 0) {
+   if (evsel__open(pos, pos->cpus, pos->threads) < 0) {
if (perf_evsel__fallback(pos, errno, msg, sizeof(msg))) 
{
if (verbose > 0)
ui__warning("%s\n", msg);
diff --git a/tools/perf/builtin-top.c b/tools/perf/builtin-top.c
index 6c0c2b78093a..5886389f6a40 100644
--- a/tools/perf/builtin-top.c
+++ b/tools/perf/builtin-top.c
@@ -989,7 +989,7 @@ static int perf_top__start_counters(struct perf_top *top)
 
evlist__for_each_entry(evlist, counter) {
 try_again:
-   if (perf_evsel__open(counter, top->evlist->cpus,
+   if (evsel__open(counter, top->evlist->cpus,
 top->evlist->threads) < 0) {
 
/*
diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c
index 16b8a4e5de8f..40511025208f 100644
--- a/tools/perf/tests/mmap-basic.c
+++ b/tools/perf/tests/mmap-basic.c
@@ -84,7 +84,7 @@ int test__basic_mmap(struct test *test __maybe_unused, int 
subtest __maybe_unuse
 
evlist__add(evlist, evsels[i]);
 
-   if (perf_evsel__open(evsels[i], cpus, threads) < 0) {
+   if (evsel__open(evsels[i], cpus, threads) < 0) {
pr_debug("failed to open counter: %s, "
 "tweak 
/proc/sys/kernel/perf_event_paranoid?\n",
 str_error_r(errno, sbuf, sizeof(sbuf)));
diff --git a/tools/perf/tests/openat-syscall-all-cpus.c 
b/tools/perf/tests/openat-syscall-all-cpus.c
index 001a0e8e6998..f96cbd304024 100644
--- a/tools/perf/tests/openat-syscall-all-cpus.c
+++ b/tools/perf/tests/openat-syscall-all-cpus.c
@@ -48,7 +48,7 @@ int test__openat_syscall_event_on_all_cpus(struct test *test 
__maybe_unused, int
goto out_cpu_map_delete;
}
 
-   if (perf_evsel__open(evsel, cpus, threads) < 0) {
+   if (evsel__open(evsel, cpus, threads) < 0) {
pr_debug("failed to open counter: %s, "
 "tweak /proc/sys/kernel/perf_event_paranoid?\n",
 str_error_r(errno, sbuf, sizeof(sbuf)));
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index 47516db62424..4627cc47de3e 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -1405,7 +1405,7 @@ int perf_evlist__open(struct evlist *evlist)
perf_evlist__update_id_pos(evlist);
 
evlist__for_each_entry(evlist, evsel) {
-   err = perf_evsel__open(evsel, evsel->cpus, evsel->threads);
+   err = evsel__open(evsel, evsel->cpus, evsel->threads);
if (err < 0)
goto out_err;
}
@@ -1918,7 +1918,7 @@ int perf_evlist__start_sb_thread(struct evlist *evlist,
goto out_delete_evlist;
 
evlist__for_each_entry(evlist, counter) {
-   if (perf_evsel__open(counter, evlist->cpus,
+   if (evsel__open(counter, evlist->cpus,
 evlist->threads) < 0)
goto out_delete_evlist;
}
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index c9723c2d57c9..f365d0685268 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1825,8 +1825,8 @@ static int perf_event_open(struct evsel *evsel,
 

[tip:perf/core] perf evlist: Rename perf_evlist__add() to evlist__add()

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  a1cf3a75d3317ed893d453c222d220ca4d5f4c4e
Gitweb: https://git.kernel.org/tip/a1cf3a75d3317ed893d453c222d220ca4d5f4c4e
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:23:59 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:43 -0300

perf evlist: Rename perf_evlist__add() to evlist__add()

Rename perf_evlist__add() to evlist__add(), so we don't have a name
clash when we add perf_evlist__add() in libperf.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-13-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-trace.c  | 12 ++--
 tools/perf/tests/mmap-basic.c   |  2 +-
 tools/perf/tests/openat-syscall-tp-fields.c |  2 +-
 tools/perf/tests/sw-clock.c |  2 +-
 tools/perf/util/evlist.c| 16 
 tools/perf/util/evlist.h|  2 +-
 tools/perf/util/header.c|  4 ++--
 tools/perf/util/python.c|  2 +-
 8 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index c5eb47f4e42e..89ae4737ef74 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -2616,7 +2616,7 @@ static int trace__record(struct trace *trace, int argc, 
const char **argv)
 
 static size_t trace__fprintf_thread_summary(struct trace *trace, FILE *fp);
 
-static bool perf_evlist__add_vfs_getname(struct evlist *evlist)
+static bool evlist__add_vfs_getname(struct evlist *evlist)
 {
bool found = false;
struct evsel *evsel, *tmp;
@@ -2719,8 +2719,8 @@ static int trace__add_syscall_newtp(struct trace *trace)
perf_evsel__config_callchain(sys_enter, >opts, _param);
perf_evsel__config_callchain(sys_exit, >opts, _param);
 
-   perf_evlist__add(evlist, sys_enter);
-   perf_evlist__add(evlist, sys_exit);
+   evlist__add(evlist, sys_enter);
+   evlist__add(evlist, sys_exit);
 
if (callchain_param.enabled && !trace->kernel_syscallchains) {
/*
@@ -3264,7 +3264,7 @@ static int trace__run(struct trace *trace, int argc, 
const char **argv)
goto out_error_raw_syscalls;
 
if (trace->trace_syscalls)
-   trace->vfs_getname = 
perf_evlist__add_vfs_getname(evlist);
+   trace->vfs_getname = evlist__add_vfs_getname(evlist);
}
 
if ((trace->trace_pgfaults & TRACE_PFMAJ)) {
@@ -3272,7 +3272,7 @@ static int trace__run(struct trace *trace, int argc, 
const char **argv)
if (pgfault_maj == NULL)
goto out_error_mem;
perf_evsel__config_callchain(pgfault_maj, >opts, 
_param);
-   perf_evlist__add(evlist, pgfault_maj);
+   evlist__add(evlist, pgfault_maj);
}
 
if ((trace->trace_pgfaults & TRACE_PFMIN)) {
@@ -3280,7 +3280,7 @@ static int trace__run(struct trace *trace, int argc, 
const char **argv)
if (pgfault_min == NULL)
goto out_error_mem;
perf_evsel__config_callchain(pgfault_min, >opts, 
_param);
-   perf_evlist__add(evlist, pgfault_min);
+   evlist__add(evlist, pgfault_min);
}
 
if (trace->sched &&
diff --git a/tools/perf/tests/mmap-basic.c b/tools/perf/tests/mmap-basic.c
index 7f96bb72f7e5..16b8a4e5de8f 100644
--- a/tools/perf/tests/mmap-basic.c
+++ b/tools/perf/tests/mmap-basic.c
@@ -82,7 +82,7 @@ int test__basic_mmap(struct test *test __maybe_unused, int 
subtest __maybe_unuse
evsels[i]->attr.wakeup_events = 1;
perf_evsel__set_sample_id(evsels[i], false);
 
-   perf_evlist__add(evlist, evsels[i]);
+   evlist__add(evlist, evsels[i]);
 
if (perf_evsel__open(evsels[i], cpus, threads) < 0) {
pr_debug("failed to open counter: %s, "
diff --git a/tools/perf/tests/openat-syscall-tp-fields.c 
b/tools/perf/tests/openat-syscall-tp-fields.c
index 0263420f4495..f822c3c181f3 100644
--- a/tools/perf/tests/openat-syscall-tp-fields.c
+++ b/tools/perf/tests/openat-syscall-tp-fields.c
@@ -48,7 +48,7 @@ int test__syscall_openat_tp_fields(struct test *test 
__maybe_unused, int subtest
goto out_delete_evlist;
}
 
-   perf_evlist__add(evlist, evsel);
+   evlist__add(evlist, evsel);
 
err = perf_evlist__create_maps(evlist, );
if (err < 0) {
diff --git a/tools/perf/tests/sw-clock.c b/tools/perf/tests/sw-clock.c
index 247d3734686e..3ab11291174c 100644
--- a/tools/perf/tests/sw-clock.c
+++ b/tools/perf/tests/sw-clock.c
@@ -54,7 +54,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)
pr_debug("perf_evsel__new\n");
goto 

[tip:perf/core] perf evsel: Rename perf_evsel__new() to evsel__new()

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  365c3ae7452ca95e0a8f1e4716dd806550ade706
Gitweb: https://git.kernel.org/tip/365c3ae7452ca95e0a8f1e4716dd806550ade706
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:23:58 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:43 -0300

perf evsel: Rename perf_evsel__new() to evsel__new()

Rename perf_evsel__new() to evsel__new(), so we don't have a name clash
when we add perf_evsel__new() in libperf.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-12-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-trace.c | 2 +-
 tools/perf/tests/sw-clock.c| 2 +-
 tools/perf/util/evsel.c| 2 +-
 tools/perf/util/evsel.h| 2 +-
 tools/perf/util/header.c   | 4 ++--
 tools/perf/util/parse-events.c | 2 +-
 6 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index 0f7d1859a2d1..c5eb47f4e42e 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -2657,7 +2657,7 @@ static struct evsel *perf_evsel__new_pgfault(u64 config)
 
event_attr_init();
 
-   evsel = perf_evsel__new();
+   evsel = evsel__new();
if (evsel)
evsel->handler = trace__pgfault;
 
diff --git a/tools/perf/tests/sw-clock.c b/tools/perf/tests/sw-clock.c
index 1c7d8adb43d0..247d3734686e 100644
--- a/tools/perf/tests/sw-clock.c
+++ b/tools/perf/tests/sw-clock.c
@@ -49,7 +49,7 @@ static int __test__sw_clock_freq(enum perf_sw_ids clock_id)
return -1;
}
 
-   evsel = perf_evsel__new();
+   evsel = evsel__new();
if (evsel == NULL) {
pr_debug("perf_evsel__new\n");
goto out_delete_evlist;
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index de379b63f1ce..c9723c2d57c9 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -301,7 +301,7 @@ struct evsel *perf_evsel__new_cycles(bool precise)
 * to kick in when we return and before perf_evsel__open() is called.
 */
 new_event:
-   evsel = perf_evsel__new();
+   evsel = evsel__new();
if (evsel == NULL)
goto out;
 
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 20b4e31b63a9..ecea51a918e0 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -219,7 +219,7 @@ int perf_evsel__object_config(size_t object_size,
 
 struct evsel *perf_evsel__new_idx(struct perf_event_attr *attr, int idx);
 
-static inline struct evsel *perf_evsel__new(struct perf_event_attr *attr)
+static inline struct evsel *evsel__new(struct perf_event_attr *attr)
 {
return perf_evsel__new_idx(attr, 0);
 }
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index 29bbfd699226..7760ddc4bc18 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -3583,7 +3583,7 @@ int perf_session__read_header(struct perf_session 
*session)
}
 
tmp = lseek(fd, 0, SEEK_CUR);
-   evsel = perf_evsel__new(_attr.attr);
+   evsel = evsel__new(_attr.attr);
 
if (evsel == NULL)
goto out_delete_evlist;
@@ -4021,7 +4021,7 @@ int perf_event__process_attr(struct perf_tool *tool 
__maybe_unused,
return -ENOMEM;
}
 
-   evsel = perf_evsel__new(>attr.attr);
+   evsel = evsel__new(>attr.attr);
if (evsel == NULL)
return -ENOMEM;
 
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index cc63367f6e45..40087cf74dd1 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -2318,7 +2318,7 @@ static bool is_event_supported(u8 type, unsigned config)
if (tmap == NULL)
return false;
 
-   evsel = perf_evsel__new();
+   evsel = evsel__new();
if (evsel) {
open_return = perf_evsel__open(evsel, NULL, tmap);
ret = open_return >= 0;


[tip:perf/core] perf evsel: Rename perf_evsel__delete() to evsel__delete()

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  5eb2dd2ade8354dcbe4cef54cd1719622af8f2dc
Gitweb: https://git.kernel.org/tip/5eb2dd2ade8354dcbe4cef54cd1719622af8f2dc
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:23:57 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:43 -0300

perf evsel: Rename perf_evsel__delete() to evsel__delete()

Remame perf_evsel__delete() to evsel__delete(), so we don't have a name
clash when we add perf_evsel__delete() in libperf.

Also renaming perf_evsel__delete_priv() to evsel__delete_priv().

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-11-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-inject.c|  4 ++--
 tools/perf/builtin-trace.c | 12 ++--
 tools/perf/tests/evsel-tp-sched.c  |  4 ++--
 tools/perf/tests/openat-syscall-all-cpus.c |  2 +-
 tools/perf/tests/openat-syscall.c  |  2 +-
 tools/perf/util/evlist.c   |  4 ++--
 tools/perf/util/evsel.c|  4 ++--
 tools/perf/util/evsel.h|  2 +-
 tools/perf/util/parse-events.c |  4 ++--
 9 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/tools/perf/builtin-inject.c b/tools/perf/builtin-inject.c
index d2131fc863be..917c8fb4baa5 100644
--- a/tools/perf/builtin-inject.c
+++ b/tools/perf/builtin-inject.c
@@ -623,7 +623,7 @@ static void strip_fini(struct perf_inject *inject)
ok_to_remove(evlist, evsel)) {
pr_debug("Deleting %s\n", perf_evsel__name(evsel));
perf_evlist__remove(evlist, evsel);
-   perf_evsel__delete(evsel);
+   evsel__delete(evsel);
}
}
 }
@@ -725,7 +725,7 @@ static int __cmd_inject(struct perf_inject *inject)
pr_debug("Deleting %s\n",
 perf_evsel__name(evsel));
perf_evlist__remove(session->evlist, evsel);
-   perf_evsel__delete(evsel);
+   evsel__delete(evsel);
}
if (inject->strip)
strip_fini(inject);
diff --git a/tools/perf/builtin-trace.c b/tools/perf/builtin-trace.c
index e133204b3bb9..0f7d1859a2d1 100644
--- a/tools/perf/builtin-trace.c
+++ b/tools/perf/builtin-trace.c
@@ -274,10 +274,10 @@ static int perf_evsel__init_tp_ptr_field(struct evsel 
*evsel,
({ struct syscall_tp *sc = evsel->priv;\
   perf_evsel__init_tp_ptr_field(evsel, >name, #name); })
 
-static void perf_evsel__delete_priv(struct evsel *evsel)
+static void evsel__delete_priv(struct evsel *evsel)
 {
zfree(>priv);
-   perf_evsel__delete(evsel);
+   evsel__delete(evsel);
 }
 
 static int perf_evsel__init_syscall_tp(struct evsel *evsel)
@@ -368,7 +368,7 @@ static struct evsel *perf_evsel__raw_syscall_newtp(const 
char *direction, void *
return evsel;
 
 out_delete:
-   perf_evsel__delete_priv(evsel);
+   evsel__delete_priv(evsel);
return NULL;
 }
 
@@ -2638,7 +2638,7 @@ static bool perf_evlist__add_vfs_getname(struct evlist 
*evlist)
 
list_del_init(>node);
evsel->evlist = NULL;
-   perf_evsel__delete(evsel);
+   evsel__delete(evsel);
}
 
return found;
@@ -2739,9 +2739,9 @@ out:
return ret;
 
 out_delete_sys_exit:
-   perf_evsel__delete_priv(sys_exit);
+   evsel__delete_priv(sys_exit);
 out_delete_sys_enter:
-   perf_evsel__delete_priv(sys_enter);
+   evsel__delete_priv(sys_enter);
goto out;
 }
 
diff --git a/tools/perf/tests/evsel-tp-sched.c 
b/tools/perf/tests/evsel-tp-sched.c
index 0170e9d2e329..261e6eaaee99 100644
--- a/tools/perf/tests/evsel-tp-sched.c
+++ b/tools/perf/tests/evsel-tp-sched.c
@@ -64,7 +64,7 @@ int test__perf_evsel__tp_sched_test(struct test *test 
__maybe_unused, int subtes
if (perf_evsel__test_field(evsel, "next_prio", 4, true))
ret = -1;
 
-   perf_evsel__delete(evsel);
+   evsel__delete(evsel);
 
evsel = perf_evsel__newtp("sched", "sched_wakeup");
 
@@ -85,6 +85,6 @@ int test__perf_evsel__tp_sched_test(struct test *test 
__maybe_unused, int subtes
if (perf_evsel__test_field(evsel, "target_cpu", 4, true))
ret = -1;
 
-   perf_evsel__delete(evsel);
+   evsel__delete(evsel);
return ret;
 }
diff --git a/tools/perf/tests/openat-syscall-all-cpus.c 
b/tools/perf/tests/openat-syscall-all-cpus.c
index 4bf73896695a..001a0e8e6998 100644
--- a/tools/perf/tests/openat-syscall-all-cpus.c
+++ b/tools/perf/tests/openat-syscall-all-cpus.c
@@ -118,7 +118,7 @@ int test__openat_syscall_event_on_all_cpus(struct test 
*test 

[tip:perf/core] perf evlist: Rename perf_evlist__delete() to evlist__delete()

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  c12995a55474e1cefac52da38c7fc47c024de067
Gitweb: https://git.kernel.org/tip/c12995a55474e1cefac52da38c7fc47c024de067
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:23:56 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:43 -0300

perf evlist: Rename perf_evlist__delete() to evlist__delete()

Rename perf_evlist__delete() to evlist__delete(), so we don't have a
name clash when we add perf_evlist__delete() in libperf.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-10-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/arch/x86/tests/intel-cqm.c|  2 +-
 tools/perf/arch/x86/tests/perf-time-to-tsc.c |  2 +-
 tools/perf/builtin-ftrace.c  |  2 +-
 tools/perf/builtin-kvm.c |  4 ++--
 tools/perf/builtin-record.c  |  2 +-
 tools/perf/builtin-stat.c|  2 +-
 tools/perf/builtin-top.c |  2 +-
 tools/perf/builtin-trace.c   |  2 +-
 tools/perf/tests/backward-ring-buffer.c  |  2 +-
 tools/perf/tests/bpf.c   |  2 +-
 tools/perf/tests/code-reading.c  |  4 ++--
 tools/perf/tests/event-times.c   |  2 +-
 tools/perf/tests/evsel-roundtrip-name.c  |  4 ++--
 tools/perf/tests/hists_cumulate.c|  2 +-
 tools/perf/tests/hists_filter.c  |  2 +-
 tools/perf/tests/hists_link.c|  2 +-
 tools/perf/tests/hists_output.c  |  2 +-
 tools/perf/tests/keep-tracking.c |  2 +-
 tools/perf/tests/mmap-basic.c|  2 +-
 tools/perf/tests/openat-syscall-tp-fields.c  |  2 +-
 tools/perf/tests/parse-events.c  |  2 +-
 tools/perf/tests/parse-no-sample-id-all.c|  2 +-
 tools/perf/tests/perf-record.c   |  2 +-
 tools/perf/tests/sw-clock.c  |  2 +-
 tools/perf/tests/switch-tracking.c   |  2 +-
 tools/perf/tests/task-exit.c |  2 +-
 tools/perf/util/data-convert-bt.c|  2 +-
 tools/perf/util/evlist.c | 12 ++--
 tools/perf/util/evlist.h |  2 +-
 tools/perf/util/header.c |  4 ++--
 tools/perf/util/parse-events.c   |  2 +-
 tools/perf/util/record.c |  4 ++--
 32 files changed, 42 insertions(+), 42 deletions(-)

diff --git a/tools/perf/arch/x86/tests/intel-cqm.c 
b/tools/perf/arch/x86/tests/intel-cqm.c
index 8089a33c6c16..2a105e3b2ad1 100644
--- a/tools/perf/arch/x86/tests/intel-cqm.c
+++ b/tools/perf/arch/x86/tests/intel-cqm.c
@@ -124,6 +124,6 @@ int test__intel_cqm_count_nmi_context(struct test *test 
__maybe_unused, int subt
kill(pid, SIGKILL);
wait(NULL);
 out:
-   perf_evlist__delete(evlist);
+   evlist__delete(evlist);
return err;
 }
diff --git a/tools/perf/arch/x86/tests/perf-time-to-tsc.c 
b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
index da9a3302d8e6..09b6cef76f5b 100644
--- a/tools/perf/arch/x86/tests/perf-time-to-tsc.c
+++ b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
@@ -163,6 +163,6 @@ next_event:
err = 0;
 
 out_err:
-   perf_evlist__delete(evlist);
+   evlist__delete(evlist);
return err;
 }
diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index b8bdc593e5b8..105ef2a17a9c 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -508,7 +508,7 @@ int cmd_ftrace(int argc, const char **argv)
ret = __cmd_ftrace(, argc, argv);
 
 out_delete_evlist:
-   perf_evlist__delete(ftrace.evlist);
+   evlist__delete(ftrace.evlist);
 
 out_delete_filters:
delete_filter_func();
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index ee896b8a9fe8..8f54bdfb5743 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -1325,7 +1325,7 @@ static struct evlist *kvm_live_event_list(void)
 
 out:
if (err) {
-   perf_evlist__delete(evlist);
+   evlist__delete(evlist);
evlist = NULL;
}
 
@@ -1460,7 +1460,7 @@ static int kvm_events_live(struct perf_kvm_stat *kvm,
 out:
perf_session__delete(kvm->session);
kvm->session = NULL;
-   perf_evlist__delete(kvm->evlist);
+   evlist__delete(kvm->evlist);
 
return err;
 }
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index e8aa8a078dff..06966a2c2cdd 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -2449,7 +2449,7 @@ int cmd_record(int argc, const char **argv)
 
err = __cmd_record(, argc, argv);
 out:
-   perf_evlist__delete(rec->evlist);
+   evlist__delete(rec->evlist);
symbol__exit();
auxtrace_record__free(rec->itr);
return err;
diff --git a/tools/perf/builtin-stat.c 

[tip:perf/core] perf evlist: Rename perf_evlist__new() to evlist__new()

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  0f98b11c616f240b54ee85629ff4d3650c7ccc7d
Gitweb: https://git.kernel.org/tip/0f98b11c616f240b54ee85629ff4d3650c7ccc7d
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:23:55 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:43 -0300

perf evlist: Rename perf_evlist__new() to evlist__new()

Rename perf_evlist__new() to evlist__new(), so we don't have a name
clash when we add perf_evlist__new() in libperf.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-9-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/arch/powerpc/util/kvm-stat.c  | 2 +-
 tools/perf/arch/x86/tests/intel-cqm.c| 2 +-
 tools/perf/arch/x86/tests/perf-time-to-tsc.c | 2 +-
 tools/perf/builtin-ftrace.c  | 2 +-
 tools/perf/builtin-kvm.c | 2 +-
 tools/perf/builtin-record.c  | 2 +-
 tools/perf/builtin-stat.c| 2 +-
 tools/perf/builtin-top.c | 2 +-
 tools/perf/builtin-trace.c   | 2 +-
 tools/perf/tests/backward-ring-buffer.c  | 2 +-
 tools/perf/tests/bpf.c   | 2 +-
 tools/perf/tests/code-reading.c  | 2 +-
 tools/perf/tests/event-times.c   | 2 +-
 tools/perf/tests/evsel-roundtrip-name.c  | 4 ++--
 tools/perf/tests/hists_cumulate.c| 2 +-
 tools/perf/tests/hists_filter.c  | 2 +-
 tools/perf/tests/hists_link.c| 2 +-
 tools/perf/tests/hists_output.c  | 2 +-
 tools/perf/tests/keep-tracking.c | 2 +-
 tools/perf/tests/mmap-basic.c| 2 +-
 tools/perf/tests/openat-syscall-tp-fields.c  | 2 +-
 tools/perf/tests/parse-events.c  | 2 +-
 tools/perf/tests/sw-clock.c  | 4 ++--
 tools/perf/tests/switch-tracking.c   | 4 ++--
 tools/perf/util/evlist.c | 8 
 tools/perf/util/evlist.h | 2 +-
 tools/perf/util/header.c | 4 ++--
 tools/perf/util/record.c | 4 ++--
 28 files changed, 36 insertions(+), 36 deletions(-)

diff --git a/tools/perf/arch/powerpc/util/kvm-stat.c 
b/tools/perf/arch/powerpc/util/kvm-stat.c
index 28fc0bab370f..f0dbf7b075c8 100644
--- a/tools/perf/arch/powerpc/util/kvm-stat.c
+++ b/tools/perf/arch/powerpc/util/kvm-stat.c
@@ -146,7 +146,7 @@ static int ppc__setup_book3s_hv(struct perf_kvm_stat *kvm,
 /* Wrapper to setup kvm tracepoints */
 static int ppc__setup_kvm_tp(struct perf_kvm_stat *kvm)
 {
-   struct evlist *evlist = perf_evlist__new();
+   struct evlist *evlist = evlist__new();
 
if (evlist == NULL)
return -ENOMEM;
diff --git a/tools/perf/arch/x86/tests/intel-cqm.c 
b/tools/perf/arch/x86/tests/intel-cqm.c
index 333b2f0d61e4..8089a33c6c16 100644
--- a/tools/perf/arch/x86/tests/intel-cqm.c
+++ b/tools/perf/arch/x86/tests/intel-cqm.c
@@ -51,7 +51,7 @@ int test__intel_cqm_count_nmi_context(struct test *test 
__maybe_unused, int subt
 
flag = perf_event_open_cloexec_flag();
 
-   evlist = perf_evlist__new();
+   evlist = evlist__new();
if (!evlist) {
pr_debug("perf_evlist__new failed\n");
return TEST_FAIL;
diff --git a/tools/perf/arch/x86/tests/perf-time-to-tsc.c 
b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
index d7092fc00e3b..da9a3302d8e6 100644
--- a/tools/perf/arch/x86/tests/perf-time-to-tsc.c
+++ b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
@@ -68,7 +68,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, 
int subtest __maybe
cpus = cpu_map__new(NULL);
CHECK_NOT_NULL__(cpus);
 
-   evlist = perf_evlist__new();
+   evlist = evlist__new();
CHECK_NOT_NULL__(evlist);
 
perf_evlist__set_maps(evlist, cpus, threads);
diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index 1263987c291a..b8bdc593e5b8 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -495,7 +495,7 @@ int cmd_ftrace(int argc, const char **argv)
goto out_delete_filters;
}
 
-   ftrace.evlist = perf_evlist__new();
+   ftrace.evlist = evlist__new();
if (ftrace.evlist == NULL) {
ret = -ENOMEM;
goto out_delete_filters;
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 963dddc5853d..ee896b8a9fe8 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -1290,7 +1290,7 @@ static struct evlist *kvm_live_event_list(void)
int err = -1;
const char * const *events_tp;
 
-   evlist = perf_evlist__new();
+   evlist = evlist__new();
if (evlist == NULL)
return NULL;
 
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index f08d1e6a1651..e8aa8a078dff 100644

[tip:perf/core] perf evlist: Rename perf_evlist__init() to evlist__init()

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  52c86bca94b42239563b1510d5fc6329b0ec1a86
Gitweb: https://git.kernel.org/tip/52c86bca94b42239563b1510d5fc6329b0ec1a86
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:23:54 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:42 -0300

perf evlist: Rename perf_evlist__init() to evlist__init()

Rename perf_evlist__init() to evlist__init(), so we don't have a name
clash when we add perf_evlist__init() in libperf.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-8-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/evlist.c | 6 +++---
 tools/perf/util/evlist.h | 4 ++--
 tools/perf/util/python.c | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index c234fa4ba92a..4fcd55c8a8d5 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -41,8 +41,8 @@ int sigqueue(pid_t pid, int sig, const union sigval value);
 #define FD(e, x, y) (*(int *)xyarray__entry(e->fd, x, y))
 #define SID(e, x, y) xyarray__entry(e->sample_id, x, y)
 
-void perf_evlist__init(struct evlist *evlist, struct perf_cpu_map *cpus,
-  struct perf_thread_map *threads)
+void evlist__init(struct evlist *evlist, struct perf_cpu_map *cpus,
+ struct perf_thread_map *threads)
 {
int i;
 
@@ -60,7 +60,7 @@ struct evlist *perf_evlist__new(void)
struct evlist *evlist = zalloc(sizeof(*evlist));
 
if (evlist != NULL)
-   perf_evlist__init(evlist, NULL, NULL);
+   evlist__init(evlist, NULL, NULL);
 
return evlist;
 }
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 54f1c3e2b721..d6a3fa461566 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -68,8 +68,8 @@ struct evsel_str_handler {
 struct evlist *perf_evlist__new(void);
 struct evlist *perf_evlist__new_default(void);
 struct evlist *perf_evlist__new_dummy(void);
-void perf_evlist__init(struct evlist *evlist, struct perf_cpu_map *cpus,
-  struct perf_thread_map *threads);
+void evlist__init(struct evlist *evlist, struct perf_cpu_map *cpus,
+ struct perf_thread_map *threads);
 void perf_evlist__exit(struct evlist *evlist);
 void perf_evlist__delete(struct evlist *evlist);
 
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index f6fe3c90828f..ade4e85c6d81 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -873,7 +873,7 @@ static int pyrf_evlist__init(struct pyrf_evlist *pevlist,
 
threads = ((struct pyrf_thread_map *)pthreads)->threads;
cpus = ((struct pyrf_cpu_map *)pcpus)->cpus;
-   perf_evlist__init(>evlist, cpus, threads);
+   evlist__init(>evlist, cpus, threads);
return 0;
 }
 


[tip:perf/core] perf evsel: Rename perf_evsel__init() to evsel__init()

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  b4b62ee688eb39151c9d8182c3e2f12c9d34602d
Gitweb: https://git.kernel.org/tip/b4b62ee688eb39151c9d8182c3e2f12c9d34602d
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:23:53 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:42 -0300

perf evsel: Rename perf_evsel__init() to evsel__init()

Rename perf_evsel__init() to evsel__init(), so we don't have a name
clash when we add perf_evsel__init() in libperf.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-7-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/evsel.c  | 8 
 tools/perf/util/evsel.h  | 3 +--
 tools/perf/util/python.c | 2 +-
 3 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index f7f97ca6e96d..97bee83f0f98 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -223,8 +223,8 @@ bool perf_evsel__is_function_event(struct evsel *evsel)
 #undef FUNCTION_EVENT
 }
 
-void perf_evsel__init(struct evsel *evsel,
- struct perf_event_attr *attr, int idx)
+void evsel__init(struct evsel *evsel,
+struct perf_event_attr *attr, int idx)
 {
evsel->idx = idx;
evsel->tracking= !idx;
@@ -255,7 +255,7 @@ struct evsel *perf_evsel__new_idx(struct perf_event_attr 
*attr, int idx)
 
if (!evsel)
return NULL;
-   perf_evsel__init(evsel, attr, idx);
+   evsel__init(evsel, attr, idx);
 
if (perf_evsel__is_bpf_output(evsel)) {
evsel->attr.sample_type |= (PERF_SAMPLE_RAW | PERF_SAMPLE_TIME |
@@ -350,7 +350,7 @@ struct evsel *perf_evsel__newtp_idx(const char *sys, const 
char *name, int idx)
event_attr_init();
attr.config = evsel->tp_format->id;
attr.sample_period = 1;
-   perf_evsel__init(evsel, , idx);
+   evsel__init(evsel, , idx);
}
 
return evsel;
diff --git a/tools/perf/util/evsel.h b/tools/perf/util/evsel.h
index 3caabd8a4aa6..af230d92fbef 100644
--- a/tools/perf/util/evsel.h
+++ b/tools/perf/util/evsel.h
@@ -238,8 +238,7 @@ struct evsel *perf_evsel__new_cycles(bool precise);
 
 struct tep_event *event_format__new(const char *sys, const char *name);
 
-void perf_evsel__init(struct evsel *evsel,
- struct perf_event_attr *attr, int idx);
+void evsel__init(struct evsel *evsel, struct perf_event_attr *attr, int idx);
 void perf_evsel__exit(struct evsel *evsel);
 void perf_evsel__delete(struct evsel *evsel);
 
diff --git a/tools/perf/util/python.c b/tools/perf/util/python.c
index ed57b6b5ed91..f6fe3c90828f 100644
--- a/tools/perf/util/python.c
+++ b/tools/perf/util/python.c
@@ -782,7 +782,7 @@ static int pyrf_evsel__init(struct pyrf_evsel *pevsel,
attr.sample_id_all  = sample_id_all;
attr.size   = sizeof(attr);
 
-   perf_evsel__init(>evsel, , idx);
+   evsel__init(>evsel, , idx);
return 0;
 }
 


[tip:perf/core] perf tools: Rename struct thread_map to struct perf_thread_map

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  9749b90e566ca1a235fc8e2118f99c5690969342
Gitweb: https://git.kernel.org/tip/9749b90e566ca1a235fc8e2118f99c5690969342
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:23:50 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:42 -0300

perf tools: Rename struct thread_map to struct perf_thread_map

Rename struct thread_map to struct perf_thread_map, so it could be part
of libperf.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-4-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/arch/x86/tests/perf-time-to-tsc.c   |  2 +-
 tools/perf/builtin-record.c|  2 +-
 tools/perf/builtin-sched.c |  4 +-
 tools/perf/builtin-script.c|  2 +-
 tools/perf/builtin-stat.c  |  4 +-
 tools/perf/tests/code-reading.c|  2 +-
 tools/perf/tests/event-times.c |  4 +-
 tools/perf/tests/keep-tracking.c   |  2 +-
 tools/perf/tests/mmap-basic.c  |  2 +-
 tools/perf/tests/mmap-thread-lookup.c  |  2 +-
 tools/perf/tests/openat-syscall-all-cpus.c |  2 +-
 tools/perf/tests/openat-syscall.c  |  2 +-
 tools/perf/tests/sw-clock.c|  2 +-
 tools/perf/tests/switch-tracking.c |  2 +-
 tools/perf/tests/task-exit.c   |  2 +-
 tools/perf/tests/thread-map.c  |  8 +--
 tools/perf/util/event.c|  6 +--
 tools/perf/util/event.h|  6 +--
 tools/perf/util/evlist.c   | 10 ++--
 tools/perf/util/evlist.h   |  6 +--
 tools/perf/util/evsel.c| 10 ++--
 tools/perf/util/evsel.h|  6 +--
 tools/perf/util/machine.c  |  2 +-
 tools/perf/util/machine.h  |  4 +-
 tools/perf/util/parse-events.c |  2 +-
 tools/perf/util/python.c   |  6 +--
 .../util/scripting-engines/trace-event-python.c|  2 +-
 tools/perf/util/thread_map.c   | 60 +++---
 tools/perf/util/thread_map.h   | 40 +++
 29 files changed, 102 insertions(+), 102 deletions(-)

diff --git a/tools/perf/arch/x86/tests/perf-time-to-tsc.c 
b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
index 4676fd967dc6..f542b878bdb5 100644
--- a/tools/perf/arch/x86/tests/perf-time-to-tsc.c
+++ b/tools/perf/arch/x86/tests/perf-time-to-tsc.c
@@ -49,7 +49,7 @@ int test__perf_time_to_tsc(struct test *test __maybe_unused, 
int subtest __maybe
},
.sample_time = true,
};
-   struct thread_map *threads = NULL;
+   struct perf_thread_map *threads = NULL;
struct perf_cpu_map *cpus = NULL;
struct perf_evlist *evlist = NULL;
struct perf_evsel *evsel = NULL;
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 8779cee58185..bcfc16450608 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -1047,7 +1047,7 @@ record__finish_output(struct record *rec)
 static int record__synthesize_workload(struct record *rec, bool tail)
 {
int err;
-   struct thread_map *thread_map;
+   struct perf_thread_map *thread_map;
 
if (rec->opts.tail_synthesize != tail)
return 0;
diff --git a/tools/perf/builtin-sched.c b/tools/perf/builtin-sched.c
index 51dd48f20972..ac6a0c5d6d6b 100644
--- a/tools/perf/builtin-sched.c
+++ b/tools/perf/builtin-sched.c
@@ -159,7 +159,7 @@ struct perf_sched_map {
DECLARE_BITMAP(comp_cpus_mask, MAX_CPUS);
int *comp_cpus;
bool comp;
-   struct thread_map   *color_pids;
+   struct perf_thread_map *color_pids;
const char  *color_pids_str;
struct perf_cpu_map *color_cpus;
const char  *color_cpus_str;
@@ -3195,7 +3195,7 @@ static int setup_map_cpus(struct perf_sched *sched)
 
 static int setup_color_pids(struct perf_sched *sched)
 {
-   struct thread_map *map;
+   struct perf_thread_map *map;
 
if (!sched->map.color_pids_str)
return 0;
diff --git a/tools/perf/builtin-script.c b/tools/perf/builtin-script.c
index 0109c8710b93..fccc960df92b 100644
--- a/tools/perf/builtin-script.c
+++ b/tools/perf/builtin-script.c
@@ -1628,7 +1628,7 @@ struct perf_script {
boolallocated;
boolper_event_dump;
struct perf_cpu_map *cpus;
-   struct thread_map   *threads;
+   struct perf_thread_map *threads;
int name_width;
 

[tip:perf/core] perf cpu_map: Rename struct cpu_map to struct perf_cpu_map

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  f854839ba2a546a888159667c5ade96793e5cd10
Gitweb: https://git.kernel.org/tip/f854839ba2a546a888159667c5ade96793e5cd10
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:23:49 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:42 -0300

perf cpu_map: Rename struct cpu_map to struct perf_cpu_map

Rename struct cpu_map to struct perf_cpu_map, so it could be part of
libperf.

Committer notes:

Added fixes for arm64, provided by Jiri.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-3-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/arch/arm/util/cs-etm.c  | 16 ++---
 tools/perf/arch/arm64/util/header.c|  2 +-
 tools/perf/arch/x86/tests/perf-time-to-tsc.c   |  2 +-
 tools/perf/arch/x86/util/intel-bts.c   |  2 +-
 tools/perf/arch/x86/util/intel-pt.c|  2 +-
 tools/perf/bench/epoll-ctl.c   |  4 +-
 tools/perf/bench/epoll-wait.c  |  4 +-
 tools/perf/bench/futex-hash.c  |  2 +-
 tools/perf/bench/futex-lock-pi.c   |  4 +-
 tools/perf/bench/futex-requeue.c   |  4 +-
 tools/perf/bench/futex-wake-parallel.c |  4 +-
 tools/perf/bench/futex-wake.c  |  4 +-
 tools/perf/builtin-c2c.c   |  2 +-
 tools/perf/builtin-ftrace.c|  6 +-
 tools/perf/builtin-sched.c |  8 +--
 tools/perf/builtin-script.c|  2 +-
 tools/perf/builtin-stat.c  | 46 ++---
 tools/perf/tests/bitmap.c  |  2 +-
 tools/perf/tests/code-reading.c|  2 +-
 tools/perf/tests/cpumap.c  |  8 +--
 tools/perf/tests/event-times.c |  4 +-
 tools/perf/tests/event_update.c|  2 +-
 tools/perf/tests/keep-tracking.c   |  2 +-
 tools/perf/tests/mem2node.c|  2 +-
 tools/perf/tests/mmap-basic.c  |  2 +-
 tools/perf/tests/openat-syscall-all-cpus.c |  2 +-
 tools/perf/tests/sw-clock.c|  2 +-
 tools/perf/tests/switch-tracking.c |  2 +-
 tools/perf/tests/task-exit.c   |  2 +-
 tools/perf/tests/topology.c|  4 +-
 tools/perf/util/cpumap.c   | 78 +++---
 tools/perf/util/cpumap.h   | 52 +++
 tools/perf/util/cputopo.c  |  4 +-
 tools/perf/util/env.h  |  2 +-
 tools/perf/util/event.c| 18 ++---
 tools/perf/util/event.h|  8 +--
 tools/perf/util/evlist.c   | 10 +--
 tools/perf/util/evlist.h   |  8 +--
 tools/perf/util/evsel.c|  8 +--
 tools/perf/util/evsel.h| 12 ++--
 tools/perf/util/header.c   |  4 +-
 tools/perf/util/mmap.c |  2 +-
 tools/perf/util/parse-events.c |  2 +-
 tools/perf/util/pmu.c  | 10 +--
 tools/perf/util/pmu.h  |  2 +-
 tools/perf/util/python.c   |  6 +-
 tools/perf/util/record.c   |  6 +-
 .../util/scripting-engines/trace-event-python.c|  2 +-
 tools/perf/util/session.c  |  2 +-
 tools/perf/util/stat.c |  2 +-
 tools/perf/util/stat.h |  6 +-
 tools/perf/util/svghelper.c|  2 +-
 52 files changed, 198 insertions(+), 198 deletions(-)

diff --git a/tools/perf/arch/arm/util/cs-etm.c 
b/tools/perf/arch/arm/util/cs-etm.c
index 4208974c24f8..d08b55c27774 100644
--- a/tools/perf/arch/arm/util/cs-etm.c
+++ b/tools/perf/arch/arm/util/cs-etm.c
@@ -155,8 +155,8 @@ static int cs_etm_set_option(struct auxtrace_record *itr,
 struct perf_evsel *evsel, u32 option)
 {
int i, err = -EINVAL;
-   struct cpu_map *event_cpus = evsel->evlist->cpus;
-   struct cpu_map *online_cpus = cpu_map__new(NULL);
+   struct perf_cpu_map *event_cpus = evsel->evlist->cpus;
+   struct perf_cpu_map *online_cpus = cpu_map__new(NULL);
 
/* Set option of each CPU we have */
for (i = 0; i < cpu__max_cpu(); i++) {
@@ -253,7 +253,7 @@ static int cs_etm_recording_options(struct auxtrace_record 
*itr,
container_of(itr, struct cs_etm_recording, itr);
struct perf_pmu *cs_etm_pmu = ptr->cs_etm_pmu;
struct perf_evsel *evsel, *cs_etm_evsel = NULL;
-   struct cpu_map 

[tip:perf/core] perf stat: Move loaded out of struct perf_counts_values

2019-07-30 Thread tip-bot for Jiri Olsa
Commit-ID:  df1d6856eaa7ec9ad1e670685b370f3e66326079
Gitweb: https://git.kernel.org/tip/df1d6856eaa7ec9ad1e670685b370f3e66326079
Author: Jiri Olsa 
AuthorDate: Sun, 21 Jul 2019 13:23:48 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 29 Jul 2019 18:34:42 -0300

perf stat: Move loaded out of struct perf_counts_values

Because we will make struct perf_counts_values public in following
patches and 'loaded' is implementation related.

No functional change is expected.

Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Alexey Budankov 
Cc: Andi Kleen 
Cc: Michael Petlan 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Link: http://lkml.kernel.org/r/20190721112506.12306-2-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-stat.c |  4 ++--
 tools/perf/util/counts.c  | 11 +++
 tools/perf/util/counts.h  | 14 +-
 tools/perf/util/evsel.c   |  3 ++-
 4 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 352cf39d7c2f..7b9c26f9cf34 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -287,7 +287,7 @@ static int read_counter(struct perf_evsel *counter, struct 
timespec *rs)
 * The leader's group read loads data into its group 
members
 * (via perf_evsel__read_counter) and sets threir 
count->loaded.
 */
-   if (!count->loaded &&
+   if (!perf_counts__is_loaded(counter->counts, cpu, 
thread) &&
read_single_counter(counter, cpu, thread, rs)) {
counter->counts->scaled = -1;
perf_counts(counter->counts, cpu, thread)->ena 
= 0;
@@ -295,7 +295,7 @@ static int read_counter(struct perf_evsel *counter, struct 
timespec *rs)
return -1;
}
 
-   count->loaded = false;
+   perf_counts__set_loaded(counter->counts, cpu, thread, 
false);
 
if (STAT_RECORD) {
if (perf_evsel__write_stat_event(counter, cpu, 
thread, count)) {
diff --git a/tools/perf/util/counts.c b/tools/perf/util/counts.c
index 88be9c4365e0..01ee81df3fe5 100644
--- a/tools/perf/util/counts.c
+++ b/tools/perf/util/counts.c
@@ -19,6 +19,15 @@ struct perf_counts *perf_counts__new(int ncpus, int nthreads)
}
 
counts->values = values;
+
+   values = xyarray__new(ncpus, nthreads, sizeof(bool));
+   if (!values) {
+   xyarray__delete(counts->values);
+   free(counts);
+   return NULL;
+   }
+
+   counts->loaded = values;
}
 
return counts;
@@ -27,6 +36,7 @@ struct perf_counts *perf_counts__new(int ncpus, int nthreads)
 void perf_counts__delete(struct perf_counts *counts)
 {
if (counts) {
+   xyarray__delete(counts->loaded);
xyarray__delete(counts->values);
free(counts);
}
@@ -34,6 +44,7 @@ void perf_counts__delete(struct perf_counts *counts)
 
 static void perf_counts__reset(struct perf_counts *counts)
 {
+   xyarray__reset(counts->loaded);
xyarray__reset(counts->values);
 }
 
diff --git a/tools/perf/util/counts.h b/tools/perf/util/counts.h
index 0d1050ccc586..460b56ce3252 100644
--- a/tools/perf/util/counts.h
+++ b/tools/perf/util/counts.h
@@ -13,13 +13,13 @@ struct perf_counts_values {
};
u64 values[3];
};
-   boolloaded;
 };
 
 struct perf_counts {
s8scaled;
struct perf_counts_values aggr;
struct xyarray*values;
+   struct xyarray*loaded;
 };
 
 
@@ -29,6 +29,18 @@ perf_counts(struct perf_counts *counts, int cpu, int thread)
return xyarray__entry(counts->values, cpu, thread);
 }
 
+static inline bool
+perf_counts__is_loaded(struct perf_counts *counts, int cpu, int thread)
+{
+   return *((bool *) xyarray__entry(counts->loaded, cpu, thread));
+}
+
+static inline void
+perf_counts__set_loaded(struct perf_counts *counts, int cpu, int thread, bool 
loaded)
+{
+   *((bool *) xyarray__entry(counts->loaded, cpu, thread)) = loaded;
+}
+
 struct perf_counts *perf_counts__new(int ncpus, int nthreads);
 void perf_counts__delete(struct perf_counts *counts);
 
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 7d1757a2ec46..d23b9574f793 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1439,7 +1439,8 @@ perf_evsel__set_count(struct perf_evsel *counter, int 
cpu, int thread,
count->val= val;
count->ena= ena;
count->run= run;
-   count->loaded = true;
+
+   perf_counts__set_loaded(counter->counts, cpu, thread, true);
 }
 
 static int


[tip:perf/urgent] perf stat: Fix segfault for event group in repeat mode

2019-07-23 Thread tip-bot for Jiri Olsa
Commit-ID:  08ef3af1579d0446db1c1bd08e2c42565addf10f
Gitweb: https://git.kernel.org/tip/08ef3af1579d0446db1c1bd08e2c42565addf10f
Author: Jiri Olsa 
AuthorDate: Mon, 15 Jul 2019 16:21:21 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Tue, 23 Jul 2019 09:00:05 -0300

perf stat: Fix segfault for event group in repeat mode

Numfor Mbiziwo-Tiapo reported segfault on stat of event group in repeat
mode:

  # perf stat -e '{cycles,instructions}' -r 10 ls

It's caused by memory corruption due to not cleaned evsel's id array and
index, which needs to be rebuilt in every stat iteration. Currently the
ids index grows, while the array (which is also not freed) has the same
size.

Fixing this by releasing id array and zeroing ids index in
perf_evsel__close function.

We also need to keep the evsel_list alive for stat record (which is
disabled in repeat mode).

Reported-by: Numfor Mbiziwo-Tiapo 
Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Ian Rogers 
Cc: Mark Drayton 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Song Liu 
Cc: Stephane Eranian 
Link: http://lkml.kernel.org/r/20190715142121.GC6032@krava
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/builtin-stat.c | 9 -
 tools/perf/util/evsel.c   | 2 ++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index b55a534b4de0..352cf39d7c2f 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -607,7 +607,13 @@ try_again:
 * group leaders.
 */
read_counters(&(struct timespec) { .tv_nsec = t1-t0 });
-   perf_evlist__close(evsel_list);
+
+   /*
+* We need to keep evsel_list alive, because it's processed
+* later the evsel_list will be closed after.
+*/
+   if (!STAT_RECORD)
+   perf_evlist__close(evsel_list);
 
return WEXITSTATUS(status);
 }
@@ -1997,6 +2003,7 @@ int cmd_stat(int argc, const char **argv)
perf_session__write_header(perf_stat.session, 
evsel_list, fd, true);
}
 
+   perf_evlist__close(evsel_list);
perf_session__delete(perf_stat.session);
}
 
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index ebb46da4dfe5..52459dd5ad0c 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1291,6 +1291,7 @@ static void perf_evsel__free_id(struct perf_evsel *evsel)
xyarray__delete(evsel->sample_id);
evsel->sample_id = NULL;
zfree(>id);
+   evsel->ids = 0;
 }
 
 static void perf_evsel__free_config_terms(struct perf_evsel *evsel)
@@ -2077,6 +2078,7 @@ void perf_evsel__close(struct perf_evsel *evsel)
 
perf_evsel__close_fd(evsel);
perf_evsel__free_fd(evsel);
+   perf_evsel__free_id(evsel);
 }
 
 int perf_evsel__open_per_cpu(struct perf_evsel *evsel,


[tip:perf/urgent] perf tools: Fix proper buffer size for feature processing

2019-07-23 Thread tip-bot for Jiri Olsa
Commit-ID:  79b2fe5e756163897175a8f57d66b26cd9befd59
Gitweb: https://git.kernel.org/tip/79b2fe5e756163897175a8f57d66b26cd9befd59
Author: Jiri Olsa 
AuthorDate: Mon, 15 Jul 2019 16:04:26 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Tue, 23 Jul 2019 08:59:49 -0300

perf tools: Fix proper buffer size for feature processing

After Song Liu's segfault fix for pipe mode, Arnaldo reported following
error:

  # perf record -o - | perf script
  0x514 [0x1ac]: failed to process type: 80

It's caused by wrong buffer size setup in feature processing, which
makes cpu topology feature fail, because it's using buffer size to
recognize its header version.

Reported-by: Arnaldo Carvalho de Melo 
Signed-off-by: Jiri Olsa 
Tested-by: Arnaldo Carvalho de Melo 
Cc: Alexander Shishkin 
Cc: David Carrillo-Cisneros 
Cc: Kan Liang 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Song Liu 
Fixes: e9def1b2e74e ("perf tools: Add feature header record to pipe-mode")
Link: http://lkml.kernel.org/r/20190715140426.32509-1-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/header.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index c24db7f4909c..20111f8da5cb 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -3747,7 +3747,7 @@ int perf_event__process_feature(struct perf_session 
*session,
return 0;
 
ff.buf  = (void *)fe->data;
-   ff.size = event->header.size - sizeof(event->header);
+   ff.size = event->header.size - sizeof(*fe);
ff.ph = >header;
 
if (feat_ops[feat].process(, NULL))


[tip:perf/core] perf jvmti: Address gcc string overflow warning for strncpy()

2019-07-09 Thread tip-bot for Jiri Olsa
Commit-ID:  dab0f4ebb22ee6d16051011d624cff79a99baa8a
Gitweb: https://git.kernel.org/tip/dab0f4ebb22ee6d16051011d624cff79a99baa8a
Author: Jiri Olsa 
AuthorDate: Fri, 31 May 2019 15:13:21 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Sun, 7 Jul 2019 12:33:32 -0300

perf jvmti: Address gcc string overflow warning for strncpy()

We are getting false positive gcc warning when we compile with gcc9 (9.1.1):

 CC   jvmti/libjvmti.o
   In file included from /usr/include/string.h:494,
from jvmti/libjvmti.c:5:
   In function ‘strncpy’,
   inlined from ‘copy_class_filename.constprop’ at jvmti/libjvmti.c:166:3:
   /usr/include/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ 
specified bound depends on the length of the source argument 
[-Werror=stringop-overflow=]
 106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos 
(__dest));
 |  
^~
   jvmti/libjvmti.c: In function ‘copy_class_filename.constprop’:
   jvmti/libjvmti.c:165:26: note: length computed here
 165 |   size_t file_name_len = strlen(file_name);
 |  ^
   cc1: all warnings being treated as errors

As per Arnaldo's suggestion use strlcpy(), which does the same thing and keeps
gcc silent.

Suggested-by: Arnaldo Carvalho de Melo 
Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Ben Gainey 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Stephane Eranian 
Link: http://lkml.kernel.org/r/20190531131321.GB1281@krava
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/jvmti/libjvmti.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/jvmti/libjvmti.c b/tools/perf/jvmti/libjvmti.c
index aea7b1fe85aa..c441a34cb1c0 100644
--- a/tools/perf/jvmti/libjvmti.c
+++ b/tools/perf/jvmti/libjvmti.c
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -162,8 +163,7 @@ copy_class_filename(const char * class_sign, const char * 
file_name, char * resu
result[i] = '\0';
} else {
/* fallback case */
-   size_t file_name_len = strlen(file_name);
-   strncpy(result, file_name, file_name_len < max_length ? 
file_name_len : max_length);
+   strlcpy(result, file_name, max_length);
}
 }
 


[tip:perf/core] perf evsel: Do not rely on errno values for precise_ip fallback

2019-07-09 Thread tip-bot for Jiri Olsa
Commit-ID:  cd136189370cc8a5aec0ea4b4ec517e5ee38d8a0
Gitweb: https://git.kernel.org/tip/cd136189370cc8a5aec0ea4b4ec517e5ee38d8a0
Author: Jiri Olsa 
AuthorDate: Wed, 3 Jul 2019 10:09:49 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Sat, 6 Jul 2019 14:30:30 -0300

perf evsel: Do not rely on errno values for precise_ip fallback

Konstantin reported problem with default perf record command, which
fails on some AMD servers, because of the default maximum precise
config.

The current fallback mechanism counts on getting ENOTSUP errno for
precise_ip fails, but that's not the case on some AMD servers.

We can fix this by removing the errno check completely, because the
precise_ip fallback is separated. We can just try  (if requested by
evsel->precise_max) all possible precise_ip, and if one succeeds we win,
if not, we continue with standard fallback.

Reported-by: Konstantin Kharlamov 
Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Andi Kleen 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Quentin Monnet 
Cc: Kim Phillips 
Link: http://lkml.kernel.org/r/20190703080949.10356-1-jo...@kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/evsel.c | 10 ++
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 4a5947625c5c..69beb9f80f07 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1785,14 +1785,8 @@ static int perf_event_open(struct perf_evsel *evsel,
if (fd >= 0)
break;
 
-   /*
-* Do quick precise_ip fallback if:
-*  - there is precise_ip set in perf_event_attr
-*  - maximum precise is requested
-*  - sys_perf_event_open failed with ENOTSUP error,
-*which is associated with wrong precise_ip
-*/
-   if (!precise_ip || !evsel->precise_max || (errno != ENOTSUP))
+   /* Do not try less precise if not requested. */
+   if (!evsel->precise_max)
break;
 
/*


[tip:perf/core] objtool: Fix build by linking against tools/lib/ctype.o sources

2019-07-03 Thread tip-bot for Jiri Olsa
Commit-ID:  0c69b93112428d43b8c103d032143ea89b895d43
Gitweb: https://git.kernel.org/tip/0c69b93112428d43b8c103d032143ea89b895d43
Author: Jiri Olsa 
AuthorDate: Tue, 2 Jul 2019 14:12:40 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Tue, 2 Jul 2019 10:49:31 -0300

objtool: Fix build by linking against tools/lib/ctype.o sources

Fix objtool build, because it adds _ctype dependency via isspace call patch.

Signed-off-by: Jiri Olsa 
Cc: Adrian Hunter 
Cc: André Goddard Rosa 
Cc: Clark Williams 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Cc: Thomas Gleixner 
Fixes: 7bd330de43fd ("tools lib: Adopt skip_spaces() from the kernel sources")
Link: http://lkml.kernel.org/r/20190702121240.GB12694@krava
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/objtool/Build | 5 +
 1 file changed, 5 insertions(+)

diff --git a/tools/objtool/Build b/tools/objtool/Build
index 749becdf5b90..8dc4f0848362 100644
--- a/tools/objtool/Build
+++ b/tools/objtool/Build
@@ -9,6 +9,7 @@ objtool-y += special.o
 objtool-y += objtool.o
 
 objtool-y += libstring.o
+objtool-y += libctype.o
 objtool-y += str_error_r.o
 
 CFLAGS += -I$(srctree)/tools/lib
@@ -17,6 +18,10 @@ $(OUTPUT)libstring.o: ../lib/string.c FORCE
$(call rule_mkdir)
$(call if_changed_dep,cc_o_c)
 
+$(OUTPUT)libctype.o: ../lib/ctype.c FORCE
+   $(call rule_mkdir)
+   $(call if_changed_dep,cc_o_c)
+
 $(OUTPUT)str_error_r.o: ../lib/str_error_r.c FORCE
$(call rule_mkdir)
$(call if_changed_dep,cc_o_c)


[tip:perf/core] perf/x86/rapl: Get attributes from new probe framework

2019-06-25 Thread tip-bot for Jiri Olsa
Commit-ID:  5fc1bd84664a5152dcbdba0962c40a6a07fbd78b
Gitweb: https://git.kernel.org/tip/5fc1bd84664a5152dcbdba0962c40a6a07fbd78b
Author: Jiri Olsa 
AuthorDate: Sun, 16 Jun 2019 16:03:57 +0200
Committer:  Ingo Molnar 
CommitDate: Mon, 24 Jun 2019 19:28:35 +0200

perf/x86/rapl: Get attributes from new probe framework

We no longer need model specific attribute arrays,
because we get all this detected in rapl_events_attrs.

Signed-off-by: Jiri Olsa 
Signed-off-by: Peter Zijlstra (Intel) 
Cc: Alexander Shishkin 
Cc: Andy Lutomirski 
Cc: Arnaldo Carvalho de Melo 
Cc: Arnaldo Carvalho de Melo 
Cc: Borislav Petkov 
Cc: Greg Kroah-Hartman 
Cc: Jiri Olsa 
Cc: Kan 
Cc: Liang
Cc: Linus Torvalds 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Stephane Eranian 
Cc: Thomas Gleixner 
Cc: Vince Weaver 
Link: https://lkml.kernel.org/r/20190616140358.27799-8-jo...@kernel.org
Signed-off-by: Ingo Molnar 
---
 arch/x86/events/intel/rapl.c | 89 
 1 file changed, 89 deletions(-)

diff --git a/arch/x86/events/intel/rapl.c b/arch/x86/events/intel/rapl.c
index 00b2b5d82d58..460196c02bae 100644
--- a/arch/x86/events/intel/rapl.c
+++ b/arch/x86/events/intel/rapl.c
@@ -416,87 +416,6 @@ RAPL_EVENT_ATTR_STR(energy-ram.scale, rapl_ram_scale, 
"2.3283064365386962890
 RAPL_EVENT_ATTR_STR(energy-gpu.scale, rapl_gpu_scale, 
"2.3283064365386962890625e-10");
 RAPL_EVENT_ATTR_STR(energy-psys.scale,   rapl_psys_scale, 
"2.3283064365386962890625e-10");
 
-static struct attribute *rapl_events_srv_attr[] = {
-   EVENT_PTR(rapl_cores),
-   EVENT_PTR(rapl_pkg),
-   EVENT_PTR(rapl_ram),
-
-   EVENT_PTR(rapl_cores_unit),
-   EVENT_PTR(rapl_pkg_unit),
-   EVENT_PTR(rapl_ram_unit),
-
-   EVENT_PTR(rapl_cores_scale),
-   EVENT_PTR(rapl_pkg_scale),
-   EVENT_PTR(rapl_ram_scale),
-   NULL,
-};
-
-static struct attribute *rapl_events_cln_attr[] = {
-   EVENT_PTR(rapl_cores),
-   EVENT_PTR(rapl_pkg),
-   EVENT_PTR(rapl_gpu),
-
-   EVENT_PTR(rapl_cores_unit),
-   EVENT_PTR(rapl_pkg_unit),
-   EVENT_PTR(rapl_gpu_unit),
-
-   EVENT_PTR(rapl_cores_scale),
-   EVENT_PTR(rapl_pkg_scale),
-   EVENT_PTR(rapl_gpu_scale),
-   NULL,
-};
-
-static struct attribute *rapl_events_hsw_attr[] = {
-   EVENT_PTR(rapl_cores),
-   EVENT_PTR(rapl_pkg),
-   EVENT_PTR(rapl_gpu),
-   EVENT_PTR(rapl_ram),
-
-   EVENT_PTR(rapl_cores_unit),
-   EVENT_PTR(rapl_pkg_unit),
-   EVENT_PTR(rapl_gpu_unit),
-   EVENT_PTR(rapl_ram_unit),
-
-   EVENT_PTR(rapl_cores_scale),
-   EVENT_PTR(rapl_pkg_scale),
-   EVENT_PTR(rapl_gpu_scale),
-   EVENT_PTR(rapl_ram_scale),
-   NULL,
-};
-
-static struct attribute *rapl_events_skl_attr[] = {
-   EVENT_PTR(rapl_cores),
-   EVENT_PTR(rapl_pkg),
-   EVENT_PTR(rapl_gpu),
-   EVENT_PTR(rapl_ram),
-   EVENT_PTR(rapl_psys),
-
-   EVENT_PTR(rapl_cores_unit),
-   EVENT_PTR(rapl_pkg_unit),
-   EVENT_PTR(rapl_gpu_unit),
-   EVENT_PTR(rapl_ram_unit),
-   EVENT_PTR(rapl_psys_unit),
-
-   EVENT_PTR(rapl_cores_scale),
-   EVENT_PTR(rapl_pkg_scale),
-   EVENT_PTR(rapl_gpu_scale),
-   EVENT_PTR(rapl_ram_scale),
-   EVENT_PTR(rapl_psys_scale),
-   NULL,
-};
-
-static struct attribute *rapl_events_knl_attr[] = {
-   EVENT_PTR(rapl_pkg),
-   EVENT_PTR(rapl_ram),
-
-   EVENT_PTR(rapl_pkg_unit),
-   EVENT_PTR(rapl_ram_unit),
-
-   EVENT_PTR(rapl_pkg_scale),
-   EVENT_PTR(rapl_ram_scale),
-   NULL,
-};
-
 /*
  * There are no default events, but we need to create
  * "events" group (with empty attrs) before updating
@@ -754,37 +673,30 @@ static int __init init_rapl_pmus(void)
 
 struct intel_rapl_init_fun {
bool apply_quirk;
-   struct attribute **attrs;
 };
 
 static const struct intel_rapl_init_fun snb_rapl_init __initconst = {
.apply_quirk = false,
-   .attrs = rapl_events_cln_attr,
 };
 
 static const struct intel_rapl_init_fun hsx_rapl_init __initconst = {
.apply_quirk = true,
-   .attrs = rapl_events_srv_attr,
 };
 
 static const struct intel_rapl_init_fun hsw_rapl_init __initconst = {
.apply_quirk = false,
-   .attrs = rapl_events_hsw_attr,
 };
 
 static const struct intel_rapl_init_fun snbep_rapl_init __initconst = {
.apply_quirk = false,
-   .attrs = rapl_events_srv_attr,
 };
 
 static const struct intel_rapl_init_fun knl_rapl_init __initconst = {
.apply_quirk = true,
-   .attrs = rapl_events_knl_attr,
 };
 
 static const struct intel_rapl_init_fun skl_rapl_init __initconst = {
.apply_quirk = false,
-   .attrs = rapl_events_skl_attr,
 };
 
 static const struct x86_cpu_id rapl_cpu_match[] __initconst = {
@@ -923,7 +835,6 @@ static int __init rapl_pmu_init(void)
 
rapl_init = (struct intel_rapl_init_fun *)id->driver_data;
apply_quirk = rapl_init->apply_quirk;
-   rapl_pmu_events_group.attrs = 

[tip:perf/core] perf/x86/rapl: Get quirk state from new probe framework

2019-06-25 Thread tip-bot for Jiri Olsa
Commit-ID:  637d97b53cdded02da55d0a25cda6fd6af3bd042
Gitweb: https://git.kernel.org/tip/637d97b53cdded02da55d0a25cda6fd6af3bd042
Author: Jiri Olsa 
AuthorDate: Sun, 16 Jun 2019 16:03:58 +0200
Committer:  Ingo Molnar 
CommitDate: Mon, 24 Jun 2019 19:28:36 +0200

perf/x86/rapl: Get quirk state from new probe framework

Getting the apply_quirk bool from new rapl_model_match array.

And because apply_quirk was the last remaining piece of data
in rapl_cpu_match, replacing it with rapl_model_match as device
table.

The switch to new perf_msr_probe detection API is done.

Signed-off-by: Jiri Olsa 
Signed-off-by: Peter Zijlstra (Intel) 
Cc: Alexander Shishkin 
Cc: Andy Lutomirski 
Cc: Arnaldo Carvalho de Melo 
Cc: Arnaldo Carvalho de Melo 
Cc: Borislav Petkov 
Cc: Greg Kroah-Hartman 
Cc: Jiri Olsa 
Cc: Kan 
Cc: Liang
Cc: Linus Torvalds 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Stephane Eranian 
Cc: Thomas Gleixner 
Cc: Vince Weaver 
Link: https://lkml.kernel.org/r/20190616140358.27799-9-jo...@kernel.org
Signed-off-by: Ingo Molnar 
---
 arch/x86/events/intel/rapl.c | 82 ++--
 1 file changed, 3 insertions(+), 79 deletions(-)

diff --git a/arch/x86/events/intel/rapl.c b/arch/x86/events/intel/rapl.c
index 460196c02bae..64ab51ffdf06 100644
--- a/arch/x86/events/intel/rapl.c
+++ b/arch/x86/events/intel/rapl.c
@@ -671,75 +671,6 @@ static int __init init_rapl_pmus(void)
 #define X86_RAPL_MODEL_MATCH(model, init)  \
{ X86_VENDOR_INTEL, 6, model, X86_FEATURE_ANY, (unsigned long) }
 
-struct intel_rapl_init_fun {
-   bool apply_quirk;
-};
-
-static const struct intel_rapl_init_fun snb_rapl_init __initconst = {
-   .apply_quirk = false,
-};
-
-static const struct intel_rapl_init_fun hsx_rapl_init __initconst = {
-   .apply_quirk = true,
-};
-
-static const struct intel_rapl_init_fun hsw_rapl_init __initconst = {
-   .apply_quirk = false,
-};
-
-static const struct intel_rapl_init_fun snbep_rapl_init __initconst = {
-   .apply_quirk = false,
-};
-
-static const struct intel_rapl_init_fun knl_rapl_init __initconst = {
-   .apply_quirk = true,
-};
-
-static const struct intel_rapl_init_fun skl_rapl_init __initconst = {
-   .apply_quirk = false,
-};
-
-static const struct x86_cpu_id rapl_cpu_match[] __initconst = {
-   X86_RAPL_MODEL_MATCH(INTEL_FAM6_SANDYBRIDGE,   snb_rapl_init),
-   X86_RAPL_MODEL_MATCH(INTEL_FAM6_SANDYBRIDGE_X, snbep_rapl_init),
-
-   X86_RAPL_MODEL_MATCH(INTEL_FAM6_IVYBRIDGE,   snb_rapl_init),
-   X86_RAPL_MODEL_MATCH(INTEL_FAM6_IVYBRIDGE_X, snbep_rapl_init),
-
-   X86_RAPL_MODEL_MATCH(INTEL_FAM6_HASWELL_CORE, hsw_rapl_init),
-   X86_RAPL_MODEL_MATCH(INTEL_FAM6_HASWELL_X,hsx_rapl_init),
-   X86_RAPL_MODEL_MATCH(INTEL_FAM6_HASWELL_ULT,  hsw_rapl_init),
-   X86_RAPL_MODEL_MATCH(INTEL_FAM6_HASWELL_GT3E, hsw_rapl_init),
-
-   X86_RAPL_MODEL_MATCH(INTEL_FAM6_BROADWELL_CORE,   hsw_rapl_init),
-   X86_RAPL_MODEL_MATCH(INTEL_FAM6_BROADWELL_GT3E,   hsw_rapl_init),
-   X86_RAPL_MODEL_MATCH(INTEL_FAM6_BROADWELL_X,  hsx_rapl_init),
-   X86_RAPL_MODEL_MATCH(INTEL_FAM6_BROADWELL_XEON_D, hsx_rapl_init),
-
-   X86_RAPL_MODEL_MATCH(INTEL_FAM6_XEON_PHI_KNL, knl_rapl_init),
-   X86_RAPL_MODEL_MATCH(INTEL_FAM6_XEON_PHI_KNM, knl_rapl_init),
-
-   X86_RAPL_MODEL_MATCH(INTEL_FAM6_SKYLAKE_MOBILE,  skl_rapl_init),
-   X86_RAPL_MODEL_MATCH(INTEL_FAM6_SKYLAKE_DESKTOP, skl_rapl_init),
-   X86_RAPL_MODEL_MATCH(INTEL_FAM6_SKYLAKE_X,   hsx_rapl_init),
-
-   X86_RAPL_MODEL_MATCH(INTEL_FAM6_KABYLAKE_MOBILE,  skl_rapl_init),
-   X86_RAPL_MODEL_MATCH(INTEL_FAM6_KABYLAKE_DESKTOP, skl_rapl_init),
-
-   X86_RAPL_MODEL_MATCH(INTEL_FAM6_CANNONLAKE_MOBILE,  skl_rapl_init),
-
-   X86_RAPL_MODEL_MATCH(INTEL_FAM6_ATOM_GOLDMONT, hsw_rapl_init),
-   X86_RAPL_MODEL_MATCH(INTEL_FAM6_ATOM_GOLDMONT_X, hsw_rapl_init),
-
-   X86_RAPL_MODEL_MATCH(INTEL_FAM6_ATOM_GOLDMONT_PLUS, hsw_rapl_init),
-
-   X86_RAPL_MODEL_MATCH(INTEL_FAM6_ICELAKE_MOBILE,  skl_rapl_init),
-   X86_RAPL_MODEL_MATCH(INTEL_FAM6_ICELAKE_DESKTOP, skl_rapl_init),
-   {},
-};
-
-MODULE_DEVICE_TABLE(x86cpu, rapl_cpu_match);
-
 static struct rapl_model model_snb = {
.events = BIT(PERF_RAPL_PP0) |
  BIT(PERF_RAPL_PKG) |
@@ -813,12 +744,12 @@ static const struct x86_cpu_id rapl_model_match[] 
__initconst = {
{},
 };
 
+MODULE_DEVICE_TABLE(x86cpu, rapl_model_match);
+
 static int __init rapl_pmu_init(void)
 {
const struct x86_cpu_id *id;
-   struct intel_rapl_init_fun *rapl_init;
struct rapl_model *rm;
-   bool apply_quirk;
int ret;
 
id = x86_match_cpu(rapl_model_match);
@@ -829,14 +760,7 @@ static int __init rapl_pmu_init(void)
rapl_cntr_mask = perf_msr_probe(rapl_msrs, PERF_RAPL_MAX,
false, (void *) >events);
 
-   id = x86_match_cpu(rapl_cpu_match);
-   

[tip:perf/core] perf/x86/rapl: Get MSR values from new probe framework

2019-06-25 Thread tip-bot for Jiri Olsa
Commit-ID:  122f1c51b11a9e572263c4965d772381fcef06c5
Gitweb: https://git.kernel.org/tip/122f1c51b11a9e572263c4965d772381fcef06c5
Author: Jiri Olsa 
AuthorDate: Sun, 16 Jun 2019 16:03:56 +0200
Committer:  Ingo Molnar 
CommitDate: Mon, 24 Jun 2019 19:28:34 +0200

perf/x86/rapl: Get MSR values from new probe framework

There's no need to have special code for getting
the bit and MSR value for given event. We can
now easily get it from rapl_msrs array.

Also getting rid of RAPL_IDX_*, which is no longer
needed and replacing INTEL_RAPL* with PERF_RAPL*
enums.

Signed-off-by: Jiri Olsa 
Signed-off-by: Peter Zijlstra (Intel) 
Cc: Alexander Shishkin 
Cc: Andy Lutomirski 
Cc: Arnaldo Carvalho de Melo 
Cc: Arnaldo Carvalho de Melo 
Cc: Borislav Petkov 
Cc: Greg Kroah-Hartman 
Cc: Jiri Olsa 
Cc: Kan 
Cc: Liang
Cc: Linus Torvalds 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Stephane Eranian 
Cc: Thomas Gleixner 
Cc: Vince Weaver 
Link: https://lkml.kernel.org/r/20190616140358.27799-7-jo...@kernel.org
Signed-off-by: Ingo Molnar 
---
 arch/x86/events/intel/rapl.c | 53 +---
 1 file changed, 11 insertions(+), 42 deletions(-)

diff --git a/arch/x86/events/intel/rapl.c b/arch/x86/events/intel/rapl.c
index 417de3fdde61..00b2b5d82d58 100644
--- a/arch/x86/events/intel/rapl.c
+++ b/arch/x86/events/intel/rapl.c
@@ -55,6 +55,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include "../perf_event.h"
@@ -65,19 +66,6 @@ MODULE_LICENSE("GPL");
 /*
  * RAPL energy status counters
  */
-#define RAPL_IDX_PP0_NRG_STAT  0   /* all cores */
-#define INTEL_RAPL_PP0 0x1 /* pseudo-encoding */
-#define RAPL_IDX_PKG_NRG_STAT  1   /* entire package */
-#define INTEL_RAPL_PKG 0x2 /* pseudo-encoding */
-#define RAPL_IDX_RAM_NRG_STAT  2   /* DRAM */
-#define INTEL_RAPL_RAM 0x3 /* pseudo-encoding */
-#define RAPL_IDX_PP1_NRG_STAT  3   /* gpu */
-#define INTEL_RAPL_PP1 0x4 /* pseudo-encoding */
-#define RAPL_IDX_PSYS_NRG_STAT 4   /* psys */
-#define INTEL_RAPL_PSYS0x5 /* pseudo-encoding */
-
-#define NR_RAPL_DOMAINS 0x5
-
 enum perf_rapl_events {
PERF_RAPL_PP0 = 0,  /* all cores */
PERF_RAPL_PKG,  /* entire package */
@@ -86,6 +74,7 @@ enum perf_rapl_events {
PERF_RAPL_PSYS, /* psys */
 
PERF_RAPL_MAX,
+   NR_RAPL_DOMAINS = PERF_RAPL_MAX,
 };
 
 static const char *const rapl_domain_names[NR_RAPL_DOMAINS] __initconst = {
@@ -149,6 +138,7 @@ static struct rapl_pmus *rapl_pmus;
 static cpumask_t rapl_cpu_mask;
 static unsigned int rapl_cntr_mask;
 static u64 rapl_timer_ms;
+static struct perf_msr rapl_msrs[];
 
 static inline struct rapl_pmu *cpu_to_rapl_pmu(unsigned int cpu)
 {
@@ -340,7 +330,7 @@ static void rapl_pmu_event_del(struct perf_event *event, 
int flags)
 static int rapl_pmu_event_init(struct perf_event *event)
 {
u64 cfg = event->attr.config & RAPL_EVENT_MASK;
-   int bit, msr, ret = 0;
+   int bit, ret = 0;
struct rapl_pmu *pmu;
 
/* only look at RAPL events */
@@ -356,33 +346,12 @@ static int rapl_pmu_event_init(struct perf_event *event)
 
event->event_caps |= PERF_EV_CAP_READ_ACTIVE_PKG;
 
-   /*
-* check event is known (determines counter)
-*/
-   switch (cfg) {
-   case INTEL_RAPL_PP0:
-   bit = RAPL_IDX_PP0_NRG_STAT;
-   msr = MSR_PP0_ENERGY_STATUS;
-   break;
-   case INTEL_RAPL_PKG:
-   bit = RAPL_IDX_PKG_NRG_STAT;
-   msr = MSR_PKG_ENERGY_STATUS;
-   break;
-   case INTEL_RAPL_RAM:
-   bit = RAPL_IDX_RAM_NRG_STAT;
-   msr = MSR_DRAM_ENERGY_STATUS;
-   break;
-   case INTEL_RAPL_PP1:
-   bit = RAPL_IDX_PP1_NRG_STAT;
-   msr = MSR_PP1_ENERGY_STATUS;
-   break;
-   case INTEL_RAPL_PSYS:
-   bit = RAPL_IDX_PSYS_NRG_STAT;
-   msr = MSR_PLATFORM_ENERGY_STATUS;
-   break;
-   default:
+   if (!cfg || cfg >= NR_RAPL_DOMAINS + 1)
return -EINVAL;
-   }
+
+   cfg = array_index_nospec((long)cfg, NR_RAPL_DOMAINS + 1);
+   bit = cfg - 1;
+
/* check event supported */
if (!(rapl_cntr_mask & (1 << bit)))
return -EINVAL;
@@ -397,7 +366,7 @@ static int rapl_pmu_event_init(struct perf_event *event)
return -EINVAL;
event->cpu = pmu->cpu;
event->pmu_private = pmu;
-   event->hw.event_base = msr;
+   event->hw.event_base = rapl_msrs[bit].msr;
event->hw.config = cfg;
event->hw.idx = bit;
 
@@ -705,7 +674,7 @@ static int rapl_check_hw_unit(bool apply_quirk)
 * of 2. Datasheet, September 2014, Reference Number: 330784-001 "
 */
if (apply_quirk)
-   rapl_hw_unit[RAPL_IDX_RAM_NRG_STAT] = 16;
+   

[tip:perf/core] perf/x86/rapl: Get rapl_cntr_mask from new probe framework

2019-06-25 Thread tip-bot for Jiri Olsa
Commit-ID:  cd105aed1a9954605d693948efad86cd8e57cb1a
Gitweb: https://git.kernel.org/tip/cd105aed1a9954605d693948efad86cd8e57cb1a
Author: Jiri Olsa 
AuthorDate: Sun, 16 Jun 2019 16:03:55 +0200
Committer:  Ingo Molnar 
CommitDate: Mon, 24 Jun 2019 19:28:34 +0200

perf/x86/rapl: Get rapl_cntr_mask from new probe framework

We get rapl_cntr_mask from perf_msr_probe call, as a replacement
for current intel_rapl_init_fun::cntr_mask value for each model.

Signed-off-by: Jiri Olsa 
Signed-off-by: Peter Zijlstra (Intel) 
Cc: Alexander Shishkin 
Cc: Andy Lutomirski 
Cc: Arnaldo Carvalho de Melo 
Cc: Arnaldo Carvalho de Melo 
Cc: Borislav Petkov 
Cc: Greg Kroah-Hartman 
Cc: Jiri Olsa 
Cc: Kan 
Cc: Liang
Cc: Linus Torvalds 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Stephane Eranian 
Cc: Thomas Gleixner 
Cc: Vince Weaver 
Link: https://lkml.kernel.org/r/20190616140358.27799-6-jo...@kernel.org
Signed-off-by: Ingo Molnar 
---
 arch/x86/events/intel/rapl.c | 38 ++
 1 file changed, 2 insertions(+), 36 deletions(-)

diff --git a/arch/x86/events/intel/rapl.c b/arch/x86/events/intel/rapl.c
index fa6d8065db15..417de3fdde61 100644
--- a/arch/x86/events/intel/rapl.c
+++ b/arch/x86/events/intel/rapl.c
@@ -96,33 +96,6 @@ static const char *const rapl_domain_names[NR_RAPL_DOMAINS] 
__initconst = {
"psys",
 };
 
-/* Clients have PP0, PKG */
-#define RAPL_IDX_CLN   (1driver_data;
-   perf_msr_probe(rapl_msrs, PERF_RAPL_MAX, false, (void *) >events);
+   rapl_cntr_mask = perf_msr_probe(rapl_msrs, PERF_RAPL_MAX,
+   false, (void *) >events);
 
id = x86_match_cpu(rapl_cpu_match);
if (!id)
@@ -987,7 +954,6 @@ static int __init rapl_pmu_init(void)
 
rapl_init = (struct intel_rapl_init_fun *)id->driver_data;
apply_quirk = rapl_init->apply_quirk;
-   rapl_cntr_mask = rapl_init->cntr_mask;
rapl_pmu_events_group.attrs = rapl_init->attrs;
 
ret = rapl_check_hw_unit(apply_quirk);


[tip:perf/core] perf/x86/rapl: Use new MSR detection interface

2019-06-25 Thread tip-bot for Jiri Olsa
Commit-ID:  5fb5273a905ca4cba7aae16e61c26127cadbac5c
Gitweb: https://git.kernel.org/tip/5fb5273a905ca4cba7aae16e61c26127cadbac5c
Author: Jiri Olsa 
AuthorDate: Sun, 16 Jun 2019 16:03:54 +0200
Committer:  Ingo Molnar 
CommitDate: Mon, 24 Jun 2019 19:28:33 +0200

perf/x86/rapl: Use new MSR detection interface

Using perf_msr_probe function to probe for RAPL MSRs.

Adding new rapl_model_match device table, that
gathers events info for given model, following
the MSR and cstate module design.

It will replace the current rapl_cpu_match device
table and detection code in following patches.

Signed-off-by: Jiri Olsa 
Signed-off-by: Peter Zijlstra (Intel) 
Cc: Alexander Shishkin 
Cc: Andy Lutomirski 
Cc: Arnaldo Carvalho de Melo 
Cc: Arnaldo Carvalho de Melo 
Cc: Borislav Petkov 
Cc: Greg Kroah-Hartman 
Cc: Jiri Olsa 
Cc: Kan 
Cc: Liang
Cc: Linus Torvalds 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Stephane Eranian 
Cc: Thomas Gleixner 
Cc: Vince Weaver 
Link: https://lkml.kernel.org/r/20190616140358.27799-5-jo...@kernel.org
Signed-off-by: Ingo Molnar 
---
 arch/x86/events/intel/rapl.c | 192 ++-
 1 file changed, 191 insertions(+), 1 deletion(-)

diff --git a/arch/x86/events/intel/rapl.c b/arch/x86/events/intel/rapl.c
index 798135419a62..fa6d8065db15 100644
--- a/arch/x86/events/intel/rapl.c
+++ b/arch/x86/events/intel/rapl.c
@@ -58,6 +58,7 @@
 #include 
 #include 
 #include "../perf_event.h"
+#include "../probe.h"
 
 MODULE_LICENSE("GPL");
 
@@ -76,6 +77,17 @@ MODULE_LICENSE("GPL");
 #define INTEL_RAPL_PSYS0x5 /* pseudo-encoding */
 
 #define NR_RAPL_DOMAINS 0x5
+
+enum perf_rapl_events {
+   PERF_RAPL_PP0 = 0,  /* all cores */
+   PERF_RAPL_PKG,  /* entire package */
+   PERF_RAPL_RAM,  /* DRAM */
+   PERF_RAPL_PP1,  /* gpu */
+   PERF_RAPL_PSYS, /* psys */
+
+   PERF_RAPL_MAX,
+};
+
 static const char *const rapl_domain_names[NR_RAPL_DOMAINS] __initconst = {
"pp0-core",
"package",
@@ -153,6 +165,11 @@ struct rapl_pmus {
struct rapl_pmu *pmus[];
 };
 
+struct rapl_model {
+   unsigned long   events;
+   boolapply_quirk;
+};
+
  /* 1/2^hw_unit Joule */
 static int rapl_hw_unit[NR_RAPL_DOMAINS] __read_mostly;
 static struct rapl_pmus *rapl_pmus;
@@ -538,9 +555,18 @@ static struct attribute *rapl_events_knl_attr[] = {
NULL,
 };
 
+/*
+ * There are no default events, but we need to create
+ * "events" group (with empty attrs) before updating
+ * it with detected events.
+ */
+static struct attribute *attrs_empty[] = {
+   NULL,
+};
+
 static struct attribute_group rapl_pmu_events_group = {
.name = "events",
-   .attrs = NULL, /* patched at runtime */
+   .attrs = attrs_empty,
 };
 
 DEFINE_RAPL_FORMAT_ATTR(event, event, "config:0-7");
@@ -561,6 +587,79 @@ static const struct attribute_group *rapl_attr_groups[] = {
NULL,
 };
 
+static struct attribute *rapl_events_cores[] = {
+   EVENT_PTR(rapl_cores),
+   EVENT_PTR(rapl_cores_unit),
+   EVENT_PTR(rapl_cores_scale),
+   NULL,
+};
+
+static struct attribute_group rapl_events_cores_group = {
+   .name  = "events",
+   .attrs = rapl_events_cores,
+};
+
+static struct attribute *rapl_events_pkg[] = {
+   EVENT_PTR(rapl_pkg),
+   EVENT_PTR(rapl_pkg_unit),
+   EVENT_PTR(rapl_pkg_scale),
+   NULL,
+};
+
+static struct attribute_group rapl_events_pkg_group = {
+   .name  = "events",
+   .attrs = rapl_events_pkg,
+};
+
+static struct attribute *rapl_events_ram[] = {
+   EVENT_PTR(rapl_ram),
+   EVENT_PTR(rapl_ram_unit),
+   EVENT_PTR(rapl_ram_scale),
+   NULL,
+};
+
+static struct attribute_group rapl_events_ram_group = {
+   .name  = "events",
+   .attrs = rapl_events_ram,
+};
+
+static struct attribute *rapl_events_gpu[] = {
+   EVENT_PTR(rapl_gpu),
+   EVENT_PTR(rapl_gpu_unit),
+   EVENT_PTR(rapl_gpu_scale),
+   NULL,
+};
+
+static struct attribute_group rapl_events_gpu_group = {
+   .name  = "events",
+   .attrs = rapl_events_gpu,
+};
+
+static struct attribute *rapl_events_psys[] = {
+   EVENT_PTR(rapl_psys),
+   EVENT_PTR(rapl_psys_unit),
+   EVENT_PTR(rapl_psys_scale),
+   NULL,
+};
+
+static struct attribute_group rapl_events_psys_group = {
+   .name  = "events",
+   .attrs = rapl_events_psys,
+};
+
+static bool test_msr(int idx, void *data)
+{
+   return test_bit(idx, (unsigned long *) data);
+}
+
+static struct perf_msr rapl_msrs[] = {
+   [PERF_RAPL_PP0]  = { MSR_PP0_ENERGY_STATUS,  
_events_cores_group, test_msr },
+   [PERF_RAPL_PKG]  = { MSR_PKG_ENERGY_STATUS,  
_events_pkg_group,   test_msr },
+   [PERF_RAPL_RAM]  = { MSR_DRAM_ENERGY_STATUS, 
_events_ram_group,   test_msr },
+   [PERF_RAPL_PP1]  = { MSR_PP1_ENERGY_STATUS,  
_events_gpu_group,   

[tip:perf/core] perf/x86/cstate: Use new probe function

2019-06-25 Thread tip-bot for Jiri Olsa
Commit-ID:  8f2a28c5859ba33519d90b66bf7f820e36640c98
Gitweb: https://git.kernel.org/tip/8f2a28c5859ba33519d90b66bf7f820e36640c98
Author: Jiri Olsa 
AuthorDate: Sun, 16 Jun 2019 16:03:53 +0200
Committer:  Ingo Molnar 
CommitDate: Mon, 24 Jun 2019 19:28:33 +0200

perf/x86/cstate: Use new probe function

Using perf_msr_probe function to probe for cstate events.

The functionality is the same, with one exception, that
perf_msr_probe checks for rdmsr to return value != 0 for
given MSR register.

Using the new attribute groups and adding the events via
pmu::attr_update.

Signed-off-by: Jiri Olsa 
Signed-off-by: Peter Zijlstra (Intel) 
Cc: Alexander Shishkin 
Cc: Andy Lutomirski 
Cc: Arnaldo Carvalho de Melo 
Cc: Arnaldo Carvalho de Melo 
Cc: Borislav Petkov 
Cc: Greg Kroah-Hartman 
Cc: Jiri Olsa 
Cc: Kan 
Cc: Liang
Cc: Linus Torvalds 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Stephane Eranian 
Cc: Thomas Gleixner 
Cc: Vince Weaver 
Link: https://lkml.kernel.org/r/20190616140358.27799-4-jo...@kernel.org
Signed-off-by: Ingo Molnar 
---
 arch/x86/events/intel/cstate.c | 152 +++--
 1 file changed, 87 insertions(+), 65 deletions(-)

diff --git a/arch/x86/events/intel/cstate.c b/arch/x86/events/intel/cstate.c
index e1caa0b49d63..688592b34564 100644
--- a/arch/x86/events/intel/cstate.c
+++ b/arch/x86/events/intel/cstate.c
@@ -96,6 +96,7 @@
 #include 
 #include 
 #include "../perf_event.h"
+#include "../probe.h"
 
 MODULE_LICENSE("GPL");
 
@@ -144,25 +145,42 @@ enum perf_cstate_core_events {
PERF_CSTATE_CORE_EVENT_MAX,
 };
 
-PMU_EVENT_ATTR_STRING(c1-residency, evattr_cstate_core_c1, "event=0x00");
-PMU_EVENT_ATTR_STRING(c3-residency, evattr_cstate_core_c3, "event=0x01");
-PMU_EVENT_ATTR_STRING(c6-residency, evattr_cstate_core_c6, "event=0x02");
-PMU_EVENT_ATTR_STRING(c7-residency, evattr_cstate_core_c7, "event=0x03");
+PMU_EVENT_ATTR_STRING(c1-residency, attr_cstate_core_c1, "event=0x00");
+PMU_EVENT_ATTR_STRING(c3-residency, attr_cstate_core_c3, "event=0x01");
+PMU_EVENT_ATTR_STRING(c6-residency, attr_cstate_core_c6, "event=0x02");
+PMU_EVENT_ATTR_STRING(c7-residency, attr_cstate_core_c7, "event=0x03");
 
-static struct perf_cstate_msr core_msr[] = {
-   [PERF_CSTATE_CORE_C1_RES] = { MSR_CORE_C1_RES,  
_cstate_core_c1 },
-   [PERF_CSTATE_CORE_C3_RES] = { MSR_CORE_C3_RESIDENCY,
_cstate_core_c3 },
-   [PERF_CSTATE_CORE_C6_RES] = { MSR_CORE_C6_RESIDENCY,
_cstate_core_c6 },
-   [PERF_CSTATE_CORE_C7_RES] = { MSR_CORE_C7_RESIDENCY,
_cstate_core_c7 },
+static unsigned long core_msr_mask;
+
+PMU_EVENT_GROUP(events, cstate_core_c1);
+PMU_EVENT_GROUP(events, cstate_core_c3);
+PMU_EVENT_GROUP(events, cstate_core_c6);
+PMU_EVENT_GROUP(events, cstate_core_c7);
+
+static bool test_msr(int idx, void *data)
+{
+   return test_bit(idx, (unsigned long *) data);
+}
+
+static struct perf_msr core_msr[] = {
+   [PERF_CSTATE_CORE_C1_RES] = { MSR_CORE_C1_RES,  
_cstate_core_c1,  test_msr },
+   [PERF_CSTATE_CORE_C3_RES] = { MSR_CORE_C3_RESIDENCY,
_cstate_core_c3,  test_msr },
+   [PERF_CSTATE_CORE_C6_RES] = { MSR_CORE_C6_RESIDENCY,
_cstate_core_c6,  test_msr },
+   [PERF_CSTATE_CORE_C7_RES] = { MSR_CORE_C7_RESIDENCY,
_cstate_core_c7,  test_msr },
 };
 
-static struct attribute *core_events_attrs[PERF_CSTATE_CORE_EVENT_MAX + 1] = {
+static struct attribute *attrs_empty[] = {
NULL,
 };
 
+/*
+ * There are no default events, but we need to create
+ * "events" group (with empty attrs) before updating
+ * it with detected events.
+ */
 static struct attribute_group core_events_attr_group = {
.name = "events",
-   .attrs = core_events_attrs,
+   .attrs = attrs_empty,
 };
 
 DEFINE_CSTATE_FORMAT_ATTR(core_event, event, "config:0-63");
@@ -211,31 +229,37 @@ enum perf_cstate_pkg_events {
PERF_CSTATE_PKG_EVENT_MAX,
 };
 
-PMU_EVENT_ATTR_STRING(c2-residency, evattr_cstate_pkg_c2, "event=0x00");
-PMU_EVENT_ATTR_STRING(c3-residency, evattr_cstate_pkg_c3, "event=0x01");
-PMU_EVENT_ATTR_STRING(c6-residency, evattr_cstate_pkg_c6, "event=0x02");
-PMU_EVENT_ATTR_STRING(c7-residency, evattr_cstate_pkg_c7, "event=0x03");
-PMU_EVENT_ATTR_STRING(c8-residency, evattr_cstate_pkg_c8, "event=0x04");
-PMU_EVENT_ATTR_STRING(c9-residency, evattr_cstate_pkg_c9, "event=0x05");
-PMU_EVENT_ATTR_STRING(c10-residency, evattr_cstate_pkg_c10, "event=0x06");
-
-static struct perf_cstate_msr pkg_msr[] = {
-   [PERF_CSTATE_PKG_C2_RES] = { MSR_PKG_C2_RESIDENCY,  
_cstate_pkg_c2 },
-   [PERF_CSTATE_PKG_C3_RES] = { MSR_PKG_C3_RESIDENCY,  
_cstate_pkg_c3 },
-   [PERF_CSTATE_PKG_C6_RES] = { MSR_PKG_C6_RESIDENCY,  
_cstate_pkg_c6 },
-   [PERF_CSTATE_PKG_C7_RES] = { MSR_PKG_C7_RESIDENCY,  
_cstate_pkg_c7 },
-   [PERF_CSTATE_PKG_C8_RES] = { MSR_PKG_C8_RESIDENCY,  
_cstate_pkg_c8 },
-   [PERF_CSTATE_PKG_C9_RES] = { MSR_PKG_C9_RESIDENCY,  
_cstate_pkg_c9 },
-   

[tip:perf/core] perf/x86/msr: Use new probe function

2019-06-25 Thread tip-bot for Jiri Olsa
Commit-ID:  dde5e72068cd0cd8237f7c2589ec8f587563a390
Gitweb: https://git.kernel.org/tip/dde5e72068cd0cd8237f7c2589ec8f587563a390
Author: Jiri Olsa 
AuthorDate: Sun, 16 Jun 2019 16:03:52 +0200
Committer:  Ingo Molnar 
CommitDate: Mon, 24 Jun 2019 19:28:32 +0200

perf/x86/msr: Use new probe function

Using perf_msr_probe function to probe for msr events.

The functionality is the same, with one exception, that
perf_msr_probe checks for rdmsr to return value != 0 for
given MSR register.

Using the new attribute groups and adding the events via
pmu::attr_update.

Signed-off-by: Jiri Olsa 
Signed-off-by: Peter Zijlstra (Intel) 
Cc: Alexander Shishkin 
Cc: Andy Lutomirski 
Cc: Arnaldo Carvalho de Melo 
Cc: Arnaldo Carvalho de Melo 
Cc: Borislav Petkov 
Cc: Greg Kroah-Hartman 
Cc: Jiri Olsa 
Cc: Kan 
Cc: Liang
Cc: Linus Torvalds 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Stephane Eranian 
Cc: Thomas Gleixner 
Cc: Vince Weaver 
Link: https://lkml.kernel.org/r/20190616140358.27799-3-jo...@kernel.org
Signed-off-by: Ingo Molnar 
---
 arch/x86/events/msr.c | 110 +++---
 1 file changed, 60 insertions(+), 50 deletions(-)

diff --git a/arch/x86/events/msr.c b/arch/x86/events/msr.c
index f3f4c2263501..9431447541e9 100644
--- a/arch/x86/events/msr.c
+++ b/arch/x86/events/msr.c
@@ -1,7 +1,9 @@
 // SPDX-License-Identifier: GPL-2.0
 #include 
+#include 
 #include 
 #include 
+#include "probe.h"
 
 enum perf_msr_id {
PERF_MSR_TSC= 0,
@@ -12,32 +14,30 @@ enum perf_msr_id {
PERF_MSR_PTSC   = 5,
PERF_MSR_IRPERF = 6,
PERF_MSR_THERM  = 7,
-   PERF_MSR_THERM_SNAP = 8,
-   PERF_MSR_THERM_UNIT = 9,
PERF_MSR_EVENT_MAX,
 };
 
-static bool test_aperfmperf(int idx)
+static bool test_aperfmperf(int idx, void *data)
 {
return boot_cpu_has(X86_FEATURE_APERFMPERF);
 }
 
-static bool test_ptsc(int idx)
+static bool test_ptsc(int idx, void *data)
 {
return boot_cpu_has(X86_FEATURE_PTSC);
 }
 
-static bool test_irperf(int idx)
+static bool test_irperf(int idx, void *data)
 {
return boot_cpu_has(X86_FEATURE_IRPERF);
 }
 
-static bool test_therm_status(int idx)
+static bool test_therm_status(int idx, void *data)
 {
return boot_cpu_has(X86_FEATURE_DTHERM);
 }
 
-static bool test_intel(int idx)
+static bool test_intel(int idx, void *data)
 {
if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL ||
boot_cpu_data.x86 != 6)
@@ -98,37 +98,51 @@ static bool test_intel(int idx)
return false;
 }
 
-struct perf_msr {
-   u64 msr;
-   struct  perf_pmu_events_attr *attr;
-   bool(*test)(int idx);
+PMU_EVENT_ATTR_STRING(tsc, attr_tsc,   
"event=0x00");
+PMU_EVENT_ATTR_STRING(aperf,   attr_aperf, 
"event=0x01");
+PMU_EVENT_ATTR_STRING(mperf,   attr_mperf, 
"event=0x02");
+PMU_EVENT_ATTR_STRING(pperf,   attr_pperf, 
"event=0x03");
+PMU_EVENT_ATTR_STRING(smi, attr_smi,   
"event=0x04");
+PMU_EVENT_ATTR_STRING(ptsc,attr_ptsc,  
"event=0x05");
+PMU_EVENT_ATTR_STRING(irperf,  attr_irperf,
"event=0x06");
+PMU_EVENT_ATTR_STRING(cpu_thermal_margin,  attr_therm, 
"event=0x07");
+PMU_EVENT_ATTR_STRING(cpu_thermal_margin.snapshot, attr_therm_snap,
"1" );
+PMU_EVENT_ATTR_STRING(cpu_thermal_margin.unit, attr_therm_unit,
"C" );
+
+static unsigned long msr_mask;
+
+PMU_EVENT_GROUP(events, aperf);
+PMU_EVENT_GROUP(events, mperf);
+PMU_EVENT_GROUP(events, pperf);
+PMU_EVENT_GROUP(events, smi);
+PMU_EVENT_GROUP(events, ptsc);
+PMU_EVENT_GROUP(events, irperf);
+
+static struct attribute *attrs_therm[] = {
+   _therm.attr.attr,
+   _therm_snap.attr.attr,
+   _therm_unit.attr.attr,
+   NULL,
 };
 
-PMU_EVENT_ATTR_STRING(tsc, evattr_tsc, 
"event=0x00");
-PMU_EVENT_ATTR_STRING(aperf,   evattr_aperf,   
"event=0x01");
-PMU_EVENT_ATTR_STRING(mperf,   evattr_mperf,   
"event=0x02");
-PMU_EVENT_ATTR_STRING(pperf,   evattr_pperf,   
"event=0x03");
-PMU_EVENT_ATTR_STRING(smi, evattr_smi, 
"event=0x04");
-PMU_EVENT_ATTR_STRING(ptsc,evattr_ptsc,
"event=0x05");
-PMU_EVENT_ATTR_STRING(irperf,  evattr_irperf,  
"event=0x06");
-PMU_EVENT_ATTR_STRING(cpu_thermal_margin,  evattr_therm,   
"event=0x07");
-PMU_EVENT_ATTR_STRING(cpu_thermal_margin.snapshot, 

[tip:perf/core] perf/x86: Add MSR probe interface

2019-06-25 Thread tip-bot for Jiri Olsa
Commit-ID:  98253a546a468d88b7e782ab67cdf447d3c7bbe2
Gitweb: https://git.kernel.org/tip/98253a546a468d88b7e782ab67cdf447d3c7bbe2
Author: Jiri Olsa 
AuthorDate: Sun, 16 Jun 2019 16:03:51 +0200
Committer:  Ingo Molnar 
CommitDate: Mon, 24 Jun 2019 19:28:31 +0200

perf/x86: Add MSR probe interface

Adding perf_msr_probe function to provide interface for
checking up on MSR register and set the related attribute
group visibility.

User defines following struct for each MSR register:

  struct perf_msr {
   u64   msr;
   struct attribute_group   *grp;
   bool(*test)(int idx, void *data);
   bool  no_check;
  };

Where:
  msr  - is the MSR address
  attrs- is attribute groups array to add if the check passed
  test - is test function pointer
  no_check - is bool that bypass the check and adds the
  attribute without any test

The array of struct perf_msr is passed into:

  perf_msr_probe(struct perf_msr *msr, int cnt, bool zero, void *data)

Together with:
  cnt  - which is the number of struct msr array elements
  data - which is user pointer passed to the test function
  zero - allow counters that returns zero on rdmsr

The perf_msr_probe will executed test code, read the MSR and
check the value is != 0. If all these tests pass, related
attribute group is kept visible.

Also adding PMU_EVENT_GROUP macro helper to define attribute
group for single attribute. It will be used in following patches.

Signed-off-by: Jiri Olsa 
Signed-off-by: Peter Zijlstra (Intel) 
Cc: Alexander Shishkin 
Cc: Andy Lutomirski 
Cc: Arnaldo Carvalho de Melo 
Cc: Arnaldo Carvalho de Melo 
Cc: Borislav Petkov 
Cc: Greg Kroah-Hartman 
Cc: Jiri Olsa 
Cc: Kan 
Cc: Liang
Cc: Linus Torvalds 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Stephane Eranian 
Cc: Thomas Gleixner 
Cc: Vince Weaver 
Link: https://lkml.kernel.org/r/20190616140358.27799-2-jo...@kernel.org
Signed-off-by: Ingo Molnar 
---
 arch/x86/events/Makefile |  2 +-
 arch/x86/events/probe.c  | 45 +
 arch/x86/events/probe.h  | 29 +
 3 files changed, 75 insertions(+), 1 deletion(-)

diff --git a/arch/x86/events/Makefile b/arch/x86/events/Makefile
index 9cbfd34042d5..9e07f554333f 100644
--- a/arch/x86/events/Makefile
+++ b/arch/x86/events/Makefile
@@ -1,5 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0-only
-obj-y  += core.o
+obj-y  += core.o probe.o
 obj-y  += amd/
 obj-$(CONFIG_X86_LOCAL_APIC)+= msr.o
 obj-$(CONFIG_CPU_SUP_INTEL)+= intel/
diff --git a/arch/x86/events/probe.c b/arch/x86/events/probe.c
new file mode 100644
index ..c2ede2f3b277
--- /dev/null
+++ b/arch/x86/events/probe.c
@@ -0,0 +1,45 @@
+// SPDX-License-Identifier: GPL-2.0
+#include 
+#include 
+#include 
+#include "probe.h"
+
+static umode_t
+not_visible(struct kobject *kobj, struct attribute *attr, int i)
+{
+   return 0;
+}
+
+unsigned long
+perf_msr_probe(struct perf_msr *msr, int cnt, bool zero, void *data)
+{
+   unsigned long avail = 0;
+   unsigned int bit;
+   u64 val;
+
+   if (cnt >= BITS_PER_LONG)
+   return 0;
+
+   for (bit = 0; bit < cnt; bit++) {
+   if (!msr[bit].no_check) {
+   struct attribute_group *grp = msr[bit].grp;
+
+   grp->is_visible = not_visible;
+
+   if (msr[bit].test && !msr[bit].test(bit, data))
+   continue;
+   /* Virt sucks; you cannot tell if a R/O MSR is present 
:/ */
+   if (rdmsrl_safe(msr[bit].msr, ))
+   continue;
+   /* Disable zero counters if requested. */
+   if (!zero && !val)
+   continue;
+
+   grp->is_visible = NULL;
+   }
+   avail |= BIT(bit);
+   }
+
+   return avail;
+}
+EXPORT_SYMBOL_GPL(perf_msr_probe);
diff --git a/arch/x86/events/probe.h b/arch/x86/events/probe.h
new file mode 100644
index ..4c8e0afc5fb5
--- /dev/null
+++ b/arch/x86/events/probe.h
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __ARCH_X86_EVENTS_PROBE_H__
+#define __ARCH_X86_EVENTS_PROBE_H__
+#include 
+
+struct perf_msr {
+   u64   msr;
+   struct attribute_group   *grp;
+   bool(*test)(int idx, void *data);
+   bool  no_check;
+};
+
+unsigned long
+perf_msr_probe(struct perf_msr *msr, int cnt, bool no_zero, void *data);
+
+#define __PMU_EVENT_GROUP(_name)   \
+static struct attribute *attrs_##_name[] = {   \
+   _##_name.attr.attr,\
+   NULL,   \
+}
+
+#define 

[tip:perf/core] perf evsel: Remove superfluous nthreads system_wide setup in alloc_fd()

2019-06-17 Thread tip-bot for Jiri Olsa
Commit-ID:  10981c8012bc9ad4119420716a5dccfe8043b596
Gitweb: https://git.kernel.org/tip/10981c8012bc9ad4119420716a5dccfe8043b596
Author: Jiri Olsa 
AuthorDate: Fri, 17 May 2019 13:33:47 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Mon, 10 Jun 2019 15:50:01 -0300

perf evsel: Remove superfluous nthreads system_wide setup in alloc_fd()

It's already setup in the only caller of this method in
perf_evsel__open(), right before calling perf_evsel__alloc_fd(), no need
to do it again.

Also it's better to have it out of the function before we move it to
libperf.

Signed-off-by: Jiri Olsa 
Cc: Adrian Hunter 
Cc: Jiri Olsa 
Cc: Namhyung Kim 
Link: https://lkml.kernel.org/n/tip-1k8lhyjxfk7o8v4g3r7ey...@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/util/evsel.c | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 9f3b58071863..68beef8f47ff 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -1148,9 +1148,6 @@ void perf_evsel__config(struct perf_evsel *evsel, struct 
record_opts *opts,
 
 static int perf_evsel__alloc_fd(struct perf_evsel *evsel, int ncpus, int 
nthreads)
 {
-   if (evsel->system_wide)
-   nthreads = 1;
-
evsel->fd = xyarray__new(ncpus, nthreads, sizeof(int));
 
if (evsel->fd) {


[tip:perf/core] perf jvmti: Address gcc string overflow warning for strncpy()

2019-06-17 Thread tip-bot for Jiri Olsa
Commit-ID:  279ab04dbea1370d2eac0f854270369ccaef8a44
Gitweb: https://git.kernel.org/tip/279ab04dbea1370d2eac0f854270369ccaef8a44
Author: Jiri Olsa 
AuthorDate: Fri, 31 May 2019 15:13:21 +0200
Committer:  Arnaldo Carvalho de Melo 
CommitDate: Wed, 5 Jun 2019 09:51:26 -0300

perf jvmti: Address gcc string overflow warning for strncpy()

We are getting false positive gcc warning when we compile with gcc9 (9.1.1):

 CC   jvmti/libjvmti.o
   In file included from /usr/include/string.h:494,
from jvmti/libjvmti.c:5:
   In function ‘strncpy’,
   inlined from ‘copy_class_filename.constprop’ at jvmti/libjvmti.c:166:3:
   /usr/include/bits/string_fortified.h:106:10: error: ‘__builtin_strncpy’ 
specified bound depends on the length of the source argument 
[-Werror=stringop-overflow=]
 106 |   return __builtin___strncpy_chk (__dest, __src, __len, __bos 
(__dest));
 |  
^~
   jvmti/libjvmti.c: In function ‘copy_class_filename.constprop’:
   jvmti/libjvmti.c:165:26: note: length computed here
 165 |   size_t file_name_len = strlen(file_name);
 |  ^
   cc1: all warnings being treated as errors

As per Arnaldo's suggestion use strlcpy(), which does the same thing and keeps
gcc silent.

Suggested-by: Arnaldo Carvalho de Melo 
Signed-off-by: Jiri Olsa 
Cc: Alexander Shishkin 
Cc: Ben Gainey 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Stephane Eranian 
Link: http://lkml.kernel.org/r/20190531131321.GB1281@krava
Signed-off-by: Arnaldo Carvalho de Melo 
---
 tools/perf/jvmti/libjvmti.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/perf/jvmti/libjvmti.c b/tools/perf/jvmti/libjvmti.c
index aea7b1fe85aa..c441a34cb1c0 100644
--- a/tools/perf/jvmti/libjvmti.c
+++ b/tools/perf/jvmti/libjvmti.c
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -162,8 +163,7 @@ copy_class_filename(const char * class_sign, const char * 
file_name, char * resu
result[i] = '\0';
} else {
/* fallback case */
-   size_t file_name_len = strlen(file_name);
-   strncpy(result, file_name, file_name_len < max_length ? 
file_name_len : max_length);
+   strlcpy(result, file_name, max_length);
}
 }
 


[tip:perf/core] perf/x86/intel: Disable check_msr for real HW

2019-06-17 Thread tip-bot for Jiri Olsa
Commit-ID:  d0e1a507bdc761a14906f03399d933ea639a1756
Gitweb: https://git.kernel.org/tip/d0e1a507bdc761a14906f03399d933ea639a1756
Author: Jiri Olsa 
AuthorDate: Sun, 16 Jun 2019 16:13:13 +0200
Committer:  Ingo Molnar 
CommitDate: Mon, 17 Jun 2019 12:36:24 +0200

perf/x86/intel: Disable check_msr for real HW

Tom Vaden reported false failure of the check_msr() function, because
some servers can do POST tracing and enable LBR tracing during
bootup.

Kan confirmed that check_msr patch was to fix a bug report in
guest, so it's ok to disable it for real HW.

Reported-by: Tom Vaden 
Signed-off-by: Jiri Olsa 
Signed-off-by: Peter Zijlstra (Intel) 
Acked-by: Tom Vaden 
Cc: Alexander Shishkin 
Cc: Arnaldo Carvalho de Melo 
Cc: Liang Kan 
Cc: Linus Torvalds 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Link: https://lkml.kernel.org/r/20190616141313.GD2500@krava
[ Readability edits. ]
Signed-off-by: Ingo Molnar 
---
 arch/x86/events/intel/core.c | 8 
 1 file changed, 8 insertions(+)

diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 5e6ae481dee7..bda450ff51ee 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -20,6 +20,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include "../perf_event.h"
 
@@ -4050,6 +4051,13 @@ static bool check_msr(unsigned long msr, u64 mask)
 {
u64 val_old, val_new, val_tmp;
 
+   /*
+* Disable the check for real HW, so we don't
+* mess with potentionaly enabled registers:
+*/
+   if (hypervisor_is_type(X86_HYPER_NATIVE))
+   return true;
+
/*
 * Read the current value, change it and read it back to see if it
 * matches, this is needed to detect certain hardware emulators


[tip:perf/core] perf/x86/intel: Use ->is_visible callback for default group

2019-06-17 Thread tip-bot for Jiri Olsa
Commit-ID:  b7c9b3927337b43b3c854064b9c17b84cb7ef0dc
Gitweb: https://git.kernel.org/tip/b7c9b3927337b43b3c854064b9c17b84cb7ef0dc
Author: Jiri Olsa 
AuthorDate: Fri, 24 May 2019 15:21:52 +0200
Committer:  Ingo Molnar 
CommitDate: Mon, 17 Jun 2019 12:36:23 +0200

perf/x86/intel: Use ->is_visible callback for default group

It's preffered to use group's ->is_visible callback, so
we do not need to use condition attribute assignment.

Suggested-by: Peter Zijlstra 
Signed-off-by: Jiri Olsa 
Signed-off-by: Peter Zijlstra (Intel) 
Cc: Alexander Shishkin 
Cc: Arnaldo Carvalho de Melo 
Cc: Greg Kroah-Hartman 
Cc: Linus Torvalds 
Cc: Namhyung Kim 
Cc: Thomas Gleixner 
Link: https://lkml.kernel.org/r/20190524132152.GB26617@krava
Signed-off-by: Ingo Molnar 
---
 arch/x86/events/intel/core.c | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 4377bf6a6f82..5e6ae481dee7 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -4391,7 +4391,7 @@ static DEVICE_ATTR(allow_tsx_force_abort, 0644,
 
 static struct attribute *intel_pmu_attrs[] = {
_attr_freeze_on_smi.attr,
-   NULL, /* _attr_allow_tsx_force_abort.attr.attr */
+   _attr_allow_tsx_force_abort.attr,
NULL,
 };
 
@@ -4419,6 +4419,15 @@ exra_is_visible(struct kobject *kobj, struct attribute 
*attr, int i)
return x86_pmu.version >= 2 ? attr->mode : 0;
 }
 
+static umode_t
+default_is_visible(struct kobject *kobj, struct attribute *attr, int i)
+{
+   if (attr == _attr_allow_tsx_force_abort.attr)
+   return x86_pmu.flags & PMU_FL_TFA ? attr->mode : 0;
+
+   return attr->mode;
+}
+
 static struct attribute_group group_events_td  = {
.name = "events",
 };
@@ -4455,7 +4464,8 @@ static struct attribute_group group_format_extra_skl = {
 };
 
 static struct attribute_group group_default = {
-   .attrs = intel_pmu_attrs,
+   .attrs  = intel_pmu_attrs,
+   .is_visible = default_is_visible,
 };
 
 static const struct attribute_group *attr_update[] = {
@@ -4979,7 +4989,6 @@ __init int intel_pmu_init(void)
x86_pmu.get_event_constraints = 
tfa_get_event_constraints;
x86_pmu.enable_all = intel_tfa_pmu_enable_all;
x86_pmu.commit_scheduling = intel_tfa_commit_scheduling;
-   intel_pmu_attrs[1] = 
_attr_allow_tsx_force_abort.attr;
}
 
pr_cont("Skylake events, ");


[tip:perf/core] perf/x86: Use update attribute groups for default attributes

2019-06-03 Thread tip-bot for Jiri Olsa
Commit-ID:  6a9f4efe78af6069a11946c64d3d4c86cb42046b
Gitweb: https://git.kernel.org/tip/6a9f4efe78af6069a11946c64d3d4c86cb42046b
Author: Jiri Olsa 
AuthorDate: Sun, 12 May 2019 17:55:18 +0200
Committer:  Ingo Molnar 
CommitDate: Mon, 3 Jun 2019 11:58:27 +0200

perf/x86: Use update attribute groups for default attributes

Using the new pmu::update_attrs attribute group for default
attributes - freeze_on_smi, allow_tsx_force_abort.

Signed-off-by: Jiri Olsa 
Signed-off-by: Peter Zijlstra (Intel) 
Cc: Alexander Shishkin 
Cc: Arnaldo Carvalho de Melo 
Cc: Greg Kroah-Hartman 
Cc: Linus Torvalds 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Link: https://lkml.kernel.org/r/20190512155518.21468-10-jo...@kernel.org
Signed-off-by: Ingo Molnar 
---
 arch/x86/events/core.c   | 34 --
 arch/x86/events/intel/core.c |  9 +
 arch/x86/events/perf_event.h |  3 ---
 3 files changed, 5 insertions(+), 41 deletions(-)

diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index dd0996ba75c3..f0e4804515d8 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -1618,32 +1618,6 @@ static struct attribute_group x86_pmu_format_group 
__ro_after_init = {
.attrs = NULL,
 };
 
-/* Merge two pointer arrays */
-__init struct attribute **merge_attr(struct attribute **a, struct attribute 
**b)
-{
-   struct attribute **new;
-   int j, i;
-
-   for (j = 0; a && a[j]; j++)
-   ;
-   for (i = 0; b && b[i]; i++)
-   j++;
-   j++;
-
-   new = kmalloc_array(j, sizeof(struct attribute *), GFP_KERNEL);
-   if (!new)
-   return NULL;
-
-   j = 0;
-   for (i = 0; a && a[i]; i++)
-   new[j++] = a[i];
-   for (i = 0; b && b[i]; i++)
-   new[j++] = b[i];
-   new[j] = NULL;
-
-   return new;
-}
-
 ssize_t events_sysfs_show(struct device *dev, struct device_attribute *attr, 
char *page)
 {
struct perf_pmu_events_attr *pmu_attr = \
@@ -1824,14 +1798,6 @@ static int __init init_hw_perf_events(void)
if (!x86_pmu.events_sysfs_show)
x86_pmu_events_group.attrs = _attrs;
 
-   if (x86_pmu.attrs) {
-   struct attribute **tmp;
-
-   tmp = merge_attr(x86_pmu_attr_group.attrs, x86_pmu.attrs);
-   if (!WARN_ON(!tmp))
-   x86_pmu_attr_group.attrs = tmp;
-   }
-
pmu.attr_update = x86_pmu.attr_update;
 
pr_info("... version:%d\n", x86_pmu.version);
diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 3bc967be7c7b..71001f005bfe 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -3897,8 +3897,6 @@ static __initconst const struct x86_pmu core_pmu = {
.check_period   = intel_pmu_check_period,
 };
 
-static struct attribute *intel_pmu_attrs[];
-
 static __initconst const struct x86_pmu intel_pmu = {
.name   = "Intel",
.handle_irq = intel_pmu_handle_irq,
@@ -3930,8 +3928,6 @@ static __initconst const struct x86_pmu intel_pmu = {
.format_attrs   = intel_arch3_formats_attr,
.events_sysfs_show  = intel_event_sysfs_show,
 
-   .attrs  = intel_pmu_attrs,
-
.cpu_prepare= intel_pmu_cpu_prepare,
.cpu_starting   = intel_pmu_cpu_starting,
.cpu_dying  = intel_pmu_cpu_dying,
@@ -4458,6 +4454,10 @@ static struct attribute_group group_format_extra_skl = {
.is_visible = exra_is_visible,
 };
 
+static struct attribute_group group_default = {
+   .attrs = intel_pmu_attrs,
+};
+
 static const struct attribute_group *attr_update[] = {
_events_td,
_events_mem,
@@ -4466,6 +4466,7 @@ static const struct attribute_group *attr_update[] = {
_caps_lbr,
_format_extra,
_format_extra_skl,
+   _default,
NULL,
 };
 
diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h
index 1da9b6f0b279..9bcec3f99e4a 100644
--- a/arch/x86/events/perf_event.h
+++ b/arch/x86/events/perf_event.h
@@ -636,7 +636,6 @@ struct x86_pmu {
const struct attribute_group **attr_update;
 
unsigned long   attr_freeze_on_smi;
-   struct attribute **attrs;
 
/*
 * CPU Hotplug hooks
@@ -903,8 +902,6 @@ static inline void set_linear_ip(struct pt_regs *regs, 
unsigned long ip)
 ssize_t x86_event_sysfs_show(char *page, u64 config, u64 event);
 ssize_t intel_event_sysfs_show(char *page, u64 config);
 
-struct attribute **merge_attr(struct attribute **a, struct attribute **b);
-
 ssize_t events_sysfs_show(struct device *dev, struct device_attribute *attr,
  char *page);
 ssize_t events_ht_sysfs_show(struct device *dev, struct device_attribute *attr,


[tip:perf/core] perf/x86/intel: Use update attributes for skylake format

2019-06-03 Thread tip-bot for Jiri Olsa
Commit-ID:  b657688069a24c3c81b6de22e0e57e1785d9211f
Gitweb: https://git.kernel.org/tip/b657688069a24c3c81b6de22e0e57e1785d9211f
Author: Jiri Olsa 
AuthorDate: Sun, 12 May 2019 17:55:17 +0200
Committer:  Ingo Molnar 
CommitDate: Mon, 3 Jun 2019 11:58:26 +0200

perf/x86/intel: Use update attributes for skylake format

Using the new pmu::update_attrs attribute group for
skylake specific format attributes.

Signed-off-by: Jiri Olsa 
Signed-off-by: Peter Zijlstra (Intel) 
Cc: Alexander Shishkin 
Cc: Arnaldo Carvalho de Melo 
Cc: Greg Kroah-Hartman 
Cc: Linus Torvalds 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Link: https://lkml.kernel.org/r/20190512155518.21468-9-jo...@kernel.org
Signed-off-by: Ingo Molnar 
---
 arch/x86/events/intel/core.c | 15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index de4779f44737..3bc967be7c7b 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -4453,6 +4453,11 @@ static struct attribute_group group_format_extra = {
.is_visible = exra_is_visible,
 };
 
+static struct attribute_group group_format_extra_skl = {
+   .name   = "format",
+   .is_visible = exra_is_visible,
+};
+
 static const struct attribute_group *attr_update[] = {
_events_td,
_events_mem,
@@ -4460,6 +4465,7 @@ static const struct attribute_group *attr_update[] = {
_caps_gen,
_caps_lbr,
_format_extra,
+   _format_extra_skl,
NULL,
 };
 
@@ -4467,11 +4473,11 @@ static struct attribute *empty_attrs;
 
 __init int intel_pmu_init(void)
 {
+   struct attribute **extra_skl_attr = _attrs;
struct attribute **extra_attr = _attrs;
struct attribute **td_attr= _attrs;
struct attribute **mem_attr   = _attrs;
struct attribute **tsx_attr   = _attrs;
-   struct attribute **to_free = NULL;
union cpuid10_edx edx;
union cpuid10_eax eax;
union cpuid10_ebx ebx;
@@ -4959,8 +4965,7 @@ __init int intel_pmu_init(void)
x86_pmu.get_event_constraints = hsw_get_event_constraints;
extra_attr = boot_cpu_has(X86_FEATURE_RTM) ?
hsw_format_attr : nhm_format_attr;
-   extra_attr = merge_attr(extra_attr, skl_format_attr);
-   to_free = extra_attr;
+   extra_skl_attr = skl_format_attr;
td_attr  = hsw_events_attrs;
mem_attr = hsw_mem_events_attrs;
tsx_attr = hsw_tsx_events_attrs;
@@ -4998,7 +5003,7 @@ __init int intel_pmu_init(void)
x86_pmu.get_event_constraints = icl_get_event_constraints;
extra_attr = boot_cpu_has(X86_FEATURE_RTM) ?
hsw_format_attr : nhm_format_attr;
-   extra_attr = merge_attr(extra_attr, skl_format_attr);
+   extra_skl_attr = skl_format_attr;
mem_attr = icl_events_attrs;
tsx_attr = icl_tsx_events_attrs;
x86_pmu.rtm_abort_event = X86_CONFIG(.event=0xca, .umask=0x02);
@@ -5033,6 +5038,7 @@ __init int intel_pmu_init(void)
group_events_mem.attrs = mem_attr;
group_events_tsx.attrs = tsx_attr;
group_format_extra.attrs = extra_attr;
+   group_format_extra_skl.attrs = extra_skl_attr;
 
x86_pmu.attr_update = attr_update;
 
@@ -5113,7 +5119,6 @@ __init int intel_pmu_init(void)
if (x86_pmu.counter_freezing)
x86_pmu.handle_irq = intel_pmu_handle_irq_v4;
 
-   kfree(to_free);
return 0;
 }
 


[tip:perf/core] perf/x86: Use update attribute groups for caps

2019-06-03 Thread tip-bot for Jiri Olsa
Commit-ID:  1f157286829c78c0bd8e495951a5c098d88e3d1a
Gitweb: https://git.kernel.org/tip/1f157286829c78c0bd8e495951a5c098d88e3d1a
Author: Jiri Olsa 
AuthorDate: Sun, 12 May 2019 17:55:15 +0200
Committer:  Ingo Molnar 
CommitDate: Mon, 3 Jun 2019 11:58:24 +0200

perf/x86: Use update attribute groups for caps

Using the new pmu::update_attrs attribute group for
"caps" directory.

Signed-off-by: Jiri Olsa 
Signed-off-by: Peter Zijlstra (Intel) 
Cc: Alexander Shishkin 
Cc: Arnaldo Carvalho de Melo 
Cc: Greg Kroah-Hartman 
Cc: Linus Torvalds 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Link: https://lkml.kernel.org/r/20190512155518.21468-7-jo...@kernel.org
Signed-off-by: Ingo Molnar 
---
 arch/x86/events/core.c   |  8 
 arch/x86/events/intel/core.c | 25 -
 arch/x86/events/perf_event.h |  1 -
 3 files changed, 20 insertions(+), 14 deletions(-)

diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index b831091d4c10..dd0996ba75c3 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -1821,14 +1821,6 @@ static int __init init_hw_perf_events(void)
 
x86_pmu_format_group.attrs = x86_pmu.format_attrs;
 
-   if (x86_pmu.caps_attrs) {
-   struct attribute **tmp;
-
-   tmp = merge_attr(x86_pmu_caps_group.attrs, x86_pmu.caps_attrs);
-   if (!WARN_ON(!tmp))
-   x86_pmu_caps_group.attrs = tmp;
-   }
-
if (!x86_pmu.events_sysfs_show)
x86_pmu_events_group.attrs = _attrs;
 
diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index 600e87055ba9..d4002e71a0b8 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -4411,6 +4411,12 @@ pebs_is_visible(struct kobject *kobj, struct attribute 
*attr, int i)
return x86_pmu.pebs ? attr->mode : 0;
 }
 
+static umode_t
+lbr_is_visible(struct kobject *kobj, struct attribute *attr, int i)
+{
+   return x86_pmu.lbr_nr ? attr->mode : 0;
+}
+
 static struct attribute_group group_events_td  = {
.name = "events",
 };
@@ -4425,10 +4431,23 @@ static struct attribute_group group_events_tsx = {
.is_visible = tsx_is_visible,
 };
 
+static struct attribute_group group_caps_gen = {
+   .name  = "caps",
+   .attrs = intel_pmu_caps_attrs,
+};
+
+static struct attribute_group group_caps_lbr = {
+   .name   = "caps",
+   .attrs  = lbr_attrs,
+   .is_visible = lbr_is_visible,
+};
+
 static const struct attribute_group *attr_update[] = {
_events_td,
_events_mem,
_events_tsx,
+   _caps_gen,
+   _caps_lbr,
NULL,
 };
 
@@ -5055,12 +5074,8 @@ __init int intel_pmu_init(void)
x86_pmu.lbr_nr = 0;
}
 
-   x86_pmu.caps_attrs = intel_pmu_caps_attrs;
-
-   if (x86_pmu.lbr_nr) {
-   x86_pmu.caps_attrs = merge_attr(x86_pmu.caps_attrs, lbr_attrs);
+   if (x86_pmu.lbr_nr)
pr_cont("%d-deep LBR, ", x86_pmu.lbr_nr);
-   }
 
/*
 * Access extra MSR may cause #GP under certain circumstances.
diff --git a/arch/x86/events/perf_event.h b/arch/x86/events/perf_event.h
index 629b313d8b8b..1da9b6f0b279 100644
--- a/arch/x86/events/perf_event.h
+++ b/arch/x86/events/perf_event.h
@@ -631,7 +631,6 @@ struct x86_pmu {
int attr_rdpmc_broken;
int attr_rdpmc;
struct attribute **format_attrs;
-   struct attribute **caps_attrs;
 
ssize_t (*events_sysfs_show)(char *page, u64 config);
const struct attribute_group **attr_update;


[tip:perf/core] perf/x86: Use update attribute groups for extra format

2019-06-03 Thread tip-bot for Jiri Olsa
Commit-ID:  3ea40ac77261530b2c96734b99c0c9f1dc1d729d
Gitweb: https://git.kernel.org/tip/3ea40ac77261530b2c96734b99c0c9f1dc1d729d
Author: Jiri Olsa 
AuthorDate: Sun, 12 May 2019 17:55:16 +0200
Committer:  Ingo Molnar 
CommitDate: Mon, 3 Jun 2019 11:58:25 +0200

perf/x86: Use update attribute groups for extra format

Using the new pmu::update_attrs attribute group for
extra "format" directory.

Signed-off-by: Jiri Olsa 
Signed-off-by: Peter Zijlstra (Intel) 
Cc: Alexander Shishkin 
Cc: Arnaldo Carvalho de Melo 
Cc: Greg Kroah-Hartman 
Cc: Linus Torvalds 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Link: https://lkml.kernel.org/r/20190512155518.21468-8-jo...@kernel.org
Signed-off-by: Ingo Molnar 
---
 arch/x86/events/intel/core.c | 18 +-
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index d4002e71a0b8..de4779f44737 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -4417,6 +4417,12 @@ lbr_is_visible(struct kobject *kobj, struct attribute 
*attr, int i)
return x86_pmu.lbr_nr ? attr->mode : 0;
 }
 
+static umode_t
+exra_is_visible(struct kobject *kobj, struct attribute *attr, int i)
+{
+   return x86_pmu.version >= 2 ? attr->mode : 0;
+}
+
 static struct attribute_group group_events_td  = {
.name = "events",
 };
@@ -4442,12 +4448,18 @@ static struct attribute_group group_caps_lbr = {
.is_visible = lbr_is_visible,
 };
 
+static struct attribute_group group_format_extra = {
+   .name   = "format",
+   .is_visible = exra_is_visible,
+};
+
 static const struct attribute_group *attr_update[] = {
_events_td,
_events_mem,
_events_tsx,
_caps_gen,
_caps_lbr,
+   _format_extra,
NULL,
 };
 
@@ -5016,15 +5028,11 @@ __init int intel_pmu_init(void)
 
snprintf(pmu_name_str, sizeof(pmu_name_str), "%s", name);
 
-   if (version >= 2 && extra_attr) {
-   x86_pmu.format_attrs = merge_attr(intel_arch3_formats_attr,
- extra_attr);
-   WARN_ON(!x86_pmu.format_attrs);
-   }
 
group_events_td.attrs  = td_attr;
group_events_mem.attrs = mem_attr;
group_events_tsx.attrs = tsx_attr;
+   group_format_extra.attrs = extra_attr;
 
x86_pmu.attr_update = attr_update;
 


[tip:perf/core] perf/x86: Add is_visible attribute_group callback for base events

2019-06-03 Thread tip-bot for Jiri Olsa
Commit-ID:  3d5672735b2348f5b13679a27f90c0847d22125d
Gitweb: https://git.kernel.org/tip/3d5672735b2348f5b13679a27f90c0847d22125d
Author: Jiri Olsa 
AuthorDate: Sun, 12 May 2019 17:55:14 +0200
Committer:  Ingo Molnar 
CommitDate: Mon, 3 Jun 2019 11:58:23 +0200

perf/x86: Add is_visible attribute_group callback for base events

We dont need to pre-filter out unsupported base events,
we can just use its group's is_visible function to do this.

Signed-off-by: Jiri Olsa 
Signed-off-by: Peter Zijlstra (Intel) 
Cc: Alexander Shishkin 
Cc: Arnaldo Carvalho de Melo 
Cc: Greg Kroah-Hartman 
Cc: Linus Torvalds 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Link: https://lkml.kernel.org/r/20190512155518.21468-6-jo...@kernel.org
Signed-off-by: Ingo Molnar 
---
 arch/x86/events/core.c | 53 ++
 1 file changed, 15 insertions(+), 38 deletions(-)

diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index db815ceb5017..b831091d4c10 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -1618,42 +1618,6 @@ static struct attribute_group x86_pmu_format_group 
__ro_after_init = {
.attrs = NULL,
 };
 
-/*
- * Remove all undefined events (x86_pmu.event_map(id) == 0)
- * out of events_attr attributes.
- */
-static void __init filter_events(struct attribute **attrs)
-{
-   struct device_attribute *d;
-   struct perf_pmu_events_attr *pmu_attr;
-   int offset = 0;
-   int i, j;
-
-   for (i = 0; attrs[i]; i++) {
-   d = (struct device_attribute *)attrs[i];
-   pmu_attr = container_of(d, struct perf_pmu_events_attr, attr);
-   /* str trumps id */
-   if (pmu_attr->event_str)
-   continue;
-   if (x86_pmu.event_map(i + offset))
-   continue;
-
-   for (j = i; attrs[j]; j++)
-   attrs[j] = attrs[j + 1];
-
-   /* Check the shifted attr. */
-   i--;
-
-   /*
-* event_map() is index based, the attrs array is organized
-* by increasing event index. If we shift the events, then
-* we need to compensate for the event_map(), otherwise
-* we are looking up the wrong event in the map
-*/
-   offset++;
-   }
-}
-
 /* Merge two pointer arrays */
 __init struct attribute **merge_attr(struct attribute **a, struct attribute 
**b)
 {
@@ -1744,9 +1708,24 @@ static struct attribute *events_attr[] = {
NULL,
 };
 
+/*
+ * Remove all undefined events (x86_pmu.event_map(id) == 0)
+ * out of events_attr attributes.
+ */
+static umode_t
+is_visible(struct kobject *kobj, struct attribute *attr, int idx)
+{
+   struct perf_pmu_events_attr *pmu_attr;
+
+   pmu_attr = container_of(attr, struct perf_pmu_events_attr, attr.attr);
+   /* str trumps id */
+   return pmu_attr->event_str || x86_pmu.event_map(idx) ? attr->mode : 0;
+}
+
 static struct attribute_group x86_pmu_events_group __ro_after_init = {
.name = "events",
.attrs = events_attr,
+   .is_visible = is_visible,
 };
 
 ssize_t x86_event_sysfs_show(char *page, u64 config, u64 event)
@@ -1852,8 +1831,6 @@ static int __init init_hw_perf_events(void)
 
if (!x86_pmu.events_sysfs_show)
x86_pmu_events_group.attrs = _attrs;
-   else
-   filter_events(x86_pmu_events_group.attrs);
 
if (x86_pmu.attrs) {
struct attribute **tmp;


[tip:perf/core] perf/x86: Use the new pmu::update_attrs attribute group

2019-06-03 Thread tip-bot for Jiri Olsa
Commit-ID:  baa0c83363c7aafb04734acf4ac252be8e13bd88
Gitweb: https://git.kernel.org/tip/baa0c83363c7aafb04734acf4ac252be8e13bd88
Author: Jiri Olsa 
AuthorDate: Sun, 12 May 2019 17:55:13 +0200
Committer:  Ingo Molnar 
CommitDate: Mon, 3 Jun 2019 11:58:23 +0200

perf/x86: Use the new pmu::update_attrs attribute group

Using the new pmu::update_attrs attribute group to
create detected events for x86_pmu.

Moving the topdown/memory/tsx attributes to separate
attribute groups with specific is_visible functions.

Signed-off-by: Jiri Olsa 
Signed-off-by: Peter Zijlstra (Intel) 
Cc: Alexander Shishkin 
Cc: Arnaldo Carvalho de Melo 
Cc: Greg Kroah-Hartman 
Cc: Linus Torvalds 
Cc: Namhyung Kim 
Cc: Peter Zijlstra 
Cc: Thomas Gleixner 
Link: https://lkml.kernel.org/r/20190512155518.21468-5-jo...@kernel.org
Signed-off-by: Ingo Molnar 
---
 arch/x86/events/core.c   | 10 ++
 arch/x86/events/intel/core.c | 86 +---
 arch/x86/events/perf_event.h |  2 +-
 3 files changed, 52 insertions(+), 46 deletions(-)

diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index 0c5a2c783374..db815ceb5017 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -1855,14 +1855,6 @@ static int __init init_hw_perf_events(void)
else
filter_events(x86_pmu_events_group.attrs);
 
-   if (x86_pmu.cpu_events) {
-   struct attribute **tmp;
-
-   tmp = merge_attr(x86_pmu_events_group.attrs, 
x86_pmu.cpu_events);
-   if (!WARN_ON(!tmp))
-   x86_pmu_events_group.attrs = tmp;
-   }
-
if (x86_pmu.attrs) {
struct attribute **tmp;
 
@@ -1871,6 +1863,8 @@ static int __init init_hw_perf_events(void)
x86_pmu_attr_group.attrs = tmp;
}
 
+   pmu.attr_update = x86_pmu.attr_update;
+
pr_info("... version:%d\n", x86_pmu.version);
pr_info("... bit width:  %d\n", x86_pmu.cntval_bits);
pr_info("... generic registers:  %d\n", x86_pmu.num_counters);
diff --git a/arch/x86/events/intel/core.c b/arch/x86/events/intel/core.c
index a5436cee20b1..600e87055ba9 100644
--- a/arch/x86/events/intel/core.c
+++ b/arch/x86/events/intel/core.c
@@ -4274,13 +4274,6 @@ static struct attribute *icl_tsx_events_attrs[] = {
NULL,
 };
 
-static __init struct attribute **get_icl_events_attrs(void)
-{
-   return boot_cpu_has(X86_FEATURE_RTM) ?
-   merge_attr(icl_events_attrs, icl_tsx_events_attrs) :
-   icl_events_attrs;
-}
-
 static ssize_t freeze_on_smi_show(struct device *cdev,
  struct device_attribute *attr,
  char *buf)
@@ -4406,32 +4399,47 @@ static struct attribute *intel_pmu_attrs[] = {
NULL,
 };
 
-static __init struct attribute **
-get_events_attrs(struct attribute **base,
-struct attribute **mem,
-struct attribute **tsx)
+static umode_t
+tsx_is_visible(struct kobject *kobj, struct attribute *attr, int i)
 {
-   struct attribute **attrs = base;
-   struct attribute **old;
+   return boot_cpu_has(X86_FEATURE_RTM) ? attr->mode : 0;
+}
 
-   if (mem && x86_pmu.pebs)
-   attrs = merge_attr(attrs, mem);
+static umode_t
+pebs_is_visible(struct kobject *kobj, struct attribute *attr, int i)
+{
+   return x86_pmu.pebs ? attr->mode : 0;
+}
 
-   if (tsx && boot_cpu_has(X86_FEATURE_RTM)) {
-   old = attrs;
-   attrs = merge_attr(attrs, tsx);
-   if (old != base)
-   kfree(old);
-   }
+static struct attribute_group group_events_td  = {
+   .name = "events",
+};
 
-   return attrs;
-}
+static struct attribute_group group_events_mem = {
+   .name   = "events",
+   .is_visible = pebs_is_visible,
+};
+
+static struct attribute_group group_events_tsx = {
+   .name   = "events",
+   .is_visible = tsx_is_visible,
+};
+
+static const struct attribute_group *attr_update[] = {
+   _events_td,
+   _events_mem,
+   _events_tsx,
+   NULL,
+};
+
+static struct attribute *empty_attrs;
 
 __init int intel_pmu_init(void)
 {
-   struct attribute **extra_attr = NULL;
-   struct attribute **mem_attr = NULL;
-   struct attribute **tsx_attr = NULL;
+   struct attribute **extra_attr = _attrs;
+   struct attribute **td_attr= _attrs;
+   struct attribute **mem_attr   = _attrs;
+   struct attribute **tsx_attr   = _attrs;
struct attribute **to_free = NULL;
union cpuid10_edx edx;
union cpuid10_eax eax;
@@ -4596,7 +4604,7 @@ __init int intel_pmu_init(void)
x86_pmu.pebs_constraints = intel_slm_pebs_event_constraints;
x86_pmu.extra_regs = intel_slm_extra_regs;
x86_pmu.flags |= PMU_FL_HAS_RSP_1;
-   x86_pmu.cpu_events = slm_events_attrs;
+

  1   2   3   4   5   6   7   8   9   10   >