更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
task_shellcmd.c
浏览该文件的文档.
1/*
2 * Copyright (c) 2013-2019 Huawei Technologies Co., Ltd. All rights reserved.
3 * Copyright (c) 2020-2022 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 "stdlib.h"
33#include "los_config.h"
34#include "los_exc.h"
35#include "los_memstat_pri.h"
36#include "los_sem_pri.h"
37#include "los_seq_buf.h"
38#include "los_task_pri.h"
39#ifdef LOSCFG_SHELL
40#include "shcmd.h"
41#include "shell.h"
42#endif
43#ifdef LOSCFG_KERNEL_CPUP
44#include "los_cpup_pri.h"
45#endif
46#ifdef LOSCFG_SAVE_EXCINFO
47#include "los_excinfo_pri.h"
48#endif
49#include "los_process_pri.h"
50#include "los_vm_dump.h"
51#ifdef LOSCFG_FS_VFS
52#include "fs/file.h"
53#endif
54#include "los_sched_pri.h"
55#include "los_swtmr_pri.h"
56
57#define OS_PROCESS_MEM_INFO 0x2U
58#define OS_PROCESS_INFO_LEN (g_processMaxNum * (sizeof(LosProcessCB)))
59#define OS_PROCESS_GROUP_INFO_LEN (g_processMaxNum * sizeof(UINT32))
60#define OS_PROCESS_UID_INFO_LEN (g_processMaxNum * sizeof(UINT32))
61#define OS_PROCESS_MEM_ALL_INFO_LEN (g_processMaxNum * PROCESS_MEMINFO_LEN)
62#ifdef LOSCFG_KERNEL_CPUP
63#define OS_PROCESS_CPUP_LEN (g_processMaxNum * sizeof(CPUP_INFO_S))
64#define OS_PROCESS_AND_TASK_CPUP_LEN ((g_processMaxNum + g_taskMaxNum) * sizeof(CPUP_INFO_S))
65#define OS_PROCESS_CPUP_ALLINFO_LEN (OS_PROCESS_AND_TASK_CPUP_LEN * 3)
66STATIC VOID TaskCpupInfoBaseGet(UINTPTR base, const CPUP_INFO_S **, const CPUP_INFO_S **, const CPUP_INFO_S **);
67STATIC VOID ProcessCpupInfoBaseGet(UINTPTR base, const CPUP_INFO_S **, const CPUP_INFO_S **, const CPUP_INFO_S **);
68#else
69#define OS_PROCESS_CPUP_ALLINFO_LEN 0
70#endif
71#define OS_PROCESS_ALL_INFO_LEN (g_processMaxNum * (sizeof(LosProcessCB) + sizeof(UINT32)) + \
72 OS_PROCESS_CPUP_ALLINFO_LEN + OS_PROCESS_UID_INFO_LEN)
73
74#define OS_INVALID_SEM_ID 0xFFFFFFFF
75#define OS_TASK_WATER_LINE_SIZE (g_taskMaxNum * sizeof(UINT32))
76#define OS_TASK_INFO_LEN (g_taskMaxNum * sizeof(LosTaskCB))
77#define OS_TASK_SCHED_INFO_LEN (g_taskMaxNum * sizeof(SchedParam))
78#define OS_TASK_ALL_INFO_LEN (g_taskMaxNum * (sizeof(LosTaskCB) + sizeof(UINT32) + sizeof(SchedParam)))
79
80#undef SHOW
81#ifdef LOSCFG_FS_VFS
82#if defined(LOSCFG_BLACKBOX) && defined(LOSCFG_SAVE_EXCINFO)
83#define SaveExcInfo(arg, ...) WriteExcInfoToBuf(arg, ##__VA_ARGS__)
84#else
85#define SaveExcInfo(arg, ...)
86#endif
87#define SHOW(arg...) do { \
88 if (seqBuf != NULL) { \
89 (void)LosBufPrintf((struct SeqBuf *)seqBuf, ##arg); \
90 } else { \
91 PRINTK(arg); \
92 } \
93 SaveExcInfo(arg); \
94} while (0)
95#else
96#define SHOW(arg...) PRINTK(arg)
97#endif
98
99#define VM_INDEX PROCESS_VM_INDEX
100#define SM_INDEX PROCESS_SM_INDEX
101#define PM_INDEX PROCESS_PM_INDEX
102#define CPUP_MULT LOS_CPUP_PRECISION_MULT
103
105{
106 if (mode == OS_KERNEL_MODE) {
107 return (UINT8 *)"kernel";
108 } else if (mode == OS_USER_MODE) {
109 return (UINT8 *)"user";
110 }
111
112 return (UINT8 *)"ERROR";
113}
114
116{
117 if (policy == LOS_SCHED_RR) {
118 return (UINT8 *)"RR";
119 } else if (policy == LOS_SCHED_FIFO) {
120 return (UINT8 *)"FIFO";
121 } else if (policy == LOS_SCHED_IDLE) {
122 return (UINT8 *)"IDLE";
123 }
124
125 return (UINT8 *)"ERROR";
126}
127
129{
130 if (status & OS_PROCESS_STATUS_ZOMBIES) {
131 return (UINT8 *)"Zombies";
132 } else if (status & OS_PROCESS_STATUS_INIT) {
133 return (UINT8 *)"Init";
134 } else if (status & OS_PROCESS_STATUS_RUNNING) {
135 return (UINT8 *)"Running";
136 } else if (status & OS_PROCESS_STATUS_READY) {
137 return (UINT8 *)"Ready";
138 }
139 return (UINT8 *)"Pending";
140}
141
142STATIC VOID ProcessInfoTitle(VOID *seqBuf, UINT16 flag)
143{
144 SHOW("\r\n PID PPID PGID UID Mode Status Policy Priority MTID TTotal");
145 if (flag & OS_PROCESS_INFO_ALL) {
146 if (flag & OS_PROCESS_MEM_INFO) {
147 SHOW(" VirtualMem ShareMem PhysicalMem");
148 }
149#ifdef LOSCFG_KERNEL_CPUP
150 SHOW(" CPUUSE CPUUSE10s CPUUSE1s");
151#endif /* LOSCFG_KERNEL_CPUP */
152 } else {
153#ifdef LOSCFG_KERNEL_CPUP
154 SHOW(" CPUUSE10s");
155#endif /* LOSCFG_KERNEL_CPUP */
156 }
157 SHOW(" PName\n");
158}
159
160STATIC VOID AllProcessDataShow(const LosProcessCB *pcbArray, const SchedParam *param,
161 UINTPTR cpupInfo, VOID *seqBuf, UINT16 flag)
162{
163 const INT32 *group = (const INT32 *)((UINTPTR)pcbArray + OS_PROCESS_INFO_LEN);
164 const INT32 *user = (const INT32 *)((UINTPTR)group + OS_PROCESS_GROUP_INFO_LEN);
165 const UINT32 *memArray = (const UINT32 *)((UINTPTR)pcbArray + OS_PROCESS_ALL_INFO_LEN);
166#ifdef LOSCFG_KERNEL_CPUP
167 const CPUP_INFO_S *cpupAll = NULL;
168 const CPUP_INFO_S *cpup10s = NULL;
169 const CPUP_INFO_S *cpup1s = NULL;
170 ProcessCpupInfoBaseGet(cpupInfo, &cpupAll, &cpup10s, &cpup1s);
171#else
172 (VOID)cpupInfo;
173#endif
174
175 for (UINT32 pid = 1; pid < g_processMaxNum; ++pid) {
176 const LosProcessCB *processCB = pcbArray + pid;
177 if (OsProcessIsUnused(processCB)) {
178 continue;
179 }
180
181 SHOW("%5u%6d%5d%6d%7s%8s%7s%9u%5u%7u", pid, (INT32)processCB->parentProcessID, group[pid], user[pid],
183 ConvertSchedPolicyToString(LOS_SCHED_RR), param[processCB->threadGroupID].basePrio,
184 processCB->threadGroupID, processCB->threadNumber);
185
186 if (flag & OS_PROCESS_INFO_ALL) {
187 if (flag & OS_PROCESS_MEM_INFO) {
188 const UINT32 *memUsage = &memArray[pid * PROCESS_VM_INDEX_MAX];
189 SHOW("%#11x%#9x%#12x", memUsage[VM_INDEX], memUsage[SM_INDEX], memUsage[PM_INDEX]);
190 }
191#ifdef LOSCFG_KERNEL_CPUP
192 SHOW("%4u.%-2u%7u.%-2u%6u.%-2u ", cpupAll[pid].usage / CPUP_MULT, cpupAll[pid].usage % CPUP_MULT,
193 cpup10s[pid].usage / CPUP_MULT, cpup10s[pid].usage % CPUP_MULT,
194 cpup1s[pid].usage / CPUP_MULT, cpup1s[pid].usage % CPUP_MULT);
195#endif /* LOSCFG_KERNEL_CPUP */
196 } else {
197#ifdef LOSCFG_KERNEL_CPUP
198 SHOW("%7u.%-2u ", cpup10s[pid].usage / CPUP_MULT, cpup10s[pid].usage % CPUP_MULT);
199#endif /* LOSCFG_KERNEL_CPUP */
200 }
201 SHOW("%-32s\n", processCB->processName);
202 }
203}
204
205#ifdef LOSCFG_KERNEL_VM
206STATIC VOID ProcessMemUsageGet(LosProcessCB *pcbArray)
207{
208 UINT32 intSave, memUsed;
209 UINT32 *memArray = (UINT32 *)((UINTPTR)pcbArray + OS_PROCESS_ALL_INFO_LEN);
210
211 for (UINT32 pid = 0; pid < g_processMaxNum; ++pid) {
212 const LosProcessCB *processCB = g_processCBArray + pid;
213 UINT32 *proMemUsage = &memArray[pid * PROCESS_VM_INDEX_MAX];
214
215 SCHEDULER_LOCK(intSave);
216 if (OsProcessIsUnused(processCB)) {
217 SCHEDULER_UNLOCK(intSave);
218 pcbArray[pid].processStatus = OS_PROCESS_FLAG_UNUSED;
219 continue;
220 }
221
222 LosVmSpace *vmSpace = processCB->vmSpace;
223 SCHEDULER_UNLOCK(intSave);
224
225 /* Process memory usage statistics, idle task defaults to 0 */
226 if (pid == OsGetIdleProcessID()) {
227 proMemUsage[VM_INDEX] = 0;
228 proMemUsage[SM_INDEX] = 0;
229 proMemUsage[PM_INDEX] = 0;
230 } else if (vmSpace == LOS_GetKVmSpace()) {
231 (VOID)OsShellCmdProcessPmUsage(vmSpace, &proMemUsage[SM_INDEX], &proMemUsage[PM_INDEX]);
232 proMemUsage[VM_INDEX] = proMemUsage[PM_INDEX];
233 } else {
234 memUsed = OsShellCmdProcessVmUsage(vmSpace);
235 if (memUsed == 0) {
236 pcbArray[pid].processStatus = OS_PROCESS_FLAG_UNUSED;
237 continue;
238 }
239 proMemUsage[VM_INDEX] = memUsed;
240 memUsed = OsShellCmdProcessPmUsage(vmSpace, &proMemUsage[SM_INDEX], &proMemUsage[PM_INDEX]);
241 if (memUsed == 0) {
242 pcbArray[pid].processStatus = OS_PROCESS_FLAG_UNUSED;
243 }
244 }
245 }
246}
247#endif
248
249#define OS_TASK_STATUS_MASK 0x00FF
250STATIC VOID ProcessInfoGet(LosProcessCB **pcbArray, LosTaskCB **tcbArray, SchedParam **schedParam)
251{
252 INT32 *group = (INT32 *)((UINTPTR)*pcbArray + OS_PROCESS_INFO_LEN);
253 INT32 *user = (INT32 *)((UINTPTR)group + OS_PROCESS_GROUP_INFO_LEN);
254 SchedParam *param = (SchedParam *)((UINTPTR)*tcbArray + OS_TASK_INFO_LEN);
255 *schedParam = param;
256
257 for (UINT32 tid = 0; tid < g_taskMaxNum; tid++) {
258 const LosTaskCB *taskCB = *tcbArray + tid;
259 if (OsTaskIsUnused(taskCB)) {
260 continue;
261 }
262
263 LosProcessCB *processCB = *pcbArray + taskCB->processID;
264 if (!OsProcessIsDead(processCB) && !OsProcessIsInit(processCB)) {
265 processCB->processStatus |= (taskCB->taskStatus & OS_TASK_STATUS_MASK);
266 }
267 taskCB->ops->schedParamGet(taskCB, &param[tid]);
268 }
269
270 for (UINT32 pid = 0; pid < g_processMaxNum; ++pid) {
271 const LosProcessCB *processCB = *pcbArray + pid;
272 if (OsProcessIsUnused(processCB)) {
273 continue;
274 }
275
276 if (processCB->group != NULL) {
277 group[processCB->processID] = processCB->group->groupID;
278 } else {
279 group[processCB->processID] = -1;
280 }
281
282#ifdef LOSCFG_SECURITY_CAPABILITY
283 if (processCB->user != NULL) {
284 user[processCB->processID] = processCB->user->userID;
285 } else {
286 user[processCB->processID] = -1;
287 }
288#else
289 user[processCB->processID] = 0;
290#endif
291 }
292}
293
294STATIC VOID ProcessInfoShow(const LosProcessCB *pcbArray, const SchedParam *param,
295 UINTPTR cpupInfo, VOID *seqBuf, UINT16 flag)
296{
297#ifdef LOSCFG_KERNEL_CPUP
298 const CPUP_INFO_S *cpupAll = NULL;
299 const CPUP_INFO_S *cpup10s = NULL;
300 const CPUP_INFO_S *cpup1s = NULL;
301 ProcessCpupInfoBaseGet(cpupInfo, &cpupAll, &cpup10s, &cpup1s);
303 UINT32 sysUsage = LOS_CPUP_PRECISION - cpupAll[pid].usage;
304
305 SHOW("\n allCpu(%%): %4u.%02u sys, %4u.%02u idle\n", sysUsage / CPUP_MULT, sysUsage % CPUP_MULT,
306 cpupAll[pid].usage / CPUP_MULT, cpupAll[pid].usage % CPUP_MULT);
307#endif
308
309 ProcessInfoTitle(seqBuf, flag);
310 AllProcessDataShow(pcbArray, param, cpupInfo, seqBuf, flag);
311}
312
314{
315 if (taskStatus & OS_TASK_STATUS_INIT) {
316 return (UINT8 *)"Init";
317 } else if (taskStatus & OS_TASK_STATUS_RUNNING) {
318 return (UINT8 *)"Running";
319 } else if (taskStatus & OS_TASK_STATUS_READY) {
320 return (UINT8 *)"Ready";
321 } else if (taskStatus & OS_TASK_STATUS_FROZEN) {
322 return (UINT8 *)"Frozen";
323 } else if (taskStatus & OS_TASK_STATUS_SUSPENDED) {
324 return (UINT8 *)"Suspended";
325 } else if (taskStatus & OS_TASK_STATUS_DELAY) {
326 return (UINT8 *)"Delay";
327 } else if (taskStatus & OS_TASK_STATUS_PENDING) {
328 if (taskStatus & OS_TASK_STATUS_PEND_TIME) {
329 return (UINT8 *)"PendTime";
330 } else {
331 return (UINT8 *)"Pending";
332 }
333 } else if (taskStatus & OS_TASK_STATUS_EXIT) {
334 return (UINT8 *)"Exit";
335 }
336
337 return (UINT8 *)"Invalid";
338}
339
340STATIC VOID TaskWaterLineGet(UINTPTR waterLineBase, LosTaskCB *tcbArray)
341{
342 UINT32 intSave;
343 UINT32 *taskWaterLine = (UINT32 *)waterLineBase;
344
345 for (UINT32 tid = 0; tid < g_taskMaxNum; ++tid) {
346 const LosTaskCB *taskCB = g_taskCBArray + tid;
347 SCHEDULER_LOCK(intSave);
348 if (OsTaskIsUnused(taskCB)) {
349 SCHEDULER_UNLOCK(intSave);
350 tcbArray[tid].taskStatus = OS_TASK_STATUS_UNUSED;
351 continue;
352 }
353
354 (VOID)OsStackWaterLineGet((const UINTPTR *)((UINTPTR)taskCB->topOfStack + taskCB->stackSize),
355 (const UINTPTR *)taskCB->topOfStack, &taskWaterLine[taskCB->taskID]);
356 SCHEDULER_UNLOCK(intSave);
357 }
358}
359
360#ifdef LOSCFG_SHELL_CMD_DEBUG
361#define OS_PEND_REASON_MAX_LEN 20
362
363STATIC CHAR *CheckTaskWaitFlag(const LosTaskCB *taskCB, UINTPTR *lockID)
364{
365 *lockID = taskCB->waitID;
366 switch (taskCB->waitFlag) {
367 case OS_TASK_WAIT_PROCESS:
368 return "Child";
369 case OS_TASK_WAIT_GID:
370 return "PGroup";
371 case OS_TASK_WAIT_ANYPROCESS:
372 return "AnyChild";
373 case OS_TASK_WAIT_SEM:
374 return "Semaphore";
375 case OS_TASK_WAIT_QUEUE:
376 return "Queue";
377 case OS_TASK_WAIT_JOIN:
378 return "Join";
379 case OS_TASK_WAIT_SIGNAL:
380 return "Signal";
381 case OS_TASK_WAIT_LITEIPC:
382 return "LiteIPC";
383 case OS_TASK_WAIT_MUTEX:
384 return "Mutex";
385 case OS_TASK_WAIT_EVENT:
386 return "Event";
387 case OS_TASK_WAIT_FUTEX:
388 return "Futex";
389 case OS_TASK_WAIT_COMPLETE:
390 return "Complete";
391 default:
392 break;
393 }
394
395 return NULL;
396}
397
398STATIC VOID TaskPendingReasonInfoGet(const LosTaskCB *taskCB, CHAR *pendReason, UINT32 maxLen, UINTPTR *lockID)
399{
400 CHAR *reason = NULL;
401
402 if (!(taskCB->taskStatus & OS_TASK_STATUS_PENDING)) {
403 reason = (CHAR *)ConvertTaskStatusToString(taskCB->taskStatus);
404 goto EXIT;
405 }
406
407 reason = CheckTaskWaitFlag(taskCB, lockID);
408 if (reason == NULL) {
409 reason = "Others";
410 }
411
412 if (taskCB->taskMux != NULL) {
413 *lockID = (UINTPTR)taskCB->taskMux;
414 LosTaskCB *owner = ((LosMux *)taskCB->taskMux)->owner;
415 if (owner != NULL) {
416 if (snprintf_s(pendReason, maxLen, maxLen - 1, "Mutex-%u", owner->taskID) == EOK) {
417 return;
418 }
419 }
420 }
421
422EXIT:
423 if (strcpy_s(pendReason, maxLen, reason) != EOK) {
424 PRINT_ERR("Get pend reason copy failed !\n");
425 }
426}
427#endif
428
429STATIC VOID TaskInfoTitle(VOID *seqBuf, UINT16 flag)
430{
431 SHOW("\r\n TID PID");
432#ifdef LOSCFG_KERNEL_SMP
433 SHOW(" Affi CPU");
434#endif
435 SHOW(" Status Policy Priority StackSize WaterLine");
436 if (flag & OS_PROCESS_INFO_ALL) {
437#ifdef LOSCFG_KERNEL_CPUP
438 SHOW(" CPUUSE CPUUSE10s CPUUSE1s");
439#endif /* LOSCFG_KERNEL_CPUP */
440#ifdef LOSCFG_SHELL_CMD_DEBUG
441 SHOW(" StackPoint TopOfStack PendReason LockID");
442#endif
443 } else {
444#ifdef LOSCFG_KERNEL_CPUP
445 SHOW(" CPUUSE10s ");
446#endif /* LOSCFG_KERNEL_CPUP */
447 }
448 SHOW(" TaskName\n");
449}
450
451STATIC VOID AllTaskInfoDataShow(const LosTaskCB *allTaskArray, UINTPTR cpupInfo, VOID *seqBuf, UINT16 flag)
452{
453 const SchedParam *param = (const SchedParam *)((UINTPTR)allTaskArray + OS_TASK_INFO_LEN);
454 const UINT32 *waterLine = (const UINT32 *)((UINTPTR)allTaskArray + OS_TASK_INFO_LEN + OS_TASK_SCHED_INFO_LEN);
455#ifdef LOSCFG_KERNEL_CPUP
456 const CPUP_INFO_S *cpupAll = NULL;
457 const CPUP_INFO_S *cpup10s = NULL;
458 const CPUP_INFO_S *cpup1s = NULL;
459 TaskCpupInfoBaseGet(cpupInfo, &cpupAll, &cpup10s, &cpup1s);
460#else
461 (VOID)cpupInfo;
462#endif
463 for (UINT32 pid = 1; pid < g_processMaxNum; ++pid) {
464 for (UINT32 tid = 0; tid < g_taskMaxNum; ++tid) {
465 const LosTaskCB *taskCB = allTaskArray + tid;
466 if (OsTaskIsUnused(taskCB) || (taskCB->processID != pid)) {
467 continue;
468 }
469#ifdef LOSCFG_SHELL_CMD_DEBUG
470 UINTPTR lockID = 0;
471 CHAR pendReason[OS_PEND_REASON_MAX_LEN] = { 0 };
472#endif
473 SHOW(" %4u%5u", tid, taskCB->processID);
474
475#ifdef LOSCFG_KERNEL_SMP
476 SHOW("%#5x%4d ", taskCB->cpuAffiMask, (INT16)(taskCB->currCpu));
477#endif
478 SHOW("%9s%7s%9u%#10x%#10x", ConvertTaskStatusToString(taskCB->taskStatus),
479 ConvertSchedPolicyToString(param[tid].policy), param[tid].priority, taskCB->stackSize, waterLine[tid]);
480 if (flag & OS_PROCESS_INFO_ALL) {
481#ifdef LOSCFG_KERNEL_CPUP
482 SHOW("%4u.%-2u%7u.%-2u%6u.%-2u ", cpupAll[tid].usage / CPUP_MULT, cpupAll[tid].usage % CPUP_MULT,
483 cpup10s[tid].usage / CPUP_MULT, cpup10s[tid].usage % CPUP_MULT,
484 cpup1s[tid].usage / CPUP_MULT, cpup1s[tid].usage % CPUP_MULT);
485#endif /* LOSCFG_KERNEL_CPUP */
486#ifdef LOSCFG_SHELL_CMD_DEBUG
487 TaskPendingReasonInfoGet(taskCB, pendReason, OS_PEND_REASON_MAX_LEN, &lockID);
488 SHOW("%#12x%#12x%11s%#11x", taskCB->stackPointer, taskCB->topOfStack, pendReason, lockID);
489#endif
490 } else {
491#ifdef LOSCFG_KERNEL_CPUP
492 SHOW("%8u.%-2u ", cpup10s[tid].usage / CPUP_MULT, cpup10s[tid].usage % CPUP_MULT);
493#endif /* LOSCFG_KERNEL_CPUP */
494 }
495 SHOW(" %-32s\n", taskCB->taskName);
496 }
497 }
498}
499
500STATIC VOID TaskInfoData(const LosTaskCB *allTaskArray, UINTPTR cpupInfo, VOID *seqBuf, UINT16 flag)
501{
502 TaskInfoTitle(seqBuf, flag);
503 AllTaskInfoDataShow(allTaskArray, cpupInfo, seqBuf, flag);
504}
505
506#ifdef LOSCFG_KERNEL_CPUP
507STATIC VOID TaskCpupInfoBaseGet(UINTPTR base, const CPUP_INFO_S **cpupAll,
508 const CPUP_INFO_S **cpup10s, const CPUP_INFO_S **cpup1s)
509{
510 UINTPTR processCpupAll = base + OS_PROCESS_UID_INFO_LEN;
511 *cpupAll = (CPUP_INFO_S *)(processCpupAll + OS_PROCESS_CPUP_LEN);
512 UINTPTR processCpup10s = processCpupAll + OS_PROCESS_AND_TASK_CPUP_LEN;
513 *cpup10s = (CPUP_INFO_S *)(processCpup10s + OS_PROCESS_CPUP_LEN);
514 UINTPTR processCpup1s = processCpup10s + OS_PROCESS_AND_TASK_CPUP_LEN;
515 *cpup1s = (CPUP_INFO_S *)(processCpup1s + OS_PROCESS_CPUP_LEN);
516}
517
518STATIC VOID ProcessCpupInfoBaseGet(UINTPTR base, const CPUP_INFO_S **cpupAll,
519 const CPUP_INFO_S **cpup10s, const CPUP_INFO_S **cpup1s)
520{
521 *cpupAll = (CPUP_INFO_S *)(base + OS_PROCESS_UID_INFO_LEN);
522 *cpup10s = (CPUP_INFO_S *)((UINTPTR)*cpupAll + OS_PROCESS_AND_TASK_CPUP_LEN);
523 *cpup1s = (CPUP_INFO_S *)((UINTPTR)*cpup10s + OS_PROCESS_AND_TASK_CPUP_LEN);
524}
525
526STATIC VOID TaskCpupInfoGet(UINTPTR base)
527{
528 UINT32 intSave;
529
530 CPUP_INFO_S *processCpupAll = (CPUP_INFO_S *)(base + OS_PROCESS_UID_INFO_LEN);
531 CPUP_INFO_S *processCpup10s = (CPUP_INFO_S *)((UINTPTR)processCpupAll + OS_PROCESS_AND_TASK_CPUP_LEN);
532 CPUP_INFO_S *processCpup1s = (CPUP_INFO_S *)((UINTPTR)processCpup10s + OS_PROCESS_AND_TASK_CPUP_LEN);
533
534 SCHEDULER_LOCK(intSave);
535 (VOID)OsGetAllProcessAndTaskCpuUsageUnsafe(CPUP_ALL_TIME, processCpupAll, OS_PROCESS_AND_TASK_CPUP_LEN);
536 SCHEDULER_UNLOCK(intSave);
537
538 SCHEDULER_LOCK(intSave);
539 (VOID)OsGetAllProcessAndTaskCpuUsageUnsafe(CPUP_LAST_TEN_SECONDS, processCpup10s, OS_PROCESS_AND_TASK_CPUP_LEN);
540 SCHEDULER_UNLOCK(intSave);
541
542 SCHEDULER_LOCK(intSave);
543 (VOID)OsGetAllProcessAndTaskCpuUsageUnsafe(CPUP_LAST_ONE_SECONDS, processCpup1s, OS_PROCESS_AND_TASK_CPUP_LEN);
544 SCHEDULER_UNLOCK(intSave);
545}
546#endif
547
548/*
549 * | pcb | group | user | task and process cpup | process mem | tcb | sched param | task water line |
550 */
551STATIC VOID ProcessAndTaskInfoGet(LosProcessCB **pcbArray, LosTaskCB **tcbArray,
552 SchedParam **schedParam, UINTPTR *cpupInfo, UINT16 flag)
553{
554 UINT32 intSave;
555 UINT32 processInfoLen = OS_PROCESS_ALL_INFO_LEN;
556
557#ifdef LOSCFG_KERNEL_VM
558 if (flag & OS_PROCESS_MEM_INFO) {
559 processInfoLen += OS_PROCESS_MEM_ALL_INFO_LEN;
560 }
561#endif
562
563 SCHEDULER_LOCK(intSave);
564 (VOID)memcpy_s(*pcbArray, OS_PROCESS_INFO_LEN, g_processCBArray, OS_PROCESS_INFO_LEN);
565 *tcbArray = (LosTaskCB *)((UINTPTR)*pcbArray + processInfoLen);
566 (VOID)memcpy_s(*tcbArray, OS_TASK_INFO_LEN, g_taskCBArray, OS_TASK_INFO_LEN);
567
568 ProcessInfoGet(pcbArray, tcbArray, schedParam);
569 SCHEDULER_UNLOCK(intSave);
570
571#ifdef LOSCFG_KERNEL_CPUP
572 *cpupInfo = (UINTPTR)*pcbArray + OS_PROCESS_INFO_LEN + OS_PROCESS_GROUP_INFO_LEN;
573 TaskCpupInfoGet(*cpupInfo);
574#endif
575
576#ifdef LOSCFG_KERNEL_VM
577 if (flag & OS_PROCESS_MEM_INFO) {
578 ProcessMemUsageGet(*pcbArray);
579 }
580#endif
581
582 TaskWaterLineGet((UINTPTR)*tcbArray + OS_TASK_INFO_LEN + OS_TASK_SCHED_INFO_LEN, *tcbArray);
583}
584
585LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdTskInfoGet(UINT32 taskID, VOID *seqBuf, UINT16 flag)
586{
587 UINT32 size;
588 LosProcessCB *pcbArray = NULL;
589 LosTaskCB *tcbArray = NULL;
590 SchedParam *schedParam = NULL;
591 UINTPTR cpupInfo = 0;
592
593 if (taskID == OS_ALL_TASK_MASK) {
594 if (flag & OS_PROCESS_MEM_INFO) {
595 size = OS_PROCESS_ALL_INFO_LEN + OS_PROCESS_MEM_ALL_INFO_LEN + OS_TASK_ALL_INFO_LEN;
596 } else {
597 size = OS_PROCESS_ALL_INFO_LEN + OS_TASK_ALL_INFO_LEN;
598 }
599 pcbArray = (LosProcessCB *)LOS_MemAlloc(m_aucSysMem1, size);
600 if (pcbArray == NULL) {
601 PRINT_ERR("Memory is not enough to save task info!\n");
602 return LOS_NOK;
603 }
604 (VOID)memset_s(pcbArray, size, 0, size);
605 ProcessAndTaskInfoGet(&pcbArray, &tcbArray, &schedParam, &cpupInfo, flag);
606 ProcessInfoShow(pcbArray, schedParam, cpupInfo, seqBuf, flag);
607 TaskInfoData(tcbArray, cpupInfo, seqBuf, flag);
608
609 (VOID)LOS_MemFree(m_aucSysMem1, pcbArray);
610 }
611
612 return LOS_OK;
613}
614
615LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdDumpTask(INT32 argc, const CHAR **argv)
616{
617 UINT32 flag = 0;
618#ifdef LOSCFG_KERNEL_VM
619 flag |= OS_PROCESS_MEM_INFO;
620#endif
621
622 if (argc >= 2) { /* 2: The task shell name restricts the parameters */
623 goto TASK_HELP;
624 }
625
626 if (argc == 1) {
627 if (strcmp("-a", argv[0]) == 0) {
628 flag |= OS_PROCESS_INFO_ALL;
629#ifdef LOSCFG_SCHED_DEBUG
630#ifdef LOSCFG_SCHED_TICK_DEBUG
631 } else if (strcmp("-i", argv[0]) == 0) {
633 return LOS_OK;
634 }
635 goto TASK_HELP;
636#endif
637 } else if (strcmp("-t", argv[0]) == 0) {
639 return LOS_OK;
640 }
641 goto TASK_HELP;
642#endif
643 } else {
644 goto TASK_HELP;
645 }
646 }
647
648 return OsShellCmdTskInfoGet(OS_ALL_TASK_MASK, NULL, flag);
649
650TASK_HELP:
651 PRINTK("Unknown option: %s\n", argv[0]);
652 PRINTK("Usage:\n");
653 PRINTK(" task --- Basic information about all created processes.\n");
654 PRINTK(" task -a --- Complete information about all created processes.\n");
655 return LOS_NOK;
656}
657
658#ifdef LOSCFG_SHELL
660#endif
661
@ CMD_TYPE_EX
不支持标准命令参数输入,会把用户填写的命令关键字屏蔽掉,例如:输入ls /ramfs,传入给注册函数的参数只有/ramfs,而ls命令关键字并不会被传入。
Definition: shell.h:91
@ CPUP_LAST_TEN_SECONDS
Definition: los_cpup.h:132
@ CPUP_ALL_TIME
Definition: los_cpup.h:134
@ CPUP_LAST_ONE_SECONDS
Definition: los_cpup.h:133
VOID * LOS_MemAlloc(VOID *pool, UINT32 size)
从指定内存池中申请size长度的内存,注意这可不是从内核堆空间中申请内存
Definition: los_memory.c:1123
UINT8 * m_aucSysMem1
系统动态内存池地址的起始地址 @note_thinking 能否不要用 0,1来命名核心变量 ???
Definition: los_memory.c:108
UINT32 LOS_MemFree(VOID *pool, VOID *ptr)
释放从指定动态内存中申请的内存
Definition: los_memory.c:1369
UINT32 OsStackWaterLineGet(const UINTPTR *stackBottom, const UINTPTR *stackTop, UINT32 *peakUsed)
Get stack waterline.
Definition: los_stackinfo.c:70
LITE_OS_SEC_BSS UINT32 g_taskMaxNum
任务最大数量 默认128个
Definition: los_task.c:150
LITE_OS_SEC_BSS LosTaskCB * g_taskCBArray
外部变量 任务池 默认128个
Definition: los_task.c:147
LITE_OS_SEC_TEXT_MINOR UINT32 OsGetAllProcessAndTaskCpuUsageUnsafe(UINT16 mode, CPUP_INFO_S *cpupInfo, UINT32 len)
Definition: los_cpup.c:595
LITE_OS_SEC_BSS LosProcessCB * g_processCBArray
进程池数组
Definition: los_process.c:80
LITE_OS_SEC_TEXT UINT32 OsGetIdleProcessID(VOID)
获取内核态空闲进程
Definition: los_process.c:2254
LITE_OS_SEC_BSS UINT32 g_processMaxNum
进程最大数量,默认64个
Definition: los_process.c:86
STATIC INLINE BOOL OsProcessIsInit(const LosProcessCB *processCB)
STATIC INLINE BOOL OsProcessIsDead(const LosProcessCB *processCB)
进程死啦死啦的定义: 身上贴有不使用且状态为僵死的进程
STATIC INLINE BOOL OsProcessIsUnused(const LosProcessCB *processCB)
UINT32 OsShellShowTickResponse(VOID)
UINT32 OsShellShowSchedStatistics(VOID)
STATIC INLINE BOOL OsTaskIsUnused(const LosTaskCB *taskCB)
任务是否在使用
Definition: los_task_pri.h:255
unsigned short UINT16
Definition: los_typedef.h:56
signed int INT32
Definition: los_typedef.h:60
signed short INT16
Definition: los_typedef.h:59
unsigned char UINT8
Definition: los_typedef.h:55
unsigned long UINTPTR
Definition: los_typedef.h:68
unsigned int UINT32
Definition: los_typedef.h:57
char CHAR
Definition: los_typedef.h:63
UINT32 OsShellCmdProcessPmUsage(LosVmSpace *space, UINT32 *sharePm, UINT32 *actualPm)
shell task 物理内存的使用情况
Definition: los_vm_dump.c:183
UINT32 OsShellCmdProcessVmUsage(LosVmSpace *space)
shell task 进程虚拟内存的使用情况
Definition: los_vm_dump.c:111
LosVmSpace * LOS_GetKVmSpace(VOID)
内核空间只有g_kVmSpace一个,所有的内核进程都共用一个内核空间
Definition: los_vm_map.c:130
Definition: los_mux.h:73
UINT16 processMode
UINT32 processID
UINT32 threadGroupID
UINT16 processStatus
CHAR processName[OS_PCB_NAME_LEN]
User * user
进程的拥有者
volatile UINT32 threadNumber
UINT32 parentProcessID
ProcessGroup * group
LosVmSpace * vmSpace
UINT32(* schedParamGet)(const LosTaskCB *taskCB, SchedParam *param)
获取调度参数
UINT16 basePrio
UINTPTR waitID
UINT16 cpuAffiMask
UINT32 taskID
UINT32 stackSize
CHAR taskName[OS_TCB_NAME_LEN]
UINTPTR topOfStack
VOID * stackPointer
UINT16 currCpu
VOID * taskMux
UINT32 processID
const SchedOps * ops
UINT16 taskStatus
UINT16 waitFlag
UINT32 userID
用户ID [0,60000],0为root用户
虚拟空间,每个进程都有一个属于自己的虚拟内存地址空间
Definition: los_vm_map.h:146
UINT32 usage
Definition: los_cpup.h:124
STATIC VOID TaskCpupInfoBaseGet(UINTPTR base, const CPUP_INFO_S **, const CPUP_INFO_S **, const CPUP_INFO_S **)
STATIC VOID AllTaskInfoDataShow(const LosTaskCB *allTaskArray, UINTPTR cpupInfo, VOID *seqBuf, UINT16 flag)
STATIC VOID TaskPendingReasonInfoGet(const LosTaskCB *taskCB, CHAR *pendReason, UINT32 maxLen, UINTPTR *lockID)
STATIC VOID ProcessAndTaskInfoGet(LosProcessCB **pcbArray, LosTaskCB **tcbArray, SchedParam **schedParam, UINTPTR *cpupInfo, UINT16 flag)
STATIC VOID ProcessInfoGet(LosProcessCB **pcbArray, LosTaskCB **tcbArray, SchedParam **schedParam)
STATIC UINT8 * ConvertProcessStatusToString(UINT16 status)
STATIC VOID ProcessInfoShow(const LosProcessCB *pcbArray, const SchedParam *param, UINTPTR cpupInfo, VOID *seqBuf, UINT16 flag)
STATIC UINT8 * ConvertTaskStatusToString(UINT16 taskStatus)
STATIC VOID ProcessCpupInfoBaseGet(UINTPTR base, const CPUP_INFO_S **, const CPUP_INFO_S **, const CPUP_INFO_S **)
STATIC VOID TaskWaterLineGet(UINTPTR waterLineBase, LosTaskCB *tcbArray)
STATIC CHAR * CheckTaskWaitFlag(const LosTaskCB *taskCB, UINTPTR *lockID)
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdTskInfoGet(UINT32 taskID, VOID *seqBuf, UINT16 flag)
STATIC VOID TaskCpupInfoGet(UINTPTR base)
STATIC VOID TaskInfoData(const LosTaskCB *allTaskArray, UINTPTR cpupInfo, VOID *seqBuf, UINT16 flag)
STATIC UINT8 * ConvertProcessModeToString(UINT16 mode)
STATIC UINT8 * ConvertSchedPolicyToString(UINT16 policy)
SHELLCMD_ENTRY(task_shellcmd, CMD_TYPE_EX, "task", 1,(CmdCallBackFunc) OsShellCmdDumpTask)
STATIC VOID AllProcessDataShow(const LosProcessCB *pcbArray, const SchedParam *param, UINTPTR cpupInfo, VOID *seqBuf, UINT16 flag)
STATIC VOID TaskInfoTitle(VOID *seqBuf, UINT16 flag)
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdDumpTask(INT32 argc, const CHAR **argv)
STATIC VOID ProcessMemUsageGet(LosProcessCB *pcbArray)
STATIC VOID ProcessInfoTitle(VOID *seqBuf, UINT16 flag)
u32_t(* CmdCallBackFunc)(u32_t argc, const char **argv)
Definition: types_adapt.h:86