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 unsigned long tmp = jiffies + 5 * HZ;
33 printk(KERN_INFO "Blocking other works in the queue\n");
34 printk(KERN_INFO "Executing task in CPU %d\n", smp_processor_id());
35 /* We also kick the CPU high */
36 while (!time_after(jiffies, tmp))
40 static void work_print(struct work_struct *work)
42 printk(KERN_INFO "Phew! That was waiting!\n");
43 printk(KERN_INFO "Task done in CPU %d\n", smp_processor_id());
46 static struct workqueue_struct *block_wq;
47 static DECLARE_WORK(block_work, work_block);
48 static DECLARE_WORK(print_work, work_print);
50 static int block_wq_init(void)
52 block_wq = create_workqueue("block_wq");
55 printk(KERN_INFO "Queueing task in CPU %d\n", get_cpu());
56 queue_work(block_wq, &block_work);
57 queue_work(block_wq, &print_work);
62 static void block_wq_exit(void)
64 destroy_workqueue(block_wq);
67 module_init(block_wq_init);
68 module_exit(block_wq_exit);