mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Robert Richter <robert.richter@amd.com>
To: Ingo Molnar <mingo@elte.hu>
Cc: LKML <linux-kernel@vger.kernel.org>,
	oprofile-list <oprofile-list@lists.sourceforge.net>,
	Robert Richter <robert.richter@amd.com>
Subject: [PATCH 2/9] oprofile: modify op_cpu_buffer_read_entry()
Date: Wed, 7 Jan 2009 23:45:18 +0100	[thread overview]
Message-ID: <1231368325-19246-3-git-send-email-robert.richter@amd.com> (raw)
In-Reply-To: <1231368325-19246-1-git-send-email-robert.richter@amd.com>

This implements the support of samples with attached data.

Signed-off-by: Robert Richter <robert.richter@amd.com>
---
 drivers/oprofile/buffer_sync.c |   23 +++++++++++++----------
 drivers/oprofile/cpu_buffer.c  |   14 +++++++++++---
 drivers/oprofile/cpu_buffer.h  |    2 +-
 3 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
index 21fd249..908202a 100644
--- a/drivers/oprofile/buffer_sync.c
+++ b/drivers/oprofile/buffer_sync.c
@@ -329,9 +329,10 @@ static void add_ibs_begin(int cpu, int code, struct mm_struct *mm)
 	int i, count;
 	unsigned long cookie = 0;
 	off_t offset;
+	struct op_entry entry;
 	struct op_sample *sample;
 
-	sample = op_cpu_buffer_read_entry(cpu);
+	sample = op_cpu_buffer_read_entry(&entry, cpu);
 	if (!sample)
 		return;
 	pc = sample->eip;
@@ -370,7 +371,7 @@ static void add_ibs_begin(int cpu, int code, struct mm_struct *mm)
 		count = IBS_OP_CODE_SIZE;	/*IBS OP is 5 int64s*/
 
 	for (i = 0; i < count; i++) {
-		sample = op_cpu_buffer_read_entry(cpu);
+		sample = op_cpu_buffer_read_entry(&entry, cpu);
 		if (!sample)
 			return;
 		add_event_entry(sample->eip);
@@ -528,6 +529,8 @@ void sync_buffer(int cpu)
 	sync_buffer_state state = sb_buffer_start;
 	unsigned int i;
 	unsigned long available;
+	struct op_entry entry;
+	struct op_sample *sample;
 
 	mutex_lock(&buffer_mutex);
 
@@ -537,19 +540,19 @@ void sync_buffer(int cpu)
 	available = op_cpu_buffer_entries(cpu);
 
 	for (i = 0; i < available; ++i) {
-		struct op_sample *s = op_cpu_buffer_read_entry(cpu);
-		if (!s)
+		sample = op_cpu_buffer_read_entry(&entry, cpu);
+		if (!sample)
 			break;
 
-		if (is_code(s->eip)) {
-			switch (s->event) {
+		if (is_code(sample->eip)) {
+			switch (sample->event) {
 			case 0:
 			case CPU_IS_KERNEL:
 				/* kernel/userspace switch */
-				in_kernel = s->event;
+				in_kernel = sample->event;
 				if (state == sb_buffer_start)
 					state = sb_sample_start;
-				add_kernel_ctx_switch(s->event);
+				add_kernel_ctx_switch(sample->event);
 				break;
 			case CPU_TRACE_BEGIN:
 				state = sb_bt_start;
@@ -566,7 +569,7 @@ void sync_buffer(int cpu)
 			default:
 				/* userspace context switch */
 				oldmm = mm;
-				new = (struct task_struct *)s->event;
+				new = (struct task_struct *)sample->event;
 				release_mm(oldmm);
 				mm = take_tasks_mm(new);
 				if (mm != oldmm)
@@ -581,7 +584,7 @@ void sync_buffer(int cpu)
 			/* ignore sample */
 			continue;
 
-		if (add_sample(mm, s, in_kernel))
+		if (add_sample(mm, sample, in_kernel))
 			continue;
 
 		/* ignore backtraces if failed to add a sample */
diff --git a/drivers/oprofile/cpu_buffer.c b/drivers/oprofile/cpu_buffer.c
index 934ff15..400f7fc 100644
--- a/drivers/oprofile/cpu_buffer.c
+++ b/drivers/oprofile/cpu_buffer.c
@@ -182,20 +182,28 @@ int op_cpu_buffer_write_commit(struct op_entry *entry)
 					 entry->irq_flags);
 }
 
-struct op_sample *op_cpu_buffer_read_entry(int cpu)
+struct op_sample *op_cpu_buffer_read_entry(struct op_entry *entry, int cpu)
 {
 	struct ring_buffer_event *e;
 	e = ring_buffer_consume(op_ring_buffer_read, cpu, NULL);
 	if (e)
-		return ring_buffer_event_data(e);
+		goto event;
 	if (ring_buffer_swap_cpu(op_ring_buffer_read,
 				 op_ring_buffer_write,
 				 cpu))
 		return NULL;
 	e = ring_buffer_consume(op_ring_buffer_read, cpu, NULL);
 	if (e)
-		return ring_buffer_event_data(e);
+		goto event;
 	return NULL;
+
+event:
+	entry->event = e;
+	entry->sample = ring_buffer_event_data(e);
+	entry->size = (ring_buffer_event_length(e) - sizeof(struct op_sample))
+		/ sizeof(entry->sample->data[0]);
+	entry->data = entry->sample->data;
+	return entry->sample;
 }
 
 unsigned long op_cpu_buffer_entries(int cpu)
diff --git a/drivers/oprofile/cpu_buffer.h b/drivers/oprofile/cpu_buffer.h
index 2d4bfde..d7c0545 100644
--- a/drivers/oprofile/cpu_buffer.h
+++ b/drivers/oprofile/cpu_buffer.h
@@ -75,7 +75,7 @@ static inline void op_cpu_buffer_reset(int cpu)
 struct op_sample
 *op_cpu_buffer_write_reserve(struct op_entry *entry, unsigned long size);
 int op_cpu_buffer_write_commit(struct op_entry *entry);
-struct op_sample *op_cpu_buffer_read_entry(int cpu);
+struct op_sample *op_cpu_buffer_read_entry(struct op_entry *entry, int cpu);
 unsigned long op_cpu_buffer_entries(int cpu);
 
 /* transient events for the CPU buffer -> event buffer */
-- 
1.6.0.1



  parent reply	other threads:[~2009-01-07 22:58 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-07 22:45 [PATCH 0/9] oprofile: implement support of samples with variable data size Robert Richter
2009-01-07 22:45 ` [PATCH 1/9] oprofile: add op_cpu_buffer_write_reserve() Robert Richter
2009-01-07 22:45 ` Robert Richter [this message]
2009-01-07 22:45 ` [PATCH 3/9] oprofile: rework implementation of cpu buffer events Robert Richter
2009-01-07 22:45 ` [PATCH 4/9] oprofile: add op_cpu_buffer_add_data() Robert Richter
2009-01-07 22:45 ` [PATCH 5/9] oprofile: add op_cpu_buffer_get_data() Robert Richter
2009-01-07 22:45 ` [PATCH 6/9] oprofile: use new data sample format for ibs Robert Richter
2009-01-07 22:45 ` [PATCH 7/9] ring_buffer: fix ring_buffer_event_length() Robert Richter
2009-01-07 22:45 ` [PATCH 8/9] oprofile: remove #ifdef CONFIG_OPROFILE_IBS in non-ibs code Robert Richter
2009-01-07 22:45 ` [PATCH 9/9] oprofile: make new cpu buffer functions part of the api Robert Richter
2009-01-14 21:53 ` [PATCH 0/9] oprofile: implement support of samples with variable data size Maynard Johnson

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=1231368325-19246-3-git-send-email-robert.richter@amd.com \
    --to=robert.richter@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=oprofile-list@lists.sourceforge.net \
    /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