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 "shcmd.h"
39
40
41 #ifdef LOSCFG_CPUP_INCLUDE_IRQ
42 STATIC CPUP_INFO_S hwiCpupAll[OS_HWI_MAX_NUM];
43 STATIC CPUP_INFO_S hwiCpup10s[OS_HWI_MAX_NUM];
44 STATIC CPUP_INFO_S hwiCpup1s[OS_HWI_MAX_NUM];
OsShellCmdHwi(INT32 argc,const CHAR ** argv)45 LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdHwi(INT32 argc, const CHAR **argv)
46 {
47 UINT32 i;
48 UINT64 cycles;
49 size_t size = sizeof(CPUP_INFO_S) * OS_HWI_MAX_NUM;
50 OsIrqCpupCB *irqCpup = OsGetIrqCpupArrayBase();
51
52 (VOID)argv;
53 if (argc > 0) {
54 PRINTK("\nUsage: hwi\n");
55 return OS_ERROR;
56 }
57
58 if (irqCpup == NULL) {
59 return OS_ERROR;
60 }
61
62 (VOID)LOS_GetAllIrqCpuUsage(CPUP_ALL_TIME, hwiCpupAll, size);
63 (VOID)LOS_GetAllIrqCpuUsage(CPUP_LAST_TEN_SECONDS, hwiCpup10s, size);
64 (VOID)LOS_GetAllIrqCpuUsage(CPUP_LAST_ONE_SECONDS, hwiCpup1s, size);
65
66 PRINTK(" InterruptNo Count ATime(us) CPUUSE CPUUSE10s CPUUSE1s Mode Name\n");
67 for (i = OS_HWI_FORM_EXC_NUM; i < OS_HWI_MAX_NUM + OS_HWI_FORM_EXC_NUM; i++) {
68 UINT32 count = OsGetHwiFormCnt(i);
69 if (count) {
70 cycles = (((OsIrqCpupCB *)(&irqCpup[i]))->cpup.allTime * OS_NS_PER_CYCLE) / (count * OS_SYS_NS_PER_US);
71 } else {
72 cycles = 0;
73 }
74 /* Different cores has different hwi form implementation */
75 if (HWI_IS_REGISTED(i)) {
76 PRINTK(" %10d:%11u%11llu", i, count, cycles);
77 } else {
78 continue;
79 }
80 PRINTK("%6u.%-2u%8u.%-2u%7u.%-2u%7s %-12s\n",
81 hwiCpupAll[i].usage / LOS_CPUP_PRECISION_MULT,
82 hwiCpupAll[i].usage % LOS_CPUP_PRECISION_MULT,
83 hwiCpup10s[i].usage / LOS_CPUP_PRECISION_MULT,
84 hwiCpup10s[i].usage % LOS_CPUP_PRECISION_MULT,
85 hwiCpup1s[i].usage / LOS_CPUP_PRECISION_MULT,
86 hwiCpup1s[i].usage % LOS_CPUP_PRECISION_MULT,
87 (g_hwiForm[i].uwParam == IRQF_SHARED) ? "shared" : "normal",
88 (OsGetHwiFormName(i) != NULL) ? OsGetHwiFormName(i) : "");
89 }
90 return 0;
91 }
92 #else
OsShellCmdHwi(INT32 argc,const CHAR ** argv)93 LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdHwi(INT32 argc, const CHAR **argv)
94 {
95 UINT32 i;
96
97 (VOID)argv;
98 if (argc > 0) {
99 PRINTK("\nUsage: hwi\n");
100 return OS_ERROR;
101 }
102
103 PRINTK(" InterruptNo Count Name\n");
104 for (i = OS_HWI_FORM_EXC_NUM; i < OS_HWI_MAX_NUM + OS_HWI_FORM_EXC_NUM; i++) {
105 /* Different cores has different hwi form implementation */
106 if (HWI_IS_REGISTED(i) && (OsGetHwiFormName(i) != NULL)) {
107 PRINTK(" %8d:%10d: %-s\n", i, OsGetHwiFormCnt(i), OsGetHwiFormName(i));
108 } else if (HWI_IS_REGISTED(i)) {
109 PRINTK(" %8d:%10d:\n", i, OsGetHwiFormCnt(i));
110 }
111 }
112 return 0;
113 }
114 #endif
115
116 SHELLCMD_ENTRY(hwi_shellcmd, CMD_TYPE_EX, "hwi", 0, (CmdCallBackFunc)OsShellCmdHwi);
117
118 #endif /* LOSCFG_SHELL */
119