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 | * profilenode.h |
| 19 | * device node for the profiler, to communicate with the linux driver |
| 20 | * |
| 21 | * WANRING: |
| 22 | * This file must present in both nss/source/pkg/profile/include for NSS driver, |
| 23 | * and linux-nbu/driver/.../nss for Linux driver |
| 24 | */ |
| 25 | |
| 26 | #include "profilesample.h" |
| 27 | |
| 28 | #define UBI32_PROFILE_HD_MAGIC 0x4F525000 // 0 + "PRO" |
| 29 | #define UBI32_PROFILE_HD_MAGIC_REV 0x0050524F // different endian |
| 30 | #define UBI32_PROFILE_HD_MMASK 0xFFFFFF00 // 1st byte is Rx/Tx cmd |
| 31 | #define UBI32_PROFILE_HD_MMASK_REV 0x00FFFFFF |
| 32 | |
| 33 | enum profile_cmds { |
| 34 | // cmds from HLOS to NSS |
| 35 | PROFILER_CHANGE_SAMPLING_RATE, // change sampling clock timer |
| 36 | PROFILER_START, // start/stop sampling engine |
| 37 | PROFILER_STOP, |
| 38 | PROFILER_FLOWCTRL, // info how many buffers available |
| 39 | DEBUG_RD_REQ, // I/O commands h2n |
| 40 | DEBUG_WR_REQ, |
| 41 | DEBUG_REPLY, // n2h respond |
| 42 | |
| 43 | // data from NSS to HLOS |
| 44 | PROFILER_FIXED_INFO = 8, // set bit 3 for data |
| 45 | PROFILER_COUNTERS, |
| 46 | PROFILER_SAMPLES, |
| 47 | }; |
| 48 | |
| 49 | struct profile_sample_ctrl_header { |
| 50 | uint32_t hd_magic; // cmd + MAGIC for packet and endianess check |
| 51 | |
| 52 | /* |
| 53 | * controlling data need to be sent to and used by upper layer (HLOS) |
| 54 | */ |
| 55 | uint16_t count; // number of valid samples |
| 56 | uint16_t max_samples; // how many samples can be in the samples array |
| 57 | uint32_t dropped_samples; // how many samples did the profiler drop due to buffer overruns |
| 58 | |
| 59 | /* |
| 60 | * info data -- sent to remote profiler tool (need swap) |
| 61 | */ |
| 62 | struct profile_ext_header exh; |
| 63 | |
| 64 | }; |
| 65 | |
| 66 | /* |
| 67 | * # of sample buffers in pbuf payload |
| 68 | */ |
| 69 | #ifndef PBUF_PAYLOAD_SIZE |
| 70 | #define PBUF_PAYLOAD_SIZE 1792 // for HLOS driver: must sync with pbuf_public |
| 71 | typedef enum meta_types { |
| 72 | PINGPONG_EMPTY, |
| 73 | PINGPONG_FULL, |
| 74 | PINGPONG_INUSE, |
| 75 | } flowctrl_t; |
| 76 | #else |
| 77 | typedef enum pnode_c2h_metadata_types flowctrl_t; // for NSS driver |
| 78 | #endif |
| 79 | |
| 80 | #define MAX_SAMPLES_PER_PBUF ((PBUF_PAYLOAD_SIZE - sizeof(struct profile_sample_ctrl_header)) / sizeof(struct profile_sample)) |
| 81 | |
| 82 | struct n2h_meta_header { |
| 83 | flowctrl_t md_type; // N2H (NSS) and receiver (HLOS) flow control (meta type) |
| 84 | uint32_t d_len; // total data length start from psc_header |
| 85 | }; |
| 86 | |
| 87 | struct profile_session { // use for per session start |
| 88 | uint32_t hd_magic; // common ovarlay in all headers |
| 89 | uint32_t num_counters; // how many registered performance (app) counters -- may change |
| 90 | uint32_t ocm_size; |
| 91 | uint32_t sram_start; |
| 92 | |
| 93 | uint32_t rate; // sampling rate |
| 94 | uint32_t cpu_id; // chip_id register |
| 95 | uint32_t cpu_freq; // chip clock |
| 96 | uint32_t ddr_freq; // DDR MEM speed |
| 97 | struct profile_counter counters[PROFILE_MAX_APP_COUNTERS]; |
| 98 | }; |
| 99 | |
| 100 | struct profile_n2h_sample_buf { |
| 101 | struct n2h_meta_header mh; |
| 102 | |
| 103 | struct profile_sample_ctrl_header psc_header; // per sample period |
| 104 | struct profile_sample samples[MAX_SAMPLES_PER_PBUF]; // per thread samples - for NSS send |
| 105 | }; |
| 106 | |
| 107 | struct profile_common { |
| 108 | struct profile_session un; |
| 109 | /* |
| 110 | * changable data sent everything pbuf |
| 111 | */ |
| 112 | struct profile_n2h_sample_buf *pn2h; // sampling ctrl for this sample period |
| 113 | struct profile_sample *samples; // samples array was allocated by the linux driver |
| 114 | // now NSS points it to pbuf + pn2h header |
| 115 | uint16_t cur; // pos where driver take (read) samples |
| 116 | int16_t enabled; // Is the profiler enabled to take samples? |
| 117 | }; |
| 118 | |
| 119 | /* |
| 120 | * each buffer holds 4-7 sets (sample intrs) of samples; by average 5 sets per buffer, |
| 121 | * at 10ms smaple clock, 1s sleep in profilerd requires kernel to have 1000 / 10 / 5 = 20 |
| 122 | * buffer to store one 1s samples. For higher sampling rate, either kernel needs more buffers |
| 123 | * or profilerd needs less sleep time, but both needs to make match. |
| 124 | */ |
| 125 | #define CCL_SIZE 32 |
| 126 | |
| 127 | struct profile_io { |
| 128 | struct profile_common pnc; |
| 129 | |
| 130 | /* |
| 131 | * control fields - HLOS |
| 132 | */ |
| 133 | void *ctx; // nss_ctx for Linux driver |
| 134 | int profile_first_packet; |
| 135 | int profile_sequence_num; |
| 136 | |
| 137 | /* |
| 138 | * circular buffers for psc_header/samples |
| 139 | */ |
| 140 | struct profile_n2h_sample_buf *ccl; |
| 141 | int ccl_read; |
| 142 | int ccl_write; |
| 143 | |
| 144 | /* |
| 145 | * data from HLOS -- used to generate sample->pid in ULTRA -- no longer needed in NSS |
| 146 | */ |
| 147 | uint32_t *sw_ksp_ptr; // pointer to array (per hardware thread) of pointers to struct thread_info |
| 148 | uint32_t task_offset; // offset in bytes in thread_info to task_struct pointer |
| 149 | uint32_t pid_offset; // offset in bytes in task_struct to the PID |
| 150 | }; |
| 151 | |
| 152 | /* |
| 153 | * Krait <--> NSS debug mechanism. It lays over on profile_n2h_sample_buf.samples (ccl->samples) |
| 154 | */ |
| 155 | #define MAX_DB_WR 28 // profile_session has 31 4B words data (32W total with hd_magic) and |
| 156 | #define MAX_DB_RD 30 // common has two more ptrs |
| 157 | struct debug_box { // this overlays with profile_common (RD) or profile_session (WR) |
| 158 | uint32_t hd_magic; // cmd + MAGIC for packet and endianess check |
| 159 | |
| 160 | uint32_t opts; |
| 161 | uint32_t *base_addr; |
| 162 | int32_t dlen; // in 4B words |
| 163 | uint32_t data[MAX_DB_RD]; |
| 164 | }; |
| 165 | |
| 166 | #define DEBUG_OPT_BCTRL 1 // basic CTRL |
| 167 | #define DEBUG_OPT_MOVEIO (1<<1) // force to use moveio in case new OCP range is added |