OProfile - Add support to OProfile for profiling CELL BE - update
Subsystems (3)
PATCH 2/2 OProfile - Add support to OProfile for profiling CELL BE - update
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. Exports spu_set_profile_private_kref and spu_get_profile_private_kref which are used by OProfile to store private profile information in spufs data structures.
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
Moved number_of_online_nodes() from pr_util.h to spu_task_sync.c and dropped the inline as it is too big.
Fixed a number of style issues.
Added some comments for structs and memory barriers. Changed set_profiling_frequency() to set_spu_profiling_frequency(). Aquire mmap_sem around vma walk.
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 +97 -0
97 lines not on this page · raw message
arch/powerpc/oprofile/cell/spu_profiler.c new file +221 -0
221 lines not on this page · raw message
arch/powerpc/oprofile/cell/spu_task_sync.c new file +484 -0
484 lines not on this page · raw message
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 +7 -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 +527 -80
891 lines not on this page · raw message
arch/powerpc/platforms/cell/spufs/sched.c +3 -1
@@ -268,6 +268,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;
@@ -308,6 +309,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 ;
@@ -594,7 +596,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 +15 -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 )