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 | /* |
Guojun Jin | f7f90f8 | 2018-08-16 18:09:23 -0700 | [diff] [blame] | 18 | * nss profile node.h |
| 19 | * device node for the profiler, for communicating between FW and GUI via host |
Sundarajan Srinivasan | 1b03fe2 | 2014-12-02 13:20:56 -0800 | [diff] [blame] | 20 | */ |
| 21 | |
| 22 | #include "profilesample.h" |
| 23 | |
Guojun Jin | f7f90f8 | 2018-08-16 18:09:23 -0700 | [diff] [blame] | 24 | #define NSS_PROFILE_HD_MAGIC 0x4F525000 /* 0 + "PRO" */ |
| 25 | #define NSS_PROFILE_HD_MAGIC_REV 0x0050524F /* different endian */ |
| 26 | #define NSS_PROFILE_HD_MMASK 0xFFFFFF00 /* 1st byte is Rx/Tx cmd */ |
| 27 | #define NSS_PROFILE_HD_MMASK_REV 0x00FFFFFF |
Sundarajan Srinivasan | 1b03fe2 | 2014-12-02 13:20:56 -0800 | [diff] [blame] | 28 | |
Guojun Jin | f7f90f8 | 2018-08-16 18:09:23 -0700 | [diff] [blame] | 29 | struct nss_profile_sample_ctrl { |
| 30 | uint32_t psc_magic; /* MAGIC + cmd for packet and endianess check */ |
Sundarajan Srinivasan | 1b03fe2 | 2014-12-02 13:20:56 -0800 | [diff] [blame] | 31 | |
| 32 | /* |
Guojun Jin | f7f90f8 | 2018-08-16 18:09:23 -0700 | [diff] [blame] | 33 | * controlling data need to be sent to and used by upper layer (HLOS). |
Sundarajan Srinivasan | 1b03fe2 | 2014-12-02 13:20:56 -0800 | [diff] [blame] | 34 | */ |
Guojun Jin | f7f90f8 | 2018-08-16 18:09:23 -0700 | [diff] [blame] | 35 | uint16_t ps_count; /* number of valid samples */ |
| 36 | uint16_t ps_max_samples; /* how many samples can be in the samples array */ |
| 37 | uint32_t ps_dropped; /* how many samples did the profiler drop due to buffer overruns */ |
Sundarajan Srinivasan | 1b03fe2 | 2014-12-02 13:20:56 -0800 | [diff] [blame] | 38 | |
| 39 | /* |
| 40 | * info data -- sent to remote profiler tool (need swap) |
| 41 | */ |
Guojun Jin | f7f90f8 | 2018-08-16 18:09:23 -0700 | [diff] [blame] | 42 | struct profile_ext_header ex_hd; |
Sundarajan Srinivasan | 1b03fe2 | 2014-12-02 13:20:56 -0800 | [diff] [blame] | 43 | |
| 44 | }; |
| 45 | |
| 46 | /* |
| 47 | * # of sample buffers in pbuf payload |
| 48 | */ |
| 49 | #ifndef PBUF_PAYLOAD_SIZE |
Guojun Jin | f7f90f8 | 2018-08-16 18:09:23 -0700 | [diff] [blame] | 50 | #define PBUF_PAYLOAD_SIZE 1792 /* for HLOS driver: must sync with pbuf_public */ |
Sundarajan Srinivasan | 1b03fe2 | 2014-12-02 13:20:56 -0800 | [diff] [blame] | 51 | typedef enum meta_types { |
| 52 | PINGPONG_EMPTY, |
| 53 | PINGPONG_FULL, |
| 54 | PINGPONG_INUSE, |
| 55 | } flowctrl_t; |
| 56 | #else |
Guojun Jin | f7f90f8 | 2018-08-16 18:09:23 -0700 | [diff] [blame] | 57 | typedef enum pnode_c2h_metadata_types flowctrl_t; /* for NSS driver */ |
Sundarajan Srinivasan | 1b03fe2 | 2014-12-02 13:20:56 -0800 | [diff] [blame] | 58 | #endif |
| 59 | |
Guojun Jin | f7f90f8 | 2018-08-16 18:09:23 -0700 | [diff] [blame] | 60 | #define MAX_SAMPLES_PER_PBUF ((PBUF_PAYLOAD_SIZE - sizeof(struct nss_profile_sample_ctrl)) / sizeof(struct nss_profile_sample)) |
Sundarajan Srinivasan | 1b03fe2 | 2014-12-02 13:20:56 -0800 | [diff] [blame] | 61 | |
| 62 | struct n2h_meta_header { |
Guojun Jin | f7f90f8 | 2018-08-16 18:09:23 -0700 | [diff] [blame] | 63 | flowctrl_t md_type; /* N2H (NSS) and receiver (HLOS) flow control (meta type) */ |
| 64 | uint32_t d_len; /* total data length start from psc_header */ |
Sundarajan Srinivasan | 1b03fe2 | 2014-12-02 13:20:56 -0800 | [diff] [blame] | 65 | }; |
| 66 | |
Guojun Jin | f7f90f8 | 2018-08-16 18:09:23 -0700 | [diff] [blame] | 67 | struct nss_profile_session { /* use for per session start */ |
| 68 | uint32_t hd_magic; /* common ovarlay in all headers */ |
Guojun Jin | 3deae8c | 2016-08-23 15:51:21 -0700 | [diff] [blame] | 69 | uint8_t num_counters; /* # performance (app) counters registered (changeable) */ |
| 70 | uint8_t unused1B; |
| 71 | uint8_t nc_sts_sel_thrA; |
| 72 | uint8_t nc_sts_sel_thrB; |
Sundarajan Srinivasan | 1b03fe2 | 2014-12-02 13:20:56 -0800 | [diff] [blame] | 73 | uint32_t ocm_size; |
| 74 | uint32_t sram_start; |
| 75 | |
Guojun Jin | f7f90f8 | 2018-08-16 18:09:23 -0700 | [diff] [blame] | 76 | uint32_t rate; /* sampling rate */ |
| 77 | uint32_t cpu_id; /* chip_id register */ |
| 78 | uint32_t cpu_freq; /* chip clock */ |
| 79 | uint32_t ddr_freq; /* DDR MEM speed */ |
Sundarajan Srinivasan | 1b03fe2 | 2014-12-02 13:20:56 -0800 | [diff] [blame] | 80 | struct profile_counter counters[PROFILE_MAX_APP_COUNTERS]; |
| 81 | }; |
| 82 | |
Guojun Jin | f7f90f8 | 2018-08-16 18:09:23 -0700 | [diff] [blame] | 83 | struct nss_profile_n2h_sample_buf { |
Sundarajan Srinivasan | 1b03fe2 | 2014-12-02 13:20:56 -0800 | [diff] [blame] | 84 | struct n2h_meta_header mh; |
| 85 | |
Guojun Jin | f7f90f8 | 2018-08-16 18:09:23 -0700 | [diff] [blame] | 86 | struct nss_profile_sample_ctrl psc_header; /* per sample period */ |
| 87 | struct nss_profile_sample samples[MAX_SAMPLES_PER_PBUF]; /* per thread samples - for NSS send */ |
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 | struct nss_profile_common { |
| 91 | struct nss_profile_session un; |
Sundarajan Srinivasan | 1b03fe2 | 2014-12-02 13:20:56 -0800 | [diff] [blame] | 92 | /* |
| 93 | * changable data sent everything pbuf |
| 94 | */ |
Guojun Jin | f7f90f8 | 2018-08-16 18:09:23 -0700 | [diff] [blame] | 95 | struct nss_profile_n2h_sample_buf *pn2h; /* sampling ctrl for this sample period */ |
| 96 | struct nss_profile_sample *samples; /* samples array was allocated by the linux driver */ |
| 97 | /* now NSS points it to pbuf + pn2h header */ |
| 98 | uint16_t cur; /* pos where driver take (read) samples */ |
| 99 | int16_t enabled; /* Is the profiler enabled to take samples? */ |
Sundarajan Srinivasan | 1b03fe2 | 2014-12-02 13:20:56 -0800 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | /* |
Guojun Jin | f7f90f8 | 2018-08-16 18:09:23 -0700 | [diff] [blame] | 103 | * Each buffer holds 4-7 sets (sample intrs) of samples, by average 5 sets per buffer |
| 104 | * at 10ms sample clock; 1s sleep in profilerd requires kernel to have 1000 / 10 / 5 = 20 |
| 105 | * buffers to store one 1s samples. For higher sampling rate, either kernel needs more |
| 106 | * buffers or profilerd needs less sleep time, but both needs to make match. |
Sundarajan Srinivasan | 1b03fe2 | 2014-12-02 13:20:56 -0800 | [diff] [blame] | 107 | */ |
| 108 | #define CCL_SIZE 32 |
| 109 | |
| 110 | struct profile_io { |
Guojun Jin | f7f90f8 | 2018-08-16 18:09:23 -0700 | [diff] [blame] | 111 | struct nss_profile_common pnc; |
Sundarajan Srinivasan | 1b03fe2 | 2014-12-02 13:20:56 -0800 | [diff] [blame] | 112 | |
| 113 | /* |
| 114 | * control fields - HLOS |
| 115 | */ |
| 116 | void *ctx; // nss_ctx for Linux driver |
| 117 | int profile_first_packet; |
| 118 | int profile_sequence_num; |
| 119 | |
| 120 | /* |
| 121 | * circular buffers for psc_header/samples |
| 122 | */ |
Guojun Jin | f7f90f8 | 2018-08-16 18:09:23 -0700 | [diff] [blame] | 123 | struct nss_profile_n2h_sample_buf *ccl; |
Sundarajan Srinivasan | 1b03fe2 | 2014-12-02 13:20:56 -0800 | [diff] [blame] | 124 | int ccl_read; |
| 125 | int ccl_write; |
| 126 | |
| 127 | /* |
| 128 | * data from HLOS -- used to generate sample->pid in ULTRA -- no longer needed in NSS |
Guojun Jin | f7f90f8 | 2018-08-16 18:09:23 -0700 | [diff] [blame] | 129 | * uint32_t task_offset; offset in bytes in thread_info to task_struct pointer |
| 130 | * uint32_t pid_offset; offset in bytes in task_struct to the PID |
Sundarajan Srinivasan | 1b03fe2 | 2014-12-02 13:20:56 -0800 | [diff] [blame] | 131 | */ |
| 132 | uint32_t *sw_ksp_ptr; // pointer to array (per hardware thread) of pointers to struct thread_info |
Sundarajan Srinivasan | 1b03fe2 | 2014-12-02 13:20:56 -0800 | [diff] [blame] | 133 | }; |
| 134 | |
| 135 | /* |
Guojun Jin | f7f90f8 | 2018-08-16 18:09:23 -0700 | [diff] [blame] | 136 | * Krait <--> NSS debug mechanism. It lays over on nss_profile_n2h_sample_buf.samples (ccl->samples) |
Sundarajan Srinivasan | 1b03fe2 | 2014-12-02 13:20:56 -0800 | [diff] [blame] | 137 | */ |
| 138 | #define MAX_DB_WR 28 // profile_session has 31 4B words data (32W total with hd_magic) and |
| 139 | #define MAX_DB_RD 30 // common has two more ptrs |
| 140 | struct debug_box { // this overlays with profile_common (RD) or profile_session (WR) |
| 141 | uint32_t hd_magic; // cmd + MAGIC for packet and endianess check |
| 142 | |
| 143 | uint32_t opts; |
Guojun Jin | a09b8b0 | 2018-01-25 16:34:43 -0800 | [diff] [blame] | 144 | int32_t base_addr; /* Ubi32 is 32-bit */ |
Sundarajan Srinivasan | 1b03fe2 | 2014-12-02 13:20:56 -0800 | [diff] [blame] | 145 | int32_t dlen; // in 4B words |
| 146 | uint32_t data[MAX_DB_RD]; |
| 147 | }; |
| 148 | |
| 149 | #define DEBUG_OPT_BCTRL 1 // basic CTRL |
| 150 | #define DEBUG_OPT_MOVEIO (1<<1) // force to use moveio in case new OCP range is added |