2 * Copyright (C) 2010 Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 * This code demonstrates why a work should not block for too long.
21 * This is worse in the case that the work is scheduled in keventd.
24 #include <linux/module.h>
25 #include <linux/workqueue.h>
27 MODULE_LICENSE("GPL");
28 MODULE_AUTHOR("Thadeu Lima de Souza Cascardo");
30 static void work_block(struct work_struct *work)
32 printk(KERN_INFO "Blocking other works in the queue\n");
33 printk(KERN_INFO "Executing task in CPU %d\n", smp_processor_id());
37 static void work_print(struct work_struct *work)
39 printk(KERN_INFO "Phew! That was waiting!\n");
40 printk(KERN_INFO "Task done in CPU %d\n", smp_processor_id());
43 static struct workqueue_struct *block_wq;
44 static DECLARE_WORK(block_work, work_block);
45 static DECLARE_WORK(print_work, work_print);
47 static int block_wq_init(void)
49 block_wq = create_singlethread_workqueue("block_wq");
52 printk(KERN_INFO "Queueing task in CPU %d\n", get_cpu());
54 queue_work(block_wq, &block_work);
55 queue_work(block_wq, &print_work);
59 static void block_wq_exit(void)
61 destroy_workqueue(block_wq);
64 module_init(block_wq_init);
65 module_exit(block_wq_exit);