xf.li | bfc6e71 | 2025-02-07 01:54:34 -0800 | [diff] [blame] | 1 | /* |
| 2 | * tracker.c - System accounting over taskstats interface |
| 3 | * |
| 4 | * Copyright (C) Jay Lan, <jlan@sgi.com> |
| 5 | * |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | */ |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/kernel.h> |
| 20 | #include <linux/sched.h> |
| 21 | #include <linux/jiffies.h> |
| 22 | #include <linux/slab.h> |
| 23 | #include <linux/timer.h> |
| 24 | #include <linux/delay.h> |
| 25 | #include <linux/kthread.h> |
| 26 | #include <mach/iomap.h> |
| 27 | |
| 28 | #ifndef CONFIG_SYSTEM_CAP |
| 29 | #include <linux/proc_fs.h> |
| 30 | #include <linux/string.h> |
| 31 | #include <linux/seq_file.h> |
| 32 | #endif |
| 33 | |
| 34 | /******************************************************************************* |
| 35 | * ºê¶¨Òå * |
| 36 | *******************************************************************************/ |
| 37 | #if defined(_OS_TOS) |
| 38 | # define OS_STATISTIC_IRAM_BASE (IRAM_BASE_ADDR_OS_STATISTIC_PSCPU) |
| 39 | # define OS_STATISTIC_TIME zDrvTimer_Stamp() |
| 40 | #elif defined(_OS_LINUX) |
| 41 | # define OS_STATISTIC_IRAM_BASE g_zxic_trace_apcpu_addr //(IRAM_BASE_ADDR_OS_STATISTIC_APCPU) |
| 42 | # define OS_STATISTIC_TIME (cpu_clock(0)>>10) |
| 43 | #else |
| 44 | # error "unknown os" |
| 45 | #endif |
| 46 | |
| 47 | #define OS_IRAM_STATISTIC_CNT (8) |
| 48 | #define OS_IRAM_STATISTIC_NAME_LEN (16) |
| 49 | #define OS_DDR_STATISTIC_CNT (1000) |
| 50 | |
| 51 | #define OS_IRAM_THREAD_SWAPIN (OS_STATISTIC_IRAM_BASE) |
| 52 | #define OS_IRAM_IRQ_START (OS_IRAM_THREAD_SWAPIN + sizeof(t_os_iram_thread_statistic)) |
| 53 | #define OS_IRAM_IRQ_END (OS_IRAM_IRQ_START + sizeof(t_os_iram_statistic)) |
| 54 | |
| 55 | #if defined(_OS_TOS) |
| 56 | #define OS_IRAM_DSR_START (OS_IRAM_IRQ_END + sizeof(t_os_iram_statistic)) |
| 57 | #define OS_IRAM_DSR_END (OS_IRAM_DSR_START + sizeof(t_os_iram_statistic)) |
| 58 | #elif defined(_OS_LINUX) |
| 59 | #define OS_IRAM_SOFTIRQ_START (OS_IRAM_IRQ_END + sizeof(t_os_iram_statistic)) |
| 60 | #define OS_IRAM_SOFTIRQ_END (OS_IRAM_SOFTIRQ_START + sizeof(t_os_iram_statistic)) |
| 61 | #define OS_IRAM_TIMER_START (OS_IRAM_SOFTIRQ_END + sizeof(t_os_iram_statistic)) |
| 62 | #define OS_IRAM_TIMER_END (OS_IRAM_TIMER_START + sizeof(t_os_iram_statistic)) |
xf.li | 771eb06 | 2025-02-09 23:05:11 -0800 | [diff] [blame^] | 63 | #define OS_IRAM_RESET_REASON_START (OS_STATISTIC_IRAM_BASE + 0x400 - sizeof(T_Reset_Reason)) |
xf.li | bfc6e71 | 2025-02-07 01:54:34 -0800 | [diff] [blame] | 64 | #endif |
| 65 | |
| 66 | #define os_statistic_check() *((volatile unsigned long *)OS_STATISTIC_IRAM_BASE) |
| 67 | #define os_statistic_enabled() g_os_statistic_enable |
| 68 | |
| 69 | #ifndef CONFIG_SYSTEM_CAP |
| 70 | #define KERNEL_L1W_IRAM_LOG_DROP (IRAM_BASE_ADDR_LOG_DROP_TRACE) |
| 71 | #define KERNEL_L1l_IRAM_LOG_DROP (KERNEL_L1W_IRAM_LOG_DROP + sizeof(T_LogIram_Record)) |
| 72 | #endif |
| 73 | /******************************************************************************* |
| 74 | * Êý¾Ý½á¹¹¶¨Òå * |
| 75 | *******************************************************************************/ |
| 76 | typedef volatile struct { |
| 77 | unsigned int enable; |
| 78 | unsigned int cnt; |
| 79 | unsigned int index; |
| 80 | struct { |
| 81 | unsigned char name[OS_IRAM_STATISTIC_NAME_LEN]; |
| 82 | unsigned int data2; |
| 83 | } statistics[OS_IRAM_STATISTIC_CNT]; |
| 84 | }t_os_iram_thread_statistic; |
| 85 | |
| 86 | typedef volatile struct { |
| 87 | unsigned int cnt; |
| 88 | unsigned int index; |
| 89 | struct { |
| 90 | unsigned int data1; |
| 91 | unsigned int data2; |
| 92 | } statistics[OS_IRAM_STATISTIC_CNT]; |
| 93 | }t_os_iram_statistic; |
| 94 | |
| 95 | typedef struct { |
| 96 | unsigned int cnt; |
| 97 | unsigned int index; |
| 98 | struct { |
| 99 | unsigned int data1; |
| 100 | unsigned int data2; |
| 101 | } statistics[OS_DDR_STATISTIC_CNT]; |
| 102 | }t_os_ddr_statistic; |
| 103 | |
| 104 | #ifndef CONFIG_SYSTEM_CAP |
| 105 | typedef struct |
| 106 | { |
| 107 | unsigned int no_lock; |
| 108 | unsigned int no_mem; |
| 109 | }T_LogIram_Record; |
| 110 | #endif |
| 111 | |
xf.li | 771eb06 | 2025-02-09 23:05:11 -0800 | [diff] [blame^] | 112 | typedef struct |
| 113 | { |
| 114 | char ramdump_reason[32]; //±ÈÈ磺ramdump_ap_appname |
| 115 | char kernel_reboot[32]; //±ÈÈ磺reboot_ap_appname |
| 116 | } T_Reset_Reason; |
| 117 | |
xf.li | bfc6e71 | 2025-02-07 01:54:34 -0800 | [diff] [blame] | 118 | /******************************************************************************* |
| 119 | * È«¾Ö±äÁ¿ * |
| 120 | *******************************************************************************/ |
| 121 | #if defined(_OS_LINUX) |
| 122 | static char *g_zxic_trace_apcpu_addr; |
| 123 | #endif |
| 124 | |
| 125 | static int g_os_statistic_enable; |
| 126 | static unsigned int g_os_statistic_cnt; |
| 127 | |
| 128 | static t_os_iram_thread_statistic *g_os_iram_swapin_statistic; |
| 129 | static t_os_iram_statistic *g_os_iram_irq_start_statistic; |
| 130 | static t_os_iram_statistic *g_os_iram_irq_end_statistic; |
| 131 | |
| 132 | #if defined(_OS_TOS) |
| 133 | static t_os_iram_statistic *g_os_iram_dsr_start_statistic; |
| 134 | static t_os_iram_statistic *g_os_iram_dsr_end_statistic; |
| 135 | #elif defined(_OS_LINUX) |
| 136 | static t_os_iram_statistic *g_os_iram_softirq_start_statistic; |
| 137 | static t_os_iram_statistic *g_os_iram_softirq_end_statistic; |
| 138 | static t_os_iram_statistic *g_os_iram_timer_start_statistic; |
| 139 | static t_os_iram_statistic *g_os_iram_timer_end_statistic; |
| 140 | #endif |
| 141 | |
| 142 | static t_os_ddr_statistic *g_os_ddr_swapin_statistic; |
| 143 | static t_os_ddr_statistic *g_os_ddr_irq_start_statistic; |
| 144 | static t_os_ddr_statistic *g_os_ddr_irq_end_statistic; |
| 145 | |
| 146 | #if defined(_OS_TOS) |
| 147 | static t_os_ddr_statistic *g_os_ddr_dsr_start_statistic; |
| 148 | static t_os_ddr_statistic *g_os_ddr_dsr_end_statistic; |
| 149 | #elif defined(_OS_LINUX) |
| 150 | static t_os_ddr_statistic *g_os_ddr_softirq_start_statistic; |
| 151 | static t_os_ddr_statistic *g_os_ddr_softirq_end_statistic; |
| 152 | static t_os_ddr_statistic *g_os_ddr_timer_start_statistic; |
| 153 | static t_os_ddr_statistic *g_os_ddr_timer_end_statistic; |
xf.li | 771eb06 | 2025-02-09 23:05:11 -0800 | [diff] [blame^] | 154 | volatile T_Reset_Reason *g_os_reset_reason; |
xf.li | bfc6e71 | 2025-02-07 01:54:34 -0800 | [diff] [blame] | 155 | #endif |
| 156 | |
| 157 | #ifndef CONFIG_SYSTEM_CAP |
| 158 | T_LogIram_Record *gL1w_LogMissPoint = (T_LogIram_Record *)KERNEL_L1W_IRAM_LOG_DROP; |
| 159 | T_LogIram_Record *gL11_LogMissPoint = (T_LogIram_Record *)KERNEL_L1l_IRAM_LOG_DROP; |
| 160 | #endif |
| 161 | |
| 162 | /******************************************************************************* |
| 163 | * È«¾Öº¯ÊýÉùÃ÷ * |
| 164 | *******************************************************************************/ |
| 165 | void os_statistic_enable(void); |
| 166 | /******************************************************************************* |
| 167 | * ¾Ö²¿º¯Êý * |
| 168 | *******************************************************************************/ |
| 169 | /******************************************************************************* |
| 170 | * ¹¦ÄÜÃèÊö: ¹ì¼£Í³¼Æµ½IRAM |
| 171 | * ²ÎÊý˵Ã÷: |
| 172 | * (´«Èë²ÎÊý) iram_addr: µØÖ· |
| 173 | data: ʼþÏî |
| 174 | time: ʱ¼ä |
| 175 | * (´«³ö²ÎÊý) void |
| 176 | * ·µ »Ø Öµ: void |
| 177 | * ÆäËü˵Ã÷: ÎÞ |
| 178 | *******************************************************************************/ |
| 179 | static inline void os_statistic_in_iram(volatile void *iram_addr, void *data, unsigned long time) |
| 180 | { |
| 181 | unsigned long index; |
| 182 | t_os_iram_statistic *iram; |
| 183 | |
| 184 | iram = (t_os_iram_statistic *)iram_addr; |
| 185 | |
| 186 | index = iram->index; |
| 187 | if(index >= OS_IRAM_STATISTIC_CNT) |
| 188 | { |
| 189 | index = 0; |
| 190 | } |
| 191 | |
| 192 | iram->statistics[index].data1 = (unsigned int)data; |
| 193 | iram->statistics[index].data2 = time; |
| 194 | index++; |
| 195 | |
| 196 | iram->index = index; |
| 197 | iram->cnt = g_os_statistic_cnt; |
| 198 | } |
| 199 | |
| 200 | /******************************************************************************* |
| 201 | * ¹¦ÄÜÃèÊö: Ï̹߳켣ͳ¼Æµ½IRAM |
| 202 | * ²ÎÊý˵Ã÷: |
| 203 | * (´«Èë²ÎÊý) iram_addr: µØÖ· |
| 204 | data: ʼþÏî |
| 205 | time: ʱ¼ä |
| 206 | * (´«³ö²ÎÊý) void |
| 207 | * ·µ »Ø Öµ: void |
| 208 | * ÆäËü˵Ã÷: ÎÞ |
| 209 | *******************************************************************************/ |
| 210 | static inline void os_statistic_thread_in_iram(volatile void *iram_addr, void *data, unsigned long time) |
| 211 | { |
| 212 | unsigned long index; |
| 213 | t_os_iram_thread_statistic *iram; |
| 214 | |
| 215 | iram = (t_os_iram_thread_statistic *)iram_addr; |
| 216 | |
| 217 | index = iram->index; |
| 218 | if(index >= OS_IRAM_STATISTIC_CNT) |
| 219 | { |
| 220 | index = 0; |
| 221 | } |
| 222 | |
| 223 | #if defined(_OS_TOS) |
| 224 | strncpy((char *)(iram->statistics[index].name), cyg_thread_get_name((cyg_handle_t)data), OS_IRAM_STATISTIC_NAME_LEN - 1); |
| 225 | #elif defined(_OS_LINUX) |
| 226 | strncpy((char *)(iram->statistics[index].name), ((struct task_struct *)data)->comm, OS_IRAM_STATISTIC_NAME_LEN - 1); |
| 227 | #else |
| 228 | # error "unkown os" |
| 229 | #endif |
| 230 | iram->statistics[index].name[OS_IRAM_STATISTIC_NAME_LEN - 1] = 0; |
| 231 | iram->statistics[index].data2 = time; |
| 232 | index++; |
| 233 | |
| 234 | iram->index = index; |
| 235 | iram->cnt = g_os_statistic_cnt; |
| 236 | } |
| 237 | |
| 238 | /******************************************************************************* |
| 239 | * ¹¦ÄÜÃèÊö: ¹ì¼£Í³¼Æµ½DDR |
| 240 | * ²ÎÊý˵Ã÷: |
| 241 | * (´«Èë²ÎÊý) iram_addr: µØÖ· |
| 242 | data: ʼþÏî |
| 243 | time: ʱ¼ä |
| 244 | * (´«³ö²ÎÊý) void |
| 245 | * ·µ »Ø Öµ: void |
| 246 | * ÆäËü˵Ã÷: ÎÞ |
| 247 | *******************************************************************************/ |
| 248 | static inline void os_statistic_in_ddr(void *ddr_addr, void *data, unsigned long time) |
| 249 | { |
| 250 | unsigned long index; |
| 251 | t_os_ddr_statistic *ddr; |
| 252 | |
| 253 | ddr = (t_os_ddr_statistic *)ddr_addr; |
| 254 | |
| 255 | index = ddr->index; |
| 256 | if (index >= OS_DDR_STATISTIC_CNT) |
| 257 | { |
| 258 | index = 0; |
| 259 | } |
| 260 | ddr->statistics[index].data1 = (unsigned int)data; |
| 261 | ddr->statistics[index].data2 = time; |
| 262 | index++; |
| 263 | |
| 264 | ddr->index = index; |
| 265 | ddr->cnt = g_os_statistic_cnt; |
| 266 | } |
| 267 | |
| 268 | /******************************************************************************* |
| 269 | * ¹¦ÄÜÃèÊö: ¹ì¼£Í³¼Æµ½DDR |
| 270 | * ²ÎÊý˵Ã÷: |
| 271 | * (´«Èë²ÎÊý) iram_addr: µØÖ· |
| 272 | data: ʼþÏî |
| 273 | time: ʱ¼ä |
| 274 | * (´«³ö²ÎÊý) void |
| 275 | * ·µ »Ø Öµ: void |
| 276 | * ÆäËü˵Ã÷: ÎÞ |
| 277 | *******************************************************************************/ |
| 278 | static inline void os_statistic_info_update(void) |
| 279 | { |
| 280 | g_os_statistic_cnt++; |
| 281 | } |
| 282 | |
| 283 | /******************************************************************************* |
| 284 | * ¹¦ÄÜÃèÊö: ¶¨Ê±Æ÷»Øµ÷¹³×Ó |
| 285 | * ²ÎÊý˵Ã÷: |
| 286 | * (´«Èë²ÎÊý) |
| 287 | * (´«³ö²ÎÊý) void |
| 288 | * ·µ »Ø Öµ: void |
| 289 | * ÆäËü˵Ã÷: ÎÞ |
| 290 | *******************************************************************************/ |
| 291 | static int os_statistic_delayed_work_timer_fn(unsigned long data) |
| 292 | { |
| 293 | int sec = 0; |
| 294 | msleep(20000); |
| 295 | while(!os_statistic_check()) |
| 296 | { |
| 297 | //³¬¹ý40s£¬Ö±½ÓÍ˳ö |
| 298 | if(sec >= 4) |
| 299 | return; |
| 300 | msleep(10000); |
| 301 | sec++; |
| 302 | } |
| 303 | os_statistic_enable(); |
| 304 | return 0; |
| 305 | } |
| 306 | |
| 307 | /******************************************************************************* |
| 308 | * È«¾Öº¯ÊýʵÏÖ * |
| 309 | *******************************************************************************/ |
| 310 | /******************************************************************************* |
| 311 | * ¹¦ÄÜÃèÊö: ¹ì¼£Í³¼Æ³õʼ»¯ |
| 312 | * ²ÎÊý˵Ã÷: |
| 313 | * (´«Èë²ÎÊý) void |
| 314 | * (´«³ö²ÎÊý) void |
| 315 | * ·µ »Ø Öµ: void |
| 316 | * ÆäËü˵Ã÷: psºËµ÷Óà |
| 317 | *******************************************************************************/ |
| 318 | void os_statistic_init(void) |
| 319 | { |
| 320 | memset((void *)IRAM_BASE_ADDR_LINUX_STATISTIC, 0x0, IRAM_BASE_LEN_LINUX_STATISTIC); |
| 321 | } |
| 322 | EXPORT_SYMBOL(os_statistic_init); |
| 323 | |
| 324 | /******************************************************************************* |
| 325 | * ¹¦ÄÜÃèÊö: ʹÄܹ켣ͳ¼Æ¹¦ÄÜ |
| 326 | * ²ÎÊý˵Ã÷: |
| 327 | * (´«Èë²ÎÊý) address: ¼Ç¼µ½IRAMÖеĵØÖ· |
| 328 | size: IRAM¿Õ¼ä´óС |
| 329 | * (´«³ö²ÎÊý) void |
| 330 | * ·µ »Ø Öµ: void |
| 331 | * ÆäËü˵Ã÷: ÎÞ |
| 332 | *******************************************************************************/ |
| 333 | void os_statistic_enable(void) |
| 334 | { |
| 335 | #if defined(_OS_TOS) |
| 336 | g_os_iram_swapin_statistic = (t_os_iram_thread_statistic *)OS_IRAM_THREAD_SWAPIN; |
| 337 | g_os_iram_irq_start_statistic = (t_os_iram_statistic *)OS_IRAM_IRQ_START; |
| 338 | g_os_iram_irq_end_statistic = (t_os_iram_statistic *)OS_IRAM_IRQ_END; |
| 339 | g_os_iram_dsr_start_statistic = (t_os_iram_statistic *)OS_IRAM_DSR_START; |
| 340 | g_os_iram_dsr_end_statistic = (t_os_iram_statistic *)OS_IRAM_DSR_END; |
| 341 | |
| 342 | g_os_ddr_swapin_statistic = (t_os_ddr_statistic *)zOss_Malloc(sizeof(t_os_ddr_statistic)); |
| 343 | g_os_ddr_irq_start_statistic = (t_os_ddr_statistic *)zOss_Malloc(sizeof(t_os_ddr_statistic)); |
| 344 | g_os_ddr_irq_end_statistic = (t_os_ddr_statistic *)zOss_Malloc(sizeof(t_os_ddr_statistic)); |
| 345 | g_os_ddr_dsr_start_statistic = (t_os_ddr_statistic *)zOss_Malloc(sizeof(t_os_ddr_statistic)); |
| 346 | g_os_ddr_dsr_end_statistic = (t_os_ddr_statistic *)zOss_Malloc(sizeof(t_os_ddr_statistic)); |
| 347 | #elif defined(_OS_LINUX) |
| 348 | g_os_iram_swapin_statistic = (t_os_iram_thread_statistic *)OS_IRAM_THREAD_SWAPIN; |
| 349 | g_os_iram_irq_start_statistic = (t_os_iram_statistic *)OS_IRAM_IRQ_START; |
| 350 | g_os_iram_irq_end_statistic = (t_os_iram_statistic *)OS_IRAM_IRQ_END; |
| 351 | g_os_iram_softirq_start_statistic = (t_os_iram_statistic *)OS_IRAM_SOFTIRQ_START; |
| 352 | g_os_iram_softirq_end_statistic = (t_os_iram_statistic *)OS_IRAM_SOFTIRQ_END; |
| 353 | g_os_iram_timer_start_statistic = (t_os_iram_statistic *)OS_IRAM_TIMER_START; |
| 354 | g_os_iram_timer_end_statistic = (t_os_iram_statistic *)OS_IRAM_TIMER_END; |
| 355 | |
| 356 | g_os_ddr_swapin_statistic = (t_os_ddr_statistic *)kmalloc(sizeof(t_os_ddr_statistic), GFP_KERNEL); |
| 357 | g_os_ddr_irq_start_statistic = (t_os_ddr_statistic *)kmalloc(sizeof(t_os_ddr_statistic), GFP_KERNEL); |
| 358 | g_os_ddr_irq_end_statistic = (t_os_ddr_statistic *)kmalloc(sizeof(t_os_ddr_statistic), GFP_KERNEL); |
| 359 | g_os_ddr_softirq_start_statistic = (t_os_ddr_statistic *)kmalloc(sizeof(t_os_ddr_statistic), GFP_KERNEL); |
| 360 | g_os_ddr_softirq_end_statistic = (t_os_ddr_statistic *)kmalloc(sizeof(t_os_ddr_statistic), GFP_KERNEL); |
| 361 | g_os_ddr_timer_start_statistic = (t_os_ddr_statistic *)kmalloc(sizeof(t_os_ddr_statistic), GFP_KERNEL); |
| 362 | g_os_ddr_timer_end_statistic = (t_os_ddr_statistic *)kmalloc(sizeof(t_os_ddr_statistic), GFP_KERNEL); |
| 363 | |
| 364 | #else |
| 365 | # error "unkown os" |
| 366 | #endif |
| 367 | |
| 368 | g_os_statistic_enable = 1; |
| 369 | } |
| 370 | EXPORT_SYMBOL(os_statistic_enable); |
| 371 | |
| 372 | /******************************************************************************* |
| 373 | * ¹¦ÄÜÃèÊö: ¹ì¼£Í³¼ÆÊ¹ÄÜ֪ͨ |
| 374 | * ²ÎÊý˵Ã÷: |
| 375 | * (´«Èë²ÎÊý) void |
| 376 | * (´«³ö²ÎÊý) void |
| 377 | * ·µ »Ø Öµ: void |
| 378 | * ÆäËü˵Ã÷: psºËµ÷Óà |
| 379 | *******************************************************************************/ |
| 380 | void os_statistic_enable_notify(void) |
| 381 | { |
| 382 | *(volatile unsigned long *)IRAM_BASE_ADDR_LINUX_STATISTIC_PSCPU = 1; |
| 383 | *(volatile unsigned long *)IRAM_BASE_ADDR_LINUX_STATISTIC_PHYCPU = 1; |
| 384 | *(volatile unsigned long *)IRAM_BASE_ADDR_LINUX_STATISTIC_APCPU = 1; |
| 385 | } |
| 386 | EXPORT_SYMBOL(os_statistic_enable_notify); |
| 387 | |
| 388 | |
| 389 | void zxic_trace_task_switch(struct task_struct *next) |
| 390 | { |
| 391 | unsigned long time; |
| 392 | if (!g_os_statistic_enable) |
| 393 | return ; |
| 394 | |
| 395 | time = OS_STATISTIC_TIME; |
| 396 | os_statistic_thread_in_iram(g_os_iram_swapin_statistic, next, time); |
| 397 | os_statistic_in_ddr(g_os_ddr_swapin_statistic, next, time); |
| 398 | os_statistic_info_update(); |
| 399 | } |
| 400 | |
| 401 | void zxic_trace_irq_enter(u32 irq) |
| 402 | { |
| 403 | unsigned long time; |
| 404 | if (!g_os_statistic_enable) |
| 405 | return ; |
| 406 | |
| 407 | time = OS_STATISTIC_TIME; |
| 408 | os_statistic_in_iram(g_os_iram_irq_start_statistic, irq, time); |
| 409 | os_statistic_in_ddr(g_os_ddr_irq_start_statistic, irq, time); |
| 410 | os_statistic_info_update(); |
| 411 | } |
| 412 | |
| 413 | void zxic_trace_irq_exit(u32 irq) |
| 414 | { |
| 415 | unsigned long time; |
| 416 | if (!g_os_statistic_enable) |
| 417 | return ; |
| 418 | |
| 419 | time = OS_STATISTIC_TIME; |
| 420 | os_statistic_in_iram(g_os_iram_irq_end_statistic, irq, time); |
| 421 | os_statistic_in_ddr(g_os_ddr_irq_end_statistic, irq, time); |
| 422 | os_statistic_info_update(); |
| 423 | } |
| 424 | |
| 425 | void zxic_trace_softirq_enter(u32 vec_nr) |
| 426 | { |
| 427 | unsigned long time; |
| 428 | if (!g_os_statistic_enable) |
| 429 | return ; |
| 430 | |
| 431 | time = OS_STATISTIC_TIME; |
| 432 | os_statistic_in_iram(g_os_iram_softirq_start_statistic, vec_nr, time); |
| 433 | os_statistic_in_ddr(g_os_ddr_softirq_start_statistic, vec_nr, time); |
| 434 | os_statistic_info_update(); |
| 435 | } |
| 436 | |
| 437 | void zxic_trace_softirq_exit(u32 vec_nr) |
| 438 | { |
| 439 | unsigned long time; |
| 440 | if (!g_os_statistic_enable) |
| 441 | return ; |
| 442 | |
| 443 | time = OS_STATISTIC_TIME; |
| 444 | os_statistic_in_iram(g_os_iram_softirq_end_statistic, vec_nr, time); |
| 445 | os_statistic_in_ddr(g_os_ddr_softirq_end_statistic, vec_nr, time); |
| 446 | os_statistic_info_update(); |
| 447 | } |
| 448 | |
| 449 | void zxic_trace_timer_enter(void *func) |
| 450 | { |
| 451 | unsigned long time; |
| 452 | if (!g_os_statistic_enable) |
| 453 | return ; |
| 454 | |
| 455 | time = OS_STATISTIC_TIME; |
| 456 | os_statistic_in_iram(g_os_iram_timer_start_statistic, func, time); |
| 457 | os_statistic_in_ddr(g_os_ddr_timer_start_statistic, func, time); |
| 458 | os_statistic_info_update(); |
| 459 | } |
| 460 | |
| 461 | void zxic_trace_timer_exit(void *func) |
| 462 | { |
| 463 | unsigned long time; |
| 464 | if (!g_os_statistic_enable) |
| 465 | return ; |
| 466 | |
| 467 | time = OS_STATISTIC_TIME; |
| 468 | os_statistic_in_iram(g_os_iram_timer_end_statistic, func, time); |
| 469 | os_statistic_in_ddr(g_os_ddr_timer_end_statistic, func, time); |
| 470 | os_statistic_info_update(); |
| 471 | } |
xf.li | 771eb06 | 2025-02-09 23:05:11 -0800 | [diff] [blame^] | 472 | /* |
| 473 | reason: 1 for ramdump, 2 for kernel reboot |
| 474 | cpu: ap/cap/rpm/phy |
| 475 | app: current->comm |
| 476 | */ |
| 477 | /* Started by AICoder, pid:pf139dce4f7776c149ec081b508bae14e6084ede */ |
| 478 | void zxic_reset_reason(int reason, const char *cpu, const char *app) |
| 479 | { |
| 480 | char buffer[32]; |
| 481 | |
| 482 | memset(buffer, 0, sizeof(buffer)); |
| 483 | switch (reason) |
| 484 | { |
| 485 | case 1: |
| 486 | snprintf(buffer, 32, "reset_ramdump_%s_%s", cpu, app); |
| 487 | memcpy(g_os_reset_reason->ramdump_reason, buffer, sizeof(buffer)); |
| 488 | break; |
| 489 | case 2: |
| 490 | snprintf(buffer, 32, "reset_kreboot_%s_%s", cpu, app); |
| 491 | memcpy(g_os_reset_reason->kernel_reboot, buffer, sizeof(buffer)); |
| 492 | break; |
| 493 | default: |
| 494 | break; |
| 495 | } |
| 496 | } |
| 497 | /* Ended by AICoder, pid:pf139dce4f7776c149ec081b508bae14e6084ede */ |
xf.li | bfc6e71 | 2025-02-07 01:54:34 -0800 | [diff] [blame] | 498 | |
| 499 | #ifndef CONFIG_SYSTEM_CAP |
| 500 | |
| 501 | /** |
| 502 | * kernel_log_miss_point_show - show the log miss cnt |
| 503 | * @m: proc file structure |
| 504 | * @v: |
| 505 | * |
| 506 | * Returns -errno, or 0 for success. |
| 507 | */ |
| 508 | static int kernel_log_miss_point_show(struct seq_file *m, void *v) |
| 509 | { |
| 510 | int index = 0; |
| 511 | T_LogIram_Record *iram = NULL; |
| 512 | |
| 513 | iram = (T_LogIram_Record *)gL1w_LogMissPoint; |
| 514 | if (iram) |
| 515 | printk("kernel_log_miss_point_show iram = %x\n",iram); |
| 516 | else |
| 517 | { |
| 518 | printk("iram is NULL\n"); |
| 519 | return -1; |
| 520 | } |
| 521 | |
| 522 | seq_printf(m,"L1W phy: log miss point count is:\n"); |
| 523 | |
| 524 | for (; index < 2; index++) |
| 525 | { |
| 526 | if (index == 1) |
| 527 | seq_printf(m,"L1l phy: log miss point count is:\n"); |
| 528 | |
| 529 | if (iram != NULL) |
| 530 | { |
| 531 | seq_printf(m,"1. Due to allocMem fail count: %u\n", iram->no_mem); |
| 532 | seq_printf(m,"2. Due to multi thread conflict count: %u\n", iram->no_lock); |
| 533 | } |
| 534 | iram = (T_LogIram_Record *)gL11_LogMissPoint; |
| 535 | } |
| 536 | |
| 537 | seq_printf(m,"done\n"); |
| 538 | |
| 539 | return 0; |
| 540 | } |
| 541 | |
| 542 | /** |
| 543 | * cpumask_parse_user - open funution |
| 544 | * @inode: file inode |
| 545 | * @file: file descriptor |
| 546 | * |
| 547 | * Returns -errno, or 0 for success. |
| 548 | */ |
| 549 | static int kernel_log_tracker_open(struct inode *inode, struct file *file) |
| 550 | { |
| 551 | return single_open(file, kernel_log_miss_point_show, NULL); |
| 552 | } |
| 553 | |
| 554 | /** |
| 555 | * kernel_log_tracker_proc_fops - proc file ops |
| 556 | * @open: open the registed proc file. |
| 557 | * @read: read the registed proc file. |
| 558 | * @write: write to the registed proc file. |
| 559 | * |
| 560 | * Returns -errno, or 0 for success. |
| 561 | */ |
| 562 | static const struct file_operations kernel_log_tracker_proc_fops = { |
| 563 | .open = kernel_log_tracker_open, |
| 564 | .read = seq_read, |
| 565 | .write = NULL |
| 566 | }; |
| 567 | |
| 568 | #endif |
| 569 | |
| 570 | /******************************************************************************* |
| 571 | * ¹¦ÄÜÃèÊö: ¹ì¼£Í³¼Æµ½DDR |
| 572 | * ²ÎÊý˵Ã÷: |
| 573 | * (´«Èë²ÎÊý) iram_addr: µØÖ· |
| 574 | data: ʼþÏî |
| 575 | time: ʱ¼ä |
| 576 | * (´«³ö²ÎÊý) void |
| 577 | * ·µ »Ø Öµ: void |
| 578 | * ÆäËü˵Ã÷: ÎÞ |
| 579 | *******************************************************************************/ |
| 580 | int __init zxic_enable_trace(void) |
| 581 | { |
| 582 | struct timer_list timer; |
| 583 | struct task_struct *task; |
| 584 | |
| 585 | #ifdef IRAM_BASE_ADDR_VA |
| 586 | g_zxic_trace_apcpu_addr = IRAM_BASE_ADDR_LINUX_STATISTIC_APCPU; |
| 587 | #else |
| 588 | |
| 589 | g_zxic_trace_apcpu_addr = ioremap(IRAM_BASE_ADDR_LINUX_STATISTIC_APCPU, IRAM_BASE_LEN_LINUX_STATISTIC_APCPU); |
| 590 | #endif |
| 591 | |
| 592 | #ifndef CONFIG_SYSTEM_CAP |
| 593 | proc_create("kernel_log_tracker", 0, NULL, &kernel_log_tracker_proc_fops); |
| 594 | #endif |
xf.li | 771eb06 | 2025-02-09 23:05:11 -0800 | [diff] [blame^] | 595 | |
| 596 | g_os_reset_reason = (T_Reset_Reason *)OS_IRAM_RESET_REASON_START; |
xf.li | bfc6e71 | 2025-02-07 01:54:34 -0800 | [diff] [blame] | 597 | /* |
| 598 | init_timer(&timer); |
| 599 | timer.expires = jiffies + 40*HZ;//msecs_to_jiffies(40*1000);//ÑÓ³Ù40Ãë |
| 600 | timer.data = 0; |
| 601 | timer.function = os_statistic_delayed_work_timer_fn; |
| 602 | setup_timer(&timer, os_statistic_delayed_work_timer_fn, 0); |
| 603 | add_timer(&timer); |
| 604 | */ |
| 605 | //task = kthread_create(os_statistic_delayed_work_timer_fn, 0, "g_zxic_trace_sync_thread", 0); |
| 606 | //wake_up_process(task); |
| 607 | |
| 608 | return 0x0; |
| 609 | } |
| 610 | module_init(zxic_enable_trace); |
| 611 | |
| 612 | |
| 613 | |