Test CPU idle rate (VxWorks)

Source: Internet
Author: User
# Include "VxWorks. H"
# Include "tasklib. H"
# Include "wdlib. H"
# Include "intlib. H"

# Define deadline_time 1
# Define priority 255

Local wdog_id wdid;

Local unsigned int idlebasecount = 0;
Local unsigned int idlecount = 0;

Unsigned int g_idlepercent = 0 xffffffff;

Local void idlefuncentry (void );
Local void calculateidlehandle (void );

Unsigned int getidlepercent (void)
{
Return g_idlepercent;
}

Bool initidlefunction (void)
{
Int tid;

Idlebasecount = 0;

If (null = (wdid = wdcreate ()))
{
Perror ("cannot create idle watchdog/N ");
Return Error;
}

If (error = wdstart (wdid, sysclkrateget () * deadline_time,
(Funcptr) calculateidlehandle, 0 ))
{
Perror ("error in starting idle watchdog timer/N ");
Return Error;
}

If (error = (TID = taskspawn (char *) "idletask", priority, 0, 1024,
(Funcptr) idlefuncentry, 0, 0, 0, 0, 0, 0, 0 )))
{
Perror ("error in create idle task/N ");
Return Error;
}
Return true;
}

Local void calculateidlehandle (void)
{

If (idlebasecount = 0)
{
G_idlepercent = 0 xffffffff;
Idlebasecount = idlecount;
} Else {
G_idlepercent = (idlecount * 100)/idlebasecount;

If (g_idlepercent> 100 ){
G_idlepercent = 100;
Idlebasecount = idlecount;
}
}

Idlecount = 0;

If (error = wdstart (wdid, sysclkrateget () * deadline_time,
(Funcptr) calculateidlehandle, 0 ))
{
Perror ("error in restarting idle watchdog timer/N ");
}
}

Local void idlefuncentry (void)
{

Idlecount = 0;

While (true)
{
If (int_context ()){

} Else {

++ Idlecount;
}

Taskdelay (0 );
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.