pull/10/head
p2gpamesw 11 months ago
commit 51d4c9f4f9

Binary file not shown.

@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
//这个头文件的作用是定义了与内存池相关的私有函数和数据结构。
#ifndef _LOS_MEMBOX_PRI_H
#define _LOS_MEMBOX_PRI_H

@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
//定义了一个多重双向链表头的私有接口和数据结构。
//这个头文件定义了一个多重双向链表头的私有接口和数据结构。
#ifndef _LOS_MULTIPLE_DLINK_HEAD_PRI_H
#define _LOS_MULTIPLE_DLINK_HEAD_PRI_H

@ -26,6 +26,9 @@
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
/*这个头文件定义了一些用于互斥锁mutex调试的接口和函数包括死锁检测、互斥锁状态跟踪、互斥锁泄漏检查等。
使*/
#ifndef _LOS_MUX_DEBUG_PRI_H
#define _LOS_MUX_DEBUG_PRI_H
@ -35,7 +38,7 @@
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
//初始化死锁检测机制
/* Deadlock detection initialization interface */
extern UINT32 OsMuxDlockCheckInit(VOID);
STATIC INLINE UINT32 OsMuxDlockCheckInitHook(VOID)
@ -46,7 +49,7 @@ STATIC INLINE UINT32 OsMuxDlockCheckInitHook(VOID)
return LOS_OK;
#endif
}
//向死锁检测机制中添加任务持有的互斥锁信息
/* Add holding mutex lock node information */
extern VOID OsMuxDlockNodeInsert(UINT32 taskId, VOID *muxCB);
STATIC INLINE VOID OsMuxDlockNodeInsertHook(UINT32 taskId, VOID *muxCB)
@ -55,6 +58,7 @@ STATIC INLINE VOID OsMuxDlockNodeInsertHook(UINT32 taskId, VOID *muxCB)
OsMuxDlockNodeInsert(taskId, muxCB);
#endif
}
//从死锁检测机制中删除任务持有的互斥锁信息
/* Delete holding mutex lock node information */
extern VOID OsMuxDlockNodeDelete(UINT32 taskId, const VOID *muxCB);
STATIC INLINE VOID OsMuxDlockNodeDeleteHook(UINT32 taskId, const VOID *muxCB)
@ -63,6 +67,7 @@ STATIC INLINE VOID OsMuxDlockNodeDeleteHook(UINT32 taskId, const VOID *muxCB)
OsMuxDlockNodeDelete(taskId, muxCB);
#endif
}
//更新任务最后执行的时间
/* Update the last time the task was executed */
extern VOID OsTaskTimeUpdate(UINT32 taskId, UINT64 tickCount);
STATIC INLINE VOID OsTaskTimeUpdateHook(UINT32 taskId, UINT64 tickCount)
@ -71,7 +76,7 @@ STATIC INLINE VOID OsTaskTimeUpdateHook(UINT32 taskId, UINT64 tickCount)
OsTaskTimeUpdate(taskId, tickCount);
#endif
}
//初始化互斥锁状态跟踪机制
/* mutex debug initialization interface */
extern UINT32 OsMuxDbgInit(VOID);
STATIC INLINE UINT32 OsMuxDbgInitHook(VOID)
@ -82,6 +87,7 @@ STATIC INLINE UINT32 OsMuxDbgInitHook(VOID)
return LOS_OK;
#endif
}
//更新互斥锁最后执行的时间
/* Update the last time the mutex was executed */
extern VOID OsMuxDbgTimeUpdate(UINT32 muxId);
STATIC INLINE VOID OsMuxDbgTimeUpdateHook(UINT32 muxId)
@ -90,6 +96,7 @@ STATIC INLINE VOID OsMuxDbgTimeUpdateHook(UINT32 muxId)
OsMuxDbgTimeUpdate(muxId);
#endif
}
//在创建或删除互斥锁时更新互斥锁的状态跟踪信息
/* Update the MUX_DEBUG_CB of the mutex when created or deleted */
extern VOID OsMuxDbgUpdate(UINT32 muxID, TSK_ENTRY_FUNC creator);
STATIC INLINE VOID OsMuxDbgUpdateHook(UINT32 muxId, TSK_ENTRY_FUNC creator)
@ -98,6 +105,7 @@ STATIC INLINE VOID OsMuxDbgUpdateHook(UINT32 muxId, TSK_ENTRY_FUNC creator)
OsMuxDbgUpdate(muxId, creator);
#endif
}
//检查互斥锁是否泄漏
/* check the leak of mutex */
extern VOID OsMutexCheck(VOID);
STATIC INLINE VOID OsMutexCheckHook(VOID)

@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
//一个关于互斥锁的内部实现的头文件
#ifndef _LOS_MUX_PRI_H
#define _LOS_MUX_PRI_H
@ -45,12 +45,13 @@ extern "C" {
* Mutex base object must be the same as the first three member names of LosMuxCB,
* so that pthread_mutex_t can share the kernel mutex mechanism.
*/
//这是互斥锁的基本控制块,包含了互斥锁的一些基本信息
typedef struct {
LOS_DL_LIST muxList; /* Mutex linked list */
LosTaskCB *owner; /* The current thread that is locking a mutex */
UINT16 muxCount; /* Times of locking a mutex */
LOS_DL_LIST muxList;//连接列表 /* Mutex linked list */
LosTaskCB *owner; //互斥锁的拥有者 /* The current thread that is locking a mutex */
UINT16 muxCount; //被锁定的次数 /* Times of locking a mutex */
} MuxBaseCB;
//这是互斥锁的控制块,包含了更多的互斥锁信息
typedef struct {
LOS_DL_LIST muxList; /* Mutex linked list */
LosTaskCB *owner; /* The current thread that is locking a mutex */
@ -60,21 +61,29 @@ typedef struct {
} LosMuxCB;
/* Mutex global array address, which can be obtained by using a handle ID. */
//全局变量:这是一个互斥锁的全局数组地址,可以通过互斥锁的 ID 来获取对应的互斥锁对象。
extern LosMuxCB *g_allMux;
/* COUNT | INDEX split bit */
#define MUX_SPLIT_BIT 16
/* Set the mutex id */
//设置互斥锁的 ID
#define SET_MUX_ID(count, muxId) (((count) << MUX_SPLIT_BIT) | (muxId))
//根据互斥锁的 ID 获取索引
#define GET_MUX_INDEX(muxId) ((muxId) & ((1U << MUX_SPLIT_BIT) - 1))
//根据互斥锁的 ID 获取计数值
#define GET_MUX_COUNT(muxId) ((muxId) >> MUX_SPLIT_BIT)
/* Obtain the pointer to a mutex object of the mutex that has a specified handle. */
//根据互斥锁的 ID 获取对应的互斥锁对象指针
#define GET_MUX(muxId) (((LosMuxCB *)g_allMux) + GET_MUX_INDEX(muxId))
//初始化互斥锁
extern UINT32 OsMuxInit(VOID);
//执行互斥锁的等待操作
extern UINT32 OsMuxPendOp(LosTaskCB *runTask, MuxBaseCB *muxPended, UINT32 timeout, UINT32 *intSave);
//执行互斥锁的释放操作
extern UINT32 OsMuxPostOp(LosTaskCB *runTask, MuxBaseCB *muxPosted);
#ifdef __cplusplus
#if __cplusplus

@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
//这个头文件定义了关于每个CPU的私有数据结构这个结构体存储了与每个 CPU 相关的一些信息。
#ifndef _LOS_PERCPU_PRI_H
#define _LOS_PERCPU_PRI_H
@ -47,35 +47,34 @@ typedef enum {
CPU_EXC /* cpu in the exc */
} ExcFlag;
#endif
//排序链表的属性结构体,用于表示任务链表和软件定时器链表
typedef struct {
SortLinkAttribute taskSortLink; /* task sort link */
#ifdef LOSCFG_BASE_CORE_SWTMR
SortLinkAttribute swtmrSortLink; /* swtmr sort link */
#endif
UINT32 idleTaskId; /* idle task id */
UINT32 taskLockCnt; /* task lock flag */
UINT32 swtmrHandlerQueue; /* software timer timeout queue id */
UINT32 swtmrTaskId; /* software timer task id */
UINT32 schedFlag; /* pending scheduler flag */
UINT32 idleTaskId;//空闲任务的任务 ID /* idle task id */
UINT32 taskLockCnt;//任务锁计数,用于标记任务是否被锁定 /* task lock flag */
UINT32 swtmrHandlerQueue;//软件定时器的超时队列 ID /* software timer timeout queue id */
UINT32 swtmrTaskId;//软件定时器任务的 ID /* software timer task id */
UINT32 schedFlag;//调度标志,用于表示是否需要进行调度 /* pending scheduler flag */
#ifdef LOSCFG_KERNEL_SMP
UINT32 excFlag; /* cpu halt or exc flag */
UINT32 excFlag;//CPU 异常标志,用于表示 CPU 的运行状态,包括运行、休眠和异常状态 /* cpu halt or exc flag */
#ifdef LOSCFG_KERNEL_SMP_CALL
LOS_DL_LIST funcLink; /* mp function call link */
LOS_DL_LIST funcLink;//多处理器函数调用链表,用于多处理器间的函数调用 /* mp function call link */
#endif
#endif
} Percpu;
/* the kernel per-cpu structure */
extern Percpu g_percpu[LOSCFG_KERNEL_CORE_NUM];
//用于获取当前CPU
STATIC INLINE Percpu *OsPercpuGet(VOID)
{
return &g_percpu[ArchCurrCpuid()];
}
//用于获取指定CPU的Percpu结构体指针
STATIC INLINE Percpu *OsPercpuGetByID(UINT32 cpuid)
{
return &g_percpu[cpuid];

@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
//关于打印函数的私有头文件
#ifndef _LOS_PRINTF_PRI_H
#define _LOS_PRINTF_PRI_H
@ -36,13 +36,16 @@
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
//在控制台上打印格式化字符串
extern VOID ConsoleVprintf(const CHAR *fmt, va_list ap);
//在串口上打印格式化字符串
extern VOID UartVprintf(const CHAR *fmt, va_list ap);
//打印异常信息
extern VOID PrintExcInfo(const CHAR *fmt, ...);
//打印内核调试信息
extern VOID LkDprintf(const CHAR *fmt, va_list ap);
#ifdef LOSCFG_SHELL_DMESG
//打印系统日志信息
extern VOID DmesgPrintf(const CHAR *fmt, va_list ap);
#endif

@ -25,7 +25,8 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
/*这个头文件定义了优先级队列的相关操作函数,
*/
#ifndef _LOS_PRIQUEUE_PRI_H
#define _LOS_PRIQUEUE_PRI_H
@ -57,6 +58,7 @@ extern "C" {
* @see none.
* @since Huawei LiteOS V100R001C00
*/
//初始化优先级队列
extern UINT32 OsPriQueueInit(VOID);
/**
@ -79,6 +81,7 @@ extern UINT32 OsPriQueueInit(VOID);
* @see OsPriQueueDequeue.
* @since Huawei LiteOS V100R001C00
*/
//根据项目的优先级将项目插入到优先级队列中
extern VOID OsPriQueueEnqueue(LOS_DL_LIST *priqueueItem, UINT32 priority);
/**
@ -99,6 +102,7 @@ extern VOID OsPriQueueEnqueue(LOS_DL_LIST *priqueueItem, UINT32 priority);
* @see OsPriQueueEnqueue.
* @since Huawei LiteOS V100R001C00
*/
//从优先级队列中删除一个项目
extern VOID OsPriQueueDequeue(LOS_DL_LIST *priqueueItem);
/**
@ -120,6 +124,7 @@ extern VOID OsPriQueueDequeue(LOS_DL_LIST *priqueueItem);
* @see none.
* @since Huawei LiteOS V100R001C00
*/
//获取优先级队列中具有最高优先级的项目
extern LOS_DL_LIST *OsPriQueueTop(VOID);
/**
@ -140,6 +145,7 @@ extern LOS_DL_LIST *OsPriQueueTop(VOID);
* @see none.
* @since Huawei LiteOS V100R001C00
*/
//获取具有指定优先级的项目数量
extern UINT32 OsPriQueueSize(UINT32 priority);
/**
@ -159,6 +165,7 @@ extern UINT32 OsPriQueueSize(UINT32 priority);
* @see none.
* @since Huawei LiteOS V100R001C00
*/
//获取优先级队列中项目的总数
extern UINT32 OsPriQueueTotalSize(VOID);
/**
@ -181,6 +188,7 @@ extern UINT32 OsPriQueueTotalSize(VOID);
* @see OsPriQueueDequeue.
* @since Huawei LiteOS V100R001C00
*/
//根据项目的优先级将项目插入到优先级队列的头部
extern VOID OsPriQueueEnqueueHead(LOS_DL_LIST *priqueueItem, UINT32 priority);
#ifdef __cplusplus

@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
//这个头文件提供了针对队列调试的相关函数声明
#ifndef _LOS_QUEUE_DEBUG_PRI_H
#define _LOS_QUEUE_DEBUG_PRI_H
@ -40,7 +40,9 @@ extern "C" {
#endif /* __cplusplus */
/* queue debug initialization interface */
//队列调试初始化接口
extern UINT32 OsQueueDbgInit(VOID);
//队列调试初始化的钩子函数根据配置是否开启队列调试功能来调用OsQueueDbgInit
STATIC INLINE UINT32 OsQueueDbgInitHook(VOID)
{
#ifdef LOSCFG_DEBUG_QUEUE
@ -50,7 +52,9 @@ STATIC INLINE UINT32 OsQueueDbgInitHook(VOID)
#endif
}
/* Update the last time the queue was executed */
//更新队列上次执行的时间
extern VOID OsQueueDbgTimeUpdate(UINT32 queueId);
//更新队列执行时间的钩子函数
STATIC INLINE VOID OsQueueDbgTimeUpdateHook(UINT32 queueId)
{
#ifdef LOSCFG_DEBUG_QUEUE
@ -58,7 +62,9 @@ STATIC INLINE VOID OsQueueDbgTimeUpdateHook(UINT32 queueId)
#endif
}
/* Update the task entry of the queue debug info when created or deleted */
//当队列被创建或删除时,更新队列调试信息中的任务入口信息
extern VOID OsQueueDbgUpdate(UINT32 queueId, TSK_ENTRY_FUNC entry);
//新队列调试信息的钩子函数
STATIC INLINE VOID OsQueueDbgUpdateHook(UINT32 queueId, TSK_ENTRY_FUNC entry)
{
#ifdef LOSCFG_DEBUG_QUEUE
@ -66,7 +72,9 @@ STATIC INLINE VOID OsQueueDbgUpdateHook(UINT32 queueId, TSK_ENTRY_FUNC entry)
#endif
}
/* check the leak of queue */
//检查队列内存泄漏
extern VOID OsQueueCheck(VOID);
//检查队列内存泄漏的钩子函数
STATIC INLINE VOID OsQueueCheckHook(VOID)
{
#ifdef LOSCFG_DEBUG_QUEUE

@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
//这个头文件定义了私有队列相关的一些结构体、宏和函数声明
#ifndef _LOS_QUEUE_PRI_H
#define _LOS_QUEUE_PRI_H
@ -42,12 +42,12 @@ typedef enum {
OS_QUEUE_WRITE = 1,
OS_QUEUE_N_RW = 2
} QueueReadWrite;
//枚举类型,分别表示队列的读写操作和队列头尾操作
typedef enum {
OS_QUEUE_HEAD = 0,
OS_QUEUE_TAIL = 1
} QueueHeadTail;
//用于生成或获取队列操作类型和读写类型
#define OS_QUEUE_OPERATE_TYPE(ReadOrWrite, HeadOrTail) (((UINT32)(HeadOrTail) << 1) | (ReadOrWrite))
#define OS_QUEUE_READ_WRITE_GET(type) ((type) & 0x01U)
#define OS_QUEUE_READ_HEAD (OS_QUEUE_READ | (OS_QUEUE_HEAD << 1))
@ -73,6 +73,7 @@ typedef enum {
#define GET_QUEUE_LIST(ptr) LOS_DL_LIST_ENTRY(ptr, LosQueueCB, readWriteList[OS_QUEUE_WRITE])
/* Queue information block structure */
//队列信息块结构体,包含了队列的各种属性和状态信息
typedef struct {
UINT8 *queueHandle; /* Pointer to a queue handle */
UINT8 queueState; /* state */
@ -88,12 +89,16 @@ typedef struct {
} LosQueueCB;
/* Queue information control block */
//全局变量,指向所有队列信息块的起始地址
extern LosQueueCB *g_allQueue;
/* alloc a stationary memory for a mail according to queueId */
//用于在指定的内存池中为邮件分配内存
extern VOID *OsQueueMailAlloc(UINT32 queueId, VOID *mailPool, UINT32 timeout);
/* free a stationary memory for a mail according to queueId. */
//释放邮件占用的内存
extern UINT32 OsQueueMailFree(UINT32 queueId, VOID *mailPool, VOID *mailMem);
//列初始化函数,用于初始化队列池
extern UINT32 OsQueueInit(VOID);
#ifdef __cplusplus

@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
//这个头文件定义了调度器相关的一些结构体和函数声明
#ifndef __LOS_SCHED_DEBUG_PRI_H
#define __LOS_SCHED_DEBUG_PRI_H
@ -34,19 +34,19 @@
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
//表示单个CPU的运行时间和上下文切换次数
typedef struct {
UINT64 runtime;
UINT32 contexSwitch;
} SchedPercpu;
//表示整个系统的调度统计信息
typedef struct {
UINT64 startRuntime;
UINT64 allRuntime;
UINT32 allContextSwitch;
SchedPercpu schedPercpu[LOSCFG_KERNEL_CORE_NUM];
UINT64 startRuntime;//开始运行的时间
UINT64 allRuntime;//所有CPU的总共运行时间
UINT32 allContextSwitch;//上下文切换次数
SchedPercpu schedPercpu[LOSCFG_KERNEL_CORE_NUM];//每个CPU的具体情况
} SchedStat;
//用于统计中断处理的时间和次数
extern VOID OsHwiStatistics(size_t intNum);
#ifdef __cplusplus

@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
//这个头文件定义了调度器相关的一些结构体和函数声明
#ifndef _LOS_SCHED_PRI_H
#define _LOS_SCHED_PRI_H
@ -37,21 +37,22 @@
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
//表示任务调度标志位每个位代表一个核心用于防止在OSStartToRun之前进行内核调度
extern UINT32 g_taskScheduled;
/*
* Schedule flag, one bit represents one core.
* This flag is used to prevent kernel scheduling before OSStartToRun.
*/
//设置对应核心的调度标志位
#define OS_SCHEDULER_SET(cpuid) do { \
g_taskScheduled |= (1U << (cpuid)); \
} while (0);
//清除对应核心的调度标志位
#define OS_SCHEDULER_CLR(cpuid) do { \
g_taskScheduled &= ~(1U << (cpuid)); \
} while (0);
//判断当前核心的调度标志位是否激活
#define OS_SCHEDULER_ACTIVE (g_taskScheduled & (1U << ArchCurrCpuid()))
typedef enum {
@ -60,6 +61,7 @@ typedef enum {
} SchedFlag;
/* Check if preemptable with counter flag */
//用于判断当前任务是否可以被抢占
STATIC INLINE BOOL OsPreemptable(VOID)
{
/*
@ -76,7 +78,7 @@ STATIC INLINE BOOL OsPreemptable(VOID)
LOS_IntRestore(intSave);
return preemptable;
}
//用于判断当前任务是否可以在调度过程中被抢占
STATIC INLINE BOOL OsPreemptableInSched(VOID)
{
BOOL preemptable = FALSE;
@ -104,6 +106,7 @@ STATIC INLINE BOOL OsPreemptableInSched(VOID)
* Current task needs to already be in the right state or the right
* queues it needs to be in.
*/
//选择下一个任务并切换到它
extern VOID OsSchedResched(VOID);
/*
@ -111,12 +114,14 @@ extern VOID OsSchedResched(VOID);
* try to do the schedule. However, the schedule won't be definitely
* taken place while there're no other higher priority tasks or locked.
*/
//将当前任务放回就绪队列,并尝试进行调度
extern VOID OsSchedPreempt(VOID);
/*
* Just like OsSchedPreempt, except this function will do the OS_INT_ACTIVE
* check, in case the schedule taken place in the middle of an interrupt.
*/
//触发调度,如果在中断中则设置调度标志位
STATIC INLINE VOID LOS_Schedule(VOID)
{
if (OS_INT_ACTIVE) {
@ -138,6 +143,7 @@ STATIC INLINE VOID LOS_Schedule(VOID)
* This API is used to check time slices. If the number of Ticks equals to the time for task switch,
* tasks are switched. Otherwise, the Tick counting continues.
*/
//检查时间片,如果满足任务切换的条件则进行切换
extern VOID OsTimesliceCheck(VOID);
#endif

@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
//这个头文件定义了一些用于调试信号量的接口和函数声明
#ifndef _LOS_SEM_DEBUG_PRI_H
#define _LOS_SEM_DEBUG_PRI_H
@ -39,7 +39,9 @@ extern "C" {
#endif /* __cplusplus */
/* semaphore debug initialization interface */
//信号量调试初始化接口
extern UINT32 OsSemDbgInit(VOID);
//更新信号量最后一次执行的时间
STATIC INLINE UINT32 OsSemDbgInitHook(VOID)
{
#ifdef LOSCFG_DEBUG_SEMAPHORE
@ -49,6 +51,7 @@ STATIC INLINE UINT32 OsSemDbgInitHook(VOID)
#endif
}
/* Update the last time the semaphore was executed */
//更新信号量最后一次执行的时间
extern VOID OsSemDbgTimeUpdate(UINT32 semId);
STATIC INLINE VOID OsSemDbgTimeUpdateHook(UINT32 semId)
{
@ -58,6 +61,7 @@ STATIC INLINE VOID OsSemDbgTimeUpdateHook(UINT32 semId)
return;
}
/* Update the SEM_DEBUG_CB of the semaphore when created or deleted */
//在创建或删除信号量时更新SEM_DEBUG_CB的信息
extern VOID OsSemDbgUpdate(UINT32 semID, TSK_ENTRY_FUNC creator, UINT16 count);
STATIC INLINE VOID OsSemDbgUpdateHook(UINT32 semId, TSK_ENTRY_FUNC creator, UINT16 count)
{
@ -67,6 +71,7 @@ STATIC INLINE VOID OsSemDbgUpdateHook(UINT32 semId, TSK_ENTRY_FUNC creator, UINT
return;
}
/* get the full data of SEM_DFX_CB */
//取SEM_DFX_CB的完整数据
extern UINT32 OsSemInfoGetFullData(VOID);
STATIC INLINE VOID OsSemInfoGetFullDataHook(VOID)
{

@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
//这个头文件定义了一些关于信号量的数据结构和函数声明,用于信号量的控制和管理。
#ifndef _LOS_SEM_PRI_H
#define _LOS_SEM_PRI_H
@ -38,24 +38,28 @@ extern "C" {
#endif /* __cplusplus */
/* Semaphore control structure. */
//信号量控制块的数据结构
typedef struct {
UINT8 semStat; /* Semaphore state, enum LosSemState */
UINT8 semType; /* Semaphore Type, enum LosSemType */
UINT16 semCount; /* number of available semaphores */
UINT32 semId; /* Semaphore control structure ID, COUNT(UINT16)|INDEX(UINT16) */
UINT8 semStat;//信号量的状态 /* Semaphore state, enum LosSemState */
UINT8 semType;//信号量的类型 /* Semaphore Type, enum LosSemType */
UINT16 semCount;//信号量可用数量 /* number of available semaphores */
UINT32 semId;//信号量ID /* Semaphore control structure ID, COUNT(UINT16)|INDEX(UINT16) */
LOS_DL_LIST semList; /* List of tasks that are waiting on a semaphore */
} LosSemCB;
/* Semaphore type */
//信号量类型的枚举值:包括计数信号量和二进制信号量
enum {
OS_SEM_COUNTING, /* The semaphore is a counting semaphore which max count is LOS_SEM_COUNT_MAX */
OS_SEM_BINARY, /* The semaphore is a binary semaphore which max count is OS_SEM_BINARY_COUNT_MAX */
};
/* Max count of binary semaphores */
//二进制信号量的最大计数值
#define OS_SEM_BINARY_COUNT_MAX 1
/* Semaphore information control block */
//信号量信息控制块的全局指针
extern LosSemCB *g_allSem;
#define GET_SEM_LIST(ptr) LOS_DL_LIST_ENTRY(ptr, LosSemCB, semList)
@ -75,6 +79,7 @@ extern LosSemCB *g_allSem;
/* This API is used to create a semaphore control structure according to the initial number of available semaphores
* specified by count and return the ID of this semaphore control structure. */
extern UINT32 OsSemInit(VOID);
#ifdef __cplusplus

@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
//这个头文件是操作系统中关于 Slab 内存分配的底层实现和接口声明
/**
* @defgroup los_slab Slab
* @ingroup kernel
@ -53,7 +53,7 @@ extern "C" {
/* max slab block size */
#define SLAB_MEM_MAX_SIZE (SLAB_MEM_CALSS_STEP_SIZE << (SLAB_MEM_COUNT - 1))
//描述 Slab 内存分配器状态的结构体
typedef struct tagLosSlabStatus {
UINT32 totalSize;
UINT32 usedSize;
@ -61,13 +61,13 @@ typedef struct tagLosSlabStatus {
UINT32 allocCount;
UINT32 freeCount;
} LosSlabStatus;
//Slab 块的节点结构体
typedef struct tagOsSlabBlockNode {
UINT16 magic;
UINT8 blkSz;
UINT8 recordId;
} OsSlabBlockNode;
//原子位图结构体,用于表示 Slab 内存分配器中的位图
struct AtomicBitset {
UINT32 numBits;
UINT32 words[0];
@ -144,25 +144,25 @@ extern UINT32 OsSlabGetMaxFreeBlkSize(const VOID *pool);
extern VOID *OsSlabCtrlHdrGet(const VOID *pool);
#else /* !LOSCFG_KERNEL_MEM_SLAB_EXTENTION */
//初始化 Slab 内存池
STATIC INLINE VOID OsSlabMemInit(VOID *pool, UINT32 size)
{
}
//销毁 Slab 内存池
STATIC INLINE VOID OsSlabMemDeinit(VOID *pool)
{
}
//从 Slab 内存池中分配内存
STATIC INLINE VOID *OsSlabMemAlloc(VOID *pool, UINT32 size)
{
return NULL;
}
//释放 Slab 内存池中的内存
STATIC INLINE BOOL OsSlabMemFree(VOID *pool, VOID *ptr)
{
return FALSE;
}
//检查指针是否属于 Slab 内存池
STATIC INLINE UINT32 OsSlabMemCheck(const VOID *pool, const VOID *ptr)
{
return (UINT32)-1;

@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
//一个用于操作排序链表SortLink的私有头文件。
#ifndef _LOS_SORTLINK_PRI_H
#define _LOS_SORTLINK_PRI_H
@ -118,13 +118,17 @@ typedef struct {
UINT16 cursor;
UINT16 reserved;
} SortLinkAttribute;
//初始化排序链表
extern UINT32 OsSortLinkInit(SortLinkAttribute *sortLinkHeader);
//一个节点添加到排序链表中
extern VOID OsAdd2SortLink(const SortLinkAttribute *sortLinkHeader, SortLinkList *sortList);
//从排序链表中删除一个节点
extern VOID OsDeleteSortLink(const SortLinkAttribute *sortLinkHeader, SortLinkList *sortList);
//获取下一个到期时间
extern UINT32 OsSortLinkGetNextExpireTime(const SortLinkAttribute *sortLinkHeader);
//获取目标节点的到期时间
extern UINT32 OsSortLinkGetTargetExpireTime(const SortLinkAttribute *sortLinkHeader,
const SortLinkList *targetSortList);
//更新到期时间 const SortLinkList *targetSortList);
extern VOID OsSortLinkUpdateExpireTime(UINT32 sleepTicks, SortLinkAttribute *sortLinkHeader);
#ifdef __cplusplus

@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
//一个用于处理堆栈信息的私有头文件
#ifndef _LOS_STACK_INFO_PRI_H
#define _LOS_STACK_INFO_PRI_H
@ -37,20 +37,25 @@
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
//堆栈信息结构体
typedef struct {
VOID *stackTop;
UINT32 stackSize;
CHAR *stackName;
VOID *stackTop;//堆栈的顶部
UINT32 stackSize;//堆栈的大小
CHAR *stackName;//堆栈的名称
} StackInfo;
//表示无效的水位线值
#define OS_INVALID_WATERLINE 0xFFFFFFFF
//于检查堆栈顶部的魔术字是否有效的宏定义
#define OS_STACK_MAGIC_CHECK(topstack) (*(UINTPTR *)(topstack) == OS_STACK_MAGIC_WORD) /* 1:magic valid 0:unvalid */
//用于异常时获取堆栈信息的函数
extern VOID OsExcStackInfo(VOID);
//用于注册异常时获取的堆栈信息的函数
extern VOID OsExcStackInfoReg(const StackInfo *stackInfo, UINT32 stackNum);
//用于初始化堆栈的函数
extern VOID OsStackInit(VOID *stacktop, UINT32 stacksize);
//用于获取堆栈的水位线和使用峰值的函数
extern UINT32 OsStackWaterLineGet(const UINTPTR *stackBottom, const UINTPTR *stackTop, UINT32 *peakUsed);
//用于获取堆栈信息的函数
extern VOID OsGetStackInfo(const StackInfo **stackInfo, UINT32 *stackNum);
#ifdef __cplusplus

@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
//一个用于实现软件定时器的私有头文件。
#ifndef _LOS_SWTMR_PRI_H
#define _LOS_SWTMR_PRI_H
@ -40,7 +40,7 @@ extern "C" {
#endif /* __cplusplus */
#ifdef LOSCFG_BASE_CORE_SWTMR
//软件定时器的状态枚举,包括未使用、已创建和计时中
enum SwtmrState {
OS_SWTMR_STATUS_UNUSED, /* The software timer is not used. */
OS_SWTMR_STATUS_CREATED, /* The software timer is created. */
@ -48,12 +48,13 @@ enum SwtmrState {
};
/* Structure of the callback function that handles software timer timeout */
//处理软件定时器超时回调的回调函数结构体
typedef struct {
SWTMR_PROC_FUNC handler; /* Callback function that handles software timer timeout */
UINTPTR arg; /* Parameter passed in when the callback function
that handles software timer timeout is called */
} SwtmrHandlerItem;
//软件定时器控制块结构体
typedef struct {
SortLinkList sortList;
UINT8 state; /* Software timer state */
@ -71,22 +72,28 @@ typedef struct {
} LosSwtmrCB;
/* Type of the pointer to the structure of the callback function that handles software timer timeout */
//指向处理软件定时器超时回调的回调函数结构体的指针类型
typedef SwtmrHandlerItem *SwtmrHandlerItemPtr;
//软件定时器控制块数组
extern LosSwtmrCB *g_swtmrCBArray;
/* The software timer count list */
//软件定时器排序链表
extern SortLinkAttribute g_swtmrSortLink;
#define OS_SWT_FROM_SWTID(swtmrId) ((LosSwtmrCB *)g_swtmrCBArray + ((swtmrId) % KERNEL_SWTMR_LIMIT))
/* This API is used to scan a software timer when a Tick interrupt occurs and determine whether
* the software timer expires. */
//在Tick中断发生时扫描软件定时器判断是否到达超时时间
extern VOID OsSwtmrScan(VOID);
//初始化软件定时器
extern UINT32 OsSwtmrInit(VOID);
//软件定时器任务,用于处理软件定时器的超时事件
extern VOID OsSwtmrTask(VOID);
//软件定时器自旋锁
extern SPIN_LOCK_S g_swtmrSpin;
#ifdef LOSCFG_EXC_INTERACTION
//判断当前任务是否为软件定时器任务
extern BOOL IsSwtmrTask(UINT32 taskId);
#endif
#endif /* LOSCFG_BASE_CORE_SWTMR */

@ -25,7 +25,8 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
/*这是关于LiteOS中任务调度相关的头文件其中定义了任务控制块的数据结构和一些任务管理的接口函数。
*/
#ifndef _LOS_TASK_PRI_H
#define _LOS_TASK_PRI_H

@ -25,7 +25,7 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
//这个头文件是关于系统时钟中断tick的定义和操作。
#ifndef _LOS_TICK_PRI_H
#define _LOS_TICK_PRI_H
@ -40,30 +40,41 @@ extern "C" {
#endif /* __cplusplus */
/* spinlock for tick */
//用于保护tick相关操作的自旋锁
extern SPIN_LOCK_S g_tickSpin;
//获取tick自旋锁并保存状态
#define TICK_LOCK(state) LOS_SpinLockSave(&g_tickSpin, &(state))
//释放tick自旋锁并恢复状态
#define TICK_UNLOCK(state) LOS_SpinUnlockRestore(&g_tickSpin, (state))
/* Count of Ticks */
//全局变量保存系统tick的计数值
extern volatile UINT64 g_tickCount[];
/* Cycle to nanosecond scale */
//循环周期到纳秒的转换比例
extern DOUBLE g_cycle2NsScale;
/* This API is called when the system tick timeout and triggers the interrupt. */
//系统tick中断处理函数当系统tick超时触发中断时调用
extern VOID OsTickHandler(VOID);
//初始化系统tick相关配置
extern UINT32 OsTickInit(UINT32 systemClock, UINT32 tickPerSecond);
//启动系统tick中断
extern VOID OsTickStart(VOID);
/* Convert from the cycle count to nanosecond. */
//将循环周期转换为纳秒
#define CYCLE_TO_NS(cycles) ((cycles) * g_cycle2NsScale)
/**
* Current system timer register is 32 bit, therefore TIMER_MAXLOAD define just in order to avoid ambiguity.
*/
//定时器最大加载值,用于避免歧义
#define TIMER_MAXLOAD 0xffffffff
#ifdef LOSCFG_KERNEL_TICKLESS
//tick中断标志在LOSCFG_KERNEL_TICKLESS选项开启时使用
#define LOS_TICK_INT_FLAG 0x80000000
#endif

@ -25,7 +25,11 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
/*
LiteOSShell
CPU
CPU101
*/
#include "los_config.h"
#ifdef LOSCFG_SHELL
#ifdef LOSCFG_CPUP_INCLUDE_IRQ
@ -39,7 +43,7 @@
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
//这个函数实现了打印硬件中断信息的表头
LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdHwiInfoTitle(VOID)
{
#ifdef LOSCFG_CPUP_INCLUDE_IRQ
@ -53,7 +57,7 @@ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdHwiInfoTitle(VOID)
PRINTK("----------- ----- ------------- --------- --------\n");
#endif
}
//这个函数会根据传入的硬件中断句柄信息,获取该中断是否为共享模式
STATIC BOOL GetHwiShare(const HwiHandleInfo *hwiForm)
{
#ifndef LOSCFG_SHARED_IRQ
@ -64,9 +68,10 @@ STATIC BOOL GetHwiShare(const HwiHandleInfo *hwiForm)
}
#ifdef LOSCFG_CPUP_INCLUDE_IRQ
STATIC CPUP_INFO_S g_hwiCpupAll[LOSCFG_PLATFORM_HWI_LIMIT];
STATIC CPUP_INFO_S g_hwiCpup10s[LOSCFG_PLATFORM_HWI_LIMIT];
STATIC CPUP_INFO_S g_hwiCpup1s[LOSCFG_PLATFORM_HWI_LIMIT];
STATIC CPUP_INFO_S g_hwiCpupAll[LOSCFG_PLATFORM_HWI_LIMIT];//所有时间段CPU利用率的统计信息
STATIC CPUP_INFO_S g_hwiCpup10s[LOSCFG_PLATFORM_HWI_LIMIT];//最近10sCPU利用率的统计信息
STATIC CPUP_INFO_S g_hwiCpup1s[LOSCFG_PLATFORM_HWI_LIMIT];//最近1sCPU利用率的统计信息
//这个函数实现了硬件中断信息的查询根据参数argc和argv判断是否有误并调用其他函数获取硬件中断的各项信息最终打印输出硬件中断的详细信息。
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdHwi(INT32 argc, const CHAR **argv)
{
UINT32 i, intSave;
@ -75,22 +80,24 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdHwi(INT32 argc, const CHAR **argv)
HwiHandleInfo *hwiForm = NULL;
(VOID)argv;
//打印错误信息
if (argc > 0) {
PRINTK("\nUsage: hwi\n");
return OS_ERROR;
}
(VOID)memset_s(g_hwiCpupAll, size, 0, size);
(VOID)memset_s(g_hwiCpup10s, size, 0, size);
(VOID)memset_s(g_hwiCpup1s, size, 0, size);
(VOID)memset_s(g_hwiCpupAll, size, 0, size);//置零
(VOID)memset_s(g_hwiCpup10s, size, 0, size);//置零
(VOID)memset_s(g_hwiCpup1s, size, 0, size);//置零
intSave = LOS_IntLock();
(VOID)LOS_AllCpuUsage(LOSCFG_PLATFORM_HWI_LIMIT, g_hwiCpupAll, CPUP_ALL_TIME, 0);
(VOID)LOS_AllCpuUsage(LOSCFG_PLATFORM_HWI_LIMIT, g_hwiCpup10s, CPUP_LAST_TEN_SECONDS, 0);
(VOID)LOS_AllCpuUsage(LOSCFG_PLATFORM_HWI_LIMIT, g_hwiCpup1s, CPUP_LAST_ONE_SECONDS, 0);
LOS_IntRestore(intSave);
//打印硬件中断信息的表头
OsShellCmdHwiInfoTitle();
//打印CPU硬件中断的利用率
for (i = 0; i < LOSCFG_PLATFORM_HWI_LIMIT; i++) {
if (!HWI_IS_REGISTED(i)) {
continue;
@ -101,6 +108,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdHwi(INT32 argc, const CHAR **argv)
}
/* Different cores has different hwi form implementation */
//打印各个时间内的硬件中断利用率
hwiForm = OsGetHwiForm(i);
PRINTK("%-8u\t %-s\t %-10u\t %-10llu %2u.%-7u %2u.%-7u %2u.%-6u",
i, GetHwiShare(hwiForm) ? "Y" : "N", OsGetHwiFormCnt(i), cycles,
@ -110,6 +118,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdHwi(INT32 argc, const CHAR **argv)
#ifdef LOSCFG_SHARED_IRQ
hwiForm = hwiForm->next;
#endif
//打印中断设备ID和信息
if ((hwiForm->registerInfo != 0) && ((HWI_IRQ_PARAM_S *)hwiForm->registerInfo)->pName != NULL) {
PRINTK("\t %-16s 0x%-.8x\n",
((HWI_IRQ_PARAM_S *)hwiForm->registerInfo)->pName,
@ -128,24 +137,28 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdHwi(INT32 argc, const CHAR **argv)
return 0;
}
#else
//这个函数主要实现对hwi命令的解释功能输出硬件中断信息
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdHwi(INT32 argc, const CHAR **argv)
{
UINT32 i;
HwiHandleInfo *hwiForm = NULL;
//参数错误,打印错误信息
(VOID)argv;
if (argc > 0) {
PRINTK("\nUsage: hwi\n");
return OS_ERROR;
}
//打印硬件中断信息的表头
OsShellCmdHwiInfoTitle();
//遍历所有硬件中断寄存器
for (i = 0; i < LOSCFG_PLATFORM_HWI_LIMIT; i++) {
if (!HWI_IS_REGISTED(i)) {
continue;
}
/* Different cores has different hwi form implementation */
//输出信息
hwiForm = OsGetHwiForm(i);
PRINTK("%-8u\t %-s\t %-10u", i, GetHwiShare(hwiForm) ? "Y" : "N", OsGetHwiFormCnt(i));
#ifdef LOSCFG_SHARED_IRQ
@ -170,7 +183,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdHwi(INT32 argc, const CHAR **argv)
return 0;
}
#endif
//该函数实现了OsShellCmdHwi的函数调用用户可以输入hwi命令来调用该函数从而查询和展示硬件中断信息
SHELLCMD_ENTRY(hwi_shellcmd, CMD_TYPE_EX, "hwi", 0, (CmdCallBackFunc)OsShellCmdHwi);
#ifdef __cplusplus

@ -25,7 +25,10 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
/*
LiteOSShell
使
*/
#include "stdlib.h"
#include "stdio.h"
#include "los_memory_pri.h"
@ -45,54 +48,60 @@ extern "C" {
#define MEM_SIZE_1K 0x400
#define MEM_SIZE_1M 0x100000
//这个函数用于检查内存完整性
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdMemCheck(INT32 argc, const CHAR *argv[])
{
//打印错误信息
if (argc > 0) {
PRINTK("\nUsage: memcheck\n");
return OS_ERROR;
}
//调用OsMemIntegrityMultiCheck函数完成内存完整性检查
OsMemIntegrityMultiCheck();
return 0;
}
#ifdef LOSCFG_SHELL
//这个函数可以读取内存中指定位置指定长度的数据调用OsDumpMemByte函数完成内存读取并打印数据
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdMemRead(INT32 argc, const CHAR *argv[])
{
size_t tempAddr;
size_t length;
CHAR *ptrlen = NULL;
CHAR *ptrAddr = NULL;
//读取错误,打印错误信息
if ((argc == 0) || (argc > 2)) { /* argc is num of parameters */
PRINTK("\nUsage: readreg [ADDRESS] [LENGTH]\n");
return OS_ERROR;
}
//读取正确
if (argc == 1) {
length = 0;
} else {
//读取长度为负数,打印错误信息
length = strtoul(argv[1], &ptrlen, 0);
if ((ptrlen == NULL) || (*ptrlen != 0)) {
PRINTK("readreg invalid length %s\n", argv[1]);
return OS_ERROR;
}
}
//保存ptrAddr的地址
tempAddr = strtoul(argv[0], &ptrAddr, 0);
//地址错误,打印错误信息
if ((ptrAddr == NULL) || (*ptrAddr != 0) || (tempAddr > g_sys_mem_addr_end) ||
((tempAddr + length) > g_sys_mem_addr_end) || (tempAddr > (OS_NULL_INT - length))) {
PRINTK("readreg invalid address %s\n", argv[0]);
return OS_ERROR;
}
//调用OsDumpMemByte函数打印指定内存位置读取的信息。
OsDumpMemByte(length, tempAddr);
return 0;
}
//这个函数用于输出代码段、数据段、只读数据段和BSS段的大小信息。
LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdSectionInfo(INT32 argc, const CHAR *argv[])
{
//计算各部分长度
size_t textLen = &__text_end - &__text_start;
size_t dataLen = &__ram_data_end - &__ram_data_start;
size_t rodataLen = &__rodata_end - &__rodata_start;
@ -103,7 +112,7 @@ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdSectionInfo(INT32 argc, const CHAR
dataLen += &__fast_data_end - &__fast_data_start;
rodataLen += &__fast_rodata_end - &__fast_rodata_start;
#endif
//打印代码段、数据段、只读数据段、BSS段的大小信息
PRINTK("\r\n text data rodata bss\n");
if ((argc == 1) && (strcmp(argv[0], "-k") == 0)) {
PRINTK("Mem: %-9lu %-10lu %-10lu %-10lu\n", textLen / MEM_SIZE_1K, dataLen / MEM_SIZE_1K,
@ -115,19 +124,24 @@ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdSectionInfo(INT32 argc, const CHAR
PRINTK("Mem: %-9lu %-10lu %-10lu %-10lu\n", textLen, dataLen, rodataLen, bssLen);
}
}
//这个函数用于输出系统可用的内存总量、已经使用的内存量和剩余内存量的大小
LITE_OS_SEC_TEXT_MINOR STATIC UINT32 OsShellCmdFreeInfo(INT32 argc, const CHAR *argv[])
{
#ifdef LOSCFG_EXC_INTERACTION
//调用LOS_MemTotaUsedGet函数得到已经使用的内存量
UINT32 memUsed0 = LOS_MemTotalUsedGet(m_aucSysMem0);
//调用LOS_MemPoolSizeGet函数得到系统可用的内存总量
UINT32 totalMem0 = LOS_MemPoolSizeGet(m_aucSysMem0);
//计算得到系统剩余的内存量
UINT32 freeMem0 = totalMem0 - memUsed0;
#endif
//调用LOS_MemTotaUsedGet函数得到已经使用的内存量
UINT32 memUsed = LOS_MemTotalUsedGet(m_aucSysMem1);
//调用LOS_MemPoolSizeGet函数得到系统可用的内存总量
UINT32 totalMem = LOS_MemPoolSizeGet(m_aucSysMem1);
/
UINT32 freeMem = totalMem - memUsed;
//打印统可用的内存总量、已经使用的内存量和剩余内存量的大小
if ((argc == 0) ||
((argc == 1) && (strcmp(argv[0], "-k") == 0)) ||
((argc == 1) && (strcmp(argv[0], "-m") == 0))) {
@ -157,47 +171,57 @@ LITE_OS_SEC_TEXT_MINOR STATIC UINT32 OsShellCmdFreeInfo(INT32 argc, const CHAR *
PRINTK("Mem1: %-9u %-10u %-10u\n", totalMem0, memUsed0, freeMem0);
#endif
} else {
//打印错误信息
PRINTK("\nUsage: free or free [-k/-m]\n");
return OS_ERROR;
}
return 0;
}
//这个函数用于显示系统内存的使用情况调用了OsShellCmdFreeInfo和OsShellCmdSectionInfo函数完成内存使用情况和内存分配情况的打印输出。
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdFree(INT32 argc, const CHAR *argv[])
{
//打印错误信息
if (argc > 1) {
PRINTK("\nUsage: free or free [-k/-m]\n");
return OS_ERROR;
}
//打印错误信息
if (OsShellCmdFreeInfo(argc, argv) != 0) {
return OS_ERROR;
}
//调用OsShellCmdSectionInfo函数输出存使用情况和内存分配情况
OsShellCmdSectionInfo(argc, argv);
return 0;
}
//这个函数根据参数选择输出不同的系统信息,在控制台上输出相应的信息。
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdUname(INT32 argc, const CHAR *argv[])
{
//如果参数为0在控制台上打印Huawei LiteOS
if (argc == 0) {
PRINTK("Huawei LiteOS\n");
return 0;
}
if (argc == 1) {
//系统参数为-a时打印LiteOS所有的信息
if (strcmp(argv[0], "-a") == 0) {
PRINTK("%s %s %s %s %s\n", HW_LITEOS_VER, HW_LITEOS_SYSNAME, HW_LITEOS_KERNEL_VERSION_STRING,
__DATE__, __TIME__);
return 0;
//系统参数为-s时打印Huawei LiteOS
} else if (strcmp(argv[0], "-s") == 0) {
PRINTK("Huawei LiteOS\n");
return 0;
//系统参数为-t时打印系统创建的时间信息
} else if (strcmp(argv[0], "-t") == 0) {
PRINTK("build date : %s %s", __DATE__, __TIME__);
return 0;
//系统参数为-v时打印LiteOS的版本信息和时间信息
} else if (strcmp(argv[0], "-v") == 0) {
PRINTK("%s %s %s %s\n", HW_LITEOS_SYSNAME, HW_LITEOS_KERNEL_VERSION_STRING,
__DATE__, __TIME__);
return 0;
//系统参数为--help时打印各参数的含义
} else if (strcmp(argv[0], "--help") == 0) {
PRINTK("-a, print all information\n"
"-s, print the kernel name\n"
@ -206,20 +230,22 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdUname(INT32 argc, const CHAR *argv[])
return 0;
}
}
//如果都不是,打印错误信息,提示用户输入--help来查看信息
PRINTK("uname: invalid option %s\n"
"Try 'uname --help' for more information.\n",
argv[0]);
return OS_ERROR;
}
#ifdef LOSCFG_MEM_LEAKCHECK
//这个函数打印了系统已使用的内存信息
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdMemUsed(INT32 argc, const CHAR *argv[])
{
//打印错误信息
if (argc > 0) {
PRINTK("\nUsage: memused\n");
return OS_ERROR;
}
//调用OsMemUsedNodeShow函数输出已使用的节点信息
OsMemUsedNodeShow(m_aucSysMem1);
#ifdef LOSCFG_EXC_INTERACTION
@ -230,6 +256,14 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdMemUsed(INT32 argc, const CHAR *argv[])
}
#endif
/*
memcheckOsMemIntegrityMultiCheck
memread [ADDRESS] [LENGTH]OsDumpMemByte
free使OsShellCmdFreeInfoOsShellCmdSectionInfo使
uname [-a/-s/-t/-v]PRINTK
*/
#ifdef LOSCFG_MEM_LEAKCHECK
SHELLCMD_ENTRY(memused_shellcmd, CMD_TYPE_EX, "memused", 0, (CmdCallBackFunc)OsShellCmdMemUsed);
#endif

@ -25,7 +25,10 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
/*
LiteOSShell
*/
#include "securec.h"
#include "los_config.h"
#include "los_stackinfo_pri.h"
@ -34,7 +37,7 @@
#include "shcmd.h"
#include "shell.h"
#endif
//这个函数用于检查堆栈是否溢出
VOID OsExcStackCheck(VOID)
{
UINT32 index;
@ -42,15 +45,17 @@ VOID OsExcStackCheck(VOID)
UINTPTR *stackTop = NULL;
const StackInfo *stackInfo = NULL;
UINT32 stackNum;
//获取堆栈信息,如果堆栈信息错误,直接返回
OsGetStackInfo(&stackInfo, &stackNum);
if ((stackInfo == NULL) || (stackNum == 0)) {
return;
}
//从头开始,遍历所有的堆栈
for (index = 0; index < stackNum; index++) {
for (cpuid = 0; cpuid < LOSCFG_KERNEL_CORE_NUM; cpuid++) {
//堆栈的栈顶
stackTop = (UINTPTR *)((UINTPTR)stackInfo[index].stackTop + cpuid * stackInfo[index].stackSize);
//检查栈顶信息是否被篡改,如果被篡改输出该堆栈溢出的信息
if (*stackTop != OS_STACK_MAGIC_WORD) {
PRINT_ERR("cpu:%u %s overflow , magic word changed to 0x%x\n",
LOSCFG_KERNEL_CORE_NUM - 1 - cpuid, stackInfo[index].stackName, *stackTop);
@ -58,7 +63,7 @@ VOID OsExcStackCheck(VOID)
}
}
}
//这个函数用于获取并打印所有的堆栈信息
VOID OsExcStackInfo(VOID)
{
UINT32 index;
@ -68,29 +73,31 @@ VOID OsExcStackInfo(VOID)
UINTPTR *stack = NULL;
const StackInfo *stackInfo = NULL;
UINT32 stackNum;
//获取堆栈信息,如果堆栈信息错误,直接返回
OsGetStackInfo(&stackInfo, &stackNum);
if ((stackInfo == NULL) || (stackNum == 0)) {
return;
}
//输出堆栈名、CPU ID、堆栈的地址、堆栈的总大小堆栈已使用的大小
PrintExcInfo("\n stack name cpu id stack addr total size used size\n"
" ---------- ------ --------- -------- --------\n");
//从头开始,遍历所有的堆栈
for (index = 0; index < stackNum; index++) {
for (cpuid = 0; cpuid < LOSCFG_KERNEL_CORE_NUM; cpuid++) {
//获取堆栈的栈顶
stackTop = (UINTPTR *)((UINTPTR)stackInfo[index].stackTop + cpuid * stackInfo[index].stackSize);
stack = (UINTPTR *)((UINTPTR)stackTop + stackInfo[index].stackSize);
//调用OsStackWaterLineGet函数计算堆栈已使用的大小
(VOID)OsStackWaterLineGet(stack, stackTop, &size);
//输出各类信息
PrintExcInfo("%11s %-5d %-10p 0x%-8x 0x%-4x\n", stackInfo[index].stackName,
LOSCFG_KERNEL_CORE_NUM - 1 - cpuid, stackTop, stackInfo[index].stackSize, size);
}
}
//进行堆栈溢出检查
OsExcStackCheck();
}
//注册Shell命令stack调用OsExcStackInfo函数获取并打印所有堆栈信息至控制台。
#ifdef LOSCFG_SHELL
SHELLCMD_ENTRY(stack_shellcmd, CMD_TYPE_EX, "stack", 1, (CmdCallBackFunc)OsExcStackInfo);
#endif

@ -25,7 +25,10 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
/*
LiteOS
ID
*/
#include "los_config.h"
#ifdef LOSCFG_SHELL
#include "stdlib.h"
@ -42,20 +45,20 @@ extern "C" {
#define SWTMR_STRLEN 12
#ifdef LOSCFG_BASE_CORE_SWTMR
//展示g_shellSwtmrMode的数据
LITE_OS_SEC_DATA_MINOR STATIC CHAR g_shellSwtmrMode[][SWTMR_STRLEN] = {
"Once",
"Period",
"NSD",
"OPP",
};
//展示g_shellSwtmrStatus的数据
LITE_OS_SEC_DATA_MINOR STATIC CHAR g_shellSwtmrStatus[][SWTMR_STRLEN] = {
"UnUsed",
"Created",
"Ticking",
};
//这个函数用于打印软件定时器的信息包括定时器ID、状态、模式、间隔、参数和处理函数地址等。
STATIC VOID OsPrintSwtmrMsg(const LosSwtmrCB *swtmr)
{
PRINTK("0x%08x "
@ -64,20 +67,20 @@ STATIC VOID OsPrintSwtmrMsg(const LosSwtmrCB *swtmr)
"%-6u "
"0x%08x "
"%p\n",
swtmr->timerId % LOSCFG_BASE_CORE_SWTMR_LIMIT,
g_shellSwtmrStatus[swtmr->state],
g_shellSwtmrMode[swtmr->mode],
swtmr->interval,
swtmr->arg,
swtmr->handler);
swtmr->timerId % LOSCFG_BASE_CORE_SWTMR_LIMIT,//打印定时器ID
g_shellSwtmrStatus[swtmr->state],//打印定时器的状态
g_shellSwtmrMode[swtmr->mode],//打印定时器的模式
swtmr->interval,//打印定时器的间隔
swtmr->arg,//打印定时器的参数
swtmr->handler);//打印定时器的处理函数地址
}
//这个函数用于打印软件定时器信息的表头
STATIC INLINE VOID OsPrintSwtmrMsgHead(VOID)
{
PRINTK("\r\nSwTmrID State Mode Interval Arg handlerAddr\n");
PRINTK("---------- ------- ------- --------- ---------- --------\n");
}
//这个函数用于获取软件定时器的信息。
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdSwtmrInfoGet(INT32 argc, const UINT8 **argv)
{
#define OS_ALL_SWTMR_MASK 0xffffffff
@ -87,34 +90,36 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdSwtmrInfoGet(INT32 argc, const UINT8 **a
size_t timerId;
UINT16 num = 0;
CHAR *endPtr = NULL;
//打印错误信息
if (argc > 1) {
PRINTK("\nUsage: swtmr [ID]\n");
return OS_ERROR;
}
//获取计时器ID
if (argc == 0) {
timerId = OS_ALL_SWTMR_MASK;
} else {
//没有这个ID打印错误信息
timerId = strtoul((CHAR *)argv[0], &endPtr, 0);
if ((endPtr == NULL) || (*endPtr != 0) || (timerId > LOSCFG_BASE_CORE_SWTMR_LIMIT)) {
PRINTK("\nswtmr ID can't access %s.\n", argv[0]);
return OS_ERROR;
}
}
//遍历所有计时器让计时器的状态加1
for (index = 0; index < LOSCFG_BASE_CORE_SWTMR_LIMIT; index++, swtmr1++) {
if (swtmr1->state == 0) {
num = num + 1;
}
}
//达到时间限制,输出错误信息
if (num == LOSCFG_BASE_CORE_SWTMR_LIMIT) {
PRINTK("\r\nThere is no swtmr was created!\n");
return OS_ERROR;
}
//打印软件定时器信息的表头
OsPrintSwtmrMsgHead();
//打印软件定时器的各类信息
if (timerId == OS_ALL_SWTMR_MASK) {
for (index = 0; index < LOSCFG_BASE_CORE_SWTMR_LIMIT; index++, swtmr++) {
if (swtmr->state != 0) {
@ -132,7 +137,7 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdSwtmrInfoGet(INT32 argc, const UINT8 **a
}
return LOS_OK;
}
//注册Shell命令swtmr调用OsShellCmdSwtmrInfoGet函数获取软件定时器的信息。根据输入的参数获取特定或者所有软件定时器的状态信息并打印出来。
SHELLCMD_ENTRY(swtmr_shellcmd, CMD_TYPE_EX, "swtmr", 1, (CmdCallBackFunc)OsShellCmdSwtmrInfoGet);
#endif

@ -25,7 +25,10 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
/*
LiteOSShell
*/
#include "los_config.h"
#include "los_swtmr.h"
#include "los_sem_pri.h"
@ -43,141 +46,173 @@
extern "C" {
#endif
#endif /* __cplusplus */
//这个函数用于获取当系统的进程数量
UINT32 OsShellCmdTaskCntGet(VOID)
{
UINT32 loop;
UINT32 taskCnt = 0;
UINT32 intSave;
LosTaskCB *taskCB = NULL;
//加上锁,用于防止中断
intSave = LOS_IntLock();
//遍历所有进程,并统计进程数量
for (loop = 0; loop < g_taskMaxNum; loop++) {
taskCB = (LosTaskCB *)g_taskCBArray + loop;
//若该进程未使用,则直接跳过
if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) {
continue;
}
taskCnt++;
}
//为进程解锁
LOS_IntRestore(intSave);
//返回系统的进程数量
return taskCnt;
}
#ifdef LOSCFG_BASE_IPC_SEM
//这个函数用于获取当前系统信号量的数量
UINT32 OsShellCmdSemCntGet(VOID)
{
UINT32 loop;
UINT32 semCnt = 0;
UINT32 intSave;
LosSemCB *semNode = NULL;
//加上锁,用于防止中断
intSave = LOS_IntLock();
//遍历所有信号量
for (loop = 0; loop < LOSCFG_BASE_IPC_SEM_LIMIT; loop++) {
semNode = GET_SEM(loop);
//如果该信号量被使用了数量加1
if (semNode->semStat == LOS_USED) {
semCnt++;
}
}
//为进程解锁
LOS_IntRestore(intSave);
//返回系统信号量的数量
return semCnt;
}
#endif
#ifdef LOSCFG_BASE_IPC_MUX
//这个函数用于获取当前系统互斥锁的数量
UINT32 OsShellCmdMuxCntGet(VOID)
{
UINT32 loop;
UINT32 muxCnt = 0;
UINT32 intSave;
LosMuxCB *muxNode = NULL;
//加上锁,用于防止中断
intSave = LOS_IntLock();
//遍历所有互斥锁
for (loop = 0; loop < LOSCFG_BASE_IPC_MUX_LIMIT; loop++) {
muxNode = GET_MUX(loop);
//如果互斥锁的状态被使用了数量加1
if (muxNode->muxStat == LOS_USED) {
muxCnt++;
}
}
//为进程解锁
LOS_IntRestore(intSave);
//返回系统互斥锁的数量
return muxCnt;
}
#endif
#ifdef LOSCFG_BASE_IPC_QUEUE
//这个函数用于获取系统消息队列的数量
UINT32 OsShellCmdQueueCntGet(VOID)
{
UINT32 loop;
UINT32 queueCnt = 0;
UINT32 intSave;
LosQueueCB *queueCB = NULL;
//加上锁,用于防止中断
intSave = LOS_IntLock();
queueCB = g_allQueue;
//遍历所有消息队列
for (loop = 0; loop < LOSCFG_BASE_IPC_QUEUE_LIMIT; loop++, queueCB++) {
//如果消息队列的状态为使用数量加1
if (queueCB->queueState == LOS_USED) {
queueCnt++;
}
}
//为进程解锁
LOS_IntRestore(intSave);
//返回系统获取消息队列的数量
return queueCnt;
}
#endif
#ifdef LOSCFG_BASE_CORE_SWTMR
//这个函数用于获取系统软件定时器的数量
UINT32 OsShellCmdSwtmrCntGet(VOID)
{
UINT32 loop;
UINT32 swtmrCnt = 0;
UINT32 intSave;
LosSwtmrCB *swtmrCB = NULL;
//加上锁,用于防止中断
intSave = LOS_IntLock();
swtmrCB = g_swtmrCBArray;
//遍历所有软件定时器
for (loop = 0; loop < LOSCFG_BASE_CORE_SWTMR_LIMIT; loop++, swtmrCB++) {
//如果软件定时器的状态不是没有使用数量加1
if (swtmrCB->state != OS_SWTMR_STATUS_UNUSED) {
swtmrCnt++;
}
}
//为进程解锁
LOS_IntRestore(intSave);
//返回系统软件定时器的数量
return swtmrCnt;
}
#endif
//这个函数用于打印系统信息,包括进程数量、信号量数量、互斥锁数量、消息队列数量和软件定时器数量。
LITE_OS_SEC_TEXT_MINOR VOID OsShellCmdSystemInfoGet(VOID)
{
//打印表头
PRINTK("\n Module Used Total\n");
PRINTK("--------------------------------\n");
//打印进程数量
PRINTK(" Task %-10u%-10d\n",
OsShellCmdTaskCntGet(),
LOSCFG_BASE_CORE_TSK_LIMIT);
#ifdef LOSCFG_BASE_IPC_SEM
//打印信号量数量
PRINTK(" Sem %-10u%-10d\n",
OsShellCmdSemCntGet(),
LOSCFG_BASE_IPC_SEM_LIMIT);
#endif
#ifdef LOSCFG_BASE_IPC_MUX
//打印互斥锁数量
PRINTK(" Mutex %-10u%-10d\n",
OsShellCmdMuxCntGet(),
LOSCFG_BASE_IPC_MUX_LIMIT);
#endif
#ifdef LOSCFG_BASE_IPC_QUEUE
//打印消息队列数量
PRINTK(" Queue %-10u%-10d\n",
OsShellCmdQueueCntGet(),
LOSCFG_BASE_IPC_QUEUE_LIMIT);
#endif
#ifdef LOSCFG_BASE_CORE_SWTMR
//打印软件定时器数量
PRINTK(" SwTmr %-10u%-10d\n",
OsShellCmdSwtmrCntGet(),
LOSCFG_BASE_CORE_SWTMR_LIMIT);
#endif
}
//这个函数用于处理shell的systeminfo命令根据相应的参数做出相应的处理
INT32 OsShellCmdSystemInfo(INT32 argc, const CHAR **argv)
{
//如果参数数量为0调用OsShellCmdSystemInfoGet函数打印所有的系统信息。
if (argc == 0) {
OsShellCmdSystemInfoGet();
return 0;
}
//参数数量不正确,打印错误信息
PRINTK("systeminfo: invalid option %s\n"
"Systeminfo has NO ARGS.\n",
argv[0]);
@ -185,6 +220,7 @@ INT32 OsShellCmdSystemInfo(INT32 argc, const CHAR **argv)
}
#ifdef LOSCFG_SHELL
//注册Shell命令systeminfo调用OsShellCmdSystemInfo根据参数输出当前系统的程数量、信号量数量、互斥锁数量、消息队列数量和软件定时器数量。。
SHELLCMD_ENTRY(systeminfo_shellcmd, CMD_TYPE_EX, "systeminfo", 1, (CmdCallBackFunc)OsShellCmdSystemInfo);
#endif /* LOSCFG_SHELL */

@ -25,7 +25,10 @@
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* --------------------------------------------------------------------------- */
/*
LiteOSShell
*/
#include "stdio.h"
#include "stdlib.h"
#include "los_config.h"
@ -53,55 +56,65 @@ extern "C" {
#define OS_INVALID_SEM_ID 0xFFFFFFFF
#ifdef LOSCFG_KERNEL_CPUP
LITE_OS_SEC_BSS STATIC CPUP_INFO_S g_taskCpupAll[LOSCFG_BASE_CORE_TSK_LIMIT];
LITE_OS_SEC_BSS STATIC CPUP_INFO_S g_taskCpup10s[LOSCFG_BASE_CORE_TSK_LIMIT];
LITE_OS_SEC_BSS STATIC CPUP_INFO_S g_taskCpup1s[LOSCFG_BASE_CORE_TSK_LIMIT];
LITE_OS_SEC_BSS STATIC CPUP_INFO_S g_taskCpupAll[LOSCFG_BASE_CORE_TSK_LIMIT];//所有时间段CPU利用率的统计信息
LITE_OS_SEC_BSS STATIC CPUP_INFO_S g_taskCpup10s[LOSCFG_BASE_CORE_TSK_LIMIT];//最近10sCPU利用率的统计信息
LITE_OS_SEC_BSS STATIC CPUP_INFO_S g_taskCpup1s[LOSCFG_BASE_CORE_TSK_LIMIT];//最近1sCPU利用率的统计信息
#endif
LITE_OS_SEC_BSS STATIC UINT32 g_taskWaterLine[LOSCFG_BASE_CORE_TSK_LIMIT];
LITE_OS_SEC_BSS STATIC UINT32 g_taskWaterLine[LOSCFG_BASE_CORE_TSK_LIMIT];//记录各个堆栈最低的水位
//这个函数通过进程状态位来判断进程的状态,并返回相应的字符串表示进程状态。
LITE_OS_SEC_TEXT_MINOR UINT8 *OsShellCmdConvertTskStatus(UINT16 taskStatus)
{
//进程处于运行状态返回Running
if (taskStatus & OS_TASK_STATUS_RUNNING) {
return (UINT8 *)"Running";
return (UINT8 *)"Running";
//进程处于就绪状态返回Ready
} else if (taskStatus & OS_TASK_STATUS_READY) {
return (UINT8 *)"Ready";
//其他的进程状态
} else {
//进程处于延迟状态返回Delay
if (taskStatus & OS_TASK_STATUS_DELAY) {
return (UINT8 *)"Delay";
} else if (taskStatus & OS_TASK_STATUS_PEND_TIME) {
//进程处于定时挂起状态返回SuspendTime
if (taskStatus & OS_TASK_STATUS_SUSPEND) {
return (UINT8 *)"SuspendTime";
//进程处于定时等待状态返回PendTime
} else if (taskStatus & OS_TASK_STATUS_PEND) {
return (UINT8 *)"PendTime";
}
//进程处于等待状态返回Pend
} else if (taskStatus & OS_TASK_STATUS_PEND) {
return (UINT8 *)"Pend";
//进程处于挂起状态返回SusPend
} else if (taskStatus & OS_TASK_STATUS_SUSPEND) {
return (UINT8 *)"Suspend";
}
}
//进程状态不合法返回Invalid
return (UINT8 *)"Invalid";
}
//这个函数用于获取所有堆栈的栈水位(堆栈的使用情况)
STATIC VOID OsShellCmdTaskWaterLineGet(const LosTaskCB *allTaskArray)
{
const LosTaskCB *taskCB = NULL;
UINT32 loop;
//遍历所有堆栈
for (loop = 0; loop < g_taskMaxNum; ++loop) {
taskCB = allTaskArray + loop;
//如果该堆栈未使用,直接跳过
if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) {
continue;
}
//调用OsStackWaterLineGet输出堆栈的栈水位信息
(VOID)OsStackWaterLineGet((const UINTPTR *)((UINTPTR)taskCB->topOfStack + taskCB->stackSize),
(const UINTPTR *)taskCB->topOfStack, &g_taskWaterLine[taskCB->taskId]);
}
}
#ifdef LOSCFG_SHELL_EXCINFO_DUMP
//这个函数用于在异常信息输出缓冲区中打印任务信息的标题。
LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdTskInfoTitleExc(VOID)
{
WriteExcInfoToBuf("\r\nName TaskEntryAddr TID ");
@ -133,7 +146,7 @@ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdTskInfoTitleExc(VOID)
WriteExcInfoToBuf("\n");
}
#endif
//这个函数用于在控制台打印任务信息的标题。
LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdTskInfoTitle(VOID)
{
PRINTK("\r\nName TaskEntryAddr TID ");
@ -165,14 +178,15 @@ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdTskInfoTitle(VOID)
PRINTK("\n");
#ifdef LOSCFG_SHELL_EXCINFO_DUMP
//在异常信息输出缓冲区中打印任务信息的标题。
OsShellCmdTskInfoTitleExc();
#endif
}
//这个函数通过TCB进程控制块获取进程所持有的信号量的ID。
LITE_OS_SEC_TEXT_MINOR STATIC INLINE UINT32 OsGetSemID(const LosTaskCB *taskCB)
{
UINT32 semId = OS_INVALID_SEM_ID;
//返回该进程的信号量ID
if (taskCB->taskSem != NULL) {
semId = ((LosSemCB *)taskCB->taskSem)->semId;
}
@ -181,12 +195,13 @@ LITE_OS_SEC_TEXT_MINOR STATIC INLINE UINT32 OsGetSemID(const LosTaskCB *taskCB)
}
#ifdef LOSCFG_SHELL_EXCINFO_DUMP
//这个函数用于将TCB进程控制块中的进程信息输出到异常信息输出缓冲区。
LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdTskInfoDataExc(const LosTaskCB *allTaskArray)
{
const LosTaskCB *taskCB = NULL;
UINT32 loop;
UINT32 semId;
//遍历所有的堆栈
for (loop = 0; loop < g_taskMaxNum; ++loop) {
taskCB = allTaskArray + loop;
if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) {
@ -194,21 +209,25 @@ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdTskInfoDataExc(const LosTaskCB *all
}
semId = OsGetSemID(taskCB);
//调用WriteExcInfoToBuf函数将TCB进程控制块的信息写入缓冲区
WriteExcInfoToBuf("%-23s0x%-18.8x0x%-5x", taskCB->taskName, taskCB->taskEntry, taskCB->taskId);
#ifdef LOSCFG_KERNEL_SMP
//调用WriteExcInfoToBuf函数将TCB进程控制块的信息写入缓冲区
WriteExcInfoToBuf("0x%04x %4d ", taskCB->cpuAffiMask, (INT16)(taskCB->currCpu));
#endif
//调用WriteExcInfoToBuf函数将TCB进程控制块的信息写入缓冲区
WriteExcInfoToBuf("%-11u%-13s0x%-11x0x%-11x 0x%-.8x 0x%-.8x 0x%-11x", taskCB->priority,
OsShellCmdConvertTskStatus(taskCB->taskStatus), taskCB->stackSize,
g_taskWaterLine[taskCB->taskId],
taskCB->stackPointer, taskCB->topOfStack, semId);
#ifdef LOSCFG_BASE_IPC_EVENT
//调用WriteExcInfoToBuf函数将TCB进程控制块的信息写入缓冲区
WriteExcInfoToBuf("0x%-6x", taskCB->eventMask);
#endif
#ifdef LOSCFG_KERNEL_CPUP
//调用WriteExcInfoToBuf函数将TCB进程控制块的信息写入缓冲区
WriteExcInfoToBuf(" %4u.%1u%9u.%1u%8u.%1u ",
g_taskCpupAll[taskCB->taskId].uwUsage / LOS_CPUP_PRECISION_MULT,
g_taskCpupAll[taskCB->taskId].uwUsage % LOS_CPUP_PRECISION_MULT,
@ -218,41 +237,47 @@ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdTskInfoDataExc(const LosTaskCB *all
g_taskCpup1s[taskCB->taskId].uwUsage % LOS_CPUP_PRECISION_MULT);
#endif /* LOSCFG_KERNEL_CPUP */
#ifdef LOSCFG_MEM_TASK_STAT
//调用WriteExcInfoToBuf函数将TCB进程控制块的信息写入缓冲区
WriteExcInfoToBuf(" %-11u", OsMemTaskUsage(taskCB->taskId));
#endif
//调用WriteExcInfoToBuf函数将TCB进程控制块的信息写入缓冲区
WriteExcInfoToBuf("\n");
}
}
#endif
//这个函数可以将TCB(进程控制块)中的信息输出到控制台。
LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdTskInfoData(const LosTaskCB *allTaskArray)
{
const LosTaskCB *taskCB = NULL;
UINT32 loop;
UINT32 semId;
//遍历所有的堆栈
for (loop = 0; loop < g_taskMaxNum; ++loop) {
taskCB = allTaskArray + loop;
if (taskCB->taskStatus & OS_TASK_STATUS_UNUSED) {
continue;
}
//调用OsGetSemID获取该进程的信号量ID
semId = OsGetSemID(taskCB);
//输出进程信息到控制台
PRINTK("%-23s0x%-18.8x0x%-5x", taskCB->taskName, taskCB->taskEntry, taskCB->taskId);
#ifdef LOSCFG_KERNEL_SMP
//输出进程信息到控制台
PRINTK("0x%04x %4d ", taskCB->cpuAffiMask, (INT16)(taskCB->currCpu));
#endif
//输出进程信息到控制台
PRINTK("%-11u%-13s0x%-11x0x%-11x 0x%-.8x 0x%-.8x 0x%-11x", taskCB->priority,
OsShellCmdConvertTskStatus(taskCB->taskStatus), taskCB->stackSize,
g_taskWaterLine[taskCB->taskId],
taskCB->stackPointer, taskCB->topOfStack, semId);
#ifdef LOSCFG_BASE_IPC_EVENT
//输出进程信息到控制台
PRINTK("0x%-6x", taskCB->eventMask);
#endif
#ifdef LOSCFG_KERNEL_CPUP
//输出进程信息到控制台
PRINTK(" %4u.%1u%9u.%1u%8u.%1u ",
g_taskCpupAll[taskCB->taskId].uwUsage / LOS_CPUP_PRECISION_MULT,
g_taskCpupAll[taskCB->taskId].uwUsage % LOS_CPUP_PRECISION_MULT,
@ -262,16 +287,19 @@ LITE_OS_SEC_TEXT_MINOR STATIC VOID OsShellCmdTskInfoData(const LosTaskCB *allTas
g_taskCpup1s[taskCB->taskId].uwUsage % LOS_CPUP_PRECISION_MULT);
#endif /* LOSCFG_KERNEL_CPUP */
#ifdef LOSCFG_MEM_TASK_STAT
//输出进程信息到控制台
PRINTK(" %-11u", OsMemTaskUsage(taskCB->taskId));
#endif
//输出进程信息到控制台
PRINTK("\n");
}
#ifdef LOSCFG_SHELL_EXCINFO_DUMP
//将进程信息输出到异常信息输出缓冲区。
OsShellCmdTskInfoDataExc(allTaskArray);
#endif
}
//这个函数可以通过进程号获取进程的信息
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdTskInfoGet(UINT32 taskId)
{
BOOL backupFlag = TRUE;
@ -279,50 +307,57 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdTskInfoGet(UINT32 taskId)
UINT32 size, intSave;
LosTaskCB *tcbArray = NULL;
INT32 ret;
//如果是目标进程
if (taskId == OS_ALL_TASK_MASK) {
size = g_taskMaxNum * sizeof(LosTaskCB);
tcbArray = (LosTaskCB *)LOS_MemAlloc(m_aucSysMem1, size);
//如果目标进程信息为空输出错误信息将backup设置为Fasle不备份该进程信息
if (tcbArray == NULL) {
PRINTK("Memory is not enough to save task info!\n");
tcbArray = g_taskCBArray;
backupFlag = FALSE;
}
#ifdef LOSCFG_KERNEL_CPUP
(VOID)memset_s((VOID *)g_taskCpupAll, sizeof(g_taskCpupAll), 0, sizeof(g_taskCpupAll));
(VOID)memset_s((VOID *)g_taskCpup10s, sizeof(g_taskCpup10s), 0, sizeof(g_taskCpup10s));
(VOID)memset_s((VOID *)g_taskCpup1s, sizeof(g_taskCpup1s), 0, sizeof(g_taskCpup1s));
(VOID)memset_s((VOID *)g_taskCpupAll, sizeof(g_taskCpupAll), 0, sizeof(g_taskCpupAll));//置零
(VOID)memset_s((VOID *)g_taskCpup10s, sizeof(g_taskCpup10s), 0, sizeof(g_taskCpup10s));//置零
(VOID)memset_s((VOID *)g_taskCpup1s, sizeof(g_taskCpup1s), 0, sizeof(g_taskCpup1s));//置零
#endif
(VOID)memset_s((VOID *)g_taskWaterLine, sizeof(g_taskWaterLine), 0, sizeof(g_taskWaterLine));
(VOID)memset_s((VOID *)g_taskWaterLine, sizeof(g_taskWaterLine), 0, sizeof(g_taskWaterLine));//置零
//如果没有调度器自旋锁,为该进程添加调度器自旋锁
if (LOS_SpinHeld(&g_taskSpin) == FALSE) {
SCHEDULER_LOCK(intSave);
lockFlag = TRUE;
}
//如果需要将进程信息备份
if (backupFlag == TRUE) {
//将进程信息备份到tcbArray
ret = memcpy_s(tcbArray, size, g_taskCBArray, size);
//如果没有备份成果返回错误
if (ret != EOK) {
return LOS_NOK;
}
}
#ifdef LOSCFG_KERNEL_CPUP
(VOID)LOS_AllCpuUsage(LOSCFG_BASE_CORE_TSK_LIMIT, g_taskCpupAll, CPUP_ALL_TIME, 1);
(VOID)LOS_AllCpuUsage(LOSCFG_BASE_CORE_TSK_LIMIT, g_taskCpup10s, CPUP_LAST_TEN_SECONDS, 1);
(VOID)LOS_AllCpuUsage(LOSCFG_BASE_CORE_TSK_LIMIT, g_taskCpup1s, CPUP_LAST_ONE_SECONDS, 1);
(VOID)LOS_AllCpuUsage(LOSCFG_BASE_CORE_TSK_LIMIT, g_taskCpupAll, CPUP_ALL_TIME, 1);//显示CPU所有时段的使用率信息
(VOID)LOS_AllCpuUsage(LOSCFG_BASE_CORE_TSK_LIMIT, g_taskCpup10s, CPUP_LAST_TEN_SECONDS, 1);//显示CPU最近10s的使用率信息
(VOID)LOS_AllCpuUsage(LOSCFG_BASE_CORE_TSK_LIMIT, g_taskCpup1s, CPUP_LAST_ONE_SECONDS, 1);//显示CPU最近1s的使用率信息
#endif
//获取进程的栈水位信息
OsShellCmdTaskWaterLineGet(tcbArray);
//如果进程有调度器自旋锁,将该进程解锁
if (lockFlag == TRUE) {
SCHEDULER_UNLOCK(intSave);
}
//打印进程信息标题
OsShellCmdTskInfoTitle();
//打印进程信息的数据
OsShellCmdTskInfoData(tcbArray);
//如果进程信息数据备份成果释放tcbArrayd的内存空间
if (backupFlag == TRUE) {
(VOID)LOS_MemFree(m_aucSysMem1, tcbArray);
}
} else {
//调用 OsTaskBackTrace函数来获取该任务的回溯信息。
OsTaskBackTrace(taskId);
}
@ -330,29 +365,34 @@ LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdTskInfoGet(UINT32 taskId)
}
#ifdef LOSCFG_SHELL
//这个函数用于处理task命令通过各种参数输出结果
LITE_OS_SEC_TEXT_MINOR UINT32 OsShellCmdDumpTask(INT32 argc, const CHAR **argv)
{
size_t taskId;
CHAR *endPtr = NULL;
//当参数数量合法时
if (argc < 2) { /* 2:Just as number of parameters */
//如果没有参数,进程号是所有进程
if (argc == 0) {
taskId = OS_ALL_TASK_MASK;
//存在一个参数为进程号
} else {
taskId = strtoul(argv[0], &endPtr, 0);
//如果进程号不合法,打印错误信息
if ((*endPtr != 0) || (taskId >= g_taskMaxNum)) {
PRINTK("\ntask ID can't access %s.\n", argv[0]);
return OS_ERROR;
}
}
//调用OsShellCmdTskInfoGet函数输出该进程的进程信息
return OsShellCmdTskInfoGet((UINT32)taskId);
} else {
//参数不合法,打印错误信息
PRINTK("\nUsage: task or task ID\n");
return OS_ERROR;
}
}
//注册Shell命令task调用OsShellCmdDumpTask根据参数进程号或者没有参数获取进程信息并输出。
SHELLCMD_ENTRY(task_shellcmd, CMD_TYPE_EX, "task", 1, (CmdCallBackFunc)OsShellCmdDumpTask);
#endif

Loading…
Cancel
Save