Determining Processor Utilization
by Byron Miller

Listing One
Null_task
{
    loop
    {
        Typically, nop code goes here, althought 
        user-specific code may be inserted here
    }
    forever     // loops until preempted by a higher priority task
}


Listing Two
(a)
null_task
{
    loop
    {
        set output pin
    }
    forever
}

(b)
task_scheduler
{
    preempt currently running task
    select highest priority task that is ready to run
    ...
    check ready task to see if it is the idle task
    if ready task is non-idle task
    {
        reset output pin
    }
    ...
}

Listing Three
task_scheduler
{
    ...
if power up sequence true
{
clear bins
reset timer counter
}
    Determine if scheduled task is idle or non-idle
    Case task idle:
    {
        stop timer counter
        calculate delta from timer counter
        sum counter delta with contents of non-idle task bin
        store results in non-idle task bin
        reset timer counter
        start timer counter
    }
    Case task non-idle:
    {
        stop timer counter
        calculate delta from timer counter
        sum counter delta with contents of idle task bin
        store results in idle task bin
        reset timer counter
        start timer counter
    ...
    }

Listing Four
task_scheduler
{
    ...
if power up sequence true
{
clear bins
reset timer counter
}
    Determine if identity of currently executing task
    stop timer counter
    calculate delta from timer counter
    sum counter delta with contents of currently executing task bin
    store results in currently executing task bin
    reset timer counter
    start timer counter
    ...
    }
}

Listing Five
/* C main() module */
int main(void)
{
   int  i;
 ...
for (;;)        /* loop forever (null task) */
   {
      if (brkflag)
         ; /* this could be "break;" which aborts RTXC */
      SET_P1;   /* macro that sets port pin 1 via xilinx */
   }
 ...
   return(1);
}

Listing Six
/* RTXC task scheduler */
static FRAME *postem(void)  /* returns with interrupts disabled */
{
 ...
    if (hipritsk->priority != NULL_TASK_PRIORITY)   
                           /* reset pin if non-idle task */
        RESET_P1;   /* macro, resets port pin 1 */
 ...
    return(hipritsk->sp);   /* exit to hipritsk via tcb.sp */
}




2


