What is the context switching time in qnx

Hello all,

What is the context switching time in QNX?

How can we calculate the context switching time.

Thanks
Gunjan

Context switching in QNX is very fast and variable depending on things like processor speed.
In a multi-core system you get better times if the process thread can stay on the same processor, something the scheduler is supposed to try to accomplish.

There are benchmark programs around that calculate this, but I’m not sure where.
As a rough estimate, you could have a client in a loop, send 1 byte to a server program and get an immediate reply.
Note that process context switching and thread context switching are different.

It’s impossible to calculate, way to many variables involved. It can be measure though, checking for maximum, minimum and average.

As Maschoen mentioned there are plenty of source code available out there.

QNX has measured this for a number of systems and has published their benchmarks results.

qnx.com/download/group.html?programid=7963

Thanks all
for your quick inputs

@ Maschoen : can i have any one of them,if you can.
It would be a greatful to me.
I am unable to get any one of them.

This program assumes you are using two processors. Otherwise multiply the result by 2.

This is a rough measurement of thread context switching.

#include <libc.h>
#include <sys/neutrino.h>
#define ITERATIONS 5000000

int chid;
int coid;

void *child_thread(void *arg)
{
char buffer[64];
int rcvid;

while(1)
{
    rcvid = MsgReceive(chid,buffer,64, NULL);
    MsgReply(rcvid,0,NULL,0);
}

}

int main()
{
int arg;
int ret;
int i;
time_t time_1, time_2;

fprintf(stderr,"Context Switch Benchmark for QNX 6\n");
chid = ChannelCreate(0);
if (chid < 0)
{
    fprintf(stderr,"ChannelCreate failure\n");
    exit(-1);
}

coid = ConnectAttach(0,getpid(),chid, _NTO_SIDE_CHANNEL,0);
if (coid < 0)
{
    fprintf(stderr,"ConnectAttach failure\n");
    exit(-1);
}
pthread_create(NULL, NULL, child_thread, &arg);
time(&time_1);
for(i=0;i<ITERATIONS;i++)
{
    ret = MsgSend(coid,"A",1,NULL,0);
    if (ret < 0)
    {
        fprintf(stderr,"MsgSend Failure\n");
        exit(-1);
    }
}
time(&time_2);
fprintf(stderr,"%d switches in %d seconds\n",ITERATIONS,time_2-time_1);
fprintf(stderr,"%f switches per second\n",
    ((double) ITERATIONS)/ ((double)(time_2-time_1)));

}