*/
 static int
 log_sample(struct oprofile_cpu_buffer *cpu_buf, unsigned long pc,
-          unsigned long backtrace, int is_kernel, unsigned long event)
+          unsigned long backtrace, int is_kernel, unsigned long event,
+          struct task_struct *task)
 {
+       struct task_struct *tsk = task ? task : current;
        cpu_buf->sample_received++;
 
        if (pc == ESCAPE_CODE) {
                return 0;
        }
 
-       if (op_add_code(cpu_buf, backtrace, is_kernel, current))
+       if (op_add_code(cpu_buf, backtrace, is_kernel, tsk))
                goto fail;
 
        if (op_add_sample(cpu_buf, pc, event))
 
 static inline void
 __oprofile_add_ext_sample(unsigned long pc, struct pt_regs * const regs,
-                         unsigned long event, int is_kernel)
+                         unsigned long event, int is_kernel,
+                         struct task_struct *task)
 {
        struct oprofile_cpu_buffer *cpu_buf = &__get_cpu_var(op_cpu_buffer);
        unsigned long backtrace = oprofile_backtrace_depth;
         * if log_sample() fail we can't backtrace since we lost the
         * source of this event
         */
-       if (!log_sample(cpu_buf, pc, backtrace, is_kernel, event))
+       if (!log_sample(cpu_buf, pc, backtrace, is_kernel, event, task))
                /* failed */
                return;
 
        oprofile_end_trace(cpu_buf);
 }
 
+void oprofile_add_ext_hw_sample(unsigned long pc, struct pt_regs * const regs,
+                               unsigned long event, int is_kernel,
+                               struct task_struct *task)
+{
+       __oprofile_add_ext_sample(pc, regs, event, is_kernel, task);
+}
+
 void oprofile_add_ext_sample(unsigned long pc, struct pt_regs * const regs,
                             unsigned long event, int is_kernel)
 {
-       __oprofile_add_ext_sample(pc, regs, event, is_kernel);
+       __oprofile_add_ext_sample(pc, regs, event, is_kernel, NULL);
 }
 
 void oprofile_add_sample(struct pt_regs * const regs, unsigned long event)
                pc = ESCAPE_CODE; /* as this causes an early return. */
        }
 
-       __oprofile_add_ext_sample(pc, regs, event, is_kernel);
+       __oprofile_add_ext_sample(pc, regs, event, is_kernel, NULL);
 }
 
 /*
 void oprofile_add_pc(unsigned long pc, int is_kernel, unsigned long event)
 {
        struct oprofile_cpu_buffer *cpu_buf = &__get_cpu_var(op_cpu_buffer);
-       log_sample(cpu_buf, pc, 0, is_kernel, event);
+       log_sample(cpu_buf, pc, 0, is_kernel, event, NULL);
 }
 
 void oprofile_add_trace(unsigned long pc)