From: Libin <huawei.libin@huawei.com>
To: Libin <huawei.libin@huawei.com>
Cc: <akpm@linux-foundation.org>, <tj@kernel.org>,
<viro@zeniv.linux.org.uk>, <eparis@redhat.com>,
<tglx@linutronix.de>, <rusty@rustcorp.com.au>,
<ebiederm@xmission.com>, <paulmck@linux.vnet.ibm.com>,
<john.stultz@linaro.org>, <mingo@redhat.com>,
<peterz@infradead.org>, <gregkh@linuxfoundation.org>,
<linux-kernel@vger.kernel.org>, <lizefan@huawei.com>,
<jovi.zhangwei@huawei.com>, <guohanjun@huawei.com>,
<zhangdianfang@huawei.com>, <wangyijing@huawei.com>
Subject: Re: [PATCH 00/14] Fix bug about invalid wake up problem
Date: Thu, 29 Aug 2013 22:08:13 +0800 [thread overview]
Message-ID: <521F55CD.8090207@huawei.com> (raw)
In-Reply-To: <1377784669-28140-1-git-send-email-huawei.libin@huawei.com>
[-- Attachment #1: Type: text/plain, Size: 577 bytes --]
On 2013/8/29 21:57, Libin wrote:
....
> 2)Test:
> I have written a test module to trigger the problem by adding some
> synchronization condition. I will post it in the form of an attachment soon.
>
> Test result as follows:
> [103135.332683] wakeup_test: create two kernel threads - producer & consumer
> [103135.332686] wakeup_test: module loaded successfully
> [103135.332692] wakeup_test: kthread producer try to wake up the kthread consumer
> [103165.299865] wakeup_test: kthread consumer have waited for 30s, indicating
> trigger an invalid wakeup problem!
>
....
[-- Attachment #2: wakeup_test.c --]
[-- Type: text/plain, Size: 3040 bytes --]
/*
* wakeup_test.c -- Linux kernel invalid wake up problem simulation test module
*
* Written By: Libin <huawei.libin@huawei.com>
*
* History
* -------
*/
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/kthread.h>
#include <linux/sched.h>
#include <linux/list.h>
#include <linux/slab.h>
#include <linux/completion.h>
#include <linux/timer.h>
#define NAME "wakeup_test"
#define WAIT_TIMEOUT HZ*30
static LIST_HEAD(product_list);
struct product_struct{
int data;
struct list_head list;
};
static struct task_struct *producer, *consumer;
static struct completion done;
static int producer_thread(void *unused)
{
struct product_struct *product;
product = (struct product_struct *)kmalloc(sizeof (struct product_struct), GFP_KERNEL);
product->data = 1;
list_add_tail(&product->list, &product_list);
wake_up_process(consumer);
printk(KERN_INFO "%s: kthread producer try to wake up the kthread consumer\n", NAME);
complete(&done); /* NOTE: added for problem trigger simulation */
while (!kthread_should_stop()){
set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(HZ);
}
printk(KERN_INFO "%s: kthread producer exit\n", NAME);
return 0;
}
static void simulate_preempted(void)
{
schedule();
}
static void wakeup_wait_timeout(unsigned long unused)
{
printk(KERN_ERR "%s: kthread consumer have waited for %ds, "
"indicating trigger an invalid wakeup problem!\n", NAME, WAIT_TIMEOUT/HZ);
}
static int consumer_thread(void *unused)
{
struct timer_list wakeup_wait_timer;
setup_timer(&wakeup_wait_timer, wakeup_wait_timeout, (unsigned long)NULL);
wait_for_completion(&done); /* NOTE: added for problem trigger simulation */
mod_timer(&wakeup_wait_timer, jiffies + WAIT_TIMEOUT);
set_current_state(TASK_INTERRUPTIBLE);
simulate_preempted(); /* NOTE: added for problem trigger simulation */
while (list_empty(&product_list)){
schedule();
set_current_state(TASK_INTERRUPTIBLE);
}
__set_current_state(TASK_RUNNING);
del_timer_sync(&wakeup_wait_timer);
if (kthread_should_stop()){
goto out;
}
if (!list_empty(&product_list)){
printk(KERN_INFO "%s: kthread consumer be woken up successfully, all right!\n", NAME);
}
while (!kthread_should_stop()){
set_current_state(TASK_INTERRUPTIBLE);
schedule_timeout(HZ);
}
out:
printk(KERN_INFO "%s: kthread consumer exit\n", NAME);
return 0;
}
static int __init wakeup_test_init(void)
{
producer = kthread_create(producer_thread, NULL, "producer");
consumer = kthread_create(consumer_thread, NULL, "consumer");
init_completion(&done);
wake_up_process(producer);
wake_up_process(consumer);
printk(KERN_INFO "%s: create two kernel threads - producer & consumer\n", NAME);
printk(KERN_INFO "%s: module loaded successfully\n", NAME);
return 0;
}
static void __exit wakeup_test_exit(void)
{
kthread_stop(producer);
kthread_stop(consumer);
printk(KERN_INFO "%s: module unloaded successfully\n", NAME);
}
module_init(wakeup_test_init);
module_exit(wakeup_test_exit);
MODULE_LICENSE("GPL");
next prev parent reply other threads:[~2013-08-29 14:11 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-08-29 13:57 [PATCH 00/14] Fix bug about invalid wake up problem Libin
2013-08-29 13:57 ` [PATCH 01/14] kthread: Fix invalid wakeup in kthreadd Libin
2013-08-30 0:20 ` Paul E. McKenney
2013-08-29 13:57 ` [PATCH 02/14] audit: Fix invalid wakeup in kauditd_thread Libin
2013-08-29 13:57 ` [PATCH 03/14] audit: Fix invalid wakeup in wait_for_auditd Libin
2013-08-29 13:57 ` [PATCH 04/14] exit: Fix invalid wakeup in do_wait Libin
2013-08-29 13:57 ` [PATCH 05/14] hrtimer: Fix invalid wakeup in do_nanosleep Libin
2013-09-12 13:33 ` Thomas Gleixner
2013-08-29 13:57 ` [PATCH 06/14] irq: Fix invalid wakeup in irq_wait_for_interrupt Libin
2013-09-12 13:36 ` Thomas Gleixner
2013-08-29 13:57 ` [PATCH 07/14] module: Fix invalid wakeup in wait_for_zero_refcount Libin
2013-08-29 13:57 ` [PATCH 08/14] namespace: Fix invalid wakeup in zap_pid_ns_processes Libin
2013-08-29 13:57 ` [PATCH 09/14] rcutree: Fix invalid wakeup in rcu_wait Libin
2013-08-30 0:23 ` Paul E. McKenney
2013-08-29 13:57 ` [PATCH 10/14] time: Fix invalid wakeup in alarmtimer_do_nsleep Libin
2013-09-12 13:36 ` Thomas Gleixner
2013-08-29 13:57 ` [PATCH 11/14] trace: Fix invalid wakeup in wait_to_die Libin
2013-08-29 13:57 ` [PATCH 12/14] trace: Fix invalid wakeup in ring_buffer_consumer_thread Libin
2013-08-29 13:57 ` [PATCH 13/14] workqueue: Fix invalid wakeup in rescuer_thread Libin
2013-08-29 13:57 ` [PATCH 14/14] klist: Fix invalid wakeup in klist_remove Libin
2013-08-29 14:08 ` Libin [this message]
2013-08-29 14:12 ` [PATCH 00/14] Fix bug about invalid wake up problem Tejun Heo
2013-08-29 14:10 ` Tejun Heo
2013-08-29 23:39 ` Libin
2013-08-30 0:18 ` Paul E. McKenney
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=521F55CD.8090207@huawei.com \
--to=huawei.libin@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=ebiederm@xmission.com \
--cc=eparis@redhat.com \
--cc=gregkh@linuxfoundation.org \
--cc=guohanjun@huawei.com \
--cc=john.stultz@linaro.org \
--cc=jovi.zhangwei@huawei.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lizefan@huawei.com \
--cc=mingo@redhat.com \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
--cc=rusty@rustcorp.com.au \
--cc=tglx@linutronix.de \
--cc=tj@kernel.org \
--cc=viro@zeniv.linux.org.uk \
--cc=wangyijing@huawei.com \
--cc=zhangdianfang@huawei.com \
/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.