Skip navigation.
Home
The QNX Community Portal

View topic - What is the context switching time in qnx

What is the context switching time in qnx

For discussion of realtime and/or embedded programming.

What is the context switching time in qnx

Postby gunjansethi » Tue Feb 22, 2011 10:29 am

Hello all,

What is the context switching time in QNX?

How can we calculate the context switching time.


Thanks
Gunjan
gunjansethi
Active Member
 
Posts: 12
Joined: Wed Oct 06, 2010 10:22 am

RE: What is the context switching time in qnx

Postby maschoen » Tue Feb 22, 2011 5:27 pm

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.
maschoen
QNX Master
 
Posts: 2640
Joined: Wed Jun 25, 2003 5:18 pm

Re: What is the context switching time in qnx

Postby mario » Tue Feb 22, 2011 6:08 pm

gunjansethi wrote:Hello all,

What is the context switching time in QNX?

How can we calculate the context switching time.

Thanks
Gunjan


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.
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

RE: Re: What is the context switching time in qnx

Postby Thunderblade » Wed Feb 23, 2011 8:25 am

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

http://www.qnx.com/download/group.html?programid=7963
Thunderblade
Senior Member
 
Posts: 487
Joined: Thu Apr 07, 2005 11:52 am

Postby gunjansethi » Wed Feb 23, 2011 11:34 am

Thanks all
for your quick inputs
gunjansethi
Active Member
 
Posts: 12
Joined: Wed Oct 06, 2010 10:22 am

Postby gunjansethi » Wed Feb 23, 2011 11:39 am

@ 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.
gunjansethi
Active Member
 
Posts: 12
Joined: Wed Oct 06, 2010 10:22 am

Postby maschoen » Sat Feb 26, 2011 6:26 am

gunjansethi wrote:@ 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)));
}
maschoen
QNX Master
 
Posts: 2640
Joined: Wed Jun 25, 2003 5:18 pm


Return to Realtime and Embedded

Who is online

Users browsing this forum: No registered users and 7 guests