linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: about kernel_thread!
  2004-12-13 13:52 about kernel_thread! Zhenyu Wu
@ 2004-12-13 13:25 ` linux-os
  0 siblings, 0 replies; 6+ messages in thread
From: linux-os @ 2004-12-13 13:25 UTC (permalink / raw)
  To: Zhenyu Wu; +Cc: quade, linux-kernel

On Mon, 13 Dec 2004, Zhenyu Wu wrote:

> Oh, my god. I find another problem, my linux kernel is 2.4.20, and i can't find
> the function allow_signal at all. BTW, whether there is such funcion in kernel
> 2.4.20?
>
> Thanks,
> Zhenyu Wu
>

Normally we do our own work... However, if you understand macros,
these might help you.


//
//  Copyright(c)  2004  Analogic Corporation
//
//
//  This program may be distributed under the GNU Public License
//  version 2, as published by the Free Software Foundation, Inc.,
//  59 Temple Place, Suite 330 Boston, MA, 02111.
//
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

#ifndef _CONFIG_H_
#define _CONFIG_H_
//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
//
//  Below are macros to handle different kernel versions.
//
#ifndef IRQ_HANDLED
#define IRQ_HANDLED 
typedef void irqreturn_t;
#endif

#ifdef KVER6
#define REMAP(a,b,c,d,e) remap_page_range((a), (b), (c), (d), (e))
#define __io_virt(p) ((void *)(p))
#define DAEMONIZE             \
     daemonize("%s", devname); \
     allow_signal(SIGTERM)
#define PCI_FIND_DEVICE(a,b,c) pci_get_device((a),(b),(c))
#else
#define lock_kernel()
#define unlock_kernel()
#define REMAP(a,b,c,d,e) remap_page_range((b), (c), (d), (e))
#define DAEMONIZE                          \
     exit_files(current);                   \
     daemonize();                           \
     spin_lock_irq(&current->sigmask_lock); \
     sigemptyset(&current->blocked);        \
     recalc_sigpending(current);            \
     spin_unlock_irq(&current->sigmask_lock)
#define PCI_FIND_DEVICE(a,b,c) pci_find_device((a),(b),(c))
#endif
#endif


Cheers,
Dick Johnson
Penguin : Linux version 2.6.9 on an i686 machine (5537.79 BogoMips).
  Notice : All mail here is now cached for review by John Ashcroft.
                  98.36% of all statistics are fiction.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: about kernel_thread!
@ 2004-12-13 13:52 Zhenyu Wu
  2004-12-13 13:25 ` linux-os
  0 siblings, 1 reply; 6+ messages in thread
From: Zhenyu Wu @ 2004-12-13 13:52 UTC (permalink / raw)
  To: quade; +Cc: linux-kernel

Oh, my god. I find another problem, my linux kernel is 2.4.20, and i can't find
the function allow_signal at all. BTW, whether there is such funcion in kernel
2.4.20?

Thanks,
Zhenyu Wu


>From: Juergen Quade <quade@hsnr.de>
>Reply-To: 
>To: Zhenyu Wu <y030729@njupt.edu.cn>
>Subject: Re: about kernel_thread!
>Date:Mon, 13 Dec 2004 13:44:26 +0100
>
>On Mon, Dec 13, 2004 at 09:12:39PM +0800, Zhenyu Wu wrote:
> > Hello, 
> > 
> > I have some confusions on kernel_thread, so I want to get help.
> > 
> > I want to create a thread in a loadable module, then I used the function
> > kernel_thread() in init_module(). Of course, the thread was created, but when
I
> > remove the module there are errors. I think it is because of the thread I
have
> > created that have not been killed. So, how can I kill this thread when I
remove
> > the module?
> 
> You can find sample-code here:
> http://ezs.kr.hsnr.de/TreiberBuch/Download/TreiberEntwickeln2004261/6-9-kthread.c
> 
>        Juergen.
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
>



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: about kernel_thread!
@ 2004-12-13 13:36 Zhenyu Wu
  0 siblings, 0 replies; 6+ messages in thread
From: Zhenyu Wu @ 2004-12-13 13:36 UTC (permalink / raw)
  To: linux-os; +Cc: linux-kernel

> You copy the method used in other kernel modules. This involves
> a semaphore and having the module removing routine send the task
> a signal. FYI, there is a wait_for_completion() routine and a
> complete_and_exit() routine already defined.

Thank you, my kernel version is 2.4.20. If i use return to terminate the thread,
then i can remove the module without errors, but if not, there are still errors,
Below is my simple test:

#define __KERNEL__ 
#define MODULE 
#include <linux/kernel.h> 
#include <linux/module.h> 
#include <linux/sched.h> 
#include <linux/spinlock.h> 
static int child(void *para) 
{ 
DECLARE_WAIT_QUEUE_HEAD(child_wait); 
int ret; 
struct task_struct *tsk = current; 
daemonize(); 
printk("child's pid =%d\n",tsk->pid); 
sprintf(tsk->comm,"%s","child"); 
for (;;) { 
static long recalc = 0,limit = 0; 
if (time_after(jiffies, recalc + 5*HZ)) { 
recalc = jiffies; 
printk("%s,pid=%d\n",(char*)para,tsk->pid); 
if(limit++ == 5) {                        // if limit ==5, break, then return
will
                                          //terminate this thread
break; 
} 
} 
interruptible_sleep_on_timeout(&child_wait,5*HZ); 
} 
return 0; 
} 
int init_module(void) 
{ 
int ret; 
printk("insmod's pid =%d\n",current->pid); 
ret = kernel_thread(child,"child",0);        //I create a thread here 
return 0; 
} 
int cleanup_module() 
{ 
return 0; 
} 




^ permalink raw reply	[flat|nested] 6+ messages in thread

* about kernel_thread!
@ 2004-12-13 13:12 Zhenyu Wu
  2004-12-13 12:31 ` linux-os
  2004-12-13 12:44 ` Juergen Quade
  0 siblings, 2 replies; 6+ messages in thread
From: Zhenyu Wu @ 2004-12-13 13:12 UTC (permalink / raw)
  To: linux-kernel

Hello, 

I have some confusions on kernel_thread, so I want to get help.

I want to create a thread in a loadable module, then I used the function
kernel_thread() in init_module(). Of course, the thread was created, but when I
remove the module there are errors. I think it is because of the thread I have
created that have not been killed. So, how can I kill this thread when I remove
the module?

Thanks,



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: about kernel_thread!
  2004-12-13 13:12 Zhenyu Wu
  2004-12-13 12:31 ` linux-os
@ 2004-12-13 12:44 ` Juergen Quade
  1 sibling, 0 replies; 6+ messages in thread
From: Juergen Quade @ 2004-12-13 12:44 UTC (permalink / raw)
  To: Zhenyu Wu; +Cc: linux-kernel

On Mon, Dec 13, 2004 at 09:12:39PM +0800, Zhenyu Wu wrote:
> Hello, 
> 
> I have some confusions on kernel_thread, so I want to get help.
> 
> I want to create a thread in a loadable module, then I used the function
> kernel_thread() in init_module(). Of course, the thread was created, but when I
> remove the module there are errors. I think it is because of the thread I have
> created that have not been killed. So, how can I kill this thread when I remove
> the module?

You can find sample-code here:
http://ezs.kr.hsnr.de/TreiberBuch/Download/TreiberEntwickeln2004261/6-9-kthread.c

       Juergen.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: about kernel_thread!
  2004-12-13 13:12 Zhenyu Wu
@ 2004-12-13 12:31 ` linux-os
  2004-12-13 12:44 ` Juergen Quade
  1 sibling, 0 replies; 6+ messages in thread
From: linux-os @ 2004-12-13 12:31 UTC (permalink / raw)
  To: Zhenyu Wu; +Cc: linux-kernel

On Mon, 13 Dec 2004, Zhenyu Wu wrote:

> Hello,
>
> I have some confusions on kernel_thread, so I want to get help.
>
> I want to create a thread in a loadable module, then I used the function
> kernel_thread() in init_module(). Of course, the thread was created, but when I
> remove the module there are errors. I think it is because of the thread I have
> created that have not been killed. So, how can I kill this thread when I remove
> the module?
>
> Thanks,
>

You copy the method used in other kernel modules. This involves
a semaphore and having the module removing routine send the task
a signal. FYI, there is a wait_for_completion() routine and a
complete_and_exit() routine already defined.


Cheers,
Dick Johnson
Penguin : Linux version 2.6.9 on an i686 machine (5537.79 BogoMips).
  Notice : All mail here is now cached for review by John Ashcroft.
                  98.36% of all statistics are fiction.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2004-12-13 13:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-12-13 13:52 about kernel_thread! Zhenyu Wu
2004-12-13 13:25 ` linux-os
  -- strict thread matches above, loose matches on Subject: below --
2004-12-13 13:36 Zhenyu Wu
2004-12-13 13:12 Zhenyu Wu
2004-12-13 12:31 ` linux-os
2004-12-13 12:44 ` Juergen Quade

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).