Dear All,
Iam trying to find the time taken by thread1 from sending a message to
receiving message from thread2.
I used rt_timer_tsc to get the tics underlying hardware .
Started the timer before thread1 sends message . (got the start tics)
ended the timer when thread1 receives the message . (got the current tics)
And i substracted current tics - start tics
and Iam getting some 0.9 to 1.5 after converting to nanoseconds and
multiplying with 1e-6 . I would like to know that this process of getting
time and the way i done
is correct or not ?
Thanks
Suresh balijepalli
Rosenehim,Baveria.
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <sys/mman.h>
#include <stdlib.h>
#include <native/task.h>
#include <native/timer.h>
#include <native/sem.h>
#include <native/mutex.h>
#include <native/queue.h>
#include <rtdk.h>
#define NTASKS 2
#define QUEUE_SIZE 255
#define MAX_MESSAGE_LENGTH 40
RT_TASK task_struct[NTASKS];
#define QUEUE_SIZE 255
RT_QUEUE myqueue;
RT_QUEUE myqueue1;
void taskOne(void *arg)
{
int retval,retval1,n;
int i=1000;
char * buffer;
char a[]="a" ;
char message[] = "Message from taskOne";
char msgBuf1[MAX_MESSAGE_LENGTH];
RTIME start_tsc = rt_timer_tsc();
rt_printf("starting tics: %.3f\n",
rt_timer_tsc2ns(start_tsc)*1e-6);
buffer = (char*) malloc (i+1);
if (buffer==NULL) exit (1);
for (n=0; n<i; n++)
{
buffer[n]=a;
rt_printf("a\n",buffer[n]);
}
free (buffer);
/* send message */
retval = rt_queue_write(&myqueue,message,sizeof(message),Q_NORMAL);
if (retval < 0 ) {
rt_printf("Sending error\n");
} else {
rt_printf("taskOne sent message to mailbox\n");
}
/* receive message */
retval1 =rt_queue_read(&myqueue1,msgBuf1,sizeof(msgBuf1),TM_INFINITE);
if (retval1 < 0 ) {
rt_printf("Receiving error\n");
} else {
rt_printf("task1 received message: %s\n",msgBuf1);
rt_printf("with length %d\n",retval1);
}
RTIME tsc=rt_timer_tsc();
rt_printf("end tics: %.3f\n",
rt_timer_tsc2ns(tsc)*1e-6);
rt_printf("with length");
rt_printf("Total time: %.3f\n",
rt_timer_tsc2ns(tsc-(start_tsc))*1e-6);
}
void taskTwo(void *arg)
{
int retval,retval1;
char msgBuf[MAX_MESSAGE_LENGTH];
char message1[] = "Message from tasktwo";
/* receive message */
retval = rt_queue_read(&myqueue,msgBuf,sizeof(msgBuf),TM_INFINITE);
if (retval < 0 ) {
rt_printf("Receiving error\n");
} else {
rt_printf("taskTwo received message: %s\n",msgBuf);
rt_printf("with length %d\n",retval);
}
/* send message */
retval1 = rt_queue_write(&myqueue1,message1,sizeof(message1),Q_NORMAL);
if (retval1 < 0 ) {
rt_printf("Sending error\n");
} else {
rt_printf("tasktwo sent message to mailbox\n");
}
}
//startup code
void startup()
{
int i;
char str[10] ;
void (*task_func[NTASKS]) (void *arg);
task_func[0]=taskOne;
task_func[1]=taskTwo;
rt_queue_create(&myqueue,"myqueue",QUEUE_SIZE,10,Q_FIFO);
rt_queue_create(&myqueue1,"myqueue1",QUEUE_SIZE,10,Q_FIFO);
rt_timer_set_mode(0);// set timer to tick in nanoseconds and not in jiffies
for(i=0; i < NTASKS; i++) {
rt_printf("start task : %d\n",i);
sprintf(str,"task%d",i);
rt_task_create(&task_struct[i], str, 0, 50, 0);
rt_task_start(&task_struct[i], task_func[i], &i);
}
}
void init_xenomai() {
/* Avoids memory swapping for this program */
mlockall(MCL_CURRENT|MCL_FUTURE);
/* Perform auto-init of rt_print buffers if the task doesn't do so */
rt_print_auto_init(1);
}
int main(int argc, char* argv[])
{
printf("\nType CTRL-C to end this program\n\n" );
// code to set things to run xenomai
init_xenomai();
//startup code
startup();
pause();
}
_______________________________________________
Xenomai-help mailing list
[email protected]
https://mail.gna.org/listinfo/xenomai-help