Sundarajan Srinivasan | 1b03fe2 | 2014-12-02 13:20:56 -0800 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
| 3 | * Copyright (c) 2014, The Linux Foundation. All rights reserved. |
| 4 | * Permission to use, copy, modify, and/or distribute this software for |
| 5 | * any purpose with or without fee is hereby granted, provided that the |
| 6 | * above copyright notice and this permission notice appear in all copies. |
| 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 10 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 12 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 13 | * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 14 | ************************************************************************** |
| 15 | */ |
| 16 | |
| 17 | /* |
| 18 | * profilesample.h |
| 19 | * Sample format for profiling |
| 20 | */ |
| 21 | |
| 22 | #ifndef _PROFILE_SAMPLE_H_ |
| 23 | #define _PROFILE_SAMPLE_H_ |
| 24 | |
| 25 | #define PROFILE_STACK_WORDS 4 |
| 26 | |
| 27 | /* |
| 28 | * Each sample is for an enabled thread, not including the profiling thread. |
| 29 | * HRT thread sampling is optional. |
| 30 | * Sampled threads may be active or inactive. Samples are included in thread number |
| 31 | * order, so each sample interval has a set of samples starting with one from thread 0 |
| 32 | * |
| 33 | * Samples include bits indicating if this thread is blocked |
| 34 | */ |
| 35 | #define PROFILE_I_BLOCKED_BIT 5 |
| 36 | #define PROFILE_I_BLOCKED (1 << PROFILE_I_BLOCKED_BIT) |
| 37 | #define PROFILE_D_BLOCKED_BIT 4 |
| 38 | #define PROFILE_D_BLOCKED (1 << PROFILE_D_BLOCKED_BIT) |
| 39 | #define PROFILE_BTB_SHIFT 6 |
| 40 | |
| 41 | #if !defined __unix__ && !defined __ELF__ && !defined __GNUC_ |
| 42 | typedef unsigned char uint8_t; |
| 43 | typedef unsigned short uint16_t; |
| 44 | typedef unsigned int uint32_t; |
| 45 | #endif |
| 46 | |
| 47 | struct profile_sample { |
| 48 | uint32_t pc; // PC value |
| 49 | uint32_t pid; // pid for the current process, or 0 if NOMMU or unmapped space |
| 50 | uint16_t active; // threads are active - for accurate counting |
| 51 | uint16_t d_blocked; // threads are blocked due to D cache misses : may be removed |
| 52 | uint16_t i_blocked; // threads are blocked due to I cache misses |
| 53 | uint8_t cond_codes; // for branch prediction |
| 54 | uint8_t thread; // 4-bit thread number |
| 55 | uint32_t a_reg; // source An if PC points to a calli. Otherwise a5 contents for parent of leaf function |
| 56 | uint32_t parent[PROFILE_STACK_WORDS]; |
| 57 | // return addresses from stack, to find the caller |
| 58 | }; |
| 59 | |
| 60 | |
| 61 | /* |
| 62 | * variables for all components/modules |
| 63 | */ |
| 64 | #ifdef ARCH_NUM_THREADS |
| 65 | #define PROFILE_MAX_THREADS ARCH_NUM_THREADS |
| 66 | #else |
| 67 | #define PROFILE_MAX_THREADS 12 |
| 68 | #endif |
| 69 | |
| 70 | /* |
| 71 | * common variables cross profile components/modules |
| 72 | */ |
| 73 | #define PROFILE_MAX_PACKET_SIZE 1440 // MSS - tcp/ip headers |
| 74 | |
| 75 | /* |
| 76 | * values chosen so all counter values fit in a single 1400 byte UDP packet |
| 77 | */ |
| 78 | #define PROFILE_COUNTERS 8 |
| 79 | #define PROFILE_COUNTER_NAME_LENGTH 20 |
| 80 | #define PROFILE_MAX_APP_COUNTERS 24 |
| 81 | |
| 82 | #define PROFILE_MAX_COUNTERS ((PROFILE_MAX_PACKET_SIZE - sizeof(struct profile_header_counters)) / (PROFILE_COUNTER_NAME_LENGTH + 4)) |
| 83 | |
| 84 | struct profile_counter { |
| 85 | char name[PROFILE_COUNTER_NAME_LENGTH]; |
| 86 | uint32_t value; |
| 87 | }; |
| 88 | |
| 89 | /* |
| 90 | * sampling period info cross all modules -- use extended struct to avoid copy |
| 91 | */ |
| 92 | struct profile_ext_header { |
| 93 | uint16_t d_blocked; // threads are blocked due to D cache misses |
| 94 | uint16_t i_blocked; // threads are blocked due to I cache misses |
| 95 | uint16_t high; // threads were enabled high priority -- unused |
| 96 | uint16_t enabled_threads; // threads were enabled at the last sample time |
| 97 | uint16_t hrt; // HRT threads |
| 98 | uint8_t profiler_tid; // thread running the profile sampler |
| 99 | uint8_t sample_sets; // typical 5-8 sets, and may be 9 - see design doc for details |
| 100 | uint32_t sets_map; // a set map uses a nibble, 8 maps and 9th is derived |
| 101 | uint32_t clocks; // system clock timer at last sample |
| 102 | uint32_t inst_count[PROFILE_MAX_THREADS]; // sampled instruction counts at most recent sample |
| 103 | uint32_t stats[PROFILE_COUNTERS]; // contents of the cache statistics counters |
| 104 | }; |
| 105 | |
| 106 | #endif // _PROFILE_SAMPLE_H_ |