kernel threads in drivers using the RT patch

From: Monica Puig-Pey
Date: Sat Jun 04 2011 - 08:30:07 EST


I'm studying how to develop drivers in a real time OS and how do they work. I'm using Ubuntu 10.04 with the 2.6.31-11-rt patch installed.
I'm trying to run a kernel thread from my driver (kernel context). I create the kthread in the module_init, I change its real time priority and then make it run .
Code shown below:

thread_handler=*(struct task_struct *)kthread_create(my_tasklet_handler, (void*)&datos,"thread_handler");
if (IS_ERR(&thread_handler)){
return PTR_ERR(&thread_handler);
printk(KERN_WARNING "<pci> (init_module) Error creating Thread handler\n");
result = sched_setscheduler(&thread_handler, SCHED_FIFO, params);

Params is global struct sched_param * and struct thread_handler a global task_struct.

I stop the Kthread in the module_exit using res=kthread_stop(&thread_handler);

The kthread "thread_handler" has a while (1) loop and it is stopped in a semaphore, waiting for the interrupt handler. When it wakes up each time it calls kthread_should_stop() and depending on that break out of the loop or run.

My problem is, when trying to establish the rtprio kthread, the whole computer get blocked and I only can restart it. If I delete this part, then kthread runs, and works well. With the ps command I can see it has a 24 NON real time priority. Then the problem come when uninstalling my module with rmmod. In the kthread_stop function, everything gets blocked.

Could someone tell what am I doing wrong? Or just give me some help about kernel threads in the RT Patch?

Thanks a lot

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at
Please read the FAQ at