OProfile - Add support to OProfile for profiling CELL BE SPUs
Subsystems (3)
PATCH 2/2 OProfile - Add support to OProfile for profiling CELL BE SPUs
From: Maynard Johnson <[email protected]>
This patch updates the existing arch/powerpc/oprofile/op_model_cell.c to add in the SPU profiling capabilities. In addition, a 'cell' subdirectory was added to arch/powerpc/oprofile to hold Cell-specific SPU profiling code.
Also incorporated several fixes from other patches (rrn). Check pointer returned from kzalloc. Eliminated unnecessary cast. Better error handling and cleanup in the related area. 64-bit unsigned long parameter was being demoted to 32-bit unsigned int and eventually promoted back to unsigned long.
---
We would like to include this patch in -mm and 2.6.23
arch/powerpc/configs/cell_defconfig +2 -1
@@ -1455,7 +1455,8 @@ CONFIG_HAS_DMA=y # Instrumentation Support # CONFIG_PROFILING=y -CONFIG_OPROFILE=y +CONFIG_OPROFILE=m +CONFIG_OPROFILE_CELL=y # CONFIG_KPROBES is not set #
arch/powerpc/oprofile/cell/pr_util.h new file +88 -0
88 lines not on this page · raw message
cycles_reset);
+
+#endif /* PR_UTIL_H */
arch/powerpc/oprofile/cell/spu_profiler.c new file +42 -0
42 lines not on this page · raw message
cycles_reset)
+{
+ unsigned long ns_per_cyc;
+ if (!freq_khz)
+ freq_khz = ppc_proc_freq/1000;
+
+ /* To calculate a timeout in nanoseconds, the basic
+ * formula is ns = cycles_reset * (NSEC_PER_SEC / cpu frequency).
+ * To avoid floating point math, we use the scale math
+ * technique as described in linux/jiffies.h. We use
+ * a scale factor of SCALE_SHIFT, which provides 4 decimal places
+ * of precision. This is close enough for the purpose at hand.
+ *
+ * The value of the timeout should be small enough that the hw
+ * trace buffer will not get more then about 1/3 full for the
+ * maximum user specified (the LFSR value) hw sampling frequency.
+ * This is to ensure the trace buffer will never fill even if the
+ * kernel thread scheduling varies under a heavy system load.
+ */
+
+ ns_per_cyc = (USEC_PER_SEC << SCALE_SHIFT)/freq_khz;
+ profiling_interval = (ns_per_cyc * cycles_reset) >> SCALE_SHIFT;
+
+}
+
+/*
+ * Extract SPU PC from trace buffer entry
+ */
+static void spu_pc_extract(int cpu, int entry)
+{
+ /* the trace buffer is 128 bits */
+ u64 trace_buffer[2];
+ u64 spu_mask;
+ int spu;
+
+ spu_mask = SPU_PC_MASK;
+
+ /* Each SPU PC is 16 bits; hence, four spus in each of
+ * the two 64-bit buffer entries that make up the
+ * 128-bit trace_buffer entry. Process two 64-bit values
+ * simultaneously.
+ * trace[0] SPU PC contents are: 0 1 2 3
+ * trace[1] SPU PC contents are: 4 5 6 7
+ */
+
+ cbe_read_trace_buffer(cpu, trace_buffer);
+
+ for (spu = SPUS_PER_TB_ENTRY-1; spu >= 0; spu--) {
+ /* spu PC trace entry is upper 16 bits of the
+ * 18 bit SPU program counter
+ */
+ samples[spu * TRACE_ARRAY_SIZE + entry]
+ = (spu_mask & trace_buffer[0]) << 2;
+ samples[(spu + SPUS_PER_TB_ENTRY) * TRACE_ARRAY_SIZE + entry]
+ = (spu_mask & trace_buffer[1]) << 2;
+
+ trace_buffer[0] = trace_buffer[0] >> NUM_SPU_BITS_TRBUF;
+ trace_buffer[1] = trace_buffer[1] >> NUM_SPU_BITS_TRBUF;
+ }
+}
+
+static int cell_spu_pc_collection(int cpu)
+{
+ u32 trace_addr;
+ int entry;
+
+ /* process the collected SPU PC for the node */
+
+ entry = 0;
+
+ trace_addr = cbe_read_pm(cpu, trace_address);
+ while (!(trace_addr & CBE_PM_TRACE_BUF_EMPTY)) {
+ /* there is data in the trace buffer to process */
+ spu_pc_extract(cpu, entry);
+
+ entry++;
+
+ if (entry >= TRACE_ARRAY_SIZE)
+ /* spu_samples is full */
+ break;
+
+ trace_addr = cbe_read_pm(cpu, trace_address);
+ }
+
+ return(entry);
+}
+
+
+static enum hrtimer_restart profile_spus(struct hrtimer *timer) +{
+ ktime_t kt;
+ int cpu, node, k, num_samples, spu_num;
+
+ if (!spu_prof_running)
+ goto stop;
+
+ for_each_online_cpu(cpu) {
+ if (cbe_get_hw_thread_id(cpu))
+ continue;
+
+ node = cbe_cpu_to_node(cpu);
+
+ /* There should only be one kernel thread at a time processing
+ * the samples. In the very unlikely case that the processing
+ * is taking a very long time and multiple kernel threads are
+ * started to process the samples. Make sure only one kernel
+ * thread is working on the samples array at a time. The
+ * sample array must be loaded and then processed for a given
+ * cpu. The sample array is not per cpu.
+ */
+ spin_lock_irqsave(&sample_array_lock,
+ sample_array_lock_flags);
+ num_samples = cell_spu_pc_collection(cpu);
+
+ if (num_samples == 0) {
+ spin_unlock_irqrestore(&sample_array_lock,
+ sample_array_lock_flags);
+ continue;
+ }
+
+ for (k = 0; k < SPUS_PER_NODE; k++) {
+ spu_num = k + (node * SPUS_PER_NODE);
+ spu_sync_buffer(spu_num,
+ samples + (k * TRACE_ARRAY_SIZE),
+ num_samples);
+ }
+
+ spin_unlock_irqrestore(&sample_array_lock,
+ sample_array_lock_flags);
+
+ }
+ smp_wmb();
+
+ kt = ktime_set(0, profiling_interval);
+ if (!spu_prof_running)
+ goto stop;
+ hrtimer_forward(timer, timer->base->get_time(), kt);
+ return HRTIMER_RESTART;
+
+ stop:
+ printk(KERN_INFO "SPU_PROF: spu-prof timer ending\n");
+ return HRTIMER_NORESTART;
+}
+
+static struct hrtimer timer;
+/*
+ * Entry point for SPU profiling.
+ * NOTE: SPU profiling is done system-wide, not per-CPU.
+ *
+ * cycles_reset is the count value specified by the user when
+ * setting up OProfile to count SPU_CYCLES.
+ */
+int start_spu_profiling(unsigned int cycles_reset)
+{
+ ktime_t kt;
+
+ pr_debug("timer resolution: %lu\n", TICK_NSEC);
+ kt = ktime_set(0, profiling_interval);
+ hrtimer_init(&timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
+ timer.expires = kt;
+ timer.function = profile_spus;
+
+ /* Allocate arrays for collecting SPU PC samples */
+ samples = kzalloc(SPUS_PER_NODE *
+ TRACE_ARRAY_SIZE * sizeof(u32), GFP_KERNEL);
+
+ if (!samples)
+ return -ENOMEM;
+
+ spu_prof_running = 1;
+ hrtimer_start(&timer, kt, HRTIMER_MODE_REL);
+
+ return 0;
+}
+
+void stop_spu_profiling(void)
+{
+ spu_prof_running = 0;
+ hrtimer_cancel(&timer);
+ kfree(samples);
+ pr_debug("SPU_PROF: stop_spu_profiling issued\n");
+}
arch/powerpc/oprofile/cell/spu_task_sync.c new file +296 -0
296 lines not on this page · raw message
objectId);
+ if (!app_dcookie || !spu_cookie) {
+ retval = -ENOENT;
+ goto out;
+ }
+
+ /* Record context info in event buffer */
+ spin_lock_irqsave(&buffer_lock, flags);
+ add_event_entry(ESCAPE_CODE);
+ add_event_entry(SPU_CTX_SWITCH_CODE);
+ add_event_entry(spu->number);
+ add_event_entry(spu->pid);
+ add_event_entry(spu->tgid);
+ add_event_entry(app_dcookie);
+ add_event_entry(spu_cookie);
+ add_event_entry(offset);
+ spin_unlock_irqrestore(&buffer_lock, flags);
+ smp_wmb();
+out:
+ return retval;
+}
+
+/*
+ * This function is invoked on either a bind_context or unbind_context.
+ * If called for an unbind_context, the val arg is 0; otherwise,
+ * it is the object-id value for the spu context.
+ * The data arg is of type 'struct spu *'.
+ */
+static int spu_active_notify(struct notifier_block *self, unsigned long val,
+ void *data)
+{
+ int retval;
+ unsigned long flags;
+ struct spu *the_spu = data;
+
+ pr_debug("SPU event notification arrived\n");
+ if (!val) {
+ spin_lock_irqsave(&cache_lock, flags);
+ retval = release_cached_info(the_spu->number);
+ spin_unlock_irqrestore(&cache_lock, flags);
+ } else {
+ retval = process_context_switch(the_spu, val);
+ }
+ return retval;
+}
+
+static struct notifier_block spu_active = {
+ .notifier_call = spu_active_notify,
+};
+
+/* The main purpose of this function is to synchronize
+ * OProfile with SPUFS by registering to be notified of
+ * SPU task switches.
+ *
+ * NOTE: When profiling SPUs, we must ensure that only
+ * spu_sync_start is invoked and not the generic sync_start
+ * in drivers/oprofile/oprof.c. A return value of
+ * SKIP_GENERIC_SYNC or SYNC_START_ERROR will
+ * accomplish this.
+ */
+int spu_sync_start(void)
+{
+ int k;
+ int ret = SKIP_GENERIC_SYNC;
+ int register_ret;
+ unsigned long flags = 0;
+
+ spu_prof_num_nodes = number_of_online_nodes();
+ num_spu_nodes = spu_prof_num_nodes * 8;
+
+ spin_lock_irqsave(&buffer_lock, flags);
+ add_event_entry(ESCAPE_CODE);
+ add_event_entry(SPU_PROFILING_CODE);
+ add_event_entry(num_spu_nodes);
+ spin_unlock_irqrestore(&buffer_lock, flags);
+
+ /* Register for SPU events */
+ register_ret = spu_switch_event_register(&spu_active);
+ if (register_ret) {
+ ret = SYNC_START_ERROR;
+ goto out;
+ }
+
+ for (k = 0; k < (MAX_NUMNODES * 8); k++)
+ last_guard_val[k] = 0;
+ pr_debug("spu_sync_start -- running.\n");
+out:
+ return ret;
+}
+
+/* Record SPU program counter samples to the oprofile event buffer. */ +void spu_sync_buffer(int spu_num, unsigned int *samples,
+ int num_samples)
+{
+ unsigned long long file_offset;
+ unsigned long flags;
+ int i;
+ struct vma_to_fileoffset_map *map;
+ struct spu *the_spu;
+ unsigned long long spu_num_ll = spu_num;
+ unsigned long long spu_num_shifted = spu_num_ll << 32;
+ struct cached_info *c_info;
+
+ /* We need to obtain the cache_lock here because it's
+ * possible that after getting the cached_info, the SPU job
+ * corresponding to this cached_info may end, thus resulting
+ * in the destruction of the cached_info.
+ */
+ spin_lock_irqsave(&cache_lock, flags);
+ c_info = get_cached_info(NULL, spu_num);
+ if (!c_info) {
+ /* This legitimately happens when the SPU task ends before all
+ * samples are recorded.
+ * No big deal -- so we just drop a few samples.
+ */
+ pr_debug("SPU_PROF: No cached SPU contex "
+ "for SPU #%d. Dropping samples.\n", spu_num);
+ goto out;
+ }
+
+ map = c_info->map;
+ the_spu = c_info->the_spu;
+ spin_lock(&buffer_lock);
+ for (i = 0; i < num_samples; i++) {
+ unsigned int sample = *(samples+i);
+ int grd_val = 0;
+ file_offset = 0;
+ if (sample == 0)
+ continue;
+ file_offset = vma_map_lookup( map, sample, the_spu, &grd_val);
+
+ /* If overlays are used by this SPU application, the guard
+ * value is non-zero, indicating which overlay section is in
+ * use. We need to discard samples taken during the time
+ * period which an overlay occurs (i.e., guard value changes).
+ */
+ if (grd_val && grd_val != last_guard_val[spu_num]) {
+ last_guard_val[spu_num] = grd_val;
+ /* Drop the rest of the samples. */
+ break;
+ }
+
+ add_event_entry(file_offset | spu_num_shifted);
+ }
+ spin_unlock(&buffer_lock);
+out:
+ spin_unlock_irqrestore(&cache_lock, flags);
+}
+
+
+int spu_sync_stop(void)
+{
+ unsigned long flags = 0;
+ int ret = spu_switch_event_unregister(&spu_active);
+ if (ret) {
+ printk(KERN_ERR "SPU_PROF: "
+ "%s, line %d: spu_switch_event_unregister returned %d\n",
+ __FUNCTION__, __LINE__, ret);
+ goto out;
+ }
+
+ spin_lock_irqsave(&cache_lock, flags);
+ ret = release_cached_info(RELEASE_ALL);
+ spin_unlock_irqrestore(&cache_lock, flags);
+out:
+ pr_debug("spu_sync_stop -- done.\n");
+ return ret;
+}
+
+
arch/powerpc/oprofile/cell/vma_map.c new file +287 -0
287 lines not on this page · raw message
arch/powerpc/oprofile/common.c +42 -9
100 lines not on this page · raw message
arch/powerpc/oprofile/Kconfig +3 -0
@@ -15,3 +15,10 @@ config OPROFILE If unsure, say N. +config OPROFILE_CELL + bool "OProfile for Cell Broadband Engine" + depends on (SPU_FS = y && OPROFILE = m) || (SPU_FS = y && OPROFILE = y) ||
(SPU_FS = m && OPROFILE = m)
+ default y
+ help
+ Profiling of Cell BE SPUs requires special support enabled
+ by this option.
arch/powerpc/oprofile/Makefile +3 -1
@@ -11,7 +11,9 @@ DRIVER_OBJS := $(addprefix ../../../driv timer_int.o ) oprofile-y := $(DRIVER_OBJS) common.o backtrace.o -oprofile-$(CONFIG_PPC_CELL_NATIVE) += op_model_cell.o +oprofile-$(CONFIG_OPROFILE_CELL) += op_model_cell.o \ + cell/spu_profiler.o cell/vma_map.o \ + cell/spu_task_sync.o oprofile-$(CONFIG_PPC64) += op_model_rs64.o op_model_power4.o op_model_pa6t.o oprofile-$(CONFIG_FSL_BOOKE) += op_model_fsl_booke.o oprofile-$(CONFIG_6xx) += op_model_7450.o
arch/powerpc/oprofile/op_model_cell.c +314 -63
591 lines not on this page · raw message
*data)
+{
+ int ret = 0;
+ struct cpufreq_freqs *frq = data;
+ if ((val == CPUFREQ_PRECHANGE && frq->old < frq->new) ||
+ (val == CPUFREQ_POSTCHANGE && frq->old > frq->new) ||
+ (val == CPUFREQ_RESUMECHANGE || val == CPUFREQ_SUSPENDCHANGE))
+ set_profiling_frequency(frq->new, spu_cycle_reset);
+ return ret;
+}
+
+static struct notifier_block cpu_freq_notifier_block = {
+ .notifier_call = oprof_cpufreq_notify
+};
+#endif
+
+static int cell_global_start_spu(struct op_counter_config *ctr) +{
+ int subfunc;
+ unsigned int lfsr_value;
+ int cpu;
+ int ret;
+ int rtas_error;
+ unsigned int cpu_khzfreq = 0;
+
+ /* The SPU profiling uses time-based profiling based on
+ * cpu frequency, so if configured with the CPU_FREQ
+ * option, we should detect frequency changes and react
+ * accordingly.
+ */
+#ifdef CONFIG_CPU_FREQ
+ ret = cpufreq_register_notifier(&cpu_freq_notifier_block,
+ CPUFREQ_TRANSITION_NOTIFIER);
+ if (ret < 0)
+ /* this is not a fatal error */
+ printk(KERN_ERR "CPU freq change registration failed: %d\n",
+ ret);
+
+ else
+ cpu_khzfreq = cpufreq_quick_get(smp_processor_id());
+#endif
+
+ set_profiling_frequency(cpu_khzfreq, spu_cycle_reset);
+
+ for_each_online_cpu(cpu) {
+ if (cbe_get_hw_thread_id(cpu))
+ continue;
+
+ /*
+ * Setup SPU cycle-based profiling.
+ * Set perf_mon_control bit 0 to a zero before
+ * enabling spu collection hardware.
+ */
+ cbe_write_pm(cpu, pm_control, 0);
+
+ if (spu_cycle_reset > MAX_SPU_COUNT)
+ /* use largest possible value */
+ lfsr_value = calculate_lfsr(MAX_SPU_COUNT-1);
+ else
+ lfsr_value = calculate_lfsr(spu_cycle_reset);
+
+ /* must use a non zero value. Zero disables data collection. */
+ if (lfsr_value == 0)
+ lfsr_value = calculate_lfsr(1);
+
+ lfsr_value = lfsr_value << 8; /* shift lfsr to correct
+ * register location
+ */
+
+ /* debug bus setup */
+ ret = pm_rtas_activate_spu_profiling(cbe_cpu_to_node(cpu));
+
+ if (unlikely(ret)) {
+ rtas_error = ret;
+ goto out;
+ }
+
+
+ subfunc = 2; /* 2 - activate SPU tracing, 3 - deactivate */
+
+ /* start profiling */
+ ret = rtas_call(spu_rtas_token, 3, 1, NULL, subfunc,
+ cbe_cpu_to_node(cpu), lfsr_value);
+
+ if (unlikely(ret != 0)) {
+ printk(KERN_ERR
+ "%s: rtas call ibm,cbe-spu-perftools failed, return = %d\n",
+ __FUNCTION__, ret);
+ rtas_error = -EIO;
+ goto out;
+ }
+ }
+
+ rtas_error = start_spu_profiling(spu_cycle_reset);
+ if (rtas_error)
+ goto out_stop;
+
+ oprofile_running = 1;
+ return 0;
+
+out_stop:
+ cell_global_stop_spu(); /* clean up the PMU/debug bus */
out:
- ;
+ return rtas_error;
}
-static void cell_global_start(struct op_counter_config *ctr) +static int cell_global_start_ppu(struct op_counter_config *ctr)
{
- u32 cpu;
+ u32 cpu, i;
u32 interrupt_mask = 0;
- u32 i;
/* This routine gets called once for the system.
* There is one performance monitor per node, so we
@@ -651,19 +1002,80 @@ static void cell_global_start(struct op_
oprofile_running = 1;
smp_wmb();
- /* NOTE: start_virt_cntrs will result in cell_virtual_cntr() being
- * executed which manipulates the PMU. We start the "virtual counter"
+ /*
+ * NOTE: start_virt_cntrs will result in cell_virtual_cntr() being
+ * executed which manipulates the PMU. We start the "virtual counter"
* here so that we do not need to synchronize access to the PMU in
* the above for-loop.
*/
start_virt_cntrs();
+
+ return 0;
}
-static void cell_global_stop(void)
+static int cell_global_start(struct op_counter_config *ctr) +{
+ if (spu_cycle_reset) {
+ return cell_global_start_spu(ctr);
+ } else {
+ return cell_global_start_ppu(ctr);
+ }
+}
+
+/*
+ * Note the generic OProfile stop calls do not support returning
+ * an error on stop. Hence, will not return an error if the FW
+ * calls fail on stop. Failure to reset the debug bus is not an issue.
+ * Failure to disable the SPU profiling is not an issue. The FW calls
+ * to enable the performance counters and debug bus will work even if
+ * the hardware was not cleanly reset.
+ */
+static void cell_global_stop_spu(void)
+{
+ int subfunc, rtn_value;
+ unsigned int lfsr_value;
+ int cpu;
+
+ oprofile_running = 0;
+
+#ifdef CONFIG_CPU_FREQ
+ cpufreq_unregister_notifier(&cpu_freq_notifier_block,
+ CPUFREQ_TRANSITION_NOTIFIER);
+#endif
+
+ for_each_online_cpu(cpu) {
+ if (cbe_get_hw_thread_id(cpu))
+ continue;
+
+ subfunc = 3; /*
+ * 2 - activate SPU tracing,
+ * 3 - deactivate
+ */
+ lfsr_value = 0x8f100000;
+
+ rtn_value = rtas_call(spu_rtas_token, 3, 1, NULL,
+ subfunc, cbe_cpu_to_node(cpu),
+ lfsr_value);
+
+ if (unlikely(rtn_value != 0)) {
+ printk(KERN_ERR
+ "%s: rtas call ibm,cbe-spu-perftools failed, return = %d\n",
+ __FUNCTION__, rtn_value);
+ }
+
+ /* Deactivate the signals */
+ pm_rtas_reset_signals(cbe_cpu_to_node(cpu));
+ }
+
+ stop_spu_profiling();
+}
+
+static void cell_global_stop_ppu(void)
{
int cpu;
- /* This routine will be called once for the system.
+ /*
+ * This routine will be called once for the system.
* There is one performance monitor per node, so we
* only need to perform this function once per node. */
@@ -687,8 +1099,17 @@ static void cell_global_stop(void)
}
}
-static void
-cell_handle_interrupt(struct pt_regs *regs, struct op_counter_config *ctr) +static void cell_global_stop(void)
+{
+ if (spu_cycle_reset) {
+ cell_global_stop_spu();
+ } else {
+ cell_global_stop_ppu();
+ }
+}
+
+static void cell_handle_interrupt(struct pt_regs *regs,
+ struct op_counter_config *ctr)
{
u32 cpu;
u64 pc;
@@ -699,13 +1120,15 @@ cell_handle_interrupt(struct pt_regs *re
cpu = smp_processor_id();
- /* Need to make sure the interrupt handler and the virt counter
+ /*
+ * Need to make sure the interrupt handler and the virt counter
* routine are not running at the same time. See the
* cell_virtual_cntr() routine for additional comments. */
spin_lock_irqsave(&virt_cntr_lock, flags);
- /* Need to disable and reenable the performance counters
+ /*
+ * Need to disable and reenable the performance counters
* to get the desired behavior from the hardware. This
* is hardware specific.
*/
@@ -714,7 +1137,8 @@ cell_handle_interrupt(struct pt_regs *re
interrupt_mask = cbe_get_and_clear_pm_interrupts(cpu);
- /* If the interrupt mask has been cleared, then the virt cntr
+ /*
+ * If the interrupt mask has been cleared, then the virt cntr
* has cleared the interrupt. When the thread that generated
* the interrupt is restored, the data count will be restored to
* 0xffffff0 to cause the interrupt to be regenerated.
@@ -732,18 +1156,20 @@ cell_handle_interrupt(struct pt_regs *re
}
}
- /* The counters were frozen by the interrupt.
+ /*
+ * The counters were frozen by the interrupt.
* Reenable the interrupt and restart the counters.
* If there was a race between the interrupt handler and
- * the virtual counter routine. The virutal counter
+ * the virtual counter routine. The virutal counter
* routine may have cleared the interrupts. Hence must
* use the virt_cntr_inter_mask to re-enable the interrupts. */
cbe_enable_pm_interrupts(cpu, hdw_thread,
virt_cntr_inter_mask);
- /* The writes to the various performance counters only writes
- * to a latch. The new values (interrupt setting bits, reset
+ /*
+ * The writes to the various performance counters only writes
+ * to a latch. The new values (interrupt setting bits, reset
* counter value etc.) are not copied to the actual registers
* until the performance monitor is enabled. In order to get
* this to work as desired, the permormance monitor needs to
@@ -755,10 +1181,33 @@ cell_handle_interrupt(struct pt_regs *re
spin_unlock_irqrestore(&virt_cntr_lock, flags);
}
+/*
+ * This function is called from the generic OProfile
+ * driver. When profiling PPUs, we need to do the
+ * generic sync start; otherwise, do spu_sync_start.
+ */
+static int cell_sync_start(void)
+{
+ if (spu_cycle_reset)
+ return spu_sync_start();
+ else
+ return DO_GENERIC_SYNC;
+}
+
+static int cell_sync_stop(void)
+{
+ if (spu_cycle_reset)
+ return spu_sync_stop();
+ else
+ return 1;
+}
+
struct op_powerpc_model op_model_cell = {
.reg_setup = cell_reg_setup, .cpu_setup = cell_cpu_setup, .global_start = cell_global_start, .global_stop = cell_global_stop,
+ .sync_start = cell_sync_start,
+ .sync_stop = cell_sync_stop,
.handle_interrupt = cell_handle_interrupt,
};
arch/powerpc/platforms/cell/spufs/sched.c +3 -1
@@ -264,6 +264,7 @@ static void spu_bind_context(struct spu ctx->spu = spu; ctx->ops = &spu_hw_ops; spu->pid = current->pid; + spu->tgid = current->tgid;spu_associate_mm (spu, ctx->owner); spu->ibox_callback = spufs_ibox_callback; spu->wbox_callback = spufs_wbox_callback;
@@ -304,6 +305,7 @@ static void spu_unbind_context(struct sp spu->dma_callback =NULL ;spu_associate_mm (spu,NULL ); spu->pid =0 ; + spu->tgid =0 ; ctx->ops = &spu_backing_ops; ctx->spu =NULL ; spu->flags =0 ;
@@ -590,7 +592,7 @@ void spu_deactivate(struct spu_context * }/** -* spu_yield - yield a physical spu if others are waiting +* spu_yield - yield a physical spu if others are waiting * @ctx: spu context to yield * * Check if there is a higher priority context waiting and if yes
drivers/oprofile/buffer_sync.c +2 -1
@@ -26,8 +26,9 @@#include <linux/profile.h> #include <linux/module.h> #include <linux/fs.h> +#include <linux/oprofile.h> #include <linux/sched.h> - +#include "oprofile_stats.h" #include "event_buffer.h" #include "cpu_buffer.h"
drivers/oprofile/event_buffer.h +1 -19
@@ -19,28 +19,10 @@ void free_event_buffer(void);/* wake up the process sleeping on the event file */ void wake_up_buffer_waiter (void ); - -/* Each escaped entry is prefixed by ESCAPE_CODE -* then one of the following codes, then the -* relevant data. -*/ -#define ESCAPE_CODE ~0UL -#define CTX_SWITCH_CODE 1 -#define CPU_SWITCH_CODE 2 -#define COOKIE_SWITCH_CODE 3 -#define KERNEL_ENTER_SWITCH_CODE 4 -#define KERNEL_EXIT_SWITCH_CODE 5 -#define MODULE_LOADED_CODE 6 -#define CTX_TGID_CODE 7 -#define TRACE_BEGIN_CODE 8 -#define TRACE_END_CODE 9 - +#define INVALID_COOKIE ~0UL#define NO_COOKIE 0UL -/* add data to the event buffer */ -void add_event_entry (unsigned long data); -extern const struct file_operations event_buffer_fops;/* mutex between sync_cpu_buffers() and the
drivers/oprofile/oprof.c +28 -0
@@ -53,9 +53,24 @@ int oprofile_setup(void)* us missing task deaths and eventually oopsing * when trying to process the event buffer. */ +if (oprofile_ops.sync_start) { +int sync_ret = oprofile_ops.sync_start (); +switch (sync_ret) { +case 0 : + goto post_sync; +case 1 : + goto do_generic; +case -1 : + goto out3; +default : + goto out3; + } + } +do_generic:if ((err =sync_start ())) goto out3; +post_sync: is_setup =1 ;mutex_unlock (&start_mutex);return 0 ;
@@ -118,7 +133,20 @@ out:void oprofile_shutdown (void ) {mutex_lock (&start_mutex); +if (oprofile_ops.sync_stop) { +int sync_ret = oprofile_ops.sync_stop (); +switch (sync_ret) { +case 0 : + goto post_sync; +case 1 : + goto do_generic; +default : + goto post_sync; + } + } +do_generic:sync_stop (); +post_sync:if (oprofile_ops.shutdown) oprofile_ops.shutdown (); is_setup =0 ;
include/asm-powerpc/oprofile_impl.h +6 -4
@@ -39,14 +39,16 @@ struct op_system_config {/* Per-arch configuration */ struct op_powerpc_model { -void (*reg_setup) (struct op_counter_config *, +int (*reg_setup) (struct op_counter_config *,struct op_system_config *,int num_counters); -void (*cpu_setup) (struct op_counter_config *); -void (*start) (struct op_counter_config *); -void (*global_start) (struct op_counter_config *); +int (*cpu_setup) (struct op_counter_config *); +int (*start) (struct op_counter_config *); +int (*global_start) (struct op_counter_config *);void (*stop) (void );void (*global_stop) (void ); +int (*sync_start)(void ); +int (*sync_stop)(void );void (*handle_interrupt) (struct pt_regs *,struct op_counter_config *);int num_counters;
include/asm-powerpc/spu.h +4 -0
@@ -137,6 +137,7 @@ struct spu {struct spu_runqueue *rq;unsigned long long timestamp;pid_t pid; +pid_t tgid;int class_0_pending;spinlock_t register_lock;
@@ -195,6 +196,20 @@ extern void spu_associate_mm(struct spustruct mm_struct ;extern void spu_flush_all_slbs (struct mm_struct *mm); +/* This interface allows a profiler (e.g., OProfile) to store a ref +* to spu context information that it creates. This caching technique +* avoids the need to recreate this information after a save/restore
operation.
+ *
+ * Assumes the caller has already incremented the ref count to
+ * profile_info; then spu_context_destroy must call kref_put
+ * on prof_info_kref.
+ */
+void spu_set_profile_private_kref(struct spu_context *ctx,
+ struct kref *prof_info_kref,
+ void ( * prof_info_release) (struct kref *kref));
+
+void *spu_get_profile_private_kref(struct spu_context *ctx); +
/* system callbacks from the SPU */
struct spu_syscall_block {
u64 nr_ret;
include/linux/oprofile.h +35 -0
@@ -17,6 +17,26 @@#include <linux/spinlock.h> #include <asm/atomic.h> +/* Each escaped entry is prefixed by ESCAPE_CODE +* then one of the following codes, then the +* relevant data. +* These #defines live in this file so that arch-specific +* buffer sync'ing code can access them. +*/ +#define ESCAPE_CODE ~0UL +#define CTX_SWITCH_CODE 1 +#define CPU_SWITCH_CODE 2 +#define COOKIE_SWITCH_CODE 3 +#define KERNEL_ENTER_SWITCH_CODE 4 +#define KERNEL_EXIT_SWITCH_CODE 5 +#define MODULE_LOADED_CODE 6 +#define CTX_TGID_CODE 7 +#define TRACE_BEGIN_CODE 8 +#define TRACE_END_CODE 9 +#define XEN_ENTER_SWITCH_CODE 10 +#define SPU_PROFILING_CODE 11 +#define SPU_CTX_SWITCH_CODE 12 +struct super_block ;struct dentry ;struct file_operations ;
@@ -35,6 +55,14 @@ struct oprofile_operations {int (*start)(void );/* Stop delivering interrupts. */ void (*stop)(void ); +/* Arch-specific buffer sync functions. +* Return value = 0: Success +* Return value = -1: Failure +* Return value = 1: Run generic sync function +*/ +int (*sync_start)(void ); +int (*sync_stop)(void ); +/* Initiate a stack backtrace. Optional. */ void (*backtrace)(struct pt_regs *const regs,unsigned int depth);/* CPU identification string. */
@@ -56,6 +84,13 @@ int oprofile_arch_init(struct oprofile_ovoid oprofile_arch_exit (void );/** +* Add data to the event buffer. +* The data passed is free-form, but typically consists of +* file offsets, dcookies, context information, and ESCAPE codes. +*/ +void add_event_entry (unsigned long data); + +/** * Add a sample. This may be called from any context. Pass * smp_processor_id() as cpu. */
arch/powerpc/kernel/time.c +1 -0
@@ -121,6 +121,7 @@ extern struct timezone sys_tz;static long timezone_offset;unsigned long ppc_proc_freq; +EXPORT_SYMBOL (ppc_proc_freq);unsigned long ppc_tb_freq; static u64 tb_last_jiffy __cacheline_aligned_in_smp;
arch/powerpc/platforms/cell/spufs/spufs.h +2 -0
@@ -94,6 +94,8 @@ struct spu_context {struct list_head gang_list;struct spu_gang *gang; +struct kref *prof_priv_kref; +void ( * prof_priv_release) (struct kref *kref);/* owner thread */ pid_t tid;
arch/powerpc/platforms/cell/spufs/context.c +20 -0
@@ -22,6 +22,7 @@#include <linux/fs.h> #include <linux/mm.h> +#include <linux/module.h> #include <linux/slab.h> #include <asm/atomic.h> #include <asm/spu.h>
@@ -81,6 +82,8 @@ void destroy_spu_context(struct kref *krspu_fini_csa (&ctx->csa);if (ctx->gang)spu_gang_remove_ctx (ctx->gang, ctx); +if (ctx->prof_priv_kref) +kref_put (ctx->prof_priv_kref, ctx->prof_priv_release);BUG_ON (!list_empty (&ctx->rq));atomic_dec (&nr_spu_contexts);kfree (ctx);
@@ -169,3 +172,20 @@ void spu_acquire_saved(struct spu_contexif (ctx->state !=SPU_STATE_SAVED )spu_deactivate (ctx); } + +void spu_set_profile_private_kref (struct spu_context *ctx, +struct kref *prof_info_kref, +void ( * prof_info_release) (struct kref *kref)) +{ + ctx->prof_priv_kref = prof_info_kref; + ctx->prof_priv_release = prof_info_release; +} +EXPORT_SYMBOL_GPL (spu_set_profile_private_kref); + +void *spu_get_profile_private_kref (struct spu_context *ctx) +{ +return ctx->prof_priv_kref; +} +EXPORT_SYMBOL_GPL (spu_get_profile_private_kref); + +
include/linux/dcookies.h +1 -0
@@ -12,6 +12,7 @@#ifdef CONFIG_PROFILING +#include <linux/dcache.h> #include <linux/types.h> struct dcookie_user ;
include/linux/elf-em.h +2 -1
@@ -20,7 +20,8 @@#define EM_PARISC 15/* HPPA */ #define EM_SPARC32PLUS 18/* Sun's "v8plus" */ #define EM_PPC 20/* PowerPC */ -#define EM_PPC64 21/* PowerPC64 */ +#define EM_PPC64 21/* PowerPC64 */ +#define EM_SPU 23/* Cell BE SPU */ #define EM_SH 42/* SuperH */ #define EM_SPARCV9 43/* SPARC v9 64-bit */ #define EM_IA_64 50/* HP/Intel IA-64 */
arch/powerpc/oprofile/op_model_rs64.c +7 -3
@@ -88,7 +88,7 @@ static unsigned long reset_value[OP_MAX_static int num_counters; -static void rs64_reg_setup (struct op_counter_config *ctr, +static int rs64_reg_setup (struct op_counter_config *ctr,struct op_system_config *sys,int num_ctrs) {
@@ -100,9 +100,10 @@ static void rs64_reg_setup(struct op_cou reset_value[i] =0x80000000UL - ctr[i].count;/* XXX setup user and kernel profiling */ +return 0 ; } -static void rs64_cpu_setup (struct op_counter_config *ctr) +static int rs64_cpu_setup (struct op_counter_config *ctr) {unsigned int mmcr0;
@@ -125,9 +126,11 @@ static void rs64_cpu_setup(struct op_cou mfspr(SPRN_MMCR0));dbg ("setup on cpu %d, mmcr1 %lx\n" ,smp_processor_id (),mfspr (SPRN_MMCR1 )); + +return 0 ; } -static void rs64_start (struct op_counter_config *ctr) +static int rs64_start (struct op_counter_config *ctr) {int i;unsigned int mmcr0;
@@ -155,6 +158,7 @@ static void rs64_start(struct op_countermtspr (SPRN_MMCR0 , mmcr0);dbg ("start on cpu %d, mmcr0 %x\n" ,smp_processor_id (), mmcr0); +return 0 ; }static void rs64_stop (void )
arch/powerpc/oprofile/op_model_power4.c +8 -3
@@ -30,7 +30,7 @@ static u32 mmcr0_val;static u64 mmcr1_val;static u64 mmcra_val; -static void power4_reg_setup (struct op_counter_config *ctr, +static int power4_reg_setup (struct op_counter_config *ctr,struct op_system_config *sys,int num_ctrs) {
@@ -58,6 +58,8 @@ static void power4_reg_setup(struct op_c mmcr0_val &= ~MMCR0_PROBLEM_DISABLE ; else mmcr0_val |= MMCR0_PROBLEM_DISABLE; + +return 0 ; }extern void ppc64_enable_pmcs (void );
@@ -82,7 +84,7 @@ static inline int mmcra_must_set_sample(return 0 ; } -static void power4_cpu_setup (struct op_counter_config *ctr) +static int power4_cpu_setup (struct op_counter_config *ctr) {unsigned int mmcr0 = mmcr0_val;unsigned long mmcra = mmcra_val;
@@ -109,9 +111,11 @@ static void power4_cpu_setup(struct op_c mfspr(SPRN_MMCR1));dbg ("setup on cpu %d, mmcra %lx\n" ,smp_processor_id (),mfspr (SPRN_MMCRA )); + +return 0 ; } -static void power4_start (struct op_counter_config *ctr) +static int power4_start (struct op_counter_config *ctr) {int i;unsigned int mmcr0;
@@ -146,6 +150,7 @@ static void power4_start(struct op_count oprofile_running =1 ;dbg ("start on cpu %d, mmcr0 %x\n" ,smp_processor_id (), mmcr0); +return 0 ; }static void power4_stop (void )
arch/powerpc/oprofile/op_model_7450.c +10 -4
@@ -81,7 +81,7 @@ static void pmc_stop_ctrs(void)/* Configures the counters on this CPU based on the global * settings */ -static void fsl7450_cpu_setup (struct op_counter_config *ctr) +static int fsl7450_cpu_setup (struct op_counter_config *ctr) {/* freeze all counters */ pmc_stop_ctrs ();
@@ -89,12 +89,14 @@ static void fsl7450_cpu_setup(struct op_mtspr (SPRN_MMCR0 , mmcr0_val);mtspr (SPRN_MMCR1 , mmcr1_val);mtspr (SPRN_MMCR2 , mmcr2_val); + +return 0 ; }#define NUM_CTRS 6/* Configures the global settings for the countes on all CPUs. */ -static void fsl7450_reg_setup (struct op_counter_config *ctr, +static int fsl7450_reg_setup (struct op_counter_config *ctr,struct op_system_config *sys,int num_ctrs) {
@@ -126,10 +128,12 @@ static void fsl7450_reg_setup(struct op_ | mmcr1_event6(ctr[5].event); mmcr2_val =0 ; + +return 0 ; }/* Sets the counters on this CPU to the chosen values, and starts them */ -static void fsl7450_start (struct op_counter_config *ctr) +static int fsl7450_start (struct op_counter_config *ctr) {int i;
@@ -148,6 +152,8 @@ static void fsl7450_start(struct op_counpmc_start_ctrs (); oprofile_running =1 ; + +return 0 ; }/* Stop the counters on this CPU */
@@ -193,7 +199,7 @@ static void fsl7450_handle_interrupt(str/* The freeze bit was set by the interrupt. */ /* Clear the freeze bit, and reenable the interrupt. * The counters won't actually start until the rfi clears -* the PMM bit */ +* the PM/M bit */ pmc_start_ctrs (); }
arch/powerpc/oprofile/op_model_fsl_booke.c +8 -3
@@ -244,7 +244,7 @@ static void dump_pmcs(void) mfpmr(PMRN_PMLCA3), mfpmr(PMRN_PMLCB3)); } -static void fsl_booke_cpu_setup (struct op_counter_config *ctr) +static int fsl_booke_cpu_setup (struct op_counter_config *ctr) {int i;
@@ -258,9 +258,11 @@ static void fsl_booke_cpu_setup(struct oset_pmc_user_kernel (i, ctr[i].user, ctr[i].kernel); } + +return 0 ; } -static void fsl_booke_reg_setup (struct op_counter_config *ctr, +static int fsl_booke_reg_setup (struct op_counter_config *ctr,struct op_system_config *sys,int num_ctrs) {
@@ -276,9 +278,10 @@ static void fsl_booke_reg_setup(struct ofor (i =0 ; i < num_counters; ++i) reset_value[i] =0x80000000UL - ctr[i].count; +return 0 ; } -static void fsl_booke_start (struct op_counter_config *ctr) +static int fsl_booke_start (struct op_counter_config *ctr) {int i;
@@ -308,6 +311,8 @@ static void fsl_booke_start(struct op_copr_debug ("start on cpu %d, pmgc0 %x\n" ,smp_processor_id (),mfpmr (PMRN_PMGC0 )); + +return 0 ; }static void fsl_booke_stop (void )
arch/powerpc/oprofile/op_model_pa6t.c +9 -3
@@ -89,7 +89,7 @@ static inline void ctr_write(unsigned in/* precompute the values to stuff in the hardware registers */ -static void pa6t_reg_setup (struct op_counter_config *ctr, +static int pa6t_reg_setup (struct op_counter_config *ctr,struct op_system_config *sys,int num_ctrs) {
@@ -135,10 +135,12 @@ static void pa6t_reg_setup(struct op_coupr_debug ("reset_value for pmc%u inited to 0x%lx\n" , pmc, reset_value[pmc]); } + +return 0 ; }/* configure registers on this cpu */ -static void pa6t_cpu_setup (struct op_counter_config *ctr) +static int pa6t_cpu_setup (struct op_counter_config *ctr) {u64 mmcr0 = mmcr0_val;u64 mmcr1 = mmcr1_val;
@@ -154,9 +156,11 @@ static void pa6t_cpu_setup(struct op_cou mfspr(SPRN_PA6T_MMCR0));pr_debug ("setup on cpu %d, mmcr1 %016lx\n" ,smp_processor_id (),mfspr (SPRN_PA6T_MMCR1 )); + +return 0 ; } -static void pa6t_start (struct op_counter_config *ctr) +static int pa6t_start (struct op_counter_config *ctr) {int i;
@@ -174,6 +178,8 @@ static void pa6t_start(struct op_counter oprofile_running =1 ;pr_debug ("start on cpu %d, mmcr0 %lx\n" ,smp_processor_id (), mmcr0); + +return 0 ; }static void pa6t_stop (void )