From: Yan Zheng <yzcorp@gmail.com>
To: Fawad Lateef <fawadlateef@gmail.com>
Cc: linux-kernel@vger.kernel.org
Subject: Re: Question about the usage of kernel_thread
Date: Sat, 5 Nov 2005 20:20:41 +0800 [thread overview]
Message-ID: <7e77d27c0511050420x2bd9c5f0x@mail.gmail.com> (raw)
In-Reply-To: <1e62d1370511050331l7e71d15i7c3cdc0d153e31a6@mail.gmail.com>
>
> AFAIK the thread created like above is a true kernel thread but in
> general practice what I saw and used that by creating thread from
> init_module, the thread first call daemonize which actually drops the
> mm related to thread and then through reparent_to_init it makes init
> as a parent of the thread/process newly created. So after daemonize
> call current->mm becomes NULL and when the scheduling is going to be
> done the previous_process->mm will be used as the current->mm and
> creating thread like above is correct.
>
> --
> Fawad Lateef
> -
Thank you very much, Fawad.
I do additional test by follow codes, the result is strange.
========================================
#include <linux/kernel.h>
#include <linux/module.h>
static int noop(void *dummy)
{
int i = 0;
while(i++ < 10) {
printk("current->mm = %p\n", current->mm);
printk("current->active_mm = %p\n", current->active_mm);
set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(HZ);
}
return 0;
}
static void create_thread(void *dummy)
{
kernel_thread(noop, NULL, CLONE_KERNEL | SIGCHLD);
}
static struct work_struct work;
static int test_init(void)
{
INIT_WORK(&work, create_thread, NULL);
schedule_work(&work);
return 0;
}
/*
static int test_init(void)
{
kernel_thread(noop, NULL, CLONE_KERNEL | SIGCHLD);
return 0;
}
*/
static void test_exit(void) {}
module_init(test_init);
module_exit(test_exit);
========================================
If use kernel_thread like above. the output is:
current->mm = 00000000
current->active_mm = dffd2640
current->mm = 00000000
current->active_mm = df4d50e0
current->mm = 00000000
current->active_mm = df4463c0
current->mm = 00000000
current->active_mm = df4d50e0
current->mm = 00000000
current->active_mm = c16ee3e0
current->mm = 00000000
current->active_mm = df4463c0
current->mm = 00000000
current->active_mm = c16ee3e0
current->mm = 00000000
current->active_mm = c16ee3e0
current->mm = 00000000
current->active_mm = df796380
current->mm = 00000000
current->active_mm = c16ee3e0
if use kernel_thread directly in module_init(...). the output is:
current->mm = df988060
current->active_mm = df988060
current->mm = df988060
current->active_mm = df988060
current->mm = df988060
current->active_mm = df988060
current->mm = df988060
current->active_mm = df988060
current->mm = df988060
current->active_mm = df988060
current->mm = df988060
current->active_mm = df988060
current->mm = df988060
current->active_mm = df988060
current->mm = df988060
current->active_mm = df988060
current->mm = df988060
current->active_mm = df988060
current->mm = df988060
current->active_mm = df988060
Would you please do some explanation.
Best Regards
next prev parent reply other threads:[~2005-11-05 12:20 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-11-05 8:40 Question about the usage of kernel_thread Yan Zheng
2005-11-05 11:31 ` Fawad Lateef
2005-11-05 12:20 ` Yan Zheng [this message]
2005-11-05 12:54 ` Fawad Lateef
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=7e77d27c0511050420x2bd9c5f0x@mail.gmail.com \
--to=yzcorp@gmail.com \
--cc=fawadlateef@gmail.com \
--cc=linux-kernel@vger.kernel.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.