Hi everyone,
Attached is a small sample multithreaded test app.
When I run this with a 2.6.21-rt3 on powerpc (MPC5200), the handler
fires the first three times and then the shell hangs (no stack on the
serial console as well). I cannot telnet into the device anymore, but
however the kernel responds to ping requests.
I ran the same test on a x86 non-rt kernel 2.6.20 and that seems to
work ok. Is there something I am doing wrong in there ?
regards
/prady
--
htp://prady.livejournal.com
#include <sys/types.h>
#include <sys/signal.h>
#include <sys/errno.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <pthread.h>
void sig_handler(sigval_t sig );
void* threadFunc(void* p);
int main()
{
struct itimerspec ts;
struct sigevent evp;
timer_t t_id;
pthread_attr_t pt_attrib;
struct sched_param sc_param;
sc_param.sched_priority = 30;
pthread_attr_init( &pt_attrib );
pthread_attr_setschedpolicy( &pt_attrib, SCHED_FIFO );
pthread_attr_setschedparam( &pt_attrib, &sc_param );
//pthread_attr_setdetachstate(&pt_attrib,PTHREAD_CREATE_DETACHED);
pthread_attr_setinheritsched(&pt_attrib, PTHREAD_EXPLICIT_SCHED);
memset(&evp, 0, sizeof(struct sigevent));
evp.sigev_notify = SIGEV_THREAD;
evp.sigev_notify_function = sig_handler;
evp.sigev_notify_attributes = &pt_attrib;
struct sched_param param;
int policy;
/*
param.sched_priority = 30;
if( sched_setscheduler(0, SCHED_FIFO, ¶m) )
{
perror("sched_setscheduler");
}
*/
pthread_getschedparam ( pthread_self(), &policy, ¶m);
printf("Hi, I'm main. My self is %d, and my pri is %d, policy=%d\n", (int)pthread_self(), param.sched_priority , policy);
pthread_t tID;
if( timer_create( CLOCK_REALTIME, &evp, &t_id ) )
{
perror("timer_create");
}
ts.it_interval.tv_sec = 1;
ts.it_interval.tv_nsec = 0;
ts.it_value.tv_sec = 1;
ts.it_value.tv_nsec = 0;
timer_settime( t_id, 0, &ts, NULL);
pthread_create( &tID, NULL, threadFunc, NULL);
for(;;)
pause();
}
void sig_handler(sigval_t signo)
{
struct sched_param param;
int policy;
pthread_getschedparam ( pthread_self(), &policy, ¶m);
printf("Hi, I'm sig_handler. My self is %d, and my pri is %d, policy=%d\n", (int)pthread_self(), param.sched_priority , policy);
}
void* threadFunc(void* p)
{
struct sched_param param;
printf("I'm %d\n",(int)pthread_self() );
usleep(3*1000*1000);
memset(¶m, 0, sizeof(struct sched_param));
param.sched_priority = 10;
if( sched_setscheduler(0, SCHED_FIFO, ¶m) )
{
perror("sched_setscheduler");
}
for(;;)
{
//Waste cpu
}
return NULL;
}