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