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