mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Arnaldo Carvalho de Melo <acme@kernel.org>
To: Adrian Hunter <adrian.hunter@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
	linux-kernel@vger.kernel.org, David Ahern <dsahern@gmail.com>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@gmail.com>,
	Stephane Eranian <eranian@google.com>
Subject: Re: [PATCH 04/44] perf tools: Add support for AUX area recording
Date: Mon, 20 Apr 2015 20:17:51 -0300	[thread overview]
Message-ID: <20150420231751.GX11111@kernel.org> (raw)
In-Reply-To: <1428594864-29309-5-git-send-email-adrian.hunter@intel.com>

Em Thu, Apr 09, 2015 at 06:53:44PM +0300, Adrian Hunter escreveu:
> Add support for reading from the AUX area
> tracing mmap and synthesizing AUX area
> tracing events.
> 
> This patch introduces an abstraction for recording
> AUX area data.  Recording is initialized
> by auxtrace_record__init() which is a weak function
> to be implemented by the architecture to provide
> recording callbacks.  Recording is mainly handled
> by auxtrace_mmap__read() and
> perf_event__synthesize_auxtrace() but there are
> callbacks for miscellaneous needs including
> validating and processing user options, populating
> private data in auxtrace_info_event, and freeing
> the structure when finished.
> 
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> Acked-by: Jiri Olsa <jolsa@kernel.org>
> ---
>  tools/perf/perf.h          |   2 +
>  tools/perf/util/auxtrace.c | 176 +++++++++++++++++++++++++++++++++++++++++++++
>  tools/perf/util/auxtrace.h |  56 ++++++++++++++-
>  tools/perf/util/record.c   |  11 ++-
>  4 files changed, 243 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/perf/perf.h b/tools/perf/perf.h
> index e14bb63..5042093 100644
> --- a/tools/perf/perf.h
> +++ b/tools/perf/perf.h
> @@ -54,8 +54,10 @@ struct record_opts {
>  	bool	     period;
>  	bool	     sample_intr_regs;
>  	bool	     running_time;
> +	bool	     full_auxtrace;
>  	unsigned int freq;
>  	unsigned int mmap_pages;
> +	unsigned int auxtrace_mmap_pages;
>  	unsigned int user_freq;
>  	u64          branch_stack;
>  	u64	     default_interval;
> diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
> index dedb646..2cafea2 100644
> --- a/tools/perf/util/auxtrace.c
> +++ b/tools/perf/util/auxtrace.c
> @@ -23,6 +23,10 @@
>  #include <linux/bitops.h>
>  #include <linux/log2.h>
>  
> +#include <stdlib.h>
> +#include <string.h>
> +#include <errno.h>
> +
>  #include "../perf.h"
>  #include "util.h"
>  #include "evlist.h"
> @@ -31,6 +35,9 @@
>  #include "asm/bug.h"
>  #include "auxtrace.h"
>  
> +#include "event.h"
> +#include "debug.h"
> +
>  int auxtrace_mmap__mmap(struct auxtrace_mmap *mm,
>  			struct auxtrace_mmap_params *mp,
>  			void *userpg, int fd)
> @@ -111,3 +118,172 @@ void auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp,
>  		mp->tid = evlist->threads->map[idx];
>  	}
>  }
> +
> +size_t auxtrace_record__info_priv_size(struct auxtrace_record *itr)
> +{
> +	if (itr)
> +		return itr->info_priv_size(itr);
> +	return 0;
> +}


	return itr ? itr->info_priv_size(itr) : 0;

Is more compact, applying anyway... There is one other comment below,
but it is as well cosmetic.

- Arnaldo

> +
> +static int auxtrace_not_supported(void)
> +{
> +	pr_err("AUX area tracing is not supported on this architecture\n");
> +	return -EINVAL;
> +}
> +
> +int auxtrace_record__info_fill(struct auxtrace_record *itr,
> +			       struct perf_session *session,
> +			       struct auxtrace_info_event *auxtrace_info,
> +			       size_t priv_size)
> +{
> +	if (itr)
> +		return itr->info_fill(itr, session, auxtrace_info, priv_size);
> +	return auxtrace_not_supported();
> +}
> +
> +void auxtrace_record__free(struct auxtrace_record *itr)
> +{
> +	if (itr)
> +		itr->free(itr);
> +}
> +
> +int auxtrace_record__options(struct auxtrace_record *itr,
> +			     struct perf_evlist *evlist,
> +			     struct record_opts *opts)
> +{
> +	if (itr)
> +		return itr->recording_options(itr, evlist, opts);
> +	return 0;
> +}
> +
> +u64 auxtrace_record__reference(struct auxtrace_record *itr)
> +{
> +	if (itr)
> +		return itr->reference(itr);
> +	return 0;
> +}
> +
> +struct auxtrace_record *__weak
> +auxtrace_record__init(struct perf_evlist *evlist __maybe_unused, int *err)
> +{
> +	*err = 0;
> +	return NULL;
> +}
> +
> +int perf_event__synthesize_auxtrace_info(struct auxtrace_record *itr,
> +					 struct perf_tool *tool,
> +					 struct perf_session *session,
> +					 perf_event__handler_t process)
> +{
> +	union perf_event *ev;
> +	size_t priv_size;
> +	int err;
> +
> +	pr_debug2("Synthesizing auxtrace information\n");
> +	priv_size = auxtrace_record__info_priv_size(itr);
> +	ev = zalloc(sizeof(struct auxtrace_info_event) + priv_size);
> +	if (!ev)
> +		return -ENOMEM;
> +
> +	ev->auxtrace_info.header.type = PERF_RECORD_AUXTRACE_INFO;
> +	ev->auxtrace_info.header.size = sizeof(struct auxtrace_info_event) +
> +					priv_size;
> +	err = auxtrace_record__info_fill(itr, session, &ev->auxtrace_info,
> +					 priv_size);
> +	if (err)
> +		goto out_free;
> +
> +	err = process(tool, ev, NULL, NULL);
> +out_free:

	if (!err)
		err = process(tool, ev, NULL, NULL);

> +	free(ev);
> +	return err;


I.e. I love gotos, but this one isn't needed :-)

> +}
> +
> +int auxtrace_mmap__read(struct auxtrace_mmap *mm, struct auxtrace_record *itr,
> +			struct perf_tool *tool, process_auxtrace_t fn)
> +{
> +	u64 head = auxtrace_mmap__read_head(mm);
> +	u64 old = mm->prev, offset, ref;
> +	unsigned char *data = mm->base;
> +	size_t size, head_off, old_off, len1, len2, padding;
> +	union perf_event ev;
> +	void *data1, *data2;
> +
> +	if (old == head)
> +		return 0;
> +
> +	pr_debug3("auxtrace idx %d old %#"PRIx64" head %#"PRIx64" diff %#"PRIx64"\n",
> +		  mm->idx, old, head, head - old);
> +
> +	if (mm->mask) {
> +		head_off = head & mm->mask;
> +		old_off = old & mm->mask;
> +	} else {
> +		head_off = head % mm->len;
> +		old_off = old % mm->len;
> +	}
> +
> +	if (head_off > old_off)
> +		size = head_off - old_off;
> +	else
> +		size = mm->len - (old_off - head_off);
> +
> +	ref = auxtrace_record__reference(itr);
> +
> +	if (head > old || size <= head || mm->mask) {
> +		offset = head - size;
> +	} else {
> +		/*
> +		 * When the buffer size is not a power of 2, 'head' wraps at the
> +		 * highest multiple of the buffer size, so we have to subtract
> +		 * the remainder here.
> +		 */
> +		u64 rem = (0ULL - mm->len) % mm->len;
> +
> +		offset = head - size - rem;
> +	}
> +
> +	if (size > head_off) {
> +		len1 = size - head_off;
> +		data1 = &data[mm->len - len1];
> +		len2 = head_off;
> +		data2 = &data[0];
> +	} else {
> +		len1 = size;
> +		data1 = &data[head_off - len1];
> +		len2 = 0;
> +		data2 = NULL;
> +	}
> +
> +	/* padding must be written by fn() e.g. record__process_auxtrace() */
> +	padding = size & 7;
> +	if (padding)
> +		padding = 8 - padding;
> +
> +	memset(&ev, 0, sizeof(ev));
> +	ev.auxtrace.header.type = PERF_RECORD_AUXTRACE;
> +	ev.auxtrace.header.size = sizeof(ev.auxtrace);
> +	ev.auxtrace.size = size + padding;
> +	ev.auxtrace.offset = offset;
> +	ev.auxtrace.reference = ref;
> +	ev.auxtrace.idx = mm->idx;
> +	ev.auxtrace.tid = mm->tid;
> +	ev.auxtrace.cpu = mm->cpu;
> +
> +	if (fn(tool, &ev, data1, len1, data2, len2))
> +		return -1;
> +
> +	mm->prev = head;
> +
> +	auxtrace_mmap__write_tail(mm, head);
> +	if (itr->read_finish) {
> +		int err;
> +
> +		err = itr->read_finish(itr, mm->idx);
> +		if (err < 0)
> +			return err;
> +	}
> +
> +	return 1;
> +}
> diff --git a/tools/perf/util/auxtrace.h b/tools/perf/util/auxtrace.h
> index 2071b36..7ab4850 100644
> --- a/tools/perf/util/auxtrace.h
> +++ b/tools/perf/util/auxtrace.h
> @@ -18,13 +18,18 @@
>  
>  #include <sys/types.h>
>  #include <stdbool.h>
> -
> +#include <stddef.h>
>  #include <linux/perf_event.h>
>  #include <linux/types.h>
>  
>  #include "../perf.h"
>  
> +union perf_event;
> +struct perf_session;
>  struct perf_evlist;
> +struct perf_tool;
> +struct record_opts;
> +struct auxtrace_info_event;
>  
>  /**
>   * struct auxtrace_mmap - records an mmap of the auxtrace buffer.
> @@ -70,6 +75,29 @@ struct auxtrace_mmap_params {
>  	int		cpu;
>  };
>  
> +/**
> + * struct auxtrace_record - callbacks for recording AUX area data.
> + * @recording_options: validate and process recording options
> + * @info_priv_size: return the size of the private data in auxtrace_info_event
> + * @info_fill: fill-in the private data in auxtrace_info_event
> + * @free: free this auxtrace record structure
> + * @reference: provide a 64-bit reference number for auxtrace_event
> + * @read_finish: called after reading from an auxtrace mmap
> + */
> +struct auxtrace_record {
> +	int (*recording_options)(struct auxtrace_record *itr,
> +				 struct perf_evlist *evlist,
> +				 struct record_opts *opts);
> +	size_t (*info_priv_size)(struct auxtrace_record *itr);
> +	int (*info_fill)(struct auxtrace_record *itr,
> +			 struct perf_session *session,
> +			 struct auxtrace_info_event *auxtrace_info,
> +			 size_t priv_size);
> +	void (*free)(struct auxtrace_record *itr);
> +	u64 (*reference)(struct auxtrace_record *itr);
> +	int (*read_finish)(struct auxtrace_record *itr, int idx);
> +};
> +
>  static inline u64 auxtrace_mmap__read_head(struct auxtrace_mmap *mm)
>  {
>  	struct perf_event_mmap_page *pc = mm->userpg;
> @@ -114,4 +142,30 @@ void auxtrace_mmap_params__set_idx(struct auxtrace_mmap_params *mp,
>  				   struct perf_evlist *evlist, int idx,
>  				   bool per_cpu);
>  
> +typedef int (*process_auxtrace_t)(struct perf_tool *tool,
> +				  union perf_event *event, void *data1,
> +				  size_t len1, void *data2, size_t len2);
> +
> +int auxtrace_mmap__read(struct auxtrace_mmap *mm, struct auxtrace_record *itr,
> +			struct perf_tool *tool, process_auxtrace_t fn);
> +
> +struct auxtrace_record *auxtrace_record__init(struct perf_evlist *evlist,
> +					      int *err);
> +
> +int auxtrace_record__options(struct auxtrace_record *itr,
> +			     struct perf_evlist *evlist,
> +			     struct record_opts *opts);
> +size_t auxtrace_record__info_priv_size(struct auxtrace_record *itr);
> +int auxtrace_record__info_fill(struct auxtrace_record *itr,
> +			       struct perf_session *session,
> +			       struct auxtrace_info_event *auxtrace_info,
> +			       size_t priv_size);
> +void auxtrace_record__free(struct auxtrace_record *itr);
> +u64 auxtrace_record__reference(struct auxtrace_record *itr);
> +
> +int perf_event__synthesize_auxtrace_info(struct auxtrace_record *itr,
> +					 struct perf_tool *tool,
> +					 struct perf_session *session,
> +					 perf_event__handler_t process);
> +
>  #endif
> diff --git a/tools/perf/util/record.c b/tools/perf/util/record.c
> index 8acd0df..0ccfa49 100644
> --- a/tools/perf/util/record.c
> +++ b/tools/perf/util/record.c
> @@ -119,7 +119,16 @@ void perf_evlist__config(struct perf_evlist *evlist, struct record_opts *opts)
>  			evsel->attr.comm_exec = 1;
>  	}
>  
> -	if (evlist->nr_entries > 1) {
> +	if (opts->full_auxtrace) {
> +		/*
> +		 * Need to be able to synthesize and parse selected events with
> +		 * arbitrary sample types, which requires always being able to
> +		 * match the id.
> +		 */
> +		use_sample_identifier = perf_can_sample_identifier();
> +		evlist__for_each(evlist, evsel)
> +			perf_evsel__set_sample_id(evsel, use_sample_identifier);
> +	} else if (evlist->nr_entries > 1) {
>  		struct perf_evsel *first = perf_evlist__first(evlist);
>  
>  		evlist__for_each(evlist, evsel) {
> -- 
> 1.9.1

  reply	other threads:[~2015-04-20 23:18 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-09 15:53 [PATCH 00/44] perf tools: Introduce an abstraction for AUX Area and Instruction Tracing Adrian Hunter
2015-04-09 15:53 ` [PATCH 01/44] perf header: Add AUX area tracing feature Adrian Hunter
2015-05-06  2:58   ` [tip:perf/core] " tip-bot for Adrian Hunter
2015-04-09 15:53 ` [PATCH 02/44] perf evlist: Add support for mmapping an AUX area buffer Adrian Hunter
2015-05-06  2:58   ` [tip:perf/core] " tip-bot for Adrian Hunter
2015-04-09 15:53 ` [PATCH 03/44] perf tools: Add user events for AUX area tracing Adrian Hunter
2015-04-20 23:06   ` Arnaldo Carvalho de Melo
2015-04-20 23:10     ` Arnaldo Carvalho de Melo
2015-04-21  9:23     ` Adrian Hunter
2015-05-06  2:59   ` [tip:perf/core] " tip-bot for Adrian Hunter
2015-04-09 15:53 ` [PATCH 04/44] perf tools: Add support for AUX area recording Adrian Hunter
2015-04-20 23:17   ` Arnaldo Carvalho de Melo [this message]
2015-05-06  2:59   ` [tip:perf/core] perf auxtrace: " tip-bot for Adrian Hunter
2015-04-09 15:53 ` [PATCH 05/44] perf record: Add basic AUX area tracing support Adrian Hunter
2015-05-06  2:59   ` [tip:perf/core] " tip-bot for Adrian Hunter
2015-04-09 15:53 ` [PATCH 06/44] perf record: Extend -m option for AUX area tracing mmap pages Adrian Hunter
2015-05-06  2:59   ` [tip:perf/core] " tip-bot for Adrian Hunter
2015-04-09 15:53 ` [PATCH 07/44] perf tools: Add a user event for AUX area tracing errors Adrian Hunter
2015-05-06  3:00   ` [tip:perf/core] " tip-bot for Adrian Hunter
2015-04-09 15:53 ` [PATCH 08/44] perf session: Add hooks to allow transparent decoding of AUX area tracing data Adrian Hunter
2015-04-21 14:41   ` Arnaldo Carvalho de Melo
2015-04-21 14:46     ` Arnaldo Carvalho de Melo
2015-05-06  3:00   ` [tip:perf/core] " tip-bot for Adrian Hunter
2015-04-09 15:53 ` [PATCH 09/44] perf session: Add instruction tracing options Adrian Hunter
2015-04-21 14:50   ` Arnaldo Carvalho de Melo
2015-04-22  6:23     ` Adrian Hunter
2015-04-23 14:08       ` Arnaldo Carvalho de Melo
2015-05-06  3:00   ` [tip:perf/core] " tip-bot for Adrian Hunter
2015-04-09 15:53 ` [PATCH 10/44] perf auxtrace: Add helpers for AUX area tracing errors Adrian Hunter
2015-05-06  3:01   ` [tip:perf/core] " tip-bot for Adrian Hunter
2015-04-09 15:53 ` [PATCH 11/44] perf auxtrace: Add helpers for queuing AUX area tracing data Adrian Hunter
2015-04-21  9:21   ` [PATCH V2 " Adrian Hunter
2015-05-06  3:01     ` [tip:perf/core] " tip-bot for Adrian Hunter
2015-04-09 15:53 ` [PATCH 12/44] perf auxtrace: Add a heap for sorting AUX area tracing queues Adrian Hunter
2015-04-21 15:01   ` Arnaldo Carvalho de Melo
2015-05-06  3:01   ` [tip:perf/core] " tip-bot for Adrian Hunter
2015-04-09 15:53 ` [PATCH 13/44] perf auxtrace: Add processing for AUX area tracing events Adrian Hunter
2015-05-06  3:01   ` [tip:perf/core] " tip-bot for Adrian Hunter
2015-04-09 15:53 ` [PATCH 14/44] perf auxtrace: Add a hashtable for caching Adrian Hunter
2015-05-06  3:02   ` [tip:perf/core] " tip-bot for Adrian Hunter
2015-04-09 15:53 ` [PATCH 15/44] perf tools: Add member to struct dso for an instruction cache Adrian Hunter
2015-05-06  3:02   ` [tip:perf/core] " tip-bot for Adrian Hunter
2015-04-09 15:53 ` [PATCH 16/44] perf script: Add Instruction Tracing support Adrian Hunter
2015-05-06  3:02   ` [tip:perf/core] " tip-bot for Adrian Hunter
2015-04-09 15:53 ` [PATCH 17/44] perf script: Always allow fields 'addr' and 'cpu' for auxtrace Adrian Hunter
2015-04-09 15:53 ` [PATCH 18/44] perf report: Add Instruction Tracing support Adrian Hunter
2015-04-23 14:16   ` Arnaldo Carvalho de Melo
2015-04-09 15:53 ` [PATCH 19/44] perf inject: Re-pipe AUX area tracing events Adrian Hunter
2015-04-21  9:21   ` [PATCH V2 " Adrian Hunter
2015-05-06  3:03     ` [tip:perf/core] " tip-bot for Adrian Hunter
2015-04-09 15:54 ` [PATCH 20/44] perf inject: Add Instruction Tracing support Adrian Hunter
2015-05-06  3:03   ` [tip:perf/core] " tip-bot for Adrian Hunter
2015-04-09 15:54 ` [PATCH 21/44] perf tools: Add AUX area tracing index Adrian Hunter
2015-04-09 15:54 ` [PATCH 22/44] perf tools: Hit all build ids when AUX area tracing Adrian Hunter
2015-04-09 15:54 ` [PATCH 23/44] perf tools: Add build option NO_AUXTRACE to exclude " Adrian Hunter
2015-04-21  9:21   ` [PATCH V2 " Adrian Hunter
2015-04-09 15:54 ` [PATCH 24/44] perf auxtrace: Add option to synthesize events for transactions Adrian Hunter
2015-04-09 15:54 ` [PATCH 25/44] perf script: Add field option 'flags' to print sample flags Adrian Hunter
2015-05-06  3:03   ` [tip:perf/core] " tip-bot for Adrian Hunter
2015-04-09 15:54 ` [PATCH 26/44] perf tools: Add aux_watermark member of struct perf_event_attr Adrian Hunter
2015-05-06  3:03   ` [tip:perf/core] " tip-bot for Adrian Hunter
2015-04-09 15:54 ` [PATCH 27/44] perf tools: Add support for PERF_RECORD_AUX Adrian Hunter
2015-04-09 15:54 ` [PATCH 28/44] perf tools: Add support for PERF_RECORD_ITRACE_START Adrian Hunter
2015-04-09 15:54 ` [PATCH 29/44] perf tools: Add AUX area tracing Snapshot Mode Adrian Hunter
2015-04-09 15:54 ` [PATCH 30/44] perf record: Add AUX area tracing Snapshot Mode support Adrian Hunter
2015-04-09 15:54 ` [PATCH 31/44] perf auxtrace: Add Intel PT as an AUX area tracing type Adrian Hunter
2015-04-09 15:54 ` [PATCH 32/44] perf tools: Add Intel PT packet decoder Adrian Hunter
2015-04-09 15:54 ` [PATCH 33/44] perf tools: Add Intel PT instruction decoder Adrian Hunter
2015-04-09 15:54 ` [PATCH 34/44] perf tools: Add Intel PT log Adrian Hunter
2015-04-09 15:54 ` [PATCH 35/44] perf tools: Add Intel PT decoder Adrian Hunter
2015-04-09 15:54 ` [PATCH 36/44] perf tools: Add Intel PT support Adrian Hunter
2015-04-09 15:54 ` [PATCH 37/44] perf tools: Take Intel PT into use Adrian Hunter
2015-04-09 15:54 ` [PATCH 38/44] perf tools: Allow auxtrace data alignment Adrian Hunter
2015-04-09 15:54 ` [PATCH 39/44] perf tools: Add Intel BTS support Adrian Hunter
2015-04-09 15:54 ` [PATCH 40/44] perf tools: Output sample flags and insn_len from intel_pt Adrian Hunter
2015-04-09 15:54 ` [PATCH 41/44] perf tools: Output sample flags and insn_len from intel_bts Adrian Hunter
2015-04-09 15:54 ` [PATCH 42/44] perf tools: Intel PT to always update thread stack trace number Adrian Hunter
2015-04-09 15:54 ` [PATCH 43/44] perf tools: Intel BTS " Adrian Hunter
2015-04-09 15:54 ` [PATCH 44/44] perf tools: Add example call-graph script Adrian Hunter

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20150420231751.GX11111@kernel.org \
    --to=acme@kernel.org \
    --cc=adrian.hunter@intel.com \
    --cc=dsahern@gmail.com \
    --cc=eranian@google.com \
    --cc=fweisbec@gmail.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=namhyung@gmail.com \
    --cc=peterz@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome