3 * arch/ubicom32/mach-common/profpkt.c
4 * Ubicom32 Profiler packet formats for communication between the linux proc driver and the profiler display tool
6 * (C) Copyright 2009, Ubicom, Inc.
8 * This file is part of the Ubicom32 Linux Kernel Port.
10 * The Ubicom32 Linux Kernel Port is free software: you can redistribute
11 * it and/or modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation, either version 2 of the
13 * License, or (at your option) any later version.
15 * The Ubicom32 Linux Kernel Port is distributed in the hope that it
16 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
17 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
18 * the GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with the Ubicom32 Linux Kernel Port. If not,
22 * see <http://www.gnu.org/licenses/>.
25 #define PROFILE_PORT 51080
26 #define PROFILE_POSIX_NAME_LENGTH 32
29 * profile UDP packet format for communicating between ip3k and host
31 * every packet starts with a header, followed by samples.
32 * samples are only taken for non-hrt threads that are
35 #define PROF_MAGIC 0x3ea0
36 #define PROF_MAGIC_COUNTERS 0x9ea0
37 #define PROF_MAGIC_MAPS 0xaea0
41 * 1 to 4 were before 6.0 release, development versions
42 * 5 was forward compatible version, shipped with 6.0 and 6.1
43 * 6 adds heap packets, and clock_freq to header, shipped with 6.2
44 * 7 adds a sequence numbers to check for dropped packets, shipped with 6.3.5
45 * 8 adds mqueue timing information, shipped with 6.3.5
46 * 9 adds sdram heap size information, shipped with 6.4
47 * 10 adds heapmem heap callers and long latency stack traces. shipped with 6.4
48 * 11 adds support for Mars (IP5K). shipped with 6.10
49 * 12 adds more support for Mars. Shipped with 7.0
50 * 13 adds per sample latency measurement. Shipped with 7.2
51 * 14 changes the heap format and adds a string packet. Shipped with 7.4
52 * 15 adds dsr stats and posix. shipped with 7.6
53 * 16 corrects maximum packet count for Ares. ships with 7.9
54 * 17 adds a5 register value to sample
57 #define PROFILE_VERSION 17
58 #define PROFILE_MAX_PACKET_SIZE 1440
60 #define PROFILE_MAX_THREADS 16
63 * each packet starts with a profile_header, then sample_count samples
64 * samples are gprof samples of pc, the return address, condition codes, and
67 struct profile_header {
68 u16_t magic; /* magic number and version */
69 u8_t header_size; /* number of bytes in profile header */
70 u8_t sample_count; /* number of samples in the packet */
71 u32_t clocks; /* clock counter value */
72 u32_t instruction_count[PROFILE_MAX_THREADS];
73 /* instructions executed per thread */
74 u32_t profile_instructions; /* instructions executed by profiler mainline */
75 u16_t enabled; /* which threads are enabled */
76 u16_t hrt; /* which threads are hrt */
77 u16_t high; /* which threads are high priority */
78 u16_t profiler_thread; /* which thread runs the profiler */
79 u32_t heap_free; /* current free on-cihp heap space in bytes */
80 u32_t heap_low_water; /* on-chip heap low water mark */
81 u32_t netpage_free; /* number of free on-chip net pages */
82 u32_t netpage_low_water; /* low water mark on free on-chip netpages */
83 u32_t min_sp[PROFILE_MAX_THREADS];
84 /* stack pointer values per thread */
85 u32_t clock_freq; /* clock frequency (Hz) of system being analyzed */
86 u32_t seq_num; /* to detect dropped profiler packets */
87 u32_t timing_sequence; /* sample number since boot */
88 u32_t timing_interval; /* second per sample timing interval */
89 u32_t timing_worst_time; /* duration of longest finction called, in core clocks */
90 u32_t timing_function; /* address of longest function */
91 u32_t timing_average; /* average time of all functions in last interval */
92 u32_t timing_count; /* number of functions called in last interval */
93 u32_t extheap_free; /* current free extmem heap space in bytes */
94 u32_t extheap_low_water; /* extmem heap low water mark */
95 u32_t cpu_id; /* CHIP_ID register contents */
96 u32_t perf_counters[4]; /* contents of the CPU performance counters */
97 u8_t perf_config[4]; /* what is being counted */
98 u32_t ddr_freq; /* DDR clock frequency */
99 u32_t extnetpage_free; /* number of free off chip net pages */
100 u32_t extnetpage_low_water; /* low water mark on off-chip free netpages */
101 u32_t dsr_max_latency; /* max time to process a dsr interrupt, in clocks, since last packet */
102 u32_t dsr_ave_latency; /* average dsr latency over last DSR_STATS_RECENT_COUNT interrupts */
103 u32_t dsr_count; /* number of dsr interrupts since last packet */
106 struct profile_header_counters {
108 u16_t ultra_count; /* how many ultra counters follow this */
109 u32_t ultra_sample_time; /* in chip clocks */
110 u32_t linux_count; /* how many linux counters follow this */
111 u32_t linux_sample_time;
115 * values chosen so all counter values fit in a single 1400 byte UDP packet
117 #define PROFILE_COUNTER_NAME_LENGTH 20
118 #define PROFILE_MAX_COUNTERS ((PROFILE_MAX_PACKET_SIZE - sizeof(struct profile_header_counters)) / (PROFILE_COUNTER_NAME_LENGTH + 4))
120 struct profile_counter_pkt {
121 char name[PROFILE_COUNTER_NAME_LENGTH];
126 * send memory maps from linux to profiler tool
129 struct profile_header_maps {
135 #define PROFILE_MAP_NUM_TYPES 32
137 /* types 0-15: size field is order. True size is 2^order */
138 #define PROFILE_MAP_TYPE_UNKNOWN 0
139 #define PROFILE_MAP_TYPE_FREE 1
140 #define PROFILE_MAP_TYPE_SMALL 2
141 #define PROFILE_MAP_TYPE_FS 3
142 /* types 16-31: size field is pages. True size is (1 << PAGE_SHIFT) * size */
143 #define PROFILE_MAP_SIZE_TYPE 16
144 #define PROFILE_MAP_TYPE_TEXT 16
145 #define PROFILE_MAP_TYPE_STACK 17
146 #define PROFILE_MAP_TYPE_APP_DATA 18
147 #define PROFILE_MAP_TYPE_CACHE 19
148 #define PROFILE_MAP_RESERVED 24
150 #define PROFILE_MAP_TYPE_SHIFT 11
151 #define PROFILE_MAP_SIZE_MASK 0x7ff
154 u16_t start; /* start page number of segment, relative to start of DRAM */
155 u16_t type_size; /* type (4 bits) of the segment and size in pages (12 bits) */
158 #define PROFILE_MAX_MAPS (PROFILE_MAX_PACKET_SIZE - sizeof(struct profile_header_maps)) / sizeof(struct profile_map)