Warning: This post contains only kindergarten level techniques about Linux kernel.
I met a problem that a real-time user space program with many threads has higher priority than my computation intensive kernel thread.
I have to adjust the priority of this kernel thread. But unfortunately, I found that the kthread_run doesn't provide me any way to set the priority of my kernel thread. So I wondered how to do it? Fortunately, I found the way to set the priority of a kernel thread. Using
struct sched_param param;
param.sched_priority =
if (sched_setscheduler(current, SCHED_FIFO, ¶m) != 0)
printk("set scheduler and its priority failed\n");
This effectively sets the process's scheduler to FIFO and priority to
However, when I try insmod
If you are a newbie like me, you might be scratching your head or starts gazing the ceiling and think, why?
After one hour of trying, I eventually noticed in sched.c, after the function body is declared
int sched_setscheduler(struct task_struct *p, int policy,
struct sched_param *param)
{
...
}
EXPORT_SYMBOL_GPL(sched_setscheduler);
The key is EXPORT_SYMBOL_GPL limits the functions to be linked by modules using GPL.
And my module just didn't contain any license statement. So I added
MODULE_LICENSE("GPL");
Now, everything works like a charm!