Hi Thomas,
Quoting Thomas Gleixner <tglx@xxxxxxxxxxxxx>:
please use short and descriptive subject lines. "I attached a test
module to reproduce this bug ..." does not tell anything.
On Mon, 12 Apr 2010, Stefan Agner wrote:
Unable to handle kernel paging request at kthread_should_stop
That would have been the real subject line :)
In fact this was my intended Subject line... The current subject line was a
copy and paste accident! Due to the fact that my online mailer eats mails
sometimes before I can send them, I wrote it in an editor.
I attached a test module to reproduce this bug. Does I miss something in my
code or is there a bug?
There are several bugs in your code :)
static int runloop(void *unused)
{
int ret;
/* Daemonize */
daemonize(MODULE_NAME);
Do not call daemonize() for a kthread created with kthread_create().
That was necessary for kthreads created with kernel_thread.
Removing this already solved the bug message.
I fixed all other bugs as well and attached the updated file.
Thanks a lot
--
Stefan Agner
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
#include <linux/module.h>
#include <linux/kthread.h>
#include <linux/hrtimer.h>
#define THREAD_PRIORITY (80)
#define THREAD_SCHEDULER SCHED_FIFO
#define MODULE_NAME "test-module"
#define KLOG_PREFIX MODULE_NAME ": "
struct task_struct *thread;
static ktime_t thread_next;
static ktime_t now;
/*
* Threaded Runloop
*/
static int runloop(void *unused)
{
struct sched_param param = { .sched_priority = THREAD_PRIORITY };
/* Set realtime priorty */
sched_setscheduler(thread, THREAD_SCHEDULER, ¶m);
/* Allow SIGTERM signal */
allow_signal(SIGTERM);
/* Calculate first shot */
now = ktime_get();
thread_next = ktime_add_us(now, 500);
do {
set_current_state(TASK_UNINTERRUPTIBLE);
schedule_hrtimeout(&thread_next, HRTIMER_MODE_ABS);
thread_next = ktime_add_us(thread_next, 500);
} while (!kthread_should_stop());
printk(KERN_INFO KLOG_PREFIX "Thread exited\n");
return 0;
}
int __init init_test_module(void)
{
/* Create kernel thread */
thread = kthread_run((void *)&runloop, NULL, MODULE_NAME);
if (IS_ERR(thread))
{
printk(KERN_INFO KLOG_PREFIX ": unable to start kernel thread\n");
return -ENOMEM;
}
return 0;
}
void __exit cleanup_test_module(void)
{
if(thread != NULL)
kthread_stop(thread);
thread = NULL;
}
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Stefan Agner <stefan@xxxxxxxx");
MODULE_DESCRIPTION("kthread test module");
module_init(init_test_module);
module_exit(cleanup_test_module);