I'm basically trying to figure out if my program is handled by the Linux
kernel (secondary mode) or the Xenomai kernel (primary mode) and also
figureo ut when the switch happens.
I'm running a RT (Real Time) program on BeagleBone Black with Xenomai and
trying to figure how to monitor/understand context switches (I know the
concept of context switches) so that I can determine when my program (in C
using POSIX skin) switches from primary and secondary mode.
Here's my program *main_posix.c*
#ifndef __XENO_SIM__
#ifndef __KERNEL__
#include <stdio.h>
#define xnarch_printf printf
#endif
#include <time.h>
#include <errno.h>
#include <unistd.h>
#include <signal.h>
#include <sys/mman.h>
#include <pthread.h>
#include <mqueue.h>
#else /* __XENO_SIM */
#include <posix/posix.h>
#endif /* __XENO_SIM */
void warn_upon_switch(){
printf("Switched to Secondary Mode \n");
}
void *threadFunc(void *arg)
{
char *str;
int i = 0;
struct timespec delay, sleep;
unsigned long over;
int ret;
str=(char*)arg;
printf("In thread \n");
sleep.tv_sec = 1;
sleep.tv_nsec = 0;
#ifdef __XENO__
ret = pthread_set_mode_np(0, 0x00040000);
printf("Warn Bit Ret %d\n", ret);
#endif /* __XENO__ */
// run this for some arbitrary time
while(i < 110000000 )
{
clock_nanosleep(CLOCK_REALTIME, 0, &sleep, NULL);
printf("threadFunc says: %s\n",str);
++i;
}
return NULL;
}
int main(void)
{
signal(SIGXCPU, warn_upon_switch);
signal(SIGKILL, warn_upon_switch);
pthread_t pth;
double i = 0;
int ret;
pthread_attr_t tattr;
struct sched_param sparam;
sparam.sched_priority = 99;
ret = pthread_attr_init(&tattr);
printf("Init Return Val %d\n", ret);
ret = pthread_setschedparam(pth,SCHED_FIFO, &sparam);
printf("SetSchedParam Ret Value %d\n", ret);
pthread_create(&pth,&tattr,threadFunc,"foo");
printf("main waiting for thread to terminate...\n");
pthread_join(pth,NULL);
return 0;
}
<https://lh3.googleusercontent.com/-inzmoRO-rQQ/WKKUVkEuV5I/AAAAAAAAAAM/oMx-op0nmkspA72CE7CQzo0KMmwDGWn0QCLcB/s1600/Capture.PNG>
Im also monitoring
/proc/xenomai/stat
I see that *CSW* and *MSW* for *PID* 3323 changes continuously.
<https://lh3.googleusercontent.com/-C7K-8Dt-FBA/WKKUsCgN9AI/AAAAAAAAAAQ/v8h_UdzrJjEg-BzJnQwFlOhJxUgY3vP4wCLcB/s1600/Capture2.PNG>
Here's the output of
ps -e -o class,rtprio,pri,nice,cmd | grep ./main_posix
The output of the program is as follows
<https://lh3.googleusercontent.com/-3RG9UEeZ5SE/WKKU0NanZ1I/AAAAAAAAAAU/fBJKF-pg6_E7SYrIMZ5jEyFb1JktCDRYACLcB/s1600/Capture3.PNG>
*My questions are as follows*
1. How do I know if my program is running in primary or secondary mode?
2. I get the return value of ret = pthread_setschedparam(pth,SCHED_FIFO,
&sparam); as 16which is EBUSY. Any idea why?
3. Tried catching the switch signal using signal(SIGXCPU,
warn_upon_switch);. The function never gets called.
4. If the program can be seen in Linux (meaning it gets a PID through
the Linux kernel), does it mean its running in secondary mode?
5. In proc/xenomai/stat, I see two processes for the same program. Is it
the main and the thread?
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups
"BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/beagleboard/c47ef5cd-f95d-485f-b127-7b0c94e89caf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.