+ struct oprofile_cpu_buffer * cpu_buf = &cpu_buffer[smp_processor_id()];
+ log_sample(cpu_buf, pc, is_kernel, event);
+}
+
+void oprofile_add_trace(unsigned long pc)
+{
+ struct oprofile_cpu_buffer * cpu_buf = &cpu_buffer[smp_processor_id()];
+
+ if (!cpu_buf->tracing)
+ return;
+
+ if (nr_available_slots(cpu_buf) < 1) {
+ cpu_buf->tracing = 0;
+ cpu_buf->sample_lost_overflow++;
+ return;
+ }
+
+ /* broken frame can give an eip with the same value as an escape code,
+ * abort the trace if we get it */
+ if (pc == ESCAPE_CODE) {
+ cpu_buf->tracing = 0;
+ cpu_buf->backtrace_aborted++;
+ return;
+ }
+
+ add_sample(cpu_buf, pc, 0);
+}
+
+int oprofile_add_domain_switch(int32_t domain_id)
+{
+ struct oprofile_cpu_buffer * cpu_buf = &cpu_buffer[smp_processor_id()];
+
+ /* should have space for switching into and out of domain
+ (2 slots each) plus one sample and one cpu mode switch */
+ if (((nr_available_slots(cpu_buf) < 6) &&
+ (domain_id != COORDINATOR_DOMAIN)) ||
+ (nr_available_slots(cpu_buf) < 2))
+ return 0;
+
+ add_code(cpu_buf, CPU_DOMAIN_SWITCH);
+ add_sample(cpu_buf, domain_id, 0);
+
+ current_domain = domain_id;
+
+ return 1;
+}
+
+/*
+ * This serves to avoid cpu buffer overflow, and makes sure
+ * the task mortuary progresses
+ *
+ * By using schedule_delayed_work_on and then schedule_delayed_work
+ * we guarantee this will stay on the correct cpu
+ */
+static void wq_sync_buffer(struct work_struct *work)
+{
+ struct oprofile_cpu_buffer * b =
+ container_of(work, struct oprofile_cpu_buffer, work.work);
+ if (b->cpu != smp_processor_id()) {
+ printk("WQ on CPU%d, prefer CPU%d\n",
+ smp_processor_id(), b->cpu);
+ }
+ sync_buffer(b->cpu);
+
+ /* don't re-add the work if we're shutting down */
+ if (work_enabled)
+ schedule_delayed_work(&b->work, DEFAULT_TIMER_EXPIRE);