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.


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.


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;

    rcvid = MsgReceive(chid,buffer,64, NULL);


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");

coid = ConnectAttach(0,getpid(),chid, _NTO_SIDE_CHANNEL,0);
if (coid < 0)
    fprintf(stderr,"ConnectAttach failure\n");
pthread_create(NULL, NULL, child_thread, &arg);
    ret = MsgSend(coid,"A",1,NULL,0);
    if (ret < 0)
        fprintf(stderr,"MsgSend Failure\n");
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)));