multithread_analyzer.h (7752B)
1 /** \file multithread_analyzer.h 2 * Supply analyzing utils that can list the resources that are 3 * shared between different threads and the APIs that are using 4 * these resources. 5 * 6 * MTA stands for Multi Thread Analyzer 7 */ 8 /* 9 * 10 * This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file. 11 * 12 * Copyright 2007-2019 Broadcom Inc. All rights reserved. 13 */ 14 15 #ifndef _DNXC_MULTITHREAD_ANALYZER_H 16 /* { */ 17 #define _DNXC_MULTITHREAD_ANALYZER_H 18 19 #include <sal/types.h> 20 21 22 #if defined(DNXC_MTA_ENABLED) 23 #define DNXC_MTA(x) x 24 #else 25 #define DNXC_MTA(x) 26 #endif 27 28 #ifdef DNXC_MTA_ENABLED 29 30 #define MTA_NO_FLAGS 0 31 #define MTA_FLAG_DISPATCHER SAL_BIT(0) 32 #define MTA_FLAG_SHR_INIT_FUNC SAL_BIT(1) 33 #define MTA_FLAG_PRINT_TO_SCREEN SAL_BIT(2) 34 #define MTA_FLAG_CINT SAL_BIT(3) 35 #define MTA_FLAG_MUTEX SAL_BIT(4) 36 #define MTA_FLAG_LOG_ONLY_MAIN SAL_BIT(5) 37 #define MTA_FLAG_LOG_ONLY_BACKGROUND SAL_BIT(6) 38 #define MTA_FLAG_DONT_LOG_MEM_REG SAL_BIT(7) 39 #define MTA_FLAG_THREAD_MAIN_FUNC SAL_BIT(8) 40 #define MTA_FLAG_DONT_LOG_ALLOC_MNGR SAL_BIT(9) 41 #define MTA_FLAG_LOG_ONLY_ALLOC_MNGR SAL_BIT(10) 42 43 #define MTA_TCL_FLAG_SET MTA_FLAG_LOG_ONLY_MAIN | MTA_FLAG_DONT_LOG_MEM_REG | MTA_FLAG_LOG_ONLY_ALLOC_MNGR 44 45 /** 46 * An enum that represent the resource type of an access entry 47 */ 48 typedef enum 49 { 50 MTA_RESOURCE_INVALID = 0, 51 MTA_RESOURCE_SW_STATE, 52 MTA_RESOURCE_DBAL, 53 MTA_RESOURCE_MEM, 54 MTA_RESOURCE_REG, 55 MTA_RESOURCE_WB_ENGINE, 56 MTA_RESOURCE_SOC_CONTROL, 57 MTA_RESOURCE_SAT, 58 MTA_RESOURCE_LINKSCAN, 59 MTA_RESOURCE_REG_OUTSIDE_DBAL, 60 MTA_RESOURCE_MEM_OUTSIDE_DBAL, 61 MTA_RESOURCE_RES_MGR, 62 MTA_RESOURCE_TMP_MGR, 63 /** 64 * should always be last 65 */ 66 MTA_RESOURCE_NOF 67 } mta_resource_e; 68 69 /** 70 * An enum that represent the tipe of element in play 71 */ 72 typedef enum 73 { 74 MTA_ELEMENT_UNKNOWN = 0, 75 MTA_ELEMENT_API, 76 MTA_ELEMENT_MUTEX, 77 MTA_ELEMENT_CINT, 78 MTA_ELEMENT_NOF 79 } mta_element_e; 80 81 /** 82 * An enum that represent dynamic sub resource type 83 */ 84 typedef enum 85 { 86 MTA_DYN_SUB_RES_RES_MGR = 0, 87 MTA_DYN_SUB_RES_TMP_MGR, 88 MTA_DYN_SUB_RES_NOF 89 } mta_dynamic_res_id_type_e; 90 91 const char *dnxc_multithread_analyzer_resource_type_name_get( 92 mta_resource_e resource_type); 93 94 const char *dnxc_multithread_analyzer_thread_name_get( 95 int unit, 96 uint8 thread_id); 97 98 const char *dnxc_multithread_analyzer_resource_id_name_get( 99 int unit, 100 mta_resource_e resource_type, 101 uint32 resource_id); 102 103 const char *dnxc_multithread_analyzer_mutex_list_get( 104 const char **mutex_name); 105 106 /** 107 * \brief - get notified by the application that init is done so 108 * we won't log access during application init 109 * 110 * \par DIRECT_INPUT: 111 * \param [in] unit - Unit-ID 112 * \param [in] is_done - TRUE/FALSE 113 * \par DIRECT OUTPUT: 114 * shr_error_e 115 * \remarks 116 * * None 117 * \see 118 * * None 119 */ 120 int dnxc_multithread_analyzer_application_init_is_done( 121 int unit, 122 uint32 is_done); 123 124 /** 125 * \brief - init the analyzer and start logging 126 * 127 * \par DIRECT_INPUT: 128 * \param [in] unit - Unit-ID 129 * \param [in] flags - flag ideas: ignore_init_deinit 130 * \par DIRECT OUTPUT: 131 * shr_error_e 132 * \remarks 133 * * init the api_in_play db and its mutex 134 * * init the resource-thread_id-api mapping db (it can be a 135 * hash table, a matrix, an sql db or whatever) 136 * * since the analyzer should stay alive even during an 137 * init_deinit cycle, this function should not be called 138 * during init, it should be called on demand by the 139 * regression session. 140 * \see 141 * * None 142 */ 143 int dnxc_multithread_analyzer_start( 144 int unit, 145 uint32 flags); 146 147 /** 148 * \brief - to be ran after analysys in order to generate a 149 * summary output file. 150 * 151 * \par DIRECT_INPUT: 152 * \param [in] unit - Unit-ID 153 * \param [in] flags - determine the format of the output. 154 * \param [in] file_name - output file's name 155 * \par DIRECT OUTPUT: 156 * shr_error_e 157 * \remarks 158 * * The output will be raw-data txt file that should be later 159 * parsed by a higher level script to extract meanningful 160 * info or diagrams. 161 * \see 162 * * None 163 */ 164 int dnxc_multithread_analyzer_generate_summary_files( 165 int unit, 166 uint32 flags, 167 char *file_name); 168 169 /** 170 * \brief - this function is used to declare the API that is 171 * currently in play, it should be called at the 172 * beginning of an API with in_play=TRUE and at the end 173 * of an API with in_play=FALSE, it is automatically 174 * called on BCM APIs by dispatcher but need to be 175 * manually called for "internal APIs" 176 * 177 * \par DIRECT_INPUT: 178 * \param [in] unit - Unit-ID 179 * \param [in] api_name - A string representing the api name 180 * (typically __FUNCTIOM__) 181 * \param [in] flags - Flags to declare properties on the log 182 * entry 183 * \param [in] in_play - should be called with TRUE when 184 * entering API and with False when exiting API 185 * \par INDIRECT INPUT: 186 * * thread_id - the api_name is stored together with the 187 * thread id 188 * * api_in_play db and mutex - a global DS to hold the 189 * current list of APIs that are in play in which threads 190 * \par DIRECT_OUTPUT: 191 * shr_error_e 192 * \remarks 193 * * there may be multiple APIs in play for a single thread at 194 * any given time, to account for API-in-API scenario. 195 * \see 196 * * None 197 */ 198 int dnxc_multithread_analyzer_declare_api_in_play( 199 int unit, 200 const char *api_name, 201 uint32 flags, 202 uint8 in_play); 203 204 /** 205 * \brief - called by resources upon access in order to log the 206 * access in the analyzer 207 * 208 * \par DIRECT_INPUT: 209 * \param [in] unit - Unit-ID 210 * \param [in] resource_type - e.g. DBAL, SW-State 211 * \param [in] resource_id - a specific identifier for the 212 * resource, every resource_type has its own set of 213 * resource_ids (e.g. DBAL table id) 214 * \param [in] is_write - TRUE for write, FALSE for read. 215 * \par INDIRECT INPUT: 216 * * thread_id 217 * * api_in_play db and mutex 218 * * is_init - it can ignore resource access during 219 * init/deinit. 220 * \par DIRECT OUTPUT: 221 * shr_error_e 222 * \remarks 223 * * None 224 * \see 225 * * None 226 */ 227 int dnxc_multithread_analyzer_log_resource_use( 228 int unit, 229 mta_resource_e resource_type, 230 uint32 resource_id, 231 uint8 is_write); 232 233 /** 234 * \brief - called by dbal to inform the multi thread analyzer 235 * that we are inside a dbal transaction. this 236 * information is used to detect MEM/REG access outside 237 * of the dbal layer 238 * \par DIRECT_INPUT: 239 * \param [in] unit - Unit-ID 240 * \param [in] is_start - TRUE for start FALSE for end 241 * \par INDIRECT INPUT: 242 * * thread_id 243 * * api_in_play db and mutex 244 * * is_init - it can ignore resource access during 245 * init/deinit. 246 * \par DIRECT OUTPUT: 247 * shr_error_e 248 * \remarks 249 * * None 250 * \see 251 * * None 252 */ 253 int dnxc_multithread_analyzer_mark_dbal_region( 254 int unit, 255 int is_start); 256 257 /** 258 * \brief - called by res and template manager to create a 259 * resource id from the resource name 260 * \par DIRECT_INPUT: 261 * \param [in] unit - Unit-ID 262 * \param [in] resource - the type of the resource i.e. res or 263 * template 264 * \param [in] res_name - a pointer to a string with the 265 * resource name 266 * \par INDIRECT INPUT: 267 * * None 268 * \par DIRECT OUTPUT: 269 * dynamic id 270 * \remarks 271 * * None 272 * \see 273 * * None 274 */ 275 int dnxc_multithread_analyzer_dynamic_sub_res_get( 276 int unit, 277 mta_dynamic_res_id_type_e resource, 278 char *res_name); 279 280 #endif /* DNXC_MTA_ENABLED */ 281 #endif /* _DNXC_MULTITHREAD_ANALYZER_H */