mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@redhat.com>
To: acme@redhat.com, a.p.zijlstra@chello.nl, mingo@elte.hu,
	paulus@samba.org, cjashfor@linux.vnet.ibm.com,
	fweisbec@gmail.com
Cc: eranian@google.com, gorcunov@openvz.org, tzanussi@gmail.com,
	mhiramat@redhat.com, robert.richter@amd.com, fche@redhat.com,
	linux-kernel@vger.kernel.org, masami.hiramatsu.pt@hitachi.com,
	drepper@gmail.com, asharma@fb.com,
	benjamin.redelings@nescent.org, Jiri Olsa <jolsa@redhat.com>
Subject: [PATCH 06/19] perf: Add ability to attach user stack dump to sample
Date: Mon, 11 Jun 2012 15:20:01 +0200	[thread overview]
Message-ID: <1339420814-7379-7-git-send-email-jolsa@redhat.com> (raw)
In-Reply-To: <1339420814-7379-1-git-send-email-jolsa@redhat.com>

Introducing sample_stack_user value into the perf_event_attr
struct to define the size of the user stack dump to be attached
to the sample. The dump itself is triggered once the
sample_stack_user is not zero.

Beeing able to dump parts of the user stack, starting from the
stack pointer, will be useful to make a post mortem dwarf CFI
based stack unwinding.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
---
 include/linux/perf_event.h |    5 +++
 kernel/events/core.c       |   66 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+), 0 deletions(-)

diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index 8960968..8db1655 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -278,6 +278,11 @@ struct perf_event_attr {
 	 * See asm/perf_regs.h for details.
 	 */
 	__u64	sample_regs_user;
+
+	/*
+	 * Defines size of the user stack to dump on samples.
+	 */
+	__u64	sample_stack_user;
 };
 
 /*
diff --git a/kernel/events/core.c b/kernel/events/core.c
index e4df59d..c1062a1 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -3765,6 +3765,38 @@ perf_output_sample_regs(struct perf_output_handle *handle,
 	}
 }
 
+static void
+perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
+			  struct pt_regs *regs)
+{
+	/* Case of a kernel thread, nothing to dump */
+	if (!regs) {
+		u64 size = 0;
+		perf_output_put(handle, size);
+	} else {
+		unsigned long sp;
+		unsigned int rem;
+		u64 dyn_size;
+
+		/*
+		 * Static size: we always dump the size
+		 * requested by the user because most of the
+		 * time, the top of the user stack is not
+		 * paged out.
+		 */
+		perf_output_put(handle, dump_size);
+
+		sp = user_stack_pointer(regs);
+		rem = __output_copy_user(handle, (void *) sp, dump_size);
+		dyn_size = dump_size - rem;
+
+		perf_output_skip(handle, rem);
+
+		/* Dynamic size: whole dump - padding. */
+		perf_output_put(handle, dyn_size);
+	}
+}
+
 static struct pt_regs *perf_sample_regs_user(struct pt_regs *regs)
 {
 	if (!user_mode(regs)) {
@@ -4054,6 +4086,11 @@ void perf_output_sample(struct perf_output_handle *handle,
 						mask);
 		}
 	}
+
+	if (event->attr.sample_stack_user)
+		perf_output_sample_ustack(handle,
+					  event->attr.sample_stack_user,
+					  data->regs_user);
 }
 
 void perf_prepare_sample(struct perf_event_header *header,
@@ -4118,6 +4155,31 @@ void perf_prepare_sample(struct perf_event_header *header,
 
 		header->size += size;
 	}
+
+	if (event->attr.sample_stack_user) {
+		/*
+		 * A first field that tells the _static_ size of the
+		 * dump. 0 if there is nothing to dump (ie: we are in
+		 * a kernel thread) otherwise the requested size.
+		 */
+		int size = sizeof(u64);
+
+		if (!data->regs_user)
+			data->regs_user = perf_sample_regs_user(regs);
+
+		/*
+		 * If there is something to dump, add space for the
+		 * dump itself and for the field that tells the
+		 * dynamic size, which is how many have been actually
+		 * dumped.
+		 */
+		if (data->regs_user) {
+			size += event->attr.sample_stack_user;
+			size += sizeof(u64);
+		}
+
+		header->size += size;
+	}
 }
 
 static void perf_event_output(struct perf_event *event,
@@ -6171,6 +6233,10 @@ static int perf_copy_attr(struct perf_event_attr __user *uattr,
 	if (attr->sample_regs_user)
 		ret = perf_reg_validate(attr->sample_regs_user);
 
+	if (attr->sample_stack_user)
+		attr->sample_stack_user = round_up(attr->sample_stack_user,
+						   sizeof(u64));
+
 out:
 	return ret;
 
-- 
1.7.7.6


  parent reply	other threads:[~2012-06-11 13:21 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-11 13:19 [RFCv5 00/19] perf: Add backtrace post dwarf unwind Jiri Olsa
2012-06-11 13:19 ` [PATCH 01/19] perf: Unified API to record selective sets of arch registers Jiri Olsa
2012-06-11 13:19 ` [PATCH 02/19] perf: Add ability to attach user level registers dump to sample Jiri Olsa
2012-06-13 11:16   ` Stephane Eranian
2012-06-13 13:12     ` Jiri Olsa
2012-06-13 13:18       ` Stephane Eranian
2012-06-13 13:23         ` Jiri Olsa
2012-06-13 13:25           ` Stephane Eranian
2012-06-13 13:40         ` Peter Zijlstra
2012-06-13 13:41           ` Stephane Eranian
2012-06-13 13:51             ` Stephane Eranian
2012-06-14  8:36             ` Peter Zijlstra
2012-06-14 10:45               ` Stephane Eranian
2012-06-14 10:50                 ` Peter Zijlstra
2012-06-14 10:56                   ` Peter Zijlstra
2012-06-13 13:37       ` Peter Zijlstra
2012-06-13 13:29   ` Stephane Eranian
2012-06-11 13:19 ` [PATCH 03/19] perf, x86: Add copy_from_user_nmi_nochk for best effort copy Jiri Olsa
2012-06-11 13:19 ` [PATCH 04/19] perf: Factor __output_copy to be usable with specific copy function Jiri Olsa
2012-06-11 13:20 ` [PATCH 05/19] perf: Add perf_output_skip function to skip bytes in sample Jiri Olsa
2012-06-11 13:20 ` Jiri Olsa [this message]
2012-06-11 13:20 ` [PATCH 07/19] perf: Add attribute to filter out callchains Jiri Olsa
2012-06-11 13:20 ` [PATCH 08/19] perf, tool: Remove unsused evsel parameter from machine__resolve_callchain Jiri Olsa
2012-06-20 16:59   ` [tip:perf/core] perf tools: Remove unused " tip-bot for Jiri Olsa
2012-06-11 13:20 ` [PATCH 09/19] perf, tool: Factor DSO symtab types to generic binary types Jiri Olsa
2012-06-11 13:20 ` [PATCH 10/19] perf, tool: Add interface to read DSO image data Jiri Olsa
2012-06-11 13:20 ` [PATCH 11/19] perf, tool: Add '.note' check into search for NOTE section Jiri Olsa
2012-06-11 13:20 ` [PATCH 12/19] perf, tool: Back [vdso] DSO with real data Jiri Olsa
2012-06-29 18:49   ` Arnaldo Carvalho de Melo
2012-06-11 13:20 ` [PATCH 13/19] perf, tool: Add interface to arch registers sets Jiri Olsa
2012-06-11 13:20 ` [PATCH 14/19] perf, tool: Add libunwind dependency for dwarf cfi unwinding Jiri Olsa
2012-06-11 13:20 ` [PATCH 15/19] perf, tool: Support user regs and stack in sample parsing Jiri Olsa
2012-06-11 13:20 ` [PATCH 16/19] perf, tool: Support for dwarf cfi unwinding on post processing Jiri Olsa
2012-06-11 13:20 ` [PATCH 17/19] perf, tool: Support for dwarf mode callchain on perf record Jiri Olsa
2012-06-11 13:20 ` [PATCH 18/19] perf, tool: Add dso data caching Jiri Olsa
2012-06-11 13:20 ` [PATCH 19/19] perf, tool: Add dso data caching tests Jiri Olsa
2012-06-11 21:44 ` [RFCv5 00/19] perf: Add backtrace post dwarf unwind Benjamin Redelings

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=1339420814-7379-7-git-send-email-jolsa@redhat.com \
    --to=jolsa@redhat.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@redhat.com \
    --cc=asharma@fb.com \
    --cc=benjamin.redelings@nescent.org \
    --cc=cjashfor@linux.vnet.ibm.com \
    --cc=drepper@gmail.com \
    --cc=eranian@google.com \
    --cc=fche@redhat.com \
    --cc=fweisbec@gmail.com \
    --cc=gorcunov@openvz.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=mhiramat@redhat.com \
    --cc=mingo@elte.hu \
    --cc=paulus@samba.org \
    --cc=robert.richter@amd.com \
    --cc=tzanussi@gmail.com \
    /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

all inboxes | Powered by JetHome®