- /* reset these to invalid values; the next sample
- * collected will populate the buffer with proper
- * values to initialize the buffer
- */
- cpu_buf->last_is_kernel = -1;
- cpu_buf->last_task = 0;
+ 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);
+}
+
+/*
+ * 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(void * data)
+{
+ struct oprofile_cpu_buffer * b = data;
+ 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);