powerpc/oprofile: IBM CELL: add SPU event profiling support
[safe/jmp/linux-2.6] / arch / powerpc / oprofile / cell / pr_util.h
1  /*
2  * Cell Broadband Engine OProfile Support
3  *
4  * (C) Copyright IBM Corporation 2006
5  *
6  * Author: Maynard Johnson <maynardj@us.ibm.com>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version
11  * 2 of the License, or (at your option) any later version.
12  */
13
14 #ifndef PR_UTIL_H
15 #define PR_UTIL_H
16
17 #include <linux/cpumask.h>
18 #include <linux/oprofile.h>
19 #include <asm/cell-pmu.h>
20 #include <asm/cell-regs.h>
21 #include <asm/spu.h>
22
23 /* Defines used for sync_start */
24 #define SKIP_GENERIC_SYNC 0
25 #define SYNC_START_ERROR -1
26 #define DO_GENERIC_SYNC 1
27 #define SPUS_PER_NODE   8
28 #define DEFAULT_TIMER_EXPIRE  (HZ / 10)
29
30 extern struct delayed_work spu_work;
31 extern int spu_prof_running;
32
33 #define TRACE_ARRAY_SIZE 1024
34
35 extern spinlock_t oprof_spu_smpl_arry_lck;
36
37 struct spu_overlay_info {       /* map of sections within an SPU overlay */
38         unsigned int vma;       /* SPU virtual memory address from elf */
39         unsigned int size;      /* size of section from elf */
40         unsigned int offset;    /* offset of section into elf file */
41         unsigned int buf;
42 };
43
44 struct vma_to_fileoffset_map {  /* map of sections within an SPU program */
45         struct vma_to_fileoffset_map *next;     /* list pointer */
46         unsigned int vma;       /* SPU virtual memory address from elf */
47         unsigned int size;      /* size of section from elf */
48         unsigned int offset;    /* offset of section into elf file */
49         unsigned int guard_ptr;
50         unsigned int guard_val;
51         /*
52          * The guard pointer is an entry in the _ovly_buf_table,
53          * computed using ovly.buf as the index into the table.  Since
54          * ovly.buf values begin at '1' to reference the first (or 0th)
55          * entry in the _ovly_buf_table, the computation subtracts 1
56          * from ovly.buf.
57          * The guard value is stored in the _ovly_buf_table entry and
58          * is an index (starting at 1) back to the _ovly_table entry
59          * that is pointing at this _ovly_buf_table entry.  So, for
60          * example, for an overlay scenario with one overlay segment
61          * and two overlay sections:
62          *      - Section 1 points to the first entry of the
63          *        _ovly_buf_table, which contains a guard value
64          *        of '1', referencing the first (index=0) entry of
65          *        _ovly_table.
66          *      - Section 2 points to the second entry of the
67          *        _ovly_buf_table, which contains a guard value
68          *        of '2', referencing the second (index=1) entry of
69          *        _ovly_table.
70          */
71
72 };
73
74 struct spu_buffer {
75         int last_guard_val;
76         int ctx_sw_seen;
77         unsigned long *buff;
78         unsigned int head, tail;
79 };
80
81
82 /* The three functions below are for maintaining and accessing
83  * the vma-to-fileoffset map.
84  */
85 struct vma_to_fileoffset_map *create_vma_map(const struct spu *spu,
86                                              u64 objectid);
87 unsigned int vma_map_lookup(struct vma_to_fileoffset_map *map,
88                             unsigned int vma, const struct spu *aSpu,
89                             int *grd_val);
90 void vma_map_free(struct vma_to_fileoffset_map *map);
91
92 /*
93  * Entry point for SPU profiling.
94  * cycles_reset is the SPU_CYCLES count value specified by the user.
95  */
96 int start_spu_profiling_cycles(unsigned int cycles_reset);
97 void start_spu_profiling_events(void);
98
99 void stop_spu_profiling_cycles(void);
100 void stop_spu_profiling_events(void);
101
102 /* add the necessary profiling hooks */
103 int spu_sync_start(void);
104
105 /* remove the hooks */
106 int spu_sync_stop(void);
107
108 /* Record SPU program counter samples to the oprofile event buffer. */
109 void spu_sync_buffer(int spu_num, unsigned int *samples,
110                      int num_samples);
111
112 void set_spu_profiling_frequency(unsigned int freq_khz, unsigned int cycles_reset);
113
114 #endif    /* PR_UTIL_H */