18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci /* 38c2ecf20Sopenharmony_ci * Cell Broadband Engine OProfile Support 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * (C) Copyright IBM Corporation 2006 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Author: Maynard Johnson <maynardj@us.ibm.com> 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#ifndef PR_UTIL_H 118c2ecf20Sopenharmony_ci#define PR_UTIL_H 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include <linux/cpumask.h> 148c2ecf20Sopenharmony_ci#include <linux/oprofile.h> 158c2ecf20Sopenharmony_ci#include <asm/cell-pmu.h> 168c2ecf20Sopenharmony_ci#include <asm/cell-regs.h> 178c2ecf20Sopenharmony_ci#include <asm/spu.h> 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_ci/* Defines used for sync_start */ 208c2ecf20Sopenharmony_ci#define SKIP_GENERIC_SYNC 0 218c2ecf20Sopenharmony_ci#define SYNC_START_ERROR -1 228c2ecf20Sopenharmony_ci#define DO_GENERIC_SYNC 1 238c2ecf20Sopenharmony_ci#define SPUS_PER_NODE 8 248c2ecf20Sopenharmony_ci#define DEFAULT_TIMER_EXPIRE (HZ / 10) 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ciextern struct delayed_work spu_work; 278c2ecf20Sopenharmony_ciextern int spu_prof_running; 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci#define TRACE_ARRAY_SIZE 1024 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ciextern spinlock_t oprof_spu_smpl_arry_lck; 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_cistruct spu_overlay_info { /* map of sections within an SPU overlay */ 348c2ecf20Sopenharmony_ci unsigned int vma; /* SPU virtual memory address from elf */ 358c2ecf20Sopenharmony_ci unsigned int size; /* size of section from elf */ 368c2ecf20Sopenharmony_ci unsigned int offset; /* offset of section into elf file */ 378c2ecf20Sopenharmony_ci unsigned int buf; 388c2ecf20Sopenharmony_ci}; 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_cistruct vma_to_fileoffset_map { /* map of sections within an SPU program */ 418c2ecf20Sopenharmony_ci struct vma_to_fileoffset_map *next; /* list pointer */ 428c2ecf20Sopenharmony_ci unsigned int vma; /* SPU virtual memory address from elf */ 438c2ecf20Sopenharmony_ci unsigned int size; /* size of section from elf */ 448c2ecf20Sopenharmony_ci unsigned int offset; /* offset of section into elf file */ 458c2ecf20Sopenharmony_ci unsigned int guard_ptr; 468c2ecf20Sopenharmony_ci unsigned int guard_val; 478c2ecf20Sopenharmony_ci /* 488c2ecf20Sopenharmony_ci * The guard pointer is an entry in the _ovly_buf_table, 498c2ecf20Sopenharmony_ci * computed using ovly.buf as the index into the table. Since 508c2ecf20Sopenharmony_ci * ovly.buf values begin at '1' to reference the first (or 0th) 518c2ecf20Sopenharmony_ci * entry in the _ovly_buf_table, the computation subtracts 1 528c2ecf20Sopenharmony_ci * from ovly.buf. 538c2ecf20Sopenharmony_ci * The guard value is stored in the _ovly_buf_table entry and 548c2ecf20Sopenharmony_ci * is an index (starting at 1) back to the _ovly_table entry 558c2ecf20Sopenharmony_ci * that is pointing at this _ovly_buf_table entry. So, for 568c2ecf20Sopenharmony_ci * example, for an overlay scenario with one overlay segment 578c2ecf20Sopenharmony_ci * and two overlay sections: 588c2ecf20Sopenharmony_ci * - Section 1 points to the first entry of the 598c2ecf20Sopenharmony_ci * _ovly_buf_table, which contains a guard value 608c2ecf20Sopenharmony_ci * of '1', referencing the first (index=0) entry of 618c2ecf20Sopenharmony_ci * _ovly_table. 628c2ecf20Sopenharmony_ci * - Section 2 points to the second entry of the 638c2ecf20Sopenharmony_ci * _ovly_buf_table, which contains a guard value 648c2ecf20Sopenharmony_ci * of '2', referencing the second (index=1) entry of 658c2ecf20Sopenharmony_ci * _ovly_table. 668c2ecf20Sopenharmony_ci */ 678c2ecf20Sopenharmony_ci 688c2ecf20Sopenharmony_ci}; 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_cistruct spu_buffer { 718c2ecf20Sopenharmony_ci int last_guard_val; 728c2ecf20Sopenharmony_ci int ctx_sw_seen; 738c2ecf20Sopenharmony_ci unsigned long *buff; 748c2ecf20Sopenharmony_ci unsigned int head, tail; 758c2ecf20Sopenharmony_ci}; 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci/* The three functions below are for maintaining and accessing 798c2ecf20Sopenharmony_ci * the vma-to-fileoffset map. 808c2ecf20Sopenharmony_ci */ 818c2ecf20Sopenharmony_cistruct vma_to_fileoffset_map *create_vma_map(const struct spu *spu, 828c2ecf20Sopenharmony_ci unsigned long objectid); 838c2ecf20Sopenharmony_ciunsigned int vma_map_lookup(struct vma_to_fileoffset_map *map, 848c2ecf20Sopenharmony_ci unsigned int vma, const struct spu *aSpu, 858c2ecf20Sopenharmony_ci int *grd_val); 868c2ecf20Sopenharmony_civoid vma_map_free(struct vma_to_fileoffset_map *map); 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci/* 898c2ecf20Sopenharmony_ci * Entry point for SPU profiling. 908c2ecf20Sopenharmony_ci * cycles_reset is the SPU_CYCLES count value specified by the user. 918c2ecf20Sopenharmony_ci */ 928c2ecf20Sopenharmony_ciint start_spu_profiling_cycles(unsigned int cycles_reset); 938c2ecf20Sopenharmony_civoid start_spu_profiling_events(void); 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_civoid stop_spu_profiling_cycles(void); 968c2ecf20Sopenharmony_civoid stop_spu_profiling_events(void); 978c2ecf20Sopenharmony_ci 988c2ecf20Sopenharmony_ci/* add the necessary profiling hooks */ 998c2ecf20Sopenharmony_ciint spu_sync_start(void); 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ci/* remove the hooks */ 1028c2ecf20Sopenharmony_ciint spu_sync_stop(void); 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci/* Record SPU program counter samples to the oprofile event buffer. */ 1058c2ecf20Sopenharmony_civoid spu_sync_buffer(int spu_num, unsigned int *samples, 1068c2ecf20Sopenharmony_ci int num_samples); 1078c2ecf20Sopenharmony_ci 1088c2ecf20Sopenharmony_civoid set_spu_profiling_frequency(unsigned int freq_khz, unsigned int cycles_reset); 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci#endif /* PR_UTIL_H */ 111