Commit e2fee276 authored by Robert Richter's avatar Robert Richter

OProfile: Rework oprofile_add_ibs_sample() function

Code looks much more cleaner now.
Signed-off-by: default avatarRobert Richter <robert.richter@amd.com>
parent c493756e
...@@ -67,8 +67,9 @@ static unsigned long reset_value[NUM_COUNTERS]; ...@@ -67,8 +67,9 @@ static unsigned long reset_value[NUM_COUNTERS];
/* The function interface needs to be fixed, something like add /* The function interface needs to be fixed, something like add
data. Should then be added to linux/oprofile.h. */ data. Should then be added to linux/oprofile.h. */
extern void oprofile_add_ibs_sample(struct pt_regs *const regs, extern void
unsigned int * const ibs_sample, u8 code); oprofile_add_ibs_sample(struct pt_regs *const regs,
unsigned int * const ibs_sample, int ibs_code);
struct ibs_fetch_sample { struct ibs_fetch_sample {
/* MSRC001_1031 IBS Fetch Linear Address Register */ /* MSRC001_1031 IBS Fetch Linear Address Register */
......
...@@ -257,21 +257,23 @@ void oprofile_add_sample(struct pt_regs * const regs, unsigned long event) ...@@ -257,21 +257,23 @@ void oprofile_add_sample(struct pt_regs * const regs, unsigned long event)
#ifdef CONFIG_OPROFILE_IBS #ifdef CONFIG_OPROFILE_IBS
#define MAX_IBS_SAMPLE_SIZE 14 #define MAX_IBS_SAMPLE_SIZE 14
static int log_ibs_sample(struct oprofile_cpu_buffer *cpu_buf,
unsigned long pc, int is_kernel, unsigned int *ibs, int ibs_code) void oprofile_add_ibs_sample(struct pt_regs *const regs,
unsigned int * const ibs_sample, int ibs_code)
{ {
int is_kernel = !user_mode(regs);
struct oprofile_cpu_buffer *cpu_buf = &__get_cpu_var(cpu_buffer);
struct task_struct *task; struct task_struct *task;
cpu_buf->sample_received++; cpu_buf->sample_received++;
if (nr_available_slots(cpu_buf) < MAX_IBS_SAMPLE_SIZE) { if (nr_available_slots(cpu_buf) < MAX_IBS_SAMPLE_SIZE) {
/* we can't backtrace since we lost the source of this event */
cpu_buf->sample_lost_overflow++; cpu_buf->sample_lost_overflow++;
return 0; return;
} }
is_kernel = !!is_kernel;
/* notice a switch from user->kernel or vice versa */ /* notice a switch from user->kernel or vice versa */
if (cpu_buf->last_is_kernel != is_kernel) { if (cpu_buf->last_is_kernel != is_kernel) {
cpu_buf->last_is_kernel = is_kernel; cpu_buf->last_is_kernel = is_kernel;
...@@ -281,7 +283,6 @@ static int log_ibs_sample(struct oprofile_cpu_buffer *cpu_buf, ...@@ -281,7 +283,6 @@ static int log_ibs_sample(struct oprofile_cpu_buffer *cpu_buf,
/* notice a task switch */ /* notice a task switch */
if (!is_kernel) { if (!is_kernel) {
task = current; task = current;
if (cpu_buf->last_task != task) { if (cpu_buf->last_task != task) {
cpu_buf->last_task = task; cpu_buf->last_task = task;
add_code(cpu_buf, (unsigned long)task); add_code(cpu_buf, (unsigned long)task);
...@@ -289,36 +290,17 @@ static int log_ibs_sample(struct oprofile_cpu_buffer *cpu_buf, ...@@ -289,36 +290,17 @@ static int log_ibs_sample(struct oprofile_cpu_buffer *cpu_buf,
} }
add_code(cpu_buf, ibs_code); add_code(cpu_buf, ibs_code);
add_sample(cpu_buf, ibs[0], ibs[1]); add_sample(cpu_buf, ibs_sample[0], ibs_sample[1]);
add_sample(cpu_buf, ibs[2], ibs[3]); add_sample(cpu_buf, ibs_sample[2], ibs_sample[3]);
add_sample(cpu_buf, ibs[4], ibs[5]); add_sample(cpu_buf, ibs_sample[4], ibs_sample[5]);
if (ibs_code == IBS_OP_BEGIN) { if (ibs_code == IBS_OP_BEGIN) {
add_sample(cpu_buf, ibs[6], ibs[7]); add_sample(cpu_buf, ibs_sample[6], ibs_sample[7]);
add_sample(cpu_buf, ibs[8], ibs[9]); add_sample(cpu_buf, ibs_sample[8], ibs_sample[9]);
add_sample(cpu_buf, ibs[10], ibs[11]); add_sample(cpu_buf, ibs_sample[10], ibs_sample[11]);
}
return 1;
}
void oprofile_add_ibs_sample(struct pt_regs *const regs,
unsigned int * const ibs_sample, u8 code)
{
int is_kernel = !user_mode(regs);
unsigned long pc = profile_pc(regs);
struct oprofile_cpu_buffer *cpu_buf =
&per_cpu(cpu_buffer, smp_processor_id());
if (!backtrace_depth) {
log_ibs_sample(cpu_buf, pc, is_kernel, ibs_sample, code);
return;
} }
/* if log_sample() fails we can't backtrace since we lost the source if (backtrace_depth)
* of this event */
if (log_ibs_sample(cpu_buf, pc, is_kernel, ibs_sample, code))
oprofile_ops.backtrace(regs, backtrace_depth); oprofile_ops.backtrace(regs, backtrace_depth);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment