cpqarray: switch to seq_file
[safe/jmp/linux-2.6] / drivers / oprofile / cpu_buffer.c
index ddba9d0..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,15 +363,14 @@ 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
-
 /*
  * Add samples with data to the ring buffer.
  *
- * Use op_cpu_buffer_add_data(&entry, val) to add data and
- * op_cpu_buffer_write_commit(&entry) to commit the sample.
+ * Use oprofile_add_data(&entry, val) to add data and
+ * oprofile_write_commit(&entry) to commit the sample.
  */
-void oprofile_add_data(struct op_entry *entry, struct pt_regs * const regs,
+void
+oprofile_write_reserve(struct op_entry *entry, struct pt_regs * const regs,
                       unsigned long pc, int code, int size)
 {
        struct op_sample *sample;
@@ -394,10 +395,38 @@ void oprofile_add_data(struct op_entry *entry, struct pt_regs * const regs,
        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)
 {