Sundarajan Srinivasan | 1b03fe2 | 2014-12-02 13:20:56 -0800 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Guojun Jin | f7f90f8 | 2018-08-16 18:09:23 -0700 | [diff] [blame] | 3 | * Copyright (c) 2014, 2018 The Linux Foundation. All rights reserved. |
Sundarajan Srinivasan | 1b03fe2 | 2014-12-02 13:20:56 -0800 | [diff] [blame] | 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 | |
Guojun Jin | f7f90f8 | 2018-08-16 18:09:23 -0700 | [diff] [blame] | 22 | #ifndef _NSS_PROFILE_SAMPLE_H_ |
| 23 | #define _NSS_PROFILE_SAMPLE_H_ |
Sundarajan Srinivasan | 1b03fe2 | 2014-12-02 13:20:56 -0800 | [diff] [blame] | 24 | |
Guojun Jin | f7f90f8 | 2018-08-16 18:09:23 -0700 | [diff] [blame] | 25 | #define NSS_PROFILE_STACK_WORDS 4 |
Sundarajan Srinivasan | 1b03fe2 | 2014-12-02 13:20:56 -0800 | [diff] [blame] | 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 | */ |
Guojun Jin | f7f90f8 | 2018-08-16 18:09:23 -0700 | [diff] [blame] | 35 | #define NSS_PROFILE_I_BLOCKED_BIT 5 |
| 36 | #define NSS_PROFILE_I_BLOCKED (1 << NSS_PROFILE_I_BLOCKED_BIT) |
| 37 | #define NSS_PROFILE_D_BLOCKED_BIT 4 |
| 38 | #define NSS_PROFILE_D_BLOCKED (1 << NSS_PROFILE_D_BLOCKED_BIT) |
| 39 | #define NSS_PROFILE_BTB_SHIFT 6 |
Sundarajan Srinivasan | 1b03fe2 | 2014-12-02 13:20:56 -0800 | [diff] [blame] | 40 | |
Guojun Jin | f7f90f8 | 2018-08-16 18:09:23 -0700 | [diff] [blame] | 41 | struct nss_profile_sample { |
| 42 | uint32_t pc; /* PC value */ |
| 43 | uint32_t pid; /* pid for the current process, or 0 if NOMMU or unmapped space */ |
| 44 | uint16_t active; /* threads are active - for accurate counting */ |
| 45 | uint16_t d_blocked; /* threads are blocked due to D cache misses : may be removed */ |
| 46 | uint16_t i_blocked; /* threads are blocked due to I cache misses */ |
| 47 | uint8_t cond_codes; /* for branch prediction */ |
| 48 | uint8_t thread; /* 4-bit thread number */ |
| 49 | uint32_t a_reg; /* source An if PC points to a calli. Otherwise a5 contents for parent of leaf function */ |
| 50 | uint32_t parent[NSS_PROFILE_STACK_WORDS]; |
| 51 | /* return addresses from stack, to find the caller */ |
Sundarajan Srinivasan | 1b03fe2 | 2014-12-02 13:20:56 -0800 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | |
| 55 | /* |
Guojun Jin | f7f90f8 | 2018-08-16 18:09:23 -0700 | [diff] [blame] | 56 | * packet size for profile communication = MSS - tcp/ip headers |
Sundarajan Srinivasan | 1b03fe2 | 2014-12-02 13:20:56 -0800 | [diff] [blame] | 57 | */ |
Guojun Jin | f7f90f8 | 2018-08-16 18:09:23 -0700 | [diff] [blame] | 58 | #define NSS_PROFILE_MAX_PACKET_SIZE 1440 |
Sundarajan Srinivasan | 1b03fe2 | 2014-12-02 13:20:56 -0800 | [diff] [blame] | 59 | |
Guojun Jin | f7f90f8 | 2018-08-16 18:09:23 -0700 | [diff] [blame] | 60 | #define NSS_PROFILE_MAX_COUNTERS ((NSS_PROFILE_MAX_PACKET_SIZE - sizeof(struct profile_header_counters)) / (PROFILE_COUNTER_NAME_LENGTH + 4)) |
Sundarajan Srinivasan | 1b03fe2 | 2014-12-02 13:20:56 -0800 | [diff] [blame] | 61 | |
| 62 | struct profile_counter { |
| 63 | char name[PROFILE_COUNTER_NAME_LENGTH]; |
| 64 | uint32_t value; |
| 65 | }; |
| 66 | |
| 67 | /* |
Guojun Jin | f7f90f8 | 2018-08-16 18:09:23 -0700 | [diff] [blame] | 68 | * NSS HW counters and CPU threads |
| 69 | */ |
| 70 | #define NSS_HW_COUNTERS 8 |
| 71 | #define NSS_CPU_THREADS 12 |
| 72 | |
| 73 | /* |
Sundarajan Srinivasan | 1b03fe2 | 2014-12-02 13:20:56 -0800 | [diff] [blame] | 74 | * sampling period info cross all modules -- use extended struct to avoid copy |
| 75 | */ |
| 76 | struct profile_ext_header { |
Guojun Jin | f7f90f8 | 2018-08-16 18:09:23 -0700 | [diff] [blame] | 77 | uint16_t d_blocked; /* threads are blocked due to D cache misses */ |
| 78 | uint16_t i_blocked; /* threads are blocked due to I cache misses */ |
| 79 | uint16_t high; /* threads were enabled high priority -- unused */ |
| 80 | uint16_t enabled_threads; /* threads were enabled at the last sample time */ |
| 81 | uint16_t hrt; /* HRT threads */ |
| 82 | uint8_t profiler_tid; /* thread running the profile sampler */ |
| 83 | uint8_t sample_sets; /* typical 5-8 sets, and may be 9 - see design doc for details */ |
| 84 | uint32_t sets_map; /* a set map uses a nibble, 8 maps and 9th is derived */ |
| 85 | uint32_t clocks; /* system clock timer at last sample */ |
| 86 | uint32_t inst_count[NSS_CPU_THREADS]; /* sampled instruction counts at most recent sample */ |
| 87 | uint32_t stats[NSS_HW_COUNTERS]; /* contents of the cache statistics counters */ |
Sundarajan Srinivasan | 1b03fe2 | 2014-12-02 13:20:56 -0800 | [diff] [blame] | 88 | }; |
| 89 | |
Guojun Jin | f7f90f8 | 2018-08-16 18:09:23 -0700 | [diff] [blame] | 90 | #endif /* _NSS_PROFILE_SAMPLE_H_ */ |