Re: Threads in 2.6.x kernel

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

 



hi,
   thanks to Jan for the help it worked fine i was really confused with
many data structures waitiqueue/wokqueue/taskqueue.Now I am able to create
threads.But i have some more doubts

*How shall i kill the thread i created with kernel_thread
      I tried using
            send_sig(SIGKILL,thread_task,1);
            thread_task i am initialising with
            thread_task = current ;
      when the thread starts.Is it the right way of killing the thread.
But  even after killing i find the thread as <defunct> with the ps viewer
under the application using the driver.

*I am making use of
interruptible_sleep_on_timeout(thread_waitqueue,200);
inside the thread .when the thread starts i get the message

Jul 22 11:26:32 Sudharsan-Linux kernel: Badness in
interruptible_sleep_on_timeout at kernel/sched.c:1942
Jul 22 11:26:32 Sudharsan-Linux kernel: Call Trace:
Jul 22 11:26:32 Sudharsan-Linux kernel:  [<0227eec8>]
interruptible_sleep_on_timeout+0x5d/0xb1
Jul 22 11:26:32 Sudharsan-Linux kernel:  [<02115e97>]
default_wake_function+0x0/0xc
Jul 22 11:26:32 Sudharsan-Linux kernel:  [<021189cd>] printk+0x106/0x113
Jul 22 11:26:32 Sudharsan-Linux kernel:  [<127fcedd>]
polling_thread+0x54/0x2aa [skull]
Jul 22 11:26:32 Sudharsan-Linux kernel:  [<02115e97>]
default_wake_function+0x0/0xc
Jul 22 11:26:32 Sudharsan-Linux kernel:  [<127fce89>]
polling_thread+0x0/0x2aa [skull]
Jul 22 11:26:32 Sudharsan-Linux kernel:  [<127fce89>]
polling_thread+0x0/0x2aa [skull]
Jul 22 11:26:32 Sudharsan-Linux kernel:  [<021041d9>]
kernel_thread_helper+0x5/0xb

I am using Fedora core 2 kernel ver 2.6.5-1.358.How to get out of this

Thanks in advance,
Sudharsanan R



On Tue, Jul 20, 2004 at 02:29:33 -0400, RSudharsanan@xxxxxxxxxxxxxx wrote:
> hi,
>    What is the simplest way to create kernel threads in 2.6.x kernel.I
got
> one for 2.4.x
> from http://www.scs.ch/~frey/linux/kernelthreads.html8

Hell, that mixes so many things that don't have anything to do with each
other.

> but the task queues are not implemented here.I suppose i have to go for

Task queues and kernel threads are one of them. They are completely
distinct things. Unfortunately it's not really obvious from that
example.

> Work queue interface
> Is it necessary first??? just for creating /stopping and killing threads.

kernel_thread() behaves exactly like clone() in userspace (but the flags
are like for fork). In fact, it calls the same code internaly. You pass
it a function that should run in it, it sets up a new task_struct
+ stack for it and runs it. When it ends, the thread exists. The thread
is a process, so it is scheduled like one (you must call schedule()
because kernel is not preemptive (2.6 can be, but may be compiled
without)). You must call kernel_thread in a process context, which
generaly means module_init(), syscall handler or another kernel thread.

Task queues are lists of functions that should be called from somewhere.
Work queues are similar, generalized.

You can use kernel threads without task/work queues and generaly it's
done so. Many modules simply spawn a kernel thread in init and the
thread then sits in a loop waiting on a wait_queue (which is
a synchronization primitive -- nothing to do with task/work queues) for
some task to do.

You can use task/work queues without kernel threads. There are many
places in kernel that run various task/work queues at different times.
There is also a generic work-queue running thread, whose services you
may use.

-------------------------------------------------------------------------------


Jan 'Bulb' Hudec <bulb@xxxxxx>
(See attached file: signature.asc)


Attachment: signature.asc
Description: Binary data


[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