All of lore.kernel.org
 help / color / mirror / Atom feed
From: moon.linux@yahoo.com (Anand Moon)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Kernel thread scheduling
Date: Sat, 21 Mar 2015 06:33:31 +0000 (UTC)	[thread overview]
Message-ID: <508921156.2279151.1426919611846.JavaMail.yahoo@mail.yahoo.com> (raw)
In-Reply-To: <4E5779AD88B2F040B8A7E83ECF544D1A5C7240@SJCPEX01CL03.citrite.net>

Hi Jeff,

kernel_thread just like daemon process. These are self monitoring process.


These process get scheduled by the kernel when their is any state change
from TASK_INTERRUPTIBLE to TASK_RUNNING or their is some condition that get full field.

If you don't schedule() the kernel thread state is not get updated by the scheduler.


Below example can help clear the concept.


http://lxr.free-electrons.com/source/drivers/vhost/vhost.c#L225


-Anand Moon


On Saturday, March 21, 2015 4:58 AM, Jeff Haran <Jeff.Haran@citrix.com> wrote:
-----Original Message-----
From: kernelnewbies-bounces@kernelnewbies.org [mailto:kernelnewbies-bounces at kernelnewbies.org] On Behalf Of Vincenzo Scotti
Sent: Friday, March 20, 2015 4:20 PM
To: kernelnewbies at kernelnewbies.org
Subject: Kernel thread scheduling

Hello,
I am actually studying kernel threads, and I have some doubts about them.
Let's take for example this snippet of code

static int thread_function(void *data)
{
    while (!kthread_should_stop()) {
        schedule();
    }

    pr_err("Stopped");
    return 0;
}

This way it works just fine, and waits until I call kthread_stop on it.
But if I comment out that schedule() call, it just hangs my system when I load it (it is part of a module). I see that the loop-schedule-wakeup pattern is used among all the others kernel threads. But I don't get why I need to call the scheduler explicitly.
I know that the kernel is fully preemptible, and in my interpretation I thought that it could stop every running thread, even in kernel space, using a timer-based interrupt handler, to give cpu to other threads. Doesn't this pattern resemble a voluntary preemption model?

Where am I wrong?

Are you sure your kernel is configured with kernel preemption on? It is a configurable option. Grep for PREEMPT in your .config file.

Jeff


_______________________________________________
Kernelnewbies mailing list
Kernelnewbies at kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

  reply	other threads:[~2015-03-21  6:33 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-20 23:19 Kernel thread scheduling Vincenzo Scotti
2015-03-20 23:27 ` Jeff Haran
2015-03-21  6:33   ` Anand Moon [this message]
2015-03-22 23:14     ` Vincenzo Scotti
2015-03-22 23:30       ` nick
2015-03-23  0:05         ` Ruben Safir
2015-03-23  0:35           ` nick
2015-04-10  1:51             ` Ruben Safir
     [not found]               ` <55272EA8.7010908@gmail.com>
2015-04-10  2:12                 ` Ruben Safir
2015-04-10  2:52                   ` nick
2015-04-10  3:37                     ` Ruben Safir
     [not found]                       ` <5527CB72.1000401@gmail.com>
2015-04-12  2:21                         ` Ruben Safir
2015-04-12  3:02                           ` Ruben Safir
2015-04-12  4:16                             ` nick
2015-04-12  4:53                               ` Ruben Safir
     [not found]                               ` <A2417C6E7F04A0438F09C31B33A6BE8B01D9CE3BE7@B-EXH-MBX2.liunet.edu>
2015-04-12  5:06                                 ` Ruben Safir
2015-04-13  3:21                                   ` nick
2015-04-17 13:10                                 ` Ruben Safir
2015-04-17 13:14                                 ` Ruben Safir
2015-04-16 14:56                     ` Ruben Safir
2015-04-16 15:07                       ` Ricardo Ribalda Delgado
2015-04-16 15:11                         ` Ruben Safir
2015-04-16 15:12                         ` Ruben Safir
2015-04-16 15:51                           ` Ricardo Ribalda Delgado
2015-04-16 15:10                       ` Aruna Hewapathirane
2015-04-16 15:37                         ` Ruben Safir
2015-04-16 15:11                       ` Mark P
2015-04-16 16:31                         ` Jeff Haran
2015-04-16 17:08                           ` Ruben Safir
2015-04-16 17:34                             ` Jeff Haran
2015-04-16 18:28                               ` Ruben Safir
2015-04-16 18:47                                 ` Valdis.Kletnieks at vt.edu
2015-04-16 21:41                                   ` Jeff Haran
2015-04-17  7:45                                     ` Silvan Jegen
2015-04-17  8:50                                     ` Ruben Safir
2015-04-16 23:05                                   ` Ruben Safir
2015-04-16 18:32                       ` John de la Garza
2015-04-16 18:38                         ` Ruben Safir
2015-04-16 18:42                         ` Ruben Safir
2015-04-16 19:43                           ` Silvan Jegen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=508921156.2279151.1426919611846.JavaMail.yahoo@mail.yahoo.com \
    --to=moon.linux@yahoo.com \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.