cpqarray: switch to seq_file
[safe/jmp/linux-2.6] / drivers / oprofile / cpu_buffer.c
index 1b65907..a7aae24 100644 (file)
@@ -21,7 +21,6 @@
 
 #include <linux/sched.h>
 #include <linux/oprofile.h>
-#include <linux/vmalloc.h>
 #include <linux/errno.h>
 
 #include "event_buffer.h"
@@ -78,16 +77,20 @@ void free_cpu_buffers(void)
        op_ring_buffer_write = NULL;
 }
 
+#define RB_EVENT_HDR_SIZE 4
+
 int alloc_cpu_buffers(void)
 {
        int i;
 
        unsigned long buffer_size = oprofile_cpu_buffer_size;
+       unsigned long byte_size = buffer_size * (sizeof(struct op_sample) +
+                                                RB_EVENT_HDR_SIZE);
 
-       op_ring_buffer_read = ring_buffer_alloc(buffer_size, OP_BUFFER_FLAGS);
+       op_ring_buffer_read = ring_buffer_alloc(byte_size, OP_BUFFER_FLAGS);
        if (!op_ring_buffer_read)
                goto fail;
-       op_ring_buffer_write = ring_buffer_alloc(buffer_size, OP_BUFFER_FLAGS);
+       op_ring_buffer_write = ring_buffer_alloc(byte_size, OP_BUFFER_FLAGS);
        if (!op_ring_buffer_write)
                goto fail;
 
@@ -161,7 +164,7 @@ struct op_sample
 {
        entry->event = ring_buffer_lock_reserve
                (op_ring_buffer_write, sizeof(struct op_sample) +
-                size * sizeof(entry->sample->data[0]), &entry->irq_flags);
+                size * sizeof(entry->sample->data[0]));
        if (entry->event)
                entry->sample = ring_buffer_event_data(entry->event);
        else
@@ -178,8 +181,7 @@ struct op_sample
 
 int op_cpu_buffer_write_commit(struct op_entry *entry)
 {
-       return ring_buffer_unlock_commit(op_ring_buffer_write, entry->event,
-                                        entry->irq_flags);
+       return ring_buffer_unlock_commit(op_ring_buffer_write, entry->event);
 }
 
 struct op_sample *op_cpu_buffer_read_entry(struct op_entry *entry, int cpu)
@@ -361,36 +363,70 @@ void oprofile_add_sample(struct pt_regs * const regs, unsigned long event)
        __oprofile_add_ext_sample(pc, regs, event, is_kernel);
 }
 
-#ifdef CONFIG_OPROFILE_IBS
-
-void oprofile_add_ibs_sample(struct pt_regs * const regs,
-                            unsigned int * const ibs_sample, int ibs_code)
+/*
+ * Add samples with data to the ring buffer.
+ *
+ * Use oprofile_add_data(&entry, val) to add data and
+ * oprofile_write_commit(&entry) to commit the sample.
+ */
+void
+oprofile_write_reserve(struct op_entry *entry, struct pt_regs * const regs,
+                      unsigned long pc, int code, int size)
 {
+       struct op_sample *sample;
        int is_kernel = !user_mode(regs);
        struct oprofile_cpu_buffer *cpu_buf = &__get_cpu_var(cpu_buffer);
-       int fail = 0;
 
        cpu_buf->sample_received++;
 
-       /* backtraces disabled for ibs */
-       fail = fail || op_add_code(cpu_buf, 0, is_kernel, current);
+       /* no backtraces for samples with data */
+       if (op_add_code(cpu_buf, 0, is_kernel, current))
+               goto fail;
 
-       fail = fail || op_add_sample(cpu_buf, ESCAPE_CODE,   ibs_code);
-       fail = fail || op_add_sample(cpu_buf, ibs_sample[0], ibs_sample[1]);
-       fail = fail || op_add_sample(cpu_buf, ibs_sample[2], ibs_sample[3]);
-       fail = fail || op_add_sample(cpu_buf, ibs_sample[4], ibs_sample[5]);
+       sample = op_cpu_buffer_write_reserve(entry, size + 2);
+       if (!sample)
+               goto fail;
+       sample->eip = ESCAPE_CODE;
+       sample->event = 0;              /* no flags */
 
-       if (ibs_code == IBS_OP_BEGIN) {
-               fail = fail || op_add_sample(cpu_buf, ibs_sample[6], ibs_sample[7]);
-               fail = fail || op_add_sample(cpu_buf, ibs_sample[8], ibs_sample[9]);
-               fail = fail || op_add_sample(cpu_buf, ibs_sample[10], ibs_sample[11]);
-       }
+       op_cpu_buffer_add_data(entry, code);
+       op_cpu_buffer_add_data(entry, pc);
 
-       if (fail)
-               cpu_buf->sample_lost_overflow++;
+       return;
+
+fail:
+       entry->event = NULL;
+       cpu_buf->sample_lost_overflow++;
 }
 
-#endif
+int oprofile_add_data(struct op_entry *entry, unsigned long val)
+{
+       if (!entry->event)
+               return 0;
+       return op_cpu_buffer_add_data(entry, val);
+}
+
+int oprofile_add_data64(struct op_entry *entry, u64 val)
+{
+       if (!entry->event)
+               return 0;
+       if (op_cpu_buffer_get_size(entry) < 2)
+               /*
+                * the function returns 0 to indicate a too small
+                * buffer, even if there is some space left
+                */
+               return 0;
+       if (!op_cpu_buffer_add_data(entry, (u32)val))
+               return 0;
+       return op_cpu_buffer_add_data(entry, (u32)(val >> 32));
+}
+
+int oprofile_write_commit(struct op_entry *entry)
+{
+       if (!entry->event)
+               return -EINVAL;
+       return op_cpu_buffer_write_commit(entry);
+}
 
 void oprofile_add_pc(unsigned long pc, int is_kernel, unsigned long event)
 {