'It seems scheduling not happen?

I may misunderstand but it looks scheduling is not happening. I created a Kernel module and created a Kernel thread in the module.

I expect "point-A" will be printed after scheduling since the monitor_main thread is set to TASK_INTERRUPTIBLE.

When I loaded the module, I saw the message "entry -- monitor_main" is printed. But, I couldn't see "point-A" printed at all. It seems I may miss something or misunderstand. Can someone add some comment on this? It will be very helpful!

Here is the code.

#include <linux/module.h>
#include <linux/kmod.h>
#include <linux/kthread.h>
#include <linux/time.h>
#include <linux/timer.h>
#include <linux/delay.h>

DECLARE_WAIT_QUEUE_HEAD(monitor_wait_q);
rwlock_t monitor_lock = RW_LOCK_UNLOCKED;
int monitor_event_id = 1;

int monitor_main(void)
{
   int event_id = 0;

   printk("entry -- monitor_main\n");
   DECLARE_WAITQUEUE(monitor_wait, current);
   daemonize("monitor_main");

   allow_signal(SIGKILL);
   add_wait_queue(&monitor_wait_q, &monitor_wait);

   for(;;)
   {
      set_current_state(TASK_INTERRUPTIBLE);
      schedule();
      printk("point-A\n");

      if (signal_pending(current))
      {
         break;
      }

      read_lock(&monitor_lock);
      if (monitor_event_id)
      {
         event_id = monitor_event_id;
         read_unlock(&monitor_lock);

         printk("event occurred\n");
      }
      else
      {
         read_unlock(&monitor_lock);
      }
   }

   set_current_state(TASK_RUNNING);
   remove_wait_queue(&monitor_wait_q, &monitor_wait);
   return 0;
}

static int __init init_activity_monitor(void)
{
   int ret;
   
   printk("Hello - init_activity_monitor\n");
   ret = kernel_thread(monitor_main, NULL, CLONE_FS | CLONE_FILES | CLONE_SIGHAND | SIGCHLD);
   if (ret < 0)
   {
      printk("failed to start kernel thread\n");
   }
   msleep(2);
   wake_up_interruptible(&monitor_wait_q);
   return 0;
}
module_init(init_activity_monitor);

static void __exit exit_activity_monitor(void)
{
   printk("Bye - exit_activity_monitor\n");
}
module_exit(exit_activity_monitor);


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source