📄 mt5_util.c
字号:
*************************************************************
** Function Name: vMt5PrintProcessInfo
** Author: x.cheng
**
** Comment:
** Print the state of every process from the ready,
** wait and zombie queues.
**
** List of parameters:
** no
**
** Return value:
** no
**
** Revisions:
** this is a debug procedures for multitasking,
** and just like others "ps" command
*************************************************************
*************************************************************/
void vMt5PrintProcessInfo()
{
static ts_QueueNode **ppstQueueHead[] = { &g_pstReadyQueue, &g_pstWaitQueue, &g_pstZombieQueue};
static char szQueueState[] = "RWZ";
ts_QueueNode *pstNode;
ts_Task *pstTask;
int iCnt;
int iTmp;
vTuiSetColor( WHITE );
iTuiPrintf("OWNER PID STATE SHELL COMMAND\n");
vTuiSetColor( DEFAULT_COLOR );
vScheduleEnterCritialRegion();
for (iCnt=0; iCnt<CountOfArray(ppstQueueHead); ++iCnt) {
if ( *(ppstQueueHead[iCnt]) != NULL ) {
for ( pstNode=*(ppstQueueHead[iCnt]), iTmp=0; (pstNode!=*(ppstQueueHead[iCnt]))||!iTmp;
pstNode = pstNode->pstNext, ++iTmp) {
pstTask = (NULL != pstNode) ? pstNode->pvVal : NULL;
if ( NULL == pstTask) {
vScheduleLeaveCriticalRegion();
return;
}
if ( pstTask->iPrivilege == KERNEL_PRIVILEGE ) {
}
else {
}
// print process informations.
iTuiPrintf("%s%7u%6c con%d %-12s\n", pstTask->iPrivilege == KERNEL_PRIVILEGE?"kernel" : "user ",
pstTask->iPid,
szQueueState[iCnt],
pstTask->iConsole,
pstTask->szName);
}
}
}
vScheduleLeaveCriticalRegion();
}
/************************************************************
*************************************************************
** Function Name: pstMt5GetTaskInfo
** Author: x.cheng
**
** Comment:
** Return the structure of the task that has pid as identifie,
** NULL if the process is not found.
**
** List of parameters:
** int iPid --task id which need to return the task info.
**
** Return value:
** ts_Task* ...
**
** Revisions:
** This routine must be called in mutual exclusion!!!
**
*************************************************************
*************************************************************/
ts_Task* pstMt5GetTaskInfo( int iPid )
{
// Queues where to search the process.
static ts_QueueNode **appstQueue[] = { &g_pstReadyQueue, &g_pstWaitQueue };
ts_QueueNode *pstEntry;
ts_Task *pstTask;
int i, iCnt;
if( (g_pstCurrentTask->iPid == iPid) || (iPid == -1) )
return ( g_pstCurrentTask );
if( iPid == 1 )
return( g_pstIdleTask );
// Look in every queues.
for( i = 0; i < CountOfArray( appstQueue ); i++) {
/*
#define queue_for_each( pos, c, head ) \
if( (head) != NULL ) \
for( pos = (head), c = 0, prefetch(pos->next); \
(pos != (head)) || !(c); \
pos = pos->next, prefetch(pos->next), ++c )
*/
//queue_for_each( entry, n, *(q[i]) )
if( *(appstQueue[i]) != NULL ) {
for( pstEntry = *(appstQueue[i]), iCnt=0;
(pstEntry != *(appstQueue[i])) || !iCnt; pstEntry = pstEntry->pstNext, ++iCnt ) {
pstTask = (ts_Task*)pvGetQueueEntry(pstEntry);
if( pstTask->iPid == iPid )
goto lbl_founded;
}
}
}
pstTask = NULL;
kprintf("%s:%d, can't find task by pid, %s", __FUNCTION__, __LINE__, __FILE__);
lbl_founded:
return (pstTask);
}
/************************************************************
*************************************************************
** Function Name: vMt5TaskSleep
** Author: x.cheng
**
** Comment:
** Sleep a process if it is awake.
**
** List of parameters:
** pstTask - The structure of the task to sleep.
**
** Return value:
** no
**
** Revisions:
**
*************************************************************
*************************************************************/
void vMt5TaskSleep(ts_Task **ppstTask)
{
ts_Task *pstTemp;
if ( !ppstTask )
return;
pstTemp = (*ppstTask);
if ( !(*ppstTask) )
(*ppstTask) = g_pstCurrentTask;
if ( (*ppstTask)->ucState != TASK_STATE_WAIT ) {
#ifdef _DEBUG__
#ifdef _DEBUG_MTS__
kprintf("%s-%d lines|%s(): sleep= [%s]\n", __FILE__, __LINE__, __FUNCTION__, (*ppstTask)->szName);
#endif
#endif
do {
(*ppstTask)->ucState = TASK_STATE_WAIT;
vMt3RefreshQueues();
}while(0);
}
// vMt5PrintProcessInfo();
vMt3Schedule();
/*
if ( pstTemp ) {
pstTemp->ucState = TASK_STATE_READY;
vMt3RefreshQueues();
}
*/
}
/************************************************************
*************************************************************
** Function Name: vMt5TaskWakeup
** Author: x.cheng
**
** Comment:
** Wakeup a process if it is sleeping.
**
** List of parameters:
** pstTask - The structure of the task to wake up.
**
** Return value:
** no
**
** Revisions:
**
*************************************************************
*************************************************************/
void vMt5TaskWakeup( ts_Task *pstTask )
{
if ( pstTask == NULL )
return;
if ( pstTask->ucState != TASK_STATE_READY ) {
#ifdef _DEBUG__
#ifdef _DEBUG_MTS__
kprintf("%s-%d lines|%s(): wakeup= [%s]\n", __FILE__, __LINE__, __FUNCTION__, (pstTask)->szName);
#endif
#endif
do {
pstTask->ucState = TASK_STATE_READY;
vMt3RefreshQueues();
}while(0);
}
// vMt5PrintProcessInfo();
// vMt3Schedule();
}
/************************************************************
*************************************************************
** Function Name: vMt5WakeupWaitQueue
** Author: x.cheng
**
** Comment:
** Wakeup a process if it is sleeping.
**
** List of parameters:
** pstTask - The structure of the task to wake up.
**
** Return value:
** no
**
** Revisions:
**
*************************************************************
*************************************************************/
void vMt5WakeupWaitQueue(ts_WaitQueueNode *pstWaitQueue )
{
unsigned long ulFlags;
ts_Task *pstTask;
int iPid;
ts_QueueNode *pstEntry, *pstDummy;
int iCnt;
SpinlockDisableIrqAndLock( &(pstWaitQueue->stLock), ulFlags );
// Mt5BrowserQueue(&pstWaitQueue, "WaitQueue");
/*
#define queue_for_each_safe( pos, n, c, head ) \
if( (head) != NULL ) \
for( pos = (head), n = pos->pstNext, \
c = count_queue( &(head) ); \
c--; \
pos = n, n = pos->pstNext )
*/
// queue_for_each_safe( entry, dummy, n, waitq->list )
if ( pstWaitQueue->pstListHead != NULL ) {
for ( pstEntry = pstWaitQueue->pstListHead, pstDummy = pstEntry->pstNext, iCnt = iCountQueueElement( &pstWaitQueue->pstListHead );
iCnt--; pstEntry = pstDummy, pstDummy = pstEntry->pstNext ) {
iPid = (int)pvGetQueueEntry( pstEntry );
pstTask = pstMt5GetTaskInfo( iPid );
if ( pstTask != NULL ) {
vMt5TaskWakeup( pstTask );
}
iDeleteQueueNode( &(pstWaitQueue->pstListHead), pstEntry);
}
}
SpinlockEnableIrqAndUnlock( &(pstWaitQueue->stLock), ulFlags );
// VmmKeDumpHeapStatus();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -