Re: Infinite Loop in Kernel

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Apr 13, 2009 at 10:34 PM, Bill Jones <bfjones77@xxxxxxxxx> wrote:
> I created some code in the kernel that loops until some condition becomes
> true, i.e.
> while(!condition) { //do nothing}

precisely, in what context do you create such busy loop? BTW, busy
loop is discouraged in any way.... try to change that code into
blocking code that periodically wake up to see if certain condition is
met...

> Now, in userspace, I created a bunch of threads using pthreads, some of
> which will change that condition to be true (by making a system call that
> will change its value in the kernel). However, when I run this code, my
> entire computer freezes up and continues to loop to infinity.
>
> This does not fit my understanding of how userspace->kernel threads and the
> scheduler works (I am using 2.6.28 kernel). I was under the impression that
> when I created a userspace thread using pthreads, the kernel would
> implicitly create a kernel thread for each of these. Now, the scheduler will
> eventually context switch out the kernel thread when its time quanta runs
> out, so there should never be the possibility for this loop to sit on the
> CPU forever and not allow anything else to run.
>
> What part of my reasoning above is flawed?

it's not completely wrong...  the thing is, do you what preemption
model is used in your kernel? if the current active kernel is not
using full preemption mode, then there's a chance the scheduler can
not reschedule your busy loop. Why? because in non full preemption
mode, preemption only happens during kernel-to-user mode transition or
certain spots in kernel code path.

There's also a chance you're doing busy loop while interrupt is
disabled.... many possibilities here. Try to check more carefully

regards,

Mulyadi.

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux