• 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 #include "los_swtmr.h"
34 #include "los_sem_pri.h"
35 #include "los_queue_pri.h"
36 #include "los_swtmr_pri.h"
37 #include "los_task_pri.h"
38 #ifdef LOSCFG_IPC_CONTAINER
39 #include "los_ipc_container_pri.h"
40 #endif
41 
42 #ifdef LOSCFG_SHELL
43 #include "shcmd.h"
44 #include "shell.h"
45 #endif
46 
47 
48 #define SYSINFO_ENABLED(x) (((x) == TRUE) ? "YES" : "NO")
OsShellCmdTaskCntGet(VOID)49 UINT32 OsShellCmdTaskCntGet(VOID)
50 {
51     UINT32 loop;
52     UINT32 taskCnt = 0;
53     UINT32 intSave;
54     LosTaskCB *taskCB = NULL;
55 
56     intSave = LOS_IntLock();
57     for (loop = 0; loop < g_taskMaxNum; loop++) {
58         taskCB = (LosTaskCB *)g_taskCBArray + loop;
59         if (OsTaskIsUnused(taskCB)) {
60             continue;
61         }
62         taskCnt++;
63     }
64     LOS_IntRestore(intSave);
65     return taskCnt;
66 }
67 
OsShellCmdSemCntGet(VOID)68 UINT32 OsShellCmdSemCntGet(VOID)
69 {
70     UINT32 loop;
71     UINT32 semCnt = 0;
72     UINT32 intSave;
73     LosSemCB *semNode = NULL;
74 
75     intSave = LOS_IntLock();
76     for (loop = 0; loop < LOSCFG_BASE_IPC_SEM_LIMIT; loop++) {
77         semNode = GET_SEM(loop);
78         if (semNode->semStat == OS_SEM_USED) {
79             semCnt++;
80         }
81     }
82     LOS_IntRestore(intSave);
83     return semCnt;
84 }
85 
OsShellCmdQueueCntGet(VOID)86 UINT32 OsShellCmdQueueCntGet(VOID)
87 {
88     UINT32 loop;
89     UINT32 queueCnt = 0;
90     UINT32 intSave;
91     LosQueueCB *queueCB = NULL;
92 
93     intSave = LOS_IntLock();
94     queueCB = IPC_ALL_QUEUE;
95     for (loop = 0; loop < LOSCFG_BASE_IPC_QUEUE_LIMIT; loop++, queueCB++) {
96         if (queueCB->queueState == OS_QUEUE_INUSED) {
97             queueCnt++;
98         }
99     }
100     LOS_IntRestore(intSave);
101     return queueCnt;
102 }
103 
OsShellCmdSwtmrCntGet(VOID)104 UINT32 OsShellCmdSwtmrCntGet(VOID)
105 {
106     UINT32 loop;
107     UINT32 swtmrCnt = 0;
108     UINT32 intSave;
109     SWTMR_CTRL_S *swtmrCB = NULL;
110 
111     intSave = LOS_IntLock();
112     swtmrCB = g_swtmrCBArray;
113     for (loop = 0; loop < LOSCFG_BASE_CORE_SWTMR_LIMIT; loop++, swtmrCB++) {
114         if (swtmrCB->ucState != OS_SWTMR_STATUS_UNUSED) {
115             swtmrCnt++;
116         }
117     }
118     LOS_IntRestore(intSave);
119     return swtmrCnt;
120 }
121 
OsShellCmdSystemInfoGet(VOID)122 LITE_OS_SEC_TEXT_MINOR VOID OsShellCmdSystemInfoGet(VOID)
123 {
124     UINT8 isTaskEnable  = TRUE;
125 #ifdef LOSCFG_BASE_IPC_SEM
126     UINT8 isSemEnable   = TRUE;
127 #else
128     UINT8 isSemEnable   = FALSE;
129 #endif
130 #ifdef LOSCFG_BASE_IPC_QUEUE
131     UINT8 isQueueEnable = TRUE;
132 #else
133     UINT8 isQueueEnable = FALSE;
134 #endif
135 #ifdef LOSCFG_BASE_CORE_SWTMR_ENABLE
136     UINT8 isSwtmrEnable = TRUE;
137 #else
138     UINT8 isSwtmrEnable = FALSE;
139 #endif
140 
141     PRINTK("\n   Module    Used      Total     Enabled\n");
142     PRINTK("--------------------------------------------\n");
143     PRINTK("   Task      %-10u%-10d%s\n",
144            OsShellCmdTaskCntGet(),
145            LOSCFG_BASE_CORE_TSK_LIMIT,
146            SYSINFO_ENABLED(isTaskEnable));
147     PRINTK("   Sem       %-10u%-10d%s\n",
148            OsShellCmdSemCntGet(),
149            LOSCFG_BASE_IPC_SEM_LIMIT,
150            SYSINFO_ENABLED(isSemEnable));
151     PRINTK("   Queue     %-10u%-10d%s\n",
152            OsShellCmdQueueCntGet(),
153            LOSCFG_BASE_IPC_QUEUE_LIMIT,
154            SYSINFO_ENABLED(isQueueEnable));
155     PRINTK("   SwTmr     %-10u%-10d%s\n",
156            OsShellCmdSwtmrCntGet(),
157            LOSCFG_BASE_CORE_SWTMR_LIMIT,
158            SYSINFO_ENABLED(isSwtmrEnable));
159 }
160 
OsShellCmdSystemInfo(INT32 argc,const CHAR ** argv)161 INT32 OsShellCmdSystemInfo(INT32 argc, const CHAR **argv)
162 {
163     if (argc == 0) {
164         OsShellCmdSystemInfoGet();
165         return 0;
166     }
167     PRINTK("systeminfo: invalid option %s\n"
168            "Systeminfo has NO ARGS.\n",
169            argv[0]);
170     return -1;
171 }
172 
173 #ifdef LOSCFG_SHELL
174 SHELLCMD_ENTRY(systeminfo_shellcmd, CMD_TYPE_EX, "systeminfo", 1, (CmdCallBackFunc)OsShellCmdSystemInfo);
175 #endif /* LOSCFG_SHELL */
176 
177