linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv3 00/10] libperf: Add sampling interface (leftover)
@ 2019-10-17 10:59 Jiri Olsa
  2019-10-17 10:59 ` [PATCH 01/10] libperf: Add perf_evlist__for_each_mmap function Jiri Olsa
                   ` (10 more replies)
  0 siblings, 11 replies; 26+ messages in thread
From: Jiri Olsa @ 2019-10-17 10:59 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Kan Liang, Steven Rostedt, Adrian Hunter, Ian Rogers,
	Stephane Eranian, Song Liu, Alexey Budankov, Andi Kleen, lkml,
	Ingo Molnar, Namhyung Kim, Alexander Shishkin, Peter Zijlstra,
	Michael Petlan, Jin Yao

hi,
sending changes for exporting basic sampling interface
in libperf. It's now possible to use following code in
applications via libperf:

--- (example is without error checks for simplicity)

  struct perf_event_attr attr = {
          .type             = PERF_TYPE_TRACEPOINT,
          .sample_period    = 1,
          .wakeup_watermark = 1,
          .disabled         = 1,
  };
  /* ... setup attr */

  cpus = perf_cpu_map__new(NULL);

  evlist = perf_evlist__new();
  evsel  = perf_evsel__new(&attr);
  perf_evlist__add(evlist, evsel);

  perf_evlist__set_maps(evlist, cpus, NULL);

  err = perf_evlist__open(evlist);
  err = perf_evlist__mmap(evlist, 4);

  err = perf_evlist__enable(evlist);

  /* ... monitored area, plus all the other cpus */

  err = perf_evlist__disable(evlist);

  perf_evlist__for_each_mmap(evlist, map) {
          if (perf_mmap__read_init(map) < 0)
                  continue;

          while ((event = perf_mmap__read_event(map)) != NULL) {
                  perf_mmap__consume(map);
          }

          perf_mmap__read_done(map);
  }

  perf_evlist__delete(evlist);
  perf_cpu_map__put(cpus);

--- (end)

Nothing is carved in stone so far, the interface is exported
as is available in perf now and we can change it as we want.

New tests are added in test-evlist.c to do thread and cpu based
sampling.

All the functionality should not change, however there's considerable
mmap code rewrite.

Now we have perf_evlist__mmap_ops called by both perf and libperf
mmaps functions with specific 'struct perf_evlist_mmap_ops'
callbacks:

  - get  - to get mmap object, both libperf and perf use different
           objects, because perf needs to carry more data for aio,
           compression and auxtrace
  - mmap - to actually mmap the object, it's simple mmap for libperf,
           but more work for perf wrt aio, compression and auxtrace
  - idx  - callback to get current IDs, used only in perf for auxtrace
           setup


It would be great if guys could run your usual workloads to see if all
is fine.. so far so good in my tests ;-)


It's also available in here:
  git://git.kernel.org/pub/scm/linux/kernel/git/jolsa/perf.git
  perf/lib

v3 changes:
  - changed mmap0 and mmap_ovw0 to mmap_first and mmap_ovw_first
  - rebased to latest perf/core
  - portion of patches already taken

v2 changes:
  - rebased to latest perf/core
  - portion of patches already taken
  - explained mmap refcnt management in following patch changelog:
    libperf: Centralize map refcnt setting

thanks,
jirka


Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Ian Rogers <irogers@google.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Song Liu <songliubraving@fb.com>
Cc: Alexey Budankov <alexey.budankov@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
---
Jiri Olsa (10):
      libperf: Add perf_evlist__for_each_mmap function
      libperf: Move mmap allocation to perf_evlist__mmap_ops::get
      libperf: Move mask setup to perf_evlist__mmap_ops function
      libperf: Link static tests with libapi.a
      libperf: Add _GNU_SOURCE define to compilation
      libperf: Add tests_mmap_thread test
      libperf: Add tests_mmap_cpus test
      libperf: Keep count of failed tests
      libperf: Do not export perf_evsel__init/perf_evlist__init
      libperf: Add pr_err macro

 tools/perf/lib/Makefile                  |   2 ++
 tools/perf/lib/evlist.c                  |  71 ++++++++++++++++++++++++++++++++++++++---------------
 tools/perf/lib/include/internal/evlist.h |   3 +++
 tools/perf/lib/include/internal/evsel.h  |   1 +
 tools/perf/lib/include/internal/mmap.h   |   5 ++--
 tools/perf/lib/include/internal/tests.h  |  20 ++++++++++++---
 tools/perf/lib/include/perf/core.h       |   1 +
 tools/perf/lib/include/perf/evlist.h     |  10 +++++++-
 tools/perf/lib/include/perf/evsel.h      |   2 --
 tools/perf/lib/internal.h                |   3 +++
 tools/perf/lib/libperf.map               |   3 +--
 tools/perf/lib/mmap.c                    |   6 +++--
 tools/perf/lib/tests/Makefile            |   8 +++---
 tools/perf/lib/tests/test-cpumap.c       |   2 +-
 tools/perf/lib/tests/test-evlist.c       | 218 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 tools/perf/lib/tests/test-evsel.c        |   2 +-
 tools/perf/lib/tests/test-threadmap.c    |   2 +-
 tools/perf/util/evlist.c                 |  29 +++++++++-------------
 18 files changed, 333 insertions(+), 55 deletions(-)

^ permalink raw reply	[flat|nested] 26+ messages in thread

end of thread, other threads:[~2019-10-22  0:05 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-17 10:59 [PATCHv3 00/10] libperf: Add sampling interface (leftover) Jiri Olsa
2019-10-17 10:59 ` [PATCH 01/10] libperf: Add perf_evlist__for_each_mmap function Jiri Olsa
2019-10-21 23:18   ` [tip: perf/core] libperf: Introduce perf_evlist__for_each_mmap() tip-bot2 for Jiri Olsa
2019-10-17 10:59 ` [PATCH 02/10] libperf: Move mmap allocation to perf_evlist__mmap_ops::get Jiri Olsa
2019-10-21 23:18   ` [tip: perf/core] " tip-bot2 for Jiri Olsa
2019-10-17 10:59 ` [PATCH 03/10] libperf: Move mask setup to perf_evlist__mmap_ops function Jiri Olsa
2019-10-21 23:18   ` [tip: perf/core] libperf: Move mask setup to perf_evlist__mmap_ops() tip-bot2 for Jiri Olsa
2019-10-17 10:59 ` [PATCH 04/10] libperf: Link static tests with libapi.a Jiri Olsa
2019-10-21 23:18   ` [tip: perf/core] " tip-bot2 for Jiri Olsa
2019-10-17 10:59 ` [PATCH 05/10] libperf: Add _GNU_SOURCE define to compilation Jiri Olsa
2019-10-18 18:07   ` Arnaldo Carvalho de Melo
2019-10-19 17:37     ` Jiri Olsa
2019-10-17 10:59 ` [PATCH 06/10] libperf: Add tests_mmap_thread test Jiri Olsa
2019-10-21 23:18   ` [tip: perf/core] " tip-bot2 for Jiri Olsa
2019-10-17 10:59 ` [PATCH 07/10] libperf: Add tests_mmap_cpus test Jiri Olsa
2019-10-18 18:14   ` Arnaldo Carvalho de Melo
2019-10-18 18:16     ` Arnaldo Carvalho de Melo
2019-10-19 17:42       ` Jiri Olsa
2019-10-21 23:18   ` [tip: perf/core] " tip-bot2 for Jiri Olsa
2019-10-17 10:59 ` [PATCH 08/10] libperf: Keep count of failed tests Jiri Olsa
2019-10-21 23:18   ` [tip: perf/core] " tip-bot2 for Jiri Olsa
2019-10-17 10:59 ` [PATCH 09/10] libperf: Do not export perf_evsel__init/perf_evlist__init Jiri Olsa
2019-10-21 23:18   ` [tip: perf/core] libperf: Do not export perf_evsel__init()/perf_evlist__init() tip-bot2 for Jiri Olsa
2019-10-17 10:59 ` [PATCH 10/10] libperf: Add pr_err macro Jiri Olsa
2019-10-21 23:18   ` [tip: perf/core] libperf: Add pr_err() macro tip-bot2 for Jiri Olsa
2019-10-18 18:29 ` [PATCHv3 00/10] libperf: Add sampling interface (leftover) Arnaldo Carvalho de Melo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).