• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3  * Copyright (c) 2020-2021 Huawei Device Co., Ltd. All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without modification,
6  * are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice, this list of
9  *    conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12  *    of conditions and the following disclaimer in the documentation and/or other materials
13  *    provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16  *    to endorse or promote products derived from this software without specific prior written
17  *    permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include "los_config.h"
33 #ifdef LOSCFG_SHELL_CMD_DEBUG
34 #ifdef LOSCFG_CPUP_INCLUDE_IRQ
35 #include "los_cpup_pri.h"
36 #endif
37 #include "los_hwi_pri.h"
38 #include "los_sys_pri.h"
39 #include "shcmd.h"
40 
41 
42 #ifdef LOSCFG_CPUP_INCLUDE_IRQ
43 #define IRQ_CPUP_INFO_SIZE     (sizeof(CPUP_INFO_S) * OS_HWI_MAX_NUM * LOSCFG_KERNEL_CORE_NUM)
44 #define IRQ_CPUP_ALL_INFO_SIZE (3 * IRQ_CPUP_INFO_SIZE)
45 #define IRQ_DATA_SZIE          (sizeof(OsIrqCpupCB) * LOSCFG_KERNEL_CORE_NUM)
46 #define CPUP_PRECISION_MULT    LOS_CPUP_PRECISION_MULT
47 
ShellCmdHwiInfoShow(OsIrqCpupCB * irqData,CPUP_INFO_S * hwiCpup1s,CPUP_INFO_S * hwiCpup10s,CPUP_INFO_S * hwiCpupAll)48 STATIC VOID ShellCmdHwiInfoShow(OsIrqCpupCB *irqData, CPUP_INFO_S *hwiCpup1s,
49                                 CPUP_INFO_S *hwiCpup10s, CPUP_INFO_S *hwiCpupAll)
50 {
51     UINT32 intSave;
52     OsIrqCpupCB *irqDataBase = OsGetIrqCpupArrayBase();
53 
54     for (UINT32 i = OS_HWI_FORM_EXC_NUM; i < OS_HWI_MAX_NUM + OS_HWI_FORM_EXC_NUM; i++) {
55         if (!HWI_IS_REGISTED(i)) {
56             continue;
57         }
58 
59         intSave = LOS_IntLock();
60         (VOID)memcpy_s(irqData, IRQ_DATA_SZIE, &irqDataBase[i * LOSCFG_KERNEL_CORE_NUM], IRQ_DATA_SZIE);
61         LOS_IntRestore(intSave);
62 
63         for (UINT32 cpu = 0; cpu < LOSCFG_KERNEL_CORE_NUM; cpu++) {
64             UINT64 cycles = 0;
65             UINT64 timeMax = 0;
66             OsIrqCpupCB *data = &irqData[cpu];
67             if (data->status == 0) {
68                 continue;
69             }
70             UINT32 count = OsGetHwiFormCnt(cpu, i);
71             if (count != 0) {
72                 if (data->count != 0) {
73                     cycles = (data->allTime * OS_NS_PER_CYCLE) / (data->count * OS_SYS_NS_PER_US);
74                 }
75                 timeMax = (data->timeMax * OS_NS_PER_CYCLE) / 1000;
76             }
77             CHAR *irqName = OsGetHwiFormName(i);
78             UINT32 index = (i * LOSCFG_KERNEL_CORE_NUM) + cpu;
79             PRINTK(" %10u:%5u%11u%11llu%10llu%6u.%-2u%8u.%-2u%7u.%-2u%7s %-12s\n", i, cpu, count, cycles, timeMax,
80                    hwiCpupAll[index].usage / CPUP_PRECISION_MULT, hwiCpupAll[index].usage % CPUP_PRECISION_MULT,
81                    hwiCpup10s[index].usage / CPUP_PRECISION_MULT, hwiCpup10s[index].usage % CPUP_PRECISION_MULT,
82                    hwiCpup1s[index].usage / CPUP_PRECISION_MULT, hwiCpup1s[index].usage % CPUP_PRECISION_MULT,
83                    (g_hwiForm[index].uwParam == IRQF_SHARED) ? "shared" : "normal", (irqName != NULL) ? irqName : "");
84         }
85     }
86 }
87 
OsShellCmdHwi(INT32 argc,const CHAR ** argv)88 LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdHwi(INT32 argc, const CHAR **argv)
89 {
90     UINT32 size;
91 
92     (VOID)argv;
93     if (argc > 0) {
94         PRINTK("\nUsage: hwi\n");
95         return OS_ERROR;
96     }
97 
98     size = IRQ_CPUP_ALL_INFO_SIZE + IRQ_DATA_SZIE;
99     CHAR *irqCpup = LOS_MemAlloc(m_aucSysMem0, size);
100     if (irqCpup == NULL) {
101         return OS_ERROR;
102     }
103 
104     CPUP_INFO_S *hwiCpupAll = (CPUP_INFO_S *)irqCpup;
105     CPUP_INFO_S *hwiCpup10s = (CPUP_INFO_S *)(irqCpup + IRQ_CPUP_INFO_SIZE);
106     CPUP_INFO_S *hwiCpup1s = (CPUP_INFO_S *)(irqCpup + 2 * IRQ_CPUP_INFO_SIZE); /* 2: offset */
107     OsIrqCpupCB *irqData = (OsIrqCpupCB *)(irqCpup + IRQ_CPUP_ALL_INFO_SIZE);
108 
109     (VOID)LOS_GetAllIrqCpuUsage(CPUP_ALL_TIME, hwiCpupAll, IRQ_CPUP_INFO_SIZE);
110     (VOID)LOS_GetAllIrqCpuUsage(CPUP_LAST_TEN_SECONDS, hwiCpup10s, IRQ_CPUP_INFO_SIZE);
111     (VOID)LOS_GetAllIrqCpuUsage(CPUP_LAST_ONE_SECONDS, hwiCpup1s, IRQ_CPUP_INFO_SIZE);
112 
113     PRINTK(" InterruptNo  cpu      Count  ATime(us) MTime(us)   CPUUSE  CPUUSE10s  CPUUSE1s   Mode Name\n");
114     ShellCmdHwiInfoShow(irqData, hwiCpup1s, hwiCpup10s, hwiCpupAll);
115     (VOID)LOS_MemFree(m_aucSysMem0, irqCpup);
116     return 0;
117 }
118 #else
OsShellCmdHwi(INT32 argc,const CHAR ** argv)119 LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdHwi(INT32 argc, const CHAR **argv)
120 {
121     UINT32 i;
122 
123     (VOID)argv;
124     if (argc > 0) {
125         PRINTK("\nUsage: hwi\n");
126         return OS_ERROR;
127     }
128 
129     PRINTK(" InterruptNo     Count     Name\n");
130     for (i = OS_HWI_FORM_EXC_NUM; i < OS_HWI_MAX_NUM + OS_HWI_FORM_EXC_NUM; i++) {
131         /* Different cores has different hwi form implementation */
132         if (HWI_IS_REGISTED(i) && (OsGetHwiFormName(i) != NULL)) {
133             PRINTK(" %8d:%10d:      %-s\n", i, OsGetHwiFormCnt(i), OsGetHwiFormName(i));
134         } else if (HWI_IS_REGISTED(i)) {
135             PRINTK(" %8d:%10d:\n", i, OsGetHwiFormCnt(i));
136         }
137     }
138     return 0;
139 }
140 #endif
141 
142 SHELLCMD_ENTRY(hwi_shellcmd, CMD_TYPE_EX, "hwi", 0, (CmdCallBackFunc)OsShellCmdHwi);
143 
144 #endif /* LOSCFG_SHELL */
145