13d8536b4Sopenharmony_ci/* 23d8536b4Sopenharmony_ci * Copyright (c) 2022-2023 Huawei Device Co., Ltd. All rights reserved. 33d8536b4Sopenharmony_ci * 43d8536b4Sopenharmony_ci * Redistribution and use in source and binary forms, with or without modification, 53d8536b4Sopenharmony_ci * are permitted provided that the following conditions are met: 63d8536b4Sopenharmony_ci * 73d8536b4Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright notice, this list of 83d8536b4Sopenharmony_ci * conditions and the following disclaimer. 93d8536b4Sopenharmony_ci * 103d8536b4Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright notice, this list 113d8536b4Sopenharmony_ci * of conditions and the following disclaimer in the documentation and/or other materials 123d8536b4Sopenharmony_ci * provided with the distribution. 133d8536b4Sopenharmony_ci * 143d8536b4Sopenharmony_ci * 3. Neither the name of the copyright holder nor the names of its contributors may be used 153d8536b4Sopenharmony_ci * to endorse or promote products derived from this software without specific prior written 163d8536b4Sopenharmony_ci * permission. 173d8536b4Sopenharmony_ci * 183d8536b4Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 193d8536b4Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 203d8536b4Sopenharmony_ci * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 213d8536b4Sopenharmony_ci * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 223d8536b4Sopenharmony_ci * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 233d8536b4Sopenharmony_ci * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 243d8536b4Sopenharmony_ci * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 253d8536b4Sopenharmony_ci * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 263d8536b4Sopenharmony_ci * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 273d8536b4Sopenharmony_ci * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 283d8536b4Sopenharmony_ci * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 293d8536b4Sopenharmony_ci */ 303d8536b4Sopenharmony_ci 313d8536b4Sopenharmony_ci#include "los_debugtools.h" 323d8536b4Sopenharmony_ci#include "securec.h" 333d8536b4Sopenharmony_ci#include "los_debug.h" 343d8536b4Sopenharmony_ci#include "los_memory.h" 353d8536b4Sopenharmony_ci#include "los_arch.h" 363d8536b4Sopenharmony_ci#include "los_interrupt.h" 373d8536b4Sopenharmony_ci#include "los_arch_interrupt.h" 383d8536b4Sopenharmony_ci 393d8536b4Sopenharmony_ci#if (LOSCFG_DEBUG_TOOLS == 1) 403d8536b4Sopenharmony_ci 413d8536b4Sopenharmony_ci#if (LOSCFG_CPUP_INCLUDE_IRQ == 1) && (LOSCFG_BASE_CORE_SWTMR == 1) 423d8536b4Sopenharmony_ci#include "los_cpup.h" 433d8536b4Sopenharmony_ci 443d8536b4Sopenharmony_ci#define IRQ_CPUP_INFO_SIZE (sizeof(CPUP_INFO_S) * LOSCFG_PLATFORM_HWI_LIMIT) 453d8536b4Sopenharmony_ci#define IRQ_CPUP_ALL_INFO_SIZE (IRQ_CPUP_INFO_SIZE + IRQ_CPUP_INFO_SIZE) 463d8536b4Sopenharmony_ci#define IRQ_DATA_SIZE sizeof(OsIrqCpupCB) 473d8536b4Sopenharmony_ci#define CPUP_PRECISION_MULT LOS_CPUP_PRECISION_MULT 483d8536b4Sopenharmony_ci 493d8536b4Sopenharmony_ciSTATIC VOID ShellCmdHwiInfoShow(OsIrqCpupCB *irqData, CPUP_INFO_S *hwiCpup1s, 503d8536b4Sopenharmony_ci CPUP_INFO_S *hwiCpup10s) 513d8536b4Sopenharmony_ci{ 523d8536b4Sopenharmony_ci UINT32 i; 533d8536b4Sopenharmony_ci UINT32 intSave; 543d8536b4Sopenharmony_ci UINT32 count; 553d8536b4Sopenharmony_ci UINT64 cycles = 0; 563d8536b4Sopenharmony_ci UINT64 timeMax = 0; 573d8536b4Sopenharmony_ci CHAR *irqName = NULL; 583d8536b4Sopenharmony_ci 593d8536b4Sopenharmony_ci OsIrqCpupCB *irqDataBase = OsGetIrqCpupArrayBase(); 603d8536b4Sopenharmony_ci if (irqDataBase == NULL) { 613d8536b4Sopenharmony_ci PRINT_ERR("get hwi info error\n"); 623d8536b4Sopenharmony_ci return; 633d8536b4Sopenharmony_ci } 643d8536b4Sopenharmony_ci 653d8536b4Sopenharmony_ci for (i = 0; i < LOSCFG_PLATFORM_HWI_LIMIT; i++) { 663d8536b4Sopenharmony_ci if ((OsHwiIsCreated(i) != TRUE) || (OsGetHwiFormCnt(i) == 0)) { 673d8536b4Sopenharmony_ci continue; 683d8536b4Sopenharmony_ci } 693d8536b4Sopenharmony_ci 703d8536b4Sopenharmony_ci intSave = LOS_IntLock(); 713d8536b4Sopenharmony_ci (VOID)memcpy_s(irqData, IRQ_DATA_SIZE, &irqDataBase[i], IRQ_DATA_SIZE); 723d8536b4Sopenharmony_ci LOS_IntRestore(intSave); 733d8536b4Sopenharmony_ci 743d8536b4Sopenharmony_ci if (irqData->status == 0) { 753d8536b4Sopenharmony_ci continue; 763d8536b4Sopenharmony_ci } 773d8536b4Sopenharmony_ci 783d8536b4Sopenharmony_ci count = OsGetHwiFormCnt(i); 793d8536b4Sopenharmony_ci if (count != 0) { 803d8536b4Sopenharmony_ci if (irqData->count != 0) { 813d8536b4Sopenharmony_ci cycles = (irqData->allTime * OS_NS_PER_CYCLE) / (irqData->count * OS_SYS_NS_PER_US); 823d8536b4Sopenharmony_ci } 833d8536b4Sopenharmony_ci timeMax = (irqData->timeMax * OS_NS_PER_CYCLE) / OS_SYS_NS_PER_US; 843d8536b4Sopenharmony_ci } 853d8536b4Sopenharmony_ci irqName = OsGetHwiFormName(i); 863d8536b4Sopenharmony_ci 873d8536b4Sopenharmony_ci PRINTK(" %10d:%11u%11llu%10llu%9u.%-2u%9u.%-2u %-12s\n", i - OS_SYS_VECTOR_CNT, count, cycles, timeMax, 883d8536b4Sopenharmony_ci hwiCpup1s[i].uwUsage / CPUP_PRECISION_MULT, hwiCpup1s[i].uwUsage % CPUP_PRECISION_MULT, 893d8536b4Sopenharmony_ci hwiCpup10s[i].uwUsage / CPUP_PRECISION_MULT, hwiCpup10s[i].uwUsage % CPUP_PRECISION_MULT, 903d8536b4Sopenharmony_ci (irqName != NULL) ? irqName : NULL); 913d8536b4Sopenharmony_ci } 923d8536b4Sopenharmony_ci} 933d8536b4Sopenharmony_ci 943d8536b4Sopenharmony_ciSTATIC VOID HwiInfoDump(VOID) 953d8536b4Sopenharmony_ci{ 963d8536b4Sopenharmony_ci UINT32 size; 973d8536b4Sopenharmony_ci 983d8536b4Sopenharmony_ci size = IRQ_CPUP_ALL_INFO_SIZE + IRQ_DATA_SIZE; 993d8536b4Sopenharmony_ci CHAR *irqCpup = LOS_MemAlloc(m_aucSysMem0, size); 1003d8536b4Sopenharmony_ci if (irqCpup == NULL) { 1013d8536b4Sopenharmony_ci return; 1023d8536b4Sopenharmony_ci } 1033d8536b4Sopenharmony_ci 1043d8536b4Sopenharmony_ci CPUP_INFO_S *hwiCpup10s = (CPUP_INFO_S *)(irqCpup); 1053d8536b4Sopenharmony_ci CPUP_INFO_S *hwiCpup1s = (CPUP_INFO_S *)(hwiCpup10s + IRQ_CPUP_INFO_SIZE); 1063d8536b4Sopenharmony_ci OsIrqCpupCB *irqData = (OsIrqCpupCB *)(irqCpup + IRQ_CPUP_ALL_INFO_SIZE); 1073d8536b4Sopenharmony_ci 1083d8536b4Sopenharmony_ci (VOID)LOS_GetAllIrqCpuUsage(CPUP_IN_1S, hwiCpup1s); 1093d8536b4Sopenharmony_ci (VOID)LOS_GetAllIrqCpuUsage(CPUP_IN_10S, hwiCpup10s); 1103d8536b4Sopenharmony_ci 1113d8536b4Sopenharmony_ci PRINTK(" InterruptNo Count ATime(us) MTime(us) CPUUSE1s CPUUSE10s Name\n"); 1123d8536b4Sopenharmony_ci ShellCmdHwiInfoShow(irqData, hwiCpup1s, hwiCpup10s); 1133d8536b4Sopenharmony_ci (VOID)LOS_MemFree(m_aucSysMem0, irqCpup); 1143d8536b4Sopenharmony_ci return; 1153d8536b4Sopenharmony_ci} 1163d8536b4Sopenharmony_ci#else 1173d8536b4Sopenharmony_ciSTATIC VOID HwiInfoDump(VOID) 1183d8536b4Sopenharmony_ci{ 1193d8536b4Sopenharmony_ci INT32 i; 1203d8536b4Sopenharmony_ci 1213d8536b4Sopenharmony_ci PRINTK(" InterruptNo Count Name\n"); 1223d8536b4Sopenharmony_ci for (i = 0; i < LOSCFG_PLATFORM_HWI_LIMIT; i++) { 1233d8536b4Sopenharmony_ci if ((OsHwiIsCreated(i) != TRUE) || (OsGetHwiFormCnt(i) == 0)) { 1243d8536b4Sopenharmony_ci continue; 1253d8536b4Sopenharmony_ci } 1263d8536b4Sopenharmony_ci 1273d8536b4Sopenharmony_ci if (OsGetHwiFormName(i) != NULL) { 1283d8536b4Sopenharmony_ci PRINTK(" %8d:%10d %-s\n", i - OS_SYS_VECTOR_CNT, OsGetHwiFormCnt(i), OsGetHwiFormName(i)); 1293d8536b4Sopenharmony_ci } else { 1303d8536b4Sopenharmony_ci PRINTK(" %8d:%10d\n", i - OS_SYS_VECTOR_CNT, OsGetHwiFormCnt(i)); 1313d8536b4Sopenharmony_ci } 1323d8536b4Sopenharmony_ci } 1333d8536b4Sopenharmony_ci return; 1343d8536b4Sopenharmony_ci} 1353d8536b4Sopenharmony_ci#endif 1363d8536b4Sopenharmony_ci 1373d8536b4Sopenharmony_ciUINT32 OsShellCmdHwiDump(INT32 argc, const CHAR **argv) 1383d8536b4Sopenharmony_ci{ 1393d8536b4Sopenharmony_ci (VOID)argv; 1403d8536b4Sopenharmony_ci 1413d8536b4Sopenharmony_ci if (argc > 1) { 1423d8536b4Sopenharmony_ci PRINT_ERR("\nUsage:hwi\n"); 1433d8536b4Sopenharmony_ci return LOS_NOK; 1443d8536b4Sopenharmony_ci } 1453d8536b4Sopenharmony_ci 1463d8536b4Sopenharmony_ci HwiInfoDump(); 1473d8536b4Sopenharmony_ci return LOS_OK; 1483d8536b4Sopenharmony_ci} 1493d8536b4Sopenharmony_ci#endif /* LOSCFG_STACK_DUMP == 1 */ 150